Skip to content

Commit

Permalink
remove from deinflector
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 committed Dec 29, 2023
1 parent 315f0f9 commit 79b02b1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
18 changes: 2 additions & 16 deletions ext/js/language/deinflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,20 @@ export class Deinflector {
/**
* Deinflects a Japanese term to all of its possible dictionary forms.
* @param {string} source The source term to deinflect.
* @param {import('translation-internal').DeinflectionOptions} options
* @returns {import('translation-internal').Deinflection[]}
* @example
* const deinflector = new Deinflector(deinflectionReasons);
* // [{ term: '食べた', rules: 0, reasons: [] }, { term: '食べる', rules: 1, reasons: ['past'] }, { term: '食ぶ', rules: 2, reasons: ['potential', 'past'] }]
* console.log(deinflector.deinflect('食べた'));
*/
deinflect(source, options) {
const {partsOfSpeechFilter} = options;
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) {
for (const [kanaIn, kanaOut, rulesIn, rulesOut] of variants) {
if (
!Deinflector.rulesCheck(partsOfSpeechFilter, rules, rulesIn) ||
(rules !== 0 && (rules & rulesIn) === 0) ||
!term.endsWith(kanaIn) ||
(term.length - kanaIn.length + kanaOut.length) <= 0
) {
Expand All @@ -79,18 +77,6 @@ export class Deinflector {
return results;
}

/**
*
* @param {boolean} checkRules
* @param {import('translation-internal').DeinflectionRuleFlags} rules1
* @param {import('translation-internal').DeinflectionRuleFlags} rules2
* @returns {boolean}
*/
static rulesCheck(checkRules, rules1, rules2){
if (!checkRules) { return true; }
return rules1 === 0 || (rules1 & rules2) !== 0;
}

/**
* @param {string} term
* @param {import('translation-internal').DeinflectionRuleFlags} rules
Expand Down
4 changes: 2 additions & 2 deletions ext/js/language/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class Translator {
const definitionRules = Deinflector.rulesToRuleFlags(databaseEntry.rules);
for (const deinflection of uniqueDeinflectionArrays[databaseEntry.index]) {
const deinflectionRules = deinflection.rules;
if (Deinflector.rulesCheck(partsOfSpeechFilter, deinflectionRules, definitionRules)) {
if (!partsOfSpeechFilter || deinflectionRules === 0 || (definitionRules & deinflectionRules) !== 0) {
deinflection.databaseEntries.push(databaseEntry);
}
}
Expand Down Expand Up @@ -339,7 +339,7 @@ export class Translator {
if (used.has(source)) { break; }
used.add(source);
const rawSource = sourceMap.source.substring(0, sourceMap.getSourceLength(i));
for (const {term, rules, reasons} of /** @type {Deinflector} */ (this._deinflector).deinflect(source, options)) {
for (const {term, rules, reasons} of /** @type {Deinflector} */ (this._deinflector).deinflect(source)) {
deinflections.push(this._createDeinflection(rawSource, source, term, rules, reasons));
}
}
Expand Down
7 changes: 0 additions & 7 deletions types/ext/translation-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,3 @@ export type DatabaseDeinflection = {
reasons: string[];
databaseEntries: DictionaryDatabase.TermEntry[];
};

export type DeinflectionOptions = {
/**
* Whether algorithm deinflections should be filtered using parts of speech.
*/
partsOfSpeechFilter: boolean;
};

0 comments on commit 79b02b1

Please sign in to comment.