summaryrefslogtreecommitdiff
path: root/ext/jp/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-03-23 18:12:33 -0700
committerAlex Yatskov <alex@foosoft.net>2016-03-23 18:12:33 -0700
commitc30837065889d4fc4d2984b14b365cc276c79214 (patch)
treeff0b620b6ef146828be43737aa79cc6c80b9a563 /ext/jp/translator.js
parenta9c92bdfbf32a96210cf676124d855880f3309e2 (diff)
Fixes to make deinflection work
Diffstat (limited to 'ext/jp/translator.js')
-rw-r--r--ext/jp/translator.js31
1 files changed, 18 insertions, 13 deletions
diff --git a/ext/jp/translator.js b/ext/jp/translator.js
index 542871a9..39ef176c 100644
--- a/ext/jp/translator.js
+++ b/ext/jp/translator.js
@@ -36,7 +36,7 @@ class Translator {
}
$.when.apply($, loaders).done((rules, edict, enamdict, kanjidic) => {
- this.deinflector.setRules(rules);
+ this.deinflector.setRules(rules[0]);
this.dictionary.addTermDict(edict[0]);
this.dictionary.addTermDict(enamdict[0]);
@@ -71,16 +71,21 @@ class Translator {
this.processTerm(groups, df.source, df.rules, df.root);
}
}
+ }
- const results = groups.sort(resultSorter);
+ let results = [];
+ for (const key in groups) {
+ results.push(groups[key]);
+ }
- let length = 0;
- for (const result of results) {
- length = Math.max(length, result.source.length);
- }
+ results = results.sort(this.resultSorter);
- return {results: results, length: length};
+ let length = 0;
+ for (const result of results) {
+ length = Math.max(length, result.source.length);
}
+
+ return {results: results, length: length};
}
findKanji(text) {
@@ -115,27 +120,27 @@ class Translator {
const sl2 = v2.source.length;
if (sl1 > sl2) {
- return -1;
- } else if (sl1 > sl2) {
return 1;
+ } else if (sl1 > sl2) {
+ return -1;
}
const p1 = v1.tags.indexOf('P') >= 0;
const p2 = v2.tags.indexOf('P') >= 0;
if (p1 && !p2) {
- return -1;
- } else if (!p1 && p2) {
return 1;
+ } else if (!p1 && p2) {
+ return -1;
}
const rl1 = v1.rules.length;
const rl2 = v2.rules.length;
if (rl1 < rl2) {
- return -1;
- } else if (rl2 > rl1) {
return 1;
+ } else if (rl2 > rl1) {
+ return -1;
}
return 0;