/go-wordsfilter

words filter

Primary LanguageGoMIT LicenseMIT

go-wordsfillter

Usage

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

trie.AddWords("dirtyword")
trie.AddWords("shit","bullshit")

Trie LoadNetWordDict

trie.LoadNetWordDict("http://xxxx.com/dict")

Trie Show

trie.Show() // will show all nodes by tree

Filter Filter

remove words

newText := filter.Filter("you bullshit")
// output => you

Filter Replace

replace words

newText := filter.Replace("you bullshit", '*')
// output => you ********

Filter FindIn

find and return first word

newText := filter.FindIn("you bullshit")
// output => true, bullshit

Filter Validate

validate and return first word

newText := filter.Validate("you bullshit")
// output => false, bullshit

Filter FindAll

find and return all words

newText := filter.FindAll("you bullshit")
// output => [bullshit]

Filter UpdateNoisePattern

set and update noise word

// failed
filter.FindIn("you bull-shit")      // false
filter.UpdateNoisePattern(`-`)
// success
filter.FindIn("you bull-shit")      // true, bullshit

Filter UpdateTrie

update trie

trie := wordsfillter.NewTrie()
trie.LoadWordDict("path/to/newDict")
filter.UpdateTrie(trie)

Filter RemoveNoise

remove noise word

filter.UpdateNoisePattern(`-`)
filter.RemoveNoise("you bull-shit")
// output => you bullshit