gedcom

package module
v0.2.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2024 License: Unlicense Imports: 6 Imported by: 2

README

gedcom

Go package to parse GEDCOM files.

Test Status Go Report Card go.dev reference

Usage

The package provides a Decoder with a single Decode method that returns a Gedcom struct. Use the NewDecoder method to create a new decoder.

This example shows how to parse a GEDCOM file and list all the individuals. In this example the entire input file is read into memory, but the decoder is streaming so it should be able to deal with very large files: just pass an appropriate Reader.

package main

import (
	"bytes"
	"github.com/iand/gedcom"
	"io/ioutil"
)

func main() {
	data, _ := ioutil.ReadFile("testdata/kennedy.ged")

	d := gedcom.NewDecoder(bytes.NewReader(data))

	g, _ := d.Decode()

	for _, rec := range g.Individual {
		if len(rec.Name) > 0 {
			println(rec.Name[0].Name)
		}			
	}
}

The structures produced by the Decoder are in types.go and correspond roughly 1:1 to the structures in the GEDCOM specification.

This package does not implement the entire GEDCOM specification, I'm still working on it. It's about 80% complete which is enough for about 99% of GEDCOM files. It has not been extensively tested with non-ASCII character sets nor with pathological cases such as the GEDCOM 5.5 Torture Test Files.

Installation

Simply run

go get github.com/iand/gedcom

Documentation is at http://godoc.org/github.com/iand/gedcom

Authors

Contributors

Contributing

  • Do submit your changes as a pull request
  • Do your best to adhere to the existing coding conventions and idioms.
  • Do run go fmt on the code before committing
  • Do feel free to add yourself to the CREDITS file and the corresponding Contributors list in the README.md. Alphabetical order applies.
  • Don't touch the AUTHORS file. An existing author will add you if your contributions are significant enough.
  • Do note that in order for any non-trivial changes to be merged (as a rule of thumb, additions larger than about 15 lines of code), an explicit Public Domain Dedication needs to be on record from you. Please include a copy of the statement found in the WAIVER file with your pull request

License

This is free and unencumbered software released into the public domain. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.

Documentation

Overview

Package gedcom provides a functions to parse GEDCOM files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressDetail added in v0.1.0

type AddressDetail struct {
	Full       string // The full address as found in free-form fields which may be optionally broken down using following structured fields
	Line1      string
	Line2      string
	Line3      string // 5.5.1
	City       string
	State      string
	PostalCode string
	Country    string
}

type AddressRecord

type AddressRecord struct {
	Address []*AddressDetail
	Phone   []string
	Email   []string // 5.5.1
	Fax     []string // 5.5.1
	WWW     []string // 5.5.1
}

See https://www.tamurajones.net/GEDCOMADDR.xhtml for very informative analysis of the ADDR structure

type AssociationRecord added in v0.0.4

type AssociationRecord struct {
	Xref     string
	Relation string
	Citation []*CitationRecord
	Note     []*NoteRecord
}

type ChangeRecord added in v0.0.4

type ChangeRecord struct {
	Date string
	Time string
	Note []*NoteRecord
}

type CitationRecord

type CitationRecord struct {
	Source      *SourceRecord
	Page        string
	Data        DataRecord
	Quay        string
	Media       []*MediaRecord
	Note        []*NoteRecord
	UserDefined []UserDefinedTag
}

type DataRecord

type DataRecord struct {
	Date        string
	Text        []string
	UserDefined []UserDefinedTag
}

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder reads and decodes GEDCOM objects from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads r.

func (*Decoder) Decode

func (d *Decoder) Decode() (*Gedcom, error)

Decode reads GEDCOM-encoded data from its input and parses it into a Gedcom structure.

func (*Decoder) LogUnhandledTags added in v0.2.0

func (d *Decoder) LogUnhandledTags(w io.Writer)

type EventRecord

type EventRecord struct {
	Tag                  string
	Value                string
	Type                 string
	Date                 string
	Place                PlaceRecord
	Address              AddressRecord
	Age                  string
	ResponsibleAgency    string
	ReligiousAffiliation string
	Cause                string
	RestrictionNotice    string        // 5.5.1
	ChildInFamily        *FamilyRecord // link to parent family for birth events
	AdoptedByParent      string        // for adoption event, one of HUSB,WIFE,BOTH
	Citation             []*CitationRecord
	Media                []*MediaRecord
	Note                 []*NoteRecord
	UserDefined          []UserDefinedTag
}

