This tool helps identify and censor profanity with high accuracy. It supports multiple languages and can be used in various scenarios, such as chats, social networks, and more.
pip3 install censoreFirst, initialize the ProfanityFilter class:
from censore import ProfanityFilter
pf = ProfanityFilter()By default ProfanityFilter will be initialized with all available languages
If you want to process the text only in certain languages, it is recommended to manually configure the list of languages ββto be checked, this will greatly speed up the text processing:
from censore import ProfanityFilter
pf = ProfanityFilter(languages=['en', 'uk'])You can add custom patterns of offensive words if they are not present:
pf = ProfanityFilter(custom_patterns=["bad"])
text = "This is a very bad text, let's say 'baddest'"
pf.censor(text)
# 'This is a very ### text, let we say '#######''As you can see it also censored the word "baddest" because it contains "bad"
But if you don't want it to censor that word, you can use the custom_exclude_patterns parameter:
pf = ProfanityFilter(custom_patterns=["bad"], custom_exclude_patterns=["baddest"])
text = "This is a very bad text, let we say 'baddest'"
pf.censor(text)
# 'This is a very ### text, let we say 'baddest''It will use only English (en) and Ukrainian (uk) languages
The contains_profanity method checks if the text contains obscene language:
text = "This is a fucking bad text"
pf.contains_profanity(text)
# TrueThe censor method replaces obscene language with hashes (#):
text = "This is a fucking bad text"
pf.censor(text)
# 'This is a ####### bad text'You can also partially censor text using the partial_censor option:
pf.censor(text, partial_censor=True)
# 'This is a fu###ng bad text'You can replace the hashes with any symbol, such as a monkey emoji π:
pf.censor(text, censor_symbol="π")
# 'This is a πππππππ bad text'It may be that you initialized only English and Ukrainian, but at some point you need to use Polish, for this you can use the languages parameter:
text = "This is a kurwa Π±Π»ΡΡΡ bad text"
pf.censor(text, languages=['en', 'uk', 'pl'])
# 'This is a ##### ##### bad text'It automatically initialized and loaded the Polish language into the list of languages and successfully censored everything, but don't you want to enter the list of languages ββyou want to use every time?
To simplify this, use the additional_languages option:
pf.censor(text, additional_languages=['pl'])
# 'This is a ##### ##### bad text'It has now added Polish to all initialized languages ββand now we don't need to enter the full list of languages
This method censors any word
pf.censor_word("anyword")
# '###'You can also partially censor text using the partial_censor option:
pf.censor_word("anyword", partial_censor=True)
# 'an###rd'Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Telegram - @okineadev