docstr:  Class for easy construction of a term document matrix.
  This class let's you define an iterator for each document (text_iter),
  an iterator for each document's category name (category_iter),
  and a document cleaning function that's applied to each document
  before it's parsed.
  
  Parameters
  ----------
  category_text_iter : iter<str: category, unicode: document)>
      An iterator of pairs. The first element is a string category
      name, the second the text of a document.  You can also set this
      using the function set_category_text_iter.
  clean_function : function (default lambda x: x)
      A function that strips invalid characters out of a string, returning
      the new string.
  post_nlp_clean_function : function (default lambda x: x)
      A function that takes a spaCy Doc
  nlp : spacy.load('en_core_web_sm') (default None)
      The spaCy parser used to parse documents.  If it's None,
      the class will go through the expensive operation of
      creating one to parse the text
  feats_from_spacy_doc : FeatsFromSpacyDoc (default None)
      Class for extraction of features from spacy
  Attributes
  ----------
  _clean_function : Callable
      function that takes a unicode document and returns
      a cleaned version of that document
  _text_iter : iter<unicode>
      an iterator that iterates through the unicode text of each
       document
  _category_iter : iter<str>
      an iterator the same size as text iter that gives a string or
      unicode name of each document catgory
  Examples
  --------
  >>> import scattertext as ST
  >>> documents = [u'What art thou that usurp''st this time of night,',
  ...u'Together with that fair and warlike form',
  ...u'In which the majesty of buried Denmark',
  ...u'Did sometimes march? by heaven I charge thee, speak!',
    ...u'Halt! Who goes there?',
    ...u'[Intro]',
    ...u'It is I sire Tone from Brooklyn.',
    ...u'Well, speak up man what is it?',
    ...u'News from the East sire! THE BEST OF BOTH WORLDS HAS RETURNED!']
  >>> categories = ['hamlet'] * 4 + ['jay-z/r. kelly'] * 5
  >>> clean_function = lambda text: '' if text.startswith('[') else text
  >>> term_doc_mat = ST.TermDocMatrixFactory(category_text_iter = zip(categories, documents),clean_function = clean_function).build()
   
