MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / clean_text_data

Method clean_text_data

camel/loaders/unstructured_io.py:191–291  ·  view source on GitHub ↗

r"""Cleans text data using a variety of cleaning functions provided by the `unstructured` library. This function applies multiple text cleaning utilities by calling the `unstructured` library's cleaning bricks for operations like replacing Unicode quotes, removing ex

(
        text: str,
        clean_options: Optional[List[Tuple[str, Dict[str, Any]]]] = None,
    )

Source from the content-addressed store, hash-verified

189
190 @staticmethod
191 def clean_text_data(
192 text: str,
193 clean_options: Optional[List[Tuple[str, Dict[str, Any]]]] = None,
194 ) -> str:
195 r"""Cleans text data using a variety of cleaning functions provided by
196 the `unstructured` library.
197
198 This function applies multiple text cleaning utilities by calling the
199 `unstructured` library's cleaning bricks for operations like
200 replacing Unicode quotes, removing extra whitespace, dashes, non-ascii
201 characters, and more.
202
203 If no cleaning options are provided, a default set of cleaning
204 operations is applied. These defaults including operations
205 "replace_unicode_quotes", "clean_non_ascii_chars",
206 "group_broken_paragraphs", and "clean_extra_whitespace".
207
208 Args:
209 text (str): The text to be cleaned.
210 clean_options (dict): A dictionary specifying which cleaning
211 options to apply. The keys should match the names of the
212 cleaning functions, and the values should be dictionaries
213 containing the parameters for each function. Supported types:
214 'clean_extra_whitespace', 'clean_bullets',
215 'clean_ordered_bullets', 'clean_postfix', 'clean_prefix',
216 'clean_dashes', 'clean_trailing_punctuation',
217 'clean_non_ascii_chars', 'group_broken_paragraphs',
218 'remove_punctuation', 'replace_unicode_quotes',
219 'bytes_string_to_string', 'translate_text'.
220
221 Returns:
222 str: The cleaned text.
223
224 Raises:
225 AttributeError: If a cleaning option does not correspond to a
226 valid cleaning function in `unstructured`.
227
228 Notes:
229 The 'options' dictionary keys must correspond to valid cleaning
230 brick names from the `unstructured` library.
231 Each brick's parameters must be provided in a nested dictionary
232 as the value for the key.
233
234 References:
235 https://unstructured-io.github.io/unstructured/
236 """
237
238 from unstructured.cleaners.core import (
239 bytes_string_to_string,
240 clean_bullets,
241 clean_dashes,
242 clean_extra_whitespace,
243 clean_non_ascii_chars,
244 clean_ordered_bullets,
245 clean_postfix,
246 clean_prefix,
247 clean_trailing_punctuation,
248 group_broken_paragraphs,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected