gensim logo

gensim tagline

Get Expert Help From The Gensim Authors

Consulting in Machine Learning & NLP

• Commercial document similarity engine:

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.


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']

Creates and returns undirected graph with given sequence of values.

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

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

Parameters:graph (Graph) – Given graph.