docstr_tok: ["Class","for","easy","construction","of","a","term","document","matrix",".","This","class","let","'s","you","define","an","iterator","for","each","document","(","text_iter",")",",","an","iterator","for","each","document","'s","category","name","(","category_iter",")",",","and","a","document","cleaning","function","that","'s","applied","to","each","document","before","it","'s","parsed",".","Parameters","--","--","--","--","--","category_text_iter",":","iter","<","str",":","category",",","unicode",":","document",")",">","An","iterator","of","pairs",".","The","first","element","is","a","string","category","name",",","the","second","the","text","of","a","document",".","You","can","also","set","this","using","the","function","set_category_text_iter",".","clean_function",":","function","(","default","lambda","x",":","x",")","A","function","that","strips","invalid","characters","out","of","a","string",",","returning","the","new","string",".","post_nlp_clean_function",":","function","(","default","lambda","x",":","x",")","A","function","that","takes","a","spaCy","Doc","nlp",":","spacy.load","(","'en_core_web_sm","'",")","(","default","None",")","The","spaCy","parser","used","to","parse","documents",".","If","it","'s","None",",","the","class","will","go","through","the","expensive","operation","of","creating","one","to","parse","the","text","feats_from_spacy_doc",":","FeatsFromSpacyDoc","(","default","None",")","Class","for","extraction","of","features","from","spacy","Attributes","--","--","--","--","--","_clean_function",":","Callable","function","that","takes","a","unicode","document","and","returns","a","cleaned","version","of","that","document","_text_iter",":","iter","<","unicode",">","an","iterator","that","iterates","through","the","unicode","text","of","each","document","_category_iter",":","iter","<","str",">","an","iterator","the","same","size","as","text","iter","that","gives","a","string","or","unicode","name","of","each","document","catgory","Examples","--","--","--","--",">",">",">","import","scattertext","as","ST",">",">",">","documents","=","[","u'What","art","thou","that","usurp","''","st","this","time","of","night",",","'",",","...","u'Together","with","that","fair","and","warlike","form","'",",","...","u'In","which","the","majesty","of","buried","Denmark","'",",","...","u'Did","sometimes","march","?","by","heaven","I","charge","thee",",","speak","!","'",",","...","u'Halt","!","Who","goes","there","?","'",",","...","u","'","[","Intro","]","'",",","...","u'It","is","I","sire","Tone","from","Brooklyn",".","'",",","...","u'Well",",","speak","up","man","what","is","it","?","'",",","...","u'News","from","the","East","sire","!","THE","BEST","OF","BOTH","WORLDS","HAS","RETURNED","!","'","]",">",">",">","categories","=","[","'hamlet","'","]","*","4","+","[","'jay-z\/r",".","kelly","'","]","*","5",">",">",">","clean_function","=","lambda","text",":","``","if","text.startswith","(","'","[","'",")","else","text",">",">",">","term_doc_mat","=","ST.TermDocMatrixFactory","(","category_text_iter","=","zip","(","categories",",","documents",")",",","clean_function","=","clean_function",")",".build","(",")"]
code: def __init__(
      self,
      category_text_iter=None,
      clean_function=lambda x: x,
      nlp=None,
      feats_from_spacy_doc=None,
  ):
      """
       Class for easy construction of a term document matrix.
      This class let's you define an iterator for each document (text_iter),
      an iterator for each document's category name (category_iter),
      and a document cleaning function that's applied to each document
      before it's parsed.
  
      Parameters
      ----------
      category_text_iter : iter<str: category, unicode: document)>
          An iterator of pairs. The first element is a string category
          name, the second the text of a document.  You can also set this
          using the function set_category_text_iter.
      clean_function : function (default lambda x: x)
          A function that strips invalid characters out of a string, returning
          the new string.
      post_nlp_clean_function : function (default lambda x: x)
          A function that takes a spaCy Doc
      nlp : spacy.load('en_core_web_sm') (default None)
          The spaCy parser used to parse documents.  If it's None,
          the class will go through the expensive operation of
          creating one to parse the text
      feats_from_spacy_doc : FeatsFromSpacyDoc (default None)
          Class for extraction of features from spacy
      Attributes
      ----------
      _clean_function : Callable
          function that takes a unicode document and returns
          a cleaned version of that document
      _text_iter : iter<unicode>
          an iterator that iterates through the unicode text of each
           document
      _category_iter : iter<str>
          an iterator the same size as text iter that gives a string or
          unicode name of each document catgory
      Examples
      --------
      >>> import scattertext as ST
      >>> documents = [u'What art thou that usurp''st this time of night,',
      ...u'Together with that fair and warlike form',
      ...u'In which the majesty of buried Denmark',
      ...u'Did sometimes march? by heaven I charge thee, speak!',
        ...u'Halt! Who goes there?',
        ...u'[Intro]',
        ...u'It is I sire Tone from Brooklyn.',
        ...u'Well, speak up man what is it?',
        ...u'News from the East sire! THE BEST OF BOTH WORLDS HAS RETURNED!']
      >>> categories = ['hamlet'] * 4 + ['jay-z/r. kelly'] * 5
      >>> clean_function = lambda text: '' if text.startswith('[') else text
      >>> term_doc_mat = ST.TermDocMatrixFactory(category_text_iter = zip(categories, documents),clean_function = clean_function).build()
      """
      self._category_text_iter = category_text_iter
      self._clean_function = clean_function
      self._nlp = nlp
      self._entity_types_to_censor = set()
      if feats_from_spacy_doc is None:
          self._feats_from_spacy_doc = FeatsFromSpacyDoc()
      else:
          self._feats_from_spacy_doc = feats_from_spacy_doc
  
imports: import string
  from collections import Counter
  import numpy
  import pandas
  from scattertext.CSRMatrixTools import CSRMatrixFactory
  from scattertext.TermDocMatrix import TermDocMatrix
  from scattertext.features.FeatsFromSpacyDoc import FeatsFromSpacyDoc
  from scattertext.indexstore.IndexStore import IndexStore
label_desc: Use image node_id 1 to create a new TermDocMatrixFactory object from inherited base classes: object with example: obj = TermDocMatrixFactory(category_text_iter, clean_function, nlp, feats_from_spacy_doc)