Beispiel #1
0
 def luup(x, y):
   if x == cl.forest_tnu or y == cl.forest_tnu: return
   assert cl.get_checklist(x) != cl.get_checklist(y)
   if in_chain(x, y0) and in_chain(y, x0):
     bar = best.get(x)
     if bar and find_in_chain(bar.cod, y, x0):
       if bar.cod == y:
         art.proclaim(draft, art.change_relation(bar, rel.eq, "extensional"))
         luup(cl.get_parent(x), cl.get_parent(y))
       else:
         art.proclaim(draft, art.extensional(y, x, rel.lt, "presumed 0"))
         luup(x, cl.get_parent(y))
     else:
       bar = best.get(y)
       if bar and find_in_chain(bar.cod, x, y0):
         if bar.cod == y:
           art.proclaim(draft, bar)
           luup(cl.get_parent(x), cl.get_parent(y))
         else:
           art.proclaim(draft, art.extensional(x, y, rel.lt, "presumed 1"))
           luup(cl.get_parent(x), y)
       else:
         # neither x nor y matches by name
         art.proclaim(draft, art.extensional(x, y, rel.eq, "presumed mutual"))
         luup(cl.get_parent(x), cl.get_parent(y))
Beispiel #2
0
 def luup(x, y):
   if x == cl.forest_tnu or y == cl.forest_tnu: return
   assert cl.get_checklist(x) != cl.get_checklist(y)
   if in_chain(x, y0) and in_chain(y, x0):
     bar = best.get(x)
     if bar and find_in_chain(bar.cod, y, x0):
       if bar.cod == y:
         art.proclaim(proposal, art.change_relation(bar, rel.eq, "extensional"))
         luup(cl.get_parent(x), cl.get_parent(y))
       else:
         art.proclaim(proposal, art.extensional(y, x, rel.lt, "refines", "refined by"))
         luup(x, cl.get_parent(y))
     else:
       bar = best.get(y)
       if bar and find_in_chain(bar.cod, x, y0):
         if bar.cod == y:
           art.proclaim(proposal, bar)
           luup(cl.get_parent(x), cl.get_parent(y))
         else:
           art.proclaim(proposal, art.extensional(x, y, rel.lt, "refines*", "refined by*"))
           luup(cl.get_parent(x), y)
       else:
         # neither x nor y matches by name
         art.proclaim(proposal, art.extensional(x, y, rel.eq, "similar="))
         luup(cl.get_parent(x), cl.get_parent(y))
Beispiel #3
0
def alignment_step(x, best, xmrcas, proposal):
  def luup(x, y):
    if x == cl.forest_tnu or y == cl.forest_tnu: return
    assert cl.get_checklist(x) != cl.get_checklist(y)
    if in_chain(x, y0) and in_chain(y, x0):
      bar = best.get(x)
      if bar and find_in_chain(bar.cod, y, x0):
        if bar.cod == y:
          art.proclaim(proposal, art.change_relation(bar, rel.eq, "extensional"))
          luup(cl.get_parent(x), cl.get_parent(y))
        else:
          art.proclaim(proposal, art.extensional(y, x, rel.lt, "refines", "refined by"))
          luup(x, cl.get_parent(y))
      else:
        bar = best.get(y)
        if bar and find_in_chain(bar.cod, x, y0):
          if bar.cod == y:
            art.proclaim(proposal, bar)
            luup(cl.get_parent(x), cl.get_parent(y))
          else:
            art.proclaim(proposal, art.extensional(x, y, rel.lt, "refines*", "refined by*"))
            luup(cl.get_parent(x), y)
        else:
          # neither x nor y matches by name
          art.proclaim(proposal, art.extensional(x, y, rel.eq, "similar="))
          luup(cl.get_parent(x), cl.get_parent(y))

  # See is b is in the chain (matching nodes in lineage)
  def find_in_chain(b, y, x0):
    if y == cl.forest_tnu:
      return False
    elif in_chain(y, x0):
      if b == y:
        return True
      else:
        return find_in_chain(b, cl.get_parent(y), x0)
    else:
      return False

  def in_chain(y, x0):
    ar = xmrcas.get(y)
    return ar and ar.cod == x0

  ar = xmrcas.get(x)          # x ~ y0
  if ar:
    y0 = ar.cod
    x0 = xmrcas.get(y0).cod
    if xmrcas.get(x0).cod != y0:     # x < y0
      art.proclaim(proposal, art.extensional(x, y0, rel.lt, "inferred"))
    else:                       # x could be <, =, > y0.  figure it out
      if x0 < y0:
        luup(x0, y0)
      else:
        pass    # pick it up later (or earlier)
