Backport regular expression enhancements from gramps40

svn: r22837
This commit is contained in:
Nick Hall 2013-08-09 21:35:05 +00:00
parent 8921c21160
commit ffab79499d
49 changed files with 152 additions and 281 deletions

View File

@ -40,6 +40,6 @@ from Filters.Rules._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")

View File

@ -40,15 +40,13 @@ from Filters.Rules 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())

View File

@ -46,6 +46,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")

View File

@ -51,7 +51,6 @@ editor_rule_list = [
HasGallery,
HasIdOf,
HasNote,
HasNoteMatchingSubstringOf,
HasNoteRegexp,
HasReferenceCountOf,
HasSource,

View File

@ -49,7 +49,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")

View File

@ -49,47 +49,42 @@ 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()
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

View File

@ -39,6 +39,6 @@ from Filters.Rules._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")

View File

@ -45,6 +45,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")

View File

@ -58,7 +58,6 @@ editor_rule_list = [
HasCitation,
HasNote,
HasNoteRegexp,
HasNoteMatchingSubstringOf,
HasReferenceCountOf,
HasSourceCount,
EventPrivate,

View File

@ -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 <Id>')
name = _('Families having child with Id containing <text>')
description = _("Matches families where child has a specified "
"Gramps ID")
category = _('Child filters')
base_class = HasGrampsId
base_class = RegExpIdBase
apply = child_base

View File

@ -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 <Id>')
name = _('Families having father with Id containing <text>')
description = _("Matches families whose father has a specified "
"Gramps ID")
category = _('Father filters')
base_class = HasGrampsId
base_class = RegExpIdBase
apply = father_base

View File

@ -49,6 +49,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")

View File

@ -39,7 +39,7 @@ from Filters.Rules._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")

View File

@ -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 <Id>')
name = _('Families having mother with Id containing <text>')
description = _("Matches families whose mother has a specified "
"Gramps ID")
category = _('Mother filters')
base_class = HasGrampsId
base_class = RegExpIdBase
apply = mother_base

View File

@ -45,6 +45,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")

View File

@ -70,7 +70,6 @@ editor_rule_list = [
HasNote,
RegExpIdOf,
HasNoteRegexp,
HasNoteMatchingSubstringOf,
HasReferenceCountOf,
HasSourceCount,
HasSourceOf,

View File

@ -39,7 +39,6 @@ from Filters.Rules._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")

View File

@ -45,6 +45,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")

View File

@ -47,7 +47,6 @@ editor_rule_list = [
RegExpIdOf,
HasCitation,
HasNoteRegexp,
HasNoteMatchingSubstringOf,
HasReferenceCountOf,
HasSourceCount,
HasSourceOf,

View File

@ -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]:

View File

@ -42,22 +42,15 @@ from Filters.Rules import Rule
class MatchesRegexpOf(Rule):
labels = [ _('Regular expression:')]
name = _('Notes containing <regular expression>')
name = _('Notes containing <text>')
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

View File

@ -45,6 +45,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")

View File

@ -43,7 +43,6 @@ editor_rule_list = [
RegExpIdOf,
HasNote,
MatchesRegexpOf,
MatchesSubstringOf,
HasReferenceCountOf,
NotePrivate,
MatchesFilter,

View File

@ -48,11 +48,11 @@ 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 = 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:

View File

@ -48,11 +48,11 @@ 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 = 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:

View File

@ -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

View File

@ -52,12 +52,13 @@ 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
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

View File

@ -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 <name>')
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

View File

@ -39,7 +39,7 @@ from Filters.Rules._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")

View File

@ -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 <substring>')
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)

View File

@ -44,6 +44,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")

View File

@ -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 <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 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

View File

@ -186,7 +186,6 @@ editor_rule_list = [
HasTextMatchingSubstringOf,
HasNote,
HasNoteRegexp,
HasNoteMatchingSubstringOf,
RegExpIdOf,
Disconnected,
ChangedSince,

View File

@ -39,6 +39,6 @@ from Filters.Rules._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")

View File

@ -45,6 +45,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")

View File

@ -53,7 +53,6 @@ editor_rule_list = [
HasCitation,
HasNote,
HasNoteRegexp,
HasNoteMatchingSubstringOf,
HasReferenceCountOf,
HasSourceOf,
HasSourceCount,

View File

@ -39,7 +39,6 @@ from Filters.Rules._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")

View File

@ -40,14 +40,12 @@ from Filters.Rules 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())

View File

@ -45,6 +45,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")

View File

@ -41,7 +41,6 @@ editor_rule_list = [
HasIdOf,
RegExpIdOf,
HasNoteRegexp,
HasNoteMatchingSubstringOf,
HasReferenceCountOf,
RepoPrivate,
MatchesFilter,

View File

@ -39,6 +39,6 @@ from Filters.Rules._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")

View File

@ -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 <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

View File

@ -40,15 +40,13 @@ from Filters.Rules 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())

View File

@ -45,6 +45,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")

View File

@ -51,7 +51,6 @@ editor_rule_list = [
RegExpIdOf,
HasNote,
HasNoteRegexp,
HasNoteMatchingSubstringOf,
HasReferenceCountOf,
SourcePrivate,
MatchesFilter,

View File

@ -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

View File

@ -41,25 +41,18 @@ from Filters.Rules import Rule
class HasNoteRegexBase(Rule):
"""People having notes containing <substring>."""
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

View File

@ -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 <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)

View File

@ -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