-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Refactor documentation API Reference for gensim.summarization #1709
Changes from 5 commits
1c6009c
851b02c
5cbb184
31be095
c6c608b
d5247c1
3031cd0
4d7b0a9
2c8ef28
254dce7
a2c2102
1a87934
0ca8332
ed188ae
20b19d6
6ec29bf
e2a2e60
d7056e4
400966c
44f617c
d2fed6c
84b0f3a
ba8b1b6
2a283d7
6bd1584
7ec89fa
fa5efce
0014d88
1a0166a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,46 @@ | |
# | ||
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html | ||
|
||
"""This module provides functions of creatinf graph from sequence of values and | ||
removing of unreachable nodes. | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
Create simple graph and add edges. Let's kake a look at nodes. | ||
|
||
>>> gg = build_graph(['Felidae', 'Lion', 'Tiger', 'Wolf']) | ||
>>> gg.add_edge(("Felidae", "Lion")) | ||
>>> gg.add_edge(("Felidae", "Tiger")) | ||
>>> gg.nodes() | ||
['Felidae', 'Lion', 'Tiger', 'Wolf'] | ||
|
||
Remove nodes with no edges. | ||
|
||
>>> remove_unreachable_nodes(gg) | ||
>>> gg.nodes() | ||
['Felidae', 'Lion', 'Tiger'] | ||
|
||
""" | ||
|
||
from gensim.summarization.graph import Graph | ||
|
||
|
||
def build_graph(sequence): | ||
"""Creates and returns graph with given sequence of values. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's "type" of graph (oriented, etc)? |
||
|
||
Parameters | ||
---------- | ||
sequence : list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. list of |
||
Sequence of values. | ||
|
||
Returns | ||
------- | ||
Graph | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Concrete link to type like
here and everywhere (for "gensim-defined" types). |
||
Created graph. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Graph produced by |
||
|
||
""" | ||
graph = Graph() | ||
for item in sequence: | ||
if not graph.has_node(item): | ||
|
@@ -15,6 +51,15 @@ def build_graph(sequence): | |
|
||
|
||
def remove_unreachable_nodes(graph): | ||
"""Removes unreachable nodes (nodes with no edges). Works inplace. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Parameters | ||
---------- | ||
graph : Graph | ||
Given graph. | ||
|
||
""" | ||
|
||
for node in graph.nodes(): | ||
if sum(graph.edge_weight((node, other)) for other in graph.neighbors(node)) == 0: | ||
graph.del_node(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed link to BM25 algorithm (wiki for example)