1

Adding parent deinflection type

Former-commit-id: f737c0b56a7403bf5693ab98ad7df7ba69f2ed48
This commit is contained in:
Alex Yatskov 2013-11-08 15:49:16 -08:00
parent 5cbe1a260e
commit 9bc04c8fcb

View File

@ -26,9 +26,10 @@ import json
# #
class Deinflection: class Deinflection:
def __init__(self, term, tags=list(), rule=str()): def __init__(self, term, parent=None, tags=list(), rule=str()):
self.children = list() self.children = list()
self.term = term self.term = term
self.parent = parent
self.tags = tags self.tags = tags
self.rule = rule self.rule = rule
@ -41,18 +42,22 @@ class Deinflection:
kanaIn = variant['kanaIn'] kanaIn = variant['kanaIn']
kanaOut = variant['kanaOut'] kanaOut = variant['kanaOut']
for i in xrange(len(kanaIn), len(self.term) + 1):
term = self.term[:i]
allowed = not self.tags allowed = not self.tags
for tag in self.tags: for tag in self.tags:
if tag in tagsIn: if tag in tagsIn:
allowed = True allowed = True
if allowed and term.endswith(kanaIn): if not allowed:
continue
for i in xrange(len(kanaIn), len(self.term) + 1):
term = self.term[:i]
if not term.endswith(kanaIn):
continue
rebase = term[:-len(kanaIn)] + kanaOut rebase = term[:-len(kanaIn)] + kanaOut
if validator(rebase, self.tags): if validator(rebase, self.tags):
child = Deinflection(rebase, tagsOut, rule) child = Deinflection(rebase, term, tagsOut, rule)
self.children.append(child) self.children.append(child)
child.deinflect(validator, rules) child.deinflect(validator, rules)
@ -60,7 +65,7 @@ class Deinflection:
def dump(self, depth=0): def dump(self, depth=0):
result = u'%s%s' % (u'\t' * depth, self.term) result = u'%s%s' % (u'\t' * depth, self.term)
if self.rule: if self.rule:
result += u' (%s)' % self.rule result += u' (%s %s)' % (self.parent, self.rule)
result += u'\n' result += u'\n'
for child in self.children: for child in self.children: