Skip to content

Commit

Permalink
Refactoring (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikawaha authored Aug 21, 2022
1 parent b1848a6 commit a16f933
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions filter/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (f *FeaturesFilter) add(fs Features) {
}

// Match returns true if a filter matches given features.
func (f FeaturesFilter) Match(fs Features) bool {
func (f *FeaturesFilter) Match(fs Features) bool {
n := &f.root
for _, v := range fs {
if k := n.has(v); k >= 0 {
Expand All @@ -92,7 +92,7 @@ func (f FeaturesFilter) Match(fs Features) bool {
}

// String implements string interface.
func (f FeaturesFilter) String() string {
func (f *FeaturesFilter) String() string {
var buf strings.Builder
filterString(&buf, 0, &f.root)
return buf.String()
Expand Down
4 changes: 2 additions & 2 deletions filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ func Benchmark_TokenFilter_WordFilter(b *testing.B) {
b.Run("specific token filter", func(b *testing.B) {
tokens := tnz.Tokenize(input)
words := []string{"人魚", "南", "の"}
filter := filter.NewWordFilter(words)
fl := filter.NewWordFilter(words)
b.ResetTimer()
for i := 0; i < b.N; i++ {
filter.Keep(&tokens)
fl.Keep(&tokens)
}
})
}
20 changes: 10 additions & 10 deletions filter/pos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func TestPOSFilter_Match(t *testing.T) {

for _, v := range testdata {
t.Run(v.title, func(t *testing.T) {
filter := filter.NewPOSFilter(v.featuresList...)
fl := filter.NewPOSFilter(v.featuresList...)
var got []string
for _, token := range tokens {
if filter.Match(token.POS()) {
if fl.Match(token.POS()) {
got = append(got, token.Surface)
}
}
Expand Down Expand Up @@ -126,9 +126,9 @@ func TestPOSFilter_Keep(t *testing.T) {
for _, v := range testdata {
t.Run(v.title, func(t *testing.T) {
tokens := tnz.Tokenize(input)
filter := filter.NewPOSFilter(v.featuresList...)
fl := filter.NewPOSFilter(v.featuresList...)
var got []string
filter.Keep(&tokens)
fl.Keep(&tokens)
for _, token := range tokens {
got = append(got, token.Surface)
}
Expand All @@ -139,8 +139,8 @@ func TestPOSFilter_Keep(t *testing.T) {
}

t.Run("empty input test", func(t *testing.T) {
filter := filter.NewPOSFilter(nil)
filter.Keep(nil)
fl := filter.NewPOSFilter(nil)
fl.Keep(nil)
})
}

Expand Down Expand Up @@ -182,9 +182,9 @@ func TestPOSFilter_Drop(t *testing.T) {
for _, v := range testdata {
t.Run(v.title, func(t *testing.T) {
tokens := tnz.Tokenize(input)
filter := filter.NewPOSFilter(v.featuresList...)
fl := filter.NewPOSFilter(v.featuresList...)
var got []string
filter.Drop(&tokens)
fl.Drop(&tokens)
for _, token := range tokens {
got = append(got, token.Surface)
}
Expand All @@ -195,8 +195,8 @@ func TestPOSFilter_Drop(t *testing.T) {
}

t.Run("empty input test", func(t *testing.T) {
filter := filter.NewPOSFilter(nil)
filter.Drop(nil)
fl := filter.NewPOSFilter(nil)
fl.Drop(nil)
})
}

Expand Down
20 changes: 10 additions & 10 deletions filter/word_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func TestWordFilter_Match(t *testing.T) {

for _, v := range testdata {
t.Run(v.title, func(t *testing.T) {
filter := filter.NewWordFilter(v.wordList)
fl := filter.NewWordFilter(v.wordList)
var got []string
for _, token := range tokens {
if filter.Match(token.Surface) {
if fl.Match(token.Surface) {
got = append(got, token.Surface)
}
}
Expand Down Expand Up @@ -92,9 +92,9 @@ func TestWordFilter_Keep(t *testing.T) {
for _, v := range testdata {
t.Run(v.title, func(t *testing.T) {
tokens := tnz.Tokenize(input)
filter := filter.NewWordFilter(v.wordList)
fl := filter.NewWordFilter(v.wordList)
var got []string
filter.Keep(&tokens)
fl.Keep(&tokens)
for _, token := range tokens {
got = append(got, token.Surface)
}
Expand All @@ -105,8 +105,8 @@ func TestWordFilter_Keep(t *testing.T) {
}

t.Run("empty input test", func(t *testing.T) {
filter := filter.NewWordFilter(nil)
filter.Keep(nil)
fl := filter.NewWordFilter(nil)
fl.Keep(nil)
})
}

Expand Down Expand Up @@ -146,9 +146,9 @@ func TestWordFilter_Drop(t *testing.T) {
for _, v := range testdata {
t.Run(v.title, func(t *testing.T) {
tokens := tnz.Tokenize(input)
filter := filter.NewWordFilter(v.wordList)
fl := filter.NewWordFilter(v.wordList)
var got []string
filter.Drop(&tokens)
fl.Drop(&tokens)
for _, token := range tokens {
got = append(got, token.Surface)
}
Expand All @@ -159,8 +159,8 @@ func TestWordFilter_Drop(t *testing.T) {
}

t.Run("empty input test", func(t *testing.T) {
filter := filter.NewWordFilter(nil)
filter.Drop(nil)
fl := filter.NewWordFilter(nil)
fl.Drop(nil)
})
}

Expand Down

0 comments on commit a16f933

Please sign in to comment.