summaryrefslogtreecommitdiff
path: root/ext/js/language/deinflector.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-07 14:07:26 -0500
committerGitHub <noreply@github.com>2021-03-07 14:07:26 -0500
commit7793e14e57639426cb9ca64c82004151f9eaba05 (patch)
tree14aa497ee70bd18890e6e0af400b58cbe68add91 /ext/js/language/deinflector.js
parent92fe1571aeee0717b85c6b47ed203852faf42d80 (diff)
Deinflector refactor (#1501)
* Make Deinflector._ruleTypes private * Add createDeinflection helper * Remove unnecessary field assignments from Deinflector Move them to Translator instead
Diffstat (limited to 'ext/js/language/deinflector.js')
-rw-r--r--ext/js/language/deinflector.js37
1 files changed, 16 insertions, 21 deletions
diff --git a/ext/js/language/deinflector.js b/ext/js/language/deinflector.js
index b6759215..4b2c1bc7 100644
--- a/ext/js/language/deinflector.js
+++ b/ext/js/language/deinflector.js
@@ -20,15 +20,8 @@ class Deinflector {
this.reasons = Deinflector.normalizeReasons(reasons);
}
- deinflect(source, rawSource) {
- const results = [{
- source,
- rawSource,
- term: source,
- rules: 0,
- reasons: [],
- databaseDefinitions: []
- }];
+ deinflect(source) {
+ const results = [this._createDeinflection(source, 0, [])];
for (let i = 0; i < results.length; ++i) {
const {rules, term, reasons} = results[i];
for (const [reason, variants] of this.reasons) {
@@ -41,20 +34,21 @@ class Deinflector {
continue;
}
- results.push({
- source,
- rawSource,
- term: term.substring(0, term.length - kanaIn.length) + kanaOut,
- rules: rulesOut,
- reasons: [reason, ...reasons],
- databaseDefinitions: []
- });
+ results.push(this._createDeinflection(
+ term.substring(0, term.length - kanaIn.length) + kanaOut,
+ rulesOut,
+ [reason, ...reasons]
+ ));
}
}
}
return results;
}
+ _createDeinflection(term, rules, reasons) {
+ return {term, rules, reasons};
+ }
+
static normalizeReasons(reasons) {
const normalizedReasons = [];
for (const [reason, reasonInfo] of Object.entries(reasons)) {
@@ -63,8 +57,8 @@ class Deinflector {
variants.push([
kanaIn,
kanaOut,
- Deinflector.rulesToRuleFlags(rulesIn),
- Deinflector.rulesToRuleFlags(rulesOut)
+ this.rulesToRuleFlags(rulesIn),
+ this.rulesToRuleFlags(rulesOut)
]);
}
normalizedReasons.push([reason, variants]);
@@ -73,7 +67,7 @@ class Deinflector {
}
static rulesToRuleFlags(rules) {
- const ruleTypes = Deinflector.ruleTypes;
+ const ruleTypes = this._ruleTypes;
let value = 0;
for (const rule of rules) {
const ruleBits = ruleTypes.get(rule);
@@ -84,7 +78,8 @@ class Deinflector {
}
}
-Deinflector.ruleTypes = new Map([
+// eslint-disable-next-line no-underscore-dangle
+Deinflector._ruleTypes = new Map([
['v1', 0b00000001], // Verb ichidan
['v5', 0b00000010], // Verb godan
['vs', 0b00000100], // Verb suru