From 51a917d5c20bc60844c975d520fafb5b6aed3f02 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 1 Oct 2011 01:26:26 +0400 Subject: [PATCH] fixed several bugs in tags... Signed-off-by: Alex A. Naanou --- TODO.otl | 7 ++++++- tags.py | 28 ++++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/TODO.otl b/TODO.otl index a68dc748..71102abe 100755 --- a/TODO.otl +++ b/TODO.otl @@ -1,2 +1,7 @@ -[X] 100% general tasks +[_] 25% general tasks [X] need unique image id + [_] 0% compleate the new tags module + [_] .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 c3fc823b..be3dd92a 100755 --- a/tags.py +++ b/tags.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20111001000000''' +__sub_version__ = '''20111001012545''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -97,7 +97,8 @@ class TagSetWithReverseIndexMixin(AbstractTagSet): res = {} index = self._index # XXX this is really ugly!! - for obj in self.objects(): + objects = reduce(set.union, index.values()) + for obj in objects: res[obj] = set(t for t in index if obj in index[t]) return res def _reset_reverse_index(self): @@ -111,7 +112,7 @@ class TagSetWithReverseIndexMixin(AbstractTagSet): ''' super(TagSetWithReverseIndexMixin, self).tag(obj, *tags) # update cache... - if obj in self._reverse_index: + if obj not in self._reverse_index: self._reverse_index[obj] = set() self._reverse_index[obj].update(tags) return self @@ -157,7 +158,7 @@ class TagSet(TagSetWithReverseIndexMixin, BasicTagSet): class TagSetWithObjectIndex(object): ''' ''' - objutils.createonaccess('_index', BasicTagSet) + objutils.createonaccess('_index', TagSet) objutils.createonaccess('_objects', dict) objutils.createonaccess('_cache', '_build_cache', local_attr_tpl='%s_data') @@ -198,10 +199,11 @@ class TagSetWithObjectIndex(object): none = _proxy_op('none') del _proxy_op - putils.proxymethods(( - 'tags', - ), '_index') - + def tags(self, *objs): + ''' + ''' + cache = self._cache + return self._index.tags(*(cache[obj] for obj in objs)) def objects(self): return self._objects.values() def getuid(self, obj): @@ -218,14 +220,14 @@ if __name__ == '__main__': from time import time import cPickle as pickle - ts = TagSet() -## ts = TagSetWithObjectIndex() +## ts = TagSet() + ts = TagSetWithObjectIndex() N = 100000 obj_tpl = 'image%010d' - def create_tagset(): + def populate_tagset(): for i in xrange(N): n = obj_tpl % i ts.tag(n, 'image') @@ -247,7 +249,9 @@ if __name__ == '__main__': print 'done (%.3fs).' % (t1-t0) return ts - ts = load_tagset() + + populate_tagset() +## ts = load_tagset() print len(ts.tags()) print len(ts.objects())