MCPcopy
hub / github.com/dgraph-io/dgraph / LoadCustomTokenizer

Function LoadCustomTokenizer

tok/tok.go:135–151  ·  view source on GitHub ↗

LoadCustomTokenizer reads and loads a custom tokenizer from the given file.

(soFile string)

Source from the content-addressed store, hash-verified

133
134// LoadCustomTokenizer reads and loads a custom tokenizer from the given file.
135func LoadCustomTokenizer(soFile string) {
136 glog.Infof("Loading custom tokenizer from %q", soFile)
137 pl, err := plugin.Open(soFile)
138 x.Checkf(err, "could not open custom tokenizer plugin file")
139 symb, err := pl.Lookup("Tokenizer")
140 x.Checkf(err, `could not find symbol "Tokenizer" while loading custom tokenizer: %v`, err)
141
142 // Let any type assertion panics occur, since they will contain a message
143 // telling the user what went wrong. Otherwise it's hard to capture this
144 // information to pass on to the user.
145 tokenizer := symb.(func() interface{})().(PluginTokenizer)
146
147 id := tokenizer.Identifier()
148 x.AssertTruef(id >= IdentCustom,
149 "custom tokenizer identifier byte must be >= 0x80, but was %#x", id)
150 registerTokenizer(CustomTokenizer{PluginTokenizer: tokenizer})
151}
152
153// GetTokenizerByID tries to find a tokenizer by id in the registered list.
154// Returns the tokenizer and true if found, otherwise nil and false.

Callers 2

RunBulkLoaderFunction · 0.92
setupCustomTokenizersFunction · 0.92

Calls 6

CheckfFunction · 0.92
AssertTruefFunction · 0.92
registerTokenizerFunction · 0.85
InfofMethod · 0.80
OpenMethod · 0.65
IdentifierMethod · 0.65

Tested by

no test coverage detected