clean_text_rhoni

Submodules

Package Contents

Classes

BaseCleanText

A utility class to clean and manipulate text

Functions

clean_text(text)

Perform a complete text cleaning process on the input text.

clean_text_snake_case(text)

Perform a complete text cleaning process on the input text and transform it to snake case

Attributes

__version__

clean_text_rhoni.__version__
class clean_text_rhoni.BaseCleanText[source]

A utility class to clean and manipulate text

transform_to_lowercase(text)[source]

Convert the input text to lowercase.

Examples

>>> transform_to_lowercase("Hello World")
"hello world"
remove_leading_trailing_spaces(text)[source]

Remove leading and trailing whitespaces from the input text.

Examples

>>> remove_leading_trailing_spaces("  hello world  ")
"hello world"
replace_multiple_spaces(text)[source]

Remove multiple spaces in the input text and replace them with a single space.

Examples

>>> replace_multiple_spaces("hello   world")
"hello world"
remove_special_characters(text)[source]

Remove special characters from the input text.

Examples

>>> remove_special_characters("Hola! cómo estás?")
"Hola cómo estás"

Notes

Special characters are characters that are neither word characters (alphanumeric and underscore) nor whitespace characters.

remove_accents(text)[source]

Remove accents from vowels in the input text.

Examples

>>> remove_accents("café")
"cafe"
remove_n_tilde(text)[source]

Remove the tilde from the n in the input text.

Examples

>>> remove_n_tilde("mañana")
"manana"
replace_spaces_by_underscores(text)[source]

Replace spaces with underscores in the input text.

Examples

>>> replace_spaces_by_underscores("hello world")
"hello_world"
replace_underscores_by_spaces(text)[source]

Replace underscores with spaces in the input text.

Examples

>>> replace_underscores_by_spaces("hello_world")
"hello world"
clean_text_rhoni.clean_text(text)[source]

Perform a complete text cleaning process on the input text.

This function performs a series of text cleaning operations, including: 1. Removing leading and trailing spaces. 2. Removing multiple spaces and replacing them with a single space. 3. Converting the text to lowercase. 4. Removing accents from vowels. 5. Removing special characters. 6. Removing tilde from ñ.

Parameters:

text (str) – The input text to be cleaned.

Returns:

text – The cleaned text after applying all cleaning operations.

Return type:

str

Examples

>>> clean_text("   Hola Sofía!,   cómo estás?   ")
"hola sofia como estas"
clean_text_rhoni.clean_text_snake_case(text)[source]

Perform a complete text cleaning process on the input text and transform it to snake case

This function performs a series of text cleaning operations, including: 1. Removing leading and trailing space. 2. Removing multiple spaces and replacing them with a single space. 3. Converting the text to lowercase. 4. Removing accents from vowels. 5. Removing special characters. 6. Removing tilde from ñ. 7. Replacing spaces by underscores

Parameters:

text (str) – The input text to be cleaned.

Returns:

text – The cleaned text after applying all cleaning operations.

Return type:

str

Examples

>>> clean_text("   Hola Sofía!,   cómo estás?   ")
"hola_sofia_como_estas"