File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1
1
- [ text 模块] ( #text-模块 )
2
2
- [ SliceSame] ( #slicesame )
3
+ - [ Kmp 文本匹配] ( #kmp-文本匹配 )
3
4
- [ Aho-Corasick automaton] ( #aho-corasick-automaton )
4
5
- [ 计算文本编辑距离] ( #计算文本编辑距离 )
5
6
- [ 计算文本相似度] ( #计算文本相似度 )
@@ -29,6 +30,39 @@ func TestSliceSmae(t *testing.T) {
29
30
}
30
31
```
31
32
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
+
32
66
## Aho-Corasick automaton
33
67
ac 自动机是一种多模式串的匹配算法。
34
68
You can’t perform that action at this time.
0 commit comments