Skip to content

Commit

Permalink
refactor trie
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky committed Aug 24, 2023
1 parent aabfeb7 commit d514e45
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions sensitive/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"github.com/Tohrusky/sensitive-go/sdict"
"github.com/Tohrusky/sensitive-go/sensitive/trie"
"io"
"net/http"
"os"
Expand All @@ -13,7 +14,7 @@ import (

// Filter 敏感词过滤器
type Filter struct {
trie *Trie
trie *trie.Trie
noise *regexp.Regexp
}

Expand All @@ -34,7 +35,7 @@ func NewWithBossSDict() *Filter {
// New 返回一个敏感词过滤器
func New() *Filter {
return &Filter{
trie: NewTrie(),
trie: trie.NewTrie(),
noise: regexp.MustCompile(`[|\s&%$@*!!#^~_—|'";.。,,?<>《》::]+`),
}
}
Expand Down
7 changes: 4 additions & 3 deletions sensitive/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sensitive

import (
"fmt"
"github.com/Tohrusky/sensitive-go/sensitive/trie"
"io"
"reflect"
"regexp"
Expand Down Expand Up @@ -336,7 +337,7 @@ func TestDeleteWord2(t *testing.T) {

func TestFilter_LoadWordDict(t *testing.T) {
type fields struct {
trie *Trie
trie *trie.Trie
noise *regexp.Regexp
}
type args struct {
Expand All @@ -363,7 +364,7 @@ func TestFilter_LoadWordDict(t *testing.T) {

func TestFilter_LoadNetWordDict(t *testing.T) {
type fields struct {
trie *Trie
trie *trie.Trie
noise *regexp.Regexp
}
type args struct {
Expand All @@ -390,7 +391,7 @@ func TestFilter_LoadNetWordDict(t *testing.T) {

func TestFilter_Load(t *testing.T) {
type fields struct {
trie *Trie
trie *trie.Trie
noise *regexp.Regexp
}
type args struct {
Expand Down
2 changes: 1 addition & 1 deletion sensitive/trie_tree.go → sensitive/trie/trie_tree.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sensitive
package trie

// Trie 短语组成的Trie树.
type Trie struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sensitive
package trie

import (
"testing"
Expand Down

0 comments on commit d514e45

Please sign in to comment.