summaryrefslogtreecommitdiff
path: root/ext/bg/js/dictionary.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-12 20:58:41 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-12 20:58:41 -0700
commitbf28dea2838619c6446367f240e240cdddef3586 (patch)
treeb30b9c6b2a8c70092df395492c44300c4d8c6a63 /ext/bg/js/dictionary.js
parent7d0991f9c1b1379c669c0da9f1f678285dd0c968 (diff)
Updating dictionaries
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r--ext/bg/js/dictionary.js33
1 files changed, 7 insertions, 26 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index a68c2daf..feb8c92b 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -19,31 +19,20 @@
class Dictionary {
constructor() {
- this.terms = [];
- this.termIndices = {};
-
- this.kanji = [];
- this.kanjiIndices = {};
+ this.termDicts = {};
+ this.kanjiDicts = {};
}
- addTermData(terms) {
- let index = this.terms.length;
- for (const [e, r, g, t] of terms) {
- this.storeIndex(this.termIndices, e, index);
- this.storeIndex(this.termIndices, r, index++);
- this.terms.push([e, r, g, t]);
- }
+ addTermDict(name, dict) {
+ this.termDicts[name] = dict;
}
- addKanjiData(kanji) {
- let index = this.kanji.length;
- for (const [c, k, o, g] of kanji) {
- this.storeIndex(this.kanjiIndices, c, index++);
- this.kanji.push([c, k, o, g]);
- }
+ addKanjiDict(name, dict) {
+ this.kanjiDicts[name] = dict;
}
findTerm(term) {
+ const results = [];
return (this.termIndices[term] || []).map(index => {
const [e, r, g, t] = this.terms[index];
return {id: index, expression: e, reading: r, glossary: g, tags: t.split(' ')};
@@ -56,12 +45,4 @@ class Dictionary {
return {id: index, character: c, kunyomi: k, onyomi: o, glossary: g};
});
}
-
- storeIndex(indices, term, index) {
- if (term.length > 0) {
- const indices = this.termIndices[term] || [];
- indices.push(index);
- this.termIndices[term] = indices;
- }
- }
}