Work on new dictionary format
This commit is contained in:
parent
bf28dea283
commit
972b945b4c
@ -33,16 +33,33 @@ class Dictionary {
|
|||||||
|
|
||||||
findTerm(term) {
|
findTerm(term) {
|
||||||
const results = [];
|
const results = [];
|
||||||
return (this.termIndices[term] || []).map(index => {
|
|
||||||
const [e, r, g, t] = this.terms[index];
|
for (const name in this.termDicts) {
|
||||||
return {id: index, expression: e, reading: r, glossary: g, tags: t.split(' ')};
|
const dict = this.termDicts[name];
|
||||||
});
|
const indices = dict.indices[term] || [];
|
||||||
|
|
||||||
|
results.push(
|
||||||
|
indices.map(index => {
|
||||||
|
const [e, r, t, ...g] = dict.defs[index];
|
||||||
|
return {id: index, expression: e, reading: r, glossary: g.join('; '), tags: t.split(' ')};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
findKanji(kanji) {
|
findKanji(kanji) {
|
||||||
return (this.kanjiIndices[kanji] || []).map(index => {
|
const results = [];
|
||||||
const [c, k, o, g] = def;
|
|
||||||
return {id: index, character: c, kunyomi: k, onyomi: o, glossary: g};
|
for (const name in this.termDicts) {
|
||||||
});
|
const def = this.termDicts[name][kanji];
|
||||||
|
if (def) {
|
||||||
|
const [c, k, o, g] = def;
|
||||||
|
results.push({id: index, character: c, kunyomi: k, onyomi: o, glossary: g});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ class Translator {
|
|||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
this.paths = {
|
this.paths = {
|
||||||
rules: 'bg/data/rules.json',
|
rules: 'bg/data/rules.json',
|
||||||
edict: 'bg/data/edict.csv',
|
edict: 'bg/data/edict.json',
|
||||||
enamdict: 'bg/data/enamdict.csv',
|
enamdict: 'bg/data/enamdict.json',
|
||||||
kanjidic: 'bg/data/kanjidic.csv'
|
kanjidic: 'bg/data/kanjidic.json'
|
||||||
};
|
};
|
||||||
|
|
||||||
this.dictionary = new Dictionary();
|
this.dictionary = new Dictionary();
|
||||||
@ -46,7 +46,7 @@ class Translator {
|
|||||||
this.deinflector.setRules(JSON.parse(response));
|
this.deinflector.setRules(JSON.parse(response));
|
||||||
break;
|
break;
|
||||||
case 'kanjidic':
|
case 'kanjidic':
|
||||||
this.dictionary.addKanjiDict('kanjidic', JSON.parse(response));
|
this.dictionary.addKanjiDict(key, JSON.parse(response));
|
||||||
break;
|
break;
|
||||||
case 'edict':
|
case 'edict':
|
||||||
case 'enamdict':
|
case 'enamdict':
|
||||||
|
Loading…
Reference in New Issue
Block a user