|
a/src/common/syngroups.cpp |
|
b/src/common/syngroups.cpp |
|
... |
|
... |
66 |
{
|
66 |
{
|
67 |
}
|
67 |
}
|
68 |
|
68 |
|
69 |
bool SynGroups::setfile(const string& fn)
|
69 |
bool SynGroups::setfile(const string& fn)
|
70 |
{
|
70 |
{
|
71 |
LOGDEB("SynGroups::setfile(" << (fn) << ")\n" );
|
71 |
LOGDEB("SynGroups::setfile(" << fn << ")\n");
|
72 |
if (!m) {
|
72 |
if (!m) {
|
73 |
m = new Internal;
|
73 |
m = new Internal;
|
74 |
if (!m) {
|
74 |
if (!m) {
|
75 |
LOGERR("SynGroups:setfile:: new Internal failed: no mem ?\n" );
|
75 |
LOGERR("SynGroups:setfile:: new Internal failed: no mem ?\n");
|
76 |
return false;
|
76 |
return false;
|
77 |
}
|
77 |
}
|
78 |
}
|
78 |
}
|
79 |
|
79 |
|
80 |
if (fn.empty()) {
|
80 |
if (fn.empty()) {
|
|
... |
|
... |
84 |
}
|
84 |
}
|
85 |
|
85 |
|
86 |
ifstream input;
|
86 |
ifstream input;
|
87 |
input.open(fn.c_str(), ios::in);
|
87 |
input.open(fn.c_str(), ios::in);
|
88 |
if (!input.is_open()) {
|
88 |
if (!input.is_open()) {
|
89 |
LOGERR("SynGroups:setfile:: could not open " << (fn) << " errno " << (errno) << "\n" );
|
89 |
LOGSYSERR("SynGroups:setfile", "open", fn);
|
90 |
return false;
|
90 |
return false;
|
91 |
}
|
91 |
}
|
92 |
|
92 |
|
93 |
string cline;
|
93 |
string cline;
|
94 |
bool appending = false;
|
94 |
bool appending = false;
|
|
... |
|
... |
99 |
for (;;) {
|
99 |
for (;;) {
|
100 |
cline.clear();
|
100 |
cline.clear();
|
101 |
getline(input, cline);
|
101 |
getline(input, cline);
|
102 |
if (!input.good()) {
|
102 |
if (!input.good()) {
|
103 |
if (input.bad()) {
|
103 |
if (input.bad()) {
|
104 |
LOGERR("Syngroup::setfile(" << (fn) << "):Parse: input.bad()\n" );
|
104 |
LOGERR("Syngroup::setfile(" << fn << "):Parse: input.bad()\n");
|
105 |
return false;
|
105 |
return false;
|
106 |
}
|
106 |
}
|
107 |
// Must be eof ? But maybe we have a partial line which
|
107 |
// Must be eof ? But maybe we have a partial line which
|
108 |
// must be processed. This happens if the last line before
|
108 |
// must be processed. This happens if the last line before
|
109 |
// eof ends with a backslash, or there is no final \n
|
109 |
// eof ends with a backslash, or there is no final \n
|
|
... |
|
... |
140 |
}
|
140 |
}
|
141 |
appending = false;
|
141 |
appending = false;
|
142 |
|
142 |
|
143 |
vector<string> words;
|
143 |
vector<string> words;
|
144 |
if (!stringToStrings(line, words)) {
|
144 |
if (!stringToStrings(line, words)) {
|
145 |
LOGERR("SynGroups:setfile: " << (fn) << ": bad line " << (lnum) << ": " << (line) << "\n" );
|
145 |
LOGERR("SynGroups:setfile: " << fn << ": bad line " << lnum <<
|
|
|
146 |
": " << line << "\n");
|
146 |
continue;
|
147 |
continue;
|
147 |
}
|
148 |
}
|
148 |
|
149 |
|
149 |
if (words.empty())
|
150 |
if (words.empty())
|
150 |
continue;
|
151 |
continue;
|
151 |
if (words.size() == 1) {
|
152 |
if (words.size() == 1) {
|
152 |
LOGERR("Syngroup::setfile(" << (fn) << "):single term group at line " << (lnum) << " ??\n" );
|
153 |
LOGERR("Syngroup::setfile(" << fn << "):single term group at line "
|
|
|
154 |
<< lnum << " ??\n");
|
153 |
continue;
|
155 |
continue;
|
154 |
}
|
156 |
}
|
155 |
|
157 |
|
156 |
m->groups.push_back(words);
|
158 |
m->groups.push_back(words);
|
157 |
for (vector<string>::const_iterator it = words.begin();
|
159 |
for (const auto& word : words) {
|
158 |
it != words.end(); it++) {
|
|
|
159 |
m->terms[*it] = m->groups.size()-1;
|
160 |
m->terms[word] = m->groups.size()-1;
|
160 |
}
|
161 |
}
|
161 |
LOGDEB1("SynGroups::setfile: group: [" << (stringsToString(m->groups.back())) << "]\n" );
|
162 |
LOGDEB1("SynGroups::setfile: group: [" <<
|
|
|
163 |
stringsToString(m->groups.back()) << "]\n");
|
162 |
}
|
164 |
}
|
163 |
m->ok = true;
|
165 |
m->ok = true;
|
164 |
return true;
|
166 |
return true;
|
165 |
}
|
167 |
}
|
166 |
|
168 |
|
|
... |
|
... |
168 |
{
|
170 |
{
|
169 |
vector<string> ret;
|
171 |
vector<string> ret;
|
170 |
if (!ok())
|
172 |
if (!ok())
|
171 |
return ret;
|
173 |
return ret;
|
172 |
|
174 |
|
173 |
std::unordered_map<string, unsigned int>::const_iterator it1 =
|
175 |
const auto it1 = m->terms.find(term);
|
174 |
m->terms.find(term);
|
|
|
175 |
if (it1 == m->terms.end()) {
|
176 |
if (it1 == m->terms.end()) {
|
176 |
LOGDEB1("SynGroups::getgroup: [" << (term) << "] not found in direct map\n" );
|
177 |
LOGDEB1("SynGroups::getgroup: [" << term<<"] not found in direct map\n");
|
177 |
return ret;
|
178 |
return ret;
|
178 |
}
|
179 |
}
|
179 |
|
180 |
|
180 |
unsigned int idx = it1->second;
|
181 |
unsigned int idx = it1->second;
|
181 |
if (idx >= m->groups.size()) {
|
182 |
if (idx >= m->groups.size()) {
|
182 |
LOGERR("SynGroups::getgroup: line index higher than line count !\n" );
|
183 |
LOGERR("SynGroups::getgroup: line index higher than line count !\n");
|
183 |
return ret;
|
184 |
return ret;
|
184 |
}
|
185 |
}
|
185 |
return m->groups[idx];
|
186 |
return m->groups[idx];
|
186 |
}
|
187 |
}
|
187 |
|
188 |
|