forked from advancedlogic/go-freeling
/
maco.go
137 lines (116 loc) · 4.43 KB
/
maco.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package nlp
type MacoOptions struct {
Lang string
LocutionsFile, QuantitiesFile, AffixFile, CompoundFile, DictionaryFile, ProbabilityFile, NPdataFile, PunctuationFile, UserMapFile string
Decimal, Thousand string
ProbabilityThreshold float64
InverseDict, RetokContractions bool
}
func NewMacoOptions(lang string) *MacoOptions {
return &MacoOptions{
Lang: lang,
UserMapFile: "",
LocutionsFile: "",
QuantitiesFile: "",
AffixFile: "",
ProbabilityFile: "",
DictionaryFile: "",
NPdataFile: "",
PunctuationFile: "",
CompoundFile: "",
Decimal: "",
Thousand: "",
ProbabilityThreshold: 0.001,
InverseDict: false,
RetokContractions: true,
}
}
func (this *MacoOptions) SetDataFiles(usr, pun, dic, aff, comp, loc, nps, qty, prb string) {
this.UserMapFile = usr
this.LocutionsFile = loc
this.QuantitiesFile = qty
this.AffixFile = aff
this.ProbabilityFile = prb
this.DictionaryFile = dic
this.NPdataFile = nps
this.PunctuationFile = pun
this.CompoundFile = comp
}
func (this *MacoOptions) SetNumericalPoint(dec string, tho string) {
this.Decimal = dec
this.Thousand = tho
}
func (this *MacoOptions) SetThreshold(t float64) {
this.ProbabilityThreshold = t
}
func (this *MacoOptions) SetInverseDict(b bool) {
this.InverseDict = b
}
func (this *MacoOptions) SetRetokContractions(b bool) {
this.RetokContractions = b
}
type Maco struct {
MultiwordsDetection, NumbersDetection, PunctuationDetection, DatesDetection, QuantitiesDetection, DictionarySearch, ProbabilityAssignment, UserMap, NERecognition bool
loc *Locutions
dic *Dictionary
prob *Probability
punct *Punts
npm *NER
/*
numb *Numbers
dates *Dates
quant *Quantities
user *regexp.Regexp
*/
}
func NewMaco(opts *MacoOptions) *Maco {
this := Maco{
MultiwordsDetection: false,
NumbersDetection: false,
PunctuationDetection: false,
DatesDetection: false,
QuantitiesDetection: false,
DictionarySearch: false,
ProbabilityAssignment: false,
UserMap: false,
NERecognition: false,
}
if opts.PunctuationFile != "" {
this.punct = NewPunts(opts.PunctuationFile)
this.PunctuationDetection = true
}
if opts.DictionaryFile != "" {
this.dic = NewDictionary(opts.Lang, opts.DictionaryFile, opts.AffixFile, opts.CompoundFile, opts.InverseDict, opts.RetokContractions)
this.DictionarySearch = true
}
if opts.LocutionsFile != "" {
this.loc = NewLocutions(opts.LocutionsFile)
this.MultiwordsDetection = true
}
if opts.NPdataFile != "" {
this.npm = NewNER(opts.NPdataFile)
this.NERecognition = true
}
if opts.ProbabilityFile != "" {
this.prob = NewProbability(opts.ProbabilityFile, opts.ProbabilityThreshold)
this.ProbabilityAssignment = true
}
return &this
}
func (this *Maco) Analyze(s *Sentence) {
if this.PunctuationDetection && this.punct != nil {
this.punct.analyze(s)
}
if this.DictionarySearch && this.dic != nil {
this.dic.Analyze(s)
}
if this.MultiwordsDetection && this.loc != nil {
this.loc.analyze(s)
}
if this.NERecognition && this.npm != nil {
this.npm.who.analyze(s)
}
if this.ProbabilityAssignment && this.prob != nil {
this.prob.Analyze(s)
}
}