diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-12-19 20:03:06 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-12-19 20:03:06 -0800 |
commit | 0aa603694c6ab912b4e74c9e87b73295ae393ee2 (patch) | |
tree | 0292f7cc57ab39979efb88e5cc014793fff8e44f /ext/bg/js | |
parent | 238c9e340e5f42f12e6f7f16b1da7b87652aa821 (diff) |
Fixing deinflection
Diffstat (limited to 'ext/bg/js')
-rw-r--r-- | ext/bg/js/deinflector.js | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/ext/bg/js/deinflector.js b/ext/bg/js/deinflector.js index b8646e73..5cfb7f75 100644 --- a/ext/bg/js/deinflector.js +++ b/ext/bg/js/deinflector.js @@ -25,27 +25,27 @@ class Deinflection { this.reason = reason; } - validate(validator) { - return validator(this.term).then(sets => { - for (const rules of sets) { - if (this.rules.length === 0) { - return true; - } + deinflect(validator, reasons, entry=false) { + const validate = () => { + if (entry) { + return Promise.resolve(true); + } - for (const rule of this.rules) { - if (rules.includes(rule)) { - return true; + return validator(this.term).then(sets => { + for (const rules of sets) { + for (const rule of this.rules) { + if (rules.includes(rule)) { + return true; + } } } - } - return false; - }); - } + return false; + }); + }; - deinflect(validator, reasons) { const promises = [ - this.validate(validator).then(valid => { + validate().then(valid => { const child = new Deinflection(this.term, this.rules); this.children.push(child); }) @@ -53,11 +53,13 @@ class Deinflection { for (const reason in reasons) { for (const variant of reasons[reason]) { - let allowed = this.rules.length === 0; - for (const rule of this.rules) { - if (variant.rulesIn.includes(rule)) { - allowed = true; - break; + let allowed = entry; + if (!allowed) { + for (const rule of this.rules) { + if (variant.rulesIn.includes(rule)) { + allowed = true; + break; + } } } @@ -119,6 +121,6 @@ class Deinflector { deinflect(term, validator) { 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() : []); } } |