add keywords utility example

This commit is contained in:
kevin
2020-08-19 17:58:57 +08:00
parent 22e75cdf78
commit 418f8f6666
5 changed files with 99 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
package main
import (
"fmt"
"github.com/tal-tech/go-zero/core/stringx"
)
func main() {
filter := stringx.NewTrie([]string{
"AV演员",
"苍井空",
"AV",
"日本AV女优",
"AV演员色情",
}, stringx.WithMask('?'))
safe, keywords, found := filter.Filter("日本AV演员兼电视、电影演员。苍井空AV女优是xx出道, 日本AV女优们最精彩的表演是AV演员色情表演")
fmt.Println(safe)
fmt.Println(keywords)
fmt.Println(found)
}

View File

@@ -0,0 +1,15 @@
package main
import (
"fmt"
"github.com/tal-tech/go-zero/core/stringx"
)
func main() {
replacer := stringx.NewReplacer(map[string]string{
"PHP": "PPT",
"世界上": "吹牛",
})
fmt.Println(replacer.Replace("PHP是世界上最好的语言"))
}