Goblok is a Go library designed for filtering and analyzing profane words in Bahasa Indonesia. It provides functionalities to filter out profane words, add or remove words from the dictionary, and analyze text to detect profane content.
To use Goblok, import the package into your Go project:
go get github.com/drizki/goblok
import "github.com/drizki/goblok"
You can create a new instance of Goblok
with a custom dictionary of profane words:
// Create a Goblok instance with a custom dictionary
goblok := goblok.New([]string{"exampleProfaneWord1", "exampleProfaneWord2"})
If you don't provide a dictionary, Goblok will use the default set of profane words.
To add or remove profane words from the dictionary:
// Add a new profane word
wordAdded := goblok.Add("newProfaneWord")
fmt.Println("Added:", wordAdded)
// Remove a profane word
wordRemoved := goblok.Remove("existingProfaneWord")
fmt.Println("Removed:", wordRemoved)
Use the Filter
method to replace profane words with a mask character:
// Filter text, replacing profane words with asterisks
filteredText := goblok.Filter("This is a bad example.", '*')
fmt.Println("Filtered Text:", filteredText)
You can specify a different mask character if desired:
// Filter text with a custom mask character
filteredText := goblok.Filter("This is another bad example.", '#')
fmt.Println("Filtered Text:", filteredText)
The Analyze
method provides detailed information about profane words in the text:
// Analyze the text for profane words
analysis, err := goblok.Analyze("This is an example with bad words.")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Original Input:", analysis.Input)
fmt.Println("Filtered Text:", analysis.Filtered)
fmt.Println("Profane Words Detected:", analysis.Profane)
fmt.Println("Locations of Profane Words:", analysis.Locations)
To check if the input text contains any profane words:
// Check if the text contains profane words
containsProfanity := goblok.Contains("This text contains a bad word.")
fmt.Println("Contains Profanity:", containsProfanity)
New(dictionary ...[]string) *Goblok
- Creates a newGoblok
instance with an optional custom dictionary.Add(word string) string
- Adds a new profane word to the dictionary.Remove(word string) string
- Removes a profane word from the dictionary.Filter(input string, mask ...rune) string
- Filters the input text, replacing profane words with the specified mask character.Analyze(input string) (Analysis, error)
- Analyzes the input text and returns details about profane words and their locations.Contains(input string) bool
- Checks if the input text contains any profane words.
Input string
- The original input text.Profane []string
- List of profane words detected in the text.Filtered string
- The input text with profane words replaced by the mask character.Locations []Location
- Locations of profane words in the original text.
Word string
- The profane word.Index int
- The starting index of the profane word in the original text.
This library is open source and available under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.