From 5e0c4d074aea97537ef2660e5f2557dd4a573d6c Mon Sep 17 00:00:00 2001 From: Tim G L Lyons Date: Sun, 16 Oct 2011 21:09:49 +0000 Subject: [PATCH] Updated Filters and Filters/Rules for citations * renamed HasSourceBase to HasSourceCountBase to reflect function, and because HasSourceBase is changed to be more widely used * consequent renaming of filters for various object types * changed source filters to a new 'Citation/source filters' category * added Citation/_HasSource to check whether Citation refers to a Source with particular properties * added Person/_HasCitation, Event/_HasCitation and Family/_HasCitation to check whether object refers to a Citation with particular properties * updated Citation/_MatchesSourceFilter * updated Rules/_MatchesSourceConfidenceBase * updated Rules/_MatchesSourceFilterBase * updated Citation object and citationbase.py for source references * updated Person/_HasSourceOf * updated comments in Filters/Rules/__init__.py to document how the various rules are used. svn: r18339 --- src/Filters/Rules/Citation/Makefile.am | 1 + .../Rules/{Source => Citation}/_HasSource.py | 37 +++++----- .../Rules/Citation/_MatchesSourceFilter.py | 21 ++++-- src/Filters/Rules/Citation/__init__.py | 2 + src/Filters/Rules/Event/Makefile.am | 3 +- src/Filters/Rules/Event/_HasCitation.py | 61 ++++++++++++++++ .../{_HasSource.py => _HasSourceCount.py} | 6 +- .../Rules/Event/_MatchesSourceFilter.py | 2 +- src/Filters/Rules/Event/__init__.py | 6 +- src/Filters/Rules/Family/Makefile.am | 3 +- src/Filters/Rules/Family/_HasCitation.py | 61 ++++++++++++++++ .../{_HasSource.py => _HasSourceCount.py} | 4 +- src/Filters/Rules/Family/__init__.py | 6 +- src/Filters/Rules/Makefile.am | 1 + src/Filters/Rules/Person/Makefile.am | 3 +- src/Filters/Rules/Person/_HasCitation.py | 60 ++++++++++++++++ .../{_HasSource.py => _HasSourceCount.py} | 4 +- src/Filters/Rules/Person/_HasSourceOf.py | 16 +++-- src/Filters/Rules/Person/__init__.py | 6 +- src/Filters/Rules/Source/__init__.py | 3 +- src/Filters/Rules/_HasCitationBase.py | 2 +- src/Filters/Rules/_HasSourceBase.py | 49 ++++++------- src/Filters/Rules/_HasSourceCountBase.py | 70 +++++++++++++++++++ .../Rules/_MatchesSourceConfidenceBase.py | 9 +-- src/Filters/Rules/_MatchesSourceFilterBase.py | 8 +-- src/Filters/Rules/__init__.py | 40 +++++++++++ src/gen/lib/citation.py | 17 ++--- src/gen/lib/citationbase.py | 14 ++++ 28 files changed, 425 insertions(+), 90 deletions(-) rename src/Filters/Rules/{Source => Citation}/_HasSource.py (69%) create mode 100644 src/Filters/Rules/Event/_HasCitation.py rename src/Filters/Rules/Event/{_HasSource.py => _HasSourceCount.py} (93%) create mode 100644 src/Filters/Rules/Family/_HasCitation.py rename src/Filters/Rules/Family/{_HasSource.py => _HasSourceCount.py} (93%) create mode 100644 src/Filters/Rules/Person/_HasCitation.py rename src/Filters/Rules/Person/{_HasSource.py => _HasSourceCount.py} (93%) mode change 100755 => 100644 src/Filters/Rules/_HasSourceBase.py create mode 100755 src/Filters/Rules/_HasSourceCountBase.py diff --git a/src/Filters/Rules/Citation/Makefile.am b/src/Filters/Rules/Citation/Makefile.am index 0ac6f4d1a..2ce89afa3 100644 --- a/src/Filters/Rules/Citation/Makefile.am +++ b/src/Filters/Rules/Citation/Makefile.am @@ -13,6 +13,7 @@ pkgdata_PYTHON = \ _HasNoteMatchingSubstringOf.py \ _HasNoteRegexp.py \ _HasReferenceCountOf.py \ + _HasSource.py \ _MatchesFilter.py \ _MatchesPageSubstringOf.py \ _MatchesRepositoryFilter.py \ diff --git a/src/Filters/Rules/Source/_HasSource.py b/src/Filters/Rules/Citation/_HasSource.py similarity index 69% rename from src/Filters/Rules/Source/_HasSource.py rename to src/Filters/Rules/Citation/_HasSource.py index ea2e3c01c..ca6e68347 100644 --- a/src/Filters/Rules/Source/_HasSource.py +++ b/src/Filters/Rules/Citation/_HasSource.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2011 Tim G L Lyons # # 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 @@ -20,6 +21,9 @@ # $Id$ +""" +Filter rule to match citation with a particular source. +""" #------------------------------------------------------------------------- # # Standard Python modules @@ -32,32 +36,27 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules._Rule import Rule +from Filters.Rules._HasSourceBase import HasSourceBase #------------------------------------------------------------------------- # -# HasSource +# HasEvent # #------------------------------------------------------------------------- -class HasSource(Rule): - """Rule that checks for a person with a particular value""" - +class HasSource(HasSourceBase): + """Rule that checks for an citation with a particular value""" labels = [ _('Title:'), _('Author:'), _('Publication:') ] name = _('Sources matching parameters') - description = _("Matches sources with particular parameters") - category = _('General filters') - - def apply(self,db,source): - if not self.match_substring(0,source.get_title()): - return False - - if not self.match_substring(1,source.get_author()): - return False - - if not self.match_substring(2,source.get_publication_info()): - return False - - return True + description = _("Matches citations with a source of a particular " + "value") + category = _('Source filters') + + def apply(self, dbase, citation): + source = dbase.get_source_from_handle( + citation.get_reference_handle()) + if HasSourceBase.apply(self, dbase, source): + return True + return False diff --git a/src/Filters/Rules/Citation/_MatchesSourceFilter.py b/src/Filters/Rules/Citation/_MatchesSourceFilter.py index c0fac2499..3f6e99fa1 100644 --- a/src/Filters/Rules/Citation/_MatchesSourceFilter.py +++ b/src/Filters/Rules/Citation/_MatchesSourceFilter.py @@ -34,23 +34,36 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules import MatchesSourceFilterBase +from Filters.Rules import MatchesFilterBase #------------------------------------------------------------------------- # # MatchesFilter # #------------------------------------------------------------------------- -class MatchesSourceFilter(MatchesSourceFilterBase): +class MatchesSourceFilter(MatchesFilterBase): """ Rule that checks against another filter. """ labels = [_('Source filter name:')] - name = _('Events with source matching the ') - description = _("Matches events with sources that match the " + name = _('Citations with source matching the ') + description = _("Matches citations with sources that match the " "specified source filter name") category = _('General filters') # we want to have this filter show source filters namespace = 'Source' + + def prepare(self, db): + MatchesFilterBase.prepare(self, db) + self.MRF_filt = self.find_filter() + + def apply(self, db, object): + if self.MRF_filt is None : + return False + + source_handle = object.source_handle + if self.MRF_filt.check(db, source_handle): + return True + return False diff --git a/src/Filters/Rules/Citation/__init__.py b/src/Filters/Rules/Citation/__init__.py index f36aeac52..af897260d 100644 --- a/src/Filters/Rules/Citation/__init__.py +++ b/src/Filters/Rules/Citation/__init__.py @@ -37,6 +37,7 @@ from _HasNote import HasNote from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _HasNoteRegexp import HasNoteRegexp from _HasReferenceCountOf import HasReferenceCountOf +from _HasSource import HasSource from _MatchesFilter import MatchesFilter from _MatchesPageSubstringOf import MatchesPageSubstringOf from _MatchesRepositoryFilter import MatchesRepositoryFilter @@ -53,6 +54,7 @@ editor_rule_list = [ HasNoteMatchingSubstringOf, HasNoteRegexp, HasReferenceCountOf, + HasSource, MatchesFilter, MatchesPageSubstringOf, MatchesRepositoryFilter, diff --git a/src/Filters/Rules/Event/Makefile.am b/src/Filters/Rules/Event/Makefile.am index 5d6f498bf..2223bc098 100644 --- a/src/Filters/Rules/Event/Makefile.am +++ b/src/Filters/Rules/Event/Makefile.am @@ -9,11 +9,12 @@ pkgdata_PYTHON = \ _HasNoteRegexp.py\ _RegExpIdOf.py\ _AllEvents.py\ + _HasCitation.py \ _HasData.py\ _HasGallery.py \ _HasIdOf.py\ _HasNote.py \ - _HasSource.py \ + _HasSourceCount.py \ _HasType.py\ _HasNoteMatchingSubstringOf.py\ _HasReferenceCountOf.py\ diff --git a/src/Filters/Rules/Event/_HasCitation.py b/src/Filters/Rules/Event/_HasCitation.py new file mode 100644 index 000000000..9381463d1 --- /dev/null +++ b/src/Filters/Rules/Event/_HasCitation.py @@ -0,0 +1,61 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2011 Tim G L Lyons +# +# 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$ + +""" +Filter rule to match event with a particular citation. +""" +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasCitationBase import HasCitationBase + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasCitation(HasCitationBase): + """Rule that checks for an event with a particular value""" + + labels = [ _('Volume/Page:'), + _('Date:'), + _('Confidence level:')] + name = _('Event with the ') + description = _("Matches events with a citation of a particular " + "value") + + def apply(self, dbase, event): + for citation_handle in event.get_citation_list(): + citation = dbase.get_citation_from_handle(citation_handle) + if HasCitationBase.apply(self, dbase, citation): + return True + return False diff --git a/src/Filters/Rules/Event/_HasSource.py b/src/Filters/Rules/Event/_HasSourceCount.py similarity index 93% rename from src/Filters/Rules/Event/_HasSource.py rename to src/Filters/Rules/Event/_HasSourceCount.py index 1562e30ca..cf1be9f34 100644 --- a/src/Filters/Rules/Event/_HasSource.py +++ b/src/Filters/Rules/Event/_HasSourceCount.py @@ -20,6 +20,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# $Id$ + #------------------------------------------------------------------------- # # Standard Python modules @@ -32,12 +34,12 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules._HasSourceBase import HasSourceBase +from Filters.Rules._HasSourceCountBase import HasSourceCountBase #------------------------------------------------------------------------- # "People having sources" #------------------------------------------------------------------------- -class HasSource(HasSourceBase): +class HasSourceCount(HasSourceCountBase): """Events with sources""" name = _('Events with sources') diff --git a/src/Filters/Rules/Event/_MatchesSourceFilter.py b/src/Filters/Rules/Event/_MatchesSourceFilter.py index b865e7eac..a65b1feef 100644 --- a/src/Filters/Rules/Event/_MatchesSourceFilter.py +++ b/src/Filters/Rules/Event/_MatchesSourceFilter.py @@ -49,7 +49,7 @@ class MatchesSourceFilter(MatchesSourceFilterBase): name = _('Events with source matching the ') description = _("Matches events with sources that match the " "specified source filter name") - category = _('General filters') + category = _('Citation/source filters') # we want to have this filter show source filters namespace = 'Source' diff --git a/src/Filters/Rules/Event/__init__.py b/src/Filters/Rules/Event/__init__.py index affc9cdaa..107ef71eb 100644 --- a/src/Filters/Rules/Event/__init__.py +++ b/src/Filters/Rules/Event/__init__.py @@ -32,11 +32,12 @@ from _AllEvents import AllEvents from _HasGallery import HasGallery from _HasIdOf import HasIdOf from _RegExpIdOf import RegExpIdOf +from _HasCitation import HasCitation from _HasNote import HasNote from _HasNoteRegexp import HasNoteRegexp from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _HasReferenceCountOf import HasReferenceCountOf -from _HasSource import HasSource +from _HasSourceCount import HasSourceCount from _EventPrivate import EventPrivate from _MatchesFilter import MatchesFilter from _MatchesPersonFilter import MatchesPersonFilter @@ -52,11 +53,12 @@ editor_rule_list = [ HasIdOf, HasGallery, RegExpIdOf, + HasCitation, HasNote, HasNoteRegexp, HasNoteMatchingSubstringOf, HasReferenceCountOf, - HasSource, + HasSourceCount, EventPrivate, MatchesFilter, MatchesPersonFilter, diff --git a/src/Filters/Rules/Family/Makefile.am b/src/Filters/Rules/Family/Makefile.am index eb8a8d5fb..1856247d6 100644 --- a/src/Filters/Rules/Family/Makefile.am +++ b/src/Filters/Rules/Family/Makefile.am @@ -8,6 +8,7 @@ pkgdata_PYTHON = \ _FamilyPrivate.py\ _HasEvent.py\ _HasAttribute.py\ + _HasCitation.py \ _HasGallery.py \ _HasIdOf.py\ _HasLDS.py \ @@ -16,7 +17,7 @@ pkgdata_PYTHON = \ _HasNoteRegexp.py\ _HasReferenceCountOf.py\ _HasRelType.py\ - _HasSource.py \ + _HasSourceCount.py \ _HasTag.py \ __init__.py\ _IsBookmarked.py\ diff --git a/src/Filters/Rules/Family/_HasCitation.py b/src/Filters/Rules/Family/_HasCitation.py new file mode 100644 index 000000000..79629c34c --- /dev/null +++ b/src/Filters/Rules/Family/_HasCitation.py @@ -0,0 +1,61 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2011 Tim G L Lyons +# +# 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$ + +""" +Filter rule to match family with a particular citation. +""" +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasCitationBase import HasCitationBase + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasCitation(HasCitationBase): + """Rule that checks for a family with a particular value""" + + labels = [ _('Volume/Page:'), + _('Date:'), + _('Confidence level:')] + name = _('Family with the ') + description = _("Matches families with a citation of a particular " + "value") + + def apply(self, dbase, family): + for citation_handle in family.get_citation_list(): + citation = dbase.get_citation_from_handle(citation_handle) + if HasCitationBase.apply(self, dbase, citation): + return True + return False diff --git a/src/Filters/Rules/Family/_HasSource.py b/src/Filters/Rules/Family/_HasSourceCount.py similarity index 93% rename from src/Filters/Rules/Family/_HasSource.py rename to src/Filters/Rules/Family/_HasSourceCount.py index e0f5bc97b..cc2873242 100755 --- a/src/Filters/Rules/Family/_HasSource.py +++ b/src/Filters/Rules/Family/_HasSourceCount.py @@ -35,12 +35,12 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules._HasSourceBase import HasSourceBase +from Filters.Rules._HasSourceCountBase import HasSourceCountBase #------------------------------------------------------------------------- # "Families having sources" #------------------------------------------------------------------------- -class HasSource(HasSourceBase): +class HasSourceCount(HasSourceCountBase): """Families with sources""" name = _('Families with sources') diff --git a/src/Filters/Rules/Family/__init__.py b/src/Filters/Rules/Family/__init__.py index 3eb635713..44b6ce624 100644 --- a/src/Filters/Rules/Family/__init__.py +++ b/src/Filters/Rules/Family/__init__.py @@ -41,8 +41,9 @@ from _RegExpIdOf import RegExpIdOf from _HasNote import HasNote from _HasNoteRegexp import HasNoteRegexp from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf -from _HasSource import HasSource +from _HasSourceCount import HasSourceCount from _HasReferenceCountOf import HasReferenceCountOf +from _HasCitation import HasCitation from _FamilyPrivate import FamilyPrivate from _HasAttribute import HasAttribute from _HasEvent import HasEvent @@ -69,7 +70,8 @@ editor_rule_list = [ HasNoteRegexp, HasNoteMatchingSubstringOf, HasReferenceCountOf, - HasSource, + HasSourceCount, + HasCitation, FamilyPrivate, HasEvent, HasAttribute, diff --git a/src/Filters/Rules/Makefile.am b/src/Filters/Rules/Makefile.am index a86b226ac..7176e895c 100644 --- a/src/Filters/Rules/Makefile.am +++ b/src/Filters/Rules/Makefile.am @@ -16,6 +16,7 @@ pkgdata_PYTHON = \ _HasNoteRegexBase.py\ _HasNoteSubstrBase.py\ _HasReferenceCountBase.py \ + _HasSourceCountBase.py \ _HasSourceBase.py \ _HasTagBase.py \ _HasTextMatchingRegexpOf.py\ diff --git a/src/Filters/Rules/Person/Makefile.am b/src/Filters/Rules/Person/Makefile.am index 3e340ec8f..682c86cbd 100644 --- a/src/Filters/Rules/Person/Makefile.am +++ b/src/Filters/Rules/Person/Makefile.am @@ -13,6 +13,7 @@ pkgdata_PYTHON = \ _HasAlternateName.py \ _HasAssociation.py \ _HasBirth.py \ + _HasCitation.py \ _HasCommonAncestorWith.py \ _HasCommonAncestorWithFilterMatch.py \ _HasDeath.py \ @@ -29,7 +30,7 @@ pkgdata_PYTHON = \ _HasNote.py \ _HasNoteMatchingSubstringOf.py \ _HasRelationship.py \ - _HasSource.py \ + _HasSourceCount.py \ _HasSourceOf.py \ _HasTag.py \ _HasTextMatchingRegexpOf.py \ diff --git a/src/Filters/Rules/Person/_HasCitation.py b/src/Filters/Rules/Person/_HasCitation.py new file mode 100644 index 000000000..558fe4cce --- /dev/null +++ b/src/Filters/Rules/Person/_HasCitation.py @@ -0,0 +1,60 @@ +# +# 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$ + +""" +Filter rule to match persons with a particular citation. +""" +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasCitationBase import HasCitationBase + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasCitation(HasCitationBase): + """Rule that checks for a person with a particular value""" + + labels = [ _('Volume/Page:'), + _('Date:'), + _('Confidence level:')] + name = _('People with the ') + description = _("Matches people with a citation of a particular " + "value") + + def apply(self, dbase, person): + for citation_handle in person.get_citation_list(): + citation = dbase.get_citation_from_handle(citation_handle) + if HasCitationBase.apply(self, dbase, citation): + return True + return False diff --git a/src/Filters/Rules/Person/_HasSource.py b/src/Filters/Rules/Person/_HasSourceCount.py similarity index 93% rename from src/Filters/Rules/Person/_HasSource.py rename to src/Filters/Rules/Person/_HasSourceCount.py index eaaa0601a..8abdc0f19 100755 --- a/src/Filters/Rules/Person/_HasSource.py +++ b/src/Filters/Rules/Person/_HasSourceCount.py @@ -35,12 +35,12 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules._HasSourceBase import HasSourceBase +from Filters.Rules._HasSourceCountBase import HasSourceCountBase #------------------------------------------------------------------------- # "People having sources" #------------------------------------------------------------------------- -class HasSource(HasSourceBase): +class HasSourceCount(HasSourceCountBase): """People with sources""" name = _('People with sources') diff --git a/src/Filters/Rules/Person/_HasSourceOf.py b/src/Filters/Rules/Person/_HasSourceOf.py index becb49437..a291f3c3c 100644 --- a/src/Filters/Rules/Person/_HasSourceOf.py +++ b/src/Filters/Rules/Person/_HasSourceOf.py @@ -44,7 +44,7 @@ class HasSourceOf(Rule): labels = [ _('Source ID:') ] name = _('People with the ') - category = _('General filters') + category = _('Citation/source filters') description = _('Matches people who have a particular source') def prepare(self,db): @@ -55,14 +55,22 @@ class HasSourceOf(Rule): self.nosource = False try: - self.source_handle = db.get_source_from_gramps_id(self.list[0]).get_handle() + self.source_handle = db.get_source_from_gramps_id( + self.list[0]).get_handle() except: self.source_handle = None def apply(self, db, person): if not self.source_handle: if self.nosource: - return len(person.get_source_references()) == 0 + # check whether the citation list is empty as a proxy for + # there being no sources + return len(person.get_all_citation_lists()) == 0 else: return False - return person.has_source_reference(self.source_handle) + else: + for citation_handle in person.get_all_citation_lists(): + citation = db.get_citation_from_handle(citation_handle) + if citation.get_reference_handle() == self.source_handle: + return True + return False diff --git a/src/Filters/Rules/Person/__init__.py b/src/Filters/Rules/Person/__init__.py index 13b48d627..380126bb9 100644 --- a/src/Filters/Rules/Person/__init__.py +++ b/src/Filters/Rules/Person/__init__.py @@ -33,6 +33,7 @@ from _HasAlternateName import HasAlternateName from _HasAssociation import HasAssociation from _HasAttribute import HasAttribute from _HasBirth import HasBirth +from _HasCitation import HasCitation from _HasCommonAncestorWith import HasCommonAncestorWith from _HasCommonAncestorWithFilterMatch import HasCommonAncestorWithFilterMatch from _HasDeath import HasDeath @@ -50,7 +51,7 @@ from _HasNote import HasNote from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _HasNoteRegexp import HasNoteRegexp from _HasRelationship import HasRelationship -from _HasSource import HasSource +from _HasSourceCount import HasSourceCount from _HasSourceOf import HasSourceOf from _HasTag import HasTag from _HasTextMatchingRegexpOf import HasTextMatchingRegexpOf @@ -131,12 +132,13 @@ editor_rule_list = [ HasRelationship, HasDeath, HasBirth, + HasCitation, HasEvent, HasFamilyEvent, HasAttribute, HasFamilyAttribute, HasTag, - HasSource, + HasSourceCount, HasSourceOf, HaveAltFamilies, HavePhotos, diff --git a/src/Filters/Rules/Source/__init__.py b/src/Filters/Rules/Source/__init__.py index bac4c398b..c4143c504 100644 --- a/src/Filters/Rules/Source/__init__.py +++ b/src/Filters/Rules/Source/__init__.py @@ -25,6 +25,8 @@ Package providing filter rules for GRAMPS. """ +from Filters.Rules._HasSourceBase import HasSourceBase as HasSource + from _AllSources import AllSources from _HasGallery import HasGallery from _HasIdOf import HasIdOf @@ -35,7 +37,6 @@ from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _HasReferenceCountOf import HasReferenceCountOf from _SourcePrivate import SourcePrivate from _MatchesFilter import MatchesFilter -from _HasSource import HasSource from _ChangedSince import ChangedSince from _HasRepository import HasRepository from _MatchesTitleSubstringOf import MatchesTitleSubstringOf diff --git a/src/Filters/Rules/_HasCitationBase.py b/src/Filters/Rules/_HasCitationBase.py index 4196f381e..779984541 100644 --- a/src/Filters/Rules/_HasCitationBase.py +++ b/src/Filters/Rules/_HasCitationBase.py @@ -53,7 +53,7 @@ class HasCitationBase(Rule): _('Confidence:') ] name = _('Citations matching parameters') description = _("Matches citations with particular parameters") - category = _('General filters') + category = _('Citation/source filters') def prepare(self, db): self.date = None diff --git a/src/Filters/Rules/_HasSourceBase.py b/src/Filters/Rules/_HasSourceBase.py old mode 100755 new mode 100644 index 39bfe9cce..e0f44fac9 --- a/src/Filters/Rules/_HasSourceBase.py +++ b/src/Filters/Rules/_HasSourceBase.py @@ -1,10 +1,8 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2002-2007 Donald N. Allingham -# Copyright (C) 2007-2008 Brian G. Matherly -# Copyright (C) 2008 Jerome Rapinat -# Copyright (C) 2008 Benny Malengier +# Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2011 Tim G L Lyons # # 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 @@ -38,32 +36,29 @@ from gen.ggettext import gettext as _ from Filters.Rules._Rule import Rule #------------------------------------------------------------------------- -# "Objects having sources" +# +# HasSource +# #------------------------------------------------------------------------- class HasSourceBase(Rule): - """Objects having notes""" + """Rule that checks for a source with a particular value""" - labels = [ _('Number of instances:'), _('Number must be:')] - name = _('Objects with sources') - description = _("Matches objects that have a certain number of sources connected to it") - category = _('General filters') - def prepare(self, db): - # things we want to do just once, not for every handle - if self.list[1] == 'lesser than': - self.count_type = 0 - elif self.list[1] == 'greater than': - self.count_type = 2 - else: - self.count_type = 1 # "equal to" + labels = [ _('Title:'), + _('Author:'), + _('Publication:') ] + name = _('Sources matching parameters') + description = _("Matches sources with particular parameters") + category = _('Citation/source filters') - self.userSelectedCount = int(self.list[0]) + def apply(self,db,source): + if not self.match_substring(0,source.get_title()): + return False - def apply(self, db, obj): - count = len(obj.get_source_references()) - if self.count_type == 0: # "lesser than" - return count < self.userSelectedCount - elif self.count_type == 2: # "greater than" - return count > self.userSelectedCount - # "equal to" - return count == self.userSelectedCount + if not self.match_substring(1,source.get_author()): + return False + + if not self.match_substring(2,source.get_publication_info()): + return False + + return True diff --git a/src/Filters/Rules/_HasSourceCountBase.py b/src/Filters/Rules/_HasSourceCountBase.py new file mode 100755 index 000000000..2aecdb501 --- /dev/null +++ b/src/Filters/Rules/_HasSourceCountBase.py @@ -0,0 +1,70 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2007 Donald N. Allingham +# Copyright (C) 2007-2008 Brian G. Matherly +# Copyright (C) 2008 Jerome Rapinat +# Copyright (C) 2008 Benny Malengier +# +# 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 gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._Rule import Rule + +#------------------------------------------------------------------------- +# "Objects having sources" +#------------------------------------------------------------------------- +class HasSourceCountBase(Rule): + """Objects having sources""" + + labels = [ _('Number of instances:'), _('Number must be:')] + name = _('Objects with sources') + description = _("Matches objects that have a certain number of sources " + "connected to it (actually citations are counted)") + category = _('Citation/source filters') + + def prepare(self, db): + # things we want to do just once, not for every handle + if self.list[1] == 'lesser than': + self.count_type = 0 + elif self.list[1] == 'greater than': + self.count_type = 2 + else: + self.count_type = 1 # "equal to" + + self.userSelectedCount = int(self.list[0]) + + def apply(self, db, obj): + count = len(obj.get_citation_list()) + if self.count_type == 0: # "lesser than" + return count < self.userSelectedCount + elif self.count_type == 2: # "greater than" + return count > self.userSelectedCount + # "equal to" + return count == self.userSelectedCount diff --git a/src/Filters/Rules/_MatchesSourceConfidenceBase.py b/src/Filters/Rules/_MatchesSourceConfidenceBase.py index 4edd5d98c..6ebc2dbcf 100644 --- a/src/Filters/Rules/_MatchesSourceConfidenceBase.py +++ b/src/Filters/Rules/_MatchesSourceConfidenceBase.py @@ -44,11 +44,12 @@ class MatchesSourceConfidenceBase(Rule): labels = [_('Confidence level:')] name = _('Object with at least one direct source >= ') description = _("Matches objects with at least one direct source with confidence level(s)") - category = _('General filters') + category = _('Citation/source filters') def apply(self, db, obj): - for source in obj.get_source_references(): - required_conf = int(self.list[0]) - if required_conf <= source.get_confidence_level(): + required_conf = int(self.list[0]) + for citation_handle in obj.get_citation_list(): + citation = db.get_citation_from_handle(citation_handle) + if required_conf <= citation.get_confidence_level(): return True return False diff --git a/src/Filters/Rules/_MatchesSourceFilterBase.py b/src/Filters/Rules/_MatchesSourceFilterBase.py index 87d3dfaea..2b63ac2ad 100644 --- a/src/Filters/Rules/_MatchesSourceFilterBase.py +++ b/src/Filters/Rules/_MatchesSourceFilterBase.py @@ -48,7 +48,7 @@ class MatchesSourceFilterBase(MatchesFilterBase): name = _('Objects with source matching the ') description = _("Matches objects with sources that match the " "specified source filter name") - category = _('General filters') + category = _('Citation/source filters') # we want to have this filter show source filters namespace = 'Source' @@ -61,9 +61,9 @@ class MatchesSourceFilterBase(MatchesFilterBase): if self.MSF_filt is None : return False - sourcelist = [x.ref for x in object.get_source_references()] - for sourcehandle in sourcelist: - #check if source in source filter + for citation_handle in object.get_citation_list(): + citation = db.get_citation_from_handle(citation_handle) + sourcehandle = citation.get_reference_handle() if self.MSF_filt.check(db, sourcehandle): return True return False diff --git a/src/Filters/Rules/__init__.py b/src/Filters/Rules/__init__.py index 30cebdaff..6d1288282 100644 --- a/src/Filters/Rules/__init__.py +++ b/src/Filters/Rules/__init__.py @@ -22,6 +22,46 @@ """ Package providing filter rules for GRAMPS. + +The following filters are provided in Filters/Rules. + +Match given values: +_HasCitationBase Citation with a particular value (HasCitation) + also used for Person, Family and Event having a + particular Citation +_HasEventBase Event with a particular value (HasEvent) + also used for Family and Person having a particular + Event +_HasSourceBase Source with a particular value (HasSource) + also used for Citation having a particular Source + +Match on sub-objects +_ChangedSinceBase Object changed since date +_HasAttributeBase Object has particular attribute value +_HasGrampsId Object has a specific Gramps Id +_HasNoteRegexBase Object has notes matching regular expression +_HasNoteSubstrBase Object has note containing substring +_HasTagBase Object has a particular tag +_HasTextMatchingRegexpOf Object has text matching regular expression +_HasTextMatchingSubstringOf Object has text containing substring +_IsPrivate Object is marked as private +_MatchesFilterBase Object matches another filter +_RegExpldBase Object has Gramps Id matching regular expression + +Match on related objects +_MatchesFilterEventBase Object has an event that matches another filter +_MatchesSourceConfidenceBase Object with specific confidence on direct sources +_MatchesSourceFilterBase Object matches another filter on direct sources + +Count based +_HasGalleryBase Object has /= number of media objects +_HasLDSBase Object has /= number of LDS sub-objects +_HasNoteBase Object has /= number of notes +_HasReferenceCountBase Object has /= number of references +_HasSourceCountBase Object has /= number of sources + +_Rule Base rule class +_Everything Match every object in the database """ # Need to expose this to be available for filter plugins: diff --git a/src/gen/lib/citation.py b/src/gen/lib/citation.py index 8f83302aa..42f3484c3 100644 --- a/src/gen/lib/citation.py +++ b/src/gen/lib/citation.py @@ -181,6 +181,8 @@ class Citation(MediaBase, NoteBase, PrimaryObject, DateBase): """ return self.media_list +# FIXME: get_sourceRef_child_list needs to be removed + # def get_sourcref_child_list(self): # """ # Return the list of child secondary objects that may refer sources. @@ -193,16 +195,6 @@ class Citation(MediaBase, NoteBase, PrimaryObject, DateBase): # """ # return [] - def get_source_references(self) : - """ - Return the list of source references associated with the object. - - :returns: Returns the list of :class:`~gen.lib.srcref.SourceRef` objects associated with - the object. - :rtype: list - """ - return [self.source_handle] - def get_note_child_list(self): """ Return the list of child secondary objects that may refer notes. @@ -236,6 +228,11 @@ class Citation(MediaBase, NoteBase, PrimaryObject, DateBase): ret += [('Source', self.get_reference_handle())] return ret +# FIXME: Remove all has_source_refernce and consequently all +# get_sourceref_child_list, because these seem to be only used in the filter +# _HasSourceOf and mergesource, and it is better to make the test directly, +# because, only citations refer to sources, and they have only one reference. +# need to check remove and replace source reference. def has_source_reference(self, src_handle) : """ Return True if any of the child objects has reference to this source diff --git a/src/gen/lib/citationbase.py b/src/gen/lib/citationbase.py index 4369f9226..c1cd1350b 100644 --- a/src/gen/lib/citationbase.py +++ b/src/gen/lib/citationbase.py @@ -137,6 +137,20 @@ class CitationBase(object): """ return self.citation_list + def get_all_citation_lists(self): + """ + Return the list of :class:`~gen.lib.citation.Citation` handles + associated with the object or with child objects. + + :returns: The list of :class:`~gen.lib.citation.Citation` handles + :rtype: list + """ + list = self.citation_list + + for item in self.get_citation_child_list(): + list += item.get_citation_list() + return list + def has_citation_reference(self, citation_handle): """ Return True if the object or any of its child objects has reference