f96837d570ed738baa0f47924cfa09f40787cdbe,src/gensim/utils.py,,isCorpus,#Any#,199

Before Change


    **NOTE**: When called on an empty corpus (no documents), will return False.
    
    try:
        if hasattr(obj, "next"):
            return False // iterators are not allowed to be corpora (need an iterable)
        doc1 = iter(obj).next() // obj supports iteration and is not empty
        if len(doc1) == 0: // the first document is empty
            return True
        id1, val1 = iter(doc1).next() // or the first document is a 2-tuple
        id1, val1 = int(id1), float(val1) // id must be an integer, weight a float

After Change


            // the input is an iterator (not iterable), meaning once we call next()
            // that element is gone forever. we must be careful to put whatever we
            // retrieve back again
            doc1 = obj.next()
            obj = itertools.chain([doc1], obj)
        else:
            doc1 = iter(obj).next()
        if not list(doc1):
            return True, obj // the first document is empty, assume this is a corpus
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: RaRe-Technologies/gensim
Commit Name: f96837d570ed738baa0f47924cfa09f40787cdbe
Time: 2010-09-06
Author: radimrehurek@seznam.cz
File Name: src/gensim/utils.py
Class Name:
Method Name: isCorpus


Project Name: IndicoDataSolutions/finetune
Commit Name: 2028dffb2a29570c72f10bcb3e35e33fa7fb1c03
Time: 2018-11-13
Author: madison@indico.io
File Name: finetune/base.py
Class Name: BaseModel
Method Name: _inference


Project Name: RaRe-Technologies/gensim
Commit Name: e0830d7736bb620f926545078bea5620a8b4a19c
Time: 2010-09-06
Author: piskvorky@92d0401f-a546-4972-9173-107b360ed7e5
File Name: src/gensim/utils.py
Class Name:
Method Name: isCorpus