Java API for checking profanity via the alt-profanity-checker python library
MIT License
ProfanityCheckerAPI is a Java API for checking if text contains profanity via the alt-profanity-checker Python library. It uses jep to run and interpret Python script to do this.
pip install jep
)
pip install alt-profanity-check
)ProfanityCheckerAPI is available from Jitpack.io. You can also view the javadocs there.
To use the library with Maven, first add the jitpack repository to your pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then, add the dependency in your <dependencies>
section.
<dependency>
<groupId>net.william278</groupId>
<artifactId>ProfanityCheckerAPI</artifactId>
<version>2.0.1</version>
<scope>compile</scope>
</dependency>
JitPack has a handy guide for how to use the dependency with other build platforms.
First of all, make sure the environment you're deploying your application on has Python v3.8+ with jep
and alt-profanity-check
installed on, and ensure jep's library is in your application's classpath (i.e. by setting LD_LIBRARY_PATH on Linux).
Get a ProfanityCheckerBuilder
using ProfanityChecker#builder()
. You can configure the checker to either automatically determine if text is profane (set by default) or specify a threshold double value withThreshold(double)
to check against. You can additionally specify which normalizers to use. Normalizers adapt the provided string against common bypass techniques, such as leet speak (by default, all normalizers are used). When you've configured the builder, invoke #build()
to get a ProfanityChecker instance.
With the instance, simply use the #isProfane(String)
against a string. When you're done with the checker, close it with (#close
) to dispose of the jep runner instance, or use it in a try-with resources statement.
// This will return true if the message contains profanity exceeding a threshold of 0.8
public static boolean isMessageProfane(String message) {
try (ProfanityChecker checker = ProfanityChecker.builder().withThreshold(0.8d).build()) {
return checker.isProfane(message);
}
}
To build ProfanityCheckerAPI, ensure Python v3.8+, jep
and alt-profanity-check
(as well as any dependencies) are installed on your machine, then run the following in the root of the repository:
./gradlew clean build
ProfanityCheckerAPI is licensed under MIT License.
© William278, 2022–2024. Licensed under the MIT License.