1

Translator sorts popular terms before others

Former-commit-id: e278bfac44058a8b9941c57381e0cab1af2ae578
This commit is contained in:
Alex Yatskov 2013-11-09 17:59:23 -08:00
parent 89f407e9fa
commit 21838ed26d

View File

@ -41,7 +41,7 @@ class Translator:
results = map(self.formatResult, groups.items()) results = map(self.formatResult, groups.items())
results = filter(operator.truth, results) results = filter(operator.truth, results)
results = sorted(results, key=lambda x: len(x['source']), reverse=True) results = sorted(results, key=lambda d: ('P' in d['tags'], len(d['source'])), reverse=True)
length = 0 length = 0
for result in results: for result in results:
@ -56,17 +56,18 @@ class Translator:
for entry in self.dictionary.findTerm(root, partial): for entry in self.dictionary.findTerm(root, partial):
key = entry['expression'], entry['reading'], entry['glossary'] key = entry['expression'], entry['reading'], entry['glossary']
if key not in groups: if key not in groups:
groups[key] = entry, source, rules groups[key] = entry['tags'], source, rules
def formatResult(self, group): def formatResult(self, group):
(expression, reading, glossary), (entry, source, rules) = group (expression, reading, glossary), (tags, source, rules) = group
return { return {
'expression': expression, 'expression': expression,
'reading': reading, 'reading': reading,
'glossary': glossary, 'glossary': glossary,
'rules': rules, 'rules': rules,
'source': source 'source': source,
'tags': tags
} }