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):