stemmer_en_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2014 Couchbase, Inc.
  2. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  3. // except in compliance with the License. You may obtain a copy of the License at
  4. // http://www.apache.org/licenses/LICENSE-2.0
  5. // Unless required by applicable law or agreed to in writing, software distributed under the
  6. // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  7. // either express or implied. See the License for the specific language governing permissions
  8. // and limitations under the License.
  9. package en
  10. import (
  11. "reflect"
  12. "testing"
  13. "github.com/couchbaselabs/bleve/analysis"
  14. "github.com/couchbaselabs/bleve/registry"
  15. )
  16. func TestEnglishStemmer(t *testing.T) {
  17. tests := []struct {
  18. input analysis.TokenStream
  19. output analysis.TokenStream
  20. }{
  21. {
  22. input: analysis.TokenStream{
  23. &analysis.Token{
  24. Term: []byte("walking"),
  25. },
  26. &analysis.Token{
  27. Term: []byte("talked"),
  28. },
  29. &analysis.Token{
  30. Term: []byte("business"),
  31. },
  32. &analysis.Token{
  33. Term: []byte("protected"),
  34. KeyWord: true,
  35. },
  36. },
  37. output: analysis.TokenStream{
  38. &analysis.Token{
  39. Term: []byte("walk"),
  40. },
  41. &analysis.Token{
  42. Term: []byte("talk"),
  43. },
  44. &analysis.Token{
  45. Term: []byte("busi"),
  46. },
  47. &analysis.Token{
  48. Term: []byte("protected"),
  49. KeyWord: true,
  50. },
  51. },
  52. },
  53. }
  54. cache := registry.NewCache()
  55. stemmerFilter, err := cache.TokenFilterNamed(StemmerName)
  56. if err != nil {
  57. t.Fatal(err)
  58. }
  59. for _, test := range tests {
  60. actual := stemmerFilter.Filter(test.input)
  61. if !reflect.DeepEqual(actual, test.output) {
  62. t.Errorf("expected %s, got %s", test.output[0].Term, actual[0].Term)
  63. }
  64. }
  65. }