本文整理汇总了Golang中github.com/khlieng/name_pending/Godeps/_workspace/src/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(DanishStopWords)
return rv, err
}
示例4: ArticlesTokenMapConstructor
func ArticlesTokenMapConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.TokenMap, error) {
rv := analysis.NewTokenMap()
err := rv.LoadBytes(ItalianArticles)
return rv, err
}