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: Get number of documents.
  
  Returns
  -------
  int
      Number of documents in file.
docstr_tok: ["Get","number","of","documents",".","Returns","--","--","--","-","int","Number","of","documents","in","file","."]
code: def _calculate_num_docs(self):
      """Get number of documents.
  
      Returns
      -------
      int
          Number of documents in file.
  
      """
      with utils.open(self.fname, "rb") as fin:
          result = sum(1 for _ in fin)
      return result
  
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 2 for calling the MalletCorpus obj's underlying member method code with example usage: obj._calculate_num_docs() and returns: result