Example #1
0
def report_on_collisions(A, B, al):
    index = cl.index_by_value(A, canonical_name)
    for name in index:
        A_nodes = index[name]
        if len(A_nodes) == 1:
            B_nodes = cl.get_nodes_with_value(B, canonical_name, name)
            if B_nodes and len(B_nodes) == 1:
                A_node = A_nodes[0]
                B_node = B_nodes[0]
                if cl.is_accepted(A_node) and cl.is_accepted(B_node):
                    ar1 = al.get(A_node)
                    ar2 = al.get(B_node)
                    ar1_bad = (ar1 and ar1.relation == rel.eq
                               and ar1.cod != B_node)
                    ar2_bad = (ar2 and ar2.relation == rel.eq
                               and ar2.cod != A_node)
                    if ar1_bad or ar2_bad:
                        dribble.log(
                            "# \"%s\" names different taxa in the two checklists"
                            % name)
                        dribble.log("  %s [%s]" %
                                    (art.express(ar1),
                                     art.reason(ar1) if ar1 else "-"))
                        dribble.log("  %s [%s]" %
                                    (art.express(ar2),
                                     art.reason(ar2) if ar2 else "-"))
Example #2
0
 def process(node, less):
   if not draft.get(node):
     e = extensional_match(node, xmrcas)
     if e:
       if e.relation == rel.lt:
         if less and e.cod == less.cod:
           print("# Suppressing %s because redundant with\n  %s" %
                 (art.express(e), art.express(less)))
           pass
         else:
           less = e
           ext[node] = e
       else:
         less = None
         ext[node] = e
     else:
       less = None
   for child in cl.get_children(node):
     process(child, less)
Example #3
0
 def process(here, there):
     for node in here.get_all_nodes():
         if cl.is_accepted(node) and not node in best:
             ar = best_intensional_match(node, there)
             if dribble.watch(node):
                 dribble.log("# Best: %s" % art.express(ar))
             if ar:
                 assert ar.dom == node
                 assert cl.is_accepted(ar.cod)
                 art.half_proclaim(best, ar)
Example #4
0
 def filter(node):
   debug = dribble.watch(node)
   found_match = None
   for child in cl.get_children(node):
     ar = filter(child)
     if ar:
       found_match = ar
   if found_match:    # Some descendant is a particle
     if debug: dribble.log("# %s: descendant matches, not keeping: %s" %
                           (cl.get_unique(node), art.express(found_match)))
     return found_match
   elif node in amap:
     ar = amap[node]
     tw[ar.dom] = ar
     if debug: dribble.log("# %s is a tipward match, keeping: %s" %
                           (cl.get_unique(node), art.express(ar)))
     return ar
   else:
     if debug: dribble.log("# %s is unmatched" % cl.get_unique(node))
     return None
Example #5
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
Example #6
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