Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dictionary deinflections #503

Merged
merged 33 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b45c902
wip
StefanVukovic99 Dec 25, 2023
509ef80
Merge remote-tracking branch 'origin/master' into dictionary-deinflec…
StefanVukovic99 Dec 30, 2023
18320bd
wip
StefanVukovic99 Jan 2, 2024
cd2ddc5
Merge remote-tracking branch 'origin' into dictionary-deinflection
StefanVukovic99 Jan 2, 2024
e3ed96c
fix v3
StefanVukovic99 Jan 2, 2024
3cd200e
wip
StefanVukovic99 Jan 3, 2024
41a5c4b
fix tests
StefanVukovic99 Jan 3, 2024
c225ff1
fix maxitems
StefanVukovic99 Jan 3, 2024
ec801d6
hide deinflection definitions
StefanVukovic99 Jan 3, 2024
a70955e
fix anki template
StefanVukovic99 Jan 3, 2024
e6fd453
undo unnecessary change
StefanVukovic99 Jan 3, 2024
6c97c26
delete console.log
StefanVukovic99 Jan 3, 2024
8fecd11
refactor
StefanVukovic99 Jan 3, 2024
0ad389d
add set false to handlebars
StefanVukovic99 Jan 3, 2024
ad57485
lint
StefanVukovic99 Jan 3, 2024
a17a46a
fix tests
StefanVukovic99 Jan 3, 2024
1bb59d3
fix comments
StefanVukovic99 Jan 5, 2024
33fc672
fix
StefanVukovic99 Jan 5, 2024
a8b48fa
Merge remote-tracking branch 'origin/master' into dictionary-deinflec…
StefanVukovic99 Jan 6, 2024
f159b39
use Map in areArraysEqualIgnoreOrder
StefanVukovic99 Jan 9, 2024
77cc705
move inflection source icons to css
StefanVukovic99 Jan 11, 2024
a0a7609
lint
StefanVukovic99 Jan 11, 2024
d110c4f
improve naming
StefanVukovic99 Jan 13, 2024
b4eab14
Merge remote-tracking branch 'origin/master' into dictionary-deinflec…
StefanVukovic99 Jan 13, 2024
249c4b9
fix tests
StefanVukovic99 Jan 13, 2024
49c84fb
add test
StefanVukovic99 Jan 13, 2024
778c4bf
typescript
StefanVukovic99 Jan 13, 2024
9d1ed7d
use for of
StefanVukovic99 Jan 13, 2024
18c6df3
Merge remote-tracking branch 'origin/master' into dictionary-deinflec…
StefanVukovic99 Jan 16, 2024
bc9c024
wip
StefanVukovic99 Jan 16, 2024
ff67a5b
comments
StefanVukovic99 Jan 17, 2024
6325c29
anki template upgrade
StefanVukovic99 Jan 17, 2024
ebe0c39
update descriptions
StefanVukovic99 Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions ext/css/display.css
Original file line number Diff line number Diff line change
Expand Up @@ -809,17 +809,39 @@ button.action-button:active {


/* Inflections */
.inflection-list {
display: inline-block;
.inflection-possibilities {
padding-inline-start: 0;
list-style-type: none;
}
.inflection-possibility {
color: var(--reason-text-color);
}
.inflection-list:empty {
.inflection-possibility:empty {
display: none;
}
.inflection-list>.inflection+.inflection-separator+.inflection::before {
.inflection-possibility>.inflection+.inflection-separator+.inflection::before {
content: var(--inflection-separator);
padding: 0 0.25em;
}
.inflection-source-icon {
display: inline-block;
white-space: nowrap;
text-align: center;
width: 1.4em;
margin-right: 0.2em;
}
.inflection-source-icon[data-inflection-source='dictionary']::after {
content: '📖';
}
.inflection-source-icon[data-inflection-source='algorithm']::after {
content: '🧩';
}
.inflection-source-icon[data-inflection-source='both'] {
width: 2.8em;
}
.inflection-source-icon[data-inflection-source='both']::after {
content: '🧩📖';
}


/* Headwords */
Expand Down
20 changes: 19 additions & 1 deletion ext/data/schemas/dictionary-term-bank-v3-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@
},
{
"type": "string",
"description": "String of space-separated rule identifiers for the definition which is used to validate delinflection. Valid rule identifiers are: v1: ichidan verb; v5: godan verb; vs: suru verb; vk: kuru verb; adj-i: i-adjective. An empty string corresponds to words which aren't inflected, such as nouns."
"description": "String of space-separated rule identifiers for the definition which is used to validate deinflection. An empty string should be used for words which aren't inflected."
},
{
"type": "number",
Expand Down Expand Up @@ -532,6 +532,24 @@
}
}
]
},
{
"type": "array",
"description": "Deinflection of the term to a non-inflected term.",
"items": [
{
"type": "string",
"description": "The deinflected term."
},
{
"type": "array",
"description": "A possible inflection combination that produced the inflected term",
"items": {
"type": "string",
"description": "An inflection."
}
}
]
}
]
}
Expand Down
7 changes: 6 additions & 1 deletion ext/data/schemas/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,8 @@
"enabled",
"allowSecondarySearches",
"definitionsCollapsible",
"partsOfSpeechFilter"
"partsOfSpeechFilter",
"useDeinflections"
],
"properties": {
"name": {
Expand All @@ -850,6 +851,10 @@
"partsOfSpeechFilter": {
"type": "boolean",
"default": true
},
"useDeinflections": {
"type": "boolean",
"default": true
}
}
}
Expand Down
22 changes: 17 additions & 5 deletions ext/data/templates/default-anki-field-templates.handlebars
StefanVukovic99 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,23 @@
{{/inline}}

