Fixing deinflection
This commit is contained in:
parent
238c9e340e
commit
0aa603694c
@ -25,13 +25,14 @@ class Deinflection {
|
|||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
validate(validator) {
|
deinflect(validator, reasons, entry=false) {
|
||||||
return validator(this.term).then(sets => {
|
const validate = () => {
|
||||||
for (const rules of sets) {
|
if (entry) {
|
||||||
if (this.rules.length === 0) {
|
return Promise.resolve(true);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return validator(this.term).then(sets => {
|
||||||
|
for (const rules of sets) {
|
||||||
for (const rule of this.rules) {
|
for (const rule of this.rules) {
|
||||||
if (rules.includes(rule)) {
|
if (rules.includes(rule)) {
|
||||||
return true;
|
return true;
|
||||||
@ -41,11 +42,10 @@ class Deinflection {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
deinflect(validator, reasons) {
|
|
||||||
const promises = [
|
const promises = [
|
||||||
this.validate(validator).then(valid => {
|
validate().then(valid => {
|
||||||
const child = new Deinflection(this.term, this.rules);
|
const child = new Deinflection(this.term, this.rules);
|
||||||
this.children.push(child);
|
this.children.push(child);
|
||||||
})
|
})
|
||||||
@ -53,13 +53,15 @@ class Deinflection {
|
|||||||
|
|
||||||
for (const reason in reasons) {
|
for (const reason in reasons) {
|
||||||
for (const variant of reasons[reason]) {
|
for (const variant of reasons[reason]) {
|
||||||
let allowed = this.rules.length === 0;
|
let allowed = entry;
|
||||||
|
if (!allowed) {
|
||||||
for (const rule of this.rules) {
|
for (const rule of this.rules) {
|
||||||
if (variant.rulesIn.includes(rule)) {
|
if (variant.rulesIn.includes(rule)) {
|
||||||
allowed = true;
|
allowed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!allowed || !this.term.endsWith(variant.kanaIn)) {
|
if (!allowed || !this.term.endsWith(variant.kanaIn)) {
|
||||||
continue;
|
continue;
|
||||||
@ -119,6 +121,6 @@ class Deinflector {
|
|||||||
|
|
||||||
deinflect(term, validator) {
|
deinflect(term, validator) {
|
||||||
const node = new Deinflection(term);
|
const node = new Deinflection(term);
|
||||||
return node.deinflect(validator, this.reasons).then(success => success ? node.gather() : []);
|
return node.deinflect(validator, this.reasons, true).then(success => success ? node.gather() : []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user