type FamilyLinkRecord

type FamilyLinkRecord struct {
	Family *FamilyRecord
	Type   string
	Note   []*NoteRecord
}

type FamilyRecord

type FamilyRecord struct {
	Xref              string
	Husband           *IndividualRecord
	Wife              *IndividualRecord
	Child             []*IndividualRecord
	Event             []*EventRecord
	NumberOfChildren  string
	UserReference     []*UserReferenceRecord
	AutomatedRecordId string
	Change            ChangeRecord
	Note              []*NoteRecord
	Citation          []*CitationRecord
	Media             []*MediaRecord
	UserDefined       []UserDefinedTag
}

type FileRecord added in v0.0.4

type FileRecord struct {
	Name        string
	Format      string
	FormatType  string
	Title       string
	UserDefined []UserDefinedTag
}

type Gedcom

type Gedcom struct {
	Header      *Header
	Family      []*FamilyRecord
	Individual  []*IndividualRecord
	Media       []*MediaRecord
	Repository  []*RepositoryRecord
	Source      []*SourceRecord
	Submitter   []*SubmitterRecord
	Trailer     *Trailer
	UserDefined []UserDefinedTag
}
type Header struct {
	SourceSystem        SystemRecord
	Destination         string
	Date                string
	Time                string
	Submitter           *SubmitterRecord
	Submission          *SubmissionRecord
	Filename            string
	Copyright           string
	Version             string
	Form                string
	CharacterSet        string
	CharacterSetVersion string
	Language            string
	Place               PlaceRecord
	Note                string
	UserDefined         []UserDefinedTag
}

A Header contains information about the GEDCOM file.

type IndividualRecord

type IndividualRecord struct {
	Xref                      string
	Name                      []*NameRecord
	Sex                       string
	Event                     []*EventRecord
	Attribute                 []*EventRecord
	Parents                   []*FamilyLinkRecord
	Family                    []*FamilyLinkRecord
	Submitter                 []*SubmitterRecord
	Association               []*AssociationRecord
	PermanentRecordFileNumber string
	AncestralFileNumber       string
	UserReference             []*UserReferenceRecord
	AutomatedRecordId         string
	Change                    ChangeRecord
	Note                      []*NoteRecord
	Citation                  []*CitationRecord
	Media                     []*MediaRecord
	UserDefined               []UserDefinedTag
}

type Line added in v0.1.0

type Line struct {
	Level      int
	Tag        string
	Value      string
	Xref       string
	LineNumber int // the line number of the input file
	Offset     int // the character offset in the input file
}

func (*Line) String added in v0.1.0

func (l *Line) String() string

type MediaRecord

type MediaRecord struct {
	Xref              string
	File              []*FileRecord
	UserReference     []*UserReferenceRecord
	AutomatedRecordId string
	Change            ChangeRecord
	Note              []*NoteRecord
	Citation          []*CitationRecord
	UserDefined       []UserDefinedTag
}

type NameRecord

type NameRecord struct {
	Name                   string
	Type                   string
	NamePiecePrefix        string
	NamePieceGiven         string
	NamePieceNick          string
	NamePieceSurnamePrefix string
	NamePieceSurname       string
	NamePieceSuffix        string
	Phonetic               []*VariantNameRecord
	Romanized              []*VariantNameRecord
	Citation               []*CitationRecord
	Note                   []*NoteRecord
}

type NoteRecord

type NoteRecord struct {
	Note     string
	Citation []*CitationRecord
}

type ParsedName added in v0.0.4

type ParsedName struct {
	Full     string
	Given    string
	Surname  string
	Suffix   string
	Nickname string
}

func SplitPersonalName added in v0.0.4

func SplitPersonalName(name string) ParsedName

SplitPersonalName parses a name in the format "First Name /Surname/ suffix" into its components.

type PlaceRecord

