Skip to content
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

Return keywords before matrix processing if no graph edges. Fixes #2075 #2154

Merged
merged 2 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gensim/summarization/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ def keywords(text, ratio=0.2, words=None, split=False, scores=False, pos_filter=

_remove_unreachable_nodes(graph)

if not graph.edges():
return _format_results([], [], split, scores)

# Ranks the tokens using the PageRank algorithm. Returns dict of lemma -> score
pagerank_scores = _pagerank(graph)

Expand Down
6 changes: 6 additions & 0 deletions gensim/test/test_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def test_text_keywords_with_small_graph(self):
kwds = keywords(text, words=1, split=True)
self.assertTrue(len(kwds))

def test_text_keywords_without_graph_edges(self):
# regression test, we get graph with no edges on this text
text = 'Sitio construcción. Estaremos línea.'
kwds = keywords(text, deacc=False, scores=True)
self.assertFalse(len(kwds))


if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.DEBUG)
Expand Down