-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaco.go
executable file
·172 lines (143 loc) · 5.27 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package linguo
type MacoOptions struct {
Path string
Lang string
LocutionsFile, QuantitiesFile, AffixFile, CompoundFile, DictionaryFile, ProbabilityFile, NPdataFile, PunctuationFile, UserMapFile string
Decimal, Thousand string
ProbabilityThreshold float64
InverseDict, RetokContractions bool
}
func NewMacoOptions(path, lang string) *MacoOptions {
return &MacoOptions{
Path: path,
Lang: lang,
UserMapFile: "",
LocutionsFile: "",
QuantitiesFile: "",
AffixFile: "",
ProbabilityFile: "",
DictionaryFile: "",
NPdataFile: "",
PunctuationFile: "",
CompoundFile: "",
Decimal: "",
Thousand: "",
ProbabilityThreshold: 0.001,
InverseDict: false,
RetokContractions: true,
}
}
func (m *MacoOptions) UserMapFilePath(path string) *MacoOptions {
m.UserMapFile = m.Path + path
return m
}
func (m *MacoOptions) LocutionsFilePath(path string) *MacoOptions {
m.LocutionsFile = m.Path + path
return m
}
func (m *MacoOptions) QuantitiesFilePath(path string) *MacoOptions {
m.QuantitiesFile = m.Path + path
return m
}
func (m *MacoOptions) AffixFilePath(path string) *MacoOptions {
m.AffixFile = m.Path + path
return m
}
func (m *MacoOptions) ProbabilityFilePath(path string) *MacoOptions {
m.ProbabilityFile = m.Path + path
return m
}
func (m *MacoOptions) DictionaryFilePath(path string) *MacoOptions {
m.DictionaryFile = m.Path + path
return m
}
func (m *MacoOptions) NPdataFilePath(path string) *MacoOptions {
m.NPdataFile = m.Path + path
return m
}
func (m *MacoOptions) PunctuationFilePath(path string) *MacoOptions {
m.PunctuationFile = m.Path + path
return m
}
func (m *MacoOptions) CompoundFilePath(path string) *MacoOptions {
m.CompoundFile = m.Path + path
return m
}
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)
}
}