summarization.graph
– Graph¶This module contains abstract class IGraph represents graphs interface and class Graph (based on IGraph) which implements undirected graph.
Examples
Create simple graph with 4 nodes.
>>> g = Graph()
>>> g.add_node('Felidae')
>>> g.add_node('Lion')
>>> g.add_node('Tiger')
>>> g.add_node('Wolf')
>>> sorted(g.nodes())
['Felidae', 'Lion', 'Tiger', 'Wolf']
Add some edges and check neighbours.
>>> g.add_edge(("Felidae", "Lion"))
>>> g.add_edge(("Felidae", "Tiger"))
>>> g.neighbors("Felidae")
['Lion', 'Tiger']
One node has no neighbours.
>>> g.neighbors("Wolf")
[]
gensim.summarization.graph.
Graph
¶Bases: gensim.summarization.graph.IGraph
Implementation of an undirected graph, based on IGraph.
DEFAULT_WEIGHT
¶Weight set by default.
float
Initializes object.
DEFAULT_WEIGHT
= 0add_edge
(edge, wt=1)¶Adds an edge to the graph connecting two nodes.
edge ((hashable, hashable)) – Given edge.
wt (float, optional) – Weight of new edge.
ValueError – If edge already exists in graph.
add_node
(node)¶Adds given node to the graph.
Note
While nodes can be of any type, it’s strongly recommended to use only numbers and single-line strings as node identifiers if you intend to use write().
node (hashable) – Given node.
ValueError – If node already exists in graph.
del_edge
(edge)¶Removes given edges from the graph.
edge ((hashable, hashable)) – Given edge.
del_node
(node)¶Removes given node and its edges from the graph.
node (hashable) – Given node.
edge_weight
(edge)¶Returns weight of given edge.
edge ((hashable, hashable)) – Given edge.
Edge weight.
float
edges
()¶Returns all edges of the graph.
Edges of graph.
list of (hashable, hashable)
has_edge
(edge)¶Returns whether an edge exists.
edge ((hashable, hashable)) – Given edge.
True if edge exists, False otherwise.
bool
has_node
(node)¶Returns whether the requested node exists.
node (hashable) – Given node.
True if node exists, False otherwise.
bool
iter_edges
()¶Returns iterator of all edges of the graph.
(hashable, hashable) – Edges of graph.
neighbors
(node)¶Returns all nodes that are directly accessible from given node.
node (hashable) – Given node identifier.
Nodes directly accessible from given node.
list of hashable
nodes
()¶Returns all nodes of the graph.
Nodes of graph.
list of hashable
gensim.summarization.graph.
IGraph
¶Bases: object
Represents the interface or contract that the graph for TextRank should implement.
add_edge
(edge, wt=1)¶Adds an edge to the graph connecting two nodes. An edge, here, is a tuple of two nodes.
edge ((hashable, hashable)) – Given edge.
wt (float, optional) – Weight of new edge.
add_node
(node)¶Adds given node to the graph.
Note
While nodes can be of any type, it’s strongly recommended to use only numbers and single-line strings as node identifiers if you intend to use write().
node (hashable) – Given node
del_node
(node)¶Removes node and its edges from the graph.
node (hashable) – Node to delete.
edge_weight
(edge)¶Returns weigth of given edge.
edge ((hashable, hashable)) – Given edge.
Edge weight.
float
edges
()¶Returns all edges of graph.
Edges of graph.
list of (hashable, hashable)
has_edge
(edge)¶Returns whether an edge exists.
edge ((hashable, hashable)) – Given edge.
True if edge exists, False otherwise.
bool
has_node
(node)¶Returns whether the requested node exists.
node (hashable) – Given node identifier.
True if node exists, False otherwise.
bool
neighbors
(node)¶Return all nodes that are directly accessible from given node.
node (hashable) – Given node identifier.
Nodes directly accessible from given node.
list of hashable
nodes
()¶Returns all nodes of graph.
Nodes of graph.
list of hashable