Exemple #1
0
def process_neo4j(args):

    # Get family data of the person
    global points

    try:
        main_person = Person()
        main_person.uniq_id = args.id1

        taapeli_person = Person()
        taapeli_person.uniq_id = args.id2

        # The fetching of the family and parents data of the main person is
        # split to two operations:
        #
        # If there are no parents in the db the result of
        # get_parentin_id() operation is empty,
        # but the get_family_data operation prints out
        # the family of the main person.
        result = main_person.get_parentin_id()
        for record in result:
            main_parents_hlink = record["parentin_hlink"]

            result = taapeli_person.get_parentin_id()
            for record in result:
                taapeli_parents_hlink = record["parentin_hlink"]
                compare_parents_data(main_parents_hlink, taapeli_parents_hlink)

        compare_family_data(main_person, taapeli_person)

        print("=== === Total points: " + str(points) + " === ===")

    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
def get_name_data(handle):

    # Get Person and Name data
    
    try:
        p = Person()
        p.handle = handle
        p.get_person_and_name_data()
        p.print_data()
    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
Exemple #3
0
def process_neo4j(args):

    # Get family data of the person
    try:

        main_person = Person()
        main_person.handle = args.handle

        # The fetching of the family and parents data of the main person is
        # split to two operations:
        #
        # If there are no parents in the db the result of
        # get_parentin_handle() operation is empty,
        # but the get_family_data operation prints out
        # the family of the main person.
        result = main_person.get_parentin_handle()
        for record in result:
            get_parents_data(record["parentin_hlink"])

        get_family_data(main_person)

    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
def process_neo4j(args):
    ''' 
        Compare a person from owner's set and another person in Taapeli db
        by the reference names of their first first name 
    '''
    try:
    
        t = time.perf_counter()
        print_cnt = 0

        u = User()
        u.userid = args.userid
        result = u.get_ids_and_refnames_of_people_of_user()
        for record in result:
            p = Person()
            # This id is the unique key of the node
            uniq_id = record["id"]
            p.id = uniq_id
            refname = record["refname"]
            p.get_person_and_name_data_by_id()

            # Use the first of first names of the refname as a search key,
            # E.g. refname = "Matti Johannes" ---> search with "Matti"
            names = refname.split(" ")
                
            tresult = Name.get_ids_of_people_with_refname_and_user_given('Taapeli', names[0])
            for trecord in tresult:
                tp = Person()
                tp.id = trecord["id"]
            
                if print_cnt == 0:
                    print("\nUnique id pairs of people with the same first name in")
                    print("the compared db : the Taapeli db")
                
                print("\n" + str(uniq_id) + " : " + str(tp.id))
                print_cnt += 1
          
        print("\n\nNumber of id pairs printted out: " + str(print_cnt))
        elapsed_time = time.perf_counter() - t
        print("\nTime needed: " + str(elapsed_time) + " seconds")

    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
Exemple #5
0
def process_neo4j(args):

    # List people with the given name
    try:
    
        t = time.perf_counter()

        u = User()
        u.userid = args.userid
        result = u.get_refnames_of_people_of_user()
        for record in result:
            p = Person()
            p.handle = record["handle"]
            refname = record["refname"]
            p.get_person_and_name_data()

            # Use the first name of the refname as a search key,
            # E.g. refname = "Matti Johannes" ---> search with "Matti"
            names = refname.split(" ")
                
            tresult = Name.get_people_with_refname_and_user_given('Taapeli', names[0])
            for trecord in tresult:
                tp = Person()
                tp.handle = trecord["handle"]
                
                print("\nPerson in the compare db:")
                call_string = "python3 get_family_with_handle_given.py " + p.handle
                subprocess.call(call_string, shell=True)
                
                print("\nPerson in the Taapeli db:")
                call_string = "python3 get_family_with_handle_given.py " + tp.handle
                subprocess.call(call_string, shell=True)
                
                print("\n#-------------------------------------------------------------------#\n")
                                   
        elapsed_time = time.perf_counter() - t
        print("\nTime needed: " + str(elapsed_time) + " seconds")

    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
Exemple #6
0
def get_family_data(mp):

    # Get main person's Family data

    try:
        print("\nMAIN PERSON: \n")
        get_person_data(mp)

        print("\nSPOUSE(S): \n")
        if mp.gender == 'M':
            result = mp.get_his_families()
        else:
            result = mp.get_her_families()

        for record in result:
            mf = Family()
            mf.handle = record["handle"]

            mf.get_family_data()
            mf.print_data()

            # This is the event(s) of the family
            for event_link in mf.eventref_hlink:
                get_event_and_place_data(event_link)

            print("\n")
            spouse = Person()
            if mp.gender == 'M':
                spouse.handle = mf.mother
            else:
                spouse.handle = mf.father
            get_person_data(spouse)

            print("\nCHILDREN: ")
            for child_link in mf.childref_hlink:
                child = Person()
                child.handle = child_link
                print("\n")
                get_person_data(child)

    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
