Ejemplo n.º 1
0
Archivo: tree.py Proyecto: flynx/pli
	logstr('''
	# creating constructors...
	constructor('A', A, 'some_tag')
	constructor('B', B, 'some_other_tag')

	>>> tree.constructor.list()
	
	>>> tree.some_tag.constructor.list()
	
	>>> tree.some_tag.relatedtags()
	
	tree.A
	tree.A()
	tree.some_tag.A()
	tree.some_tag.constructor.A()
	tree.B()
	tree.some_other_tag.constructor.B()
	
	>>> tree.instance.list('attr', '__class__')
	
	>>> tree.some_tag.instance.list()
	
	>>> tree.some_other_tag.list()
##	>>> tree.some_other_tag.objects()
	
	>>> tree.relatedtags()
	>>> tree.some_other_tag.relatedtags()

	tree.addtags('xxx', 'yyy')
	tree.xxx.keys()

	AA = constructor('X', A, 'fff:ggg')
	tree.X()

	tree['fff:ggg']

	tree['fff']


##	##!!! pickle does not seem to work with recursive references... (2.5.1-specific?)
##	import pickle
##
##	class X(object): pass
##
##	x = X()
##
##	d = {'x':x}
##	x.d = d
##	print d
##	print pickle.dumps(d)

	import cPickle as pickle

	s = pickle.dumps(tree)

	ss = pickle.dumps(tree.some_tag)

	AA

	sss = pickle.dumps(AA)

	''')
Ejemplo n.º 2
0
	!ts.none('10', '5')
	!t1 = time()
	print 'done (%.3fs).' % (t1-t0)

	print 'getting object tags...',
	!t0 = time()
	!ts.tags(OBJ_TPL % 10)
	!t1 = time()
	print 'done (%.3fs).' % (t1-t0)
	'''

    logstr('''
	ts = tags.TagSet()

##	populate_tagset(ts)
##	save_tagset(ts)

	ts = load_tagset()

	''')

    logstr(test_code)
    ##	logstr(test_code2)

    logstr('''
	ts = tags.TagSetWithObjectIndex()

	populate_tagset(ts)
##	save_tagset(ts)
	''')
Ejemplo n.º 3
0
	!t1 = time()
	print 'done (%.3fs).' % (t1-t0)

	print 'getting object tags...',
	!t0 = time()
	!ts.tags(OBJ_TPL % 10)
	!t1 = time()
	print 'done (%.3fs).' % (t1-t0)
	'''


	logstr('''
	ts = tags.TagSet()

##	populate_tagset(ts)
##	save_tagset(ts)

	ts = load_tagset()

	''')

	logstr(test_code)
##	logstr(test_code2)
	

	logstr('''
	ts = tags.TagSetWithObjectIndex()

	populate_tagset(ts)
##	save_tagset(ts)
	''')
