Fix regular expressions in sidebar filters

svn: r22966
This commit is contained in:
Nick Hall 2013-08-30 20:33:09 +00:00
parent 6da4a00375
commit 4ee02a80af
9 changed files with 38 additions and 111 deletions

View File

@ -44,9 +44,8 @@ from gui.widgets import MonitoredMenu, DateEntry
import gen.lib import gen.lib
from Filters.SideBar import SidebarFilter from Filters.SideBar import SidebarFilter
from Filters import GenericFilterFactory, build_filter_model, Rules from Filters import GenericFilterFactory, build_filter_model, Rules
from Filters.Rules.Citation import (RegExpIdOf, HasIdOf, HasCitation, from Filters.Rules.Citation import (RegExpIdOf, HasCitation, HasNoteRegexp,
HasNoteMatchingSubstringOf, HasNoteRegexp, MatchesFilter)
MatchesFilter)
from Utils import confidence from Utils import confidence
GenericCitationFilter = GenericFilterFactory('Citation') GenericCitationFilter = GenericFilterFactory('Citation')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -130,20 +129,14 @@ class CitationSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericCitationFilter() generic_filter = GenericCitationFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasCitation([page, date, conf], use_regex=regex) rule = HasCitation([page, date, conf], use_regex=regex)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if self.generic.get_active() != 0: if self.generic.get_active() != 0:

View File

