This commit is contained in:
Alex Yatskov 2016-12-17 21:42:53 -08:00
parent 5be864bb6f
commit d44f0c5764
2 changed files with 19 additions and 15 deletions

View File

@ -64,6 +64,7 @@ class Database {
reading: row.reading, reading: row.reading,
tags: splitField(row.tags), tags: splitField(row.tags),
glossary: row.glossary, glossary: row.glossary,
score: row.score,
dictionary: row.dictionary, dictionary: row.dictionary,
id: row.id id: row.id
}); });
@ -117,7 +118,7 @@ class Database {
continue; continue;
} }
const tagMeta = this.tagMetaCache[dictionary] = {}; const tagMeta = {};
promises.push( promises.push(
this.db.tagMeta.where('dictionary').equals(dictionary).each(row => { this.db.tagMeta.where('dictionary').equals(dictionary).each(row => {
tagMeta[row.name] = { tagMeta[row.name] = {
@ -125,6 +126,8 @@ class Database {
notes: row.notes, notes: row.notes,
order: row.order order: row.order
}; };
}).then(() => {
this.tagMetaCache[dictionary] = tagMeta;
}) })
); );
} }

View File

@ -42,10 +42,10 @@ class Translator {
} }
findTerm(text, dictionaries, enableSoftKatakanaSearch) { findTerm(text, dictionaries, enableSoftKatakanaSearch) {
return this.findDeinflectGroups(text, dictionaries).then(groups => { return this.findDeinflectionGroups(text, dictionaries).then(groups => {
const textHiragana = wanakana._katakanaToHiragana(text); const textHiragana = wanakana._katakanaToHiragana(text);
if (text !== textHiragana && enableSoftKatakanaSearch) { if (text !== textHiragana && enableSoftKatakanaSearch) {
return this.findDeinflectGroups(textHiragana, dictionaries).then(groupsHiragana => { return this.findDeinflectionGroups(textHiragana, dictionaries).then(groupsHiragana => {
for (const key in groupsHiragana) { for (const key in groupsHiragana) {
groups[key] = groups[key] || groupsHiragana[key]; groups[key] = groups[key] || groupsHiragana[key];
} }
@ -87,24 +87,24 @@ class Translator {
return Promise.all(promises).then(sets => this.processKanji(sets.reduce((a, b) => a.concat(b), []))); return Promise.all(promises).then(sets => this.processKanji(sets.reduce((a, b) => a.concat(b), [])));
} }
findDeinflectGroups(text, dictionaries) { findDeinflectionGroups(text, dictionaries) {
const deinflectGroups = {}; const deinflectionGroups = {};
const deinflectPromises = []; const deinflectionPromises = [];
for (let i = text.length; i > 0; --i) { for (let i = text.length; i > 0; --i) {
deinflectPromises.push( deinflectionPromises.push(
this.deinflector.deinflect(text.slice(0, i), term => { this.deinflector.deinflect(text.slice(0, i), term => {
return this.database.findTerm(term, dictionaries).then(definitions => definitions.map(definition => definition.rules)); return this.database.findTerm(term, dictionaries).then(definitions => definitions.map(definition => definition.rules));
}).then(deinflects => { }).then(deinflections => {
const processPromises = []; const processPromises = [];
for (const deinflect of deinflects) { for (const deinflection of deinflections) {
processPromises.push( processPromises.push(
this.processDeinflection( this.processDeinflection(
deinflectGroups, deinflectionGroups,
deinflect.source, deinflection.source,
deinflect.rules, deinflection.rules,
deinflect.reasons, deinflection.reasons,
deinflect.root, deinflection.root,
dictionaries dictionaries
) )
); );
@ -115,7 +115,7 @@ class Translator {
); );
} }
return Promise.all(deinflectPromises).then(() => deinflectGroups); return Promise.all(deinflectionPromises).then(() => deinflectionGroups);
} }
processDeinflection(groups, source, rules, reasons, root, dictionaries) { processDeinflection(groups, source, rules, reasons, root, dictionaries) {
@ -142,6 +142,7 @@ class Translator {
source, source,
reasons, reasons,
score: definition.score, score: definition.score,
dictionary: definition.dictionary,
expression: definition.expression, expression: definition.expression,
reading: definition.reading, reading: definition.reading,
glossary: definition.glossary, glossary: definition.glossary,