forked from advancedlogic/go-freeling
/
engine.go
73 lines (60 loc) · 1.67 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package engine
import (
"fmt"
"sync"
"time"
"github.com/cheggaaa/pb"
"github.com/advancedlogic/go-freeling/nlp"
. "github.com/advancedlogic/go-freeling/terminal"
)
type Engine struct {
semaphore *sync.Mutex
NLP *nlp.NLPEngine
Ready bool
}
func NewEngine() *Engine {
return &Engine{
semaphore: new(sync.Mutex),
Ready: false,
}
}
var path = "./"
var lang = "en"
func (e *Engine) InitNLP() {
e.semaphore.Lock()
defer e.semaphore.Unlock()
if e.Ready {
return
}
Infoln("Init Natural Language Processing Engine")
initialized := false
count := 80
bar := pb.StartNew(count)
bar.ShowPercent = true
bar.ShowCounters = false
inc := func() {
for i := 0; i < 10; i++ {
bar.Increment()
}
}
start := time.Now().UnixNano()
nlpOptions := nlp.NewNLPOptions(path+"data/", lang, inc)
nlpOptions.Severity = nlp.ERROR
nlpOptions.TokenizerFile = "tokenizer.dat"
nlpOptions.SplitterFile = "splitter.dat"
nlpOptions.TaggerFile = "tagger.dat"
nlpOptions.ShallowParserFile = "chunker/grammar-chunk.dat"
nlpOptions.SenseFile = "senses.dat"
nlpOptions.UKBFile = "" //"ukb.dat"
nlpOptions.DisambiguatorFile = "common/knowledge.dat"
macoOptions := nlp.NewMacoOptions(lang)
macoOptions.SetDataFiles("", path+"data/common/punct.dat", path+"data/"+lang+"/dicc.src", "", "", path+"data/"+lang+"/locucions-extended.dat", path+"data/"+lang+"/np.dat", "", path+"data/"+lang+"/probabilitats.dat")
nlpOptions.MorfoOptions = macoOptions
nlpEngine := nlp.NewNLPEngine(nlpOptions)
stop := time.Now().UnixNano()
delta := (stop - start) / (1000 * 1000)
initialized = true
bar.FinishPrint(fmt.Sprintf("Data loaded in %dms", delta))
e.NLP = nlpEngine
e.Ready = initialized
}