class_docstr: Makes text documents more readable by removing extra whitespaces, empty lines, specified substrings, regexes, page headers and footers (in this order).
  This is useful for preparing the documents for further processing by LLMs.
  
  Example usage in an indexing pipeline:
  
  ```python
  document_store = InMemoryDocumentStore()
  p = Pipeline()
  p.add_component(instance=TextFileToDocument(), name="text_file_converter")
  p.add_component(instance=DocumentCleaner(), name="cleaner")
  p.add_component(instance=TextDocumentSplitter(split_by="sentence", split_length=1), name="splitter")
  p.add_component(instance=DocumentWriter(document_store=document_store), name="writer")
  p.connect("text_file_converter.documents", "cleaner.documents")
  p.connect("cleaner.documents", "splitter.documents")
  p.connect("splitter.documents", "writer.documents")
  ```
class_docstr_tok: ["Makes","text","documents","more","readable","by","removing","extra","whitespaces",",","empty","lines",",","specified","substrings",",","regexes",",","page","headers","and","footers","(","in","this","order",")",".","This","is","useful","for","preparing","the","documents","for","further","processing","by","LLMs",".","Example","usage","in","an","indexing","pipeline",":","``","`","python","document_store","=","InMemoryDocumentStore","(",")","p","=","Pipeline","(",")","p.add_component","(","instance=TextFileToDocument","(",")",",","name=","''","text_file_converter","''",")","p.add_component","(","instance=DocumentCleaner","(",")",",","name=","''","cleaner","''",")","p.add_component","(","instance=TextDocumentSplitter","(","split_by=","''","sentence","''",",","split_length=1",")",",","name=","''","splitter","''",")","p.add_component","(","instance=DocumentWriter","(","document_store=document_store",")",",","name=","''","writer","''",")","p.connect","(","``","text_file_converter.documents","''",",","``","cleaner.documents","''",")","p.connect","(","``","cleaner.documents","''",",","``","splitter.documents","''",")","p.connect","(","``","splitter.documents","''",",","``","writer.documents","''",")","``","`"]
docstr: Return all ngrams of length n from a text sequence. Each ngram consists of n words split by whitespace.
  :param seq: The sequence to generate ngrams from.
  :param n: The length of the ngrams to generate.
  :return: A Generator generating all ngrams of length n from the given sequence.
docstr_tok: ["Return","all","ngrams","of","length","n","from","a","text","sequence",".","Each","ngram","consists","of","n","words","split","by","whitespace",".",":","param","seq",":","The","sequence","to","generate","ngrams","from",".",":","param","n",":","The","length","of","the","ngrams","to","generate",".",":","return",":","A","Generator","generating","all","ngrams","of","length","n","from","the","given","sequence","."]
code: def _ngram(self, seq: str, n: int) -> Generator[str, None, None]:
      """
      Return all ngrams of length n from a text sequence. Each ngram consists of n words split by whitespace.
      :param seq: The sequence to generate ngrams from.
      :param n: The length of the ngrams to generate.
      :return: A Generator generating all ngrams of length n from the given sequence.
      """
  
      # In order to maintain the original whitespace, but still consider \n and \t for n-gram tokenization,
      # we add a space here and remove it after creation of the ngrams again (see below)
      seq = seq.replace("\n", " \n")
      seq = seq.replace("\t", " \t")
  
      words = seq.split(" ")
      ngrams = (
          " ".join(words[i : i + n])
          .replace(" \n", "\n")
          .replace(" \t", "\t")
          for i in range(0, len(words) - n + 1)
      )
  
      return ngrams
  
file_path: haystack/haystack/components/preprocessors/document_cleaner.py
imports: import logging
  import re
  from copy import deepcopy
  from functools import partial, reduce
  from itertools import chain
  from typing import Generator, List, Optional, Set
  from haystack import Document, component
label_desc: Use image node_id 9 for calling the DocumentCleaner obj's underlying member method code with example usage: obj._ngram(seq, n) and returns: ngrams