aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-12-17 16:11:19 -0500
committerGitHub <noreply@github.com>2021-12-17 16:11:19 -0500
commit19ab9df6e4110ef7d5927c95993141a1f8960c53 (patch)
tree31849bf1e1c9622cd1aa3aeb0709ad95ffc744b1 /ext/js
parent70fa701c906fa4319e0d62818fe5737e983b49ef (diff)
Replace 'wildcard' parameter with 'matchType' (#2038)
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/background/backend.js8
-rw-r--r--ext/js/display/display.js4
-rw-r--r--ext/js/language/dictionary-database.js12
-rw-r--r--ext/js/language/translator.js12
4 files changed, 19 insertions, 17 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index f8424e80..ce830361 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -1080,7 +1080,8 @@ class Backend {
const jp = this._japaneseUtil;
const mode = 'simple';
const options = this._getProfileOptions(optionsContext);
- const findTermsOptions = this._getTranslatorFindTermsOptions(mode, {wildcard: null}, options);
+ const details = {matchType: 'exact'};
+ const findTermsOptions = this._getTranslatorFindTermsOptions(mode, details, options);
const results = [];
let previousUngroupedSegment = null;
let i = 0;
@@ -1958,7 +1959,8 @@ class Backend {
}
_getTranslatorFindTermsOptions(mode, details, options) {
- const {wildcard} = details;
+ let {matchType} = details;
+ if (typeof matchType !== 'string') { matchType = 'exact'; }
const enabledDictionaryMap = this._getTranslatorEnabledDictionaryMap(options);
const {
general: {mainDictionary, sortFrequencyDictionary, sortFrequencyDictionaryOrder},
@@ -1985,7 +1987,7 @@ class Backend {
excludeDictionaryDefinitions.add(mainDictionary);
}
return {
- wildcard,
+ matchType,
mainDictionary,
sortFrequencyDictionary,
sortFrequencyDictionaryOrder,
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index 697e735f..50df3b9d 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -850,9 +850,9 @@ class Display extends EventDispatcher {
const match = /^([*\uff0a]*)([\w\W]*?)([*\uff0a]*)$/.exec(source);
if (match !== null) {
if (match[1]) {
- findDetails.wildcard = 'prefix';
+ findDetails.matchType = 'suffix';
} else if (match[3]) {
- findDetails.wildcard = 'suffix';
+ findDetails.matchType = 'prefix';
}
source = match[2];
}
diff --git a/ext/js/language/dictionary-database.js b/ext/js/language/dictionary-database.js
index 25adb571..c20921b5 100644
--- a/ext/js/language/dictionary-database.js
+++ b/ext/js/language/dictionary-database.js
@@ -196,7 +196,7 @@ class DictionaryDatabase {
}
}
- findTermsBulk(termList, dictionaries, wildcard) {
+ findTermsBulk(termList, dictionaries, matchType) {
const visited = new Set();
const predicate = (row) => {
if (!dictionaries.has(row.dictionary)) { return false; }
@@ -206,17 +206,17 @@ class DictionaryDatabase {
return true;
};
- const indexNames = (wildcard === 'prefix') ? ['expressionReverse', 'readingReverse'] : ['expression', 'reading'];
+ const indexNames = (matchType === 'suffix') ? ['expressionReverse', 'readingReverse'] : ['expression', 'reading'];
let createQuery;
- switch (wildcard) {
- case 'suffix':
+ switch (matchType) {
+ case 'prefix':
createQuery = this._createBoundQuery1;
break;
- case 'prefix':
+ case 'suffix':
createQuery = this._createBoundQuery2;
break;
- default:
+ default: // 'exact'
createQuery = this._createOnlyQuery1;
break;
}
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index 28e1cfcc..5db781dd 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -63,7 +63,7 @@ class Translator {
* @param options An object using the following structure:
* ```
* {
- * wildcard: (enum: null, 'prefix', 'suffix'),
+ * matchType: (enum: 'exact', 'prefix', 'suffix'),
* mainDictionary: (string),
* sortFrequencyDictionary: (null or string),
* sortFrequencyDictionaryOrder: (enum: 'ascending', 'descending'),
@@ -227,7 +227,6 @@ class Translator {
// Find terms internal implementation
async _findTermsInternal(text, enabledDictionaryMap, options) {
- const {wildcard} = options;
if (options.removeNonJapaneseCharacters) {
text = this._getJapaneseOnlyText(text);
}
@@ -235,9 +234,10 @@ class Translator {
return {dictionaryEntries: [], originalTextLength: 0};
}
+ const {matchType} = options;
const deinflections = await (
- wildcard ?
- this._findTermsWildcard(text, enabledDictionaryMap, wildcard) :
+ matchType && matchType !== 'exact' ?
+ this._findTermsWildcard(text, enabledDictionaryMap, matchType) :
this._findTermDeinflections(text, enabledDictionaryMap, options)
);
@@ -259,8 +259,8 @@ class Translator {
return {dictionaryEntries, originalTextLength};
}
- async _findTermsWildcard(text, enabledDictionaryMap, wildcard) {
- const databaseEntries = await this._database.findTermsBulk([text], enabledDictionaryMap, wildcard);
+ async _findTermsWildcard(text, enabledDictionaryMap, matchType) {
+ const databaseEntries = await this._database.findTermsBulk([text], enabledDictionaryMap, matchType);
return databaseEntries.length > 0 ? [this._createDeinflection(text, text, text, 0, [], databaseEntries)] : [];
}