{{#*inline "conjugation"}}
{{~#if definition.reasons~}}
{{~#each definition.reasons~}}
{{~#if (op ">" @index 0)}} « {{/if~}}
{{.}}
{{~/each~}}
{{~#if (op ">" definition.inflectionPossibilities.length 0)~}}
{{~set "multiple" false~}}
{{~#if (op ">" definition.inflectionPossibilities.length 1)~}}
{{~set "multiple" true~}}
{{~/if~}}
{{~#if (get "multiple")~}}<ul>{{/if~}}
{{~#each definition.inflectionPossibilities~}}
{{~#if (op ">" inflections.length 0)~}}
{{~#if (get "multiple")~}}<li>{{/if~}}
{{~#each inflections~}}
{{~#if (op ">" @index 0)}} « {{/if~}}
{{.}}
{{~/each~}}
{{~#if (get "multiple")~}}</li>{{/if~}}
{{~/if~}}
{{~/each~}}
{{~#if (get "multiple")~}}</ul>{{/if~}}
{{~/if~}}
{{/inline}}

Expand Down
3 changes: 2 additions & 1 deletion ext/display-templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div class="headword-list"></div>
<div class="headword-list-details">
<div class="headword-list-tag-list tag-list"></div>
<div class="inflection-list"></div>
<ul class="inflection-possibilities"></ul>
</div>
</div>
<div class="entry-body">
Expand Down Expand Up @@ -77,6 +77,7 @@
<template id="definition-disambiguation-template"><span class="definition-disambiguation"></span></template>
<template id="gloss-item-template"><li class="gloss-item click-scannable"><span class="gloss-separator"> </span><span class="gloss-content"></span></li></template>
<template id="gloss-item-image-description-template"> <span class="gloss-image-description"></span></template>
<template id="inflection-possibility-template"><li class="inflection-possibility"></li></template>
<template id="inflection-template"><span class="inflection"></span><span class="inflection-separator"> </span></template>

<!-- Frequency templates -->
Expand Down
8 changes: 5 additions & 3 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,8 @@ export class Backend {
index: enabledDictionaryMap.size,
priority: 0,
allowSecondarySearches: false,
partsOfSpeechFilter: true
partsOfSpeechFilter: true,
useDeinflections: true
});
excludeDictionaryDefinitions = new Set();
excludeDictionaryDefinitions.add(mainDictionary);
Expand Down Expand Up @@ -2474,12 +2475,13 @@ export class Backend {
const enabledDictionaryMap = new Map();
for (const dictionary of options.dictionaries) {
if (!dictionary.enabled) { continue; }
const {name, priority, allowSecondarySearches, partsOfSpeechFilter} = dictionary;
const {name, priority, allowSecondarySearches, partsOfSpeechFilter, useDeinflections} = dictionary;
enabledDictionaryMap.set(name, {
index: enabledDictionaryMap.size,
priority,
allowSecondarySearches,
partsOfSpeechFilter
partsOfSpeechFilter,
useDeinflections
});
}
return enabledDictionaryMap;
Expand Down
15 changes: 14 additions & 1 deletion ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ export class OptionsUtil {
this._updateVersion20,
this._updateVersion21,
this._updateVersion22,
this._updateVersion23
this._updateVersion23,
this._updateVersion24
];
if (typeof targetVersion === 'number' && targetVersion < result.length) {
result.splice(targetVersion);
Expand Down Expand Up @@ -1155,6 +1156,18 @@ export class OptionsUtil {
}
}

/**
* - Added dictionaries[].useDeinflections.
* @type {import('options-util').UpdateFunction}
*/
_updateVersion24(options) {
for (const {options: profileOptions} of options.profiles) {
for (const dictionary of profileOptions.dictionaries) {
dictionary.useDeinflections = true;
}
}
}

/**
* @param {string} url
* @returns {Promise<chrome.tabs.Tab>}
Expand Down
4 changes: 2 additions & 2 deletions ext/js/data/sandbox/anki-note-data-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export class AnkiNoteDataCreator {
case 'merge': type = 'termMerged'; break;
}

const {inflections, score, dictionaryIndex, dictionaryPriority, sourceTermExactMatchCount, definitions} = dictionaryEntry;
const {inflectionPossibilities, score, dictionaryIndex, dictionaryPriority, sourceTermExactMatchCount, definitions} = dictionaryEntry;

let {url} = context;
if (typeof url !== 'string') { url = ''; }
Expand All @@ -401,7 +401,7 @@ export class AnkiNoteDataCreator {
source: (primarySource !== null ? primarySource.transformedText : null),
rawSource: (primarySource !== null ? primarySource.originalText : null),
sourceTerm: (type !== 'termMerged' ? (primarySource !== null ? primarySource.deinflectedText : null) : void 0),
reasons: inflections,
inflectionPossibilities,
score,
isPrimary: (type === 'term' ? dictionaryEntry.isPrimary : void 0),
get sequence() { return self.getCachedValue(sequence); },
Expand Down
2 changes: 1 addition & 1 deletion ext/js/dictionary/dictionary-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class DictionaryImporter {
const glossaryList = entry.glossary;
for (let j = 0, jj = glossaryList.length; j < jj; ++j) {
const glossary = glossaryList[j];
if (typeof glossary !== 'object' || glossary === null) { continue; }
if (typeof glossary !== 'object' || glossary === null || Array.isArray(glossary)) { continue; }
glossaryList[j] = this._formatDictionaryTermGlossaryObject(glossary, entry, requirements);
}
if ((i % formatProgressInterval) === 0) {
Expand Down
48 changes: 44 additions & 4 deletions ext/js/display/display-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ export class DisplayGenerator {
const node = this._instantiate('term-entry');

const headwordsContainer = this._querySelector(node, '.headword-list');
const inflectionsContainer = this._querySelector(node, '.inflection-list');
const inflectionPossibilitiesContainer = this._querySelector(node, '.inflection-possibilities');
const groupedPronunciationsContainer = this._querySelector(node, '.pronunciation-group-list');
const frequencyGroupListContainer = this._querySelector(node, '.frequency-group-list');
const definitionsContainer = this._querySelector(node, '.definition-list');
const headwordTagsContainer = this._querySelector(node, '.headword-list-tag-list');

const {headwords, type, inflections, definitions, frequencies, pronunciations} = dictionaryEntry;
const {headwords, type, inflectionPossibilities, definitions, frequencies, pronunciations} = dictionaryEntry;
const groupedPronunciations = DictionaryDataUtil.getGroupedPronunciations(dictionaryEntry);
const pronunciationCount = groupedPronunciations.reduce((i, v) => i + v.pronunciations.length, 0);
const groupedFrequencies = DictionaryDataUtil.groupTermFrequencies(dictionaryEntry);
Expand Down Expand Up @@ -112,7 +112,7 @@ export class DisplayGenerator {
}
headwordsContainer.dataset.count = `${headwords.length}`;

this._appendMultiple(inflectionsContainer, this._createTermInflection.bind(this), inflections);
this._appendMultiple(inflectionPossibilitiesContainer, this._createInflectionPossibility.bind(this), inflectionPossibilities);
this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, false);
this._appendMultiple(groupedPronunciationsContainer, this._createGroupedPronunciation.bind(this), groupedPronunciations);
this._appendMultiple(headwordTagsContainer, this._createTermTag.bind(this), termTags, headwords.length);
Expand Down Expand Up @@ -356,6 +356,46 @@ export class DisplayGenerator {
return node;
}

/**
* @param {import('dictionary').InflectionPossibility} inflectionPossibility
* @returns {?HTMLElement}
*/
_createInflectionPossibility(inflectionPossibility) {
const {source, inflections} = inflectionPossibility;
if (!Array.isArray(inflections) || inflections.length === 0) { return null; }
const fragment = this._instantiate('inflection-possibility');

const sourceIcon = this._getInflectionSourceIcon(source);

fragment.appendChild(sourceIcon);

this._appendMultiple(fragment, this._createTermInflection.bind(this), inflections);
return fragment;
}

/**
* @param {import('dictionary').InflectionSource} source
* @returns {HTMLElement}
*/
_getInflectionSourceIcon(source) {
const icon = document.createElement('span');
icon.classList.add('inflection-source-icon');
StefanVukovic99 marked this conversation as resolved.
Show resolved Hide resolved
switch (source) {
case 'dictionary':
StefanVukovic99 marked this conversation as resolved.
Show resolved Hide resolved
icon.dataset.inflectionSource = 'dictionary';
icon.title = 'Dictionary Deinflection';
return icon;
case 'algorithm':
icon.dataset.inflectionSource = 'algorithm';
icon.title = 'Algorithm Deinflection';
return icon;
case 'both':
icon.dataset.inflectionSource = 'both';
icon.title = 'Dictionary and Algorithm Deinflection';
return icon;
}
}

/**
* @param {string} inflection
* @returns {DocumentFragment}
Expand Down Expand Up @@ -396,7 +436,7 @@ export class DisplayGenerator {
}

/**
* @param {import('dictionary-data').TermGlossary} entry
* @param {import('dictionary-data').TermGlossaryContent} entry
* @param {string} dictionary
* @returns {?HTMLElement}
*/
Expand Down
Loading