A Python library for detecting and censoring profanity in text
Project description
Magic Profanity
magic_profanity
is a Python library for detecting and censoring profanity in text using customizable word lists and character mappings. It support English and Hinglish
Installation
You can install magic_profanity
using pip:
pip install ProfanityFilter
Requirements
Python 3+
Usage
Importing the Library
from magic_profanity import ProfanityFilter
Initializing the Profanity Filter
Create an instance of MagicProfanity:
profanity_filter = ProfanityFilter()
Loading Custom Words
You can load custom words into the profanity filter either from a list or from a file:
Load words from a list
profanity_filter.load_words(["badword1", "badword2"])
Load words from a file
profanity_filter.load_words_from_file("path/to/custom_wordlist.txt")
Load Custom Words
Only accepts list, tuple, or set.
profanity_filter.add_custom_words(["badword1", "badword2"])
Checking for Profanity You can check if a text contains profanity using contains_profanity:
text = "This sentence contains a badword1 and a BadWord2."
if profanity_filter.has_profanity(text):
print("Profanity detected!")
else:
print("No profanity found.")
Censoring Text
You can censor profanity in text using censor:
censored_text = profanity_filter.censor_text(text)
print(censored_text)
Adding Custom Words
You can add custom words to the profanity filter:
profanity_filter.add_censor_words(["newbadword1", "newbadword2"])
Custom Character Mappings
You can customize character mappings used for censoring:
profanity_filter.char_map = {
"a": ("a", "@", "*", "4"),
"i": ("i", "*", "l", "1"),
"o": ("o", "*", "0", "@"),
# Add more mappings as needed
}
#Contributing Contributions are welcome! If you have any suggestions, bug reports, or enhancements, please open an issue or a pull request on GitHub.
#License This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for magic_profanity-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 293fd66df2914b30ee1e812a91752396769a12184d9488361104a05045081d7d |
|
MD5 | 6a70ca2aac0bba6b1925eeab9b3f5060 |
|
BLAKE2b-256 | 719600a62a4980c03e53fbd22d685d03a3f30fd9c5c690a5e9e5f657d8fe707f |