Esempio n. 1
0
def half_proclaim(draft, ar):
    p = proclaimable(draft, ar)
    if p == MEH:
        if dribble.watch(ar.dom):
            dribble.log("# Meh: %s" % express(ar))
        pass
    elif p:
        if dribble.watch(ar.dom):
            dribble.log("# storing")
        draft[ar.dom] = ar
    else:
        print("** Not OK to replace %s\n   with %s" %
              (express(draft.get(ar.dom)), express(ar)))
        assert False

    if dribble.watch(ar.dom):
        dribble.log("# Proclaim %s\n  yields %s" %
                    (express(ar), express(draft.get(ar.dom))))
Esempio n. 2
0
 def process(node):
     merged = inject(node, al)
     if not merged in parents:
         p = merged_parent(merged, al)
         if p:
             if dribble.watch(node):
                 (x, y) = p
                 dribble.log("# Merged parent(%s) = (%s, %s)" %
                             (cl.get_unique(node), cl.get_unique(x),
                              cl.get_unique(y)))
             parents[merged] = p  # Otherwise it's a root
         else:
             if dribble.watch(node):
                 dribble.log("# No merge(%s)" % cl.get_unique(node))
             if not merged in roots:
                 roots.append(merged)
     for child in cl.get_children(node):
         process(child)
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 6
0
def proclaimable(draft, ar):
    if dribble.watch(ar.dom): print("# Proclaimable? %s" % express(ar))
    before = draft.get(ar.dom)
    if not before:
        if dribble.watch(ar.dom): print("# New: %s" % express(ar))
        return True  # Improvement

    elif ar.relation == before.relation and ar.cod == before.cod:
        # Update reason
        if dribble.watch(ar.dom):
            print("# Change reason only: %s" % express(ar))
        return True  # Improvement

    elif before.relation == rel.matches:
        if dribble.watch(ar.dom): print("# Upgrade ~: %s" % express(ar))
        return True  # Improvement

    elif ar.cod == before.cod:
        # Relations differ.
        # Change in RCC5 between two fixed nodes is not allowed.
        if dribble.watch(ar.dom): print("# Wrong RCC5: %s" % express(ar))
        return False  # Inconsistent

    # Codomains are different, relations may or may not be different

    elif ar.relation == rel.eq and before.relation == rel.eq:
        if dribble.watch(ar.dom): print("# UNA: %s" % express(ar))
        return False  # Inconsistent (unique name assumption)
    elif before.relation == rel.gt or before.relation == rel.matches:
        if dribble.watch(ar.dom): print("# Upgrade: %s" % express(ar))
        return True

    else:
        if dribble.watch(ar.dom):
            print("# Meh: before %s,\n  after        %s" %
                  (express(before), express(ar)))
        return MEH
Esempio n. 7
0
 def subanalyze_cross_mrcas(node, other):
   result = None
   probe = tipwards.get(node)
   if probe:
     # Could be: = < or >
     result = probe.cod
   else:
     children = cl.get_children(node)
     if children:
       m = None      # None is the identity for mrca
       for child in children:
         m2 = subanalyze_cross_mrcas(child, other)
         if m2 != None:
           m = cl.mrca(m, m2) if m != None else m2
       if m != None:
         result = m
   if result:
     assert cl.get_checklist(result) != cl.get_checklist(node)
     if dribble.watch(node):
       dribble.log("# Cross-mrca(%s) = %s" %
                   (cl.get_unique(node), cl.get_unique(result)))
     cross_mrcas[node] = result
   return result             # in B
Esempio n. 8
0
def extensional(dom, cod, re, reason, revreason=None):
    ar = bridge(dom, cod, re, reason, revreason)
    if dribble.watch(dom):
        dribble.log("# Extensional articulation %s" % art.express(ar))
    return ar
Esempio n. 9
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