gensim logo

gensim
gensim tagline

Get Expert Help From The Gensim Authors

Consulting in Machine Learning & NLP

• Commercial document similarity engine: ScaleText.ai

Corporate trainings in Python Data Science and Deep Learning

summarization.commons – Common graph functions

summarization.commons – Common graph functions

This module provides functions of creating graph from sequence of values and removing of unreachable nodes.

Examples

Create simple graph and add edges. Let’s take a look at nodes.

>>> gg = build_graph(['Felidae', 'Lion', 'Tiger', 'Wolf'])
>>> gg.add_edge(("Felidae", "Lion"))
>>> gg.add_edge(("Felidae", "Tiger"))
>>> sorted(gg.nodes())
['Felidae', 'Lion', 'Tiger', 'Wolf']

Remove nodes with no edges.

>>> remove_unreachable_nodes(gg)
>>> sorted(gg.nodes())
['Felidae', 'Lion', 'Tiger']
gensim.summarization.commons.build_graph(sequence)

Creates and returns undirected graph with given sequence of values.

Parameters:sequence (list of hashable) – Sequence of values.
Returns:Created graph.
Return type:Graph
gensim.summarization.commons.remove_unreachable_nodes(graph)

Removes unreachable nodes (nodes with no edges), inplace.

Parameters:graph (Graph) – Given graph.