summarization.pagerank_weighted
– Weighted PageRank algorithm¶This module calculate PageRank 1 based on wordgraph.
Examples
Calculate Pagerank for words
>>> from gensim.summarization.keywords import get_graph
>>> from gensim.summarization.pagerank_weighted import pagerank_weighted
>>> graph = get_graph("The road to hell is paved with good intentions.")
>>> # result will looks like {'good': 0.70432858653171504, 'hell': 0.051128871128006126, ...}
>>> result = pagerank_weighted(graph)
Build matrix from graph
>>> from gensim.summarization.pagerank_weighted import build_adjacency_matrix
>>> build_adjacency_matrix(graph).todense()
matrix([[ 0., 0., 0., 0., 0.],
[ 0., 0., 1., 0., 0.],
[ 0., 1., 0., 0., 0.],
[ 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0.]])
gensim.summarization.pagerank_weighted.
build_adjacency_matrix
(graph, coeff=1)¶Get matrix representation of given graph.
graph (Graph
) – Given graph.
coeff (float) – Matrix values coefficient, optonal.
Adjacency matrix of given graph, n is number of nodes.
scipy.sparse.csr_matrix
, shape = [n, n]
gensim.summarization.pagerank_weighted.
build_probability_matrix
(graph, coeff=1.0)¶Get square matrix of shape (n, n), where n is number of nodes of the given graph.
graph (Graph
) – Given graph.
coeff (float) – Matrix values coefficient, optonal.
Eigenvector of matrix a, n is number of nodes of graph.
numpy.ndarray, shape = [n, n]
gensim.summarization.pagerank_weighted.
pagerank_weighted
(graph, damping=0.85)¶Get dictionary of graph nodes and its ranks.
graph (Graph
) – Given graph.
damping (float) – Damping parameter, optional
Nodes of graph as keys, its ranks as values.
dict
gensim.summarization.pagerank_weighted.
principal_eigenvector
(a)¶Get eigenvector of square matrix a.
a (numpy.ndarray, shape = [n, n]) – Given matrix.
Eigenvector of matrix a.
numpy.ndarray, shape = [n, ]
gensim.summarization.pagerank_weighted.
process_results
(graph, vec)¶Get graph nodes and corresponding absolute values of provided eigenvector.
This function is helper for pagerank_weighted()
graph (Graph
) – Given graph.
vec (numpy.ndarray, shape = [n, ]) – Given eigenvector, n is number of nodes of graph.
Graph nodes as keys, corresponding elements of eigenvector as values.
dict