Exemplo n.º 1
0
def commonancestor(d, r1, r2, leaves):
    ancestors1 = {x:True for x in getAncestors(d, r1, [])}
    ancestors2 = getAncestors(d, r2, [])
    for x in ancestors2:
        if x in ancestors1:
            t1 = abstractTree(prune(subTree(x, r1, leaves), d, ancestors1))
            offsets = sortOffsets(getOffsets(t1))
            t1 = renumber(t1, offsets=offsets)
            d = renumber(abstractTree([leaves[x], [leaves[d]]]), offsets=offsets)
            return (t1, d)
    return False
Exemplo n.º 2
0
def renumber(t, top=False, offsets=False):
    if type(top) == "bool":
        top = t[0].position
        if type(offsets) == "bool":
            offsets = sortOffsets(getOffsets(t))
    if type(t) == "WORD":
        t.position = offsets[t.position]
    else:
        for d in t:
            renumber(d, top=top, offsets=offsets)
    return t
Exemplo n.º 3
0
def simplifyTree(t):
    t = abstractTree(t)
    renumber(t)
    return t