def add_sentences(self, sentences):
"""
@type sentences: list[Sentence]
:param sentences:
:return:
"""
counter = self.counter
G = self.G
for sentence in sentences:
G.add_nodes_from(sentence.concepts)
counter.update(ngrams(sentence.concepts, self.N))
for (keys, value) in counter.items():
for i in range(0, len(keys) - 1):
for j in range(1, len(keys)):
G.add_edge(keys[i], keys[j], weight=value)
# counter.update((keys[i], keys[j]))
# for (key, value) in counter.items():
# G.add_edge(key[0], key[1], attr={"weight": value})
print("V := (N,E), |N| = %s, |E| = %s" % (len(G.nodes()), len(G.edges())))
self.pr = nx.pagerank(G)
feedback_graph.py 文件源码
python
阅读 29
收藏 0
点赞 0
评论 0
评论列表
文章目录