The shamoji (杓文字) is word filtering package.
$ go get github.com/osamingo/shamoji@latest
package main
import (
"fmt"
"sync"
"github.com/osamingo/shamoji"
"github.com/osamingo/shamoji/filter"
"github.com/osamingo/shamoji/tokenizer"
"golang.org/x/text/unicode/norm"
)
var (
o sync.Once
s *shamoji.Serve
)
func main() {
yes, word := Contains("我が生涯に一片の悔い無し")
fmt.Printf("Result: %v, Word: %s", yes, word)
}
func Contains(sentence string) (bool, string) {
o.Do(func() {
tok, err := tokenizer.NewKagomeTokenizer(norm.NFKC)
if err != nil {
panic(err)
}
s = &shamoji.Serve{
Tokenizer: tok,
Filer: filter.NewCuckooFilter("涯に", "悔い"),
}
})
return s.Do(sentence)
}
Released under the MIT License.