Ejemplo n.º 4
0
Archivo: tagset.py Proyecto: flynx/pli
	logstr('''

	ts = DictTagSet()

	ts.tag('X', 'a', 'b', 'c')

	>>> ts

	ts = DictTagSet()

	! ts.tag('X', 'a')
	! ts.tag('X', 'b')
	! ts.tag('X', 'c')

	>>> ts

	! ts.tag('Y', 'c', 'd')

	# test of types that can be used as tags... (sanity check)
	! ts.tag('Z', 'string', u'unicode', True, False, 1, 1.1)
	! ts.tag('ZZ', ()) 
	### NOTE: tags MUST be hashable, so the following will fail.
	##! ts.tag('ZZ', [], {}) 

	>>> ts


	# unite:
	##!!! should yield a tagset only containing X
	ts.any('a', 'b')

	# _intersect:
	ts._all('a')

	# intersect:
	ts.all('a')

	# exclude:
	ts.none('a')


##	ts.untag('X', 'a')


	---

	>>> ts


	ts.istagsconsistent()
		-> True
	tuple(ts.itertaggaps())
		-> ()
	tuple(ts.iterorphans())
		-> ()

	words = DictTagSet() 
	! [ words.tag(w, *tuple(w)) for w in txt.split() ]

##	>>> words
##	words.__tagset__['t']

##	words.all('t', 'x')

	##!!! Q: sould the resultin tagset be tag complete?
	##!!!    ...i.e. .tags(obj) should return all the tags in any sub-tagset 
	##!!!    or only the relevant tags for that subset? (see next couple of lines)
	>>> words.any('a', 'x').tags('that')
	>>> words.tags('that')

	>>> words.any('a', 'x').tags('a')

	>>> words.tags('a')

##	>>> words.any('t', 'x').none('c')

	>>> words.objects()

	>>> words.any('a').objects()

	>>> words.tags()

	>>> words.tags('that')

	>>> words.tags('t')

	##!!! is this correct???
	>>> words.all()

	>>> words.relatedtags('a', 't')

	>>> words.relatedtags('a', 't', 'e')

	>>> words.relatedtags('a', 't', 'e', 'g')

	>>> words.relatedtags('a', 't', 'e', 'g', 'd')
	>>> words.all('a', 't', 'e', 'g', 'd').tags()
	>>> words.all('a', 't', 'e', 'g', 'd').objects()

	>>> words.all('a', 't', 'e', 'g', 'd').none('.').objects()
	>>> words.all('a', 't', 'e', 'g', 'd').none('.', 'a').objects()


	>>> words.all('t', 'e').tags()
	>>> words.all('t', 'e').any('l', 'j').objects()

	# errors -- tag conflicts...
	# XXX should these err or just return empty tagsets???
	>>> words.all('t', 'e').any('l').any('j').objects()
	>>> words.all('t', 'e').all('l').all('j').objects()
	>>> words.all('t', 'e').all('l').all('j').tags()
	>>> words.all('t', 'e').all('l')
	>>> words.all('t', 'e').all('l').any('j')
	>>> words.all('t', 'e').all('l').any('j').tags()
	>>> words.all('t', 'e').all('l').none('j').tags()
	>>> words.all('t', 'e').all('l').all('j')

	
	---

	# test tagchain functionality...
	
	words = DictTagSet() 

	words.tags2chain('a', 'b', 'c')
		-> 'a:b:c'
	words.chain2tags('a:b:c')
		-> ('a', 'b', 'c')

	! words.tag('that', 'T:H:A:T')
	! words.tag('this', 'T:H:I:S')
	! words.tag('that', 't', 'h', 'a', 't')
	! words.tag('that', 't', 'h', 'i', 's')

	words.tags('that')
	words.all('A').objects()

	words.chains()
	words.chains('A')
	words.chains('T:H')
	words.all('T', 'H').chains()

	words.all('T:H:A:T').objects()
		-> set(['that'])

	>>> words.all('t', 'h', 'a').objects()

	words.all('T:H:I:S').objects()
		-> set(['this'])

	# NOTE: this will return a tagset and not a list of objects.
	>>> words.all('T:H:I:S', words.__object_tag__)

	''')
