本文整理匯總了Golang中github.com/blevesearch/bleve/analysis.NewTokenMap函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTokenMap函數的具體用法?Golang NewTokenMap怎麽用?Golang NewTokenMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewTokenMap函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestKeyWordMarkerFilter
func TestKeyWordMarkerFilter(t *testing.T) {
inputTokenStream := analysis.TokenStream{
&analysis.Token{
Term: []byte("a"),
},
&analysis.Token{
Term: []byte("walk"),
},
&analysis.Token{
Term: []byte("in"),
},
&analysis.Token{
Term: []byte("the"),
},
&analysis.Token{
Term: []byte("park"),
},
}
expectedTokenStream := analysis.TokenStream{
&analysis.Token{
Term: []byte("a"),
},
&analysis.Token{
Term: []byte("walk"),
KeyWord: true,
},
&analysis.Token{
Term: []byte("in"),
},
&analysis.Token{
Term: []byte("the"),
},
&analysis.Token{
Term: []byte("park"),
KeyWord: true,
},
}
keyWordsMap := analysis.NewTokenMap()
keyWordsMap.AddToken("walk")
keyWordsMap.AddToken("park")
filter := NewKeyWordMarkerFilter(keyWordsMap)
ouputTokenStream := filter.Filter(inputTokenStream)
if !reflect.DeepEqual(ouputTokenStream, expectedTokenStream) {
t.Errorf("expected %#v got %#v", expectedTokenStream[0].KeyWord, ouputTokenStream[0].KeyWord)
}
}
示例2: GenericTokenMapConstructor
func GenericTokenMapConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.TokenMap, error) {
rv := analysis.NewTokenMap()
// first: try to load by filename
filename, ok := config["filename"].(string)
if ok {
err := rv.LoadFile(filename)
return rv, err
}
// next: look for an inline word list
tokens, ok := config["tokens"].([]interface{})
if ok {
for _, token := range tokens {
tokenStr, ok := token.(string)
if ok {
rv.AddToken(tokenStr)
}
}
return rv, nil
}
return nil, fmt.Errorf("must specify filename or list of tokens for token map")
}
示例3: TokenMapConstructor
func TokenMapConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.TokenMap, error) {
rv := analysis.NewTokenMap()
err := rv.LoadBytes(ItalianStopWords)
return rv, err
}
示例4: ArticlesTokenMapConstructor
func ArticlesTokenMapConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.TokenMap, error) {
rv := analysis.NewTokenMap()
err := rv.LoadBytes(IrishArticles)
return rv, err
}