diff --git a/ChangeLog b/ChangeLog index 4893c5e86..93547af9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2004-08-20 Alex Roitman + * src/plugins/rel_da.py: Convert to new interface. Add to CVS. + * src/plugins/rel_fi.py: Convert to new interface. Add to CVS. + * src/plugins/rel_fr.py: Convert to new interface. Add to CVS. + * src/plugins/rel_no.py: Convert to new interface. Add to CVS. + * src/plugins/rel_sv.py: Convert to new interface. Add to CVS. + * src/plugins/Makefile.am: Ship new files. + * src/Relationship.py (apply_filter): Keep gender info of all + member in the relationship chain, not just number of generations; + (is_spouse): correctly compare handles; (get_relationship_distance, + get_relationship, get_grandparents_string): correctly use apply_filter. + * src/plugins/rel_it.py (get_relationship): Correctly use apply_filter. + * src/plugins/rel_hu.py (get_relationship): Correctly use apply_filter. + * src/plugins/rel_de.py (is_spouse): Remove function; + (get_relationship): Correctly use apply_filter. + * src/plugins/rel_ru.py (is_spouse): Remove function; + (get_relationship): Correctly use apply_filter. + 2004-08-20 Tim Waugh * src/RelLib.py (Event.are_equal): Fixed comparison with None. diff --git a/src/Relationship.py b/src/Relationship.py index b6a85ed82..378a36574 100644 --- a/src/Relationship.py +++ b/src/Relationship.py @@ -163,19 +163,19 @@ class RelationshipCalculator: def set_db(self,db): self.db = db - def apply_filter(self,person,index,plist,pmap): + def apply_filter(self,person,rel_str,plist,pmap): if person == None: return plist.append(person.get_handle()) - pmap[person.get_handle()] = index + pmap[person.get_handle()] = rel_str family_handle = person.get_main_parents_family_handle() if family_handle != None: family = self.db.get_family_from_handle(family_handle) father = self.db.get_person_from_handle(family.get_father_handle()) mother = self.db.get_person_from_handle(family.get_mother_handle()) - self.apply_filter(father,index+1,plist,pmap) - self.apply_filter(mother,index+1,plist,pmap) + self.apply_filter(father,rel_str+'f',plist,pmap) + self.apply_filter(mother,rel_str+'m',plist,pmap) def get_cousin(self,level,removed): if removed > len(_removed_level)-1 or level>len(_level_name)-1: @@ -241,7 +241,7 @@ class RelationshipCalculator: for f in orig.get_family_handle_list(): family = self.db.get_family_from_handle(f) if family: - if other == family.get_father_handle() or other == family.get_mother_handle(): + if other.get_handle() == family.get_father_handle() or other.get_handle() == family.get_mother_handle(): return 1 else: return 0 @@ -271,14 +271,14 @@ class RelationshipCalculator: rank = 9999999 try: - self.apply_filter(orig_person,0,firstList,firstMap) - self.apply_filter(other_person,0,secondList,secondMap) + self.apply_filter(orig_person,'',firstList,firstMap) + self.apply_filter(other_person,'',secondList,secondMap) except RuntimeError: return (firstRel,secondRel,_("Relationship loop detected")) for person_handle in firstList: if person_handle in secondList: - new_rank = firstMap[person_handle] + new_rank = len(firstMap[person_handle]) if new_rank < rank: rank = new_rank common = [ person_handle ] @@ -316,6 +316,9 @@ class RelationshipCalculator: else: return ("",[]) + firstRel = len(firstRel) + secondRel = len(secondRel) + if firstRel == 0: if secondRel == 0: return ('',common) @@ -365,10 +368,10 @@ class RelationshipCalculator: else: return ("",[]) - if firstRel == 0: - if secondRel == 0: + if len(firstRel) == 0: + if len(secondRel) == 0: return ('',common) else: - return (self.get_parents(secondRel),common) + return (self.get_parents(len(secondRel)),common) else: return None diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 3dfc17117..43cdd93b7 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -50,7 +50,12 @@ pkgdata_PYTHON = \ RelGraph.py\ rel_it.py\ rel_hu.py\ - rel_de.py + rel_da.py\ + rel_de.py\ + rel_fi.py\ + rel_fr.py\ + rel_no.py\ + rel_sv.py pkgpyexecdir = @pkgpyexecdir@/plugins pkgpythondir = @pkgpythondir@/plugins diff --git a/src/plugins/rel_da.py b/src/plugins/rel_da.py new file mode 100644 index 000000000..120493450 --- /dev/null +++ b/src/plugins/rel_da.py @@ -0,0 +1,184 @@ +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2003-2004 Donald N. Allingham +# +# 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 +# + +# $Id$ + +# Written by Alex Roitman, largely based on Relationship.py by Don Allingham +# and on valuable input from Lars Kr. Lundin + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- + +import RelLib +import Relationship +import types +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# Danish-specific definitions of relationships +# +#------------------------------------------------------------------------- + +_parents_level = [ "forældre", "bedsteforældre", "oldeforældre", +"tipoldeforældre", "tiptipoldeforældre" , "tiptiptipoldeforældre" ] + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +class RelationshipCalculator(Relationship.RelationshipCalculator): + + def __init__(self,db): + Relationship.RelationshipCalculator.__init__(self,db) + + 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): + result = [] + item = "" + for word in rel_list[:]: + if not word: + continue + if item: + if word == 'søster': + item = item[0:-1] + word = 'ster' + elif word == 'sønne': + word = 'søn' + result.append(item + word) + item = "" + else: + item = word + if item: + result.append(item) + gen_result = [ item + 's' for item in result[0:-1] ] + return ' '.join(gen_result+result[-1:]) + + def get_direct_ancestor(self,person,rel_string): + result = [] + for ix in range(len(rel_string)): + if rel_string[ix] == 'f': + result.append('far') + else: + result.append('mor') + return self.pair_up(result) + + def get_direct_descendant(self,person,rel_string): + result = [] + for ix in range(len(rel_string)-2,-1,-1): + if rel_string[ix] == 'f': + result.append('sønne') + else: + result.append('datter') + if person.get_gender() == RelLib.Person.male: + result.append('søn') + else: + result.append('datter') + return self.pair_up(result) + + 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 first_rel_string[-2] == 'f': + result.append('bror') + else: + result.append('søster') + for ix in range(len(first_rel_string)-3,-1,-1): + if first_rel_string[ix] == 'f': + result.append('sønne') + else: + result.append('datter') + if person.get_gender() == RelLib.Person.male: + result.append('søn') + else: + result.append('datter') + else: + if person.get_gender() == RelLib.Person.male: + result.append('bror') + else: + result.append('søster') + return self.pair_up(result) + + def get_relationship(self,orig_person,other_person): + """ + Returns a string representing the relationshp between the two people, + along with a list of common ancestors (typically father,mother) + + Special cases: relation strings "", "undefined" and "spouse". + """ + + if orig_person == None: + return ("undefined",[]) + + if orig_person == other_person: + return ('', []) + + if self.is_spouse(orig_person,other_person): + if other_person.get_gender() == RelLib.Person.male: + return ("ægtefælle",[]) + else: + return ("hustru",[]) + + (firstRel,secondRel,common) = self.get_relationship_distance(orig_person,other_person) + + if type(common) == types.StringType or type(common) == types.UnicodeType: + return (common,[]) + elif common: + person_handle = common[0] + else: + return ("",[]) + + if not firstRel: + if not secondRel: + return ('',common) + else: + return (self.get_direct_ancestor(other_person,secondRel),common) + elif not secondRel: + return (self.get_direct_descendant(other_person,firstRel),common) + else: + return (self.get_two_way_rel(other_person,firstRel,secondRel),common) + +#------------------------------------------------------------------------- +# +# Register this class with the Plugins system +# +#------------------------------------------------------------------------- +from Plugins import register_relcalc + +register_relcalc(RelationshipCalculator, + ["da","DA","da_DK","danish","Danish","da_DK.UTF8","da_DK@euro","da_DK.UTF8@euro", + "dansk","Dansk", "da_DK.UTF-8", "da_DK.utf-8", "da_DK.utf8"]) diff --git a/src/plugins/rel_de.py b/src/plugins/rel_de.py index f3b8c6d52..3a61b3b8f 100644 --- a/src/plugins/rel_de.py +++ b/src/plugins/rel_de.py @@ -21,10 +21,8 @@ # $Id$ -# # Written by Alex Roitman, largely based on Relationship.py by Don Allingham. # and on valuable input from Dr. Martin Senftleben -# #------------------------------------------------------------------------- # @@ -326,14 +324,6 @@ class RelationshipCalculator(Relationship.RelationshipCalculator): else: return _niece_level[level] - def is_spouse(self,orig,other): - for f in orig.get_family_handle_list(): - family = self.db.get_family_from_handle(f) - if family: - if other == family.get_father_handle() or other == family.get_mother_handle(): - return 1 - return 0 - def get_relationship(self,orig_person,other_person): """ Returns a string representing the relationshp between the two people, @@ -360,6 +350,9 @@ class RelationshipCalculator(Relationship.RelationshipCalculator): else: return ("",[]) + firstRel = len(firstRel) + secondRel = len(secondRel) + if firstRel == 0: if secondRel == 0: return ('',common) diff --git a/src/plugins/rel_fi.py b/src/plugins/rel_fi.py new file mode 100644 index 000000000..9f2a95069 --- /dev/null +++ b/src/plugins/rel_fi.py @@ -0,0 +1,223 @@ +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2003-2004 Donald N. Allingham +# +# 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 +# + +# $Id$ + +# Written by Alex Roitman, largely based on Relationship.py by Don Allingham +# and on valuable input from Eero Tamminen + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- + +import RelLib +import Relationship +import types +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# Finnish-specific definitions of relationships +# +#------------------------------------------------------------------------- + +_parents_level = [ "", "vanhemmat", "isovanhemmat", "isoisovanhemmat", +"isoisoisovanhemmat", "isoisoisoisovanhemmat" ] + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +class RelationshipCalculator(Relationship.RelationshipCalculator): + + def __init__(self,db): + Relationship.RelationshipCalculator.__init__(self,db) + + def get_cousin(self,level): + if level == 0: + return "" + elif level == 1: + return "serkku" + elif level == 2: + return "pikkuserkku" + elif level > 2: + return "%d. serkku" % level + + def get_cousin_genitive(self,level): + if level == 0: + return "" + elif level == 1: + return "serkun" + elif level == 2: + return "pikkuserkun" + elif level > 2: + return "%d. serkun" % level + + def get_parents(self,level): + if level>len(_parents_level)-1: + return "kaukaiset esivanhemmat" + else: + return _parents_level[level] + + def get_direct_ancestor(self,person,rel_string): + result = [] + for ix in range(len(rel_string)-1): + if rel_string[ix] == 'f': + result.append('isän') + else: + result.append('äidin') + if person.get_gender() == RelLib.Person.male: + result.append('isä') + else: + result.append('äiti') + return ' '.join(result) + + def get_direct_descendant(self,person,rel_string): + result = [] + for ix in range(len(rel_string)-2,-1,-1): + if rel_string[ix] == 'f': + result.append('pojan') + elif rel_string[ix] == 'm': + result.append('tyttären') + else: + result.append('lapsen') + if person.get_gender() == RelLib.Person.male: + result.append('poika') + elif person.get_gender() == RelLib.Person.female: + result.append('tytär') + else: + result.append('lapsi') + return ' '.join(result) + + def get_ancestors_cousin(self,rel_string_long,rel_string_short): + result = [] + removed = len(rel_string_long)-len(rel_string_short) + level = len(rel_string_short)-1 + for ix in range(removed): + if rel_string_long[ix] == 'f': + result.append('isän') + else: + result.append('äidin') + result.append(self.get_cousin(level)) + return ' '.join(result) + + def get_cousins_descendant(self,person,rel_string_long,rel_string_short): + result = [] + removed = len(rel_string_long)-len(rel_string_short)-1 + level = len(rel_string_short)-1 + if level: + result.append(self.get_cousin_genitive(level)) + elif rel_string_long[removed] == 'f': + result.append('veljen') + else: + result.append('sisaren') + for ix in range(removed-1,-1,-1): + if rel_string_long[ix] == 'f': + result.append('pojan') + elif rel_string_long[ix] == 'm': + result.append('tyttären') + else: + result.append('lapsen') + if person.get_gender() == RelLib.Person.male: + result.append('poika') + elif person.get_gender() == RelLib.Person.female: + result.append('tytär') + else: + result.append('lapsi') + return ' '.join(result) + + def get_ancestors_brother(self,rel_string): + result = [] + for ix in range(len(rel_string)-1): + if rel_string[ix] == 'f': + result.append('isän') + else: + result.append('äidin') + result.append('veli') + return ' '.join(result) + + def get_ancestors_sister(self,rel_string): + result = [] + for ix in range(len(rel_string)-1): + if rel_string[ix] == 'f': + result.append('isän') + else: + result.append('äidin') + result.append('sisar') + return ' '.join(result) + + + def get_relationship(self,orig_person,other_person): + """ + Returns a string representing the relationshp between the two people, + along with a list of common ancestors (typically father,mother) + + Special cases: relation strings "", "undefined" and "spouse". + """ + + if orig_person == None: + return ("undefined",[]) + + if orig_person == other_person: + return ('', []) + + if self.is_spouse(orig_person,other_person): + return ("puoliso",[]) + + (firstRel,secondRel,common) = self.get_relationship_distance(orig_person,other_person) + + if type(common) == types.StringType or type(common) == types.UnicodeType: + return (common,[]) + elif common: + person_handle = common[0] + else: + return ("",[]) + + if not firstRel: + if not secondRel: + return ('',common) + else: + return (self.get_direct_ancestor(other_person,secondRel),common) + elif not secondRel: + return (self.get_direct_descendant(other_person,firstRel),common) + elif len(firstRel) == 1: + if other_person.get_gender() == RelLib.Person.male: + return (self.get_ancestors_brother(secondRel),common) + else: + return (self.get_ancestors_sister(secondRel),common) + elif len(secondRel) >= len(firstRel): + return (self.get_ancestors_cousin(secondRel,firstRel),common) + else: + return (self.get_cousins_descendant(other_person,firstRel,secondRel),common) + +#------------------------------------------------------------------------- +# +# Register this class with the Plugins system +# +#------------------------------------------------------------------------- +from Plugins import register_relcalc + +register_relcalc(RelationshipCalculator, + ["fi","FI","fi_FI","finnish","Finnish","fi_FI.UTF8","fi_FI@euro","fi_FI.UTF8@euro", + "suomi","Suomi", "fi_FI.UTF-8", "fi_FI.utf-8", "fi_FI.utf8"]) diff --git a/src/plugins/rel_fr.py b/src/plugins/rel_fr.py new file mode 100644 index 000000000..5bede2f1e --- /dev/null +++ b/src/plugins/rel_fr.py @@ -0,0 +1,225 @@ +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2003-2004 Donald N. Allingham +# +# 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 +# + +# $Id$ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- + +import RelLib +import Relationship +import types +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- + +_level_name = [ "", "premier", "deuxième", "troisième", "quatrième", "cinquième", "sixième", + "septième", "huitième", "neuvième", "dicième", "onzième", "douzième", + "treizième", "quatorzième", "quinzième", "seizième", + "dix-septième", "dix-huitième", "dix_neuvième", "vingtième", ] + +_parents_level = [ "", "parents", "grand-parents", "arrières grand-parents", + "trisaïeux", ] + +_father_level = [ "", "le père", "le grand-père", "l'arrière grand-père", "le trisaïeul", ] + +_mother_level = [ "", "la mère", "la grand-mère", "l'arrière grand-mère", "la trisaïeule", ] + +_son_level = [ "", "le fils", "le petits-fils", "l'arrière petit-fils", ] + +_daughter_level = [ "", "la fille", "la petite-fille", "l'arrière petite-fille", ] + +_sister_level = [ "", "la soeur", "la tante", "la grande-tante", "l'arrière grande-tante", ] + +_brother_level = [ "", "le frère", "l'oncle", "le grand-oncle", "l'arrière grand-oncle", ] + +_nephew_level = [ "", "le neveu", "le petit-neveu", "l'arrière petit-neveu", ] + +_niece_level = [ "", "la nièce", "la petite-nièce", "l'arrière petite-nièce", ] + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +class RelationshipCalculator(Relationship.RelationshipCalculator): + + def __init__(self,db): + Relationship.RelationshipCalculator.__init__(self,db) + + def get_male_cousin(self,level): + return "cousin au %s degré" % (_level_name[level]) + + def get_female_cousin(self,level): + return "cousine au %s degré" % (_level_name[level]) + + def get_parents(self,level): + if level>len(_parents_level)-1: + return "ancêtres lointains" + else: + return _parents_level[level] + + def get_father(self,level): + if level>len(_father_level)-1: + return "ancêtre lointain" + else: + return _father_level[level] + + def get_son(self,level): + if level>len(_son_level)-1: + return "descendant lointain" + else: + return _son_level[level] + + def get_mother(self,level): + if level>len(_mother_level)-1: + return "ancêtre lointaine" + else: + return _mother_level[level] + + def get_daughter(self,level): + if level>len(_daughter_level)-1: + return "descendante lointaine" + else: + return _daughter_level[level] + + def get_aunt(self,level): + if level>len(_sister_level)-1: + return "ancêtre lointaine" + else: + return _sister_level[level] + + def get_uncle(self,level): + if level>len(_brother_level)-1: + return "ancêtre lointain" + else: + return _brother_level[level] + + def get_nephew(self,level): + if level>len(_nephew_level)-1: + return "descendant lointain" + else: + return _nephew_level[level] + + def get_niece(self,level): + if level>len(_niece_level)-1: + return "descendant lointaine" + else: + return _niece_level[level] + + def get_relationship(self,orig_person,other_person): + """ + Returns a string representing the relationshp between the two people, + along with a list of common ancestors (typically father,mother) + + Special cases: relation strings "", "undefined" and "spouse". + """ + + if orig_person == None: + return ("undefined",[]) + + if orig_person == other_person: + return ('', []) + + if self.is_spouse(orig_person,other_person): + if other_person.get_gender() == RelLib.Person.male: + return ("le mari",[]) + else: + return ("la femme",[]) + + (firstRel,secondRel,common) = self.get_relationship_distance(orig_person,other_person) + + if type(common) == types.StringType or type(common) == types.UnicodeType: + return (common,[]) + elif common: + person_handle = common[0] + else: + return ("",[]) + + firstRel = len(firstRel) + secondRel = len(secondRel) + + if firstRel == 0: + if secondRel == 0: + return ('',common) + elif other_person.get_gender() == RelLib.Person.male: + return (self.get_father(secondRel),common) + else: + return (self.get_mother(secondRel),common) + elif secondRel == 0: + if other_person.get_gender() == RelLib.Person.male: + return (self.get_son(firstRel),common) + else: + return (self.get_daughter(firstRel),common) + elif firstRel == 1: + if other_person.get_gender() == RelLib.Person.male: + return (self.get_uncle(secondRel),common) + else: + return (self.get_aunt(secondRel),common) + elif secondRel == 1: + if other_person.get_gender() == RelLib.Person.male: + return (self.get_nephew(firstRel-1),common) + else: + return (self.get_niece(firstRel-1),common) + elif firstRel == 2 and secondRel == 2: + if other_person.get_gender() == RelLib.Person.male: + return ('le cousin germain',common) + else: + return ('la cousine germaine',common) + elif firstRel == 3 and secondRel == 2: + if other_person.get_gender() == RelLib.Person.male: + return ('le neveu à la mode de Bretagne',common) + else: + return ('la nièce à la mode de Bretagne',common) + elif firstRel == 2 and secondRel == 3: + if other_person.get_gender() == RelLib.Person.male: + return ('l\'oncle à la mode de Bretagne',common) + else: + return ('la tante à la mode de Bretagne',common) + else: + if other_person.get_gender() == RelLib.Person.male: + if firstRel+secondRel>len(_level_name)-1: + return (self.get_male_cousin(firstRel+secondRel),common) + else: + return ('le cousin lointain',common) + else: + if firstRel+secondRel>len(_level_name)-1: + return (self.get_female_cousin(firstRel+secondRel),common) + else: + return ('la cousine lointaine',common) + +#------------------------------------------------------------------------- +# +# Register this class with the Plugins system +# +#------------------------------------------------------------------------- +from Plugins import register_relcalc + +register_relcalc(RelationshipCalculator, + ["fr","FR","fr_FR","francais","Francais","fr_FR.UTF8","fr_FR@euro","fr_FR.UTF8@euro", + "french","French", "fr_FR.UTF-8", "fr_FR.utf-8", "fr_FR.utf8"]) diff --git a/src/plugins/rel_hu.py b/src/plugins/rel_hu.py index dd843c74c..1c8c62079 100644 --- a/src/plugins/rel_hu.py +++ b/src/plugins/rel_hu.py @@ -296,6 +296,9 @@ class RelationshipCalculator(Relationship.RelationshipCalculator): else: return ("",[]) + firstRel = len(firstRel) + secondRel = len(secondRel) + if firstRel == 0: if secondRel == 0: return ('',common) diff --git a/src/plugins/rel_it.py b/src/plugins/rel_it.py index 24fde2acd..3358207bb 100644 --- a/src/plugins/rel_it.py +++ b/src/plugins/rel_it.py @@ -164,6 +164,9 @@ class RelationshipCalculator(Relationship.RelationshipCalculator): else: return ("",[]) + firstRel = len(firstRel) + secondRel = len(secondRel) + if firstRel == 0: if secondRel == 0: return ('',common) diff --git a/src/plugins/rel_no.py b/src/plugins/rel_no.py new file mode 100644 index 000000000..dac813721 --- /dev/null +++ b/src/plugins/rel_no.py @@ -0,0 +1,283 @@ +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2003-2004 Donald N. Allingham +# +# 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 +# + +# $Id$ + +# Written by Alex Roitman, largely based on Relationship.py by Don Allingham +# and on valuable input from Frode Jemtland + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- + +import RelLib +import Relationship +import types +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# Norwegian-specific definitions of relationships +# +#------------------------------------------------------------------------- + +_cousin_level = [ "", "", #brother/sister, fetter/kusine -- these are taken care of separately +"tremenning", "firemenning", "femmenning", +"seksmenning", "sjumenning", "åttemenning", +"nimenning", "timenning", "elvemenning", +"tolvmenning", "tretenmenning", "fjortenmenning", +"femtenmenning", "sekstenmenning", "syttenmenning", +"attenmenning", "nittenmenning", "tyvemenning" ] + +_cousin_terms = _cousin_level + ["fetter","kusine"] +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +class RelationshipCalculator(Relationship.RelationshipCalculator): + + def __init__(self,db): + Relationship.RelationshipCalculator.__init__(self,db) + + def get_parents(self,level): + if level == 0: + return "forelder" + else: + return "ane i %d-te generationen" % (level+1) + + def get_cousin(self,level): + if level>len(_cousin_level)-1: + # FIXME: use Norwegian term term here, + # UPDATED by Frode: unsure about the expretion "en fjern slektning", should it be just "fjern slektning". + # Need to see it used in the program to get the understanding. + return "en fjern slektning" + else: + return _cousin_level[level] + + def pair_up(self,rel_list): + result = [] + item = "" + for word in rel_list[:]: + if not word: + continue + if word in _cousin_terms: + if item: + result.append(item) + item = "" + result.append(word) + continue + if item: + if word == 'sønne': + word = 'sønn' + result.append(item + word) + item = "" + else: + item = word + if item: + result.append(item) + gen_result = [ item + 's' for item in result[0:-1] ] + return ' '.join(gen_result+result[-1:]) + + def get_direct_ancestor(self,person,rel_string): + result = [] + for ix in range(len(rel_string)): + if rel_string[ix] == 'f': + result.append('far') + else: + result.append('mor') + return self.pair_up(result) + + def get_direct_descendant(self,person,rel_string): + result = [] + for ix in range(len(rel_string)-2,-1,-1): + if rel_string[ix] == 'f': + result.append('sønne') + else: + result.append('datter') + if person.get_gender() == RelLib.Person.male: + result.append('sønn') + else: + result.append('datter') + return self.pair_up(result) + + def get_ancestors_cousin(self,person,rel_string_long,rel_string_short): + result = [] + removed = len(rel_string_long)-len(rel_string_short) + level = len(rel_string_short)-1 + for ix in range(removed): + if rel_string_long[ix] == 'f': + result.append('far') + else: + result.append('mor') + if level > 1: + result.append(self.get_cousin(level)) + elif person.get_gender() == RelLib.Person.male: + result.append('fetter') + else: + result.append('kusine') + main_string = self.get_two_way_rel(person,rel_string_short,rel_string_long) + aux_string = self.pair_up(result) + return "%s (%s)" % (main_string,aux_string) + + def get_cousins_descendant(self,person,rel_string_long,rel_string_short): + result = [] + aux_string = "" + removed = len(rel_string_long)-len(rel_string_short)-1 + level = len(rel_string_short)-1 + if level > 1: # Cousin terms without gender + result.append(self.get_cousin(level)) + elif level == 1: # gender-dependent fetter/kusine + if rel_string_long[removed] == 'f': + result.append('fetter') + else: + result.append('kusine') + elif rel_string_long[removed] == 'f': + result.append('bror') + else: + result.append('søster') + for ix in range(removed-1,-1,-1): + if rel_string_long[ix] == 'f': + result.append('sønn') + else: + result.append('datter') + if person.get_gender() == RelLib.Person.male: + result.append('sønn') + else: + result.append('datter') + main_string = self.get_two_way_rel(person,rel_string_long,rel_string_short) + if level: + aux_string = " (%s)" % self.pair_up(result) + return "%s%s" % (main_string,aux_string) + + def get_ancestors_brother(self,rel_string): + result = [] + for ix in range(len(rel_string)-1): + if rel_string[ix] == 'f': + result.append('far') + else: + result.append('mor') + result.append('bror') + return self.pair_up(result) + + def get_ancestors_sister(self,rel_string): + result = [] + for ix in range(len(rel_string)-1): + if rel_string[ix] == 'f': + result.append('far') + else: + result.append('mor') + result.append('søster') + return self.pair_up(result) + + 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 first_rel_string[-2] == 'f': + result.append('bror') + else: + result.append('søster') + for ix in range(len(first_rel_string)-3,-1,-1): + if first_rel_string[ix] == 'f': + result.append('sønne') + else: + result.append('datter') + if person.get_gender() == RelLib.Person.male: + result.append('sønn') + else: + result.append('datter') + else: + if person.get_gender() == RelLib.Person.male: + result.append('bror') + else: + result.append('søster') + return self.pair_up(result) + + def get_relationship(self,orig_person,other_person): + """ + Returns a string representing the relationshp between the two people, + along with a list of common ancestors (typically father,mother) + + Special cases: relation strings "", "undefined" and "spouse". + """ + + if orig_person == None: + return ("undefined",[]) + + if orig_person == other_person: + return ('', []) + + if self.is_spouse(orig_person,other_person): + return ('spouse', []) +# FIXME: need Norwegian term for spouse. If gender-specific, use the code below. +# UPDATE by Frode: unsure about how it's included in the finished code, so I need +# to see this running to know if it is the right words to use. +# if other_person.get_gender() == RelLib.Person.male: +# return ("ektemann",[]) +# else: +# return ("hustru",[]) + + (firstRel,secondRel,common) = self.get_relationship_distance(orig_person,other_person) + + if type(common) == types.StringType or type(common) == types.UnicodeType: + return (common,[]) + elif common: + person_handle = common[0] + else: + return ("",[]) + + if not firstRel: + if not secondRel: + return ('',common) + else: + return (self.get_direct_ancestor(other_person,secondRel),common) + elif not secondRel: + return (self.get_direct_descendant(other_person,firstRel),common) + elif len(firstRel) == 1: + if other_person.get_gender() == RelLib.Person.male: + return (self.get_ancestors_brother(secondRel),common) + else: + return (self.get_ancestors_sister(secondRel),common) + elif len(secondRel) >= len(firstRel): + return (self.get_ancestors_cousin(other_person,secondRel,firstRel),common) + else: + return (self.get_cousins_descendant(other_person,firstRel,secondRel),common) + +#------------------------------------------------------------------------- +# +# Register this class with the Plugins system +# +#------------------------------------------------------------------------- +from Plugins import register_relcalc + +register_relcalc(RelationshipCalculator, + ["nb","nn","no", "nb_NO","nn_NO","no_NO","nb_NO.UTF8","nn_NO.UTF8","no_NO.UTF8", + "nb_NO.UTF-8","nn_NO.UTF-8","no_NO.UTF-8", + "nb_NO.utf-8","nn_NO.utf-8","no_NO.utf-8", + "nb_NO.iso88591","nn_NO.iso88591","no_NO.iso88591", + "nynorsk","Nynorsk"]) diff --git a/src/plugins/rel_ru.py b/src/plugins/rel_ru.py index 91f26a8ac..60e4bfdf4 100644 --- a/src/plugins/rel_ru.py +++ b/src/plugins/rel_ru.py @@ -21,9 +21,7 @@ # $Id$ -# # Written by Alex Roitman, largely based on Relationship.py by Don Allingham. -# #------------------------------------------------------------------------- # @@ -195,18 +193,6 @@ class RelationshipCalculator(Relationship.RelationshipCalculator): else: return _niece_level[level] - def is_spouse(self,orig,other): - for f in orig.get_family_handle_list(): - family = self.db.get_family_from_handle(f) - if family: - if other == family.get_father_handle() or other == family.get_mother_handle(): - return 1 - else: - return 0 - return 0 - - - def get_relationship(self,orig_person,other_person): """ Returns a string representing the relationshp between the two people, @@ -233,6 +219,9 @@ class RelationshipCalculator(Relationship.RelationshipCalculator): else: return ("",[]) + firstRel = len(firstRel) + secondRel = len(secondRel) + if firstRel == 0: if secondRel == 0: return ('',common) diff --git a/src/plugins/rel_sv.py b/src/plugins/rel_sv.py new file mode 100644 index 000000000..d2997096b --- /dev/null +++ b/src/plugins/rel_sv.py @@ -0,0 +1,231 @@ +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2003-2004 Donald N. Allingham +# +# 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 +# + +# $Id$ + +# Written by Alex Roitman, largely based on Relationship.py by Don Allingham +# and on valuable input from Jens Arvidsson + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- + +import RelLib +import Relationship +import types +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# Swedish-specific definitions of relationships +# +#------------------------------------------------------------------------- + +_cousin_level = [ "", "kusin", +"tremänning", "fyrmänning", "femmänning", +"sexmänning", "sjumänning", "åttamänning", +"niomänning", "tiomänning", "elvammänning", +"tolvmänning", "trettonmänning", "fjortonmänning", +"femtonmänning", "sextonmänning", "sjuttonmänning", +"artonmänning", "nittonmänning", "tjugomänning" ] + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +class RelationshipCalculator(Relationship.RelationshipCalculator): + + def __init__(self,db): + Relationship.RelationshipCalculator.__init__(self,db) + + def get_parents(self,level): + if level == 0: + return "föräldrar" + else: + return "anor i %d-te generationen" % (level+1) + + def get_cousin(self,level): + if level>len(_cousin_level)-1: + return "distant relative" + else: + return _cousin_level[level] + + def pair_up(self,rel_list): + result = [] + item = "" + for word in rel_list[:]: + if not word: + continue + if word in _cousin_level: + if item: + result.append(item) + item = "" + result.append(word) + continue + if item: + if word == 'syster': + item = item[0:-1] + word = 'ster' + elif word == 'dotter' and item == 'bror': + item = 'brors' + result.append(item + word) + item = "" + else: + item = word + if item: + result.append(item) + gen_result = [ item + 's' for item in result[0:-1] ] + return ' '.join(gen_result+result[-1:]) + + def get_direct_ancestor(self,person,rel_string): + result = [] + for ix in range(len(rel_string)): + if rel_string[ix] == 'f': + result.append('far') + else: + result.append('mor') + return self.pair_up(result) + + def get_direct_descendant(self,person,rel_string): + result = [] + for ix in range(len(rel_string)-2,-1,-1): + if rel_string[ix] == 'f': + result.append('son') + else: + result.append('dotter') + if person.get_gender() == RelLib.Person.male: + result.append('son') + else: + result.append('dotter') + return self.pair_up(result) + + def get_ancestors_cousin(self,rel_string_long,rel_string_short): + result = [] + removed = len(rel_string_long)-len(rel_string_short) + level = len(rel_string_short)-1 + for ix in range(removed): + if rel_string_long[ix] == 'f': + result.append('far') + else: + result.append('mor') + result.append(self.get_cousin(level)) + return self.pair_up(result) + + def get_cousins_descendant(self,person,rel_string_long,rel_string_short): + result = [] + removed = len(rel_string_long)-len(rel_string_short)-1 + level = len(rel_string_short)-1 + if level: + result.append(self.get_cousin(level)) + elif rel_string_long[removed] == 'f': + result.append('bror') + else: + result.append('syster') + for ix in range(removed-1,-1,-1): + if rel_string_long[ix] == 'f': + result.append('son') + else: + result.append('dotter') + if person.get_gender() == RelLib.Person.male: + result.append('son') + else: + result.append('dotter') + return self.pair_up(result) + + def get_ancestors_brother(self,rel_string): + result = [] + for ix in range(len(rel_string)-1): + if rel_string[ix] == 'f': + result.append('far') + else: + result.append('mor') + result.append('bror') + return self.pair_up(result) + + def get_ancestors_sister(self,rel_string): + result = [] + for ix in range(len(rel_string)-1): + if rel_string[ix] == 'f': + result.append('far') + else: + result.append('mor') + result.append('syster') + return self.pair_up(result) + + def get_relationship(self,orig_person,other_person): + """ + Returns a string representing the relationshp between the two people, + along with a list of common ancestors (typically father,mother) + + Special cases: relation strings "", "undefined" and "spouse". + """ + + if orig_person == None: + return ("undefined",[]) + + if orig_person == other_person: + return ('', []) + + if self.is_spouse(orig_person,other_person): + if other_person.get_gender() == RelLib.Person.male: + return ("make",[]) + else: + return ("maka",[]) + + (firstRel,secondRel,common) = self.get_relationship_distance(orig_person,other_person) + + if type(common) == types.StringType or type(common) == types.UnicodeType: + return (common,[]) + elif common: + person_handle = common[0] + else: + return ("",[]) + + if not firstRel: + if not secondRel: + return ('',common) + else: + return (self.get_direct_ancestor(other_person,secondRel),common) + elif not secondRel: + return (self.get_direct_descendant(other_person,firstRel),common) + elif len(firstRel) == 1: + if other_person.get_gender() == RelLib.Person.male: + return (self.get_ancestors_brother(secondRel),common) + else: + return (self.get_ancestors_sister(secondRel),common) + elif len(secondRel) >= len(firstRel): + return (self.get_ancestors_cousin(secondRel,firstRel),common) + else: + return (self.get_cousins_descendant(other_person,firstRel,secondRel),common) + +#------------------------------------------------------------------------- +# +# Register this class with the Plugins system +# +#------------------------------------------------------------------------- +from Plugins import register_relcalc + +register_relcalc(RelationshipCalculator, + ["sv","SV","sv_SE","swedish","Swedish","sv_SE.UTF8","sv_SE@euro","sv_SE.UTF8@euro", + "svenska","Svenska", "sv_SE.UTF-8", "sv_SE.utf-8", "sv_SE.utf8"])