Пример #1
0
def delete_nodes(graph, nodes):
    g = Hgraph()
    for p, r, ch in graph.triples():
        if (p not in nodes) and (not (len(ch) == 1 and ch[0] in nodes)):
            g._add_triple(p, r, ch, warn=False)
        else:
            if (p not in nodes) and (p not in g):
                g[p] = ListMap()
            if len(ch) == 1 and (ch[0] not in nodes) and (ch[0] not in g):
                g[ch[0]] = ListMap()
    g.roots = g.find_roots(warn=False)
    return g
Пример #2
0
def delete_nodes(graph, nodes):
    g = Hgraph()
    for p, r, ch in graph.triples():
        if (p not in nodes) and (not (len(ch) == 1 and ch[0] in nodes)):
            g._add_triple(p, r, ch, warn=False)
        else:
            if (p not in nodes) and (p not in g):
                g[p] = ListMap()
            if len(ch) == 1 and (ch[0] not in nodes) and (ch[0] not in g):
                g[ch[0]] = ListMap()
    g.roots = g.find_roots(warn=False)
    return g
Пример #3
0
def get_line_graph(graph):

    lgraph = Hgraph()
    edges_for_node = defaultdict(list)

    for p, r, ch in graph.triples():
        edges_for_node[p].append(str((p, r, ch)))
        for c in ch:
            edges_for_node[c].append(str((p, r, ch)))

    for r in edges_for_node:
        for p, c in itertools.combinations(edges_for_node[r], 2):
            lgraph._add_triple(p, r, (c,), warn=False)
            lgraph._add_triple(c, r, (p,), warn=False)
    lgraph.roots = lgraph.find_roots()
    return lgraph
Пример #4
0
def get_line_graph(graph):

    lgraph = Hgraph()
    edges_for_node = defaultdict(list)

    for p, r, ch in graph.triples():
        edges_for_node[p].append(str((p, r, ch)))
        for c in ch:
            edges_for_node[c].append(str((p, r, ch)))

    for r in edges_for_node:
        for p, c in itertools.combinations(edges_for_node[r], 2):
            lgraph._add_triple(p, r, (c, ), warn=False)
            lgraph._add_triple(c, r, (p, ), warn=False)
    lgraph.roots = lgraph.find_roots()
    return lgraph