从网络图中提取边缘数据



我需要提取显示的每个图形的边缘信息。数据采用 utf-8 格式。

将显示文档中每个句子的图形。所以现在必须从图表中提取信息。要提取的句子与在图形中合并的某些句子不同。该图解释了包含一些图形的输出(每个图形最多有三个节点(

for s in subject_list:
    if s is not "":
        graph.add_node(s)
        labels[s] = s

for o in object_list:
    if o is not "":
        graph.add_node(o)
        labels[b] = b
for v in verb_list:
    if v is not "":
        graph.add_node(v)
        labels[v] = v

for (s, o, v) in zip(subject_list, object_list, verb_list):
    if s and o is not "":
        graph.add_edge(s, o)
    if o and v is not "":
        graph.add_edge(o, v)
pos=nx.spring_layout(graph)
nx.draw(graph, with_labels = True, font_family = "Nirmala UI", node_size = 40, font_size = 9 ,node_color = "darkblue")
pl.show()
g=[]
for component in nx.connected_components(graph):
    # Each component is the set of nodes
    #print(component)
    # Filter all edges in graph: we keep only that are in the component
    g=(list(
        filter(
            lambda x: x[0] in component and x[1] in component,
            graph.edges
        )
    ))
    print g
ls=[]
for x in g[0]:
    ls.append(x)
    print (x)
![connected components output][1]

[1]: https://i.stack.imgur.com/iynw1.png
你需要

connected_components函数:

for component in nx.connected_components(graph):
    # Each component is the set of nodes
    print(component)
    # Filter all edges in graph: we keep only that are in the component
    print(list(
        filter(
            lambda x: x[0] in component and x[1] in component,
            graph.edges
        )
    ))

最新更新