Menu

[r45]: / trunk / libtop_engine / psearch_rule.h  Maximize  Restore  History

Download this file

382 lines (276 with data), 10.0 kB

  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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#ifndef PSEARCH_RULE_H_
#define PSEARCH_RULE_H_
#include "psearch_core.h"
namespace psearch {
/////////////////////////////////////////////////////////////////////////////////////////
// class Rule
//
// Logical class used for authoring Patterns, this class generate the associated patterns:
// o contains a set of categories having an existential relationship (at least one
// of their node must be activated - a pattern is create for each node).
// o contains c1 node which are in conjuction together - translate to ci nodes of pattern
/////////////////////////////////////////////////////////////////////////////////////////
class Rule: public PSBase
{
public:
inline Rule(PSearchDB * db_p, index_type index):
PSBase(db_p, index),
m_patterns(),
m_weight(0),
m_ex_categories(),
m_c1_nodes(),
m_c2_nodes(),
m_negated_nodes(),
m_is_active(true),
m_patterns_generated(false)
{};
inline rule_index_type
get_rule_index()const
{
return this;
};
inline bool
is_active() const
{
return m_is_active;
};
inline unsigned int
get_weight() const
{
return m_weight;
};
bool
is_consistent()const;
//////////////////////////////////////////////////////////////////////////////////////
// relationship with Pattern
/////////////////////////////////////////////////////////////////////////////////////
inline bool
has_pattern(pattern_index_type pindex)const
{
return m_patterns.find(pindex) != m_patterns.end();
};
inline pattern_const_iterator_type
get_patterns_begin()const
{
return m_patterns.begin();
};
inline pattern_const_iterator_type
get_patterns_end()const
{
return m_patterns.end();
};
inline pattern_set_const_iterator
get_patterns_iterator()const
{
return pattern_set_const_iterator(get_patterns_begin(), get_patterns_end());
};
inline size_t
get_nbr_patterns()const
{
return m_patterns.size();
};
///////////////////////////////////////////////////////////////////////////////////////
// relationship to Category
//////////////////////////////////////////////////////////////////////////////////////
inline bool
has_ex_category(category_index_type category_index)const
{
return m_ex_categories.find(category_index) != m_ex_categories.end();
};
inline category_const_iterator_type
get_ex_categories_begin()const
{
return m_ex_categories.begin();
};
inline category_const_iterator_type
get_ex_categories_end()const
{
return m_ex_categories.end();
};
inline category_set_const_iterator
get_ex_categories_iterator()const
{
return category_set_const_iterator(get_ex_categories_begin(), get_ex_categories_end());
};
inline size_t
get_nbr_ex_categories()const
{
return m_ex_categories.size();
};
///////////////////////////////////////////////////////////////////////////////////////
// relationship to Node
//////////////////////////////////////////////////////////////////////////////////////
// this consider only nodes (not negated_nodes)
inline bool
is_c1_node(node_index_type node_index)const
{
return m_c1_nodes.find(node_index) != m_c1_nodes.end();
};
// which includes c1 nodes.
inline bool
is_c2_node(node_index_type node_index)const
{
return m_c2_nodes.find(node_index) != m_c2_nodes.end();
};
// based on negated_node
inline bool
is_negated_by_node(node_index_type node_index)const
{
return m_negated_nodes.find(node_index) != m_negated_nodes.end();
};
inline node_const_iterator_type
get_c1_nodes_begin()const
{
return m_c1_nodes.begin();
};
inline node_const_iterator_type
get_c1_nodes_end()const
{
return m_c1_nodes.end();
};
inline node_set_const_iterator
get_c1_nodes_iterator()const
{
return node_set_const_iterator(get_c1_nodes_begin(), get_c1_nodes_end());
};
inline node_const_iterator_type
get_c2_nodes_begin()const
{
return m_c2_nodes.begin();
};
inline node_const_iterator_type
get_c2_nodes_end()const
{
return m_c2_nodes.end();
};
inline node_set_const_iterator
get_c2_nodes_iterator()const
{
return node_set_const_iterator(get_c2_nodes_begin(), get_c2_nodes_end());
};
inline node_exclude_set_const_iterator
get_c2_nodes_only_iterator()const
{
return node_exclude_set_const_iterator(get_c2_nodes_begin(), get_c2_nodes_end(), m_c1_nodes);
};
inline node_const_iterator_type
get_negated_nodes_begin()const
{
return m_negated_nodes.begin();
};
inline node_const_iterator_type
get_negated_nodes_end()const
{
return m_negated_nodes.end();
};
inline node_set_const_iterator
get_negated_nodes_iterator()const
{
return node_set_const_iterator(get_negated_nodes_begin(), get_negated_nodes_end());
};
protected:
inline void
set_active(bool b)
{
m_is_active = b;
};
inline void
set_weight(unsigned int weight)
{
m_weight = weight;
};
inline void
add_ex_category(category_index_type category_index)
{
if(!category_index) return;
m_ex_categories.insert(category_index);
};
inline void
remove_ex_category(category_index_type category_index)
{
m_ex_categories.erase(category_index);
};
inline void
remove_all_ex_categories()
{
m_ex_categories.clear();
};
inline void
add_c1_node(node_index_type node_index)
{
if(!node_index) return;
m_c1_nodes.insert(node_index);
m_c2_nodes.insert(node_index);
};
inline void
add_c2_node(node_index_type node_index)
{
if(!node_index) return;
m_c2_nodes.insert(node_index);
};
inline void
add_negated_node(node_index_type node_index)
{
if(!node_index) return;
m_negated_nodes.insert(node_index);
};
inline void
remove_c1_node(node_index_type node_index)
{
m_c1_nodes.erase(node_index);
m_c2_nodes.erase(node_index);
};
inline void
remove_c2_node(node_index_type node_index)
{
m_c2_nodes.erase(node_index);
};
inline void
remove_negated_node(node_index_type node_index)
{
m_negated_nodes.erase(node_index);
};
inline void
remove_all_nodes()
{
m_c1_nodes.clear();
m_c2_nodes.clear();
m_negated_nodes.clear();
};
void
generate_patterns(PSearchDB * db_p, bool verbose);
void
generate_xp_patterns(PSearchDB * db_p, node_set_type const& x_nodes, category_vector_type const& categories_stack, bool verbose);
void
init_pattern(PSearchDB * db_p, Pattern & pattern);
inline void
clear_generated_patterns()
{
m_patterns_generated = false;
m_patterns.clear();
};
inline bool
is_patterns_generated()const
{
return m_patterns_generated;
};
private:
friend class PSearchDB;
friend std::ostream& operator<<(std::ostream& out, Rule const& pattern);
friend std::ostream& operator<<(std::ostream& out, rule_index_type rule_index);
pattern_set_type m_patterns;
unsigned int m_weight;
category_set_type m_ex_categories;
node_set_type m_c1_nodes;
node_set_type m_c2_nodes;
node_set_type m_negated_nodes;
bool m_is_active;
bool m_patterns_generated;
};
inline std::ostream& operator<<(std::ostream& out, rule_index_type rule_index)
{
out << *rule_index;
return out;
};
}; /* psearch namespace */
#endif /*PSEARCH_RULE_H_*/
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.