From 495c12b6c27968837c135902b4446c3bba958590 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 22 Mar 2016 20:02:41 -0700 Subject: [PATCH] Maybe this works --- ext/jp/dictionary.js | 4 ++-- ext/jp/translator.js | 39 +++++++++------------------------------ 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/ext/jp/dictionary.js b/ext/jp/dictionary.js index 871a9550..18a15ab0 100644 --- a/ext/jp/dictionary.js +++ b/ext/jp/dictionary.js @@ -56,7 +56,7 @@ class Dictionary { findTermInDict(term, dict) { return (dict.indices[term] || []).map(index => { const [e, r, g, t] = dict.defs[index]; - return {expression: e, reading: r, glossary: g, tags: t}; + return {id: index, expression: e, reading: r, glossary: g, tags: t}; }); } @@ -67,6 +67,6 @@ class Dictionary { } const [c, k, o, g] = def; - return {character: c, kunyomi: k, onyomi: o, glossary: g}; + return {id: kanji.charCodeAt(0), character: c, kunyomi: k, onyomi: o, glossary: g}; } } diff --git a/ext/jp/translator.js b/ext/jp/translator.js index a071a768..c45d7174 100644 --- a/ext/jp/translator.js +++ b/ext/jp/translator.js @@ -64,7 +64,7 @@ class Translator { } } - const results = formatResults(groups).sort(resultSorter); + const results = groups.sort(resultSorter); let length = 0; for (const result of results) { @@ -90,37 +90,16 @@ class Translator { } processTerm(groups, source, rules=[], root='') { - root = root || source; - - // for (const entry of this.dictionary.findTerm(root)) { - // const key = - // } - - // root = root or source - - // for entry in self.dictionary.findTerm(root, wildcards): - // key = entry['expression'], entry['reading'], entry['glossary'] - // if key not in groups: - // groups[key] = entry['tags'], source, rules - } - - formatResult(group) { - const results = []; - for (const [key, value] of groups) { - [expression, reading, glossary] = key; - [tags, source, rules] = group; - - results.push({ - expression: expression, - reading: reading, - glossary: glossary, - rules: rules, + for (const entry of this.dictionary.findTerm(root || source)) { + groups[entry.id] = { + expression: entry.expression, + reading: entry.reading, + glossary: entry.glossary, + tags: entry.tags, source: source, - tags: tags - }); + rules: rules + }; } - - return results; } resultSorter(v1, v2) {