slaviclean
SlaviCleaner is a profanity filtering library designed for cleaning text from offensive language, specifically tailored for Ukrainian and Russian languages. It detects, masks, and reports offensive words while providing different levels of filtering.
This module uses spaCy for natural language processing and employs advanced techniques for detecting profanities, including handling obfuscated words, variants of swear words, and morphology forms.
Features
- Detects and masks offensive words in slavic languages (Ukrainian, Russian).
- Handles obfuscated, substituted, and morphologically varied forms of profanity.
- Provides detailed reporting of profanities detected, including the type of relationship (e.g., euphemism, vulgar, loanword).
- Allows the customization of filtering level with three options:
complete,basic,minimal. - Offers support for subtree-level profanity filtering.
- Handles masked and obfuscated profanity patterns effectively.
Installation
To install SlaviCleaner, run:
pip install slaviclean
Usage
Initializing
from slaviclean import SlaviCleaner
scleaner = SlaviCleaner()
Initializing with preloads
You can preload the necessary language models for faster processing.
The preload option loads the models for the supported languages (uk, ru, surzhyk).
from slaviclean import SlaviCleaner
scleaner = SlaviCleaner(preload=True)
Core Functions
get_available_languages()
Retrieves a set of languages supported by the profanity filter.
-
Returns:
- A set of language codes (e.g.,
{'uk', 'ru', 'surzhyk'}).
- A set of language codes (e.g.,
-
Example:
from slaviclean import SlaviCleaner
scleaner = SlaviCleaner(preload=True)
languages = scleaner.get_available_languages()
print(languages)
# Output: {'uk', 'ru', 'surzhyk'}
sanitize(message, lang, min_subtree_size, mask_symbol, slevel, analyze_morph)
Filters profanities from the given message and returns a detailed report.
-
Arguments:
message(str): The input message to filter.lang(str): The language of the message (supports'uk','ru', and'surzhyk', default is'surzhyk').min_subtree_size(float): Minimum size of the token subtree for dependency parsing (default is3).mask_symbol(str): Symbol used to mask profanities (default is'*').slevel(str): Severity level of filtering (can be'complete','basic', or'minimal', default is'complete').analyze_morph(bool): Whether to analyze the morphology of words (default isFalse).
-
Returns:
- A
SanitizeReportcontaining the masked message and list of detected profanities.
- A
-
Example:
from slaviclean import SlaviCleaner
scleaner = SlaviCleaner(preload=True)
message = "От же ж, к у р в а, страхуй, бо об’ївся г***м супом, облив себе соком, ще й сумка, су4k@, відірвалась"
sanitize_report = scleaner.sanitize(message, lang='uk')
print(sanitize_report)
# Output:
# SanitizeReport(
# message='От же ж, курва, страхуй, бо об’ївся г***м супом, облив себе соком, ще й сумка, су4k@, відірвалась',
# masked_message='От же ж, *****, страхуй, бо об’ївся ***** супом, облив себе соком, ще й сумка, *****, відірвалась',
# profanities=[
# Profanity(span=(9, 14), nearest='курва', tags=['vulgar', 'euphemism', 'loanword']),
# Profanity(span=(36, 41), nearest='г***м', tags=['masked']),
# Profanity(span=(79, 84), nearest='сучка', tags=['insulting', 'slur', 'vulgar'])])
Available Severity Levels
complete
Cleans all profanities, including euphemisms, vulgarities, and loanwords.basic
Cleans more aggressive profanity, without including euphemisms.minimal
Only cleans the most offensive words.
Supported Languages
SlaviCleaner currently supports the following languages:
- Ukrainian (
uk) - Russian (
ru) - Surzhyk (
surzhyk)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- The spaCy library is used for NLP tasks like tokenization, part-of-speech tagging, and dependency parsing.
- The pymorphy3 library is used for morphological analysis.
Release files for slaviclean 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| slaviclean-0.1.1.tar.gz | 287.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| slaviclean-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 584.1 kB
Release files / slaviclean-0.1.1.tar.gz
| Download URL | slaviclean-0.1.1.tar.gz |
|---|---|
| Size | 287.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
843b68f997d3926d344c281f21e883ec650c2048b0a66796abbec8ad8ed91e67
|
|
BLAKE2b-256 checksum How to use checksums |
5f3f6d3d780237de99be12e4ec0a632f85724ae8b8fbac035d06e9f7f67ca691
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.10
|
Release files / slaviclean-0.1.1-py3-none-any.whl
| Download URL | slaviclean-0.1.1-py3-none-any.whl |
|---|---|
| Size | 296.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ea841baffc22d9a92ce924d2ab9349a1544baed2b7eeb3f5c695ed72c845eb4
|
|
BLAKE2b-256 checksum How to use checksums |
7814612adae63406bb29e355460eff2426700dfb5d62f0a0261a7b6a816a1078
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.10
|