2003-03-23 01:56:44 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2003-04-04 11:18:25 +05:30
|
|
|
# Copyright (C) 2003 Donald N. Allingham
|
2003-03-23 01:56:44 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
import RelLib
|
|
|
|
import GrampsCfg
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
_level_name = [ "", "first", "second", "third", "fourth", "fifth", "sixth",
|
|
|
|
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth",
|
|
|
|
"thirteenth", "fourteenth", "fifteenth", "sixteenth",
|
|
|
|
"seventeenth", "eigthteenth", "nineteenth", "twentieth" ]
|
|
|
|
|
|
|
|
_removed_level = [ "", " once removed", " twice removed", " three times removed",
|
|
|
|
" four times removed", " five times removed", " six times removed",
|
|
|
|
" sevent times removed", " eight times removed", " nine times removed",
|
|
|
|
" ten times removed", " eleven times removed", " twelve times removed",
|
|
|
|
" thirteen times removed", " fourteen times removed", " fifteen times removed",
|
|
|
|
" sixteen times removed", " seventeen times removed", " eighteen times removed",
|
|
|
|
" nineteen times removed", " twenty times removed" ]
|
|
|
|
|
|
|
|
_father_level = [ "", "father", "grandfather", "great grandfather", "second great grandfather",
|
|
|
|
"third great grandfather", "fourth great grandfather",
|
|
|
|
"fifth great grandfather", "sixth great grandfather",
|
|
|
|
"seventh great grandfather", "eighth great grandfather",
|
|
|
|
"ninth great grandfather", "tenth great grandfather",
|
|
|
|
"eleventh great grandfather", "twelefth great grandfather",
|
|
|
|
"thirteenth great grandfather", "fourteenth great grandfather",
|
|
|
|
"fifteenth great grandfather", "sixteenth great grandfather",
|
|
|
|
"seventeenth great grandfather", "eightteenth great grandfather",
|
|
|
|
"ninetheen great grandfather", "twentieth great grandfather", ]
|
|
|
|
|
|
|
|
_mother_level = [ "", "mother", "grandmother", "great grandmother", "second great grandmother",
|
|
|
|
"third great grandmother", "fourth great grandmother",
|
|
|
|
"fifth great grandmother", "sixth great grandmother",
|
|
|
|
"seventh great grandmother", "eighth great grandmother",
|
|
|
|
"ninth great grandmother", "tenth great grandmother",
|
|
|
|
"eleventh great grandmother", "twelefth great grandmother",
|
|
|
|
"thirteenth great grandmother", "fourteenth great grandmother",
|
|
|
|
"fifteenth great grandmother", "sixteenth great grandmother",
|
|
|
|
"seventeenth great grandmother", "eightteenth great grandmother",
|
|
|
|
"ninetheen great grandmother", "twentieth great grandmother", ]
|
|
|
|
|
|
|
|
_son_level = [ "", "son", "grandson", "great grandson", "second great grandson",
|
|
|
|
"third great grandson", "fourth great grandson",
|
|
|
|
"fifth great grandson", "sixth great grandson",
|
|
|
|
"seventh great grandson", "eighth great grandson",
|
|
|
|
"ninth great grandson", "tenth great grandson",
|
|
|
|
"eleventh great grandson", "twelefth great grandson",
|
|
|
|
"thirteenth great grandson", "fourteenth great grandson",
|
|
|
|
"fifteenth great grandson", "sixteenth great grandson",
|
|
|
|
"seventeenth great grandson", "eightteenth great grandson",
|
|
|
|
"ninetheen great grandson", "twentieth great grandson", ]
|
|
|
|
|
|
|
|
_daughter_level = [ "", "daughter", "granddaughter", "great granddaughter",
|
|
|
|
"second great granddaughter",
|
|
|
|
"third great granddaughter", "fourth great granddaughter",
|
|
|
|
"fifth great granddaughter", "sixth great granddaughter",
|
|
|
|
"seventh great granddaughter", "eighth great granddaughter",
|
|
|
|
"ninth great granddaughter", "tenth great granddaughter",
|
|
|
|
"eleventh great granddaughter", "twelefth great granddaughter",
|
|
|
|
"thirteenth great granddaughter", "fourteenth great granddaughter",
|
|
|
|
"fifteenth great granddaughter", "sixteenth great granddaughter",
|
|
|
|
"seventeenth great granddaughter", "eightteenth great granddaughter",
|
|
|
|
"ninetheen great granddaughter", "twentieth great granddaughter", ]
|
|
|
|
|
|
|
|
_sister_level = [ "", "sister", "aunt", "grandaunt", "great grandaunt", "second great grandaunt",
|
|
|
|
"third great grandaunt", "fourth great grandaunt",
|
|
|
|
"fifth great grandaunt", "sixth great grandaunt",
|
|
|
|
"seventh great grandaunt", "eighth great grandaunt",
|
|
|
|
"ninth great grandaunt", "tenth great grandaunt",
|
|
|
|
"eleventh great grandaunt", "twelefth great grandaunt",
|
|
|
|
"thirteenth great grandaunt", "fourteenth great grandaunt",
|
|
|
|
"fifteenth great grandaunt", "sixteenth great grandaunt",
|
|
|
|
"seventeenth great grandaunt", "eightteenth great grandaunt",
|
|
|
|
"ninetheen great grandaunt", "twentieth great grandaunt", ]
|
|
|
|
|
|
|
|
_brother_level = [ "", "brother", "uncle", "granduncle", "great granduncle", "second great granduncle",
|
|
|
|
"third great granduncle", "fourth great granduncle",
|
|
|
|
"fifth great granduncle", "sixth great granduncle",
|
|
|
|
"seventh great granduncle", "eighth great granduncle",
|
|
|
|
"ninth great granduncle", "tenth great granduncle",
|
|
|
|
"eleventh great granduncle", "twelefth great granduncle",
|
|
|
|
"thirteenth great granduncle", "fourteenth great granduncle",
|
|
|
|
"fifteenth great granduncle", "sixteenth great granduncle",
|
|
|
|
"seventeenth great granduncle", "eightteenth great granduncle",
|
|
|
|
"ninetheen great granduncle", "twentieth great granduncle", ]
|
|
|
|
|
|
|
|
_nephew_level = [ "", "nephew", "grandnephew", "great grandnephew", "second great grandnephew",
|
|
|
|
"third great grandnephew", "fourth great grandnephew",
|
|
|
|
"fifth great grandnephew", "sixth great grandnephew",
|
|
|
|
"seventh great grandnephew", "eighth great grandnephew",
|
|
|
|
"ninth great grandnephew", "tenth great grandnephew",
|
|
|
|
"eleventh great grandnephew", "twelefth great grandnephew",
|
|
|
|
"thirteenth great grandnephew", "fourteenth great grandnephew",
|
|
|
|
"fifteenth great grandnephew", "sixteenth great grandnephew",
|
|
|
|
"seventeenth great grandnephew", "eightteenth great grandnephew",
|
|
|
|
"ninetheen great grandnephew", "twentieth great grandnephew", ]
|
|
|
|
|
|
|
|
_niece_level = [ "", "niece", "grandniece", "great grandniece", "second great grandniece",
|
|
|
|
"third great grandniece", "fourth great grandniece",
|
|
|
|
"fifth great grandniece", "sixth great grandniece",
|
|
|
|
"seventh great grandniece", "eighth great grandniece",
|
|
|
|
"ninth great grandniece", "tenth great grandniece",
|
|
|
|
"eleventh great grandniece", "twelefth great grandniece",
|
|
|
|
"thirteenth great grandniece", "fourteenth great grandniece",
|
|
|
|
"fifteenth great grandniece", "sixteenth great grandniece",
|
|
|
|
"seventeenth great grandniece", "eightteenth great grandniece",
|
|
|
|
"ninetheen great grandniece", "twentieth great grandniece", ]
|
2003-03-23 01:56:44 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-04-30 05:54:32 +05:30
|
|
|
def apply_filter(person,index,plist,pmap):
|
2003-03-23 01:56:44 +05:30
|
|
|
if person == None:
|
|
|
|
return
|
2003-04-30 05:54:32 +05:30
|
|
|
plist.append(person)
|
|
|
|
pmap[person.getId()] = index
|
2003-03-23 01:56:44 +05:30
|
|
|
|
|
|
|
family = person.getMainParents()
|
|
|
|
if family != None:
|
2003-04-30 05:54:32 +05:30
|
|
|
apply_filter(family.getFather(),index+1,plist,pmap)
|
|
|
|
apply_filter(family.getMother(),index+1,plist,pmap)
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
def get_cousin(level,removed):
|
|
|
|
return "%s cousin%s" % (_level_name[level],_removed_level[removed])
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
def get_father(level):
|
|
|
|
return _father_level[level]
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
def get_son(level):
|
|
|
|
return _son_level[level]
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
def get_mother(level):
|
|
|
|
return _mother_level[level]
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
def get_daughter(level):
|
|
|
|
return _daughter_level[level]
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
def get_aunt(level):
|
|
|
|
return _sister_level[level]
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
def get_uncle(level):
|
|
|
|
return _brother_level[level]
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
def get_nephew(level):
|
|
|
|
return _nephew_level[level]
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
def get_niece(level):
|
|
|
|
return _niece_level[level],f
|
2003-03-23 01:56:44 +05:30
|
|
|
|
2003-04-04 11:18:25 +05:30
|
|
|
def is_spouse(orig,other):
|
|
|
|
for f in orig.getFamilyList():
|
|
|
|
if other == f.getFather() or other == f.getMother():
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2003-03-23 01:56:44 +05:30
|
|
|
def get_relationship(orig_person,other_person):
|
2003-04-30 05:54:32 +05:30
|
|
|
"""
|
|
|
|
returns a string representing the relationshp between the two people,
|
|
|
|
along with a list of common ancestors (typically father,mother)
|
|
|
|
"""
|
2003-03-23 01:56:44 +05:30
|
|
|
firstMap = {}
|
|
|
|
firstList = []
|
|
|
|
secondMap = {}
|
|
|
|
secondList = []
|
|
|
|
common = []
|
|
|
|
rank = 9999999
|
|
|
|
|
2003-04-04 11:18:25 +05:30
|
|
|
if orig_person == None:
|
2003-04-30 09:51:04 +05:30
|
|
|
return ("undefined",[])
|
2003-04-04 11:18:25 +05:30
|
|
|
|
|
|
|
firstName = orig_person.getPrimaryName().getRegularName()
|
|
|
|
secondName = other_person.getPrimaryName().getRegularName()
|
|
|
|
|
|
|
|
if orig_person == other_person:
|
2003-04-30 05:54:32 +05:30
|
|
|
return ('', [])
|
2003-04-04 11:18:25 +05:30
|
|
|
if is_spouse(orig_person,other_person):
|
2003-04-30 05:54:32 +05:30
|
|
|
return ("spouse",[])
|
2003-04-04 11:18:25 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
apply_filter(orig_person,0,firstList,firstMap)
|
|
|
|
apply_filter(other_person,0,secondList,secondMap)
|
2003-03-23 01:56:44 +05:30
|
|
|
|
|
|
|
for person in firstList:
|
|
|
|
if person in secondList:
|
|
|
|
new_rank = firstMap[person.getId()]
|
|
|
|
if new_rank < rank:
|
|
|
|
rank = new_rank
|
|
|
|
common = [ person ]
|
|
|
|
elif new_rank == rank:
|
|
|
|
common.append(person)
|
|
|
|
|
|
|
|
firstRel = -1
|
|
|
|
secondRel = -1
|
|
|
|
|
|
|
|
length = len(common)
|
|
|
|
|
|
|
|
if length == 1:
|
|
|
|
person = common[0]
|
|
|
|
secondRel = firstMap[person.getId()]
|
|
|
|
firstRel = secondMap[person.getId()]
|
|
|
|
elif length == 2:
|
|
|
|
p1 = common[0]
|
|
|
|
secondRel = firstMap[p1.getId()]
|
|
|
|
firstRel = secondMap[p1.getId()]
|
|
|
|
elif length > 2:
|
|
|
|
person = common[0]
|
|
|
|
secondRel = firstMap[person.getId()]
|
|
|
|
firstRel = secondMap[person.getId()]
|
|
|
|
|
|
|
|
if firstRel == -1:
|
2003-04-30 05:54:32 +05:30
|
|
|
return ("",[])
|
2003-03-23 01:56:44 +05:30
|
|
|
elif firstRel == 0:
|
|
|
|
if secondRel == 0:
|
2003-04-30 05:54:32 +05:30
|
|
|
return ('',common)
|
2003-03-23 01:56:44 +05:30
|
|
|
elif other_person.getGender() == RelLib.Person.male:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_father(secondRel),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
else:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_mother(secondRel),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
elif secondRel == 0:
|
|
|
|
if other_person.getGender() == RelLib.Person.male:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_son(firstRel),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
else:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_daughter(firstRel),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
elif firstRel == 1:
|
|
|
|
if other_person.getGender() == RelLib.Person.male:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_uncle(secondRel),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
else:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_aunt(secondRel),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
elif secondRel == 1:
|
|
|
|
if other_person.getGender() == RelLib.Person.male:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_nephew(firstRel-1),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
else:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_niece(firstRel-1),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
else:
|
|
|
|
if secondRel > firstRel:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_cousin(firstRel-1,secondRel-firstRel),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
else:
|
2003-04-30 05:54:32 +05:30
|
|
|
return (get_cousin(secondRel-1,firstRel-secondRel),common)
|
2003-03-23 01:56:44 +05:30
|
|
|
|