Class OffensiveWordFilter
java.lang.Object
dev.getelements.elements.sdk.util.OffensiveWordFilter
Placeholder class for offensive word filtering functionality. This includes words that are considered offensive,
hateful, or would be inappropriate in automatically generated unique codes. This loads a list of such words from
a properties file and provides methods to check and filter them as needed.
The line of the properties file should contain one offensive word per line, with the value of the property being
the permitted edit distance for that word. We provide a builtin set of bad words for English, but additional
languages and custom bad word lists can be provided by overriding the default properties file or suppying an
instance of
Properties when initializing the filter.
For example:
BADWORD=1 means "BADWORD" is offensive, and any word within an edit distance of 1 from "BADWORD" is also considered
offensive. This could include "BADWRD", "BADWOR", "BADWORDX", etc.
The default properties file is included on the classpath and can be loaded using the Builder's
OffensiveWordFilter.Builder.addDefaultWords() method. The built-in file contains a basic set of words tht are commonly
considered hate speed in English. In addition to hate speech, it includes words that while not exactly hate speed
could be considered vulgar, awkward, or inappropriate in certain contexts.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructing an OffensiveWordFilter with a list of offensive words.static final recordConfiguration for the OffensiveWordFilter.static final recordRepresents an offensive word and its associated edit distance. -
Constructor Summary
ConstructorsConstructorDescriptionOffensiveWordFilter(OffensiveWordFilter.Configuration configuration) Creates a new OffensiveWordFilter with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionReturns the configuration of this OffensiveWordFilter.booleanisOffensive(CharSequence input) Returns true if the input contains any offensive words or their variants based on the defined edit distances.
-
Constructor Details
-
OffensiveWordFilter
Creates a new OffensiveWordFilter with the given configuration.- Parameters:
configuration- the configuration
-
-
Method Details
-
isOffensive
Returns true if the input contains any offensive words or their variants based on the defined edit distances.- Parameters:
input- the input CharSequence to check- Returns:
- true if offensive words are found, false otherwise
-
getConfiguration
Returns the configuration of this OffensiveWordFilter.- Returns:
- the configuration
-