Persian Swear Censor is a Python script that censors offensive words in Persian text by replacing them with asterisks. The script reads a list of offensive words from a file, sorts them by length, and then replaces occurrences of these words in the input text.
- Load offensive words from a file
- Trim and sort words by length (longest to shortest)
- Replace offensive words in the input text with asterisks
- Handle file access errors gracefully
- Clone the repository:
git clone https://github.com/BaseMax/Persian-Swear-Censor.git
cd Persian-Swear-Censor
Ensure you have Python installed (version 3.6 or higher).
-
Create a file named
words.txt
in the project directory and add the offensive words you want to censor, one per line. -
Use the
censor_text
function in your Python script:
from persiansweercensor import censor_text
input_text = "Your input text here"
censored_text = censor_text(input_text)
print(censored_text)
Given the following words.txt file:
badword1
badword2
And the following input text:
input_text = "This is a badword1 and another badword2."
The output will be:
This is a ******* and another *******.
The script includes error handling to ensure that the file exists and is accessible. If the file is not found or cannot be read, an appropriate error message will be printed, and the original input text will be returned.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or suggestions, feel free to open an issue or contact the repository owner.
Copyright 2024, Max Base