Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def rec(node):
attrib = node.attrib
if 'terminal' not in attrib:
cat = Category.parse(attrib['category'])
children = [rec(spans[child]) for child in attrib['child'].split(' ')]
if len(children) == 1:
return Tree.make_unary(cat, children[0], lang)
else:
assert len(children) == 2
left, right = children
combinator = guess_combinator_by_triplet(
binary_rules, cat, left.cat, right.cat)
combinator = combinator or UNKNOWN_COMBINATOR
return Tree.make_binary(cat, left, right, combinator, lang)
else:
cat = Category.parse(attrib['category'])
word = try_get_surface(tokens[attrib['terminal']])
return Tree.make_terminal(word, cat, lang)
def rec(node):
attrib = node.attrib
if 'terminal' not in attrib:
cat = Category.parse(attrib['category'])
children = [rec(spans[child]) for child in attrib['child'].split(' ')]
if len(children) == 1:
return Tree.make_unary(cat, children[0], lang)
else:
assert len(children) == 2
left, right = children
combinator = guess_combinator_by_triplet(
binary_rules, cat, left.cat, right.cat)
combinator = combinator or UNKNOWN_COMBINATOR
return Tree.make_binary(cat, left, right, combinator, lang)
else:
cat = Category.parse(attrib['category'])
word = try_get_surface(tokens[attrib['terminal']])
return Tree.make_terminal(word, cat, lang)
def rec(node):
attrib = node.attrib
if node.tag == 'rule':
cat = Category.parse(attrib['cat'])
children = [rec(child) for child in node.getchildren()]
if len(children) == 1:
return Tree.make_unary(cat, children[0], lang)
else:
assert len(children) == 2
left, right = children
combinator = guess_combinator_by_triplet(
binary_rules, cat, left.cat, right.cat)
combinator = combinator or UNKNOWN_COMBINATOR
return Tree.make_binary(cat, left, right, combinator, lang)
else:
assert node.tag == 'lf'
cat = Category.parse(attrib['cat'])
word = attrib['word']
token = Token(word=attrib['word'],
pos=attrib['pos'],
attrib = node.attrib
if node.tag == 'rule':
cat = Category.parse(attrib['cat'])
children = [rec(child) for child in node.getchildren()]
if len(children) == 1:
return Tree.make_unary(cat, children[0], lang)
else:
assert len(children) == 2
left, right = children
combinator = guess_combinator_by_triplet(
binary_rules, cat, left.cat, right.cat)
combinator = combinator or UNKNOWN_COMBINATOR
return Tree.make_binary(cat, left, right, combinator, lang)
else:
assert node.tag == 'lf'
cat = Category.parse(attrib['cat'])
word = attrib['word']
token = Token(word=attrib['word'],
pos=attrib['pos'],
entity=attrib['entity'],
lemma=attrib['lemma'],
chunk=attrib['chunk'])
tokens.append(token)
return Tree.make_terminal(word, cat, lang)
tokens = []
def rec() -> None:
if len(buf) == 0:
return
item = buf.pop()
assert item[0] == '(' or item[-1] == ')'
if item[0] == '(':
stack.append(Category.parse(item[1:]))
elif item[-1] == ')':
reduce(item)
rec()