예제 #1
0
def identities(g, s):
    #
    # use overlap of UCCA yields in picking initial node pairing
    #
    if g.framework == "ucca" and g.input \
            and s.framework == "ucca" and s.input:
        g_identities = dict()
        s_identities = dict()
        g_dominated = dict()
        s_dominated = dict()
        for node in g.nodes:
            g_identities, g_dominated = \
                identify(g, node.id, g_identities, g_dominated)
        g_identities = {
            key: explode(g.input, value)
            for key, value in g_identities.items()
        }
        for node in s.nodes:
            s_identities, s_dominated = \
                identify(s, node.id, s_identities, s_dominated)
        s_identities = {
            key: explode(s.input, value)
            for key, value in s_identities.items()
        }
    else:
        g_identities = s_identities = g_dominated = s_dominated = None
    return g_identities, s_identities, g_dominated, s_dominated
예제 #2
0
 def __init__(self, graph, index):
     self.node2id = dict()
     self.id2node = dict()
     self.nodes = []
     self.edges = []
     for i, node in enumerate(graph.nodes):
         self.node2id[node] = i
         self.id2node[i] = node
         self.nodes.append(i)
     for edge in graph.edges:
         src = graph.find_node(edge.src)
         src = self.node2id[src]
         tgt = graph.find_node(edge.tgt)
         tgt = self.node2id[tgt]
         self.edges.append((src, tgt, edge.lab))
         if edge.attributes:
             for prop, val in zip(edge.attributes, edge.values):
                 self.edges.append((src, tgt, ("E", prop, val)))
     #
     # Build the pseudo-edges. These have target nodes that are
     # unique for the value of the label, anchor, property.
     #
     if index is None:
         index = dict()
     for i, node in enumerate(graph.nodes):
         # labels
         j = get_or_update(index, ("L", node.label))
         self.edges.append((i, reindex(j), None))
         # tops
         if node.is_top:
             j = get_or_update(index, ("T"))
             self.edges.append((i, reindex(j), None))
         # anchors
         if node.anchors is not None:
             anchor = score_core.anchor(node)
             if graph.input:
                 anchor = score_core.explode(graph.input, anchor)
             j = get_or_update(index, ("A", anchor))
             self.edges.append((i, reindex(j), None))
         # properties
         if node.properties:
             for prop, val in zip(node.properties, node.values):
                 j = get_or_update(index, ("P", prop, val))
                 self.edges.append((i, reindex(j), None))
예제 #3
0
def tuples(graph):
    identities = dict()
    for node in graph.nodes:
        identities, _ = identify(graph, node.id, identities)
    #
    # for robust comparison, represent each yield as a character set
    #
    if graph.input:
        for id in identities:
            identities[id] = explode(graph.input, identities[id])
    lprimary = set()
    lremote = set()
    uprimary = set()
    uremote = set()
    for edge in graph.edges:
        source = identities[edge.src]
        target = identities[edge.tgt]
        if edge.attributes and "remote" in edge.attributes:
            lremote.add((source, target, edge.lab))
            uremote.add((source, target))
        else:
            lprimary.add((source, target, edge.lab))
            uprimary.add((source, target))
    return lprimary, lremote, uprimary, uremote