Skip to content

Commit

Permalink
update stringx doc
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Aug 19, 2020
1 parent 2607bb8 commit a1b990c
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions doc/keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PPT是吹牛最好的语言!

示例代码见`example/stringx/replace/replace.go`

## 3. 敏感词过滤
## 3. 查找敏感词

```go
filter := stringx.NewTrie([]string{
Expand All @@ -34,7 +34,27 @@ filter := stringx.NewTrie([]string{
"AV",
"日本AV女优",
"AV演员色情",
}, stringx.WithMask('?'))
})
keywords := filter.FindKeywords("日本AV演员兼电视、电影演员。苍井空AV女优是xx出道, 日本AV女优们最精彩的表演是AV演员色情表演")
fmt.Println(keywords)
```

可以得到:

```
[苍井空 日本AV女优 AV演员色情 AV AV演员]
```

## 4. 敏感词过滤

```go
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)
Expand All @@ -51,7 +71,7 @@ true

示例代码见`example/stringx/filter/filter.go`

## 4. Benchmark
## 5. Benchmark

| Sentences | Keywords | Regex | Go-Zero |
|-----------|----------|----------|----------|
Expand Down

0 comments on commit a1b990c

Please sign in to comment.