| 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 "CPrecomputedSaturationSubsumerExtractor.h" |
| 22 |
|
| 23 |
namespace Konclude { |
| 24 |
|
| 25 |
namespace Reasoner { |
| 26 |
|
| 27 |
namespace Classifier { |
| 28 |
|
| 29 |
|
| 30 |
CPrecomputedSaturationSubsumerExtractor::CPrecomputedSaturationSubsumerExtractor(CConcreteOntology* ontology) { |
| 31 |
mSatCalcTask = nullptr; |
| 32 |
mOntology = ontology; |
| 33 |
CSaturationData* saturationData = mOntology->getPrecomputation()->getSaturationModelData(); |
| 34 |
CSaturationTaskData* saturationTaskData = (CSaturationTaskData*)saturationData; |
| 35 |
if (saturationTaskData) { |
| 36 |
mSatCalcTask = saturationTaskData->getSaturationTask(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
bool CPrecomputedSaturationSubsumerExtractor::extractSubsumers(CConcept* concept, CConceptSubsumerObserver* subsumerObserver, bool* possibleSubsumerFlag, CIndividualDependenceTrackingObserver* indDepTrackingObserver, CIndividualDependenceTrackingMarker* indiDepTrackMarker) { |
| 41 |
if (mSatCalcTask) { |
| 42 |
CProcessingDataBox* procDataBox = mSatCalcTask->getProcessingDataBox(); |
| 43 |
CConceptProcessData* conProData = (CConceptProcessData*)concept->getConceptData(); |
| 44 |
if (conProData) { |
| 45 |
CConceptSaturationReferenceLinkingData* conSatRefLinking = (CConceptSaturationReferenceLinkingData*)conProData->getConceptReferenceLinking(); |
| 46 |
if (conSatRefLinking) { |
| 47 |
CSaturationConceptReferenceLinking* saturationConceptRefLinkingData = (CSaturationConceptReferenceLinking*)conSatRefLinking->getPositiveConceptSaturationReferenceLinkingData(); |
| 48 |
if (saturationConceptRefLinkingData) { |
| 49 |
CIndividualSaturationProcessNode* baseIndiNode = (CIndividualSaturationProcessNode*)saturationConceptRefLinkingData->getIndividualProcessNodeForConcept(); |
| 50 |
if (baseIndiNode) { |
| 51 |
CIndividualSaturationProcessNode* indiNode = baseIndiNode; |
| 52 |
while (indiNode->hasSubstituteIndividualNode()) { |
| 53 |
if (indiNode != baseIndiNode) { |
| 54 |
CSaturationConceptDataItem* subsumerSatConDataItem = (CSaturationConceptDataItem*)indiNode->getSaturationConceptReferenceLinking(); |
| 55 |
if (!subsumerSatConDataItem->getSaturationNegation() && !subsumerSatConDataItem->getSaturationRoleRanges()) { |
| 56 |
CConcept* subsumerConcept = subsumerSatConDataItem->getSaturationConcept(); |
| 57 |
if (subsumerConcept != concept && subsumerConcept->hasClassName()) { |
| 58 |
subsumerObserver->tellConceptSupsumption(concept,subsumerConcept); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
indiNode = indiNode->getSubstituteIndividualNode(); |
| 63 |
} |
| 64 |
CReapplyConceptSaturationLabelSet* conSet = indiNode->getReapplyConceptSaturationLabelSet(false); |
| 65 |
if (conSet) { |
| 66 |
for (CConceptSaturationDescriptor* conSatDesIt = conSet->getConceptSaturationDescriptionLinker(); conSatDesIt; conSatDesIt = conSatDesIt->getNext()) { |
| 67 |
if (!conSatDesIt->isNegated()) { |
| 68 |
CConcept* subsumerConcept = conSatDesIt->getConcept(); |
| 69 |
if (subsumerConcept != concept && subsumerConcept->hasClassName()) { |
| 70 |
subsumerObserver->tellConceptSupsumption(concept,subsumerConcept); |
| 71 |
} else { |
| 72 |
if (subsumerConcept->getOperatorCode() == CCEQCAND) { |
| 73 |
CIndividualSaturationProcessNodeStatusFlags* directFlags = indiNode->getDirectStatusFlags(); |
| 74 |
if (directFlags->hasEQCandidateProplematicFlag()) { |
| 75 |
if (possibleSubsumerFlag) { |
| 76 |
*possibleSubsumerFlag = true; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
if (indiDepTrackMarker) { |
| 85 |
CSuccessorConnectedNominalSet* succConnNomSet = indiNode->getSuccessorConnectedNominalSet(false); |
| 86 |
if (succConnNomSet) { |
| 87 |
indiDepTrackMarker->setIndividualDependenceTracked(); |
| 88 |
} |
| 89 |
} |
| 90 |
if (indDepTrackingObserver) { |
| 91 |
CSuccessorConnectedNominalSet* succConnNomSet = indiNode->getSuccessorConnectedNominalSet(false); |
| 92 |
if (succConnNomSet) { |
| 93 |
CIndividualDependenceTracking* indiDepTracking = indDepTrackingObserver->getExtendingIndividualDependenceTracking(); |
| 94 |
CReferredIndividualTrackingVector* refIndiDepTrackVec = nullptr; |
| 95 |
if (indiDepTracking) { |
| 96 |
refIndiDepTrackVec = dynamic_cast<CReferredIndividualTrackingVector*>(indiDepTracking); |
| 97 |
} |
| 98 |
if (!refIndiDepTrackVec) { |
| 99 |
cint64 aboxIndiCount = mOntology->getABox()->getIndividualCount(); |
| 100 |
cint64 trackIndiCount = aboxIndiCount; |
| 101 |
CConsistenceData* consData = mOntology->getConsistence()->getConsistenceModelData(); |
| 102 |
if (consData) { |
| 103 |
CConsistenceTaskData* consTaskData = dynamic_cast<CConsistenceTaskData*>(consData); |
| 104 |
if (consTaskData) { |
| 105 |
CSatisfiableCalculationTask* cachedSatTask = consTaskData->getDeterministicSatisfiableTask(); |
| 106 |
if (cachedSatTask) { |
| 107 |
trackIndiCount = qMax(trackIndiCount,cachedSatTask->getProcessingDataBox()->getIndividualProcessNodeVector()->getItemCount()); |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
refIndiDepTrackVec = new CReferredIndividualTrackingVector(); |
| 112 |
refIndiDepTrackVec->initReferredIndividualTrackingVector(trackIndiCount,aboxIndiCount); |
| 113 |
refIndiDepTrackVec = dynamic_cast<CReferredIndividualTrackingVector*>(indDepTrackingObserver->installIndividualDependenceTracking(refIndiDepTrackVec)); |
| 114 |
} |
| 115 |
if (refIndiDepTrackVec) { |
| 116 |
for (CSuccessorConnectedNominalSet::const_iterator it = succConnNomSet->constBegin(), itEnd = succConnNomSet->constEnd(); it != itEnd; ++it) { |
| 117 |
cint64 nominalIndiID(*it); |
| 118 |
refIndiDepTrackVec->setIndividualReferred(nominalIndiID); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
return true; |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
return false; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
cint64 CPrecomputedSaturationSubsumerExtractor::getSubsumerCount(CConcept* concept) { |
| 135 |
cint64 subsumerCount = 0; |
| 136 |
if (mSatCalcTask) { |
| 137 |
CProcessingDataBox* procDataBox = mSatCalcTask->getProcessingDataBox(); |
| 138 |
CConceptProcessData* conProData = (CConceptProcessData*)concept->getConceptData(); |
| 139 |
if (conProData) { |
| 140 |
CConceptSaturationReferenceLinkingData* conSatRefLinking = (CConceptSaturationReferenceLinkingData*)conProData->getConceptReferenceLinking(); |
| 141 |
if (conSatRefLinking) { |
| 142 |
CSaturationConceptReferenceLinking* saturationConceptRefLinkingData = (CSaturationConceptReferenceLinking*)conSatRefLinking->getPositiveConceptSaturationReferenceLinkingData(); |
| 143 |
if (saturationConceptRefLinkingData) { |
| 144 |
CIndividualSaturationProcessNode* baseIndiNode = (CIndividualSaturationProcessNode*)saturationConceptRefLinkingData->getIndividualProcessNodeForConcept(); |
| 145 |
if (baseIndiNode) { |
| 146 |
CIndividualSaturationProcessNode* indiNode = baseIndiNode; |
| 147 |
while (indiNode->hasSubstituteIndividualNode()) { |
| 148 |
if (indiNode != baseIndiNode) { |
| 149 |
CSaturationConceptDataItem* subsumerSatConDataItem = (CSaturationConceptDataItem*)indiNode->getSaturationConceptReferenceLinking(); |
| 150 |
if (!subsumerSatConDataItem->getSaturationNegation() && !subsumerSatConDataItem->getSaturationRoleRanges()) { |
| 151 |
CConcept* subsumerConcept = subsumerSatConDataItem->getSaturationConcept(); |
| 152 |
if (subsumerConcept != concept && subsumerConcept->hasClassName()) { |
| 153 |
++subsumerCount; |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
indiNode = indiNode->getSubstituteIndividualNode(); |
| 158 |
} |
| 159 |
CReapplyConceptSaturationLabelSet* conSet = indiNode->getReapplyConceptSaturationLabelSet(false); |
| 160 |
if (conSet) { |
| 161 |
for (CConceptSaturationDescriptor* conSatDesIt = conSet->getConceptSaturationDescriptionLinker(); conSatDesIt; conSatDesIt = conSatDesIt->getNext()) { |
| 162 |
if (!conSatDesIt->isNegated()) { |
| 163 |
CConcept* subsumerConcept = conSatDesIt->getConcept(); |
| 164 |
if (subsumerConcept != concept && subsumerConcept->hasClassName()) { |
| 165 |
++subsumerCount; |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
return subsumerCount; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
bool CPrecomputedSaturationSubsumerExtractor::hasSubsumerConcept(CConcept* concept, CConcept* testSubsumerConcept) { |
| 181 |
if (mSatCalcTask) { |
| 182 |
CProcessingDataBox* procDataBox = mSatCalcTask->getProcessingDataBox(); |
| 183 |
CConceptProcessData* conProData = (CConceptProcessData*)concept->getConceptData(); |
| 184 |
if (conProData) { |
| 185 |
CConceptSaturationReferenceLinkingData* conSatRefLinking = (CConceptSaturationReferenceLinkingData*)conProData->getConceptReferenceLinking(); |
| 186 |
if (conSatRefLinking) { |
| 187 |
CSaturationConceptReferenceLinking* saturationConceptRefLinkingData = (CSaturationConceptReferenceLinking*)conSatRefLinking->getPositiveConceptSaturationReferenceLinkingData(); |
| 188 |
if (saturationConceptRefLinkingData) { |
| 189 |
CIndividualSaturationProcessNode* baseIndiNode = (CIndividualSaturationProcessNode*)saturationConceptRefLinkingData->getIndividualProcessNodeForConcept(); |
| 190 |
if (baseIndiNode) { |
| 191 |
CIndividualSaturationProcessNode* indiNode = baseIndiNode; |
| 192 |
while (indiNode->hasSubstituteIndividualNode()) { |
| 193 |
if (indiNode != baseIndiNode) { |
| 194 |
CSaturationConceptDataItem* subsumerSatConDataItem = (CSaturationConceptDataItem*)indiNode->getSaturationConceptReferenceLinking(); |
| 195 |
if (!subsumerSatConDataItem->getSaturationNegation() && !subsumerSatConDataItem->getSaturationRoleRanges()) { |
| 196 |
CConcept* subsumerConcept = subsumerSatConDataItem->getSaturationConcept(); |
| 197 |
if (subsumerConcept == testSubsumerConcept) { |
| 198 |
return true; |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
indiNode = indiNode->getSubstituteIndividualNode(); |
| 203 |
} |
| 204 |
CReapplyConceptSaturationLabelSet* conSet = indiNode->getReapplyConceptSaturationLabelSet(false); |
| 205 |
if (conSet) { |
| 206 |
if (conSet->containsConcept(testSubsumerConcept,false)) { |
| 207 |
return true; |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
return false; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
CConcept* CPrecomputedSaturationSubsumerExtractor::getDirectSubsumerCount(CConcept* concept, bool (*isDirectSubsumer)(CConcept*, CConcept*)) { |
| 221 |
if (mSatCalcTask) { |
| 222 |
CProcessingDataBox* procDataBox = mSatCalcTask->getProcessingDataBox(); |
| 223 |
CConceptProcessData* conProData = (CConceptProcessData*)concept->getConceptData(); |
| 224 |
if (conProData) { |
| 225 |
CConceptSaturationReferenceLinkingData* conSatRefLinking = (CConceptSaturationReferenceLinkingData*)conProData->getConceptReferenceLinking(); |
| 226 |
if (conSatRefLinking) { |
| 227 |
CSaturationConceptReferenceLinking* saturationConceptRefLinkingData = (CSaturationConceptReferenceLinking*)conSatRefLinking->getPositiveConceptSaturationReferenceLinkingData(); |
| 228 |
if (saturationConceptRefLinkingData) { |
| 229 |
CIndividualSaturationProcessNode* baseIndiNode = (CIndividualSaturationProcessNode*)saturationConceptRefLinkingData->getIndividualProcessNodeForConcept(); |
| 230 |
if (baseIndiNode) { |
| 231 |
CIndividualSaturationProcessNode* indiNode = baseIndiNode; |
| 232 |
while (indiNode->hasSubstituteIndividualNode()) { |
| 233 |
if (indiNode != baseIndiNode) { |
| 234 |
CSaturationConceptDataItem* subsumerSatConDataItem = (CSaturationConceptDataItem*)indiNode->getSaturationConceptReferenceLinking(); |
| 235 |
if (!subsumerSatConDataItem->getSaturationNegation() && !subsumerSatConDataItem->getSaturationRoleRanges()) { |
| 236 |
CConcept* subsumerConcept = subsumerSatConDataItem->getSaturationConcept(); |
| 237 |
if (subsumerConcept != concept && subsumerConcept->hasClassName()) { |
| 238 |
if (isDirectSubsumer(concept,subsumerConcept)) { |
| 239 |
return subsumerConcept; |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
indiNode = indiNode->getSubstituteIndividualNode(); |
| 245 |
} |
| 246 |
CReapplyConceptSaturationLabelSet* conSet = indiNode->getReapplyConceptSaturationLabelSet(false); |
| 247 |
if (conSet) { |
| 248 |
for (CConceptSaturationDescriptor* conSatDesIt = conSet->getConceptSaturationDescriptionLinker(); conSatDesIt; conSatDesIt = conSatDesIt->getNext()) { |
| 249 |
if (!conSatDesIt->isNegated()) { |
| 250 |
CConcept* subsumerConcept = conSatDesIt->getConcept(); |
| 251 |
if (subsumerConcept != concept && subsumerConcept->hasClassName()) { |
| 252 |
if (isDirectSubsumer(concept,subsumerConcept)) { |
| 253 |
return subsumerConcept; |
| 254 |
} |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
} |
| 264 |
return nullptr; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
bool CPrecomputedSaturationSubsumerExtractor::getConceptFlags(CConcept* concept, bool* unsatisfiableFlag, bool* insufficientFlag, bool* incompleteProcessedFlag) { |
| 269 |
if (mSatCalcTask) { |
| 270 |
CProcessingDataBox* procDataBox = mSatCalcTask->getProcessingDataBox(); |
| 271 |
CConceptProcessData* conProData = (CConceptProcessData*)concept->getConceptData(); |
| 272 |
if (conProData) { |
| 273 |
CConceptSaturationReferenceLinkingData* conSatRefLinking = (CConceptSaturationReferenceLinkingData*)conProData->getConceptReferenceLinking(); |
| 274 |
if (conSatRefLinking) { |
| 275 |
CSaturationConceptReferenceLinking* saturationConceptRefLinkingData = (CSaturationConceptReferenceLinking*)conSatRefLinking->getPositiveConceptSaturationReferenceLinkingData(); |
| 276 |
if (saturationConceptRefLinkingData) { |
| 277 |
CIndividualSaturationProcessNode* baseIndiNode = (CIndividualSaturationProcessNode*)saturationConceptRefLinkingData->getIndividualProcessNodeForConcept(); |
| 278 |
if (baseIndiNode) { |
| 279 |
CIndividualSaturationProcessNode* indiNode = baseIndiNode; |
| 280 |
while (indiNode->hasSubstituteIndividualNode()) { |
| 281 |
indiNode = indiNode->getSubstituteIndividualNode(); |
| 282 |
} |
| 283 |
CIndividualSaturationProcessNodeStatusFlags* baseFlags = baseIndiNode->getIndirectStatusFlags(); |
| 284 |
CIndividualSaturationProcessNodeStatusFlags* flags = indiNode->getIndirectStatusFlags(); |
| 285 |
if ((baseFlags->hasClashedFlag() || flags->hasClashedFlag()) && unsatisfiableFlag) { |
| 286 |
*unsatisfiableFlag = true; |
| 287 |
} |
| 288 |
if ((baseFlags->hasInsufficientFlag() || flags->hasInsufficientFlag()) && insufficientFlag) { |
| 289 |
*insufficientFlag = true; |
| 290 |
} |
| 291 |
if ((baseFlags->hasUnprocessedFlag() || flags->hasUnprocessedFlag()) && incompleteProcessedFlag) { |
| 292 |
*incompleteProcessedFlag = true; |
| 293 |
} |
| 294 |
return true; |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
return false; |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
}; // end namespace Classifier |
| 305 |
|
| 306 |
}; // end namespace Reasoner |
| 307 |
|
| 308 |
}; // end namespace Konclude |