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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file magic_profanity-1.1.1.tar.gz.

File metadata

  • Download URL: magic_profanity-1.1.1.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.19

File hashes

Hashes for magic_profanity-1.1.1.tar.gz
Algorithm Hash digest
SHA256 e9263b188f32b31338edfdd87ea1c77f10065909efd0c81aa6a93249184f5729
MD5 46a842b490c62dccbf99ca58e4893d8e
BLAKE2b-256 3e328c907fbcbdeae79c824860b4e3ac5492190389863e6b8164142afc1c027c

See more details on using hashes here.

File details

Details for the file magic_profanity-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for magic_profanity-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 105feabc88bb6ff0ddb8ee2806629bca88d32ba1be37bba7730b0d4f203b92a7
MD5 eeac213cdf14d45c1a0a29679cf9c869
BLAKE2b-256 89d5bf5ce8ef76d3bc1b1116fc1102945a5c2968cd022791fd2288462546ebff

See more details on using hashes here.

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