-
Notifications
You must be signed in to change notification settings - Fork 125
/
FAWREConf_pack.cpp
239 lines (190 loc) · 5.42 KB
/
FAWREConf_pack.cpp
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
#include "blingfire-client_src_pch.h"
#include "FAConfig.h"
#include "FAWREConf_pack.h"
#include "FAFsmConst.h"
#include "FAArray_pack.h"
#include "FAMultiMap_pack.h"
#include "FAState2Ow_pack_triv.h"
#include "FAState2Ows_pack_triv.h"
#include "FAMealyDfa_pack_triv.h"
#include "FARSDfa_pack_triv.h"
FAWREConf_pack::FAWREConf_pack () :
m_WreType (0),
m_TokenType (0),
m_TagOwBase (0),
m_pTxtDfa (NULL),
m_pTxtOws (NULL),
m_pDctArr (NULL),
m_pDfa1 (NULL),
m_pDfa2 (NULL),
m_pState2Ows (NULL),
m_pSigma1 (NULL),
m_pSigma2 (NULL),
m_pTrBr (NULL)
{}
FAWREConf_pack::~FAWREConf_pack ()
{
FAWREConf_pack::Clear ();
}
void FAWREConf_pack::Clear ()
{
if (m_pTxtDfa) {
delete m_pTxtDfa;
m_pTxtDfa = NULL;
}
if (m_pTxtOws) {
delete m_pTxtOws;
m_pTxtOws = NULL;
}
if (m_pDctArr) {
delete m_pDctArr;
m_pDctArr = NULL;
}
if (m_pDfa1) {
delete m_pDfa1;
m_pDfa1 = NULL;
}
if (m_pDfa2) {
delete m_pDfa2;
m_pDfa2 = NULL;
}
if (m_pState2Ows) {
delete m_pState2Ows;
m_pState2Ows = NULL;
}
if (m_pSigma1) {
delete m_pSigma1;
m_pSigma1 = NULL;
}
if (m_pSigma2) {
delete m_pSigma2;
m_pSigma2 = NULL;
}
if (m_pTrBr) {
delete m_pTrBr;
m_pTrBr = NULL;
}
}
void FAWREConf_pack::SetImage (const unsigned char * pImage)
{
FAWREConf_pack::Clear ();
if (!pImage) {
return;
}
const int * pConf = (const int *) pImage ;
/// setup constants
m_WreType = pConf [FAFsmConst::WRE_CONF_WRE_TYPE];
LogAssert (FAFsmConst::WRE_TYPE_RS <= m_WreType && \
FAFsmConst::WRE_TYPE_COUNT > m_WreType);
m_TokenType = pConf [FAFsmConst::WRE_CONF_TOKEN_TYPE];
LogAssert ((FAFsmConst::WRE_TT_TEXT | FAFsmConst::WRE_TT_TAGS | \
FAFsmConst::WRE_TT_DCTS) & m_TokenType);
m_TagOwBase = pConf [FAFsmConst::WRE_CONF_TAG_OW_BASE];
/// setup text digitizer, if any
if (0 < pConf [FAFsmConst::WRE_CONF_TXT_DIG]) {
const unsigned char * pImg = \
pImage + pConf [FAFsmConst::WRE_CONF_TXT_DIG];
DebugLogAssert (NULL == m_pTxtDfa);
m_pTxtDfa = NEW FARSDfa_pack_triv;
m_pTxtDfa->SetImage (pImg);
DebugLogAssert (NULL == m_pTxtOws);
m_pTxtOws = NEW FAState2Ow_pack_triv;
m_pTxtOws->SetImage (pImg);
}
/// setup dict digitizer, if any
if (0 < pConf [FAFsmConst::WRE_CONF_DCT_DIG]) {
const unsigned char * pImg = \
pImage + pConf [FAFsmConst::WRE_CONF_DCT_DIG];
DebugLogAssert (NULL == m_pDctArr);
m_pDctArr = NEW FAArray_pack;
m_pDctArr->SetImage (pImg);
}
/// setup rules1 automaton, if any
if (0 < pConf [FAFsmConst::WRE_CONF_FSM1]) {
const unsigned char * pImg = \
pImage + pConf [FAFsmConst::WRE_CONF_FSM1];
DebugLogAssert (NULL == m_pDfa1);
m_pDfa1 = NEW FARSDfa_pack_triv;
m_pDfa1->SetImage (pImg);
if (FAFsmConst::WRE_TYPE_MOORE == m_WreType) {
DebugLogAssert (NULL == m_pState2Ows);
m_pState2Ows = NEW FAState2Ows_pack_triv;
m_pState2Ows->SetImage (pImg);
} else if (FAFsmConst::WRE_TYPE_MEALY == m_WreType) {
DebugLogAssert (NULL == m_pSigma1);
m_pSigma1 = NEW FAMealyDfa_pack_triv;
m_pSigma1->SetImage (pImg);
}
}
/// setup rules2 automaton, if any
if (0 < pConf [FAFsmConst::WRE_CONF_FSM2]) {
const unsigned char * pImg = \
pImage + pConf [FAFsmConst::WRE_CONF_FSM2];
DebugLogAssert (NULL == m_pDfa2);
m_pDfa2 = NEW FARSDfa_pack_triv;
m_pDfa2->SetImage (pImg);
DebugLogAssert (NULL == m_pSigma2);
m_pSigma2 = NEW FAMealyDfa_pack_triv;
m_pSigma2->SetImage (pImg);
}
/// setup trbr map, if any
if (0 < pConf [FAFsmConst::WRE_CONF_TRBR]) {
const unsigned char * pImg = \
pImage + pConf [FAFsmConst::WRE_CONF_TRBR];
DebugLogAssert (NULL == m_pTrBr);
m_pTrBr = NEW FAMultiMap_pack;
m_pTrBr->SetImage (pImg);
}
}
const int FAWREConf_pack::GetType () const
{
return m_WreType;
}
const int FAWREConf_pack::GetTokenType () const
{
return m_TokenType;
}
const int FAWREConf_pack::GetTagOwBase () const
{
return m_TagOwBase;
}
const FARSDfaCA * FAWREConf_pack::GetTxtDigDfa () const
{
return m_pTxtDfa;
}
const FAState2OwCA * FAWREConf_pack::GetTxtDigOws () const
{
return m_pTxtOws;
}
const FAArrayCA * FAWREConf_pack::GetDictDig () const
{
return m_pDctArr;
}
const FARSDfaCA * FAWREConf_pack::GetDfa1 () const
{
return m_pDfa1;
}
const FARSDfaCA * FAWREConf_pack::GetDfa2 () const
{
return m_pDfa2;
}
const FAState2OwsCA * FAWREConf_pack::GetState2Ows () const
{
return m_pState2Ows;
}
const FAMealyDfaCA * FAWREConf_pack::GetSigma1 () const
{
return m_pSigma1;
}
const FAMealyDfaCA * FAWREConf_pack::GetSigma2 () const
{
return m_pSigma2;
}
const FAMultiMapCA * FAWREConf_pack::GetTrBrMap () const
{
return m_pTrBr;
}