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:
|
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,26 +42,30 @@ class Deinflection:
|
|||||||
kanaIn = variant['kanaIn']
|
kanaIn = variant['kanaIn']
|
||||||
kanaOut = variant['kanaOut']
|
kanaOut = variant['kanaOut']
|
||||||
|
|
||||||
|
allowed = not self.tags
|
||||||
|
for tag in self.tags:
|
||||||
|
if tag in tagsIn:
|
||||||
|
allowed = True
|
||||||
|
|
||||||
|
if not allowed:
|
||||||
|
continue
|
||||||
|
|
||||||
for i in xrange(len(kanaIn), len(self.term) + 1):
|
for i in xrange(len(kanaIn), len(self.term) + 1):
|
||||||
term = self.term[:i]
|
term = self.term[:i]
|
||||||
|
if not term.endswith(kanaIn):
|
||||||
|
continue
|
||||||
|
|
||||||
allowed = not self.tags
|
rebase = term[:-len(kanaIn)] + kanaOut
|
||||||
for tag in self.tags:
|
if validator(rebase, self.tags):
|
||||||
if tag in tagsIn:
|
child = Deinflection(rebase, term, tagsOut, rule)
|
||||||
allowed = True
|
self.children.append(child)
|
||||||
|
child.deinflect(validator, rules)
|
||||||
if allowed and term.endswith(kanaIn):
|
|
||||||
rebase = term[:-len(kanaIn)] + kanaOut
|
|
||||||
if validator(rebase, self.tags):
|
|
||||||
child = Deinflection(rebase, tagsOut, rule)
|
|
||||||
self.children.append(child)
|
|
||||||
child.deinflect(validator, rules)
|
|
||||||
|
|
||||||
|
|
||||||
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:
|
||||||
|
Loading…
Reference in New Issue
Block a user