From 48574cee03a8f6cc26441122eaef0b0ee0dba40c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 4 Oct 2011 19:11:18 +0400 Subject: [PATCH] added .relatedtags(...) to tags.py... Signed-off-by: Alex A. Naanou --- TODO.otl | 7 ++++--- tags.py | 25 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/TODO.otl b/TODO.otl index f455df2f..d9c0206f 100755 --- a/TODO.otl +++ b/TODO.otl @@ -1,4 +1,4 @@ -[_] 11% general tasks +[_] 14% general tasks [_] 0% actions: [_] import [_] export/build @@ -47,8 +47,9 @@ | this can happen when adding a new object to a tag via an .update(...) method, in-place. | | need to use immutable data only. - [_] 0% compleate the new tags module - [_] .relatedtags(...) + [_] 33% compleate the new tags module + [X] .relatedtags(...) + [_] see if we need strict and non-strict .relatedtags(...) [_] concatinative mode or abbility to build new tagsets from selections [_] import test images and ratings [_] importer based on xmpgen diff --git a/tags.py b/tags.py index e9ff6664..9f8f55bf 100755 --- a/tags.py +++ b/tags.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20111001012751''' +__sub_version__ = '''20111004190928''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -145,8 +145,22 @@ class TagSetWithReverseIndexMixin(AbstractTagSet): return self._reverse_index.keys() + +#------------------------------------------TagSetWithRelatedTagsMixin--- +class TagSetWithRelatedTagsMixin(AbstractTagSet): + ''' + + NOTE: this requires the .tags(...) method. + ''' + ##!!! should be two modes: strict (all) and non-strict (any)... + def relatedtags(self, *tags): + ''' + ''' + return self.tags(*self.all(*tags)).difference(tags) + + #--------------------------------------------------------------TagSet--- -class TagSet(TagSetWithReverseIndexMixin, BasicTagSet): +class TagSet(TagSetWithRelatedTagsMixin, TagSetWithReverseIndexMixin, BasicTagSet): ''' ''' pass @@ -224,7 +238,8 @@ if __name__ == '__main__': ## ts = TagSetWithObjectIndex() - N = 100000 +## N = 100000 + N = 1000 obj_tpl = 'image%010d' def populate_tagset(): @@ -263,6 +278,10 @@ if __name__ == '__main__': print ts.tags(obj_tpl % 0) print ts.tags(obj_tpl % 10) + print ts.relatedtags('image') + print ts.relatedtags('image', '0') + print ts.relatedtags('10') + print 'selecting (all)...', t0 = time()