mirror of
https://github.com/xxjwxc/public.git
synced 2025-09-26 11:51:14 +08:00
1
This commit is contained in:
@@ -83,7 +83,7 @@ loop:
|
||||
words = root
|
||||
i = e
|
||||
// Maximum Matching Principle, Matching Backwards First
|
||||
for ; i < l; i ++ {
|
||||
for ; i < l; i++ {
|
||||
word := string(textr[i])
|
||||
if n, ok := words[word]; ok {
|
||||
back = append(back, n)
|
||||
@@ -136,20 +136,31 @@ func (node *Node) contains(text string, root map[string]*Node) bool {
|
||||
if root == nil || text == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
point := root
|
||||
index := 0
|
||||
jump := false
|
||||
textr := []rune(text)
|
||||
end := len(textr) - 1
|
||||
for i := 0; i <= end; i++ {
|
||||
word := string(textr[i])
|
||||
if n, ok := root[word]; ok {
|
||||
if n, ok := point[word]; ok {
|
||||
if i == end {
|
||||
return n.Placeholders != ""
|
||||
} else {
|
||||
if len(n.Child) == 0 { // last
|
||||
return true
|
||||
}
|
||||
root = n.Child
|
||||
point = n.Child
|
||||
index = i
|
||||
jump = true
|
||||
}
|
||||
} else {
|
||||
if jump {
|
||||
point = root //重头来
|
||||
i = index
|
||||
jump = false
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@@ -6,15 +6,17 @@ import (
|
||||
|
||||
func TestWordsFilter(t *testing.T) {
|
||||
texts := []string{
|
||||
"Miyamoto Musashi",
|
||||
"妲己",
|
||||
"アンジェラ",
|
||||
"爱女人",
|
||||
"爱液",
|
||||
"你他妈",
|
||||
"ความรุ่งโรจน์",
|
||||
}
|
||||
wf := New()
|
||||
// wf.StripSpace = false
|
||||
// wf.Placeholder = ""
|
||||
root := wf.Generate(texts)
|
||||
wf.Remove("shif", root)
|
||||
c1 := wf.Contains("アン", root) // 是否有敏感词
|
||||
c1 := wf.Contains("你爱液", root) // 是否有敏感词
|
||||
if c1 != false {
|
||||
t.Errorf("Test Contains expect false, get %T, %v", c1, c1)
|
||||
}
|
||||
|
Reference in New Issue
Block a user