Exemple #1
0
def alignchildren(t1, t2, M, E, w, x):
    """
  See figure 9 in reference.
  """

    for c in w.elements():
        c.inorder = False
    for c in x.elements():
        c.inorder = False

    s1 = [
        child for child in w.elements()
        if child in M.left and M.left[child].parent == x
    ]
    s2 = [
        child for child in x.elements()
        if child in M.right and M.right[child].parent == w
    ]

    def equal(a, b):
        return (a, b) in M

    S = [(s1[x], s2[y]) for x, y in lcs.lcs(lcs.path(s1, s2, equal))]
    for (a, b) in S:
        a.inorder = b.inorder = True

    for a in s1:
        for b in s2:
            if (a, b) in M and (a, b) not in S:
                k = findpos(M, b)
                E.move(a.path(), w.path(), k)
                t1.move(a.path(), w.path(), str(k))
                a.inorder = b.inorder = True
Exemple #2
0
def compare_value(value1, value2):
    if value1 is None and value2 is None:
        return 0.0
    if value1 is None or value2 is None:
        return 1.0
    return 1.0 - (float(len(lcs.lcs(lcs.path(value1, value2)))) /
                  max(len(value1), len(value2)))
Exemple #3
0
def alignchildren(t1, t2, M, E, w, x):
  """
  See figure 9 in reference.
  """

  for c in w.elements():
    c.inorder = False
  for c in x.elements():
    c.inorder = False

  s1 = [child for child in w.elements() if child in M.left and M.left[child].parent == x]
  s2 = [child for child in x.elements() if child in M.right and M.right[child].parent == w]

  def equal(a, b):
    return (a, b) in M

  S = [(s1[x], s2[y]) for x, y in lcs.lcs(lcs.path(s1, s2, equal))]
  for (a, b) in S:
    a.inorder = b.inorder = True

  for a in s1:
    for b in s2:
      if (a, b) in M and (a, b) not in S:
        k = findpos(M, b)
        E.move(a.path(), w.path(), k)
        t1.move(a.path(), w.path(), str(k))
        a.inorder = b.inorder = True
Exemple #4
0
def _match(nodes1, nodes2, M, equal):
    nodes = nodes1 + nodes2
    for label in utils.nub([node.label for node in nodes]):

        s1 = get_chain(nodes1, label)
        s2 = get_chain(nodes2, label)

        path = lcs.lcs(lcs.path(s1, s2, equal))

        for x, y in path:
            M.add((s1[x], s2[y]))
        for x, y in reversed(path):
            s1.pop(x)
            s2.pop(y)

        for x in range(len(s1)):
            for y in range(len(s2)):
                if equal(s1[x], s2[y]):
                    M.add((s1[x], s2[y]))
                    s2.pop(y)
                    break
Exemple #5
0
def _match(nodes1, nodes2, M, equal):
  nodes = nodes1 + nodes2
  for label in utils.nub([node.label for node in nodes]):

    s1 = get_chain(nodes1, label)
    s2 = get_chain(nodes2, label)

    path = lcs.lcs(lcs.path(s1, s2, equal))

    for x, y in path:
      M.add((s1[x], s2[y]))
    for x, y in reversed(path):
      s1.pop(x)
      s2.pop(y)

    for x in range(len(s1)):
      for y in range(len(s2)):
        if equal(s1[x], s2[y]):
          M.add((s1[x], s2[y]))
          s2.pop(y)
          break
Exemple #6
0
def compare_value(value1, value2):
  if value1 is None and value2 is None:
    return 0.0
  if value1 is None or value2 is None:
    return 1.0
  return 1.0 - (float(len(lcs.lcs(lcs.path(value1, value2)))) / max(len(value1), len(value2)))