1

More deinflector cleanup

Former-commit-id: 19c54590928ce4c37fd2f66b45a023decfe2e71c
This commit is contained in:
Alex Yatskov 2013-11-09 12:23:26 -08:00
parent c854826ed4
commit 33cd58c0c6

View File

@ -35,7 +35,7 @@ class Deinflection:
self.success = False self.success = False
def validateTerm(self, validator): def validate(self, validator):
for tags in validator(self.term): for tags in validator(self.term):
if len(self.tags) == 0: if len(self.tags) == 0:
return True return True
@ -45,8 +45,8 @@ class Deinflection:
return True return True
def deinflect(self, validator, rules, candidates): def deinflect(self, validator, rules):
if self.validateTerm(validator): if self.validate(validator):
child = Deinflection(self.term) child = Deinflection(self.term)
self.children.append(child) self.children.append(child)
@ -67,10 +67,9 @@ class Deinflection:
continue continue
term = self.term[:-len(kanaIn)] + kanaOut term = self.term[:-len(kanaIn)] + kanaOut
candidates.update([term])
child = Deinflection(term, tagsOut, rule) child = Deinflection(term, tagsOut, rule)
if child.deinflect(validator, rules, candidates): if child.deinflect(validator, rules):
self.children.append(child) self.children.append(child)
if len(self.children) > 0: if len(self.children) > 0:
@ -85,21 +84,14 @@ class Deinflection:
def gather(self): def gather(self):
if len(self.children) == 0: if len(self.children) == 0:
endpoint = { return [{'root': self.term, 'rules': list()}]
'root': self.term,
'source': self.term,
'rules': [self.rule] if self.rule else list()
}
return [endpoint]
paths = list() paths = list()
for child in self.children: for child in self.children:
for path in child.gather(): for path in child.gather():
if self.rule: if self.rule:
path['rules'].append(self.rule) path['rules'].append(self.rule)
else: path['source'] = self.term
path['source'] = self.term
paths.append(path) paths.append(path)
return paths return paths
@ -116,7 +108,6 @@ class Deinflector:
def deinflect(self, term, validator): def deinflect(self, term, validator):
candidates = set()
node = Deinflection(term) node = Deinflection(term)
if node.deinflect(validator, self.rules, candidates): if node.deinflect(validator, self.rules):
return node.gather(), candidates return node.gather()