def label_predication(node, inherit_tag=False): kid_tag = strip_tag_if(not inherit_tag, node.tag) kids = map(label_node, node.kids) last_kid, second_last_kid = twice(get_kid_)(kids) cur = Node(kid_tag, [second_last_kid, last_kid], head_index=1) while kids: kid = get_kid_(kids) cur = Node(kid_tag, [kid, cur], head_index=1) cur.tag = node.tag # restore the full tag at the topmost level return cur
def label_head_initial(node, inherit_tag=False): if has_tag(node, 'c'): inherit_tag=False kid_tag = strip_tag_if(not inherit_tag, node.tag) kids = map(label_node, node.kids)[::-1] first_kid, second_kid = twice(kids.pop)() cur = Node(kid_tag, [first_kid, second_kid], head_index=0) while kids: kid = kids.pop() cur = Node(kid_tag, [cur, kid], head_index=0) cur.tag = node.tag return cur