Skip to content

Commit 24974b8

Browse files
author
willzhen
committed
Update readme
1 parent 735459b commit 24974b8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

readme.md

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- [text 模块](#text-模块)
22
- [SliceSame](#slicesame)
3+
- [Kmp 文本匹配](#kmp-文本匹配)
34
- [Aho-Corasick automaton](#aho-corasick-automaton)
45
- [计算文本编辑距离](#计算文本编辑距离)
56
- [计算文本相似度](#计算文本相似度)
@@ -29,6 +30,39 @@ func TestSliceSmae(t *testing.T) {
2930
}
3031
```
3132

33+
## Kmp 文本匹配
34+
通过编辑距离,计算两个文本的相似度。
35+
36+
example: [TestTextSim](https://github.com/memory-overflow/go-text-algorithm/blob/main/text_test.go#L37)
37+
```go
38+
import (
39+
"testing"
40+
41+
"github.com/memory-overflow/go-text-algorithm"
42+
)
43+
44+
func TestKmp(t *testing.T) {
45+
k := textalg.BuildKmp("a")
46+
indexs := k.Search("aaaaab") // find "a" in "aaaaab"
47+
t.Log(indexs)
48+
k.AppendPatternStr("a")
49+
indexs = k.Search("aaaaab") // find "aa" in "aaaaab"
50+
t.Log(indexs)
51+
k.AppendPatternStr("a")
52+
indexs = k.Search("aaaaab") // find "aaa" in "aaaaab"
53+
t.Log(indexs)
54+
k.AppendPatternStr("b")
55+
indexs = k.Search("aaaaab") // find "aaab" in "aaaaab"
56+
t.Log(indexs)
57+
k.AppendPatternStr("b")
58+
indexs = k.Search("aaaaab") // find "aaabb" in "aaaaab"
59+
t.Log(indexs)
60+
k.ResetPatternStr("ab")
61+
indexs = k.Search("aaaaab") // find "ab" in "aaaaab"
62+
t.Log(indexs)
63+
}
64+
```
65+
3266
## Aho-Corasick automaton
3367
ac 自动机是一种多模式串的匹配算法。
3468

0 commit comments

Comments
 (0)