def load_persons_as_map(file_name): map_tree_persons = {} ged_file = gedcom.parse(file_name) for person in ged_file.individuals: # check do the person exist if person.id not in map_tree_persons: # continue tree_person = make_tree_person(person) map_tree_persons[person.id] = tree_person else: tree_person = map_tree_persons[person.id] if person.mother: if person.mother.id not in map_tree_persons: mother = make_tree_person(person.mother) map_tree_persons[person.mother.id] = mother tree_person.mother = mother else: tree_person.mother = map_tree_persons[person.mother.id] map_tree_persons[person.mother.id].children.append(tree_person) if person.father: if person.father.id not in map_tree_persons: father = make_tree_person(person.father) map_tree_persons[person.father.id] = father tree_person.father = father else: tree_person.father = map_tree_persons[person.father.id] map_tree_persons[person.father.id].children.append(tree_person) return map_tree_persons
def testSimpleFileConvert(self): gedcomfile = gedcom.parse(GEDCOM_FILE) rdf_graph = gedcomrdf.gedcom2rdf(gedcomfile) # Since BNodes might be used, we'll query it with SPARQL results = list(rdf_graph.query("SELECT ?bob WHERE { ?bob a foaf:Person ; foaf:gender 'male' ; foaf:givenName 'Bob' ; foaf:familyName 'Cox' }")) self.assertEqual(len(results), 1) bob_node = results[0][0] results = list(rdf_graph.query("SELECT ?joann WHERE { ?joann a foaf:Person ; foaf:gender 'female' ; foaf:givenName 'Joann' ; foaf:familyName 'Para' }")) self.assertEqual(len(results), 1) joann_node = results[0][0] results = list(rdf_graph.query("SELECT ?bobby_jo WHERE { ?bobby_jo a foaf:Person ; foaf:gender 'male' ; foaf:givenName 'Bobby Jo' ; foaf:familyName 'Cox' }")) self.assertEqual(len(results), 1) bobby_jo_node = results[0][0] # ensure these are all different uris self.assertNotEqual(bob_node, joann_node) self.assertNotEqual(bob_node, bobby_jo_node) self.assertNotEqual(joann_node, bobby_jo_node) self.assertTrue(rdf_graph.query("ASK { ?bobby_jo bio:father ?bob }", initBindings={'bobby_jo': bobby_jo_node, 'bob': bob_node })) self.assertTrue(rdf_graph.query("ASK { ?bobby_jo bio:mother ?joann }", initBindings={'joann': joann_node, 'bobby_jo': bobby_jo_node })) self.assertTrue(rdf_graph.query("ASK { ?marriage bio:partner ?bob, ?joann . }", initBindings={'joann': joann_node, 'bob': bob_node }))
def main(): """ the main function (this one) is the only function that runs when the program is called to run """ ### parse gedcom file for information gedfile = gedcom.parse(argIn) ### runs all functions and writes to file writeToJSONfile(gedfile)
def main(): gedfile = gedcom.parse(argIn) # getFatherRelation(gedfile) # getMotherRelation(gedfile) # parseTime(gedfile) # makeLength(gedfile) # makeJSONobject(gedfile) writeToJSONfile(gedfile)
def testSimpleFileConvert(self): gedcomfile = gedcom.parse(GEDCOM_FILE) rdf_graph = gedcomrdf.gedcom2rdf(gedcomfile) # Since BNodes might be used, we'll query it with SPARQL results = list( rdf_graph.query( "SELECT ?bob WHERE { ?bob a foaf:Person ; foaf:gender 'male' ; foaf:givenName 'Bob' ; foaf:familyName 'Cox' }" )) self.assertEqual(len(results), 1) bob_node = results[0][0] results = list( rdf_graph.query( "SELECT ?joann WHERE { ?joann a foaf:Person ; foaf:gender 'female' ; foaf:givenName 'Joann' ; foaf:familyName 'Para' }" )) self.assertEqual(len(results), 1) joann_node = results[0][0] results = list( rdf_graph.query( "SELECT ?bobby_jo WHERE { ?bobby_jo a foaf:Person ; foaf:gender 'male' ; foaf:givenName 'Bobby Jo' ; foaf:familyName 'Cox' }" )) self.assertEqual(len(results), 1) bobby_jo_node = results[0][0] # ensure these are all different uris self.assertNotEqual(bob_node, joann_node) self.assertNotEqual(bob_node, bobby_jo_node) self.assertNotEqual(joann_node, bobby_jo_node) self.assertTrue( rdf_graph.query("ASK { ?bobby_jo bio:father ?bob }", initBindings={ 'bobby_jo': bobby_jo_node, 'bob': bob_node })) self.assertTrue( rdf_graph.query("ASK { ?bobby_jo bio:mother ?joann }", initBindings={ 'joann': joann_node, 'bobby_jo': bobby_jo_node })) self.assertTrue( rdf_graph.query("ASK { ?marriage bio:partner ?bob, ?joann . }", initBindings={ 'joann': joann_node, 'bob': bob_node }))
def gedcom2gephi(gedcomFilename='gedcom.ged', gephiFilename=None): getName = lambda n: n.name[0] + ' ' + n.name[1] getId = lambda n: n.id[1:-1] getFamilyName = lambda n: n.name[1] g = gedcom.parse(gedcomFilename) dg = nx.DiGraph() for p in g.individuals: if p.id not in dg: dg.add_node(getId(p), label=getName(p), name=getName(p), familyName=getFamilyName(p)) for p in g.individuals: if p.father: dg.add_edge(getId(p.father), getId(p)) if p.mother: dg.add_edge(getId(p.mother), getId(p)) if gephiFilename is None: gephiFilename = os.path.splitext(gedcomFilename)[0] + '.gexf' nx.write_gexf(dg, gephiFilename)
def testCanAutoDetectInputFilename(self): myfile = tempfile.NamedTemporaryFile() filename = myfile.name parsed = gedcom.parse(filename) self.assertTrue(isinstance(parsed, gedcom.GedcomFile))
import unittest import parser_gedcom import gedcom import datetime import HTMLTestRunner parsed_data = gedcom.parse("sample.ged") fam = parser.for_families(parsed_data) ind = parser.for_individuals(parsed_data) #Implemnted test cases for user story 07 class TestMarriageBeforeDeath_US05(unittest.TestCase): def test_marriageBeforeDeath_US05_marriage_availibility(self): self.assertIsNotNone( fam[0]['marriage'], "ERROR: Family: US05: Marriage " + str(fam[0]['marriage']) + " Marriage Date cannot be None.") def test_marriageBeforeDeath_US05_MarriageDateType(self): self.assertEqual( type(fam[0]['marriage']), datetime.datetime, "ERROR: Family: US07: Marriage date " + str(fam[0]['marriage']) + " Marriage date is of wrong type.") def test_marriageBeforeDeath_US05_ReturnsFalse(self): self.assertFalse( parser.marriageBeforeDeath_US05(fam, ind), "ERROR: Family: US05: Returns False Function can't return False.") def test_marriageBeforeDeath_US05_ageIsString(self): self.assertNotEquals(
def testCanAutoDetectInputFP(self): fp = six.StringIO(GEDCOM_FILE) parsed = gedcom.parse(fp) self.assertTrue(isinstance(parsed, gedcom.GedcomFile))
def testCanAutoDetectInputString(self): parsed = gedcom.parse(GEDCOM_FILE) self.assertTrue(isinstance(parsed, gedcom.GedcomFile))
import gedcom import image import time from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt from matplotlib import animation import numpy as np if __name__ == "__main__": gedcomFile = gedcom.parse("Wainwright_Wroblewski.ged") names = [] birthYear = [] birthPlace = [] i = 0 k = 0 lons, lats = (-500, -500) for person in gedcomFile.individuals: i = i + 1 birthPlaces = person['BIRT'] firstName, lastName = person.name personName = firstName + " " + lastName names.append(personName) birthYear.append(birthPlaces.date) birthPlace.append(birthPlaces.place) myMap = Basemap(llcrnrlat=0, llcrnrlon=-120, urcrnrlat=75, urcrnrlon=45,
import gedcom import US0408sourabh, US10and22Sourabh, US12andUS36Sou, US09and11Sourabh import util_khalid import ga, ga2, ga3, ga4, ga5, ga6, ga7, ga8 FILE_PATH = 'GEDCOM.ged' if __name__ == '__main__': gedcom.parse(FILE_PATH) print('\nIndividuals') gedcom.print_individuals() print('\nFamilies') gedcom.print_families() # Demonstration of user stories # US01 fam_check = util_khalid.check_family_dates_before_current(gedcom.FAMs) indi_check = util_khalid.check_individual_dates_before_current( gedcom.INDIs) # US02 ga.US02bbm() # US03 ga2.US03bbm() # US04 US0408sourabh.US4MbD() # US05 ga3.US05bbm() # US06 ga4.US06bbm() # US07 util_khalid.check_individual_age_less_than_150(gedcom.INDIs)
def __init__(self, source, cache): self.node = gedcom.parse(io.StringIO(source)) self.cache = cache self.individual_cache = {} self.individuals = self.build_individuals()
import gedcom gc = gedcom.parse("tree.ged") with open("prog.pro", 'w') as output: for person in gc.individuals: firstname, lastname = person.name if (person.father): output.write("{0}{1}, {2}{3}\n".format("father(", person.father.name[0], person.name[0], ")")) if (person.mother): output.write("{0}{1}, {2}{3}\n".format("mother(", person.mother.name[0], person.name[0], ")"))
# thing to do right now is to strip them out into a temp file first. def prepare_file(file_path, tmp_path): with open(file_path, 'rb') as f: content = f.read().split('\r') content = [x for x in content if not x.startswith('2 CONT')] content = [x for x in content if not x.startswith('1 TITL')] with open(tmp_path, "w") as text_file: text_file.write('\n'.join(content)) print("Loading GEDCOM files...") # Read all of the people from the first file (main). prepare_file(args.file1, '/tmp/a.ged') gedcomfile = gedcom.parse('/tmp/a.ged') people1 = {} for person in gedcomfile.individuals: people1[person.id] = person # Read all of the people from the second file (to diff). prepare_file(args.file2, '/tmp/b.ged') gedcomfile = gedcom.parse('/tmp/b.ged') people2 = {} for person in gedcomfile.individuals: people2[person.id] = person def find_by_id(people1, id2, person2):
def parseGedcomFile(filename): """parse the gedcom file and return the result""" return gedcom.parse(filename)
from __future__ import print_function import gedcom from colorama import Fore, Style, Back gedcomfile = gedcom.parse("my.ged") color_stages = [ Fore.RED + Style.DIM, Fore.GREEN + Style.DIM, Fore.YELLOW + Style.DIM, Fore.MAGENTA + Style.DIM, Fore.CYAN + Style.DIM, Fore.WHITE + Style.DIM, Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.MAGENTA, Fore.CYAN, Fore.WHITE, Fore.RED + Style.BRIGHT, Fore.GREEN + Style.BRIGHT, Fore.YELLOW + Style.BRIGHT, Fore.MAGENTA + Style.BRIGHT, Fore.CYAN + Style.BRIGHT, Fore.WHITE + Style.BRIGHT, ] generations = [0] * 100 def tree(person, indent=0, silent=False):
def main(): gedfile = gedcom.parse(argIn) records = makeRecords(gedfile) jsonRecords = recordsToJson(records) writeToFile(jsonRecords, argOut)
def main(): gedfile = gedcom.parse(argIn) writeToJSONfile(gedfile)
import gedcom import datetime from prettytable import PrettyTable parsedData = gedcom.parse("sample.ged") today = datetime.datetime.now() allPersons = [] allFamilies = [] def forIndividual(parsedData): individual = list(parsedData.individuals) individualTable = PrettyTable() individualTable.field_names = ["ID", "Name", "Gender", "Birthday", "Age", "Alive", "Death", "Child", "Spouse"] for i in range(len(individual)): temp = individual[i] person = {} fname, lname = temp.name person['id'] = temp.id person['name'] = fname +" "+ lname person['gender'] = temp.gender person['birthdate'] = datetime.datetime.strptime(temp.birth.date, '%d %b %Y') birthDate = datetime.datetime.strptime(temp.birth.date,'%d %b %Y') if temp.__contains__('DEAT'): person['alive'] = None deathDate = (temp.__getitem__('DEAT')).date person['deathdate'] = datetime.datetime.strptime(deathDate, '%d %b %Y') else: person['deathdate'] = None