svn: r13976
This commit is contained in:
Jérôme Rapinat 2010-01-05 19:15:51 +00:00
parent 9ae34b4ba8
commit d2876c8318
3 changed files with 104 additions and 89 deletions

View File

@ -25,7 +25,9 @@
# Written by Alex Roitman, largely based on Relationship.py by Don Allingham # Written by Alex Roitman, largely based on Relationship.py by Don Allingham
# and on valuable input from Lars Kr. Lundin # and on valuable input from Lars Kr. Lundin
"""
Specific classes for relationships.
"""
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
@ -75,19 +77,22 @@ _niece_level = [ "", "niecen", "næstsøskendebarnet", "søsterens barnebarn", ]
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class RelationshipCalculator(Relationship.RelationshipCalculator): class RelationshipCalculator(Relationship.RelationshipCalculator):
"""
RelationshipCalculator Class
"""
def __init__(self): def __init__(self):
Relationship.RelationshipCalculator.__init__(self) Relationship.RelationshipCalculator.__init__(self)
def get_parents(self,level): def get_parents(self, level):
if level>len(_parents_level)-1: if level > len(_parents_level)-1:
#return "fjern forfader" #return "fjern forfader"
#Instead of "remote ancestors" using "tip (level) oldeforældre" here. #Instead of "remote ancestors" using "tip (level) oldeforældre" here.
return "tip (%d) oldeforældre" % level return "tip (%d) oldeforældre" % level
else: else:
return _parents_level[level] return _parents_level[level]
def pair_up(self,rel_list): def pair_up(self, rel_list):
result = [] result = []
item = "" item = ""
for word in rel_list[:]: for word in rel_list[:]:
@ -108,7 +113,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
gen_result = [ item + 's' for item in result[0:-1] ] gen_result = [ item + 's' for item in result[0:-1] ]
return ' '.join(gen_result+result[-1:]) return ' '.join(gen_result+result[-1:])
def get_direct_ancestor(self,person,rel_string): def get_direct_ancestor(self, person, rel_string):
result = [] result = []
for ix in range(len(rel_string)): for ix in range(len(rel_string)):
if rel_string[ix] == 'f': if rel_string[ix] == 'f':
@ -117,9 +122,9 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
result.append('mor') result.append('mor')
return self.pair_up(result) return self.pair_up(result)
def get_direct_descendant(self,person,rel_string): def get_direct_descendant(self, person, rel_string):
result = [] result = []
for ix in range(len(rel_string)-2,-1,-1): for ix in range(len(rel_string)-2, -1, -1):
if rel_string[ix] == 'f': if rel_string[ix] == 'f':
result.append('sønne') result.append('sønne')
else: else:
@ -130,19 +135,19 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
result.append('datter') result.append('datter')
return self.pair_up(result) return self.pair_up(result)
def get_two_way_rel(self,person,first_rel_string,second_rel_string): def get_two_way_rel(self, person, first_rel_string, second_rel_string):
result = [] result = []
for ix in range(len(second_rel_string)-1): for ix in range(len(second_rel_string)-1):
if second_rel_string[ix] == 'f': if second_rel_string[ix] == 'f':
result.append('far') result.append('far')
else: else:
result.append('mor') result.append('mor')
if len(first_rel_string)>1: if len(first_rel_string) > 1:
if first_rel_string[-2] == 'f': if first_rel_string[-2] == 'f':
result.append('bror') result.append('bror')
else: else:
result.append('søster') result.append('søster')
for ix in range(len(first_rel_string)-3,-1,-1): for ix in range(len(first_rel_string)-3, -1, -1):
if first_rel_string[ix] == 'f': if first_rel_string[ix] == 'f':
result.append('sønne') result.append('sønne')
else: else:
@ -164,23 +169,23 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
common = "" common = ""
if not firstRel: if not firstRel:
if not secondRel: if not secondRel:
return ('',common) return ('', common)
else: else:
return (self.get_direct_ancestor(other_person,secondRel),common) return (self.get_direct_ancestor(other_person, secondRel), common)
elif not secondRel: elif not secondRel:
return (self.get_direct_descendant(other_person,firstRel),common) return (self.get_direct_descendant(other_person, firstRel), common)
else: else:
return (self.get_two_way_rel(other_person,firstRel,secondRel),common) return (self.get_two_way_rel(other_person, firstRel, secondRel), common)
def get_single_relationship_string(self, Ga, Gb, gender_a, gender_b, def get_single_relationship_string(self, Ga, Gb, gender_a, gender_b,
reltocommon_a, reltocommon_b, reltocommon_a, reltocommon_b,
only_birth=True, only_birth=True,
in_law_a=False, in_law_b=False): in_law_a=False, in_law_b=False):
return self.get_relationship(reltocommon_a, reltocommon_b, gender_a, gender_b)[0]; return self.get_relationship(reltocommon_a, reltocommon_b, gender_a, gender_b)[0]
def get_sibling_relationship_string(self, sib_type, gender_a, gender_b, def get_sibling_relationship_string(self, sib_type, gender_a, gender_b,
in_law_a=False, in_law_b=False): in_law_a=False, in_law_b=False):
return self.get_two_way_rel(gender_b,"","") return self.get_two_way_rel(gender_b, "", "")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -29,7 +29,9 @@
# http://de.wikipedia.org/wiki/Verwandtschaftsbeziehung # http://de.wikipedia.org/wiki/Verwandtschaftsbeziehung
# Rewritten from scratch for GRAMPS 3 by Stefan Siegel, # Rewritten from scratch for GRAMPS 3 by Stefan Siegel,
# loosely based on rel_fr.py # loosely based on rel_fr.py
"""
German-specific classes for relationships.
"""
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# standard python modules # standard python modules
@ -126,6 +128,9 @@ _schwippschwager = {
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class RelationshipCalculator(Relationship.RelationshipCalculator): class RelationshipCalculator(Relationship.RelationshipCalculator):
"""
RelationshipCalculator Class
"""
def __init__(self): def __init__(self):
Relationship.RelationshipCalculator.__init__(self) Relationship.RelationshipCalculator.__init__(self)

View File

@ -23,7 +23,9 @@
# Written by Julio Sanchez <julio.sanchez@gmail.com> # Written by Julio Sanchez <julio.sanchez@gmail.com>
# $Id$ # $Id$
"""
Spanish-specific classes for relationships.
"""
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
@ -117,215 +119,218 @@ _niece_level = [ "", "sobrina", "sobrina nieta", "sobrina bisnieta", ]
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class RelationshipCalculator(Relationship.RelationshipCalculator): class RelationshipCalculator(Relationship.RelationshipCalculator):
"""
RelationshipCalculator Class
"""
def __init__(self): def __init__(self):
Relationship.RelationshipCalculator.__init__(self) Relationship.RelationshipCalculator.__init__(self)
def get_male_cousin(self,level): def get_male_cousin(self, level):
if level<len(_level_name_male): if level < len(_level_name_male):
return "primo %s" % (_level_name_male[level]) return "primo %s" % (_level_name_male[level])
else: else:
return "primo %d-ésimo" % level return "primo %d-ésimo" % level
def get_female_cousin(self,level): def get_female_cousin(self, level):
if level<len(_level_name_female): if level < len(_level_name_female):
return "prima %s" % (_level_name_female[level]) return "prima %s" % (_level_name_female[level])
else: else:
return "prima %d-ésima" % level return "prima %d-ésima" % level
def get_distant_uncle(self,level): def get_distant_uncle(self, level):
if level<len(_level_name_male): if level < len(_level_name_male):
return "tío %s" % (_level_name_male[level]) return "tío %s" % (_level_name_male[level])
else: else:
return "tío %d-ésimo" % level return "tío %d-ésimo" % level
def get_distant_aunt(self,level): def get_distant_aunt(self, level):
if level<len(_level_name_female): if level < len(_level_name_female):
return "tía %s" % (_level_name_female[level]) return "tía %s" % (_level_name_female[level])
else: else:
return "tía %d-ésima" % level return "tía %d-ésima" % level
def get_distant_nephew(self,level): def get_distant_nephew(self, level):
if level<len(_level_name_male): if level < len(_level_name_male):
return "sobrino %s" % (_level_name_male[level]) return "sobrino %s" % (_level_name_male[level])
else: else:
return "sobrino %d-ésimo" % level return "sobrino %d-ésimo" % level
def get_distant_nieve(self,level): def get_distant_nieve(self, level):
if level<len(_level_name_female): if level < len(_level_name_female):
return "sobrina %s" % (_level_name_female[level]) return "sobrina %s" % (_level_name_female[level])
else: else:
return "sobrina %d-ésima" % level return "sobrina %d-ésima" % level
def get_male_relative(self,level1,level2): def get_male_relative(self, level1, level2):
if level1<len(_level_name_male_a): if level1 < len(_level_name_male_a):
level1_str = _level_name_male_a[level1] level1_str = _level_name_male_a[level1]
else: else:
level1_str = "%d-ésimo" % level1 level1_str = "%d-ésimo" % level1
if level2<len(_level_name_male_a): if level2 < len(_level_name_male_a):
level2_str = _level_name_male_a[level2] level2_str = _level_name_male_a[level2]
else: else:
level2_str = "%d-ésimo" % level2 level2_str = "%d-ésimo" % level2
level = level1 + level2 level = level1 + level2
if level<len(_level_name_male_a): if level < len(_level_name_male_a):
level_str = _level_name_male_a[level] level_str = _level_name_male_a[level]
else: else:
level_str = "%d-ésimo" % level level_str = "%d-ésimo" % level
return "pariente en %s grado (%s con %s)" % (level_str,level1_str,level2_str) return "pariente en %s grado (%s con %s)" % (level_str, level1_str, level2_str)
def get_female_relative(self,level1,level2): def get_female_relative(self, level1, level2):
return self.get_male_relative(level1,level2) return self.get_male_relative(level1, level2)
def get_parents(self,level): def get_parents(self, level):
if level<len(_parents_level): if level < len(_parents_level):
return _parents_level[level] return _parents_level[level]
elif (level-1)<len(_level_name_plural): elif (level-1) < len(_level_name_plural):
return "%s abuelos" % (_level_name_plural[level-1]) return "%s abuelos" % (_level_name_plural[level-1])
else: else:
return "%d-ésimos abuelos" % (level-1) return "%d-ésimos abuelos" % (level-1)
def get_father(self,level): def get_father(self, level):
if level<len(_father_level): if level < len(_father_level):
return _father_level[level] return _father_level[level]
elif (level-1)<len(_level_name_male_a): elif (level-1) < len(_level_name_male_a):
return "%s abuelo" % (_level_name_male_a[level-1]) return "%s abuelo" % (_level_name_male_a[level-1])
else: else:
return "%d-ésimo abuelo" % (level-1) return "%d-ésimo abuelo" % (level-1)
def get_son(self,level): def get_son(self, level):
if level<len(_son_level): if level < len(_son_level):
return _son_level[level] return _son_level[level]
elif (level-1)<len(_level_name_male_a): elif (level-1) < len(_level_name_male_a):
return "%s nieto" % (_level_name_male_a[level-1]) return "%s nieto" % (_level_name_male_a[level-1])
else: else:
return "%d-ésimo nieto" % (level-1) return "%d-ésimo nieto" % (level-1)
def get_mother(self,level): def get_mother(self, level):
if level<len(_mother_level): if level < len(_mother_level):
return _mother_level[level] return _mother_level[level]
elif (level-1)<len(_level_name_female): elif (level-1) < len(_level_name_female):
return "%s abuela" % (_level_name_female[level-1]) return "%s abuela" % (_level_name_female[level-1])
else: else:
return "%d-ésima abuela" % (level-1) return "%d-ésima abuela" % (level-1)
def get_daughter(self,level): def get_daughter(self, level):
if level<len(_daughter_level): if level < len(_daughter_level):
return _daughter_level[level] return _daughter_level[level]
elif (level-1)<len(_level_name_female): elif (level-1) < len(_level_name_female):
return "%s nieta" % (_level_name_female[level-1]) return "%s nieta" % (_level_name_female[level-1])
else: else:
return "%d-ésima nieta" % (level-1) return "%d-ésima nieta" % (level-1)
def get_aunt(self,level): def get_aunt(self, level):
if level<len(_sister_level): if level < len(_sister_level):
return _sister_level[level] return _sister_level[level]
elif (level-2)<len(_level_name_female): elif (level-2) < len(_level_name_female):
return "%s tía abuela" % (_level_name_female[level-2]) return "%s tía abuela" % (_level_name_female[level-2])
else: else:
return "%d-ésima tía abuela" % (level-2) return "%d-ésima tía abuela" % (level-2)
def get_uncle(self,level): def get_uncle(self, level):
if level<len(_brother_level): if level < len(_brother_level):
return _brother_level[level] return _brother_level[level]
elif (level-2)<len(_level_name_male_a): elif (level-2) < len(_level_name_male_a):
return "%s tío abuelo" % (_level_name_male_a[level-2]) return "%s tío abuelo" % (_level_name_male_a[level-2])
else: else:
return "%d-ésimo tío abuelo" % (level-2) return "%d-ésimo tío abuelo" % (level-2)
def get_nephew(self,level): def get_nephew(self, level):
if level<len(_nephew_level): if level < len(_nephew_level):
return _nephew_level[level] return _nephew_level[level]
elif (level-1)<len(_level_name_male_a): elif (level-1) < len(_level_name_male_a):
return "%s sobrino nieto" % (_level_name_male_a[level-1]) return "%s sobrino nieto" % (_level_name_male_a[level-1])
else: else:
return "%d-ésimo sobrino nieto" % (level-1) return "%d-ésimo sobrino nieto" % (level-1)
def get_niece(self,level): def get_niece(self, level):
if level<len(_niece_level): if level < len(_niece_level):
return _niece_level[level] return _niece_level[level]
elif (level-1)<len(_level_name_female): elif (level-1) < len(_level_name_female):
return "%s sobrina nieta" % (_level_name_female[level-1]) return "%s sobrina nieta" % (_level_name_female[level-1])
else: else:
return "%d-ésima sobrina nieta" % (level-1) return "%d-ésima sobrina nieta" % (level-1)
def get_relationship(self,db, orig_person, other_person): def get_relationship(self, db, orig_person, other_person):
""" """
returns a string representing the relationshp between the two people, returns a string representing the relationshp between the two people,
along with a list of common ancestors (typically father,mother) along with a list of common ancestors (typically father,mother)
""" """
if orig_person is None: if orig_person is None:
return ("undefined",[]) return ("undefined", [])
if orig_person.get_handle() == other_person.get_handle(): if orig_person.get_handle() == other_person.get_handle():
return ('', []) return ('', [])
is_spouse = self.is_spouse(db, orig_person, other_person) is_spouse = self.is_spouse(db, orig_person, other_person)
if is_spouse: if is_spouse:
return (is_spouse,[]) return (is_spouse, [])
#get_relationship_distance changed, first data is relation to #get_relationship_distance changed, first data is relation to
#orig person, apperently secondRel in this function #orig person, apperently secondRel in this function
(secondRel,firstRel,common) = \ (secondRel, firstRel, common) = \
self.get_relationship_distance(db, orig_person, other_person) self.get_relationship_distance(db, orig_person, other_person)
if isinstance(common, basestring): if isinstance(common, basestring):
return (common,[]) return (common, [])
elif common: elif common:
person_handle = common[0] person_handle = common[0]
else: else:
return ("",[]) return ("", [])
firstRel = len(firstRel) firstRel = len(firstRel)
secondRel = len(secondRel) secondRel = len(secondRel)
if firstRel == 0: if firstRel == 0:
if secondRel == 0: if secondRel == 0:
return ('',common) return ('', common)
elif other_person.get_gender() == gen.lib.Person.MALE: elif other_person.get_gender() == gen.lib.Person.MALE:
return (self.get_father(secondRel),common) return (self.get_father(secondRel), common)
else: else:
return (self.get_mother(secondRel),common) return (self.get_mother(secondRel), common)
elif secondRel == 0: elif secondRel == 0:
if other_person.get_gender() == gen.lib.Person.MALE: if other_person.get_gender() == gen.lib.Person.MALE:
return (self.get_son(firstRel),common) return (self.get_son(firstRel), common)
else: else:
return (self.get_daughter(firstRel),common) return (self.get_daughter(firstRel), common)
elif firstRel == 1: elif firstRel == 1:
if other_person.get_gender() == gen.lib.Person.MALE: if other_person.get_gender() == gen.lib.Person.MALE:
return (self.get_uncle(secondRel),common) return (self.get_uncle(secondRel), common)
else: else:
return (self.get_aunt(secondRel),common) return (self.get_aunt(secondRel), common)
elif secondRel == 1: elif secondRel == 1:
if other_person.get_gender() == gen.lib.Person.MALE: if other_person.get_gender() == gen.lib.Person.MALE:
return (self.get_nephew(firstRel-1),common) return (self.get_nephew(firstRel-1), common)
else: else:
return (self.get_niece(firstRel-1),common) return (self.get_niece(firstRel-1), common)
elif firstRel == secondRel == 2: elif firstRel == secondRel == 2:
if other_person.get_gender() == gen.lib.Person.MALE: if other_person.get_gender() == gen.lib.Person.MALE:
return ('primo hermano',common) return ('primo hermano', common)
else: else:
return ('prima hermana',common) return ('prima hermana', common)
elif firstRel == secondRel: elif firstRel == secondRel:
if other_person.get_gender() == gen.lib.Person.MALE: if other_person.get_gender() == gen.lib.Person.MALE:
return (self.get_male_cousin(firstRel-1),common) return (self.get_male_cousin(firstRel-1), common)
else: else:
return (self.get_female_cousin(firstRel-1),common) return (self.get_female_cousin(firstRel-1), common)
elif firstRel == secondRel+1: elif firstRel == secondRel+1:
if other_person.get_gender() == gen.lib.Person.MALE: if other_person.get_gender() == gen.lib.Person.MALE:
return (self.get_distant_nephew(secondRel),common) return (self.get_distant_nephew(secondRel), common)
else: else:
return (self.get_distant_niece(secondRel),common) return (self.get_distant_niece(secondRel), common)
elif firstRel+1 == secondRel: elif firstRel+1 == secondRel:
if other_person.get_gender() == gen.lib.Person.MALE: if other_person.get_gender() == gen.lib.Person.MALE:
return (self.get_distant_uncle(firstRel),common) return (self.get_distant_uncle(firstRel), common)
else: else:
return (self.get_distant_aunt(firstRel),common) return (self.get_distant_aunt(firstRel), common)
else: else:
if other_person.get_gender() == gen.lib.Person.MALE: if other_person.get_gender() == gen.lib.Person.MALE:
return (self.get_male_relative(firstRel,secondRel),common) return (self.get_male_relative(firstRel, secondRel), common)
else: else:
return (self.get_female_relative(firstRel,secondRel),common) return (self.get_female_relative(firstRel, secondRel), common)
if __name__ == "__main__": if __name__ == "__main__":