Beispiel #4
0
 def subinfer_partners(x, other):
   y = None
   for child in cl.get_children(x):
     child_ar = subinfer_partners(child, other) # an articulation
     if child_ar != None:
       child_y = child_ar.cod
       if y == None:
         y = child_y
       else:
         y = cl.mrca(y, child_y)
   if y != None:
     ar = art.extensional(x, y, rel.matches, "cross-mrca")
   else:
     ar = get_mutual(best, x)
   if ar:
     assert cl.get_checklist(ar.cod) != cl.get_checklist(x)
     if dribble.watch(x):
       dribble.log("# Cross-mrca: %s" % (art.express(ar)))
     xmrcas[x] = ar
   return ar             # in B
Beispiel #5
0
def extensional_match(node, xmrcas):
  partner = xmrcas.get(node)      # node in other checklist; 'conode'
  if not partner:
    # Descendant of a particle
    if dribble.watch(node):
      dribble.log("# EM: %s is not tipward." % cl.get_unique(node))
    return None
  back = xmrcas.get(partner)    # 'bounce'
  if not back:
    # Not sure how this can happen but it does (NCBI vs. GBIF)
    dribble.log("%s <= %s <= nowhere" % (cl.get_unique(node),
                                         cl.get_unique(partner)))
    if dribble.watch(node):
      dribble.log("# EM: %s killed because aborted round trip." % cl.get_unique(node))
    return None
  # node <= partner <= back
  how = cl.how_related(node, back)    # Alway rcc5
  if how == rel.eq:
    # Should end up being eq iff name match or unique match
    # Can test for unique match by looking at xmrca of parent

    # Could be part of a 'monotypic' chain; fix later
    how = rel.matches
    reason = "mutual-cross-mrca"
  elif how == rel.gt:
    how = rel.matches
    reason = "monotypic-inversion"
  elif how == rel.disjoint:
    reason = "particle-set-exclusion"
  else:               # must be rel.lt
    # Assume resolution (node < partner) until conflict is proven
    reason = "refinement"
    # Look for an intersection between any partner-child and node
    # x is in A checklist, y is in B checklist
    for pchild in cl.get_children(partner):
      pchild_back = xmrcas.get(pchild)
      if pchild_back == None:
        # pchild ! node
        pass
      else:
        (d, e) = cross_compare(node, pchild, xmrcas)
        # d < node while e ! node
        if d and e:
          how = rel.conflict
          reason = ("%s is in; its sibling %s is not" %
                    (cl.get_unique(d), cl.get_unique(e)))
          dribble.log("** %s conflicts with %s because\n"
                      "   %s ! %s\n   (but sibling %s < %s)" %
                      (cl.get_unique(node),
                       cl.get_unique(partner),
                       cl.get_unique(e),
                       cl.get_unique(node),
                       cl.get_unique(d),
                       cl.get_unique(node)))
          break
        elif e:
          reason = ("%s is not in it" % cl.get_unique(e))

  ar = art.extensional(node, partner, how, reason)
  if dribble.watch(node):
    dribble.log("# Extensional articulation %s" % art.express(ar))
  return ar