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_MAPPINGandALLOWED_CHARACTERS.
Structs§
- CharSet
- A set of characters, such as
ALLOWED_CHARACTERS, and which of them are whitespace to Python’sstr.strip(). - Config
- What
_hide_swear_wordsreads 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_WORDSETfor all of them at once. - Word
SetBuilder - Builds a
WordSetfrom 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
textas better_profanity’s_hide_swear_words(text, censor_char)does.