def import_gedcom_data(): gedcom_file = Gedcom('family.ged') people_elements = [] fam_dict = {} family_codes = [] for elem in gedcom_file.element_list(): if elem.tag() == 'NAME': people_elements.append(elem) if elem.parent().tag() == 'INDI': for fam in gedcom_file.families(elem.parent()): p = fam.pointer() if p not in family_codes: family_codes.append(p) for fc in family_codes: for pe in people_elements: if pe.parent().tag() == 'INDI': for fam in gedcom_file.families(pe.parent()): if fam.pointer() == fc: if fc in fam_dict.keys(): fam_dict[fc].append(pe) else: fam_dict[fc] = [pe] for fam in gedcom_file.families(pe.parent(), family_type='FAMC'): if fam.pointer() == fc: if fc in fam_dict.keys(): fam_dict[fc].append(pe) else: fam_dict[fc] = [pe] print fam_dict
def checkmemoryusage(fn,n): from gedcom import Gedcom from time import sleep print ( "Creating %s gedcom objects from %s ... " % ( n, fn ) ) for i in range(0,n): print ( i + 1 ) g = None time.sleep(10) g = Gedcom.fromfilename(fn) print ( "We should be done now." ) g=None while True: sleep(10) #checkstorage() #checkdb() #checkmemoryusage(afilename,2)
if args.firstname: given_names.append(args.firstname) if args.middlename: given_names.append(args.middlename) if given_names: match_criteria.append("name={}".format(" ".join(given_names))) if args.lastname is not None: match_criteria.append("surname={}".format(args.lastname)) # The matching criteria as defined in gedcom.py criteria_match() function criteria = ":".join(match_criteria) if args.state: # State census dates fall on the fifth year of each decade, e.g. 1915, 1925, etc offset = 5 else: # Federal census dates fall on the zero year of each decade, e.g. 1910, 1920, etc offset = 0 # Parse the Gedcom file, using the lovely parser we snatched out of Github gedcom = Gedcom(args.gedfilename) # Look at EVERYONE for element in gedcom.element_list(): # Do they match? if element.criteria_match(criteria): # A match, fingerprint them data = fingerprint_data(gedcom, element, offset) print_fingerprint(data)
# (A header with FHKB ontology definitions is still required.) # TODO adoptive families (>1) are not considered (TODO?) # Author: Evgeny Blokhin # License: MIT import os, sys from gedcom import Gedcom try: workpath = sys.argv[1] except IndexError: sys.exit("No gedcom defined!") def term2id(el): return "i" + el.pointer().replace('@', '').lower() g = Gedcom(workpath) gedcom_dict = g.element_dict() individuals, marriages = {}, {} for k, v in gedcom_dict.iteritems(): if v.is_individual(): children, siblings = set(), set() idx = term2id(v) title = v.name()[0].decode('utf8').encode('ascii', 'xmlcharrefreplace') + " " + v.name()[1].decode('utf8').encode('ascii', 'xmlcharrefreplace') title = title.replace('"', '').replace('[', '').replace(']', '').replace('(', '').replace(')', '').strip() own_families = g.families(v, 'FAMS') for fam in own_families: children |= set(term2id(i) for i in g.get_family_members(fam, "CHIL"))
# Project for SSW-555 # Author: Jiakuan Fan # Author: Hangbo Li # Author: Shan Jiang from gedcom import Gedcom if __name__ == '__main__': sprint_4_demo = Gedcom("sprint_4_test") sprint_4_demo.set_output_url("spirnt_4_demo_output.txt") sprint_4_demo.print_pretty_table() sprint_4_demo.check_all_objects_sprint_4()
# Project for SSW-555 # Author: Jiakuan Fan # Author: Hangbo Li # Author: Shan Jiang from gedcom import Gedcom import us01 import us02 import us03 import us04 import us05 import us06 if __name__ == '__main__': sprint_1_demo = Gedcom("sprint_1_test") sprint_1_demo.set_output_url("spirnt_1_demo_output.txt") sprint_1_demo.print_pretty_table() us01.check_date_b4_current(sprint_1_demo) us02.check_birth_b4_marr(sprint_1_demo) us03.check_birth_b4_death(sprint_1_demo) us04.check_marr_b4_div(sprint_1_demo) us05.check_marr_b4_death(sprint_1_demo) us06.check_div_b4_death(sprint_1_demo) output_stream = open(sprint_1_demo.output_url, "a") output_stream.write("Errors:\n") for error in sprint_1_demo.error_list: print(error) output_stream.write(error + '\n') output_stream.close()
#!/opt/local/bin/python from gedcom import Gedcom, GedcomIndividual import json from migra import MigraPerson, MigraGeocoder, MigraPersonEncoder import sys sys.stderr.write ( "Reading file into gedcom object...\n" ) g = Gedcom.fromfilename('/Users/rolando/src/migradata/big.ged') #g = Gedcom.fromfilename('/Users/rolando/src/migradata/romney2.ged') gc = MigraGeocoder() sys.stderr.write ( "Done... Building JSON list...\n" ) pList = [] for i in g.element_list(): if i.individual(): pList.append ( MigraPerson(i,0,gc) ) sys.stderr.write ( "Done. Dumping JSON list. . .\n" ) print json.dumps(pList,indent=4,cls=MigraPersonEncoder) sys.stderr.write ( "Done.\n" )
def test(individuals, families, input_errors): gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_corresponding_entries(gedcom) for error in errors: assert error in input_errors assert len(errors) == len(input_errors)
def test_validate_no_bigamy(): # Spouse 1 and Spouse 2 each don't have another marriage families = [ Family('f01', married=datetime(2000, 10, 10), husband_id='i01', wife_id='i02') ] individuals = [ Individual('i01', spouses=['f01']), Individual('i02', spouses=['f01']) ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_no_bigamy(gedcom) assert len(errors) == 0 # Spouse 1 got married to Spouse 3 during still-existing marriage to Spouse 2 families = [ Family('f01', married=datetime(2000, 10, 10), husband_id='i01', wife_id='i02'), Family('f02', married=datetime(2005, 10, 10), husband_id='i01', wife_id='i03') ] individuals = [ Individual('i01', spouses=['f01', 'f02']), Individual('i02', spouses=['f01']), Individual('i03', spouses=['f02']) ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_no_bigamy(gedcom) assert errors[ 0] == 'Error: US11: Individual i01 married i03 on 10-10-2005, which was during their marriage to i02' assert len(errors) == 1 # Spouse 1 got married to spouse 3 during marriage to spouse 2 families = [ Family('f01', married=datetime(2000, 10, 10), divorced=datetime(2010, 10, 10), husband_id='i01', wife_id='i02'), Family('f02', married=datetime(2005, 10, 10), husband_id='i01', wife_id='i03') ] individuals = [ Individual('i01', spouses=['f01', 'f02']), Individual('i02', spouses=['f01']), Individual('i03', spouses=['f02']) ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_no_bigamy(gedcom) assert errors[ 0] == 'Error: US11: Individual i01 married i03 on 10-10-2005, which was during their marriage to i02' assert len(errors) == 1 # Spouse 1 married Spouse 2, got divorced, and then married Spouse 3 families = [ Family('f01', married=datetime(2000, 10, 10), divorced=datetime(2010, 10, 10), husband_id='i01', wife_id='i02'), Family('f02', married=datetime(2012, 10, 10), husband_id='i01', wife_id='i03') ] individuals = [ Individual('i01', spouses=['f01', 'f02']), Individual('i02', spouses=['f01']), Individual('i03', spouses=['f02']) ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_no_bigamy(gedcom) assert len(errors) == 0
def test_correct_gender(): # Husband is female or anything other than male families = [ Family('F01', married=datetime(1999, 9, 9), husband_id='I01', wife_id='I02') ] individuals = [ Individual('I01', spouses=['F01'], sex='X'), Individual('I02', spouses=['F01'], sex='F') ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_correct_gender(gedcom) assert errors[0] == 'Error: US21: Husband I01 in Family F01 should be male' assert len(errors) == 1 # Wife is male or anything other than female families = [ Family('F01', married=datetime(1999, 9, 9), husband_id='I01', wife_id='I02') ] individuals = [ Individual('I01', spouses=['F01'], sex='M'), Individual('I02', spouses=['F01'], sex='X') ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_correct_gender(gedcom) assert errors[0] == 'Error: US21: Wife I02 in Family F01 should be female' assert len(errors) == 1 # Both Husband and wife are not male and femalerespectively families = [ Family('F01', married=datetime(1999, 9, 9), husband_id='I01', wife_id='I02') ] individuals = [ Individual('I01', spouses=['F01'], sex='X'), Individual('I02', spouses=['F01'], sex='X') ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_correct_gender(gedcom) assert errors[0] == 'Error: US21: Husband I01 in Family F01 should be male' assert errors[1] == 'Error: US21: Wife I02 in Family F01 should be female' assert len(errors) == 2 # Both Husband and Wife are correct gender families = [ Family('F01', married=datetime(1999, 9, 9), husband_id='I01', wife_id='I02') ] individuals = [ Individual('I01', spouses=['F01'], sex='M'), Individual('I02', spouses=['F01'], sex='F') ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_correct_gender(gedcom) assert len(errors) == 0
def test_marriage_after_fourteen(): # Husband < 14 individuals = [ Individual('I01', spouse='F01', birthday=datetime(2007, 1, 1)), Individual('I02', spouse='F01', birthday=datetime(1997, 6, 18)) ] families = [ Family('F01', husband_id='I01', wife_id='I02', married=datetime(2020, 2, 20)) ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_marriage_after_fourteen(gedcom) assert errors[ 0] == 'Error: US10: Spouse I01 in family F01 was married at less than 14 years old, age=13' assert len(errors) == 1 # Wife < 14 individuals = [ Individual('I01', spouse='F01', birthday=datetime(2007, 1, 1)), Individual('I02', spouse='F01', birthday=datetime(1997, 6, 18)) ] families = [ Family('F01', wife_id='I01', husband_id='I02', married=datetime(2020, 2, 20)) ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_marriage_after_fourteen(gedcom) assert errors[ 0] == 'Error: US10: Spouse I01 in family F01 was married at less than 14 years old, age=13' assert len(errors) == 1 # Husband + Wife < 14 individuals = [ Individual('I01', spouse='F01', birthday=datetime(2007, 1, 1)), Individual('I02', spouse='F01', birthday=datetime(2007, 1, 1)) ] families = [ Family('F01', wife_id='I01', husband_id='I02', married=datetime(2020, 2, 20)) ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_marriage_after_fourteen(gedcom) assert errors[ 0] == 'Error: US10: Spouse I01 in family F01 was married at less than 14 years old, age=13' assert errors[ 1] == 'Error: US10: Spouse I02 in family F01 was married at less than 14 years old, age=13' assert len(errors) == 2 # Husband + Wife > 14 individuals = [ Individual('I01', spouse='F01', birthday=datetime(1997, 6, 18)), Individual('I02', spouse='F01', birthday=datetime(1997, 6, 18)) ] families = [ Family('F01', wife_id='I01', husband_id='I02', married=datetime(2020, 2, 20)) ] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_marriage_after_fourteen(gedcom) assert len(errors) == 0 # No marriage --> no errors individuals = [ Individual('I01', spouse='F01', birthday=datetime(1997, 6, 18)), Individual('I02', spouse='F01', birthday=datetime(1997, 6, 18)) ] families = [Family('F01', wife_id='I01', husband_id='I02')] gedcom = Gedcom(individuals=individuals, families=families) errors = validation.validate_marriage_after_fourteen(gedcom) assert len(errors) == 0
def readgedcom(path): root = Gedcom(path) people = {} families = [] d = root.element_dict() for i in d: elem = d[i] id = i if elem.is_individual(): name = '' for i in elem.children(): if i.tag() == 'NAME': name = i.value().replace('/', '') people[id] = name else: fam = [[], 0, 0] for i in elem.children(): if i.tag() == 'CHIL': fam[0].append(i.value()) if i.tag() == 'HUSB': fam[1] = i.value() if i.tag() == 'WIFE': fam[2] = i.value() families.append(fam) return (people, families)