aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/data/schemas/options-schema.json7
-rw-r--r--ext/js/background/backend.js11
-rw-r--r--ext/js/data/options-util.js15
-rw-r--r--ext/js/language/translator.js5
-rw-r--r--ext/js/pages/settings/dictionary-controller.js12
-rw-r--r--ext/settings.html18
-rw-r--r--ext/welcome.html18
-rw-r--r--test/data/translator-test-inputs.json3
-rw-r--r--test/options-util.test.js5
-rw-r--r--types/ext/settings.d.ts1
-rw-r--r--types/ext/translation.d.ts4
11 files changed, 86 insertions, 13 deletions
diff --git a/ext/data/schemas/options-schema.json b/ext/data/schemas/options-schema.json
index 65c4102e..8cf00400 100644
--- a/ext/data/schemas/options-schema.json
+++ b/ext/data/schemas/options-schema.json
@@ -822,7 +822,8 @@
"priority",
"enabled",
"allowSecondarySearches",
- "definitionsCollapsible"
+ "definitionsCollapsible",
+ "partsOfSpeechFilter"
],
"properties": {
"name": {
@@ -845,6 +846,10 @@
"type": "string",
"enum": ["not-collapsible", "expanded", "collapsed", "force-collapsed", "force-expanded"],
"default": "not-collapsible"
+ },
+ "partsOfSpeechFilter": {
+ "type": "boolean",
+ "default": true
}
}
}
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 3f3c6063..a5a42272 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -2427,7 +2427,8 @@ export class Backend {
enabledDictionaryMap.set(mainDictionary, {
index: enabledDictionaryMap.size,
priority: 0,
- allowSecondarySearches: false
+ allowSecondarySearches: false,
+ partsOfSpeechFilter: true
});
excludeDictionaryDefinitions = new Set();
excludeDictionaryDefinitions.add(mainDictionary);
@@ -2473,10 +2474,12 @@ export class Backend {
const enabledDictionaryMap = new Map();
for (const dictionary of options.dictionaries) {
if (!dictionary.enabled) { continue; }
- enabledDictionaryMap.set(dictionary.name, {
+ const {name, priority, allowSecondarySearches, partsOfSpeechFilter} = dictionary;
+ enabledDictionaryMap.set(name, {
index: enabledDictionaryMap.size,
- priority: dictionary.priority,
- allowSecondarySearches: dictionary.allowSecondarySearches
+ priority,
+ allowSecondarySearches,
+ partsOfSpeechFilter
});
}
return enabledDictionaryMap;
diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js
index c6acf373..c93e261d 100644
--- a/ext/js/data/options-util.js
+++ b/ext/js/data/options-util.js
@@ -555,7 +555,8 @@ export class OptionsUtil {
this._updateVersion19,
this._updateVersion20,
this._updateVersion21,
- this._updateVersion22
+ this._updateVersion22,
+ this._updateVersion23
];
if (typeof targetVersion === 'number' && targetVersion < result.length) {
result.splice(targetVersion);
@@ -1140,8 +1141,18 @@ export class OptionsUtil {
for (const {options: profileOptions} of options.profiles) {
profileOptions.translation.searchResolution = 'letter';
}
+ }
- return options;
+ /**
+ * - Added dictionaries[].partsOfSpeechFilter.
+ * @type {import('options-util').UpdateFunction}
+ */
+ _updateVersion23(options) {
+ for (const {options: profileOptions} of options.profiles) {
+ for (const dictionary of profileOptions.dictionaries) {
+ dictionary.partsOfSpeechFilter = true;
+ }
+ }
}
/**
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index 36ed8b43..5441294b 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -269,10 +269,13 @@ export class Translator {
const databaseEntries = await this._database.findTermsBulk(uniqueDeinflectionTerms, enabledDictionaryMap, matchType);
for (const databaseEntry of databaseEntries) {
+ const entryDictionary = /** @type {import('translation').FindTermDictionary} */ (enabledDictionaryMap.get(databaseEntry.dictionary));
+ const partsOfSpeechFilter = entryDictionary.partsOfSpeechFilter;
+
const definitionRules = Deinflector.rulesToRuleFlags(databaseEntry.rules);
for (const deinflection of uniqueDeinflectionArrays[databaseEntry.index]) {
const deinflectionRules = deinflection.rules;
- if (deinflectionRules === 0 || (definitionRules & deinflectionRules) !== 0) {
+ if (!partsOfSpeechFilter || deinflectionRules === 0 || (definitionRules & deinflectionRules) !== 0) {
deinflection.databaseEntries.push(databaseEntry);
}
}
diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js
index 81b781da..18a802be 100644
--- a/ext/js/pages/settings/dictionary-controller.js
+++ b/ext/js/pages/settings/dictionary-controller.js
@@ -164,7 +164,7 @@ class DictionaryEntry {
/** */
_showDetails() {
- const {title, revision, version, prefixWildcardsSupported} = this._dictionaryInfo;
+ const {title, revision, version, counts, prefixWildcardsSupported} = this._dictionaryInfo;
const modal = this._dictionaryController.modalController.getModal('dictionary-details');
if (modal === null) { return; }
@@ -181,12 +181,19 @@ class DictionaryEntry {
const wildcardSupportedElement = querySelectorNotNull(modal.node, '.dictionary-prefix-wildcard-searches-supported');
/** @type {HTMLElement} */
const detailsTableElement = querySelectorNotNull(modal.node, '.dictionary-details-table');
+ /** @type {HTMLElement} */
+ const partsOfSpeechFilterSetting = querySelectorNotNull(modal.node, '.dictionary-parts-of-speech-filter-setting');
+ /** @type {HTMLElement} */
+ const partsOfSpeechFilterToggle = querySelectorNotNull(partsOfSpeechFilterSetting, '.dictionary-parts-of-speech-filter-toggle');
titleElement.textContent = title;
versionElement.textContent = `rev.${revision}`;
outdateElement.hidden = (version >= 3);
countsElement.textContent = this._counts !== null ? JSON.stringify(this._counts, null, 4) : '';
wildcardSupportedElement.checked = prefixWildcardsSupported;
+ partsOfSpeechFilterSetting.hidden = !counts.terms.total;
+ partsOfSpeechFilterToggle.dataset.setting = `dictionaries[${this._index}].partsOfSpeechFilter`;
+
this._setupDetails(detailsTableElement);
modal.setVisible(true);
@@ -513,7 +520,8 @@ export class DictionaryController {
priority: 0,
enabled,
allowSecondarySearches: false,
- definitionsCollapsible: 'not-collapsible'
+ definitionsCollapsible: 'not-collapsible',
+ partsOfSpeechFilter: true
};
}
diff --git a/ext/settings.html b/ext/settings.html
index 8f432eb4..2cc521d5 100644
--- a/ext/settings.html
+++ b/ext/settings.html
@@ -2673,6 +2673,24 @@
<p><a tabindex="0" class="more-toggle" data-parent-distance="3">Hide&hellip;</a></p>
</div>
</div>
+ <div class="settings-item dictionary-parts-of-speech-filter-setting" hidden>
+ <div class="settings-item-inner">
+ <div class="settings-item-left">
+ <div class="settings-item-label">
+ Part of speech filtering
+ <a tabindex="0" class="more-toggle more-only" data-parent-distance="4">(?)</a>
+ </div>
+ </div>
+ <div class="settings-item-right">
+ <label class="toggle"><input type="checkbox" class="dictionary-parts-of-speech-filter-toggle"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label>
+ </div>
+ </div>
+ <div class="settings-item-children more" hidden>
+ When deinflecting words, only dictionary entries whose POS matches that expected by the deinflector will be shown.
+ <p><a tabindex="0" class="more-toggle" data-parent-distance="3">Hide&hellip;</a></p>
+ </div>
+ </div>
+ <hr>
<div class="settings-item"><div class="settings-item-children">
<div class="dictionary-details-table"></div>
<div class="dictionary-counts"></div>
diff --git a/ext/welcome.html b/ext/welcome.html
index 40639881..80bd6ab4 100644
--- a/ext/welcome.html
+++ b/ext/welcome.html
@@ -366,6 +366,24 @@
<p><a tabindex="0" class="more-toggle" data-parent-distance="3">Hide&hellip;</a></p>
</div>
</div>
+ <div class="settings-item dictionary-parts-of-speech-filter-setting" hidden>
+ <div class="settings-item-inner">
+ <div class="settings-item-left">
+ <div class="settings-item-label">
+ Part of speech filtering
+ <a tabindex="0" class="more-toggle more-only" data-parent-distance="4">(?)</a>
+ </div>
+ </div>
+ <div class="settings-item-right">
+ <label class="toggle"><input type="checkbox" class="dictionary-parts-of-speech-filter-toggle"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label>
+ </div>
+ </div>
+ <div class="settings-item-children more" hidden>
+ When deinflecting words, only dictionary entries whose POS matches that expected by the deinflector will be shown.
+ <p><a tabindex="0" class="more-toggle" data-parent-distance="3">Hide&hellip;</a></p>
+ </div>
+ </div>
+ <hr>
<div class="settings-item"><div class="settings-item-children">
<div class="dictionary-details-table"></div>
<div class="dictionary-counts"></div>
diff --git a/test/data/translator-test-inputs.json b/test/data/translator-test-inputs.json
index ec7f1a11..91cf0ab2 100644
--- a/test/data/translator-test-inputs.json
+++ b/test/data/translator-test-inputs.json
@@ -34,7 +34,8 @@
{
"index": 0,
"priority": 0,
- "allowSecondarySearches": false
+ "allowSecondarySearches": false,
+ "partsOfSpeechFilter": true
}
]
]
diff --git a/test/options-util.test.js b/test/options-util.test.js
index daffe886..41743b9f 100644
--- a/test/options-util.test.js
+++ b/test/options-util.test.js
@@ -425,7 +425,8 @@ function createProfileOptionsUpdatedTestData1() {
priority: 0,
enabled: true,
allowSecondarySearches: false,
- definitionsCollapsible: 'not-collapsible'
+ definitionsCollapsible: 'not-collapsible',
+ partsOfSpeechFilter: true
}
],
parsing: {
@@ -602,7 +603,7 @@ function createOptionsUpdatedTestData1() {
}
],
profileCurrent: 0,
- version: 22,
+ version: 23,
global: {
database: {
prefixWildcardsSupported: false
diff --git a/types/ext/settings.d.ts b/types/ext/settings.d.ts
index 25ea46d9..b95691b2 100644
--- a/types/ext/settings.d.ts
+++ b/types/ext/settings.d.ts
@@ -258,6 +258,7 @@ export type DictionaryOptions = {
enabled: boolean;
allowSecondarySearches: boolean;
definitionsCollapsible: DictionaryDefinitionsCollapsible;
+ partsOfSpeechFilter: boolean;
};
export type ParsingOptions = {
diff --git a/types/ext/translation.d.ts b/types/ext/translation.d.ts
index c8938e00..d597c006 100644
--- a/types/ext/translation.d.ts
+++ b/types/ext/translation.d.ts
@@ -173,6 +173,10 @@ export type FindTermDictionary = {
* Whether or not secondary term searches are allowed for this dictionary.
*/
allowSecondarySearches: boolean;
+ /**
+ * Whether this dictionary's part of speech rules should be used to filter results.
+ */
+ partsOfSpeechFilter: boolean;
};
export type TermEnabledDictionaryMap = Map<string, FindTermDictionary>;