code: def build_from_category_whitespace_delimited_text(category_text_iter):
      """
  
      Parameters
      ----------
      category_text_iter iterator of (string category name, one line per sentence, whitespace-delimited text) pairs
  
      Returns
      -------
      TermDocMatrix
      """
      y = []
      X_factory = CSRMatrixFactory()
      term_idx_store = IndexStore()
      category_idx_store = IndexStore()
      mX_factory = CSRMatrixFactory()
      for doci, (category, text) in enumerate(category_text_iter):
          y.append(category_idx_store.getidx(category))
          term_freq = Counter()
          for sent in (
              text.strip(string.punctuation).lower().split("\n")
          ):
              unigrams = []
              for tok in sent.strip().split():
                  unigrams.append(tok)
              bigrams = list(
                  map(" ".join, zip(unigrams[:-1], unigrams[1:]))
              )
              for term in unigrams + bigrams:
                  term_freq[term_idx_store.getidx(term)] += 1
          for word_idx, freq in term_freq.items():
              X_factory[doci, word_idx] = freq
      metadata_idx_store = IndexStore()
      return TermDocMatrix(
          X=X_factory.get_csr_matrix(),
          mX=mX_factory.get_csr_matrix(),
          y=np.array(y),
          term_idx_store=term_idx_store,
          metadata_idx_store=metadata_idx_store,
          category_idx_store=category_idx_store,
      )
  
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 for calling a global function with example usage: build_from_category_whitespace_delimited_text(category_text_iter) and returns: TermDocMatrix