class_docstr: Corpus handles input in `Mallet format <http://mallet.cs.umass.edu/import.php>`_.
  
  **Format description**
  
  One file, one instance per line, assume the data is in the following format ::
  
      [URL] [language] [text of the page...]
  
  Or, more generally, ::
  
      [document #1 id] [label] [text of the document...]
      [document #2 id] [label] [text of the document...]
      ...
      [document #N id] [label] [text of the document...]
  
  Note that language/label is *not* considered in Gensim, used `__unknown__` as default value.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.test.utils import get_tmpfile, common_texts
      >>> from gensim.corpora import MalletCorpus
      >>> from gensim.corpora import Dictionary
      >>>
      >>> # Prepare needed data
      >>> dictionary = Dictionary(common_texts)
      >>> corpus = [dictionary.doc2bow(doc) for doc in common_texts]
      >>>
      >>> # Write corpus in Mallet format to disk
      >>> output_fname = get_tmpfile("corpus.mallet")
      >>> MalletCorpus.serialize(output_fname, corpus, dictionary)
      >>>
      >>> # Read corpus
      >>> loaded_corpus = MalletCorpus(output_fname)
class_docstr_tok: ["Corpus","handles","input","in","`","Mallet","format","<","http",":","\/\/mallet.cs.umass.edu\/import.php",">","`","_",".","*","*","Format","description","*","*","One","file",",","one","instance","per","line",",","assume","the","data","is","in","the","following","format",":",":","[","URL","]","[","language","]","[","text","of","the","page","...","]","Or",",","more","generally",",",":",":","[","document","#","1","id","]","[","label","]","[","text","of","the","document","...","]","[","document","#","2","id","]","[","label","]","[","text","of","the","document","...","]","...","[","document","#","N","id","]","[","label","]","[","text","of","the","document","...","]","Note","that","language\/label","is","*","not","*","considered","in","Gensim",",","used","`","__unknown__","`","as","default","value",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.test.utils","import","get_tmpfile",",","common_texts",">",">",">","from","gensim.corpora","import","MalletCorpus",">",">",">","from","gensim.corpora","import","Dictionary",">",">",">",">",">",">","#","Prepare","needed","data",">",">",">","dictionary","=","Dictionary","(","common_texts",")",">",">",">","corpus","=","[","dictionary.doc2bow","(","doc",")","for","doc","in","common_texts","]",">",">",">",">",">",">","#","Write","corpus","in","Mallet","format","to","disk",">",">",">","output_fname","=","get_tmpfile","(","``","corpus.mallet","''",")",">",">",">","MalletCorpus.serialize","(","output_fname",",","corpus",",","dictionary",")",">",">",">",">",">",">","#","Read","corpus",">",">",">","loaded_corpus","=","MalletCorpus","(","output_fname",")"]
docstr: Parameters
  ----------
  fname : str
      Path to file in Mallet 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`.
  metadata : bool, optional
      If True, return additional information ("document id" and "lang" when you call
      :meth:`~gensim.corpora.malletcorpus.MalletCorpus.line2doc`,
      :meth:`~gensim.corpora.malletcorpus.MalletCorpus.__iter__` or
      :meth:`~gensim.corpora.malletcorpus.MalletCorpus.docbyoffset`
docstr_tok: ["Parameters","--","--","--","--","--","fname",":","str","Path","to","file","in","Mallet","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","`",".","metadata",":","bool",",","optional","If","True",",","return","additional","information","(","``","document","id","''","and","``","lang","''","when","you","call",":","meth",":","`","~gensim.corpora.malletcorpus.MalletCorpus.line2doc","`",",",":","meth",":","`","~gensim.corpora.malletcorpus.MalletCorpus.__iter__","`","or",":","meth",":","`","~gensim.corpora.malletcorpus.MalletCorpus.docbyoffset","`"]
code: def __init__(self, fname, id2word=None, metadata=False):
      """
  
      Parameters
      ----------
      fname : str
          Path to file in Mallet 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`.
      metadata : bool, optional
          If True, return additional information ("document id" and "lang" when you call
          :meth:`~gensim.corpora.malletcorpus.MalletCorpus.line2doc`,
          :meth:`~gensim.corpora.malletcorpus.MalletCorpus.__iter__` or
          :meth:`~gensim.corpora.malletcorpus.MalletCorpus.docbyoffset`
  
      """
      self.metadata = metadata
      LowCorpus.__init__(self, fname, id2word)
  
file_path: gensim/gensim/corpora/malletcorpus.py
imports: from __future__ import with_statement
  import logging
  from gensim import utils
  from gensim.corpora import LowCorpus
label_desc: Use image node_id 1 to create a new MalletCorpus object from inherited base classes: LowCorpus with example: obj = MalletCorpus(fname, id2word, metadata)