package main
import (
"fmt"
"github.com/lockp111/go-wordsfillter"
)
func main() {
trie := wordsfillter.NewTrie()
trie.LoadWordDict("path/to/dict")
filter := wordsfillter.New(trie)
// do something
}
trie.AddWords("dirtyword")
trie.AddWords("shit","bullshit")
trie.LoadNetWordDict("http://xxxx.com/dict")
trie.Show() // will show all nodes by tree
remove words
newText := filter.Filter("you bullshit")
// output => you
replace words
newText := filter.Replace("you bullshit", '*')
// output => you ********
find and return first word
newText := filter.FindIn("you bullshit")
// output => true, bullshit
validate and return first word
newText := filter.Validate("you bullshit")
// output => false, bullshit
find and return all words
newText := filter.FindAll("you bullshit")
// output => [bullshit]
set and update noise word
// failed
filter.FindIn("you bull-shit") // false
filter.UpdateNoisePattern(`-`)
// success
filter.FindIn("you bull-shit") // true, bullshit
update trie
trie := wordsfillter.NewTrie()
trie.LoadWordDict("path/to/newDict")
filter.UpdateTrie(trie)
remove noise word
filter.UpdateNoisePattern(`-`)
filter.RemoveNoise("you bull-shit")
// output => you bullshit