From aa2a0c09f446aaa4ac5b052f5b9afb040e37afc2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 28 Mar 2020 14:52:44 -0400 Subject: Update how pitch accent expressions are disambiguated --- ext/mixed/js/display-generator.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js index 30c82472..8177c31c 100644 --- a/ext/mixed/js/display-generator.js +++ b/ext/mixed/js/display-generator.js @@ -304,7 +304,7 @@ class DisplayGenerator { } createPitch(details) { - const {expressions, reading, position, tags} = details; + const {exclusiveExpressions, reading, position, tags} = details; const morae = jp.getKanaMorae(reading); const node = this._templateHandler.instantiate('term-pitch-accent'); @@ -319,7 +319,7 @@ class DisplayGenerator { DisplayGenerator._appendMultiple(n, this.createTag.bind(this), tags); n = node.querySelector('.term-pitch-accent-expression-list'); - DisplayGenerator._appendMultiple(n, this.createPitchExpression.bind(this), expressions); + DisplayGenerator._appendMultiple(n, this.createPitchExpression.bind(this), exclusiveExpressions); n = node.querySelector('.term-pitch-accent-characters'); for (let i = 0, ii = morae.length; i < ii; ++i) { @@ -481,6 +481,7 @@ class DisplayGenerator { static _getPitchInfos(definition) { const results = new Map(); + const allExpressions = new Set(); const expressions = definition.expressions; const sources = Array.isArray(expressions) ? expressions : [definition]; for (const {pitches: expressionPitches, expression} of sources) { @@ -498,10 +499,22 @@ class DisplayGenerator { dictionaryResults.push(pitchInfo); } pitchInfo.expressions.add(expression); + allExpressions.add(expression); } } } + for (const dictionaryResults of results.values()) { + for (const result of dictionaryResults) { + const exclusiveExpressions = []; + const resultExpressions = result.expressions; + if (!areSetsEqual(resultExpressions, allExpressions)) { + exclusiveExpressions.push(...getSetIntersection(resultExpressions, allExpressions)); + } + result.exclusiveExpressions = exclusiveExpressions; + } + } + return [...results.entries()]; } -- cgit v1.2.3