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: Run the DocumentCleaner on the given list of documents.
  The documents' metadata remain unchanged.
docstr_tok: ["Run","the","DocumentCleaner","on","the","given","list","of","documents",".","The","documents","'","metadata","remain","unchanged","."]
code: def run(self, documents: List[Document]):
      """
      Run the DocumentCleaner on the given list of documents.
      The documents' metadata remain unchanged.
      """
      if (
          not isinstance(documents, list)
          or documents
          and not isinstance(documents[0], Document)
      ):
          raise TypeError(
              "DocumentCleaner expects a List of Documents as input."
          )
  
      cleaned_docs = []
      for doc in documents:
          if doc.content is None:
              logger.warning(
                  "DocumentCleaner only cleans text documents but document.content for document ID %s is None.",
                  doc.id,
              )
              cleaned_docs.append(doc)
              continue
          text = doc.content
  
          if self.remove_extra_whitespaces:
              text = self._remove_extra_whitespaces(text)
          if self.remove_empty_lines:
              text = self._remove_empty_lines(text)
          if self.remove_substrings:
              text = self._remove_substrings(
                  text, self.remove_substrings
              )
          if self.remove_regex:
              text = self._remove_regex(text, self.remove_regex)
          if self.remove_repeated_substrings:
              text = self._remove_repeated_substrings(text)
  
          cleaned_docs.append(
              Document(content=text, meta=deepcopy(doc.meta))
          )
  
      return {"documents": cleaned_docs}
  
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 2 for calling the DocumentCleaner obj's underlying member method code with example usage: obj.run(documents) and returns: dict