In[]:=
parseGEDFile[ged_]:=Module[{g=ged,indi,x,λ,j,temp,persnum,surname,startrecord,endrecord,record,givenname,childof,spouseof,sex,birth,tree={}},λ=Length[ged];For[j=1,j≤λ,j++,While[j≤λ&&StringTake[g[[j]],4]!="0 @I",j++];startrecord=j;If[startrecord>λ,Break[]];j++;While[j≤λ&&StringTake[g[[j]],1]!="0",j++];endrecord=j-1;record=g[[startrecord;;endrecord]];temp=Flatten[StringCases[record,"@I"~~x___~~"@"x]];If[temp≠{},persnum="I"<>First[temp]];temp=Flatten[StringCases[record," /"~~x___~~"/"x]];If[temp≠{},surname=First[temp]];temp=Flatten[StringCases[record,"1 NAME "~~x___~~" /"x]];givenname=If[temp=={},"Unknown",First[temp]];temp=Flatten[StringCases[record,"1 FAMC @"~~x___~~"@"x]];childof=If[temp=={},"Unknown",First[temp]];temp=Flatten[StringCases[record,"1 FAMS @"~~x___~~"@"x]];spouseof=If[temp=={},"Unknown",First[temp]];temp=Flatten[StringCases[record,"1 SEX "~~x_x]];If[temp≠{},sex=First[temp]];temp=Flatten[StringCases[Extract[record,Position[record,"1 BIRT"]+1],"2 DATE"~~x___x]];If[temp≠{},birth=First[temp]];AppendTo[tree,<|"Id"persnum,"Surname"surname,"GivenName"givenname,"ChildOf"childof,"SpouseOf"spouseof,"Sex"sex,"Birth"birth|>];j=endrecord];Return[Dataset[tree]]]
Some useful selection apps
In[]:=
childrenOf[persnum_,dataset_]:=Module[{f,children,G=dataset},f=G[Select[#"Id"persnum&]][1,"SpouseOf"];children=If[f"Unknown",{},Normal[G[Select[#"ChildOf"f&]][All,"Id"]]];Return[children]]
Update and Reset are used in LOD, a recursive program to find all lines of descent between an ancestor and a descendant
In[]:=
update[θ_,x_]:=Module[{newx,newθ,y},newθ=θ;newx=x;y=First[x];If[y{},newx=Drop[x,1];newθ=If[Length[newθ]>1,Drop[newθ,-1],newθ]];If[y≠{},newx[[1]]=Rest[y];newx=PrependTo[newx,childrenOf[First[y],G]];newθ=Append[newθ,First[y]]];Return[{newθ,newx}]]
In[]:=
reset[θ_,x_]:=Module[{newpath,newx},newpath=θ;newx=x;If[Length[newpath]>2,newpath=Drop[newpath,-2]];If[Length[newx]≥2,newx=Drop[newx,2],newx={}];Return[{newpath,newx}]]
In[]:=
LOD[path_,descendant_,notYetVisited_,allPaths_]:=Module[{curpath=path,p=descendant,X=notYetVisited,AP=allPaths,cond1,cond2},cond1=X{};cond2=Last[curpath]p;Catch[If[cond1,Throw[allPaths],If[Not[cond1],If[Not[cond2],{curpath,X}=update[curpath,X];Throw[LOD@@{curpath,p,X,AP}],AppendTo[AP,curpath];{curpath,X}=reset[curpath,X];Throw[LOD@@{curpath,p,X,AP}]]]]]]
In[]:=
getName[id_,G_]:=person=G[Select[#"Id"id&]][1,"GivenName"]<>" "<>G[Select[#"Id"id&]][1,"Surname"]
Get couple gets the spouse of an individual based on the id. There are 4 options for the output:
A Married B
A
married
B
Framed or not framed for each
A Married B
A
married
B
Framed or not framed for each
In[]:=
getCouple[id_,x_,framed_]:=Module[{husb,wife,hw,person,spouse,insert},If[x1,insert=" Married "];If[x2,insert=FromCharacterCode[10]<>"Maried"<>FromCharacterCode[10]];person=G[Select[#"Id"id&]];sex=person[1,"Sex"];spouse=person[1,"SpouseOf"];If[spouse≠"Unknown",hw=G[Select[#"SpouseOf"spouse&]];husb=hw[Select[#"Sex""M"&]][1,"GivenName"]<>" "<>hw[Select[#"Sex""M"&]][1,"Surname"];wife=hw[Select[#"Sex""F"&]][1,"GivenName"]<>" "<>hw[Select[#"Sex""F"&]][1,"Surname"]];If[spouse=="Unknown"&&sex"M",husb=person[1,"GivenName"]<>" "<>person[1,"Surname"];wife="Unknown"];If[spouse=="Unknown"&&sex"F",wife=person[1,"GivenName"]<>" "<>person[1,"Surname"];husb="Unknown"];Return[If[framedTrue,Framed[husb<>insert<>wife],husb<>insert<>wife]]]
begats produces a descendant list
In[]:=
begats[descent_]:=Module[{dl=descent,ances,δ},δ=Length[dl];ances=Table[dl[[j]]<>" begat "<>dl[[j+1]],{j,1,δ-1}];Return[ances]]