type PlaceRecord struct {
	Name      string
	Phonetic  []*VariantPlaceNameRecord
	Romanized []*VariantPlaceNameRecord
	Latitude  string
	Longitude string
	Citation  []*CitationRecord
	Note      []*NoteRecord
}

type RepositoryRecord

type RepositoryRecord struct {
	Xref              string
	Name              string
	Address           AddressRecord
	Note              []*NoteRecord
	UserReference     []*UserReferenceRecord
	AutomatedRecordId string
	Change            ChangeRecord
	UserDefined       []UserDefinedTag
}

type ScanErr added in v0.1.0

type ScanErr struct {
	Err        error
	LineNumber int
	Offset     int
}

func (*ScanErr) Error added in v0.1.0

func (e *ScanErr) Error() string

func (*ScanErr) Unwrap added in v0.1.0

func (e *ScanErr) Unwrap() error

type Scanner added in v0.1.0

type Scanner struct {
	// contains filtered or unexported fields
}

A Scanner is a GEDCOM scanning state machine.

func NewScanner added in v0.1.0

func NewScanner(r io.RuneScanner) *Scanner

NewScanner creates a new Scanner ready for use.

func (*Scanner) Err added in v0.1.0

func (s *Scanner) Err() error

Err returns the first non-EOF error that was encountered by the Scanner.

func (*Scanner) Line added in v0.1.0

func (s *Scanner) Line() Line

Line returns the most recent line tokenized by a call to Next.

func (*Scanner) Next added in v0.1.0

func (s *Scanner) Next() bool

Next advances the scanner to the next line. It returns false if there are no more lines or if an error is encountered. The caller should check the Err method whenever this method returns false.

type SourceCallNumberRecord added in v0.0.4

type SourceCallNumberRecord struct {
	CallNumber string
	MediaType  string
}

type SourceDataRecord added in v0.0.4

type SourceDataRecord struct {
	Event []*SourceEventRecord
}

type SourceEventRecord added in v0.0.4

type SourceEventRecord struct {
	Kind  string
	Date  string
	Place string
}

type SourceRecord

type SourceRecord struct {
	Xref              string
	Title             string
	Data              *SourceDataRecord
	Originator        string
	FiledBy           string
	PublicationFacts  string
	Text              string
	Repository        *SourceRepositoryRecord
	UserReference     []*UserReferenceRecord
	AutomatedRecordId string
	Change            ChangeRecord
	Note              []*NoteRecord
	Media             []*MediaRecord
	UserDefined       []UserDefinedTag
}

type SourceRepositoryRecord added in v0.0.4

type SourceRepositoryRecord struct {
	Repository *RepositoryRecord
	Note       []*NoteRecord
	CallNumber []*SourceCallNumberRecord
}

type SubmissionRecord

type SubmissionRecord struct {
	Xref string
}

type SubmitterRecord

type SubmitterRecord struct {
	Xref string
}

type SystemRecord

type SystemRecord struct {
	Xref            string
	Version         string
	ProductName     string
	BusinessName    string
	Address         AddressRecord
	SourceName      string
	SourceDate      string
	SourceCopyright string
	UserDefined     []UserDefinedTag
}

A SystemRecord contains information about the system that produced the GEDCOM.

type Trailer

type Trailer struct{}

type UserDefinedTag added in v0.0.4

type UserDefinedTag struct {
	Tag         string
	Value       string
	Xref        string
	Level       int
	UserDefined []UserDefinedTag
}

A UserDefinedTag is a tag that is not defined in the GEDCOM specification but is included by the publisher of the data. In GEDCOM user defined tags must be prefixed with an underscore. This is preserved in the Tag field.

type UserReferenceRecord added in v0.0.4

type UserReferenceRecord struct {
	Number string
	Type   string
}

type VariantNameRecord added in v0.2.0

type VariantNameRecord struct {
	Name                   string
	Type                   string
	NamePiecePrefix        string
	NamePieceGiven         string
	NamePieceNick          string
	NamePieceSurnamePrefix string
	NamePieceSurname       string
	NamePieceSuffix        string
	Citation               []*CitationRecord
	Note                   []*NoteRecord
}

type VariantPlaceNameRecord added in v0.2.0

type VariantPlaceNameRecord struct {
	Name string
	Type string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL