* src/Config/_GrampsConfigKeys.py: add config keys for fuzzy date match
* src/RelLib/_CalSdn.py: correct type in comment * src/RelLib/_Date.py: add new match function to match two dates with fuzzy date support (about 2000 matches about 2005). * src/Filters/Rules/_HasEventBase.py: use new match * src/Filters/Rules/MediaObject/_HasMedia.py: use new match * src/Filters/Rules/Person/_HasBirth.py: use new match * src/Filters/Rules/Person/_HasDeath.py: use new match * src/Filters/Rules/Person/_HasFamilyEvent.py: use new match * src/Filters/Rules/_RuleUtils.py: delete, contained old match date routines * src/Filters/Rules/Makefile.am: remove RuleUtils * po/POTFILES.in: remove RuleUtils Based on patch of Douglas S. Blank <dblank@cs.brynmawr.edu>, ticket #1219 svn: r8995
This commit is contained in:
@@ -18,7 +18,6 @@ pkgdata_PYTHON = \
|
||||
_IsPrivate.py\
|
||||
_RegExpIdBase.py\
|
||||
_Rule.py\
|
||||
_RuleUtils.py\
|
||||
_MatchesFilterBase.py\
|
||||
_HasMarkerBase.py
|
||||
|
||||
|
@@ -34,7 +34,6 @@ from gettext import gettext as _
|
||||
#-------------------------------------------------------------------------
|
||||
import DateHandler
|
||||
from Filters.Rules._Rule import Rule
|
||||
from Filters.Rules._RuleUtils import loose_date_cmp
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -73,7 +72,7 @@ class HasMedia(Rule):
|
||||
return False
|
||||
|
||||
if self.date:
|
||||
if not loose_date_cmp(self.date,obj.get_date_object()):
|
||||
if not obj.get_date_object().match(self.date):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
@@ -35,7 +35,6 @@ from gettext import gettext as _
|
||||
import DateHandler
|
||||
from RelLib import EventType,EventRoleType
|
||||
from Filters.Rules._Rule import Rule
|
||||
from Filters.Rules._RuleUtils import loose_date_cmp
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -72,7 +71,7 @@ class HasBirth(Rule):
|
||||
# No match: wrong description
|
||||
continue
|
||||
if self.date:
|
||||
if loose_date_cmp(self.date,event.get_date_object()) == 0:
|
||||
if not event.get_date_object().match(self.date):
|
||||
# No match: wrong date
|
||||
continue
|
||||
if self.list[1]:
|
||||
|
@@ -35,7 +35,6 @@ from gettext import gettext as _
|
||||
import DateHandler
|
||||
from RelLib import EventType,EventRoleType
|
||||
from Filters.Rules._Rule import Rule
|
||||
from Filters.Rules._RuleUtils import loose_date_cmp
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -72,7 +71,7 @@ class HasDeath(Rule):
|
||||
# No match: wrong description
|
||||
continue
|
||||
if self.date:
|
||||
if loose_date_cmp(self.date,event.get_date_object()) == 0:
|
||||
if not event.get_date_object().match(self.date):
|
||||
# No match: wrong date
|
||||
continue
|
||||
if self.list[1]:
|
||||
|
@@ -35,7 +35,6 @@ from gettext import gettext as _
|
||||
import DateHandler
|
||||
from RelLib import EventType
|
||||
from Filters.Rules._Rule import Rule
|
||||
from Filters.Rules._RuleUtils import date_cmp
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -80,7 +79,7 @@ class HasFamilyEvent(Rule):
|
||||
if v and event.get_description().upper().find(v.upper())==-1:
|
||||
val = 0
|
||||
if self.date:
|
||||
if date_cmp(self.date,event.get_date_object()):
|
||||
if event.get_date_object().match(self.date):
|
||||
val = 0
|
||||
if self.list[2]:
|
||||
pl_id = event.get_place_handle()
|
||||
|
@@ -35,7 +35,6 @@ from gettext import gettext as _
|
||||
import DateHandler
|
||||
from RelLib import EventType
|
||||
from Filters.Rules._Rule import Rule
|
||||
from Filters.Rules._RuleUtils import loose_date_cmp
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -74,9 +73,11 @@ class HasEventBase(Rule):
|
||||
if self.list[3] and event.get_description().upper().find(
|
||||
self.list[3].upper())==-1:
|
||||
return False
|
||||
|
||||
if self.date:
|
||||
if not loose_date_cmp(self.date,event.get_date_object()):
|
||||
if not event.get_date_object().match(self.date):
|
||||
return False
|
||||
|
||||
if self.list[2]:
|
||||
pl_id = event.get_place_handle()
|
||||
if pl_id:
|
||||
|
@@ -1,72 +0,0 @@
|
||||
#
|
||||
# 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$
|
||||
|
||||
import RelLib
|
||||
import DateHandler
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Useful functions used by some rules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def date_cmp(rule,value):
|
||||
s = rule.get_modifier()
|
||||
if s == RelLib.Date.MOD_TEXTONLY:
|
||||
# If the entered date did not parse, then we can only compare
|
||||
# the text against the textual representation of the tested date
|
||||
value_text = DateHandler.displayer.display(value)
|
||||
return (value_text.upper().find(rule.text.upper()) != -1)
|
||||
|
||||
sd = rule.get_start_date()
|
||||
od = value.get_start_date()
|
||||
cmp_rule = (sd[2],sd[1],sd[0])
|
||||
cmp_value = (od[2],od[1],od[0])
|
||||
if s == RelLib.Date.MOD_BEFORE:
|
||||
return cmp_rule > cmp_value
|
||||
elif s == RelLib.Date.MOD_AFTER:
|
||||
return cmp_rule < cmp_value
|
||||
else:
|
||||
return cmp_rule == cmp_value
|
||||
|
||||
def loose_date_cmp(rule,value):
|
||||
s = rule.get_modifier()
|
||||
if s == RelLib.Date.MOD_TEXTONLY:
|
||||
# If the entered date did not parse, then we can only compare
|
||||
# the text against the textual representation of the tested date
|
||||
value_text = DateHandler.displayer.display(value)
|
||||
return (value_text.upper().find(rule.text.upper()) != -1)
|
||||
|
||||
sd = rule.get_start_date()
|
||||
od = value.get_start_date()
|
||||
cmp_rule = (sd[2],sd[1],sd[0])
|
||||
cmp_value = (od[2],od[1],od[0])
|
||||
|
||||
if s == RelLib.Date.MOD_BEFORE:
|
||||
return cmp_rule > cmp_value
|
||||
elif s == RelLib.Date.MOD_AFTER:
|
||||
return cmp_rule < cmp_value
|
||||
elif cmp_rule[0] and not cmp_rule[1] and not cmp_rule[2]:
|
||||
return cmp_rule[0] == cmp_value[0]
|
||||
elif cmp_rule[0] and cmp_rule[1] and not cmp_rule[2]:
|
||||
return cmp_rule[0:2] == cmp_value[0:2]
|
||||
else:
|
||||
return cmp_rule == cmp_value
|
Reference in New Issue
Block a user