-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathengine.go
executable file
·52 lines (43 loc) · 1.13 KB
/
engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package linguo
import (
"sync"
)
type Engine struct {
semaphore *sync.Mutex
NLP *NLPEngine
Ready bool
}
func NewEngine() *Engine {
return &Engine{
semaphore: new(sync.Mutex),
Ready: false,
}
}
func (e *Engine) InitNLP(path, lang string) {
e.semaphore.Lock()
defer e.semaphore.Unlock()
if e.Ready {
return
}
options := e.makeOptions(path, lang)
nlpEngine := NewNLPEngine(options)
e.NLP = nlpEngine
e.Ready = true
}
func (e *Engine) makeOptions(path, lang string) *NLPOptions {
macoOptions := NewMacoOptions(path, lang).
PunctuationFilePath("/common/punct.dat").
DictionaryFilePath("/" + lang + "/dicc.src").
LocutionsFilePath("/" + lang + "/locucions-extended.dat").
NPdataFilePath("/" + lang + "/np.dat").
ProbabilityFilePath("/" + lang + "/probabilitats.dat")
return NewNLPOptions(path, lang).
TokenizerFilePath("/tokenizer.dat").
SplitterFilePath("/splitter.dat").
TaggerFilePath("/tagger.dat").
ShallowParserFilePath("/chunker/grammar-chunk.dat").
SenseFilePath("/senses.dat").
UKBFilePath("/ukb.dat").
DisambiguatorFilePath("/common/knowledge.dat").
WithMorfoOptions(macoOptions)
}