From 2ee3e3a7a18cc8cb71febe3030c149e0280ed9a7 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 18 Jul 2021 16:01:42 -0400 Subject: Update pronunciation anki templates (#1842) * Update anki pronunciation templates * Expose nasalPositions/devoicePositions * Update templates to support nasal/devoice positions * Update test data --- .../anki-field-templates-upgrade-v13.handlebars | 83 ++++++++++++++++++++++ .../default-anki-field-templates.handlebars | 67 +---------------- ext/js/data/options-util.js | 1 + ext/js/data/sandbox/anki-note-data-creator.js | 4 +- 4 files changed, 89 insertions(+), 66 deletions(-) (limited to 'ext') diff --git a/ext/data/templates/anki-field-templates-upgrade-v13.handlebars b/ext/data/templates/anki-field-templates-upgrade-v13.handlebars index b3e0f1b9..afa5a2c0 100644 --- a/ext/data/templates/anki-field-templates-upgrade-v13.handlebars +++ b/ext/data/templates/anki-field-templates-upgrade-v13.handlebars @@ -63,3 +63,86 @@ {{=======}} {{~#if (hasMedia "clipboardText")}}{{#getMedia "clipboardText"}}{{/getMedia}}{{/if~}} {{>>>>>>>}} + +{{<<<<<<<}} +{{#*inline "pitch-accent-item-downstep-notation"}} + {{~#scope~}} + + {{~#set "style1a"~}}display:inline-block;position:relative;{{~/set~}} + {{~#set "style1b"~}}padding-right:0.1em;margin-right:0.1em;{{~/set~}} + {{~#set "style2a"~}}display:block;user-select:none;pointer-events:none;position:absolute;top:0.1em;left:0;right:0;height:0;border-top:0.1em solid;{{~/set~}} + {{~#set "style2b"~}}right:-0.1em;height:0.4em;border-right:0.1em solid;{{~/set~}} + {{~#each (getKanaMorae reading)~}} + {{~#set "style1"}}{{#get "style1a"}}{{/get}}{{/set~}} + {{~#set "style2"}}{{/set~}} + {{~#if (isMoraPitchHigh @index ../position)}} + {{~#set "style2"}}{{#get "style2a"}}{{/get}}{{/set~}} + {{~#if (op "!" (isMoraPitchHigh (op "+" @index 1) ../position))~}} + {{~#set "style1" (op "+" (get "style1") (get "style1b"))}}{{/set~}} + {{~#set "style2" (op "+" (get "style2") (get "style2b"))}}{{/set~}} + {{~/if~}} + {{~/if~}} + {{{.}}} + {{~/each~}} + + {{~/scope~}} +{{/inline}} + +{{#*inline "pitch-accent-item-graph-position-x"}}{{#op "+" 25 (op "*" index 50)}}{{/op}}{{/inline}} +{{#*inline "pitch-accent-item-graph-position-y"}}{{#op "+" 25 (op "?:" (isMoraPitchHigh index position) 0 50)}}{{/op}}{{/inline}} +{{#*inline "pitch-accent-item-graph-position"}}{{> pitch-accent-item-graph-position-x index=index position=position}} {{> pitch-accent-item-graph-position-y index=index position=position}}{{/inline}} +{{#*inline "pitch-accent-item-graph"}} + {{~#scope~}} + {{~#set "morae" (getKanaMorae reading)}}{{/set~}} + {{~#set "morae-count" (property (get "morae") "length")}}{{/set~}} + + + + + + + pitch-accent-item-graph-position index=@index position=../position~}} + {{~#set "cmd" "L"}}{{/set~}} + {{~/each~}} + "> + pitch-accent-item-graph-position index=(get "morae-count") position=position}}"> + {{#each (get "morae")}} + + {{/each}} + + + {{~/scope~}} +{{/inline}} + +{{#*inline "pitch-accent-item-position"~}} + [{{position}}] +{{~/inline}} + +{{#*inline "pitch-accent-item"}} + {{~#if (op "==" format "downstep-notation")~}} + {{~> pitch-accent-item-downstep-notation~}} + {{~else if (op "==" format "graph")~}} + {{~> pitch-accent-item-graph~}} + {{~else if (op "==" format "position")~}} + {{~> pitch-accent-item-position~}} + {{~/if~}} +{{/inline}} +{{=======}} +{{#*inline "pitch-accent-item"}} + {{~#pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}}{{~/pronunciation~}} +{{/inline}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{#*inline "pitch-accents"}} + {{~> pitch-accent-list format='downstep-notation'~}} +{{/inline}} +{{=======}} +{{#*inline "pitch-accents"}} + {{~> pitch-accent-list format='text'~}} +{{/inline}} +{{>>>>>>>}} diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 92f9c6b7..31d5d13f 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -183,71 +183,8 @@ {{/inline}} {{! Pitch Accents }} -{{#*inline "pitch-accent-item-downstep-notation"}} - {{~#scope~}} - - {{~#set "style1a"~}}display:inline-block;position:relative;{{~/set~}} - {{~#set "style1b"~}}padding-right:0.1em;margin-right:0.1em;{{~/set~}} - {{~#set "style2a"~}}display:block;user-select:none;pointer-events:none;position:absolute;top:0.1em;left:0;right:0;height:0;border-top:0.1em solid;{{~/set~}} - {{~#set "style2b"~}}right:-0.1em;height:0.4em;border-right:0.1em solid;{{~/set~}} - {{~#each (getKanaMorae reading)~}} - {{~#set "style1"}}{{#get "style1a"}}{{/get}}{{/set~}} - {{~#set "style2"}}{{/set~}} - {{~#if (isMoraPitchHigh @index ../position)}} - {{~#set "style2"}}{{#get "style2a"}}{{/get}}{{/set~}} - {{~#if (op "!" (isMoraPitchHigh (op "+" @index 1) ../position))~}} - {{~#set "style1" (op "+" (get "style1") (get "style1b"))}}{{/set~}} - {{~#set "style2" (op "+" (get "style2") (get "style2b"))}}{{/set~}} - {{~/if~}} - {{~/if~}} - {{{.}}} - {{~/each~}} - - {{~/scope~}} -{{/inline}} - -{{#*inline "pitch-accent-item-graph-position-x"}}{{#op "+" 25 (op "*" index 50)}}{{/op}}{{/inline}} -{{#*inline "pitch-accent-item-graph-position-y"}}{{#op "+" 25 (op "?:" (isMoraPitchHigh index position) 0 50)}}{{/op}}{{/inline}} -{{#*inline "pitch-accent-item-graph-position"}}{{> pitch-accent-item-graph-position-x index=index position=position}} {{> pitch-accent-item-graph-position-y index=index position=position}}{{/inline}} -{{#*inline "pitch-accent-item-graph"}} - {{~#scope~}} - {{~#set "morae" (getKanaMorae reading)}}{{/set~}} - {{~#set "morae-count" (property (get "morae") "length")}}{{/set~}} - - - - - - - pitch-accent-item-graph-position index=@index position=../position~}} - {{~#set "cmd" "L"}}{{/set~}} - {{~/each~}} - "> - pitch-accent-item-graph-position index=(get "morae-count") position=position}}"> - {{#each (get "morae")}} - - {{/each}} - - - {{~/scope~}} -{{/inline}} - -{{#*inline "pitch-accent-item-position"~}} - [{{position}}] -{{~/inline}} - {{#*inline "pitch-accent-item"}} - {{~#if (op "==" format "downstep-notation")~}} - {{~> pitch-accent-item-downstep-notation~}} - {{~else if (op "==" format "graph")~}} - {{~> pitch-accent-item-graph~}} - {{~else if (op "==" format "position")~}} - {{~> pitch-accent-item-position~}} - {{~/if~}} + {{~#pronunciation format=format reading=reading downstepPosition=position nasalPositions=nasalPositions devoicePositions=devoicePositions~}}{{~/pronunciation~}} {{/inline}} {{#*inline "pitch-accent-item-disambiguation"}} @@ -280,7 +217,7 @@ {{/inline}} {{#*inline "pitch-accents"}} - {{~> pitch-accent-list format='downstep-notation'~}} + {{~> pitch-accent-list format='text'~}} {{/inline}} {{#*inline "pitch-accent-graphs"}} diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index d131d0c6..42d8a93a 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -857,6 +857,7 @@ class OptionsUtil { // Added {selection-text} field marker. // Added {sentence-furigana} field marker. // Added anki.duplicateScopeCheckAllModels. + // Updated pronunciation templates. await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v13.handlebars'); for (const profile of options.profiles) { profile.options.anki.duplicateScopeCheckAllModels = false; diff --git a/ext/js/data/sandbox/anki-note-data-creator.js b/ext/js/data/sandbox/anki-note-data-creator.js index 3622e837..e09c6d7b 100644 --- a/ext/js/data/sandbox/anki-note-data-creator.js +++ b/ext/js/data/sandbox/anki-note-data-creator.js @@ -159,11 +159,13 @@ class AnkiNoteDataCreator { if (dictionaryEntry.type === 'term') { for (const {dictionary, pitches} of DictionaryDataUtil.getPitchAccentInfos(dictionaryEntry)) { const pitches2 = []; - for (const {terms, reading, position, tags, exclusiveTerms, exclusiveReadings} of pitches) { + for (const {terms, reading, position, nasalPositions, devoicePositions, tags, exclusiveTerms, exclusiveReadings} of pitches) { pitches2.push({ expressions: terms, reading, position, + nasalPositions, + devoicePositions, tags, exclusiveExpressions: exclusiveTerms, exclusiveReadings -- cgit v1.2.3