diff --git a/gramps/gen/filters/rules/person/__init__.py b/gramps/gen/filters/rules/person/__init__.py index 7deba8f10..903fb1a46 100644 --- a/gramps/gen/filters/rules/person/__init__.py +++ b/gramps/gen/filters/rules/person/__init__.py @@ -109,6 +109,7 @@ from ._matchidof import MatchIdOf from ._regexpidof import RegExpIdOf from ._changedsince import ChangedSince from ._isrelatedwith import IsRelatedWith +from ._hassoundexname import HasSoundexName #------------------------------------------------------------------------- # @@ -189,5 +190,6 @@ editor_rule_list = [ Disconnected, ChangedSince, IsRelatedWith, + HasSoundexName, ] diff --git a/gramps/gen/filters/rules/person/_hassoundexname.py b/gramps/gen/filters/rules/person/_hassoundexname.py new file mode 100644 index 000000000..ae280dbda --- /dev/null +++ b/gramps/gen/filters/rules/person/_hassoundexname.py @@ -0,0 +1,86 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2017 Paul Culley +# +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from ....const import GRAMPS_LOCALE as glocale +_ = glocale.translation.sgettext + +#------------------------------------------------------------------------- +# +# Gramps modules +# +#------------------------------------------------------------------------- +from .. import Rule +from ....lib.nameorigintype import NameOriginType +from gramps.gen.soundex import soundex + + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class HasSoundexName(Rule): + """Rule that checks for full or partial name matches""" + + labels = [_('Name:')] + name = _('Soundex match of People with the ') + description = _("Soundex Match of people with a specified name. First " + "name, Surname, Call name, and Nickname are searched in " + "primary and alternate names.") + category = _('General filters') + allow_regex = False + + def apply(self, db, person): + self.sndx = soundex(self.list[0]) + for name in [person.get_primary_name()] + person.get_alternate_names(): + if self._match_name(name): + return True + return False + + def _match_name(self, name): + if self.list[0]: + if soundex(str(name.get_first_name())) == self.sndx: + return True + elif soundex(str(name.get_surname())) == self.sndx: + return True + elif soundex(str(name.get_call_name())) == self.sndx: + return True + elif soundex(str(name.get_nick_name())) == self.sndx: + return True + elif soundex(str(name.get_family_nick_name())) == self.sndx: + return True + else: + for surn in name.get_surname_list(): + if self._match_surname(surn): + return True + return False + + def _match_surname(self, surn): + if soundex(str(surn.get_surname())) == self.sndx: + return True + if surn.get_origintype().value == NameOriginType.PATRONYMIC: + if soundex(str(surn.get_surname())) == self.sndx: + return True + return False