Skip to content

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.

License

Notifications You must be signed in to change notification settings

kshired/ban-word-validator

Repository files navigation

Ban word validator

GitHub

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.

Installation

Gradle

dependencies {
    implementation 'io.github.kshired:ban-word-validator:0.1.1'
}

Gradle(kotlin)

dependencies {
    implementation("io.github.kshired:ban-word-validator:0.1.1")
}

Maven

<dependency>
    <groupId>io.github.kshired</groupId>
    <artifactId>ban-word-validator</artifactId>
    <version>0.1.1</version>
</dependency>

Usage

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
    }
}

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages