mirror of
https://github.com/fumiama/jieba.git
synced 2026-06-05 00:32:51 +08:00
28 lines
590 B
Go
Executable File
28 lines
590 B
Go
Executable File
package tokenizers
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/blevesearch/bleve/analysis"
|
|
"github.com/blevesearch/bleve/registry"
|
|
)
|
|
|
|
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)
|
|
}
|