Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magic_profanity-1.1.1.tar.gz (26.8 kB view hashes)

Uploaded Source

Built Distribution

magic_profanity-1.1.1-py3-none-any.whl (43.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page