mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
fixed several bugs in tags...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
bca3bef9c3
commit
51a917d5c2
7
TODO.otl
7
TODO.otl
@ -1,2 +1,7 @@
|
|||||||
[X] 100% general tasks
|
[_] 25% general tasks
|
||||||
[X] need unique image id
|
[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
|
||||||
|
|||||||
28
tags.py
28
tags.py
@ -1,7 +1,7 @@
|
|||||||
#=======================================================================
|
#=======================================================================
|
||||||
|
|
||||||
__version__ = '''0.0.01'''
|
__version__ = '''0.0.01'''
|
||||||
__sub_version__ = '''20111001000000'''
|
__sub_version__ = '''20111001012545'''
|
||||||
__copyright__ = '''(c) Alex A. Naanou 2011'''
|
__copyright__ = '''(c) Alex A. Naanou 2011'''
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +97,8 @@ class TagSetWithReverseIndexMixin(AbstractTagSet):
|
|||||||
res = {}
|
res = {}
|
||||||
index = self._index
|
index = self._index
|
||||||
# XXX this is really ugly!!
|
# 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])
|
res[obj] = set(t for t in index if obj in index[t])
|
||||||
return res
|
return res
|
||||||
def _reset_reverse_index(self):
|
def _reset_reverse_index(self):
|
||||||
@ -111,7 +112,7 @@ class TagSetWithReverseIndexMixin(AbstractTagSet):
|
|||||||
'''
|
'''
|
||||||
super(TagSetWithReverseIndexMixin, self).tag(obj, *tags)
|
super(TagSetWithReverseIndexMixin, self).tag(obj, *tags)
|
||||||
# update cache...
|
# update cache...
|
||||||
if obj in self._reverse_index:
|
if obj not in self._reverse_index:
|
||||||
self._reverse_index[obj] = set()
|
self._reverse_index[obj] = set()
|
||||||
self._reverse_index[obj].update(tags)
|
self._reverse_index[obj].update(tags)
|
||||||
return self
|
return self
|
||||||
@ -157,7 +158,7 @@ class TagSet(TagSetWithReverseIndexMixin, BasicTagSet):
|
|||||||
class TagSetWithObjectIndex(object):
|
class TagSetWithObjectIndex(object):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
objutils.createonaccess('_index', BasicTagSet)
|
objutils.createonaccess('_index', TagSet)
|
||||||
objutils.createonaccess('_objects', dict)
|
objutils.createonaccess('_objects', dict)
|
||||||
objutils.createonaccess('_cache', '_build_cache', local_attr_tpl='%s_data')
|
objutils.createonaccess('_cache', '_build_cache', local_attr_tpl='%s_data')
|
||||||
|
|
||||||
@ -198,10 +199,11 @@ class TagSetWithObjectIndex(object):
|
|||||||
none = _proxy_op('none')
|
none = _proxy_op('none')
|
||||||
del _proxy_op
|
del _proxy_op
|
||||||
|
|
||||||
putils.proxymethods((
|
def tags(self, *objs):
|
||||||
'tags',
|
'''
|
||||||
), '_index')
|
'''
|
||||||
|
cache = self._cache
|
||||||
|
return self._index.tags(*(cache[obj] for obj in objs))
|
||||||
def objects(self):
|
def objects(self):
|
||||||
return self._objects.values()
|
return self._objects.values()
|
||||||
def getuid(self, obj):
|
def getuid(self, obj):
|
||||||
@ -218,14 +220,14 @@ if __name__ == '__main__':
|
|||||||
from time import time
|
from time import time
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
|
|
||||||
ts = TagSet()
|
## ts = TagSet()
|
||||||
## ts = TagSetWithObjectIndex()
|
ts = TagSetWithObjectIndex()
|
||||||
|
|
||||||
|
|
||||||
N = 100000
|
N = 100000
|
||||||
obj_tpl = 'image%010d'
|
obj_tpl = 'image%010d'
|
||||||
|
|
||||||
def create_tagset():
|
def populate_tagset():
|
||||||
for i in xrange(N):
|
for i in xrange(N):
|
||||||
n = obj_tpl % i
|
n = obj_tpl % i
|
||||||
ts.tag(n, 'image')
|
ts.tag(n, 'image')
|
||||||
@ -247,7 +249,9 @@ if __name__ == '__main__':
|
|||||||
print 'done (%.3fs).' % (t1-t0)
|
print 'done (%.3fs).' % (t1-t0)
|
||||||
return ts
|
return ts
|
||||||
|
|
||||||
ts = load_tagset()
|
|
||||||
|
populate_tagset()
|
||||||
|
## ts = load_tagset()
|
||||||
|
|
||||||
print len(ts.tags())
|
print len(ts.tags())
|
||||||
print len(ts.objects())
|
print len(ts.objects())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user