Add regular expressions to rules
svn: r22823
This commit is contained in:
parent
01a7fd6cf6
commit
927415ee88
@ -73,6 +73,7 @@ from ._rule import Rule
|
||||
|
||||
from ._everything import Everything
|
||||
from ._hasgrampsid import HasGrampsId
|
||||
from ._regexpidbase import RegExpIdBase
|
||||
from ._isprivate import IsPrivate
|
||||
from ._ispublic import IsPublic
|
||||
from ._hastextmatchingsubstringof import HasTextMatchingSubstringOf
|
||||
|
@ -51,6 +51,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]:
|
||||
@ -61,5 +62,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
|
||||
|
@ -37,30 +37,23 @@ _ = glocale.translation.gettext
|
||||
from . import Rule
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# "People having notes that contain a substring"
|
||||
# Objects having notes that contain a substring or match a regular expression
|
||||
#-------------------------------------------------------------------------
|
||||
class HasNoteRegexBase(Rule):
|
||||
"""People having notes containing <substring>."""
|
||||
"""Objects having notes containing <text>."""
|
||||
|
||||
labels = [ _('Regular expression:')]
|
||||
name = 'Objects having notes containing <regular expression>'
|
||||
description = "Matches objects whose notes contain text " \
|
||||
"matching a regular expression"
|
||||
labels = [ _('Text:')]
|
||||
name = 'Objects having notes containing <text>'
|
||||
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
|
||||
|
@ -43,22 +43,16 @@ from . import Rule
|
||||
#-------------------------------------------------------------------------
|
||||
class RegExpIdBase(Rule):
|
||||
"""
|
||||
Rule that checks for an object whose GRAMPS ID matches regular expression.
|
||||
Objects with a Gramps ID that contains a substring or matches a
|
||||
regular expression.
|
||||
"""
|
||||
|
||||
labels = [ _('Regular expression:') ]
|
||||
labels = [ _('Text:') ]
|
||||
name = 'Objects with <Id>'
|
||||
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)
|
||||
|
@ -52,7 +52,6 @@ editor_rule_list = [
|
||||
HasGallery,
|
||||
HasIdOf,
|
||||
HasNote,
|
||||
HasNoteMatchingSubstringOf,
|
||||
HasNoteRegexp,
|
||||
HasReferenceCountOf,
|
||||
HasSource,
|
||||
|
@ -41,6 +41,6 @@ from .._hasnoteregexbase import HasNoteRegexBase
|
||||
#-------------------------------------------------------------------------
|
||||
class HasNoteRegexp(HasNoteRegexBase):
|
||||
|
||||
name = _('Citations having notes containing <regular expression>')
|
||||
name = _('Citations having notes containing <text>')
|
||||
description = _("Matches citations whose notes contain text "
|
||||
"matching a regular expression")
|
||||
|
@ -41,15 +41,13 @@ from .. import Rule
|
||||
class MatchesPageSubstringOf(Rule):
|
||||
"""Citation Volume/Page title containing <substring>"""
|
||||
|
||||
labels = [ _('Substring:')]
|
||||
name = _('Citation Volume/Page containing <substring>')
|
||||
labels = [ _('Text:')]
|
||||
name = _('Citations with Volume/Page containing <text>')
|
||||
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())
|
||||
|
@ -47,6 +47,6 @@ class RegExpIdOf(RegExpIdBase):
|
||||
matches regular expression.
|
||||
"""
|
||||
|
||||
name = _('Citations with <Id> matching regular expression')
|
||||
name = _('Citations with Id containing <text>')
|
||||
description = _("Matches citations whose Gramps ID matches "
|
||||
"the regular expression")
|
||||
|
@ -59,7 +59,6 @@ editor_rule_list = [
|
||||
HasCitation,
|
||||
HasNote,
|
||||
HasNoteRegexp,
|
||||
HasNoteMatchingSubstringOf,
|
||||
HasReferenceCountOf,
|
||||
HasSourceCount,
|
||||
EventPrivate,
|
||||
|
@ -50,7 +50,7 @@ class HasCitation(HasCitationBase):
|
||||
labels = [ _('Volume/Page:'),
|
||||
_('Date:'),
|
||||
_('Confidence level:')]
|
||||
name = _('Event with the <citation>')
|
||||
name = _('Events with the <citation>')
|
||||
description = _("Matches events with a citation of a particular "
|
||||
"value")
|
||||
|
||||
|
@ -50,14 +50,11 @@ class HasData(Rule):
|
||||
name = _('Events with <data>')
|
||||
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()
|
||||
@ -71,26 +68,24 @@ class HasData(Rule):
|
||||
# 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
|
||||
|
@ -40,6 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase
|
||||
#-------------------------------------------------------------------------
|
||||
class HasNoteRegexp(HasNoteRegexBase):
|
||||
|
||||
name = _('Events having notes containing <regular expression>')
|
||||
name = _('Events having notes containing <text>')
|
||||
description = _("Matches events whose notes contain text "
|
||||
"matching a regular expression")
|
||||
|
@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase):
|
||||
matches regular expression.
|
||||
"""
|
||||
|
||||
name = _('Events with <Id> matching regular expression')
|
||||
name = _('Events with Id containing <text>')
|
||||
description = _("Matches events whose Gramps ID matches "
|
||||
"the regular expression")
|
||||
|
@ -54,10 +54,13 @@ from ._matchesfilter import MatchesFilter
|
||||
from ._matchessourceconfidence import MatchesSourceConfidence
|
||||
from ._fatherhasnameof import FatherHasNameOf
|
||||
from ._fatherhasidof import FatherHasIdOf
|
||||
from ._fatherregexpidof import FatherRegExpIdOf
|
||||
from ._motherhasnameof import MotherHasNameOf
|
||||
from ._motherhasidof import MotherHasIdOf
|
||||
from ._motherregexpidof import MotherRegExpIdOf
|
||||
from ._childhasnameof import ChildHasNameOf
|
||||
from ._childhasidof import ChildHasIdOf
|
||||
from ._childregexpidof import ChildRegExpIdOf
|
||||
from ._changedsince import ChangedSince
|
||||
from ._hastag import HasTag
|
||||
from ._hastwins import HasTwins
|
||||
@ -71,7 +74,6 @@ editor_rule_list = [
|
||||
HasNote,
|
||||
RegExpIdOf,
|
||||
HasNoteRegexp,
|
||||
HasNoteMatchingSubstringOf,
|
||||
HasReferenceCountOf,
|
||||
HasSourceCount,
|
||||
HasSourceOf,
|
||||
@ -83,11 +85,11 @@ editor_rule_list = [
|
||||
MatchesFilter,
|
||||
MatchesSourceConfidence,
|
||||
FatherHasNameOf,
|
||||
FatherHasIdOf,
|
||||
FatherRegExpIdOf,
|
||||
MotherHasNameOf,
|
||||
MotherHasIdOf,
|
||||
MotherRegExpIdOf,
|
||||
ChildHasNameOf,
|
||||
ChildHasIdOf,
|
||||
ChildRegExpIdOf,
|
||||
ChangedSince,
|
||||
HasTag,
|
||||
HasTwins,
|
||||
|
53
gramps/gen/filters/rules/family/_childregexpidof.py
Normal file
53
gramps/gen/filters/rules/family/_childregexpidof.py
Normal file
@ -0,0 +1,53 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2002-2006 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Standard Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ....const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from .. import RegExpIdBase
|
||||
from ._memberbase import child_base
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# HasNameOf
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class ChildRegExpIdOf(RegExpIdBase):
|
||||
"""Rule that checks for a person with a specific GRAMPS ID"""
|
||||
|
||||
labels = [ _('Person ID:') ]
|
||||
name = _('Families having child with Id containing <text>')
|
||||
description = _("Matches families where child has a specified "
|
||||
"Gramps ID")
|
||||
category = _('Child filters')
|
||||
base_class = RegExpIdBase
|
||||
apply = child_base
|
53
gramps/gen/filters/rules/family/_fatherregexpidof.py
Normal file
53
gramps/gen/filters/rules/family/_fatherregexpidof.py
Normal file
@ -0,0 +1,53 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2002-2006 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Standard Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ....const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from .. import RegExpIdBase
|
||||
from ._memberbase import father_base
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# HasNameOf
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class FatherRegExpIdOf(RegExpIdBase):
|
||||
"""Rule that checks for a person with a specific GRAMPS ID"""
|
||||
|
||||
labels = [ _('Person ID:') ]
|
||||
name = _('Families having father with Id containing <text>')
|
||||
description = _("Matches families whose father has a specified "
|
||||
"Gramps ID")
|
||||
category = _('Father filters')
|
||||
base_class = RegExpIdBase
|
||||
apply = father_base
|
@ -50,6 +50,6 @@ class HasCitation(HasCitationBase):
|
||||
labels = [ _('Volume/Page:'),
|
||||
_('Date:'),
|
||||
_('Confidence level:')]
|
||||
name = _('Family with the <citation>')
|
||||
name = _('Families with the <citation>')
|
||||
description = _("Matches families with a citation of a particular "
|
||||
"value")
|
||||
|
@ -40,7 +40,7 @@ from .._hasnoteregexbase import HasNoteRegexBase
|
||||
#-------------------------------------------------------------------------
|
||||
class HasNoteRegexp(HasNoteRegexBase):
|
||||
|
||||
name = _('Families having notes containing <regular expression>')
|
||||
name = _('Families having notes containing <text>')
|
||||
description = _("Matches families whose notes contain text "
|
||||
"matching a regular expression")
|
||||
|
||||
|
53
gramps/gen/filters/rules/family/_motherregexpidof.py
Normal file
53
gramps/gen/filters/rules/family/_motherregexpidof.py
Normal file
@ -0,0 +1,53 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2002-2006 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Standard Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ....const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from .. import RegExpIdBase
|
||||
from ._memberbase import mother_base
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# HasNameOf
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class MotherRegExpIdOf(RegExpIdBase):
|
||||
"""Rule that checks for a person with a specific GRAMPS ID"""
|
||||
|
||||
labels = [ _('Person ID:') ]
|
||||
name = _('Families having mother with Id containing <text>')
|
||||
description = _("Matches families whose mother has a specified "
|
||||
"Gramps ID")
|
||||
category = _('Mother filters')
|
||||
base_class = RegExpIdBase
|
||||
apply = mother_base
|
@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase):
|
||||
matches regular expression.
|
||||
"""
|
||||
|
||||
name = _('Families with <Id> matching regular expression')
|
||||
name = _('Families with Id containing <text>')
|
||||
description = _("Matches families whose Gramps ID matches "
|
||||
"the regular expression")
|
||||
|
@ -47,7 +47,6 @@ editor_rule_list = [
|
||||
HasIdOf,
|
||||
RegExpIdOf,
|
||||
HasNoteRegexp,
|
||||
HasNoteMatchingSubstringOf,
|
||||
HasReferenceCountOf,
|
||||
HasSourceCount,
|
||||
HasSourceOf,
|
||||
|
@ -40,7 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase
|
||||
#-------------------------------------------------------------------------
|
||||
class HasNoteRegexp(HasNoteRegexBase):
|
||||
|
||||
name = _('Media objects having notes '
|
||||
'containing <regular expression>')
|
||||
name = _('Media objects having notes containing <text>')
|
||||
description = _("Matches media objects whose notes contain text "
|
||||
"matching a regular expression")
|
||||
|
@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase):
|
||||
matches regular expression.
|
||||
"""
|
||||
|
||||
name = _('Media Objects with <Id> matching regular expression')
|
||||
name = _('Media objects with Id containing <text>')
|
||||
description = _("Matches media objects whose Gramps ID matches "
|
||||
"the regular expression")
|
||||
|
@ -44,7 +44,6 @@ editor_rule_list = [
|
||||
RegExpIdOf,
|
||||
HasNote,
|
||||
MatchesRegexpOf,
|
||||
MatchesSubstringOf,
|
||||
HasReferenceCountOf,
|
||||
NotePrivate,
|
||||
MatchesFilter,
|
||||
|
@ -51,6 +51,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]:
|
||||
|
@ -38,27 +38,20 @@ _ = glocale.translation.gettext
|
||||
from .. import Rule
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# "Repos having notes that contain a substring"
|
||||
# Notes that contain a substring or match a regular expression
|
||||
#-------------------------------------------------------------------------
|
||||
class MatchesRegexpOf(Rule):
|
||||
|
||||
labels = [ _('Regular expression:')]
|
||||
name = _('Notes containing <regular expression>')
|
||||
description = _("Matches notes that contain text "
|
||||
"which matches a regular expression")
|
||||
labels = [ _('Text:')]
|
||||
name = _('Notes containing <text>')
|
||||
description = _("Matches notes that contain a substring "
|
||||
"or match 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
|
||||
|
@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase):
|
||||
matches regular expression.
|
||||
"""
|
||||
|
||||
name = _('Notes with <Id> matching regular expression')
|
||||
name = _('Notes with Id containing <text>')
|
||||
description = _("Matches notes whose Gramps ID matches "
|
||||
"the regular expression")
|
||||
|
@ -187,7 +187,6 @@ editor_rule_list = [
|
||||
HasTextMatchingSubstringOf,
|
||||
HasNote,
|
||||
HasNoteRegexp,
|
||||
HasNoteMatchingSubstringOf,
|
||||
RegExpIdOf,
|
||||
Disconnected,
|
||||
ChangedSince,
|
||||
|
@ -50,9 +50,9 @@ class HasBirth(Rule):
|
||||
name = _('People with the <birth data>')
|
||||
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 = parser.parse(self.list[0])
|
||||
else:
|
||||
@ -69,9 +69,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:
|
||||
@ -79,11 +77,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:
|
||||
|
@ -50,9 +50,9 @@ class HasDeath(Rule):
|
||||
name = _('People with the <death data>')
|
||||
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 = parser.parse(self.list[0])
|
||||
else:
|
||||
@ -69,9 +69,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:
|
||||
@ -79,11 +77,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:
|
||||
|
@ -48,6 +48,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]:
|
||||
@ -59,8 +60,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
|
||||
|
@ -53,6 +53,7 @@ class HasFamilyEvent(Rule):
|
||||
name = _('People with the family <event>')
|
||||
description = _("Matches people with a family event of a particular value")
|
||||
category = _('Event filters')
|
||||
allow_regex = True
|
||||
|
||||
def prepare(self,db):
|
||||
self.date = None
|
||||
@ -78,18 +79,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
|
||||
|
@ -40,7 +40,7 @@ from .._hasnoteregexbase import HasNoteRegexBase
|
||||
#-------------------------------------------------------------------------
|
||||
class HasNoteRegexp(HasNoteRegexBase):
|
||||
|
||||
name = _('People having notes containing <regular expression>')
|
||||
name = _('People having notes containing <text>')
|
||||
description = _("Matches people whose notes contain text "
|
||||
"matching a regular expression")
|
||||
|
||||
|
@ -45,6 +45,6 @@ class RegExpIdOf(RegExpIdBase):
|
||||
matches regular expression.
|
||||
"""
|
||||
|
||||
name = _('People with <Id> matching regular expression')
|
||||
name = _('People with Id containing <text>')
|
||||
description = _("Matches people whose Gramps ID matches "
|
||||
"the regular expression")
|
||||
|
@ -45,25 +45,18 @@ import re
|
||||
class RegExpName(Rule):
|
||||
"""Rule that checks for full or partial name matches"""
|
||||
|
||||
labels = [_('Expression:')]
|
||||
name = _('People matching the <regex_name>')
|
||||
description = _("Matches people's names with a specified regular expression")
|
||||
labels = [_('Text:')]
|
||||
name = _('People with a name matching <text>')
|
||||
description = _("Matches people's names with 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
|
||||
|
@ -54,7 +54,6 @@ editor_rule_list = [
|
||||
RegExpIdOf,
|
||||
HasNote,
|
||||
HasNoteRegexp,
|
||||
HasNoteMatchingSubstringOf,
|
||||
HasReferenceCountOf,
|
||||
HasSourceCount,
|
||||
HasSourceOf,
|
||||
|
@ -40,6 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase
|
||||
#-------------------------------------------------------------------------
|
||||
class HasNoteRegexp(HasNoteRegexBase):
|
||||
|
||||
name = _('Places having notes containing <regular expression>')
|
||||
name = _('Places having notes containing <text>')
|
||||
description = _("Matches places whose notes contain text "
|
||||
"matching a regular expression")
|
||||
|
@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase):
|
||||
matches regular expression.
|
||||
"""
|
||||
|
||||
name = _('Places with <Id> matching regular expression')
|
||||
name = _('Places with Id containing <text>')
|
||||
description = _("Matches places whose Gramps ID matches "
|
||||
"the regular expression")
|
||||
|
@ -42,7 +42,6 @@ editor_rule_list = [
|
||||
HasIdOf,
|
||||
RegExpIdOf,
|
||||
HasNoteRegexp,
|
||||
HasNoteMatchingSubstringOf,
|
||||
HasReferenceCountOf,
|
||||
RepoPrivate,
|
||||
MatchesFilter,
|
||||
|
@ -40,7 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase
|
||||
#-------------------------------------------------------------------------
|
||||
class HasNoteRegexp(HasNoteRegexBase):
|
||||
|
||||
name = _('Repositories having notes '
|
||||
'containing <regular expression>')
|
||||
name = _('Repositories having notes containing <text>')
|
||||
description = _("Matches repositories whose notes contain text "
|
||||
"matching a regular expression")
|
||||
|
@ -41,14 +41,12 @@ from .. import Rule
|
||||
class MatchesNameSubstringOf(Rule):
|
||||
"""Repository name containing <substring>"""
|
||||
|
||||
labels = [ _('Substring:')]
|
||||
name = _('Repository name containing <substring>')
|
||||
labels = [ _('Text:')]
|
||||
name = _('Repositories with name containing <text>')
|
||||
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())
|
||||
|
@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase):
|
||||
matches regular expression.
|
||||
"""
|
||||
|
||||
name = _('Repositories with <Id> matching regular expression')
|
||||
name = _('Repositories with Id containing <text>')
|
||||
description = _("Matches repositories whose Gramps ID matches "
|
||||
"the regular expression")
|
||||
|
@ -52,7 +52,6 @@ editor_rule_list = [
|
||||
RegExpIdOf,
|
||||
HasNote,
|
||||
HasNoteRegexp,
|
||||
HasNoteMatchingSubstringOf,
|
||||
HasReferenceCountOf,
|
||||
SourcePrivate,
|
||||
MatchesFilter,
|
||||
|
@ -40,6 +40,6 @@ from .._hasnoteregexbase import HasNoteRegexBase
|
||||
#-------------------------------------------------------------------------
|
||||
class HasNoteRegexp(HasNoteRegexBase):
|
||||
|
||||
name = _('Sources having notes containing <regular expression>')
|
||||
name = _('Sources having notes containing <text>')
|
||||
description = _("Matches sources whose notes contain text "
|
||||
"matching a regular expression")
|
||||
|
@ -42,19 +42,15 @@ from .. import Rule
|
||||
class HasRepositoryCallNumberRef(Rule):
|
||||
"""Sources which reference repositories by a special Call Number"""
|
||||
|
||||
labels = [ _('Substring:')]
|
||||
name = _('Sources with repository reference containing <substring> in "Call Number"')
|
||||
labels = [ _('Text:')]
|
||||
name = _('Sources with repository reference containing <text> 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
|
||||
|
@ -41,15 +41,13 @@ from .. import Rule
|
||||
class MatchesTitleSubstringOf(Rule):
|
||||
"""Source title containing <substring>"""
|
||||
|
||||
labels = [ _('Substring:')]
|
||||
name = _('Sources title containing <substring>')
|
||||
labels = [ _('Text:')]
|
||||
name = _('Sources with title containing <text>')
|
||||
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())
|
||||
|
@ -46,6 +46,6 @@ class RegExpIdOf(RegExpIdBase):
|
||||
matches regular expression.
|
||||
"""
|
||||
|
||||
name = _('Sources with <Id> matching regular expression')
|
||||
name = _('Sources with Id containing <text>')
|
||||
description = _("Matches sources whose Gramps ID matches "
|
||||
"the regular expression")
|
||||
|
@ -81,9 +81,11 @@ gramps/gen/filters/rules/family/_allfamilies.py
|
||||
gramps/gen/filters/rules/family/_changedsince.py
|
||||
gramps/gen/filters/rules/family/_childhasidof.py
|
||||
gramps/gen/filters/rules/family/_childhasnameof.py
|
||||
gramps/gen/filters/rules/family/_childregexpidof.py
|
||||
gramps/gen/filters/rules/family/_familyprivate.py
|
||||
gramps/gen/filters/rules/family/_fatherhasidof.py
|
||||
gramps/gen/filters/rules/family/_fatherhasnameof.py
|
||||
gramps/gen/filters/rules/family/_fatherregexpidof.py
|
||||
gramps/gen/filters/rules/family/_hasattribute.py
|
||||
gramps/gen/filters/rules/family/_hascitation.py
|
||||
gramps/gen/filters/rules/family/_hasevent.py
|
||||
@ -104,6 +106,7 @@ gramps/gen/filters/rules/family/_matchesfilter.py
|
||||
gramps/gen/filters/rules/family/_matchessourceconfidence.py
|
||||
gramps/gen/filters/rules/family/_motherhasidof.py
|
||||
gramps/gen/filters/rules/family/_motherhasnameof.py
|
||||
gramps/gen/filters/rules/family/_motherregexpidof.py
|
||||
gramps/gen/filters/rules/family/_regexpchildname.py
|
||||
gramps/gen/filters/rules/family/_regexpfathername.py
|
||||
gramps/gen/filters/rules/family/_regexpidof.py
|
||||
|
Loading…
Reference in New Issue
Block a user