Beispiel #1
0
def query(qstr, qtype=diceng.QRY_AUTO, cmd=diceng.CMD_QUERY, qparam=None, dictfilter=None, detailfilter=None):
	'Return a list of query results, each item containing dictionary basename, '
	'dictionary name, and entry list of word ID, word string and content ('
	'None if detailfilter(basename, qstr, qtype, word string) returns False).'
	dictlist = filter(dictpool.has_key, [n for n, p in wdcfg.dictlist()])
	dictlist = filter(dictfilter, dictlist)
	enginelist = map(dictpool.get, dictlist)
	if type(qstr) == types.StringType:
		try:
			qstr = qstr.decode('utf-8')
		except:
			logging.error('Query string is not UTF-8 encoded:' + qstr)
	logging.info('Query begin cmd:%d, qstr:%s, qtype:%d' % (cmd, qstr, qtype))
	diceng.asyncquery(enginelist, cmd=cmd, qstr=qstr, qtype=qtype, qparam=qparam)
	result = diceng.fetchresults()
	logging.info('Query end cmd:%d, qstr:%s, qtype:%d' % (cmd, qstr, qtype))
	if cmd != diceng.CMD_QUERY:
		return result
	toshow = []
	for engine, cmd, ar in result:
		if ar:
			entries = []
			for wordid, word in ar:
				if detailfilter and detailfilter(engine.basename, qstr, qtype,
						word):
					logging.info('Get detail for %s %s' % (engine.basename, wordid))
					content = engine.detail(wordid)[0][1]
					logging.info('Get detail done for %s %s' % (engine.basename, wordid))
				else:
					content = None
				entries.append((wordid, word, content))
			toshow.append((engine.basename, engine.name, entries))
	return toshow
Beispiel #2
0
def deldict(basename):
	d = dict(wdcfg.dictlist())
	wdcfg.deldict(basename)
	del dictpool[basename]
	path = d[basename]
	del d[basename]
	if path not in d.values():
		_usedpath.remove(os.path.abspath(path))
Beispiel #3
0
def dictnamelist():
	result = []
	for name, path in wdcfg.dictlist():
		if dictpool.has_key(name):
			result.append((name, dictpool[name].name))
	return result
Beispiel #4
0
def loaddicts():
	for name, path in wdcfg.dictlist():
		if not _adddict(path):
			wdcfg.deldict(name)