【发布时间】:2019-09-10 07:11:52
【问题描述】:
我需要为每个显示的图形提取边缘信息。数据为 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
【问题讨论】:
-
您能否详细说明您的代码“不起作用”的原因?你期待什么,实际发生了什么?如果您遇到异常/错误,请按照如何创建minimal reproducible example 页面发布它发生的行和异常/错误详细信息。请edit您的问题将这些详细信息添加到其中,否则我们可能无法提供帮助。如果你还没有解决你的新挑战——我们不会为你编写代码,帮助你解决你的问题。为了使我们能够做到这一点,我们需要知道出了什么问题。
-
这一大块 unicodedata 与您的问题有何关系?你能用我们可以阅读的文字代替它吗?
-
graph.get_edge_data(s,o) s=[] s=graph.edges() print s 这些行给了我一大堆 unicodedata。我试图提取边缘数据,但这个输出是显示的所有图表的边缘数据。我怎样才能为每个图表实现相同的效果?@PatrickArtner
-
你的意思是connected components?在这种情况下,请查看 connected_components 的
networkx。
标签: python-2.7 matplotlib utf-8 networkx