class_docstr: Corpus handles input in `GibbsLda++ format <https://gibbslda.sourceforge.net/>`_.
  
  **Format description**
  
  Both data for training/estimating the model and new data (i.e., previously unseen data) have the same format
  as follows ::
  
      [M]
      [document1]
      [document2]
      ...
      [documentM]
  
  in which the first line is the total number for documents [M]. Each line after that is one document.
  [documenti] is the ith document of the dataset that consists of a list of Ni words/terms ::
  
      [documenti] = [wordi1] [wordi2] ... [wordiNi]
  
  in which all [wordij] (i=1..M, j=1..Ni) are text strings and they are separated by the blank character.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.test.utils import get_tmpfile, common_texts
      >>> from gensim.corpora import LowCorpus
      >>> from gensim.corpora import Dictionary
      >>>
      >>> # Prepare needed data
      >>> dictionary = Dictionary(common_texts)
      >>> corpus = [dictionary.doc2bow(doc) for doc in common_texts]
      >>>
      >>> # Write corpus in GibbsLda++ format to disk
      >>> output_fname = get_tmpfile("corpus.low")
      >>> LowCorpus.serialize(output_fname, corpus, dictionary)
      >>>
      >>> # Read corpus
      >>> loaded_corpus = LowCorpus(output_fname)
class_docstr_tok: ["Corpus","handles","input","in","`","GibbsLda++","format","<","https",":","\/\/gibbslda.sourceforge.net\/",">","`","_",".","*","*","Format","description","*","*","Both","data","for","training\/estimating","the","model","and","new","data","(","i.e.",",","previously","unseen","data",")","have","the","same","format","as","follows",":",":","[","M","]","[","document1","]","[","document2","]","...","[","documentM","]","in","which","the","first","line","is","the","total","number","for","documents","[","M","]",".","Each","line","after","that","is","one","document",".","[","documenti","]","is","the","ith","document","of","the","dataset","that","consists","of","a","list","of","Ni","words\/terms",":",":","[","documenti","]","=","[","wordi1","]","[","wordi2","]","...","[","wordiNi","]","in","which","all","[","wordij","]","(","i=1","..","M",",","j=1","..","Ni",")","are","text","strings","and","they","are","separated","by","the","blank","character",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.test.utils","import","get_tmpfile",",","common_texts",">",">",">","from","gensim.corpora","import","LowCorpus",">",">",">","from","gensim.corpora","import","Dictionary",">",">",">",">",">",">","#","Prepare","needed","data",">",">",">","dictionary","=","Dictionary","(","common_texts",")",">",">",">","corpus","=","[","dictionary.doc2bow","(","doc",")","for","doc","in","common_texts","]",">",">",">",">",">",">","#","Write","corpus","in","GibbsLda++","format","to","disk",">",">",">","output_fname","=","get_tmpfile","(","``","corpus.low","''",")",">",">",">","LowCorpus.serialize","(","output_fname",",","corpus",",","dictionary",")",">",">",">",">",">",">","#","Read","corpus",">",">",">","loaded_corpus","=","LowCorpus","(","output_fname",")"]
docstr: Parameters
  ----------
  fname : str
      Path to file in GibbsLda++ format.
  id2word : {dict of (int, str), :class:`~gensim.corpora.dictionary.Dictionary`}, optional
      Mapping between word_ids (integers) and words (strings).
      If not provided, the mapping is constructed directly from `fname`.
  line2words : callable, optional
      Function which converts lines(str) into tokens(list of str),
      using :func:`~gensim.parsing.preprocessing.split_on_space` as default.
docstr_tok: ["Parameters","--","--","--","--","--","fname",":","str","Path","to","file","in","GibbsLda++","format",".","id2word",":","{","dict","of","(","int",",","str",")",",",":","class",":","`","~gensim.corpora.dictionary.Dictionary","`","}",",","optional","Mapping","between","word_ids","(","integers",")","and","words","(","strings",")",".","If","not","provided",",","the","mapping","is","constructed","directly","from","`","fname","`",".","line2words",":","callable",",","optional","Function","which","converts","lines","(","str",")","into","tokens","(","list","of","str",")",",","using",":","func",":","`","~gensim.parsing.preprocessing.split_on_space","`","as","default","."]
code: def __init__(self, fname, id2word=None, line2words=split_on_space):
      """
  
      Parameters
      ----------
      fname : str
          Path to file in GibbsLda++ format.
      id2word : {dict of (int, str), :class:`~gensim.corpora.dictionary.Dictionary`}, optional
          Mapping between word_ids (integers) and words (strings).
          If not provided, the mapping is constructed directly from `fname`.
      line2words : callable, optional
          Function which converts lines(str) into tokens(list of str),
          using :func:`~gensim.parsing.preprocessing.split_on_space` as default.
  
      """
      IndexedCorpus.__init__(self, fname)
      logger.info("loading corpus from %s", fname)
  
      self.fname = fname  # input file, see class doc for format
      self.line2words = line2words  # how to translate lines into words (simply split on space by default)
      self.num_docs = self._calculate_num_docs()
  
      if not id2word:
          # build a list of all word types in the corpus (distinct words)
          logger.info("extracting vocabulary from the corpus")
          all_terms = set()
          self.use_wordids = (
              False  # return documents as (word, wordCount) 2-tuples
          )
          for doc in self:
              all_terms.update(word for word, wordCnt in doc)
          all_terms = sorted(
              all_terms
          )  # sort the list of all words; rank in that list = word's integer id
          # build a mapping of word id(int) -> word (string)
          self.id2word = dict(zip(range(len(all_terms)), all_terms))
      else:
          logger.info(
              "using provided word mapping (%i ids)", len(id2word)
          )
          self.id2word = id2word
      self.num_terms = len(self.word2id)
      self.use_wordids = (
          True  # return documents as (wordIndex, wordCount) 2-tuples
      )
  
      logger.info(
          "loaded corpus with %i documents and %i terms from %s",
          self.num_docs,
          self.num_terms,
          fname,
      )
  
file_path: gensim/gensim/corpora/lowcorpus.py
imports: import logging
  from collections import Counter
  from gensim import utils
  from gensim.corpora import IndexedCorpus
  from gensim.parsing.preprocessing import split_on_space
label_desc: Use image node_id 1 to create a new LowCorpus object from inherited base classes: IndexedCorpus with example: obj = LowCorpus(fname, id2word, line2words)