From c25bb4b268f01171627bc27f61cd81dd04a8d193 Mon Sep 17 00:00:00 2001 From: samyak jain Date: Wed, 31 Jan 2018 11:04:00 +0530 Subject: [PATCH] Fixes #1401 , IS_SINGLE Function updated --- gensim/models/phrases.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gensim/models/phrases.py b/gensim/models/phrases.py index 33b8e0e8a3..13ca1a7b67 100644 --- a/gensim/models/phrases.py +++ b/gensim/models/phrases.py @@ -104,6 +104,7 @@ def _is_single(obj): is a corpus if it is an iterable of documents. """ obj_iter = iter(obj) + temp_iter = obj_iter try: peek = next(obj_iter) obj_iter = it.chain([peek], obj_iter) @@ -113,9 +114,12 @@ def _is_single(obj): if isinstance(peek, string_types): # It's a document, return the iterator return True, obj_iter + if temp_iter == obj : + #Checking for iterator to the object + return False , obj_iter else: # If the first item isn't a string, assume obj is a corpus - return False, list(obj_iter) + return False, obj class SentenceAnalyzer(object):