Exemple #7
0
def get_parents_data(handle):

    # Get main person's parents data

    try:
        f = Family()
        f.handle = handle

        f.get_family_data()
        #        f.print_data()

        print("\nFATHER: \n")
        father = Person()
        father.handle = f.father
        get_person_data(father)

        print("\nMOTHER: \n")
        mother = Person()
        mother.handle = f.mother
        get_person_data(mother)

    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
Exemple #8
0
def compare_family_data(mp, tp):

    # Get main and the compared person's Family data
    
    try:
        spouse1 = None
        spouse2 = None
        children1 = None
        children2 = None

        print("\nMAIN PERSONS: \n")
        compare_person_data(mp, tp)
                         
        if mp.gender == 'M':
            result = mp.get_his_families_by_id()
        else:
            result = mp.get_her_families_by_id()
            
        for record in result:
            mf = Family()
            mf.uniq_id = record["uniq_id"]
            
            mf.get_family_data_by_id()
                       
            spouse1 = Person()
            if mp.gender == 'M':
                spouse1.uniq_id = mf.mother
            else:
                spouse1.uniq_id = mf.father
   
            children1 = []
            for child_id in mf.childref_hlink:
                child = Person()
                child.uniq_id = child_id
                children1.append(child)
            
        if tp.gender == 'M':
            result = tp.get_his_families_by_id()
        else:
            result = tp.get_her_families_by_id()
            
        for record in result:
            tf = Family()
            tf.uniq_id = record["uniq_id"]
            
            tf.get_family_data_by_id()
                       
            spouse2 = Person()
            if tp.gender == 'M':
                spouse2.uniq_id = tf.mother
            else:
                spouse2.uniq_id = tf.father
   
            children2 = []
            for child_id in tf.childref_hlink:            
                child = Person()
                child.uniq_id = child_id
                children2.append(child)
            
        if spouse1:
            if spouse2:
                print("\nSPOUSE(S): \n")
                compare_person_data(spouse1, spouse2)
        
        if children1:
            if children2:
                print("\nCHILDREN: ")
                if (len(children2) >= len(children1)):
                    for i in range (len(children1)):
                        print("\n")
                        compare_person_data(children1[i], children2[i])
                
    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
Exemple #9
0
def process_neo4j(args):

    # Get family data of the person
    global points
    
    try:    
        t = time.perf_counter()
        print_cnt = 0
        
        total_points = []
        compared_ids = []
        taapeli_ids = []

        u = User()
        u.userid = args.userid
        result = u.get_ids_and_refnames_of_people_of_user()
        for record in result:
            p = Person()
            # This id is the unique key of the node
            p.uniq_id = record["id"]
            refname = record["refname"]
            p.get_person_and_name_data_by_id()

            # Use the first name of the refname as a search key,
            # E.g. refname = "Matti Johannes" ---> search with "Matti"
            names = refname.split(" ")
                
            tresult = Name.get_ids_of_people_with_refname_and_user_given('Taapeli', names[0])
            for trecord in tresult:
                tp = Person()
                tp.uniq_id = trecord["id"]
                
                # The fetching of the family and parents data of the main person is
                # split to two operations:
                #
                # If there are no parents in the db the result of 
                # get_parentin_id() operation is empty,
                # but the get_family_data operation prints out
                # the family of the main person.
                result = p.get_parentin_id()            
                for record in result:
                    main_parents_hlink = record["parentin_hlink"]
                    
                    result = tp.get_parentin_id()            
                    for record in result:
                        taapeli_parents_hlink = record["parentin_hlink"]
                        compare_parents_data(main_parents_hlink, taapeli_parents_hlink)
        
                compare_family_data(p, tp)
                
                total_points.append(points)
                compared_ids.append(p.uniq_id)
                taapeli_ids.append(tp.uniq_id)
                print_cnt += 1
                
        print("\nTotal points # Compared ids # Taapeli ids")
        print("-----------------------------------------")
        for i in range(len(total_points)):
            print("\n  " + str(total_points[i]) + "   #   " + str(compared_ids[i]) + "   #   " + str(taapeli_ids[i]))

        print("\nLines printted: " + str(print_cnt))
                
        elapsed_time = time.perf_counter() - t
        print("\nTime needed: " + str(elapsed_time) + " seconds")

    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
Exemple #10
0
def compare_parents_data(id1, id2):

    # Get main person's parents data
    
    try:
        f1 = Family()
        f1.uniq_id = id1
        f1.get_family_data_by_id()
        
        f2 = Family()
        f2.uniq_id = id2
        f2.get_family_data_by_id()
            
        print("\nFATHER: \n")
        father1 = Person()
        father1.uniq_id = f1.father
        father2 = Person()
        father2.uniq_id = f2.father
        compare_person_data(father1, father2)
                      
        print("\nMOTHER: \n")
        mother1 = Person()
        mother1.uniq_id = f1.mother
        mother2 = Person()
        mother2.uniq_id = f2.mother
        compare_person_data(mother1, mother2)
                                                    
    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
