Skip to content

Commit

Permalink
Fixes piskvorky#1401 , Phrases behavious now consistent on different …
Browse files Browse the repository at this point in the history
…versions , test added for empty iterator
  • Loading branch information
sj29-innovate committed Jan 23, 2018
1 parent 33a88f4 commit d9b098a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gensim/models/phrases.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _is_single(obj):
return True, obj_iter
else:
# If the first item isn't a string, assume obj is a corpus
return False, obj_iter
return False, list(obj_iter)


class SentenceAnalyzer(object):
Expand Down
7 changes: 7 additions & 0 deletions gensim/test/test_phrases.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ def setUp(self):
self.bigram_unicode = Phrases(
self.unicode_sentences, min_count=1, threshold=1, common_terms=self.common_terms)

def testEmptyPhrasifiedSentencesIterator(self):
bigram_phrases = Phrases(self.sentences)
bigram_phraser = Phraser(bigram_phrases)
trigram_phrases = Phrases(bigram_phraser[self.sentences])
trigram_phraser = Phraser(trigram_phrases)
self.assertNotEqual(trigram_phraser[bigram_phraser[self.sentences]].__len__(), 0)

def testEmptyInputsOnBigramConstruction(self):
"""Test that empty inputs don't throw errors and return the expected result."""
# Empty list -> empty list
Expand Down

0 comments on commit d9b098a

Please sign in to comment.