aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-27 15:08:55 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-16 22:39:26 -0500
commita50e2fb0f12838673543131c02e7ca37fe4b66fb (patch)
treebb8c848a5881121a708135ce7f52d9de7f4c266c /ext/bg
parent56ee7f8df47a3826e10d9b0876f313f5ced4c98e (diff)
Fix furigana segmentation
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/dictionary.js3
-rw-r--r--ext/bg/js/translator.js33
2 files changed, 23 insertions, 13 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index ee7ee756..67128725 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -147,8 +147,9 @@ function dictTermsGroup(definitions, dictionaries) {
definitions: groupDefs,
expression: firstDef.expression,
reading: firstDef.reading,
+ furiganaSegments: firstDef.furiganaSegments,
reasons: firstDef.reasons,
- termTags: groupDefs[0].termTags,
+ termTags: firstDef.termTags,
score: groupDefs.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER),
source: firstDef.source
});
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 7473c6ad..e31f9f62 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -121,16 +121,10 @@ class Translator {
dictTermsSort(result.definitions, dictionaries);
const expressions = [];
- for (const expression of result.expressions.keys()) {
- for (const reading of result.expressions.get(expression).keys()) {
- const termTags = result.expressions.get(expression).get(reading);
+ for (const [expression, readingMap] of result.expressions.entries()) {
+ for (const [reading, termTags] of readingMap.entries()) {
const score = termTags.map((tag) => tag.score).reduce((p, v) => p + v, 0);
- expressions.push({
- expression: expression,
- reading: reading,
- termTags: dictTagsSort(termTags),
- termFrequency: Translator.scoreToTermFrequency(score)
- });
+ expressions.push(Translator.createExpression(expression, reading, dictTagsSort(termTags), Translator.scoreToTermFrequency(score)));
}
}
@@ -194,7 +188,7 @@ class Translator {
const strayDefinitions = defaultDefinitions.filter((definition, index) => !mergedByTermIndices.has(index));
for (const groupedDefinition of dictTermsGroup(strayDefinitions, dictionaries)) {
- groupedDefinition.expressions = [{expression: groupedDefinition.expression, reading: groupedDefinition.reading}];
+ groupedDefinition.expressions = [Translator.createExpression(expression, reading)];
definitionsMerged.push(groupedDefinition);
}
@@ -241,14 +235,18 @@ class Translator {
definitionTags.push(dictTagBuildSource(definition.dictionary));
const termTags = await this.expandTags(definition.termTags, definition.dictionary);
+ const {expression, reading} = definition;
+ const furiganaSegments = jpDistributeFurigana(expression, reading);
+
definitions.push({
source: deinflection.source,
reasons: deinflection.reasons,
score: definition.score,
id: definition.id,
dictionary: definition.dictionary,
- expression: definition.expression,
- reading: definition.reading,
+ expression,
+ reading,
+ furiganaSegments,
glossary: definition.glossary,
definitionTags: dictTagsSort(definitionTags),
termTags: dictTagsSort(termTags),
@@ -504,6 +502,17 @@ class Translator {
return tagMetaList;
}
+ static createExpression(expression, reading, termTags=null, termFrequency=null) {
+ const furiganaSegments = jpDistributeFurigana(expression, reading);
+ return {
+ expression,
+ reading,
+ furiganaSegments,
+ termTags,
+ termFrequency
+ };
+ }
+
static scoreToTermFrequency(score) {
if (score > 0) {
return 'popular';