aboutsummaryrefslogtreecommitdiff
path: root/ext/jp/dictionary.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-03-20 17:15:40 -0700
committerAlex Yatskov <alex@foosoft.net>2016-03-20 17:15:40 -0700
commitd8a630fa2881a0cf012c6548706dde7c4740fe14 (patch)
tree80a4cc60c491373154d5c39146b3c0dac9eb3840 /ext/jp/dictionary.js
parent7208872b9fee135318b8a1a8b4483547b3986c89 (diff)
Simple lookup now works.
Diffstat (limited to 'ext/jp/dictionary.js')
-rw-r--r--ext/jp/dictionary.js50
1 files changed, 47 insertions, 3 deletions
diff --git a/ext/jp/dictionary.js b/ext/jp/dictionary.js
index 2b11d252..871a9550 100644
--- a/ext/jp/dictionary.js
+++ b/ext/jp/dictionary.js
@@ -18,11 +18,55 @@
class Dictionary {
- constructor(rules) {
- this.rules = rules;
+ constructor() {
+ this.termDicts = [];
+ this.kanjiDicts = [];
}
- deinflect(term, validator) {
+ addTermDict(termDict) {
+ this.termDicts.push(termDict);
+ }
+
+ addKanjiDict(kanjiDict) {
+ this.kanjiDicts.push(kanjiDict);
+ }
+
+
+ findTerm(term) {
+ let results = [];
+ for (let dict of this.termDicts) {
+ results = results.concat(this.findTermInDict(term, dict));
+ }
+
+ return results;
+ }
+
+ findKanji(kanji) {
+ const results = [];
+ for (let dict of this.kanjiDicts) {
+ const result = this.findKanjiInDict(kanji, dict);
+ if (result !== null) {
+ results.push(result);
+ }
+ }
+
+ return results;
+ }
+
+ 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};
+ });
+ }
+
+ findKanjiInDict(kanji, dict) {
+ const def = dict.defs[kanji];
+ if (def === null) {
+ return null;
+ }
+ const [c, k, o, g] = def;
+ return {character: c, kunyomi: k, onyomi: o, glossary: g};
}
}