From 21838ed26d7c56d4b3e7399470cd18a52b09243a Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 9 Nov 2013 17:59:23 -0800 Subject: [PATCH] Translator sorts popular terms before others Former-commit-id: e278bfac44058a8b9941c57381e0cab1af2ae578 --- yomi_base/japanese/translate.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/yomi_base/japanese/translate.py b/yomi_base/japanese/translate.py index f3df471..cdb5fca 100644 --- a/yomi_base/japanese/translate.py +++ b/yomi_base/japanese/translate.py @@ -41,7 +41,7 @@ class Translator: results = map(self.formatResult, groups.items()) 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 for result in results: @@ -56,17 +56,18 @@ class Translator: for entry in self.dictionary.findTerm(root, partial): key = entry['expression'], entry['reading'], entry['glossary'] if key not in groups: - groups[key] = entry, source, rules + groups[key] = entry['tags'], source, rules def formatResult(self, group): - (expression, reading, glossary), (entry, source, rules) = group + (expression, reading, glossary), (tags, source, rules) = group return { 'expression': expression, 'reading': reading, 'glossary': glossary, 'rules': rules, - 'source': source + 'source': source, + 'tags': tags }