summaryrefslogtreecommitdiff
path: root/ext/bg/js/dictionary.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r--ext/bg/js/dictionary.js44
1 files changed, 41 insertions, 3 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 41c90b1c..7d6d176c 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -170,9 +170,31 @@ function dictTermsMergeBySequence(definitions, mainDictionary) {
return definitionsBySequence;
}
-function dictTermsMergeByGloss(result, definitions) {
- const definitionsByGloss = {};
- for (const definition of definitions) {
+function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
+ const definitionsByGloss = appendTo || {};
+ for (const [index, definition] of definitions.entries()) {
+ if (appendTo) {
+ let match = false;
+ for (const expression of result.expressions.keys()) {
+ if (definition.expression === expression) {
+ for (const reading of result.expressions.get(expression).keys()) {
+ if (definition.reading === reading) {
+ match = true;
+ break;
+ }
+ }
+ }
+ if (match) {
+ break;
+ }
+ }
+
+ if (!match) {
+ continue;
+ } else if (mergedIndices) {
+ mergedIndices.add(index);
+ }
+ }
const gloss = JSON.stringify(definition.glossary);
if (!definitionsByGloss[gloss]) {
@@ -180,6 +202,7 @@ function dictTermsMergeByGloss(result, definitions) {
expression: new Set(),
reading: new Set(),
tags: new Set(),
+ glossary: definition.glossary,
source: result.source,
reasons: [],
score: definition.score,
@@ -212,6 +235,21 @@ function dictTermsMergeByGloss(result, definitions) {
}
}
+ for (const gloss in definitionsByGloss) {
+ const definition = definitionsByGloss[gloss];
+ definition.only = [];
+ if (!utilSetEqual(definition.expression, result.expression)) {
+ for (const expression of utilSetIntersection(definition.expression, result.expression)) {
+ definition.only.push(expression);
+ }
+ }
+ if (!utilSetEqual(definition.reading, result.reading)) {
+ for (const reading of utilSetIntersection(definition.reading, result.reading)) {
+ definition.only.push(reading);
+ }
+ }
+ }
+
return definitionsByGloss;
}