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
# and on valuable input from Lars Kr. Lundin
"""
Specific classes for relationships.
"""
#-------------------------------------------------------------------------
#
# GRAMPS modules
@ -75,19 +77,22 @@ _niece_level = [ "", "niecen", "næstsøskendebarnet", "søsterens barnebarn", ]
#
#-------------------------------------------------------------------------
class RelationshipCalculator(Relationship.RelationshipCalculator):
"""
RelationshipCalculator Class
"""
def __init__(self):
Relationship.RelationshipCalculator.__init__(self)
def get_parents(self,level):
if level>len(_parents_level)-1:
def get_parents(self, level):
if level > len(_parents_level)-1:
#return "fjern forfader"
#Instead of "remote ancestors" using "tip (level) oldeforældre" here.
return "tip (%d) oldeforældre" % level
else:
return _parents_level[level]
def pair_up(self,rel_list):
def pair_up(self, rel_list):
result = []
item = ""
for word in rel_list[:]:
@ -108,7 +113,7 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
gen_result = [ item + 's' for item in result[0:-1] ]
return ' '.join(gen_result+result[-1:])
def get_direct_ancestor(self,person,rel_string):
def get_direct_ancestor(self, person, rel_string):
result = []
for ix in range(len(rel_string)):
if rel_string[ix] == 'f':
@ -117,9 +122,9 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
result.append('mor')
return self.pair_up(result)
def get_direct_descendant(self,person,rel_string):
def get_direct_descendant(self, person, rel_string):
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':
result.append('sønne')
else:
@ -130,19 +135,19 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
result.append('datter')
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 = []
for ix in range(len(second_rel_string)-1):
if second_rel_string[ix] == 'f':
result.append('far')
else:
result.append('mor')
if len(first_rel_string)>1:
if len(first_rel_string) > 1:
if first_rel_string[-2] == 'f':
result.append('bror')
else:
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':
result.append('sønne')
else:
@ -164,23 +169,23 @@ class RelationshipCalculator(Relationship.RelationshipCalculator):
common = ""
if not firstRel:
if not secondRel:
return ('',common)
return ('', common)
else:
return (self.get_direct_ancestor(other_person,secondRel),common)
return (self.get_direct_ancestor(other_person, secondRel), common)
elif not secondRel:
return (self.get_direct_descendant(other_person,firstRel),common)
return (self.get_direct_descendant(other_person, firstRel), common)
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,
reltocommon_a, reltocommon_b,
only_birth=True,
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,
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__":

View File

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

View File

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