Exemple #11
0
def compare_parents_data(handle1, handle2, print_out):

    # Get main person's parents data

    try:
        f1 = Family()
        f1.handle = handle1
        f1.get_family_data()

        f2 = Family()
        f2.handle = handle2
        f2.get_family_data()

        print("\nFATHER: \n")
        father1 = Person()
        father1.handle = f1.father
        father2 = Person()
        father2.handle = f2.father
        compare_person_data(father1, father2, print_out)

        print("\nMOTHER: \n")
        mother1 = Person()
        mother1.handle = f1.mother
        mother2 = Person()
        mother2.handle = f2.mother
        compare_person_data(mother1, mother2, print_out)

    except Exception as err:
        print("Virhe: {0}".format(err), file=stderr)
Exemple #12
0
def number_of_people():
    print("Number of people in db: " + Person.get_total())
Exemple #13
0
def handle_people(collection, userid):
    # Get all the people in the collection
    people = collection.getElementsByTagName("person")

    print("*****People*****")
    counter = 0

    # Print detail of each person
    for person in people:

        p = Person()

        if person.hasAttribute("handle"):
            p.handle = person.getAttribute("handle")
        if person.hasAttribute("change"):
            p.change = person.getAttribute("change")
        if person.hasAttribute("id"):
            p.id = person.getAttribute("id")

        if len(person.getElementsByTagName('gender')) == 1:
            person_gender = person.getElementsByTagName('gender')[0]
            p.gender = person_gender.childNodes[0].data
        elif len(person.getElementsByTagName('gender')) > 1:
            print("Error: More than one gender tag in a person")

        if len(person.getElementsByTagName('name')) >= 1:
            for i in range(len(person.getElementsByTagName('name'))):
                person_name = person.getElementsByTagName('name')[i]
                pname = Name()
                if person_name.hasAttribute("alt"):
                    pname.alt = person_name.getAttribute("alt")
                if person_name.hasAttribute("type"):
                    pname.type = person_name.getAttribute("type")

                if len(person_name.getElementsByTagName('first')) == 1:
                    person_first = person_name.getElementsByTagName('first')[0]
                    if len(person_first.childNodes) == 1:
                        pname.first = person_first.childNodes[0].data
                    elif len(person_first.childNodes) > 1:
                        print(
                            "Error: More than one child node in a first name of a person"
                        )
                elif len(person_name.getElementsByTagName('first')) > 1:
                    print("Error: More than one first name in a person")

                if len(person_name.getElementsByTagName('surname')) == 1:
                    person_surname = person_name.getElementsByTagName(
                        'surname')[0]
                    if len(person_surname.childNodes) == 1:
                        pname.surname = person_surname.childNodes[0].data
                    elif len(person_surname.childNodes) > 1:
                        print(
                            "Error: More than one child node in a surname of a person"
                        )
                elif len(person_name.getElementsByTagName('surname')) > 1:
                    print("Error: More than one surname in a person")

                if len(person_name.getElementsByTagName('suffix')) == 1:
                    person_suffix = person_name.getElementsByTagName(
                        'suffix')[0]
                    pname.suffix = person_suffix.childNodes[0].data
                elif len(person_name.getElementsByTagName('suffix')) > 1:
                    print("Error: More than one suffix in a person")

                p.name.append(pname)

        if len(person.getElementsByTagName('eventref')) >= 1:
            for i in range(len(person.getElementsByTagName('eventref'))):
                person_eventref = person.getElementsByTagName('eventref')[i]
                if person_eventref.hasAttribute("hlink"):
                    p.eventref_hlink.append(
                        person_eventref.getAttribute("hlink"))
                if person_eventref.hasAttribute("role"):
                    p.eventref_role.append(
                        person_eventref.getAttribute("role"))

        if len(person.getElementsByTagName('parentin')) >= 1:
            for i in range(len(person.getElementsByTagName('parentin'))):
                person_parentin = person.getElementsByTagName('parentin')[i]
                if person_parentin.hasAttribute("hlink"):
                    p.parentin_hlink.append(
                        person_parentin.getAttribute("hlink"))

        if len(person.getElementsByTagName('citationref')) >= 1:
            for i in range(len(person.getElementsByTagName('citationref'))):
                person_citationref = person.getElementsByTagName(
                    'citationref')[i]
                if person_citationref.hasAttribute("hlink"):
                    p.citationref_hlink.append(
                        person_citationref.getAttribute("hlink"))

        p.save(userid)
        counter += 1

        # There can be so many individs to store that Cypher needs a pause
        time.sleep(0.1)

    print("Number of people stored: " + str(counter))