matchType/deinflect distinction (#2040)
* Pass a "deinflect" option to findTerms * Update Translator to use deinflect option * Fix test input options
This commit is contained in:
parent
8e548a17eb
commit
8a377cabe6
@ -1080,7 +1080,7 @@ class Backend {
|
|||||||
const jp = this._japaneseUtil;
|
const jp = this._japaneseUtil;
|
||||||
const mode = 'simple';
|
const mode = 'simple';
|
||||||
const options = this._getProfileOptions(optionsContext);
|
const options = this._getProfileOptions(optionsContext);
|
||||||
const details = {matchType: 'exact'};
|
const details = {matchType: 'exact', deinflect: true};
|
||||||
const findTermsOptions = this._getTranslatorFindTermsOptions(mode, details, options);
|
const findTermsOptions = this._getTranslatorFindTermsOptions(mode, details, options);
|
||||||
const results = [];
|
const results = [];
|
||||||
let previousUngroupedSegment = null;
|
let previousUngroupedSegment = null;
|
||||||
@ -1959,8 +1959,9 @@ class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getTranslatorFindTermsOptions(mode, details, options) {
|
_getTranslatorFindTermsOptions(mode, details, options) {
|
||||||
let {matchType} = details;
|
let {matchType, deinflect} = details;
|
||||||
if (typeof matchType !== 'string') { matchType = 'exact'; }
|
if (typeof matchType !== 'string') { matchType = 'exact'; }
|
||||||
|
if (typeof deinflect !== 'boolean') { deinflect = true; }
|
||||||
const enabledDictionaryMap = this._getTranslatorEnabledDictionaryMap(options);
|
const enabledDictionaryMap = this._getTranslatorEnabledDictionaryMap(options);
|
||||||
const {
|
const {
|
||||||
general: {mainDictionary, sortFrequencyDictionary, sortFrequencyDictionaryOrder},
|
general: {mainDictionary, sortFrequencyDictionary, sortFrequencyDictionaryOrder},
|
||||||
@ -1988,6 +1989,7 @@ class Backend {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
matchType,
|
matchType,
|
||||||
|
deinflect,
|
||||||
mainDictionary,
|
mainDictionary,
|
||||||
sortFrequencyDictionary,
|
sortFrequencyDictionary,
|
||||||
sortFrequencyDictionaryOrder,
|
sortFrequencyDictionaryOrder,
|
||||||
|
@ -851,8 +851,10 @@ class Display extends EventDispatcher {
|
|||||||
if (match !== null) {
|
if (match !== null) {
|
||||||
if (match[1]) {
|
if (match[1]) {
|
||||||
findDetails.matchType = 'suffix';
|
findDetails.matchType = 'suffix';
|
||||||
|
findDetails.deinflect = false;
|
||||||
} else if (match[3]) {
|
} else if (match[3]) {
|
||||||
findDetails.matchType = 'prefix';
|
findDetails.matchType = 'prefix';
|
||||||
|
findDetails.deinflect = false;
|
||||||
}
|
}
|
||||||
source = match[2];
|
source = match[2];
|
||||||
}
|
}
|
||||||
|
@ -234,12 +234,7 @@ class Translator {
|
|||||||
return {dictionaryEntries: [], originalTextLength: 0};
|
return {dictionaryEntries: [], originalTextLength: 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
const {matchType} = options;
|
const deinflections = await this._findTermsInternal2(text, enabledDictionaryMap, options);
|
||||||
const deinflections = await (
|
|
||||||
matchType && matchType !== 'exact' ?
|
|
||||||
this._findTermsWildcard(text, enabledDictionaryMap, matchType) :
|
|
||||||
this._findTermDeinflections(text, enabledDictionaryMap, options)
|
|
||||||
);
|
|
||||||
|
|
||||||
let originalTextLength = 0;
|
let originalTextLength = 0;
|
||||||
const dictionaryEntries = [];
|
const dictionaryEntries = [];
|
||||||
@ -259,17 +254,13 @@ class Translator {
|
|||||||
return {dictionaryEntries, originalTextLength};
|
return {dictionaryEntries, originalTextLength};
|
||||||
}
|
}
|
||||||
|
|
||||||
async _findTermsWildcard(text, enabledDictionaryMap, matchType) {
|
async _findTermsInternal2(text, enabledDictionaryMap, options) {
|
||||||
const databaseEntries = await this._database.findTermsBulk([text], enabledDictionaryMap, matchType);
|
const deinflections = (
|
||||||
return databaseEntries.length > 0 ? [this._createDeinflection(text, text, text, 0, [], databaseEntries)] : [];
|
options.deinflect ?
|
||||||
}
|
this._getAllDeinflections(text, options) :
|
||||||
|
[this._createDeinflection(text, text, text, 0, [], [])]
|
||||||
async _findTermDeinflections(text, enabledDictionaryMap, options) {
|
);
|
||||||
const deinflections = this._getAllDeinflections(text, options);
|
if (deinflections.length === 0) { return []; }
|
||||||
|
|
||||||
if (deinflections.length === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const uniqueDeinflectionTerms = [];
|
const uniqueDeinflectionTerms = [];
|
||||||
const uniqueDeinflectionArrays = [];
|
const uniqueDeinflectionArrays = [];
|
||||||
@ -286,7 +277,8 @@ class Translator {
|
|||||||
deinflectionArray.push(deinflection);
|
deinflectionArray.push(deinflection);
|
||||||
}
|
}
|
||||||
|
|
||||||
const databaseEntries = await this._database.findTermsBulk(uniqueDeinflectionTerms, enabledDictionaryMap, null);
|
const {matchType} = options;
|
||||||
|
const databaseEntries = await this._database.findTermsBulk(uniqueDeinflectionTerms, enabledDictionaryMap, matchType);
|
||||||
|
|
||||||
for (const databaseEntry of databaseEntries) {
|
for (const databaseEntry of databaseEntries) {
|
||||||
const definitionRules = Deinflector.rulesToRuleFlags(databaseEntry.rules);
|
const definitionRules = Deinflector.rulesToRuleFlags(databaseEntry.rules);
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"default": {
|
"default": {
|
||||||
"wildcard": null,
|
"matchType": "exact",
|
||||||
|
"deinflect": true,
|
||||||
"mainDictionary": "${title}",
|
"mainDictionary": "${title}",
|
||||||
"sortFrequencyDictionary": null,
|
"sortFrequencyDictionary": null,
|
||||||
"sortFrequencyDictionaryOrder": "descending",
|
"sortFrequencyDictionaryOrder": "descending",
|
||||||
|
Loading…
Reference in New Issue
Block a user