Ejemplo n.º 5
0
Archivo: test.py Proyecto: flynx/XMPGen
logstr('''
	!cleanup()

	!list(collect(TEST_DIR))
	!list(rcollect(TEST_DIR))

	list(collect(TEST_DIR)) == list(rcollect(TEST_DIR))[::-1]
		-> True


	---

	bestpathmatch('ABT', ('A', 'AB', 'ABT', 'AC', 'ABD'))
		-> 'ABT'

	bestpathmatch('ABT', ('A', 'AB', 'AC', 'ABD'))
		-> 'AB'

	bestpathmatch('ABT', ('A', 'AC', 'ABD'))
		-> 'ABD'

	bestpathmatch('AT', ('AB', 'ACD', 'AT'))
		-> 'AT'

	bestpathmatch('AT', ('AB', 'ACD'))
		-> 'AB'

##	##!!! this should fail because we have two paths with same score...
##	bestpathmatch('AT', ('AB', 'AC'))


	---

	!list(index(collect(TEST_DIR)))

	# corner cases...
	list(collect('mooo'))
		-> []
	list(collect(EMPTY_DIR)) 
		-> []

	list(index([]))
		-> []
	list(rate([]))
		-> []
	list(rate(index([])))
		-> []

	generate([], 'fooo', actions=())
		-> None

	buildfilecache('fooo') 
		-> {}
##	# this will fail with a KeyError, because 'mooo' does indeed not
##	# exist in an empty cache...
##	getfilepath('fooo', 'mooo', buildfilecache('fooo'))
##		

	builddircache('fooo', 'mooo')
		-> {}
	list(getdirpaths('fooo', 'mooo', buildfilecache('fooo', 'mooo')))
		-> []

##	[ (e['total count'], len(e['items'])) for e in list(index([ [(1, 2), (4, 5), ], [(1, 2), (4, 5), (5, 6)], [(1, 2), (2, 3), (4, 5), (5, 6)], ]))]


	---

	!list(index(collect(TEST_DIR)))

	[ (e['total count'], len(e['items'])) for e in index(collect(TEST_DIR)) ]
		-> [(101, 101), (107, 6), (184, 77), (487, 303)]

##	raise SystemExit

	[ (rating, len(data)) for rating, data in dict(rate(index(collect(TEST_DIR)))).items() ]
		-> [('blue', 1), (4, 1), (5, 1), ('yellow', 1)]

	# will combine two levels...
	[ (rating, len(data)) for rating, data in dict(rate(index(collect(TEST_DIR)), threshold=10)).items() ]
		-> [('blue', 2), (5, 1), ('yellow', 1)]

	# output sums number of elements puer group...
	[ (rating, [len(i['items']) for i in data]) for rating, data in dict(rate(index(collect(TEST_DIR)), threshold=10)).items() ]
		-> [('blue', [6, 77]), (5, [303]), ('yellow', [101])]

	---

	# generate the XMP files...
	generate(rate(index(collect(TEST_DIR)), threshold=10), TEST_DESTINATION)

	# cleanup...
	cleanup()
		-> 'found and removed 487 XMP files in 1 directories.'

	---

	# generate the XMP files and put them in the same place as a
	# coresponding raw file...
	generate(rate(index(collect(TEST_DIR)), threshold=10), TEST_DESTINATION, curry(getfilepath, cache=buildfilecache(TEST_DESTINATION, )))

	# cleanup...
	cleanup()
		-> 'found and removed 487 XMP files in 2 directories.'

	---

	os.system('python xmpgen.py --root=test --no-search-output --no-search-input -m')
		-> 0

	cleanup()
		-> 'found and removed 184 XMP files in 1 directories.'

	---

	os.system('python xmpgen.py --root=test --no-search-input -m')
		-> 0

	cleanup()
		-> 'found and removed 184 XMP files in 2 directories.'

	---

	os.system('python xmpgen.py -m')
		-> 0

	cleanup()
		-> 'found and removed 199 XMP files in 3 directories.'

	---

	os.system('python xmpgen.py --rate-top-level -m')
		-> 0

	cleanup()
		-> 'found and removed 517 XMP files in 3 directories.'

##	---
##
##	# test different strategies handling existing xmp files...
##
##	os.system('python xmpgen.py -m')
##		-> 0

	---

	# corner cases...

	os.system('python xmpgen.py --input=fooo -m')
		-> 0

	cleanup()
		-> 'found and removed 0 XMP files in 0 directories.'

	---

	os.system('python xmpgen.py --input=%s -m' % os.path.join('test', 'empty'))
		-> 0

	cleanup()
		-> 'found and removed 0 XMP files in 0 directories.'

	---

	os.system('python xmpgen.py --root=%s -m' % os.path.join('test', 'empty'))
		-> 0

	cleanup()
		-> 'found and removed 0 XMP files in 0 directories.'

	---

	# XXX same as above...
	os.system('python xmpgen.py --input=fooo --no-search-input -m')
		-> 0

	cleanup()
		-> 'found and removed 0 XMP files in 0 directories.'

	---

	os.system('python xmpgen.py --input=fooo --no-search-output -m')
		-> 0

	cleanup()
		-> 'found and removed 0 XMP files in 0 directories.'

	---

	os.system('python xmpgen.py --input=fooo --no-search-output --no-search-input -m')
		-> 0

	cleanup()
		-> 'found and removed 0 XMP files in 0 directories.'

''', only_errors=False)