def __getitem__(self, docno): """Get document by `docno` index. Parameters ---------- docno : {int, iterable of int} Document number or iterable of numbers (like a list of str). Returns ------- list of (int, float) If `docno` is int - return document in BoW format. :class:`~gensim.utils.SlicedCorpus` If `docno` is iterable of int - return several documents in BoW format wrapped to :class:`~gensim.utils.SlicedCorpus`. Raises ------ RuntimeError If index isn't exist. """ if self.index is None: raise RuntimeError("Cannot call corpus[docid] without an index") if isinstance(docno, (slice, list, numpy.ndarray)): return utils.SlicedCorpus(self, docno) elif isinstance(docno, six.integer_types + (numpy.integer, )): return self.docbyoffset(self.index[docno]) # TODO: no `docbyoffset` method, should be defined in this class else: raise ValueError( 'Unrecognised value for docno, use either a single integer, a slice or a numpy.ndarray' )
def __getitem__(self, docno): if self.index is None: raise RuntimeError("cannot call corpus[docid] without an index") if isinstance(docno, slice): return utils.SlicedCorpus(self, docno) return self.docbyoffset(self.index[docno])
def __getitem__(self, docno): if self.index is None: raise RuntimeError("Cannot call corpus[docid] without an index") if isinstance(docno, (slice, list, numpy.ndarray)): return utils.SlicedCorpus(self, docno) elif isinstance(docno, six.integer_types + (numpy.integer, )): return self.docbyoffset(self.index[docno]) else: raise ValueError( 'Unrecognised value for docno, use either a single integer, a slice or a numpy.ndarray' )