Simple Java ban word validation library with allowed words. By using ahocorasick algorithm, it can detect ban words in a text faster than a simple iteration.
This library is inspired by an article by woowabros.
dependencies {
implementation 'io.github.kshired:ban-word-validator:0.1.1'
}
dependencies {
implementation("io.github.kshired:ban-word-validator:0.1.1")
}
<dependency>
<groupId>io.github.kshired</groupId>
<artifactId>ban-word-validator</artifactId>
<version>0.1.1</version>
</dependency>
import com.kshired.banwordvalidator.BanWordValidator;
public class Main {
public static void main(String[] args) {
BanWordValidator banWordValidator = new BanWordValidator(
Set.of("ero"), // ban words
Set.of("hero") // allowed words
);
System.out.println(banWordValidator.validate("erotic").getDetectedBanWords().size); // 1
System.out.println(banWordValidator.validate("hero").getDetectedBanWords().size); // 0
}
}