Adding parent deinflection type
Former-commit-id: f737c0b56a7403bf5693ab98ad7df7ba69f2ed48
This commit is contained in:
parent
5cbe1a260e
commit
9bc04c8fcb
@ -26,9 +26,10 @@ import json
|
||||
#
|
||||
|
||||
class Deinflection:
|
||||
def __init__(self, term, tags=list(), rule=str()):
|
||||
def __init__(self, term, parent=None, tags=list(), rule=str()):
|
||||
self.children = list()
|
||||
self.term = term
|
||||
self.parent = parent
|
||||
self.tags = tags
|
||||
self.rule = rule
|
||||
|
||||
@ -41,18 +42,22 @@ class Deinflection:
|
||||
kanaIn = variant['kanaIn']
|
||||
kanaOut = variant['kanaOut']
|
||||
|
||||
for i in xrange(len(kanaIn), len(self.term) + 1):
|
||||
term = self.term[:i]
|
||||
|
||||
allowed = not self.tags
|
||||
for tag in self.tags:
|
||||
if tag in tagsIn:
|
||||
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
|
||||
if validator(rebase, self.tags):
|
||||
child = Deinflection(rebase, tagsOut, rule)
|
||||
child = Deinflection(rebase, term, tagsOut, rule)
|
||||
self.children.append(child)
|
||||
child.deinflect(validator, rules)
|
||||
|
||||
@ -60,7 +65,7 @@ class Deinflection:
|
||||
def dump(self, depth=0):
|
||||
result = u'%s%s' % (u'\t' * depth, self.term)
|
||||
if self.rule:
|
||||
result += u' (%s)' % self.rule
|
||||
result += u' (%s %s)' % (self.parent, self.rule)
|
||||
result += u'\n'
|
||||
|
||||
for child in self.children:
|
||||
|
Loading…
Reference in New Issue
Block a user