| 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 "CNegationTransformationPreProcess.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Preprocess { |
| 29 |
|
| 30 |
|
| 31 |
CNegationTransformationPreProcess::CNegationTransformationPreProcess() { |
| 32 |
mLastConceptId = 0; |
| 33 |
mLastRoleId = 0; |
| 34 |
mLastIndiId = 0; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
CNegationTransformationPreProcess::~CNegationTransformationPreProcess() { |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
CConcreteOntology *CNegationTransformationPreProcess::preprocess(CConcreteOntology *ontology, CPreProcessContext* context) { |
| 43 |
|
| 44 |
mOntology = ontology; |
| 45 |
mLastConceptId = 0; |
| 46 |
mLastRoleId = 0; |
| 47 |
mLastIndiId = 0; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
return continuePreprocessing(); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
CConcreteOntology* CNegationTransformationPreProcess::continuePreprocessing() { |
| 56 |
if (mOntology) { |
| 57 |
CTBox* tbox = mOntology->getDataBoxes()->getTBox(); |
| 58 |
CABox *abox = mOntology->getDataBoxes()->getABox(); |
| 59 |
CRBox *rbox = mOntology->getDataBoxes()->getRBox(); |
| 60 |
|
| 61 |
CConceptVector *concepts = tbox->getConceptVector(); |
| 62 |
qint64 itemConCounts = concepts->getItemCount(); |
| 63 |
for (qint64 i = mLastConceptId; i < itemConCounts; ++i) { |
| 64 |
CConcept *concept = concepts->getLocalData(i); |
| 65 |
|
| 66 |
if (concept && concept->getOperatorCode() != CCNOT) { |
| 67 |
|
| 68 |
CSortedNegLinker<CConcept *> *operands = concept->getOperandList(); |
| 69 |
while (operands) { |
| 70 |
while (operands->getData()->getDefinitionOperatorTag() == CCNOT) { |
| 71 |
CConcept *compConcept = operands->getData()->getOperandList()->getData(); |
| 72 |
operands->setData(compConcept); |
| 73 |
operands->setNegated(!operands->isNegated()); |
| 74 |
} |
| 75 |
operands = operands->getNext(); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
mLastConceptId = itemConCounts; |
| 80 |
|
| 81 |
|
| 82 |
CRoleVector *roles = rbox->getRoleVector(); |
| 83 |
qint64 itemRolCounts = roles->getItemCount(); |
| 84 |
for (qint64 i = mLastRoleId; i < itemRolCounts; ++i) { |
| 85 |
CRole *role = roles->getLocalData(i); |
| 86 |
|
| 87 |
if (role) { |
| 88 |
|
| 89 |
CSortedNegLinker<CConcept *> *operandsDomIt = role->getDomainConceptList(); |
| 90 |
while (operandsDomIt) { |
| 91 |
while (operandsDomIt->getData()->getDefinitionOperatorTag() == CCNOT) { |
| 92 |
CConcept *compConcept = operandsDomIt->getData()->getOperandList()->getData(); |
| 93 |
operandsDomIt->setData(compConcept); |
| 94 |
operandsDomIt->setNegated(!operandsDomIt->isNegated()); |
| 95 |
} |
| 96 |
operandsDomIt = operandsDomIt->getNext(); |
| 97 |
} |
| 98 |
|
| 99 |
CSortedNegLinker<CConcept *> *operandsRanIt = role->getRangeConceptList(); |
| 100 |
while (operandsRanIt) { |
| 101 |
while (operandsRanIt->getData()->getDefinitionOperatorTag() == CCNOT) { |
| 102 |
CConcept *compConcept = operandsRanIt->getData()->getOperandList()->getData(); |
| 103 |
operandsRanIt->setData(compConcept); |
| 104 |
operandsRanIt->setNegated(!operandsRanIt->isNegated()); |
| 105 |
} |
| 106 |
operandsRanIt = operandsRanIt->getNext(); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
mLastRoleId = itemRolCounts; |
| 111 |
|
| 112 |
CIndividualVector *indis = abox->getIndividualVector(); |
| 113 |
qint64 itemIndiCounts = indis->getItemCount(); |
| 114 |
for (qint64 i = mLastIndiId; i < itemIndiCounts; ++i) { |
| 115 |
CIndividual *indi = indis->getLocalData(i); |
| 116 |
|
| 117 |
if (indi) { |
| 118 |
for (CConceptAssertionLinker* conAssLinkerIt = indi->getAssertionConceptLinker(); conAssLinkerIt; conAssLinkerIt = conAssLinkerIt->getNext()) { |
| 119 |
CConcept *compConcept = conAssLinkerIt->getData(); |
| 120 |
if (compConcept->getDefinitionOperatorTag() == CCNOT) { |
| 121 |
conAssLinkerIt->setData(compConcept->getOperandList()->getData()); |
| 122 |
conAssLinkerIt->setNegation(!conAssLinkerIt->getNegation()); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
mLastIndiId = itemIndiCounts; |
| 128 |
} |
| 129 |
return mOntology; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
}; // end namespace Preprocess |
| 134 |
|
| 135 |
}; // end namespace Reasoner |
| 136 |
|
| 137 |
}; // end namespace Konclude |