diff --git a/src/Filters/Rules/Citation/_HasNoteRegexp.py b/src/Filters/Rules/Citation/_HasNoteRegexp.py index 727bca318..214103c02 100644 --- a/src/Filters/Rules/Citation/_HasNoteRegexp.py +++ b/src/Filters/Rules/Citation/_HasNoteRegexp.py @@ -40,6 +40,6 @@ from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Citations having notes containing ') + name = _('Citations having notes containing ') description = _("Matches citations whose notes contain text " "matching a regular expression") diff --git a/src/Filters/Rules/Citation/_MatchesPageSubstringOf.py b/src/Filters/Rules/Citation/_MatchesPageSubstringOf.py index d58c2eec8..126e83d3d 100644 --- a/src/Filters/Rules/Citation/_MatchesPageSubstringOf.py +++ b/src/Filters/Rules/Citation/_MatchesPageSubstringOf.py @@ -40,15 +40,13 @@ from Filters.Rules import Rule class MatchesPageSubstringOf(Rule): """Citation Volume/Page title containing """ - labels = [ _('Substring:')] - name = _('Citation Volume/Page containing ') + labels = [ _('Text:')] + name = _('Citations with Volume/Page containing ') description = _("Matches citations whose Volume/Page contains a " "certain substring") category = _('General filters') + allow_regex = True def apply(self, db, object): """ Apply the filter """ - title = object.get_page() - if title.upper().find(self.list[0].upper()) != -1: - return True - return False + return self.match_substring(0, object.get_page()) diff --git a/src/Filters/Rules/Citation/_RegExpIdOf.py b/src/Filters/Rules/Citation/_RegExpIdOf.py index d2fd256b0..f08121173 100644 --- a/src/Filters/Rules/Citation/_RegExpIdOf.py +++ b/src/Filters/Rules/Citation/_RegExpIdOf.py @@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Citations with matching regular expression') + name = _('Citations with Id containing ') description = _("Matches citations whose Gramps ID matches " "the regular expression") diff --git a/src/Filters/Rules/Citation/__init__.py b/src/Filters/Rules/Citation/__init__.py index 36ce27825..c8d8353ed 100644 --- a/src/Filters/Rules/Citation/__init__.py +++ b/src/Filters/Rules/Citation/__init__.py @@ -51,7 +51,6 @@ editor_rule_list = [ HasGallery, HasIdOf, HasNote, - HasNoteMatchingSubstringOf, HasNoteRegexp, HasReferenceCountOf, HasSource, diff --git a/src/Filters/Rules/Event/_HasCitation.py b/src/Filters/Rules/Event/_HasCitation.py index 9381463d1..b17fdf43e 100644 --- a/src/Filters/Rules/Event/_HasCitation.py +++ b/src/Filters/Rules/Event/_HasCitation.py @@ -49,7 +49,7 @@ class HasCitation(HasCitationBase): labels = [ _('Volume/Page:'), _('Date:'), _('Confidence level:')] - name = _('Event with the ') + name = _('Events with the ') description = _("Matches events with a citation of a particular " "value") diff --git a/src/Filters/Rules/Event/_HasData.py b/src/Filters/Rules/Event/_HasData.py index ef12a1c8a..26f840574 100644 --- a/src/Filters/Rules/Event/_HasData.py +++ b/src/Filters/Rules/Event/_HasData.py @@ -49,47 +49,42 @@ class HasData(Rule): name = _('Events with ') description = _("Matches events with data of a particular value") category = _('General filters') + allow_regex = True - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - + def prepare(self, dbase): self.event_type = self.list[0] self.date = self.list[1] - self.place = self.list[2] - self.description = self.list[3] if self.event_type: self.event_type = EventType() self.event_type.set_from_xml_str(self.list[0]) if self.date: - self.date = DateHandler.parser.parse(self.date) + self.date = parser.parse(self.date) def apply(self, db, event): if self.event_type and event.get_type() != self.event_type: # No match return False - ed = event.get_description().upper() - if self.description and ed.find(self.description.upper()) == -1: - # No match - return False - if self.date and not event.get_date_object().match(self.date): # No match return False - if self.place: - pl_id = event.get_place_handle() - if pl_id: - pl = db.get_place_from_handle(pl_id) - pn = pl.get_title().upper() - if pn.find(self.place.upper()) == -1: + if self.list[2]: + place_id = event.get_place_handle() + if place_id: + place = db.get_place_from_handle(place_id) + if not self.match_substring(2, place.get_title()): # No match return False else: # No place attached to event return False + if not self.match_substring(3, event.get_description()): + # No match + return False + # All conditions matched return True diff --git a/src/Filters/Rules/Event/_HasNoteRegexp.py b/src/Filters/Rules/Event/_HasNoteRegexp.py index 9d5eada55..b7cc92dee 100644 --- a/src/Filters/Rules/Event/_HasNoteRegexp.py +++ b/src/Filters/Rules/Event/_HasNoteRegexp.py @@ -39,6 +39,6 @@ from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Events having notes containing ') + name = _('Events having notes containing ') description = _("Matches events whose notes contain text " "matching a regular expression") diff --git a/src/Filters/Rules/Event/_RegExpIdOf.py b/src/Filters/Rules/Event/_RegExpIdOf.py index 4aab823df..319d1deba 100644 --- a/src/Filters/Rules/Event/_RegExpIdOf.py +++ b/src/Filters/Rules/Event/_RegExpIdOf.py @@ -45,6 +45,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Events with matching regular expression') + name = _('Events with Id containing ') description = _("Matches events whose Gramps ID matches " "the regular expression") diff --git a/src/Filters/Rules/Event/__init__.py b/src/Filters/Rules/Event/__init__.py index fe90c6a6c..821eaba33 100644 --- a/src/Filters/Rules/Event/__init__.py +++ b/src/Filters/Rules/Event/__init__.py @@ -58,7 +58,6 @@ editor_rule_list = [ HasCitation, HasNote, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, HasSourceCount, EventPrivate, diff --git a/src/Filters/Rules/Family/_ChildHasIdOf.py b/src/Filters/Rules/Family/_ChildHasIdOf.py index 837ac8c2f..5432ab616 100644 --- a/src/Filters/Rules/Family/_ChildHasIdOf.py +++ b/src/Filters/Rules/Family/_ChildHasIdOf.py @@ -32,7 +32,7 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules import HasGrampsId +from Filters.Rules import RegExpIdBase from _MemberBase import child_base #------------------------------------------------------------------------- @@ -40,13 +40,13 @@ from _MemberBase import child_base # HasNameOf # #------------------------------------------------------------------------- -class ChildHasIdOf(HasGrampsId): +class ChildHasIdOf(RegExpIdBase): """Rule that checks for a person with a specific GRAMPS ID""" labels = [ _('Person ID:') ] - name = _('Families with child with the ') + name = _('Families having child with Id containing ') description = _("Matches families where child has a specified " "Gramps ID") category = _('Child filters') - base_class = HasGrampsId + base_class = RegExpIdBase apply = child_base diff --git a/src/Filters/Rules/Family/_FatherHasIdOf.py b/src/Filters/Rules/Family/_FatherHasIdOf.py index e970edfdb..6158abb53 100644 --- a/src/Filters/Rules/Family/_FatherHasIdOf.py +++ b/src/Filters/Rules/Family/_FatherHasIdOf.py @@ -32,7 +32,7 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules import HasGrampsId +from Filters.Rules import RegExpIdBase from _MemberBase import father_base #------------------------------------------------------------------------- @@ -40,13 +40,13 @@ from _MemberBase import father_base # HasNameOf # #------------------------------------------------------------------------- -class FatherHasIdOf(HasGrampsId): +class FatherHasIdOf(RegExpIdBase): """Rule that checks for a person with a specific GRAMPS ID""" labels = [ _('Person ID:') ] - name = _('Families with father with the ') + name = _('Families having father with Id containing ') description = _("Matches families whose father has a specified " "Gramps ID") category = _('Father filters') - base_class = HasGrampsId + base_class = RegExpIdBase apply = father_base diff --git a/src/Filters/Rules/Family/_HasCitation.py b/src/Filters/Rules/Family/_HasCitation.py index f4e404d7c..e11719064 100644 --- a/src/Filters/Rules/Family/_HasCitation.py +++ b/src/Filters/Rules/Family/_HasCitation.py @@ -49,6 +49,6 @@ class HasCitation(HasCitationBase): labels = [ _('Volume/Page:'), _('Date:'), _('Confidence level:')] - name = _('Family with the ') + name = _('Families with the ') description = _("Matches families with a citation of a particular " "value") diff --git a/src/Filters/Rules/Family/_HasNoteRegexp.py b/src/Filters/Rules/Family/_HasNoteRegexp.py index 338e445aa..c378b092c 100644 --- a/src/Filters/Rules/Family/_HasNoteRegexp.py +++ b/src/Filters/Rules/Family/_HasNoteRegexp.py @@ -39,7 +39,7 @@ from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Families having notes containing ') + name = _('Families having notes containing ') description = _("Matches families whose notes contain text " "matching a regular expression") diff --git a/src/Filters/Rules/Family/_MotherHasIdOf.py b/src/Filters/Rules/Family/_MotherHasIdOf.py index 01292685e..d9e92dcc3 100644 --- a/src/Filters/Rules/Family/_MotherHasIdOf.py +++ b/src/Filters/Rules/Family/_MotherHasIdOf.py @@ -32,7 +32,7 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules import HasGrampsId +from Filters.Rules import RegExpIdBase from _MemberBase import mother_base #------------------------------------------------------------------------- @@ -40,13 +40,13 @@ from _MemberBase import mother_base # HasNameOf # #------------------------------------------------------------------------- -class MotherHasIdOf(HasGrampsId): +class MotherHasIdOf(RegExpIdBase): """Rule that checks for a person with a specific GRAMPS ID""" labels = [ _('Person ID:') ] - name = _('Families with mother with the ') + name = _('Families having mother with Id containing ') description = _("Matches families whose mother has a specified " "Gramps ID") category = _('Mother filters') - base_class = HasGrampsId + base_class = RegExpIdBase apply = mother_base diff --git a/src/Filters/Rules/Family/_RegExpIdOf.py b/src/Filters/Rules/Family/_RegExpIdOf.py index 8a37754bd..75b55fad6 100644 --- a/src/Filters/Rules/Family/_RegExpIdOf.py +++ b/src/Filters/Rules/Family/_RegExpIdOf.py @@ -45,6 +45,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Families with matching regular expression') + name = _('Families with Id containing ') description = _("Matches families whose Gramps ID matches " "the regular expression") diff --git a/src/Filters/Rules/Family/__init__.py b/src/Filters/Rules/Family/__init__.py index 1038dfee0..daa7ae806 100644 --- a/src/Filters/Rules/Family/__init__.py +++ b/src/Filters/Rules/Family/__init__.py @@ -70,7 +70,6 @@ editor_rule_list = [ HasNote, RegExpIdOf, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, HasSourceCount, HasSourceOf, diff --git a/src/Filters/Rules/MediaObject/_HasNoteRegexp.py b/src/Filters/Rules/MediaObject/_HasNoteRegexp.py index 85585453f..09c4578a3 100644 --- a/src/Filters/Rules/MediaObject/_HasNoteRegexp.py +++ b/src/Filters/Rules/MediaObject/_HasNoteRegexp.py @@ -39,7 +39,6 @@ from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Media objects having notes ' - 'containing ') + name = _('Media objects having notes containing ') description = _("Matches media objects whose notes contain text " "matching a regular expression") diff --git a/src/Filters/Rules/MediaObject/_RegExpIdOf.py b/src/Filters/Rules/MediaObject/_RegExpIdOf.py index 18f69638e..81679857f 100644 --- a/src/Filters/Rules/MediaObject/_RegExpIdOf.py +++ b/src/Filters/Rules/MediaObject/_RegExpIdOf.py @@ -45,6 +45,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Media Objects with matching regular expression') + name = _('Media objects with Id containing ') description = _("Matches media objects whose Gramps ID matches " "the regular expression") diff --git a/src/Filters/Rules/MediaObject/__init__.py b/src/Filters/Rules/MediaObject/__init__.py index f691721e4..8e4a997fc 100644 --- a/src/Filters/Rules/MediaObject/__init__.py +++ b/src/Filters/Rules/MediaObject/__init__.py @@ -47,7 +47,6 @@ editor_rule_list = [ RegExpIdOf, HasCitation, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, HasSourceCount, HasSourceOf, diff --git a/src/Filters/Rules/Note/_HasNote.py b/src/Filters/Rules/Note/_HasNote.py index 1ff337934..d9c7e3873 100644 --- a/src/Filters/Rules/Note/_HasNote.py +++ b/src/Filters/Rules/Note/_HasNote.py @@ -50,6 +50,7 @@ class HasNote(Rule): name = _('Notes matching parameters') description = _("Matches Notes with particular parameters") category = _('General filters') + allow_regex = True def prepare(self, dbase): if self.list[1]: diff --git a/src/Filters/Rules/Note/_MatchesRegexpOf.py b/src/Filters/Rules/Note/_MatchesRegexpOf.py index 77974a707..f6aa544f1 100644 --- a/src/Filters/Rules/Note/_MatchesRegexpOf.py +++ b/src/Filters/Rules/Note/_MatchesRegexpOf.py @@ -42,22 +42,15 @@ from Filters.Rules import Rule class MatchesRegexpOf(Rule): labels = [ _('Regular expression:')] - name = _('Notes containing ') + name = _('Notes containing ') description = _("Matches notes that contain text " "which matches a regular expression") category = _('General filters') + allow_regex = True - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - - try: - self.match = re.compile(list[0], re.I|re.U|re.L) - except: - self.match = re.compile('') - def apply(self, db, note): """ Apply the filter """ text = note.get() - if self.match.search(text) is not None: + if self.match_substring(0, text) is not None: return True return False diff --git a/src/Filters/Rules/Note/_RegExpIdOf.py b/src/Filters/Rules/Note/_RegExpIdOf.py index 11f2d7374..af8cc4f95 100644 --- a/src/Filters/Rules/Note/_RegExpIdOf.py +++ b/src/Filters/Rules/Note/_RegExpIdOf.py @@ -45,6 +45,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Notes with matching regular expression') + name = _('Notes with Id containing ') description = _("Matches notes whose Gramps ID matches " "the regular expression") diff --git a/src/Filters/Rules/Note/__init__.py b/src/Filters/Rules/Note/__init__.py index fdb3772d4..dbcf31c97 100644 --- a/src/Filters/Rules/Note/__init__.py +++ b/src/Filters/Rules/Note/__init__.py @@ -43,7 +43,6 @@ editor_rule_list = [ RegExpIdOf, HasNote, MatchesRegexpOf, - MatchesSubstringOf, HasReferenceCountOf, NotePrivate, MatchesFilter, diff --git a/src/Filters/Rules/Person/_HasBirth.py b/src/Filters/Rules/Person/_HasBirth.py index 89c485586..c4e0e9448 100644 --- a/src/Filters/Rules/Person/_HasBirth.py +++ b/src/Filters/Rules/Person/_HasBirth.py @@ -48,11 +48,11 @@ class HasBirth(Rule): name = _('People with the ') description = _("Matches people with birth data of a particular value") category = _('Event filters') + allow_regex = True - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) + def prepare(self, db): if self.list[0]: - self.date = DateHandler.parser.parse(self.list[0]) + self.date = parser.parse(self.list[0]) else: self.date = None @@ -67,9 +67,7 @@ class HasBirth(Rule): if event.get_type() != EventType.BIRTH: # No match: wrong type continue - ed = event.get_description().upper() - if self.list[2] \ - and ed.find(self.list[2].upper())==-1: + if not self.match_substring(2, event.get_description()): # No match: wrong description continue if self.date: @@ -77,11 +75,10 @@ class HasBirth(Rule): # No match: wrong date continue if self.list[1]: - pl_id = event.get_place_handle() - if pl_id: - pl = db.get_place_from_handle(pl_id) - pn = pl.get_title().upper() - if pn.find(self.list[1].upper()) == -1: + place_id = event.get_place_handle() + if place_id: + place = db.get_place_from_handle(place_id) + if not self.match_substring(1, place.get_title()): # No match: wrong place continue else: diff --git a/src/Filters/Rules/Person/_HasDeath.py b/src/Filters/Rules/Person/_HasDeath.py index ee9e57824..5a50839d9 100644 --- a/src/Filters/Rules/Person/_HasDeath.py +++ b/src/Filters/Rules/Person/_HasDeath.py @@ -48,11 +48,11 @@ class HasDeath(Rule): name = _('People with the ') description = _("Matches people with death data of a particular value") category = _('Event filters') + allow_regex = True - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) + def prepare(self, db): if self.list[0]: - self.date = DateHandler.parser.parse(self.list[0]) + self.date = parser.parse(self.list[0]) else: self.date = None @@ -67,9 +67,7 @@ class HasDeath(Rule): if event.get_type() != EventType.DEATH: # No match: wrong type continue - ed = event.get_description().upper() - if self.list[2] \ - and ed.find(self.list[2].upper())==-1: + if not self.match_substring(2, event.get_description()): # No match: wrong description continue if self.date: @@ -77,11 +75,10 @@ class HasDeath(Rule): # No match: wrong date continue if self.list[1]: - pl_id = event.get_place_handle() - if pl_id: - pl = db.get_place_from_handle(pl_id) - pn = pl.get_title().upper() - if pn.find(self.list[1].upper()) == -1: + place_id = event.get_place_handle() + if place_id: + place = db.get_place_from_handle(place_id) + if not self.match_substring(1, place.get_title()): # No match: wrong place continue else: diff --git a/src/Filters/Rules/Person/_HasFamilyAttribute.py b/src/Filters/Rules/Person/_HasFamilyAttribute.py index 17de7b49c..c8d10cfeb 100644 --- a/src/Filters/Rules/Person/_HasFamilyAttribute.py +++ b/src/Filters/Rules/Person/_HasFamilyAttribute.py @@ -47,6 +47,7 @@ class HasFamilyAttribute(Rule): description = _("Matches people with the family attribute " "of a particular value") category = _('General filters') + allow_regex = True def apply(self,db,person): if not self.list[0]: @@ -58,8 +59,7 @@ class HasFamilyAttribute(Rule): for attr in f.get_attribute_list(): if attr: name_match = self.list[0] == attr.get_type() - value_match = \ - attr.get_value().upper().find(self.list[1].upper()) != -1 + value_match = self.match_substring(1, attr.get_value()) if name_match and value_match: return True return False diff --git a/src/Filters/Rules/Person/_HasFamilyEvent.py b/src/Filters/Rules/Person/_HasFamilyEvent.py index 393a1407d..748c9a5bd 100644 --- a/src/Filters/Rules/Person/_HasFamilyEvent.py +++ b/src/Filters/Rules/Person/_HasFamilyEvent.py @@ -52,12 +52,13 @@ class HasFamilyEvent(Rule): name = _('People with the family ') description = _("Matches people with a family event of a particular value") category = _('Event filters') + allow_regex = True def prepare(self,db): self.date = None try: if self.list[1]: - self.date = DateHandler.parser.parse(self.list[1]) + self.date = parser.parse(self.list[1]) except: pass @@ -77,18 +78,17 @@ class HasFamilyEvent(Rule): specified_type.set_from_xml_str(self.list[0]) if event.type != specified_type: val = 0 - v = self.list[3] - if v and event.get_description().upper().find(v.upper())==-1: - val = 0 + if self.list[3]: + if not self.match_substring(3, event.get_description()): + val = 0 if self.date: if event.get_date_object().match(self.date): val = 0 if self.list[2]: - pl_id = event.get_place_handle() - if pl_id: - pl = db.get_place_from_handle(pl_id) - pn = pl.get_title().upper() - if pn.find(self.list[2].upper()) == -1: + place_id = event.get_place_handle() + if place_id: + place = db.get_place_from_handle(place_id) + if not self.match_substring(2, place.get_title()): val = 0 else: val = 0 diff --git a/src/Filters/Rules/Person/_HasNameOf.py b/src/Filters/Rules/Person/_HasNameOf.py index fc72aeaa8..a0fb37d0b 100644 --- a/src/Filters/Rules/Person/_HasNameOf.py +++ b/src/Filters/Rules/Person/_HasNameOf.py @@ -27,7 +27,6 @@ # #------------------------------------------------------------------------- from gen.ggettext import sgettext as _ -import re #------------------------------------------------------------------------- # @@ -45,7 +44,7 @@ from gen.lib import NameOriginType class HasNameOf(Rule): """Rule that checks for full or partial name matches""" - labels = [ _('Given name:'), + labels = [_('Given name:'), _('Full Family name:'), _('person|Title:'), _('Suffix:'), @@ -55,117 +54,47 @@ class HasNameOf(Rule): _('Single Surname:'), _('Connector'), _('Patronymic:'), - _('Family Nick Name:'), - _('Regular-Expression matching:')] + _('Family Nick Name:')] name = _('People with the ') description = _("Matches people with a specified (partial) name") category = _('General filters') + allow_regex = True - def prepare(self, db): - if len(self.list) >= 12: - self.regular_expression = bool(int(self.list[11])) - else: - self.regular_expression = False - if self.regular_expression: - self.firstn = self.list[0] - self.lastn = self.list[1] - self.title = self.list[2] - self.suffix = self.list[3] - self.calln = self.list[4] - self.nick = self.list[5] - self.famnick = self.list[10] - #surname parts - self.prefix = self.list[6] - self.surn = self.list[7] - self.con = self.list[8] - self.patr = self.list[9] - else: - self.firstn = self.list[0].upper() - self.lastn = self.list[1].upper() - self.title = self.list[2].upper() - self.suffix = self.list[3].upper() - self.calln = self.list[4].upper() - self.nick = self.list[5].upper() - self.famnick = self.list[10].upper() - #surname parts - self.prefix = self.list[6].upper() - self.surn = self.list[7].upper() - self.con = self.list[8].upper() - self.patr = self.list[9].upper() - def apply(self, db, person): for name in [person.get_primary_name()] + person.get_alternate_names(): - val = 1 - valpref = 0 - if not self.prefix: - valpref = 1 - valsurn = 0 - if not self.surn: - valsurn = 1 - valcon = 0 - if not self.con: - valcon = 1 - valpatr = 0 - if not self.patr: - valpatr = 1 - if self.regular_expression: - try: - if self.firstn and not re.search(self.firstn, name.get_first_name(), re.I|re.U|re.L): - val = 0 - elif self.lastn and not re.search(self.lastn, name.get_surname(), re.I|re.U|re.L): - val = 0 - elif self.suffix and not re.search(self.suffix, name.get_suffix(), re.I|re.U|re.L): - val = 0 - elif self.title and not re.search(self.title, name.get_title(), re.I|re.U|re.L): - val = 0 - elif self.calln and not re.search(self.calln, name.get_call_name(), re.I|re.U|re.L): - val = 0 - elif self.nick and not re.search(self.nick, name.get_nick_name(), re.I|re.U|re.L): - val = 0 - elif self.famnick and not re.search(self.famnick, name.get_family_nick_name(), re.I|re.U|re.L): - val = 0 - else: - #obtain surnames - for surn in name.get_surname_list(): - if self.prefix and re.search(self.prefix, surn.get_prefix(), re.I|re.U|re.L): - valpref = 1 - if self.surn and re.search(self.surn, surn.get_surname(), re.I|re.U|re.L): - valsurn = 1 - if self.con and re.search(self.con, surn.get_connector(), re.I|re.U|re.L): - valcon = 1 - if self.patr and surn.get_origintype().value == NameOriginType.PATRONYMIC \ - and re.search(self.patr, surn.get_surname(), re.I|re.U|re.L): - valpatr = 1 - except re.error: - #indicate error in the pattern by matching everyone - return True - else: - if self.firstn and name.get_first_name().upper().find(self.firstn) == -1: - val = 0 - elif self.lastn and name.get_surname().upper().find(self.lastn) == -1: - val = 0 - elif self.suffix and name.get_suffix().upper().find(self.surn) == -1: - val = 0 - elif self.title and name.get_title().upper().find(self.title) == -1: - val = 0 - elif self.calln and name.get_call_name().upper().find(self.calln) == -1: - val = 0 - elif self.nick and name.get_nick_name().upper().find(self.nick) == -1: - val = 0 - elif self.famnick and name.get_family_nick_name().upper().find(self.famnick) == -1: - val = 0 - else: - #obtain surnames - for surn in name.get_surname_list(): - if self.prefix and surn.get_prefix().upper().find(self.prefix) != -1: - valpref = 1 - if self.surn and surn.get_surname().upper().find(self.surn) != -1: - valsurn = 1 - if self.con and surn.get_connector().upper().find(self.con) != -1: - valcon = 1 - if self.patr and surn.get_origintype().value == NameOriginType.PATRONYMIC \ - and surn.get_surname().upper().find(self.patr) != -1: - valpatr = 1 - if val == 1 and valpref == 1 and valsurn == 1 and valcon == 1 and valpatr ==1: + if self.match_name(name): return True return False + + def match_name(self, name): + if self.list[0] and not self.match_substring(0, name.get_first_name()): + return False + elif self.list[1] and not self.match_substring(1, name.get_surname()): + return False + elif self.list[2] and not self.match_substring(2, name.get_title()): + return False + elif self.list[3] and not self.match_substring(3, name.get_suffix()): + return False + elif self.list[4] and not self.match_substring(4, name.get_call_name()): + return False + elif self.list[5] and not self.match_substring(5, name.get_nick_name()): + return False + elif self.list[10] and not self.match_substring(10, name.get_family_nick_name()): + return False + else: + for surn in name.get_surname_list(): + if self.match_surname(surn): + return True + return False + + def match_surname(self, surn): + if self.list[6] and not self.match_substring(6, surn.get_prefix()): + return False + if self.list[7] and not self.match_substring(7, surn.get_surname()): + return False + if self.list[8] and not self.match_substring(8, surn.get_connector()): + return False + if surn.get_origintype().value == NameOriginType.PATRONYMIC: + if self.list[9] and not self.match_substring(9, surn.get_surname()): + return False + return True diff --git a/src/Filters/Rules/Person/_HasNoteRegexp.py b/src/Filters/Rules/Person/_HasNoteRegexp.py index 56feaa5b1..e81ccf6bf 100644 --- a/src/Filters/Rules/Person/_HasNoteRegexp.py +++ b/src/Filters/Rules/Person/_HasNoteRegexp.py @@ -39,7 +39,7 @@ from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('People having notes containing ') + name = _('People having notes containing ') description = _("Matches people whose notes contain text " "matching a regular expression") diff --git a/src/Filters/Rules/Person/_HasTextMatchingSubstringOf.py b/src/Filters/Rules/Person/_HasTextMatchingSubstringOf.py index ef0a4504d..755717d80 100644 --- a/src/Filters/Rules/Person/_HasTextMatchingSubstringOf.py +++ b/src/Filters/Rules/Person/_HasTextMatchingSubstringOf.py @@ -45,12 +45,12 @@ class HasTextMatchingSubstringOf(Rule): """Rule that checks for string matches in any textual information""" labels = [ _('Substring:'), - _('Case sensitive:'), - _('Regular-Expression matching:')] + _('Case sensitive:')] name = _('People with records containing ') description = _("Matches people whose records contain text " "matching a substring") category = _('General filters') + allow_regex = True def prepare(self,db): self.db = db @@ -216,6 +216,6 @@ class HasTextMatchingSubstringOf(Rule): def match_object(self, obj): if not obj: return False - if self.regexp_match: + if self.use_regex: return obj.matches_regexp(self.list[0],self.case_sensitive) return obj.matches_string(self.list[0],self.case_sensitive) diff --git a/src/Filters/Rules/Person/_RegExpIdOf.py b/src/Filters/Rules/Person/_RegExpIdOf.py index a7a1ccdc3..9e0061e86 100644 --- a/src/Filters/Rules/Person/_RegExpIdOf.py +++ b/src/Filters/Rules/Person/_RegExpIdOf.py @@ -44,6 +44,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('People with matching regular expression') + name = _('People with Id containing ') description = _("Matches people whose Gramps ID matches " "the regular expression") diff --git a/src/Filters/Rules/Person/_RegExpName.py b/src/Filters/Rules/Person/_RegExpName.py index 5b72b1468..ab7d6c311 100644 --- a/src/Filters/Rules/Person/_RegExpName.py +++ b/src/Filters/Rules/Person/_RegExpName.py @@ -34,7 +34,6 @@ from gen.ggettext import gettext as _ # #------------------------------------------------------------------------- from Filters.Rules._Rule import Rule -import re #------------------------------------------------------------------------- # @@ -44,25 +43,18 @@ import re class RegExpName(Rule): """Rule that checks for full or partial name matches""" - labels = [_('Expression:')] - name = _('People matching the ') - description = _("Matches people's names with a specified regular expression") + labels = [_('Text:')] + name = _('People with a name matching ') + description = _("Matches people's names containing a substring or " + "matching a regular expression") category = _('General filters') - - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - - try: - self.match = re.compile(list[0],re.I|re.U|re.L) - except re.error: - #indicate error by matching everyone - self.match = re.compile('') + allow_regex = True def apply(self,db,person): for name in [person.get_primary_name()] + person.get_alternate_names(): for field in [name.first_name, name.get_surname(), name.suffix, name.title, name.nick, name.famnick, name.call]: - if self.match.search(field): + if self.match_substring(0, field): return True else: return False diff --git a/src/Filters/Rules/Person/__init__.py b/src/Filters/Rules/Person/__init__.py index 40261fdb8..d4cd9b28b 100644 --- a/src/Filters/Rules/Person/__init__.py +++ b/src/Filters/Rules/Person/__init__.py @@ -186,7 +186,6 @@ editor_rule_list = [ HasTextMatchingSubstringOf, HasNote, HasNoteRegexp, - HasNoteMatchingSubstringOf, RegExpIdOf, Disconnected, ChangedSince, diff --git a/src/Filters/Rules/Place/_HasNoteRegexp.py b/src/Filters/Rules/Place/_HasNoteRegexp.py index 15205f60d..85dabf8dc 100644 --- a/src/Filters/Rules/Place/_HasNoteRegexp.py +++ b/src/Filters/Rules/Place/_HasNoteRegexp.py @@ -39,6 +39,6 @@ from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Places having notes containing ') + name = _('Places having notes containing ') description = _("Matches places whose notes contain text " "matching a regular expression") diff --git a/src/Filters/Rules/Place/_RegExpIdOf.py b/src/Filters/Rules/Place/_RegExpIdOf.py index cb2e99aec..2cbd0a816 100644 --- a/src/Filters/Rules/Place/_RegExpIdOf.py +++ b/src/Filters/Rules/Place/_RegExpIdOf.py @@ -45,6 +45,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Places with matching regular expression') + name = _('Places with Id containing ') description = _("Matches places whose Gramps ID matches " "the regular expression") diff --git a/src/Filters/Rules/Place/__init__.py b/src/Filters/Rules/Place/__init__.py index 5d0c343ef..ffe7a0503 100644 --- a/src/Filters/Rules/Place/__init__.py +++ b/src/Filters/Rules/Place/__init__.py @@ -53,7 +53,6 @@ editor_rule_list = [ HasCitation, HasNote, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, HasSourceOf, HasSourceCount, diff --git a/src/Filters/Rules/Repository/_HasNoteRegexp.py b/src/Filters/Rules/Repository/_HasNoteRegexp.py index a109e245a..b076fe359 100644 --- a/src/Filters/Rules/Repository/_HasNoteRegexp.py +++ b/src/Filters/Rules/Repository/_HasNoteRegexp.py @@ -39,7 +39,6 @@ from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Repositories having notes ' - 'containing ') + name = _('Repositories having notes containing ') description = _("Matches repositories whose notes contain text " "matching a regular expression") diff --git a/src/Filters/Rules/Repository/_MatchesNameSubstringOf.py b/src/Filters/Rules/Repository/_MatchesNameSubstringOf.py index 7a1fa21b1..19e5975b5 100644 --- a/src/Filters/Rules/Repository/_MatchesNameSubstringOf.py +++ b/src/Filters/Rules/Repository/_MatchesNameSubstringOf.py @@ -40,14 +40,12 @@ from Filters.Rules import Rule class MatchesNameSubstringOf(Rule): """Repository name containing """ - labels = [ _('Substring:')] - name = _('Repository name containing ') + labels = [ _('Text:')] + name = _('Repositories with name containing ') description = _("Matches repositories whose name contains a certain substring") category = _('General filters') + allow_regex = True def apply(self, db, repository): """ Apply the filter """ - name = repository.get_name() - if name.upper().find(self.list[0].upper()) != -1: - return True - return False + return self.match_substring(0, repository.get_name()) diff --git a/src/Filters/Rules/Repository/_RegExpIdOf.py b/src/Filters/Rules/Repository/_RegExpIdOf.py index b5463584c..166669733 100644 --- a/src/Filters/Rules/Repository/_RegExpIdOf.py +++ b/src/Filters/Rules/Repository/_RegExpIdOf.py @@ -45,6 +45,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Repositories with matching regular expression') + name = _('Repositories with Id containing ') description = _("Matches repositories whose Gramps ID matches " "the regular expression") diff --git a/src/Filters/Rules/Repository/__init__.py b/src/Filters/Rules/Repository/__init__.py index 8d354e8ee..c158f0988 100644 --- a/src/Filters/Rules/Repository/__init__.py +++ b/src/Filters/Rules/Repository/__init__.py @@ -41,7 +41,6 @@ editor_rule_list = [ HasIdOf, RegExpIdOf, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, RepoPrivate, MatchesFilter, diff --git a/src/Filters/Rules/Source/_HasNoteRegexp.py b/src/Filters/Rules/Source/_HasNoteRegexp.py index 5a98372b9..e75c05cbc 100644 --- a/src/Filters/Rules/Source/_HasNoteRegexp.py +++ b/src/Filters/Rules/Source/_HasNoteRegexp.py @@ -39,6 +39,6 @@ from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase #------------------------------------------------------------------------- class HasNoteRegexp(HasNoteRegexBase): - name = _('Sources having notes containing ') + name = _('Sources having notes containing ') description = _("Matches sources whose notes contain text " "matching a regular expression") diff --git a/src/Filters/Rules/Source/_HasRepositoryCallNumberRef.py b/src/Filters/Rules/Source/_HasRepositoryCallNumberRef.py index 9f4c1f3c8..19ba1625d 100644 --- a/src/Filters/Rules/Source/_HasRepositoryCallNumberRef.py +++ b/src/Filters/Rules/Source/_HasRepositoryCallNumberRef.py @@ -41,19 +41,15 @@ from Filters.Rules import Rule class HasRepositoryCallNumberRef(Rule): """Sources which reference repositories by a special Call Number""" - labels = [ _('Substring:')] - name = _('Sources with repository reference containing in "Call Number"') + labels = [ _('Text:')] + name = _('Sources with repository reference containing in "Call Number"') description = _("Matches sources with a repository reference\n" "containing a substring in \"Call Number\"") category = _('General filters') + allow_regex = True def apply(self, db, obj): - count = len(obj.get_reporef_list()) - if count > 0: - for RepoRef in obj.get_reporef_list(): - if len(RepoRef.call_number) > 0: - CallNumb = RepoRef.call_number - if CallNumb.upper().find(self.list[0].upper()) != -1: - return True - + for repo_ref in obj.get_reporef_list(): + if self.match_substring(0, repo_ref.call_number): + return True return False diff --git a/src/Filters/Rules/Source/_MatchesTitleSubstringOf.py b/src/Filters/Rules/Source/_MatchesTitleSubstringOf.py index cd5039297..929924f62 100644 --- a/src/Filters/Rules/Source/_MatchesTitleSubstringOf.py +++ b/src/Filters/Rules/Source/_MatchesTitleSubstringOf.py @@ -40,15 +40,13 @@ from Filters.Rules import Rule class MatchesTitleSubstringOf(Rule): """Source title containing """ - labels = [ _('Substring:')] - name = _('Sources title containing ') + labels = [ _('Text:')] + name = _('Sources with title containing ') description = _("Matches sources whose title contains a " "certain substring") category = _('General filters') + allow_regex = True def apply(self, db, source): """ Apply the filter """ - title = source.get_title() - if title.upper().find(self.list[0].upper()) != -1: - return True - return False + return self.match_substring(0, source.get_title()) diff --git a/src/Filters/Rules/Source/_RegExpIdOf.py b/src/Filters/Rules/Source/_RegExpIdOf.py index 22563d8ec..9b9610876 100644 --- a/src/Filters/Rules/Source/_RegExpIdOf.py +++ b/src/Filters/Rules/Source/_RegExpIdOf.py @@ -45,6 +45,6 @@ class RegExpIdOf(RegExpIdBase): matches regular expression. """ - name = _('Sources with matching regular expression') + name = _('Sources with Id containing ') description = _("Matches sources whose Gramps ID matches " "the regular expression") diff --git a/src/Filters/Rules/Source/__init__.py b/src/Filters/Rules/Source/__init__.py index 9eef81791..a21479781 100644 --- a/src/Filters/Rules/Source/__init__.py +++ b/src/Filters/Rules/Source/__init__.py @@ -51,7 +51,6 @@ editor_rule_list = [ RegExpIdOf, HasNote, HasNoteRegexp, - HasNoteMatchingSubstringOf, HasReferenceCountOf, SourcePrivate, MatchesFilter, diff --git a/src/Filters/Rules/_HasAttributeBase.py b/src/Filters/Rules/_HasAttributeBase.py index 51893d0a0..f014475ff 100644 --- a/src/Filters/Rules/_HasAttributeBase.py +++ b/src/Filters/Rules/_HasAttributeBase.py @@ -50,6 +50,7 @@ class HasAttributeBase(Rule): description = _("Matches objects with the given attribute " "of a particular value") category = _('General filters') + allow_regex = True def apply(self, db, obj): if not self.list[0]: @@ -60,5 +61,5 @@ class HasAttributeBase(Rule): name_match = attr.get_type() == specified_type if name_match: - return attr.get_value().upper().find(self.list[1].upper()) != -1 + return self.match_substring(1, attr.get_value()) return False diff --git a/src/Filters/Rules/_HasNoteRegexBase.py b/src/Filters/Rules/_HasNoteRegexBase.py index 2e98cdf9a..c35a7bc90 100644 --- a/src/Filters/Rules/_HasNoteRegexBase.py +++ b/src/Filters/Rules/_HasNoteRegexBase.py @@ -41,25 +41,18 @@ from Filters.Rules import Rule class HasNoteRegexBase(Rule): """People having notes containing .""" - labels = [ _('Regular expression:')] - name = _('Objects having notes containing ') - description = _("Matches objects whose notes contain text " - "matching a regular expression") + labels = [ _('Text:')] + name = _('Objects having notes containing ') + description = _("Matches objects whose notes contain a substring " + "or match a regular expression") category = _('General filters') - - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - - try: - self.match = re.compile(list[0],re.I|re.U|re.L) - except: - self.match = re.compile('') + allow_regex = True def apply(self, db, person): notelist = person.get_note_list() for notehandle in notelist: note = db.get_note_from_handle(notehandle) n = note.get() - if self.match.search(n) is not None: + if self.match_substring(0, n) is not None: return True return False diff --git a/src/Filters/Rules/_RegExpIdBase.py b/src/Filters/Rules/_RegExpIdBase.py index 476b3ac4e..14bf30cb1 100644 --- a/src/Filters/Rules/_RegExpIdBase.py +++ b/src/Filters/Rules/_RegExpIdBase.py @@ -45,19 +45,12 @@ class RegExpIdBase(Rule): Rule that checks for an object whose GRAMPS ID matches regular expression. """ - labels = [ _('Regular expression:') ] + labels = [ _('Text:') ] name = _('Objects with ') - description = _("Matches objects whose Gramps ID matches " - "the regular expression") + description = _("Matches objects whose Gramps ID contains a substring " + "or matches a regular expression") category = _('General filters') - - def __init__(self, list, use_regex=False): - Rule.__init__(self, list, use_regex) - - try: - self.match = re.compile(list[0], re.I|re.U|re.L) - except: - self.match = re.compile('') + allow_regex = True def apply(self, db, obj): - return self.match.search(obj.gramps_id) is not None + return self.match_substring(0, obj.gramps_id) diff --git a/src/Filters/Rules/__init__.py b/src/Filters/Rules/__init__.py index 7eddf2f68..d73243cde 100644 --- a/src/Filters/Rules/__init__.py +++ b/src/Filters/Rules/__init__.py @@ -73,6 +73,7 @@ from Filters.Rules._Rule import Rule from Filters.Rules._Everything import Everything from Filters.Rules._HasGrampsId import HasGrampsId +from Filters.Rules._RegExpIdBase import RegExpIdBase from Filters.Rules._IsPrivate import IsPrivate from Filters.Rules._IsPublic import IsPublic from Filters.Rules._HasTextMatchingSubstringOf import HasTextMatchingSubstringOf