From a780c60bafd91b450df71a14a35ff3ea708a6fab Mon Sep 17 00:00:00 2001 From: Hivan Du Date: Sat, 6 Jan 2024 16:40:49 +0800 Subject: [PATCH] fix 'networkx' has no attribute 'from_numpy_matrix' --- textrank4zh/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/textrank4zh/util.py b/textrank4zh/util.py index f9e356f..87fb2a6 100644 --- a/textrank4zh/util.py +++ b/textrank4zh/util.py @@ -157,7 +157,7 @@ def sort_words(vertex_source, edge_source, window = 2, pagerank_config = {'alpha debug('graph:\n', graph) - nx_graph = nx.from_numpy_matrix(graph) + nx_graph = nx.from_numpy_array(graph) scores = nx.pagerank(nx_graph, **pagerank_config) # this is a dict sorted_scores = sorted(scores.items(), key = lambda item: item[1], reverse=True) for index, score in sorted_scores: @@ -186,7 +186,7 @@ def sort_sentences(sentences, words, sim_func = get_similarity, pagerank_config graph[x, y] = similarity graph[y, x] = similarity - nx_graph = nx.from_numpy_matrix(graph) + nx_graph = nx.from_numpy_array(graph) scores = nx.pagerank(nx_graph, **pagerank_config) # this is a dict sorted_scores = sorted(scores.items(), key = lambda item: item[1], reverse=True)