ProfanityCheckerAPI
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.
Requirements
- Java 11+
- Python 3.8+
- jep (
pip install jep
)- Make sure your library paths are set correctly once you've installed it, as this isn't always the case, particularly on Windows.
- If you get an "Unsatisfied Link" error, check here for solutions.
- alt-profanity-check (
pip install alt-profanity-check
)
Maven
ProfanityCheckerAPI is available from Jitpack.io. You can also view the javadocs there.
Add the repository
<repositories>
<repository>
<id>jitpack.ioid>
<url>https://jitpack.iourl>
repository>
repositories>
Add the dependency
<dependency>
<groupId>com.github.WiIIiam278groupId>
<artifactId>ProfanityCheckerAPIartifactId>
<version>1.1version>
<scope>compilescope>
dependency>
Usage
Create an instance of the ProfanityChecker
class to get started. It is recommended that you handle these operations on a separate thread from the main thread as jep can be an expensive blocking operation.
You can then simply get if text is profane using the #isTextProfane(String)
method. Alternatively, you can return a probability double (0 to 1 inclusive) of how likely the machine learning algorithm thinks the text contains profanity using the #getTextProfanityLikelihood(String)
method.
You should not make more than one instance of ProfanityChecker
on the same thread, as this can result in an exception from jep. Once you are done with a ProfanityChecker, you can safely dispose of it using the #dispose
method.
Javadocs for ProfanityCheckerAPI are available here.