mirror of
https://github.com/fumiama/jieba.git
synced 2026-06-23 12:40:39 +08:00
优化
This commit is contained in:
30
tokenizers/analyzer.go
Executable file
30
tokenizers/analyzer.go
Executable file
@@ -0,0 +1,30 @@
|
||||
package tokenizers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/blevesearch/bleve/analysis"
|
||||
"github.com/blevesearch/bleve/registry"
|
||||
)
|
||||
|
||||
type JiebaAnalyzer struct {
|
||||
}
|
||||
|
||||
func analyzerConstructor(config map[string]interface{}, cache *registry.Cache) (*analysis.Analyzer, error) {
|
||||
tokenizerName, ok := config["tokenizer"].(string)
|
||||
if !ok {
|
||||
return nil, errors.New("must specify tokenizer")
|
||||
}
|
||||
tokenizer, err := cache.TokenizerNamed(tokenizerName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
alz := &analysis.Analyzer{
|
||||
Tokenizer: tokenizer,
|
||||
}
|
||||
return alz, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
registry.RegisterAnalyzer("jieba", analyzerConstructor)
|
||||
}
|
||||
Reference in New Issue
Block a user