summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-05 12:51:27 -0400
committerGitHub <noreply@github.com>2020-04-05 12:51:27 -0400
commitf439d12718247411ccd0575af0d1de82aa22564a (patch)
tree2989cc53af496a9d9b84134d7fd761300a8ddee4 /ext/bg/js
parent167e83c14794437e43b7df2017efab1e7e060a99 (diff)
parent938b69646820482a958cd8e0a65a03400ee6a7ac (diff)
Merge pull request #385 from toasted-nutbread/pitch-accents
Pitch accents
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/dictionary.js32
-rw-r--r--ext/bg/js/options.js5
-rw-r--r--ext/bg/js/settings/main.js6
-rw-r--r--ext/bg/js/translator.js22
4 files changed, 36 insertions, 29 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 3dd1d0c1..74bd5a64 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -137,30 +137,6 @@ function dictTermsGroup(definitions, dictionaries) {
return dictTermsSort(results);
}
-function dictAreSetsEqual(set1, set2) {
- if (set1.size !== set2.size) {
- return false;
- }
-
- for (const value of set1) {
- if (!set2.has(value)) {
- return false;
- }
- }
-
- return true;
-}
-
-function dictGetSetIntersection(set1, set2) {
- const result = [];
- for (const value of set1) {
- if (set2.has(value)) {
- result.push(value);
- }
- }
- return result;
-}
-
function dictTermsMergeBySequence(definitions, mainDictionary) {
const sequencedDefinitions = new Map();
const nonSequencedDefinitions = [];
@@ -281,11 +257,11 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices
const only = [];
const expressionSet = definition.expression;
const readingSet = definition.reading;
- if (!dictAreSetsEqual(expressionSet, resultExpressionSet)) {
- only.push(...dictGetSetIntersection(expressionSet, resultExpressionSet));
+ if (!areSetsEqual(expressionSet, resultExpressionSet)) {
+ only.push(...getSetIntersection(expressionSet, resultExpressionSet));
}
- if (!dictAreSetsEqual(readingSet, resultReadingSet)) {
- only.push(...dictGetSetIntersection(readingSet, resultReadingSet));
+ if (!areSetsEqual(readingSet, resultReadingSet)) {
+ only.push(...getSetIntersection(readingSet, resultReadingSet));
}
definition.only = only;
}
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index bd0bbe0e..b36fe812 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -124,7 +124,10 @@ function profileOptionsCreateDefaults() {
customPopupCss: '',
customPopupOuterCss: '',
enableWanakana: true,
- enableClipboardMonitor: false
+ enableClipboardMonitor: false,
+ showPitchAccentDownstepNotation: true,
+ showPitchAccentPositionNotation: true,
+ showPitchAccentGraph: false
},
audio: {
diff --git a/ext/bg/js/settings/main.js b/ext/bg/js/settings/main.js
index ebc443df..7caeaea0 100644
--- a/ext/bg/js/settings/main.js
+++ b/ext/bg/js/settings/main.js
@@ -84,6 +84,9 @@ async function formRead(options) {
options.general.popupScalingFactor = parseFloat($('#popup-scaling-factor').val());
options.general.popupScaleRelativeToPageZoom = $('#popup-scale-relative-to-page-zoom').prop('checked');
options.general.popupScaleRelativeToVisualViewport = $('#popup-scale-relative-to-visual-viewport').prop('checked');
+ options.general.showPitchAccentDownstepNotation = $('#show-pitch-accent-downstep-notation').prop('checked');
+ options.general.showPitchAccentPositionNotation = $('#show-pitch-accent-position-notation').prop('checked');
+ options.general.showPitchAccentGraph = $('#show-pitch-accent-graph').prop('checked');
options.general.popupTheme = $('#popup-theme').val();
options.general.popupOuterTheme = $('#popup-outer-theme').val();
options.general.customPopupCss = $('#custom-popup-css').val();
@@ -161,6 +164,9 @@ async function formWrite(options) {
$('#popup-scaling-factor').val(options.general.popupScalingFactor);
$('#popup-scale-relative-to-page-zoom').prop('checked', options.general.popupScaleRelativeToPageZoom);
$('#popup-scale-relative-to-visual-viewport').prop('checked', options.general.popupScaleRelativeToVisualViewport);
+ $('#show-pitch-accent-downstep-notation').prop('checked', options.general.showPitchAccentDownstepNotation);
+ $('#show-pitch-accent-position-notation').prop('checked', options.general.showPitchAccentPositionNotation);
+ $('#show-pitch-accent-graph').prop('checked', options.general.showPitchAccentGraph);
$('#popup-theme').val(options.general.popupTheme);
$('#popup-outer-theme').val(options.general.popupOuterTheme);
$('#custom-popup-css').val(options.general.customPopupCss);
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 6f43f7b0..f16889ce 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -490,6 +490,7 @@ class Translator {
// New data
term.frequencies = [];
+ term.pitches = [];
}
const metas = await this.database.findTermMetaBulk(expressionsUnique, dictionaries);
@@ -500,6 +501,13 @@ class Translator {
term.frequencies.push({expression, frequency: data, dictionary});
}
break;
+ case 'pitch':
+ for (const term of termsUnique[index]) {
+ const pitchData = await this.getPitchData(expression, data, dictionary, term);
+ if (pitchData === null) { continue; }
+ term.pitches.push(pitchData);
+ }
+ break;
}
}
}
@@ -583,6 +591,20 @@ class Translator {
return tagMetaList;
}
+ async getPitchData(expression, data, dictionary, term) {
+ const reading = data.reading;
+ const termReading = term.reading || expression;
+ if (reading !== termReading) { return null; }
+
+ const pitches = [];
+ for (let {position, tags} of data.pitches) {
+ tags = Array.isArray(tags) ? await this.getTagMetaList(tags, dictionary) : [];
+ pitches.push({position, tags});
+ }
+
+ return {reading, pitches, dictionary};
+ }
+
static createExpression(expression, reading, termTags=null, termFrequency=null) {
const furiganaSegments = jp.distributeFurigana(expression, reading);
return {