Skip to main content

Crate better_profanity

Crate better_profanity 

Source
Expand description

A port of the Python word filter better_profanity 0.7.0 that censors exactly the same words, including their leetspeak spellings and words split by separators (f.u.c.k, H4nd j0b), and leaves every other character of the text as it was.

use better_profanity::Profanity;

let profanity = Profanity::new();
assert_eq!(
    profanity.censor("That wh0re gave m3 a very good H@nD j0b.", "*"),
    "That **** gave m3 a very good ****."
);
assert!(!profanity.contains_profanity("Hello there"));

Profanity follows better_profanity’s Profanity class. The lower-level hide_swear_words, WordSet and CharSet reproduce its algorithm with any word set, separator set and lowercasing; the Python package better-profanity-rs uses them to match the interpreter it runs on.

Modules§

data
The data of better_profanity 0.7.0: its word list, CHARS_MAPPING and ALLOWED_CHARACTERS.

Structs§

CharSet
A set of characters, such as ALLOWED_CHARACTERS, and which of them are whitespace to Python’s str.strip().
Config
What _hide_swear_words reads besides its arguments.
Profanity
better_profanity’s Profanity: a list of words to censor and how to match them.
SetId
A character set interned by a WordSetBuilder.
StdLowercase
Lowercasing with Rust’s Unicode tables, which apply the same rules as Python.
Walk
The trie nodes reached by the characters fed so far.
WordSet
The words to censor, answering string in CENSOR_WORDSET for all of them at once.
WordSetBuilder
Builds a WordSet from words given as sequences of character sets.

Traits§

Lowercase
Python’s str.lower() for strings with at least one non-ASCII character.

Functions§

hide_swear_words
Censors text as better_profanity’s _hide_swear_words(text, censor_char) does.