@ -44,8 +44,7 @@ import gen.lib
from Filters.SideBar import SidebarFilter from Filters.SideBar import SidebarFilter
from Filters import GenericFilterFactory, build_filter_model, Rules from Filters import GenericFilterFactory, build_filter_model, Rules
from Filters.Rules.Event import (RegExpIdOf, HasIdOf, HasNoteRegexp, from Filters.Rules.Event import (RegExpIdOf, HasNoteRegexp, MatchesFilter,
HasNoteMatchingSubstringOf, MatchesFilter,
HasEvent) HasEvent)
GenericEventFilter = GenericFilterFactory('Event') GenericEventFilter = GenericFilterFactory('Event')
@ -128,10 +127,7 @@ class EventSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericEventFilter() generic_filter = GenericEventFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasEvent([etype, date, place, desc, mainparts], rule = HasEvent([etype, date, place, desc, mainparts],
@ -139,10 +135,7 @@ class EventSidebarFilter(SidebarFilter):
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if self.generic.get_active() != 0: if self.generic.get_active() != 0:

View File

@ -45,12 +45,9 @@ import gen.lib
from Filters.SideBar import SidebarFilter from Filters.SideBar import SidebarFilter
from Filters import GenericFilterFactory, build_filter_model, Rules from Filters import GenericFilterFactory, build_filter_model, Rules
from Filters.Rules.Family import (RegExpIdOf, HasIdOf, RegExpFatherName, from Filters.Rules.Family import (RegExpIdOf, HasEvent, RegExpFatherName,
SearchFatherName, RegExpMotherName, RegExpMotherName, RegExpChildName, HasTag,
SearchMotherName, RegExpChildName, HasRelType, HasNoteRegexp, MatchesFilter)
SearchChildName, HasEvent, HasRelType,
HasTag, HasNoteRegexp,
HasNoteMatchingSubstringOf, MatchesFilter)
GenericFamilyFilter = GenericFilterFactory('Family') GenericFamilyFilter = GenericFilterFactory('Family')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -152,31 +149,19 @@ class FamilySidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericFamilyFilter() generic_filter = GenericFamilyFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if father: if father:
if regex: rule = RegExpFatherName([father], use_regex=regex)
rule = RegExpFatherName([father])
else:
rule = SearchFatherName([father])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if mother: if mother:
if regex: rule = RegExpMotherName([mother], use_regex=regex)
rule = RegExpMotherName([mother])
else:
rule = SearchMotherName([mother])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if child: if child:
if regex: rule = RegExpChildName([child], use_regex=regex)
rule = RegExpChildName([child])
else:
rule = SearchChildName([child])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if etype: if etype:
@ -188,10 +173,7 @@ class FamilySidebarFilter(SidebarFilter):
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -43,9 +43,8 @@ import gtk
from gui import widgets from gui import widgets
from Filters.SideBar import SidebarFilter from Filters.SideBar import SidebarFilter
from Filters import GenericFilterFactory, build_filter_model, Rules from Filters import GenericFilterFactory, build_filter_model, Rules
from Filters.Rules.MediaObject import (RegExpIdOf, HasIdOf, HasMedia, HasTag, from Filters.Rules.MediaObject import (RegExpIdOf, HasMedia, HasTag,
HasNoteRegexp, MatchesFilter, HasNoteRegexp, MatchesFilter)
HasNoteMatchingSubstringOf)
GenericMediaFilter = GenericFilterFactory('MediaObject') GenericMediaFilter = GenericFilterFactory('MediaObject')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -123,20 +122,14 @@ class MediaSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericMediaFilter() generic_filter = GenericMediaFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasMedia([title, mime, path, date], use_regex=regex) rule = HasMedia([title, mime, path, date], use_regex=regex)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -45,8 +45,7 @@ from gen.lib import Note, NoteType
from Filters.SideBar import SidebarFilter from Filters.SideBar import SidebarFilter
from Filters import GenericFilterFactory, build_filter_model, Rules from Filters import GenericFilterFactory, build_filter_model, Rules
from Filters.Rules.Note import (RegExpIdOf, HasIdOf, HasNote, MatchesFilter, from Filters.Rules.Note import RegExpIdOf, HasNote, MatchesFilter, HasTag
HasTag)
GenericNoteFilter = GenericFilterFactory('Note') GenericNoteFilter = GenericFilterFactory('Note')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -120,10 +119,7 @@ class NoteSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericNoteFilter() generic_filter = GenericNoteFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasNote([text, ntype], use_regex=regex) rule = HasNote([text, ntype], use_regex=regex)

View File

@ -46,10 +46,9 @@ import gen.lib
import DateHandler import DateHandler
from Filters.SideBar import SidebarFilter from Filters.SideBar import SidebarFilter
from Filters.Rules.Person import (RegExpName, SearchName, RegExpIdOf, MatchIdOf, from Filters.Rules.Person import (RegExpName, RegExpIdOf, IsMale, IsFemale,
IsMale, IsFemale, HasUnknownGender, HasEvent, HasUnknownGender, HasEvent, HasTag, HasBirth,
HasTag, HasBirth, HasDeath, HasNoteRegexp, HasDeath, HasNoteRegexp, MatchesFilter)
HasNoteMatchingSubstringOf, MatchesFilter)
from Filters import GenericFilter, build_filter_model, Rules from Filters import GenericFilter, build_filter_model, Rules
def extract_text(entry_widget): def extract_text(entry_widget):
@ -182,19 +181,13 @@ class PersonSidebarFilter(SidebarFilter):
# if the name is not empty, choose either the regular expression # if the name is not empty, choose either the regular expression
# version or the normal text match # version or the normal text match
if name: if name:
if regex: rule = RegExpName([name], use_regex=regex)
rule = RegExpName([name])
else:
rule = SearchName([name])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# if the id is not empty, choose either the regular expression # if the id is not empty, choose either the regular expression
# version or the normal text match # version or the normal text match
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = MatchIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the gender, and select the right rule based on gender # check the gender, and select the right rule based on gender
@ -226,10 +219,7 @@ class PersonSidebarFilter(SidebarFilter):
# Build note filter if needed # Build note filter if needed
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
# check the Tag # check the Tag

View File

@ -44,8 +44,8 @@ import gtk
from gui import widgets from gui import widgets
from Filters.SideBar import SidebarFilter from Filters.SideBar import SidebarFilter
from Filters import GenericFilterFactory, build_filter_model, Rules from Filters import GenericFilterFactory, build_filter_model, Rules
from Filters.Rules.Place import (RegExpIdOf, HasIdOf, HasPlace, HasNoteRegexp, from Filters.Rules.Place import (RegExpIdOf, HasPlace, HasNoteRegexp,
HasNoteMatchingSubstringOf, MatchesFilter) MatchesFilter)
GenericPlaceFilter = GenericFilterFactory('Place') GenericPlaceFilter = GenericFilterFactory('Place')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -133,10 +133,7 @@ class PlaceSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericPlaceFilter() generic_filter = GenericPlaceFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasPlace([title, street, locality, city, county, state, rule = HasPlace([title, street, locality, city, county, state,
@ -144,10 +141,7 @@ class PlaceSidebarFilter(SidebarFilter):
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if self.generic.get_active() != 0: if self.generic.get_active() != 0:

View File

@ -44,9 +44,8 @@ from gen.lib import Repository, RepositoryType
from Filters.SideBar import SidebarFilter from Filters.SideBar import SidebarFilter
from Filters import GenericFilterFactory, build_filter_model, Rules from Filters import GenericFilterFactory, build_filter_model, Rules
from Filters.Rules.Repository import (RegExpIdOf, HasIdOf, HasRepo, from Filters.Rules.Repository import (RegExpIdOf, HasRepo, HasNoteRegexp,
HasNoteRegexp, MatchesFilter, MatchesFilter)
HasNoteMatchingSubstringOf)
GenericRepoFilter = GenericFilterFactory('Repository') GenericRepoFilter = GenericFilterFactory('Repository')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -124,20 +123,14 @@ class RepoSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericRepoFilter() generic_filter = GenericRepoFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasRepo([title, rtype, address, url], use_regex=regex) rule = HasRepo([title, rtype, address, url], use_regex=regex)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if self.generic.get_active() != 0: if self.generic.get_active() != 0:

View File

@ -42,8 +42,7 @@ import gtk
from gui import widgets from gui import widgets
from Filters.SideBar import SidebarFilter from Filters.SideBar import SidebarFilter
from Filters import GenericFilterFactory, build_filter_model, Rules from Filters import GenericFilterFactory, build_filter_model, Rules
from Filters.Rules.Source import (RegExpIdOf, HasIdOf, HasSource, from Filters.Rules.Source import (RegExpIdOf, HasSource, HasNoteRegexp,
HasNoteMatchingSubstringOf, HasNoteRegexp,
MatchesFilter) MatchesFilter)
GenericSourceFilter = GenericFilterFactory('Source') GenericSourceFilter = GenericFilterFactory('Source')
@ -112,20 +111,14 @@ class SourceSidebarFilter(SidebarFilter):
else: else:
generic_filter = GenericSourceFilter() generic_filter = GenericSourceFilter()
if gid: if gid:
if regex: rule = RegExpIdOf([gid], use_regex=regex)
rule = RegExpIdOf([gid])
else:
rule = HasIdOf([gid])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasSource([title, author, abbr, pub], use_regex=regex) rule = HasSource([title, author, abbr, pub], use_regex=regex)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if note: if note:
if regex: rule = HasNoteRegexp([note], use_regex=regex)
rule = HasNoteRegexp([note])
else:
rule = HasNoteMatchingSubstringOf([note])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if self.generic.get_active() != 0: if self.generic.get_active() != 0: