Debian Codegraph @

Source/Reasoner/Classifier/CPartialPruningHierarchyNode.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CPartialPruningHierarchyNode.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Classifier {
29
30
31 CPartialPruningHierarchyNode::CPartialPruningHierarchyNode(CConcept *representiveConcept) : CHierarchyNode(representiveConcept) {
32 #ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS
33 generateNodeStrings();
34 #endif
35 }
36
37
38 CPartialPruningHierarchyNode::~CPartialPruningHierarchyNode() {
39 }
40
41
42 CHierarchyNode *CPartialPruningHierarchyNode::repairParentNodeInsertion(CHierarchyNode *replacedParentNodeCandidate, CClassifierStatistics *statistics) {
43 // called for the subsumer node
44 QList<CHierarchyNode *> parentNodes(parentNodeSet.values());
45 for (QList<CHierarchyNode *>::const_iterator it = parentNodes.constBegin(), itEnd = parentNodes.constEnd(); it != itEnd; ++it) {
46 CHierarchyNode *parentNode = *it;
47 if (parentNode != replacedParentNodeCandidate) {
48 if (replacedParentNodeCandidate->hasPredecessorNode(parentNode)) {
49 // the previous parent node is not longer a direct parent
50 removeParent(parentNode);
51 parentNode->removeChild(this);
52 }
53 }
54 }
55 #ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS
56 generateNodeStrings();
57 #endif
58 return this;
59 }
60
61 CHierarchyNode *CPartialPruningHierarchyNode::repairChildsParentNodeReplacement(CHierarchyNode *replacedParentNodeCandidate, CClassifierStatistics *statistics) {
62 // called for the subsumed node
63 QList<CHierarchyNode *> childNodes(childNodeSet.values());
64 for (QList<CHierarchyNode *>::const_iterator it = childNodes.constBegin(), itEnd = childNodes.constEnd(); it != itEnd; ++it) {
65 CHierarchyNode *childNode = *it;
66 if (childNode->hasPredecessorNode(replacedParentNodeCandidate)) {
67 removeChild(childNode);
68 childNode->removeParent(this);
69 }
70 }
71 #ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS
72 generateNodeStrings();
73 #endif
74 return this;
75 }
76
77
78 CHierarchyNode *CPartialPruningHierarchyNode::mergeToParentNode(CHierarchyNode *mergeParentDirection, CClassifierStatistics *statistics) {
79
80 QSet<CHierarchyNode*> mergeNodesSet;
81 QList<CHierarchyNode*> potMergeNodesList(getParentNodeList());
82
83 while (!potMergeNodesList.isEmpty()) {
84 CHierarchyNode* potMergeNode = potMergeNodesList.takeFirst();
85 if (potMergeNode->hasPredecessorNode(mergeParentDirection) || potMergeNode == mergeParentDirection) {
86 if (!mergeNodesSet.contains(potMergeNode)) {
87 mergeNodesSet.insert(potMergeNode);
88 if (potMergeNode != mergeParentDirection) {
89 potMergeNodesList.append(potMergeNode->getParentNodeList());
90 }
91 }
92 }
93 }
94
95 foreach (CHierarchyNode* mergeNode, mergeNodesSet) {
96 foreach (CConcept* concept, *mergeNode->getEquivalentConceptList()) {
97 addEquivalentConcept(concept);
98 }
99 foreach (CHierarchyNode* parentNode, *mergeNode->getParentNodeSet()) {
100 if (!hasParentNode(parentNode) && !mergeNodesSet.contains(parentNode)) {
101 makeParent(parentNode);
102 }
103 mergeNode->removeParent(parentNode);
104 parentNode->removeChild(mergeNode);
105 }
106 foreach (CHierarchyNode* childNode, *mergeNode->getChildNodeSet()) {
107 if (!hasChildNode(childNode) && !mergeNodesSet.contains(childNode) && childNode != this) {
108 makeChild(childNode);
109 }
110 mergeNode->removeChild(childNode);
111 childNode->removeParent(mergeNode);
112 }
113
114 foreach (CHierarchyNode* predNode, *mergeNode->getPredecessorNodeSet()) {
115 if (!hasPredecessorNode(predNode) && !mergeNodesSet.contains(predNode)) {
116 makePredecessor(predNode);
117 }
118 mergeNode->removePredecessor(predNode);
119 predNode->removeSuccessor(mergeNode);
120 }
121 foreach (CHierarchyNode* succNode, *mergeNode->getSuccessorNodeSet()) {
122 if (!hasSuccessorNode(succNode) && !mergeNodesSet.contains(succNode) && succNode != this) {
123 makeSuccessor(succNode);
124 }
125 mergeNode->removeSuccessor(succNode);
126 succNode->removePredecessor(mergeNode);
127 }
128 foreach (CHierarchyNode* incPredNode, *mergeNode->getIncompatiblePredecessorNodeSet()) {
129 if (!hasIncompatiblePredecessorNode(incPredNode)) {
130 makeIncompatiblePredecessor(incPredNode);
131 }
132 mergeNode->removeIncompatiblePredecessorNode(incPredNode);
133 incPredNode->removeIncompatibleSuccessorNode(mergeNode);
134 }
135 foreach (CHierarchyNode* incSuccNode, *mergeNode->getIncompatibleSuccessorNodeSet()) {
136 if (!hasIncompatibleSuccessorNode(incSuccNode)) {
137 makeIncompatibleSuccessor(incSuccNode);
138 }
139 mergeNode->removeIncompatibleSuccessorNode(incSuccNode);
140 incSuccNode->removeIncompatiblePredecessorNode(mergeNode);
141 }
142
143 foreach (CHierarchyNode* disjNode, *mergeNode->getDisjointNodeSet()) {
144 if (!hasDisjointNode(disjNode)) {
145 makeDisjoint(disjNode);
146 }
147 mergeNode->removeDisjointNode(disjNode);
148 disjNode->removeDisjointNode(mergeNode);
149 }
150 }
151
152 foreach (CHierarchyNode* parNode1, parentNodeSet) {
153 foreach (CHierarchyNode* parNode2, parentNodeSet) {
154 if (parNode1 != parNode2 && parNode2->hasPredecessorNode(parNode1)) {
155 removeParent(parNode1);
156 parNode1->removeChild(this);
157 }
158 }
159 }
160
161 foreach (CHierarchyNode* childNode1, childNodeSet) {
162 foreach (CHierarchyNode* childNode2, childNodeSet) {
163 if (childNode1 != childNode2 && childNode1->hasPredecessorNode(childNode2)) {
164 removeChild(childNode1);
165 childNode1->removeParent(this);
166 }
167 }
168 }
169
170
171 //QSet<CHierarchyNode *> parentMergeNodesSet(parentNodeSet);
172 //QList<CHierarchyNode *> parentMergeNodesList(parentMergeNodesSet.values());
173 //parentMergeNodesSet.insert(this);
174 //bool mergedIntoDirection = false;
175 //while (!parentMergeNodesList.isEmpty()) {
176 // CHierarchyNode *parentNode = parentMergeNodesList.takeFirst();
177
178 // if (parentNode == this) {
179 // bool bug = true;
180 // }
181
182 // if (parentNode == mergeParentDirection || parentNode->hasPredecessorNode(mergeParentDirection)) {
183 // // has to merge
184 // qint64 addParentEqConCount = parentNode->getEquivalentConceptCount();
185 // qint64 thisPrevEqConCount = eqConCount;
186
187 // foreach (CConcept *con, *parentNode->getEquivalentConceptList()) {
188 // eqConCount++;
189 // eqConList.append(con);
190 // }
191 // if (statistics && parentNode != mergeParentDirection) {
192 // statistics->incDerivatedTestedSubsumptionCount(addParentEqConCount*thisPrevEqConCount);
193 // }
194
195 // if (statistics) {
196 // foreach (CHierarchyNode *precNode, predNodeSet) {
197 // if (!parentNode->hasPredecessorNode(precNode) && parentNode != mergeParentDirection) {
198 // statistics->incDerivatedTestedSubsumptionCount(addParentEqConCount*precNode->getEquivalentConceptCount());
199 // }
200 // }
201 // foreach (CHierarchyNode *succNode, succNodeSet) {
202 // if (!parentNode->hasSuccessorNode(succNode)) {
203 // statistics->incDerivatedTestedSubsumptionCount(addParentEqConCount*succNode->getEquivalentConceptCount());
204 // }
205 // }
206 // foreach (CHierarchyNode *incPrecNode, incompPredNodeSet) {
207 // if (!parentNode->hasIncompatiblePredecessorNode(incPrecNode)) {
208 // statistics->incPrunedTestedSubsumptionCount(addParentEqConCount*incPrecNode->getEquivalentConceptCount());
209 // }
210 // }
211 // foreach (CHierarchyNode *incSuccNode, incompSuccNodeSet) {
212 // if (!parentNode->hasIncompatibleSuccessorNode(incSuccNode)) {
213 // statistics->incPrunedTestedSubsumptionCount(addParentEqConCount*incSuccNode->getEquivalentConceptCount());
214 // }
215 // }
216 // }
217
218 // //((CPartialPruningHierarchyNode *)parentNode)->repairChildsParentNodeReplacement(this,statistics);
219
220
221 // QList<CHierarchyNode *> parentList(parentNode->getParentNodeList());
222 // foreach (CHierarchyNode *parentParentNode, parentList) {
223 // parentParentNode->removeChild(parentNode);
224 // parentNode->removeParent(parentParentNode);
225 // if (parentNodeSet.isEmpty()) {
226 // bool bug = true;
227 // }
228 // if (!hasPredecessorNode(parentParentNode)) {
229 // if (statistics && parentParentNode != mergeParentDirection) {
230 // statistics->incDerivatedTestedSubsumptionCount(thisPrevEqConCount*parentParentNode->getEquivalentConceptCount());
231 // }
232 // }
233 // bool oldParPredecessor = false;
234 // foreach (CHierarchyNode* oldParNode, parentNodeSet) {
235 // if (oldParNode == parentParentNode && oldParNode->hasPredecessorNode(parentParentNode)) {
236 // oldParPredecessor = true;
237 // }
238 // }
239 // if (!oldParPredecessor) {
240 // makeParent(parentParentNode);
241 // if (!parentMergeNodesSet.contains(parentParentNode)) {
242 // parentMergeNodesSet.insert(parentParentNode);
243 // parentMergeNodesList.append(parentParentNode);
244 // }
245 // }
246 // }
247
248 // QList<CHierarchyNode *> childList(parentNode->getChildNodeList());
249 // foreach (CHierarchyNode *parentChildNode, childList) {
250 // parentChildNode->removeParent(parentNode);
251 // parentNode->removeChild(parentChildNode);
252 // if (parentNodeSet.isEmpty()) {
253 // bool bug = true;
254 // }
255 // if (parentChildNode != this) {
256 // if (!hasSuccessorNode(parentChildNode)) {
257 // if (statistics) {
258 // statistics->incDerivatedTestedSubsumptionCount(thisPrevEqConCount*parentChildNode->getEquivalentConceptCount());
259 // }
260 // makeChild(parentChildNode);
261 // }
262 // }
263 // }
264
265 // QList<CHierarchyNode *> predList(parentNode->getPredecessorNodeList());
266 // foreach (CHierarchyNode *parentPredeccessorNode, predList) {
267 // parentPredeccessorNode->removeSuccessor(parentNode);
268 // parentNode->removePredecessor(parentPredeccessorNode);
269 // if (!hasPredecessorNode(parentPredeccessorNode)) {
270 // if (statistics && parentPredeccessorNode != mergeParentDirection) {
271 // statistics->incDerivatedTestedSubsumptionCount(thisPrevEqConCount*parentPredeccessorNode->getEquivalentConceptCount());
272 // }
273 // makePredecessor(parentPredeccessorNode);
274 // }
275 // }
276
277 // QSet<CHierarchyNode *> *disjointSet(parentNode->getDisjointNodeSet());
278 // foreach (CHierarchyNode *disjointNode, *disjointSet) {
279 // disjointNode->removeDisjointNode(parentNode);
280 // parentNode->removeDisjointNode(disjointNode);
281 // if (!hasDisjointNode(disjointNode)) {
282 // makeDisjoint(disjointNode);
283 // if (!hasIncompatiblePredecessorNode(disjointNode)) {
284 // if (statistics) {
285 // statistics->incPrunedTestedSubsumptionCount(thisPrevEqConCount*disjointNode->getEquivalentConceptCount());
286 // }
287 // addIncompatiblePredecessorNode(disjointNode);
288 // disjointNode->addIncompatibleSuccessorNode(this);
289 // }
290 // if (!hasIncompatibleSuccessorNode(disjointNode)) {
291 // if (statistics) {
292 // statistics->incPrunedTestedSubsumptionCount(thisPrevEqConCount*disjointNode->getEquivalentConceptCount());
293 // }
294 // addIncompatibleSuccessorNode(disjointNode);
295 // disjointNode->addIncompatiblePredecessorNode(this);
296 // }
297 // }
298 // }
299
300 // QList<CHierarchyNode *> succList(parentNode->getSuccessorNodeList());
301 // foreach (CHierarchyNode *parentSuccessorNode, succList) {
302 // parentSuccessorNode->removePredecessor(parentNode);
303 // parentNode->removeSuccessor(parentSuccessorNode);
304 // if (parentSuccessorNode != this) {
305 // if (!hasSuccessorNode(parentSuccessorNode)) {
306 // if (statistics) {
307 // statistics->incDerivatedTestedSubsumptionCount(thisPrevEqConCount*parentSuccessorNode->getEquivalentConceptCount());
308 // }
309 // makeSuccessor(parentSuccessorNode);
310 // }
311 // }
312 // }
313
314 // QSet<CHierarchyNode *> *incPredList(parentNode->getIncompatiblePredecessorNodeSet());
315 // foreach (CHierarchyNode *parentIncompatiblePredNode, *incPredList) {
316 // parentIncompatiblePredNode->removeIncompatibleSuccessorNode(parentNode);
317 // parentNode->removeIncompatiblePredecessorNode(parentIncompatiblePredNode);
318 // if (!hasIncompatiblePredecessorNode(parentIncompatiblePredNode)) {
319 // if (statistics) {
320 // statistics->incPrunedTestedSubsumptionCount(thisPrevEqConCount*parentIncompatiblePredNode->getEquivalentConceptCount());
321 // }
322 // addIncompatiblePredecessorNode(parentIncompatiblePredNode);
323 // parentIncompatiblePredNode->addIncompatibleSuccessorNode(this);
324 // }
325 // }
326 // QSet<CHierarchyNode *> *incSuccList(parentNode->getIncompatibleSuccessorNodeSet());
327 // foreach (CHierarchyNode *parentIncompatibleSuccNode, *incSuccList) {
328 // parentIncompatibleSuccNode->removeIncompatiblePredecessorNode(parentNode);
329 // parentNode->removeIncompatibleSuccessorNode(parentIncompatibleSuccNode);
330 // if (!hasIncompatibleSuccessorNode(parentIncompatibleSuccNode)) {
331 // if (statistics) {
332 // statistics->incPrunedTestedSubsumptionCount(thisPrevEqConCount*parentIncompatibleSuccNode->getEquivalentConceptCount());
333 // }
334 // addIncompatibleSuccessorNode(parentIncompatibleSuccNode);
335 // parentIncompatibleSuccNode->addIncompatiblePredecessorNode(this);
336 // }
337 // }
338
339
340 // foreach (CHierarchyNode* parNode1, parentNodeSet) {
341 // foreach (CHierarchyNode* parNode2, parentNodeSet) {
342 // if (parNode1 != parNode2 && parNode2->hasPredecessorNode(parNode1)) {
343 // removeParent(parNode1);
344 // parNode1->removeChild(this);
345
346 // if (parentNodeSet.isEmpty()) {
347 // bool bug = true;
348 // }
349
350 // }
351 // }
352 // }
353
354 // foreach (CHierarchyNode* childNode1, childNodeSet) {
355 // foreach (CHierarchyNode* childNode2, childNodeSet) {
356 // if (childNode1 != childNode2 && childNode1->hasPredecessorNode(childNode2)) {
357 // removeChild(childNode1);
358 // childNode1->removeParent(this);
359
360 // if (childNode1->getParentNodeSet()->isEmpty()) {
361 // bool bug = true;
362 // }
363
364 // }
365 // }
366 // }
367
368
369 // } else {
370 // //repairParentNodeInsertion(parentNode,statistics);
371
372 // //((CPartialPruningHierarchyNode *)parentNode)->repairChildsParentNodeReplacement(this,statistics);
373
374 // if (parentNodeSet.isEmpty()) {
375 // bool bug = true;
376 // }
377
378 // }
379 //}
380 #ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS
381 generateNodeStrings();
382 #endif
383 return this;
384 }
385
386 CHierarchyNode *CPartialPruningHierarchyNode::propagateTransitiveRelations(CClassifierStatistics *statistics) {
387 CHierarchyNode *updateNode = this;
388 QSet<CHierarchyNode *> *updateChildNodeSet = getChildNodeSet();
389 QSet<CHierarchyNode *> *updateParentNodeSet = getParentNodeSet();
390 QSet<CHierarchyNode *> *updatePredNodeSet = getPredecessorNodeSet();
391 QSet<CHierarchyNode *> *updateSuccNodeSet = getSuccessorNodeSet();
392 QSet<CHierarchyNode *> *updateDisjointSet = getDisjointNodeSet();
393
394 for (QSet<CHierarchyNode *>::const_iterator itPred = updatePredNodeSet->constBegin(), itPredEnd = updatePredNodeSet->constEnd(); itPred != itPredEnd; ++itPred) {
395 CHierarchyNode *predNode = (*itPred);
396 QList<CHierarchyNode *> updateList;
397 // add missing predecessor nodes to children
398 updateList += getChildNodeList();
399 while (!updateList.isEmpty()) {
400 CHierarchyNode *updateNode = updateList.takeFirst();
401 if (!updateNode->hasPredecessorNode(predNode)) {
402 if (statistics) {
403 statistics->incDerivatedTestedSubsumptionCount(updateNode->getEquivalentConceptCount()*predNode->getEquivalentConceptCount());
404 }
405 updateNode->makePredecessor(predNode);
406 updateList += updateNode->getChildNodeList();
407 }
408 }
409 }
410
411
412 for (QSet<CHierarchyNode *>::const_iterator itDisj = updateDisjointSet->constBegin(), itDisjEnd = updateDisjointSet->constEnd(); itDisj != itDisjEnd; ++itDisj) {
413 CHierarchyNode *disjNode = (*itDisj);
414 QList<CHierarchyNode *> updateList;
415 // add missing disjoint nodes to children
416 updateList += getChildNodeList();
417 while (!updateList.isEmpty()) {
418 CHierarchyNode *updateNode = updateList.takeFirst();
419 if (!updateNode->hasDisjointNode(disjNode)) {
420 updateNode->makeDisjoint(disjNode);
421
422 if (!updateNode->hasIncompatiblePredecessorNode(disjNode)) {
423 if (statistics) {
424 statistics->incPrunedTestedSubsumptionCount(updateNode->getEquivalentConceptCount()*disjNode->getEquivalentConceptCount());
425 }
426 updateNode->makeIncompatiblePredecessor(disjNode);
427 }
428 if (!updateNode->hasIncompatibleSuccessorNode(disjNode)) {
429 if (statistics) {
430 statistics->incPrunedTestedSubsumptionCount(updateNode->getEquivalentConceptCount()*disjNode->getEquivalentConceptCount());
431 }
432 updateNode->makeIncompatibleSuccessor(disjNode);
433 }
434 updateList += updateNode->getChildNodeList();
435 }
436 }
437 }
438
439
440 for (QSet<CHierarchyNode *>::const_iterator itSucc = updateSuccNodeSet->constBegin(), itSuccEnd = updateSuccNodeSet->constEnd(); itSucc != itSuccEnd; ++itSucc) {
441 CHierarchyNode *succNode = (*itSucc);
442 QList<CHierarchyNode *> updateList;
443 // add missing successor nodes to parents
444 updateList += getParentNodeList();
445 while (!updateList.isEmpty()) {
446 CHierarchyNode *updateNode = updateList.takeFirst();
447 if (!updateNode->hasSuccessorNode(succNode)) {
448 if (statistics) {
449 statistics->incDerivatedTestedSubsumptionCount(updateNode->getEquivalentConceptCount()*succNode->getEquivalentConceptCount());
450 }
451 updateNode->makeSuccessor(succNode);
452 updateList += updateNode->getParentNodeList();
453 }
454 }
455 }
456
457 QSet<CHierarchyNode *> *incompSuccNodeSet = getIncompatibleSuccessorNodeSet();
458 for (QSet<CHierarchyNode *>::const_iterator itIncomp = incompSuccNodeSet->constBegin(), itIncompEnd = incompSuccNodeSet->constEnd(); itIncomp != itIncompEnd; ++itIncomp) {
459 CHierarchyNode *incompNode = (*itIncomp);
460 QList<CHierarchyNode *> updateList;
461 // propagate incompatible successor node relations from current node to all children
462 updateList += getChildNodeList();
463 while (!updateList.isEmpty()) {
464 CHierarchyNode *updateNode = updateList.takeFirst();
465 if (!updateNode->hasIncompatibleSuccessorNode(incompNode)) {
466 if (statistics) {
467 statistics->incPrunedTestedSubsumptionCount(updateNode->getEquivalentConceptCount()*incompNode->getEquivalentConceptCount());
468 }
469 updateNode->addIncompatibleSuccessorNode(incompNode);
470 incompNode->addIncompatiblePredecessorNode(updateNode);
471 QSet<CHierarchyNode *> *updateChildNodeSet = updateNode->getChildNodeSet();
472 for (QSet<CHierarchyNode *>::const_iterator itUpChild = updateChildNodeSet->constBegin(), itUpChildEnd = updateChildNodeSet->constEnd(); itUpChild != itUpChildEnd; ++itUpChild) {
473 CHierarchyNode *updateChildNode = (*itUpChild);
474 updateList.append(updateChildNode);
475 }
476 }
477 }
478 }
479
480
481 QSet<CHierarchyNode *> *incompPredNodeSet = getIncompatiblePredecessorNodeSet();
482 for (QSet<CHierarchyNode *>::const_iterator itIncomp = incompPredNodeSet->constBegin(), itIncompEnd = incompPredNodeSet->constEnd(); itIncomp != itIncompEnd; ++itIncomp) {
483 CHierarchyNode *incompNode = (*itIncomp);
484 QList<CHierarchyNode *> updateList;
485 // propagate incompatible predecessor node relations from current node to all parents
486 updateList += getParentNodeList();
487 while (!updateList.isEmpty()) {
488 CHierarchyNode *updateNode = updateList.takeFirst();
489 if (!updateNode->hasIncompatiblePredecessorNode(incompNode)) {
490 if (statistics) {
491 statistics->incPrunedTestedSubsumptionCount(updateNode->getEquivalentConceptCount()*incompNode->getEquivalentConceptCount());
492 }
493 updateNode->addIncompatiblePredecessorNode(incompNode);
494 incompNode->addIncompatibleSuccessorNode(updateNode);
495 QSet<CHierarchyNode *> *updateParentNodeSet = updateNode->getParentNodeSet();
496 for (QSet<CHierarchyNode *>::const_iterator itUpParent = updateParentNodeSet->constBegin(), itUpParentEnd = updateParentNodeSet->constEnd(); itUpParent != itUpParentEnd; ++itUpParent) {
497 CHierarchyNode *updateParentNode = (*itUpParent);
498 updateList.append(updateParentNode);
499 }
500 }
501 }
502 }
503
504
505 //// derivate new incompatible equivalences to parent nodes
506 //for (QSet<CHierarchyNode *>::const_iterator itParent = updateParentNodeSet->constBegin(), itParentEnd = updateParentNodeSet->constEnd(); itParent != itParentEnd; ++itParent) {
507 // CHierarchyNode *parentNode = (*itParent);
508 // if (!hasIncompatibleSuccessorNode(parentNode)) {
509 // for (QSet<CHierarchyNode *>::const_iterator itUpChild = parentNode->getChildNodeSet()->constBegin(), itUpChildEnd = parentNode->getChildNodeSet()->constEnd(); itUpChild != itUpChildEnd; ++itUpChild) {
510 // CHierarchyNode *parentChildNode = (*itUpChild);
511 // if (hasIncompatibleSuccessorNode(parentChildNode) || hasIncompatiblePredecessorNode(parentChildNode)) {
512 // if (statistics) {
513 // statistics->incDerivatedTestedSubsumptionCount(getEquivalentConceptCount()*parentNode->getEquivalentConceptCount());
514 // }
515 // makeIncompatiblePredecessor(parentNode);
516 // }
517 // }
518 // }
519 //}
520
521
522 #ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS
523 generateNodeStrings();
524 #endif
525 return this;
526 }
527
528
529
530 CHierarchyNode *CPartialPruningHierarchyNode::repairChildNodes(CClassifierStatistics *statistics) {
531 foreach (CHierarchyNode* childNode1, childNodeSet) {
532 foreach (CHierarchyNode* childNode2, childNodeSet) {
533 if (childNode1 != childNode2 && childNode1->hasPredecessorNode(childNode2)) {
534 removeChild(childNode1);
535 childNode1->removeParent(this);
536 }
537 }
538 }
539 return this;
540 }
541
542
543 CHierarchyNode *CPartialPruningHierarchyNode::repairParentNodes(CClassifierStatistics *statistics) {
544 foreach (CHierarchyNode* parNode1, parentNodeSet) {
545 foreach (CHierarchyNode* parNode2, parentNodeSet) {
546 if (parNode1 != parNode2 && parNode2->hasPredecessorNode(parNode1)) {
547 removeParent(parNode1);
548 parNode1->removeChild(this);
549 }
550 }
551 }
552 return this;
553 }
554
555
556
557 CHierarchyNode *CPartialPruningHierarchyNode::propagateTransitivePredecessorRelation(CHierarchyNode *transAddPredNode, CClassifierStatistics *statistics) {
558 QList<CHierarchyNode *> updateList;
559 updateList.append(this);
560 while (!updateList.isEmpty()) {
561 CHierarchyNode *updateNode = updateList.takeFirst();
562 QSet<CHierarchyNode *> *updateChildNodeSet = updateNode->getChildNodeSet();
563 QSet<CHierarchyNode *> *updatePredNodeSet = updateNode->getPredecessorNodeSet();
564 for (QSet<CHierarchyNode *>::const_iterator itChild = updateChildNodeSet->constBegin(), itChildEnd = updateChildNodeSet->constEnd(); itChild != itChildEnd; ++itChild) {
565 CHierarchyNode *childNode = (*itChild);
566 if (!childNode->hasPredecessorNode(transAddPredNode)) {
567 if (statistics) {
568 statistics->incDerivatedTestedSubsumptionCount(childNode->getEquivalentConceptCount()*transAddPredNode->getEquivalentConceptCount());
569 }
570 childNode->makePredecessor(transAddPredNode);
571 updateList.append(childNode);
572 }
573 }
574 }
575 #ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS
576 generateNodeStrings();
577 #endif
578 return this;
579 }
580
581
582
583 CHierarchyNode *CPartialPruningHierarchyNode::pruneTransitiveRelations(CHierarchyNode *initIncompNode, CClassifierStatistics *statistics) {
584 for (QSet<CHierarchyNode *>::const_iterator parentIt = initIncompNode->getParentNodeSet()->constBegin(), parentItEnd = initIncompNode->getParentNodeSet()->constEnd(); parentIt != parentItEnd; ++parentIt) {
585 CHierarchyNode *incompNodeParent = (*parentIt);
586 if (!incompNodeParent->hasIncompatiblePredecessorNode(initIncompNode)) {
587 if (hasPredecessorNode(incompNodeParent)) {
588 if (statistics) {
589 statistics->incPrunedTestedSubsumptionCount(incompNodeParent->getEquivalentConceptCount()*initIncompNode->getEquivalentConceptCount());
590 }
591 incompNodeParent->makeIncompatiblePredecessor(initIncompNode);
592 }
593 }
594 }
595 QList<CHierarchyNode *> incompChildNodeList;
596 QSet<CHierarchyNode *> incompNodeSet;
597 incompChildNodeList.append(initIncompNode);
598 incompNodeSet.insert(initIncompNode);
599 while (!incompChildNodeList.isEmpty()) {
600 CHierarchyNode *nextIncompNode = incompChildNodeList.takeFirst();
601 QSet<CHierarchyNode *> *incNodeSet = nextIncompNode->getChildNodeSet();
602 for (QSet<CHierarchyNode *>::const_iterator childIt = incNodeSet->constBegin(), childItEnd = incNodeSet->constEnd(); childIt != childItEnd; ++childIt) {
603 CHierarchyNode *childIncompNode = (*childIt);
604 if (!hasIncompatiblePredecessorNode(childIncompNode)) {
605 if (!incompNodeSet.contains(childIncompNode)) {
606 incompNodeSet.insert(childIncompNode);
607 incompChildNodeList.append(childIncompNode);
608 }
609 }
610 }
611 }
612 QList<CHierarchyNode *> predList;
613 for (QSet<CHierarchyNode *>::const_iterator incompIt = incompNodeSet.constBegin(), incompItEnd = incompNodeSet.constEnd(); incompIt != incompItEnd; ++incompIt) {
614 CHierarchyNode *incompNode = (*incompIt);
615 // set incompatible to all predecessors
616 predList.append(this);
617 while (!predList.isEmpty()) {
618 CHierarchyNode *predNode = predList.takeFirst();
619 if (!predNode->hasIncompatiblePredecessorNode(incompNode)) {
620 if (statistics) {
621 statistics->incPrunedTestedSubsumptionCount(predNode->getEquivalentConceptCount()*incompNode->getEquivalentConceptCount());
622 }
623 predNode->addIncompatiblePredecessorNode(incompNode);
624 incompNode->addIncompatibleSuccessorNode(predNode);
625 QSet<CHierarchyNode *> *parentNodeSet = predNode->getParentNodeSet();
626 for (QSet<CHierarchyNode *>::const_iterator parentIt = parentNodeSet->constBegin(), parentItEnd = parentNodeSet->constEnd(); parentIt != parentItEnd; ++parentIt) {
627 CHierarchyNode *parentNode = (*parentIt);
628 predList.append(parentNode);
629 }
630 }
631 }
632 }
633
634 #ifdef DEBUGHIERARCHYNODECONCEPTSTRINGS
635 generateNodeStrings();
636 #endif
637 return this;
638 }
639
640
641 }; // end namespace Classifier
642
643 }; // end namespace Reasoner
644
645 }; // end namespace Konclude