| 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 "COntologyInspector.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Ontology { |
| 29 |
|
| 30 |
|
| 31 |
COntologyInspector::COntologyInspector() { |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
COntologyInspector::~COntologyInspector() { |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
COntologyStructureSummary *COntologyInspector::createStructureSummary(CConcreteOntology *ontology) { |
| 40 |
COntologyStructureSummary *ontStrSum = inspectOntology(ontology); |
| 41 |
if (ontStrSum) { |
| 42 |
ontology->setStructureSummary(ontStrSum); |
| 43 |
} |
| 44 |
return ontStrSum; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
CBOXSET<CConcept*> *COntologyInspector::createConceptContainsSet(CConcept *concept, CTBox *tBox, CBOXSET<CConcept*> *containsSet) { |
| 49 |
if (!containsSet) { |
| 50 |
containsSet = new CBOXSET<CConcept*>(); |
| 51 |
} |
| 52 |
QList<CConcept *> checkList; |
| 53 |
checkList.append(concept); |
| 54 |
CSortedNegLinker<CConcept *> *conIt = 0; |
| 55 |
while (!checkList.isEmpty()) { |
| 56 |
CConcept *checkConcept = checkList.takeFirst(); |
| 57 |
if (!containsSet->contains(checkConcept)) { |
| 58 |
containsSet->insert(checkConcept); |
| 59 |
// collect new dependencies |
| 60 |
CRole *role = checkConcept->getRole(); |
| 61 |
if (role) { |
| 62 |
CSortedNegLinker<CRole *> *superRoleIt = role->getIndirectSuperRoleList(); |
| 63 |
while (superRoleIt) { |
| 64 |
CRole *superRole = superRoleIt->getData(); |
| 65 |
conIt = superRole->getDomainConceptList(); |
| 66 |
while (conIt) { |
| 67 |
CConcept *con = conIt->getData(); |
| 68 |
checkList.append(con); |
| 69 |
conIt = conIt->getNext(); |
| 70 |
} |
| 71 |
conIt = superRole->getRangeConceptList(); |
| 72 |
while (conIt) { |
| 73 |
CConcept *con = conIt->getData(); |
| 74 |
checkList.append(con); |
| 75 |
conIt = conIt->getNext(); |
| 76 |
} |
| 77 |
superRoleIt = superRoleIt->getNext(); |
| 78 |
} |
| 79 |
} |
| 80 |
conIt = checkConcept->getOperandList(); |
| 81 |
while (conIt) { |
| 82 |
CConcept *con = conIt->getData(); |
| 83 |
checkList.append(con); |
| 84 |
conIt = conIt->getNext(); |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
return containsSet; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
COntologyInspector *COntologyInspector::createGCIConceptSet(CTBox *tBox) { |
| 93 |
CConceptVector *conVec = tBox->getConceptVector(); |
| 94 |
qint64 conCount = conVec->getItemCount(); |
| 95 |
CConcept *topCon = conVec->getData(1); |
| 96 |
if (topCon) { |
| 97 |
CContext* tBoxContext = tBox->getBoxContext(); |
| 98 |
CBOXSET<CConcept*> *gciContainsSet = createConceptContainsSet(topCon,tBox,CObjectParameterizingAllocator< CBOXSET<CConcept*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(tBoxContext),tBoxContext)); |
| 99 |
tBox->setGCIConceptSet(gciContainsSet); |
| 100 |
} |
| 101 |
return this; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
COntologyStructureSummary* COntologyInspector::inspectConcept(CConcreteOntology *ontology, CConcept* concept, bool negation, COntologyStructureSummary *ontStructSum) { |
| 106 |
qint64 conOpTag = concept->getDefinitionOperatorTag(); |
| 107 |
bool isClass = concept->hasClassName(); |
| 108 |
bool opCount = concept->getOperandCount() > 0; |
| 109 |
cint64 parm = concept->getParameter(); |
| 110 |
CSortedNegLinker<CConcept*>* opLinker = concept->getOperandList(); |
| 111 |
for (CSortedNegLinker<CConcept*>* opLinkerIt = opLinker; opLinkerIt; opLinkerIt = opLinkerIt->getNext()) { |
| 112 |
if (opLinkerIt->isNegated()) { |
| 113 |
CConcept* opConcept = opLinkerIt->getData(); |
| 114 |
CConceptOperator* conOperator = opConcept->getConceptOperator(); |
| 115 |
if (!conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_TRIG_TYPE)) { |
| 116 |
ontStructSum->setNegationDisjunctionsOccurrence(); |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
CRole* role = concept->getRole(); |
| 121 |
if (role && role->isDataRole()) { |
| 122 |
ontStructSum->setDatatypeOccurrence(); |
| 123 |
} |
| 124 |
if (isClass) { |
| 125 |
ontStructSum->incClassCount(); |
| 126 |
} |
| 127 |
if (conOpTag == CCATOM) { |
| 128 |
ontStructSum->incPrimitiveConceptCount(); |
| 129 |
if (isClass) { |
| 130 |
ontStructSum->incAtomicClassCount(); |
| 131 |
} |
| 132 |
} else { |
| 133 |
ontStructSum->incComplexConceptCount(); |
| 134 |
if (isClass) { |
| 135 |
ontStructSum->incComplexClassCount(); |
| 136 |
} |
| 137 |
if (conOpTag == CCPBINDGROUND || conOpTag == CCNOMTEMPLREF || conOpTag == CCVARBINDGROUND) { |
| 138 |
ontStructSum->setGroundingOccurrence(); |
| 139 |
} else if (conOpTag == CCNOT) { |
| 140 |
ontStructSum->incConceptNegCount(); |
| 141 |
ontStructSum->setNegationDisjunctionsOccurrence(); |
| 142 |
} else if (conOpTag == CCAND) { |
| 143 |
ontStructSum->incConceptIntersectionCount(); |
| 144 |
} else if (conOpTag == CCOR) { |
| 145 |
ontStructSum->incConceptUnionCount(); |
| 146 |
ontStructSum->setNegationDisjunctionsOccurrence(); |
| 147 |
} else if (conOpTag == CCATMOST) { |
| 148 |
ontStructSum->incConceptAtmostCount(); |
| 149 |
if (opCount) { |
| 150 |
ontStructSum->incConceptQualifiedAtmostCount(); |
| 151 |
} else { |
| 152 |
ontStructSum->incConceptNotQualifiedAtmostCount(); |
| 153 |
} |
| 154 |
if (parm == 1) { |
| 155 |
ontStructSum->setFunctionalityOccurrence(); |
| 156 |
ontStructSum->incConceptFunctionalAtmostCount(); |
| 157 |
} else if (opCount) { |
| 158 |
ontStructSum->setQualifiedCardinalityOccurrence(); |
| 159 |
} else { |
| 160 |
ontStructSum->setCardinalityOccurrence(); |
| 161 |
} |
| 162 |
} else if (conOpTag == CCATLEAST) { |
| 163 |
ontStructSum->setExistensialOccurrence(); |
| 164 |
ontStructSum->incConceptAtleastCount(); |
| 165 |
if (opCount) { |
| 166 |
ontStructSum->incConceptQualifiedAtleastCount(); |
| 167 |
if (parm != 1) { |
| 168 |
ontStructSum->setQualifiedCardinalityOccurrence(); |
| 169 |
} |
| 170 |
} else { |
| 171 |
ontStructSum->incConceptNotQualifiedAtleastCount(); |
| 172 |
if (parm != 1) { |
| 173 |
ontStructSum->setCardinalityOccurrence(); |
| 174 |
} |
| 175 |
} |
| 176 |
} else if (conOpTag == CCALL) { |
| 177 |
ontStructSum->incConceptOnlyCount(); |
| 178 |
ontStructSum->setExistensialOccurrence(); |
| 179 |
} else if (conOpTag == CCSOME || conOpTag == CCAQSOME) { |
| 180 |
ontStructSum->incConceptSomeCount(); |
| 181 |
ontStructSum->setExistensialOccurrence(); |
| 182 |
} else if (conOpTag == CCEQ) { |
| 183 |
ontStructSum->setNegationDisjunctionsOccurrence(); |
| 184 |
ontStructSum->incConceptEquivalenceCount(); |
| 185 |
} else if (conOpTag == CCSUB) { |
| 186 |
ontStructSum->incConceptSubclassCount(); |
| 187 |
} else if (conOpTag == CCVALUE) { |
| 188 |
ontStructSum->incConceptValueCount(); |
| 189 |
ontStructSum->setNominalIndividualOccurrence(); |
| 190 |
} else if (conOpTag == CCNOMINAL) { |
| 191 |
ontStructSum->incConceptNominalIndividualCount(); |
| 192 |
ontStructSum->setNominalIndividualOccurrence(); |
| 193 |
ontStructSum->setNegationDisjunctionsOccurrence(); |
| 194 |
} else if (conOpTag == CCSELF) { |
| 195 |
ontStructSum->incConceptSelfCount(); |
| 196 |
} else if (conOpTag == CCDATATYPE || CCDATALITERAL || CCDATARESTRICTION) { |
| 197 |
} |
| 198 |
} |
| 199 |
return ontStructSum; |
| 200 |
} |
| 201 |
|
| 202 |
COntologyStructureSummary *COntologyInspector::inspectOntology(CConcreteOntology *ontology) { |
| 203 |
COntologyStructureSummary *ontStructSum = new COntologyStructureSummary(); |
| 204 |
|
| 205 |
CRBox *rBox = ontology->getDataBoxes()->getRBox(); |
| 206 |
CRoleVector *roleVec = rBox->getRoleVector(); |
| 207 |
qint64 roleCount = roleVec->getItemCount(); |
| 208 |
for (qint64 index = 0; index < roleCount; ++index) { |
| 209 |
CRole* role = roleVec->getData(index); |
| 210 |
if (role) { |
| 211 |
CSortedNegLinker<CRole*>* invEqRoleLinkerIt = role->getInverseEquivalentRoleList(); |
| 212 |
while (invEqRoleLinkerIt) { |
| 213 |
bool neg = invEqRoleLinkerIt->isNegated(); |
| 214 |
CRole* inEqRole = invEqRoleLinkerIt->getData(); |
| 215 |
if (neg) { |
| 216 |
ontStructSum->setInverseOccurrence(); |
| 217 |
ontStructSum->incRoleInverseCount(); |
| 218 |
} else { |
| 219 |
ontStructSum->incRoleEquivalenceCount(); |
| 220 |
} |
| 221 |
invEqRoleLinkerIt = invEqRoleLinkerIt->getNext(); |
| 222 |
} |
| 223 |
CSortedNegLinker<CRole*>* disRoleLinkerIt = role->getDisjointRoleList(); |
| 224 |
while (disRoleLinkerIt) { |
| 225 |
ontStructSum->incRoleDisjointCount(); |
| 226 |
disRoleLinkerIt = disRoleLinkerIt->getNext(); |
| 227 |
} |
| 228 |
CSortedNegLinker<CConcept*>* domConLinkerIt = role->getDomainConceptList(); |
| 229 |
while (domConLinkerIt) { |
| 230 |
ontStructSum->incRoleDomainConceptCount(); |
| 231 |
domConLinkerIt = domConLinkerIt->getNext(); |
| 232 |
} |
| 233 |
CSortedNegLinker<CConcept*>* rangeConLinkerIt = role->getRangeConceptList(); |
| 234 |
while (rangeConLinkerIt) { |
| 235 |
ontStructSum->incRoleRangeConceptCount(); |
| 236 |
rangeConLinkerIt = rangeConLinkerIt->getNext(); |
| 237 |
} |
| 238 |
if (role->isAsymmetric()) { |
| 239 |
ontStructSum->incRoleAsymmetricCount(); |
| 240 |
} |
| 241 |
if (role->isSymmetric()) { |
| 242 |
ontStructSum->incRoleSymmetricCount(); |
| 243 |
} |
| 244 |
if (role->isTransitive()) { |
| 245 |
ontStructSum->setTransitivityOccurrence(); |
| 246 |
ontStructSum->incRoleTransetivCount(); |
| 247 |
} |
| 248 |
if (role->isReflexive()) { |
| 249 |
ontStructSum->incRoleReflexivityCount(); |
| 250 |
} |
| 251 |
if (role->isIrreflexive()) { |
| 252 |
ontStructSum->incRoleIrreflexivityCount(); |
| 253 |
} |
| 254 |
if (role->isFunctional()) { |
| 255 |
ontStructSum->setFunctionalityOccurrence(); |
| 256 |
ontStructSum->incRoleFunctionalCount(); |
| 257 |
} |
| 258 |
if (role->isInverseFunctional()) { |
| 259 |
ontStructSum->setFunctionalityOccurrence(); |
| 260 |
ontStructSum->incRoleInverseFunctionalCount(); |
| 261 |
} |
| 262 |
if (role->hasRoleChainSuperSharing()) { |
| 263 |
bool allTransChaincs = true; |
| 264 |
CXLinker<CRoleChain*>* roleChainLinkerIt = role->getRoleChainSuperSharingLinker(); |
| 265 |
while (roleChainLinkerIt && allTransChaincs) { |
| 266 |
CRoleChain* roleChain = roleChainLinkerIt->getData(); |
| 267 |
CXLinker<CRole*>* chainRoleLinker = roleChain->getRoleChainLinker(); |
| 268 |
while (chainRoleLinker) { |
| 269 |
CRole* chainRole = chainRoleLinker->getData(); |
| 270 |
if (chainRole != role) { |
| 271 |
ontStructSum->setComplexSubRoleOccurrence(); |
| 272 |
allTransChaincs = false; |
| 273 |
break; |
| 274 |
} |
| 275 |
chainRoleLinker = chainRoleLinker->getNext(); |
| 276 |
} |
| 277 |
roleChainLinkerIt = roleChainLinkerIt->getNext(); |
| 278 |
} |
| 279 |
if (allTransChaincs) { |
| 280 |
ontStructSum->setTransitivityOccurrence(); |
| 281 |
} |
| 282 |
} |
| 283 |
CSortedNegLinker<CRole*>* superRoleLinkerIt = role->getSuperRoleList(); |
| 284 |
while (superRoleLinkerIt) { |
| 285 |
if (!superRoleLinkerIt->isNegated()) { |
| 286 |
//if (!role->hasEquivalentRole(superRoleLinkerIt->getData())) { |
| 287 |
//} |
| 288 |
ontStructSum->setRoleHierarchyOccurrence(); |
| 289 |
} |
| 290 |
superRoleLinkerIt = superRoleLinkerIt->getNext(); |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
CABox *aBox = ontology->getDataBoxes()->getABox(); |
| 296 |
CIndividualVector *indiVec = aBox->getIndividualVector(); |
| 297 |
qint64 indiCount = indiVec->getItemCount(); |
| 298 |
|
| 299 |
|
| 300 |
CTBox *tBox = ontology->getDataBoxes()->getTBox(); |
| 301 |
CConceptVector *conVec = tBox->getConceptVector(); |
| 302 |
qint64 conCount = conVec->getItemCount(); |
| 303 |
for (qint64 index = 0; index < conCount; ++index) { |
| 304 |
CConcept *concept = conVec->getData(index); |
| 305 |
if (concept) { |
| 306 |
ontStructSum->incConceptCount(); |
| 307 |
inspectConcept(ontology,concept,false,ontStructSum); |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
return ontStructSum; |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
bool COntologyInspector::testOntologyForNonDeterministicConcepts(CConcreteOntology *ontology, COntologyStructureSummary *ontStructSum) { |
| 317 |
CStructureFlags structureFlags; |
| 318 |
|
| 319 |
CTBox *tBox = ontology->getDataBoxes()->getTBox(); |
| 320 |
CABox* aBox = ontology->getDataBoxes()->getABox(); |
| 321 |
CConcept *topConcept = ontology->getDataBoxes()->getTopConcept(); |
| 322 |
CConcept *bottomConcept = ontology->getDataBoxes()->getBottomConcept(); |
| 323 |
|
| 324 |
QSet< QPair<CConcept*,bool> > singleConNegSet; |
| 325 |
|
| 326 |
CDatatypeValueSpacesTriggers* valueSpaceTriggers = ontology->getDataBoxes()->getMBox()->getValueSpacesTriggers(false); |
| 327 |
if (valueSpaceTriggers) { |
| 328 |
structureFlags.mValidDeterministic = false; |
| 329 |
} |
| 330 |
|
| 331 |
CBOXSET<CConcept*> *conceptHash = tBox->getActiveClassConceptSet(false); |
| 332 |
if (conceptHash) { |
| 333 |
for (CBOXSET<CConcept*>::const_iterator it = conceptHash->constBegin(), itEnd = conceptHash->constEnd(); it != itEnd && (structureFlags.mValidDeterministic); ++it) { |
| 334 |
CConcept *concept = (*it); |
| 335 |
if (concept) { |
| 336 |
if (concept->getOperatorCode() == CCEQ) { |
| 337 |
structureFlags.mValidDeterministic = false; |
| 338 |
} else { |
| 339 |
analyseConceptStructureFlags(concept,false,singleConNegSet,nullptr,structureFlags); |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
if (structureFlags.mValidDeterministic && (structureFlags.mUniversalRoleOccurence || structureFlags.mNominalOccurence)) { |
| 345 |
CBOXSET<CIndividual*>* individualSet = aBox->getActiveIndividualSet(false); |
| 346 |
if (individualSet) { |
| 347 |
for (CBOXSET<CIndividual*>::const_iterator it = individualSet->constBegin(), itEnd = individualSet->constEnd(); it != itEnd && (structureFlags.mValidDeterministic); ++it) { |
| 348 |
CIndividual *indi = (*it); |
| 349 |
if (indi) { |
| 350 |
CConceptAssertionLinker* assConIt = indi->getAssertionConceptLinker(); |
| 351 |
while (assConIt) { |
| 352 |
CConcept* assCon = assConIt->getData(); |
| 353 |
bool assConNeg = assConIt->isNegated(); |
| 354 |
analyseConceptStructureFlags(assCon,assConNeg,singleConNegSet,nullptr,structureFlags); |
| 355 |
assConIt = assConIt->getNext(); |
| 356 |
} |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
if (ontStructSum) { |
| 363 |
ontStructSum->setOnlyDeterministicConceptClasses(structureFlags.mValidDeterministic); |
| 364 |
} |
| 365 |
|
| 366 |
return structureFlags.mValidDeterministic; |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
bool COntologyInspector::testOntologyForNonELConcepts(CConcreteOntology *ontology, COntologyStructureSummary *ontStructSum) { |
| 371 |
CStructureFlags structureFlags; |
| 372 |
|
| 373 |
CTBox *tBox = ontology->getDataBoxes()->getTBox(); |
| 374 |
CConcept *topConcept = ontology->getDataBoxes()->getTopConcept(); |
| 375 |
CConcept *bottomConcept = ontology->getDataBoxes()->getBottomConcept(); |
| 376 |
|
| 377 |
QSet< QPair<CConcept*,bool> > singleConNegSet; |
| 378 |
QHash<CRole*,bool> existRoleHash; |
| 379 |
|
| 380 |
CDatatypeValueSpacesTriggers* valueSpaceTriggers = ontology->getDataBoxes()->getMBox()->getValueSpacesTriggers(false); |
| 381 |
if (valueSpaceTriggers) { |
| 382 |
structureFlags.mValidEL = false; |
| 383 |
} |
| 384 |
|
| 385 |
CBOXSET<CConcept*> *conceptHash = tBox->getActiveClassConceptSet(false); |
| 386 |
if (conceptHash) { |
| 387 |
for (CBOXSET<CConcept*>::const_iterator it = conceptHash->constBegin(), itEnd = conceptHash->constEnd(); it != itEnd && (structureFlags.mValidEL); ++it) { |
| 388 |
CConcept *concept = (*it); |
| 389 |
if (concept) { |
| 390 |
if (concept->getOperatorCode() == CCEQ) { |
| 391 |
structureFlags.mValidEL = false; |
| 392 |
} else { |
| 393 |
analyseConceptStructureFlags(concept,false,singleConNegSet,&existRoleHash,structureFlags); |
| 394 |
} |
| 395 |
} |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
if (ontStructSum) { |
| 400 |
ontStructSum->setOnlyELConceptClasses(structureFlags.mValidEL); |
| 401 |
} |
| 402 |
|
| 403 |
return structureFlags.mValidEL; |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
bool COntologyInspector::analyzeOntologyConceptsStructureFlags(CConcreteOntology *ontology, COntologyStructureSummary *ontStructSum) { |
| 408 |
|
| 409 |
CStructureFlags structureFlags; |
| 410 |
|
| 411 |
CTBox* tBox = ontology->getDataBoxes()->getTBox(); |
| 412 |
CABox* aBox = ontology->getDataBoxes()->getABox(); |
| 413 |
CConcept *topConcept = ontology->getDataBoxes()->getTopConcept(); |
| 414 |
CConcept *bottomConcept = ontology->getDataBoxes()->getBottomConcept(); |
| 415 |
|
| 416 |
QSet< QPair<CConcept*,bool> > singleConNegSet; |
| 417 |
QHash<CRole*,bool> existRoleHash; |
| 418 |
|
| 419 |
CDatatypeValueSpacesTriggers* valueSpaceTriggers = ontology->getDataBoxes()->getMBox()->getValueSpacesTriggers(false); |
| 420 |
if (valueSpaceTriggers) { |
| 421 |
structureFlags.mValidEL = false; |
| 422 |
structureFlags.mValidDeterministic = false; |
| 423 |
} |
| 424 |
|
| 425 |
CBOXSET<CConcept*>* conceptSet = tBox->getActiveClassConceptSet(false); |
| 426 |
if (conceptSet) { |
| 427 |
for (CBOXSET<CConcept*>::const_iterator it = conceptSet->constBegin(), itEnd = conceptSet->constEnd(); it != itEnd && (structureFlags.mValidEL || structureFlags.mValidDeterministic || !structureFlags.mNominalOccurence); ++it) { |
| 428 |
CConcept *concept = (*it); |
| 429 |
if (concept) { |
| 430 |
if (concept->getOperatorCode() == CCEQ) { |
| 431 |
structureFlags.mValidEL = false; |
| 432 |
structureFlags.mValidDeterministic = false; |
| 433 |
} else { |
| 434 |
analyseConceptStructureFlags(concept,false,singleConNegSet,&existRoleHash,structureFlags); |
| 435 |
} |
| 436 |
} |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
if (structureFlags.mValidDeterministic && (structureFlags.mUniversalRoleOccurence || structureFlags.mNominalOccurence)) { |
| 442 |
CBOXSET<CIndividual*>* individualSet = aBox->getActiveIndividualSet(false); |
| 443 |
if (individualSet) { |
| 444 |
for (CBOXSET<CIndividual*>::const_iterator it = individualSet->constBegin(), itEnd = individualSet->constEnd(); it != itEnd && (structureFlags.mValidEL || structureFlags.mValidDeterministic || !structureFlags.mNominalOccurence); ++it) { |
| 445 |
CIndividual *indi = (*it); |
| 446 |
if (indi) { |
| 447 |
CConceptAssertionLinker* assConIt = indi->getAssertionConceptLinker(); |
| 448 |
while (assConIt) { |
| 449 |
CConcept* assCon = assConIt->getData(); |
| 450 |
bool assConNeg = assConIt->isNegated(); |
| 451 |
analyseConceptStructureFlags(assCon,assConNeg,singleConNegSet,&existRoleHash,structureFlags); |
| 452 |
assConIt = assConIt->getNext(); |
| 453 |
} |
| 454 |
} |
| 455 |
} |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
if (ontStructSum) { |
| 460 |
ontStructSum->setNominalOccurrence(structureFlags.mNominalOccurence); |
| 461 |
ontStructSum->setOnlyELConceptClasses(structureFlags.mValidEL); |
| 462 |
ontStructSum->setOnlyDeterministicConceptClasses(structureFlags.mValidDeterministic); |
| 463 |
} |
| 464 |
|
| 465 |
return structureFlags.mValidEL || structureFlags.mValidDeterministic; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
bool COntologyInspector::analyseConceptStructureFlags(CConcept* concept, bool negated, QSet< QPair<CConcept*,bool> >& singleConNegSet, QHash<CRole*,bool>* existRoleHash, CStructureFlags& structureFlags) { |
| 472 |
singleConNegSet.insert(QPair<CConcept*,bool>(concept,negated)); |
| 473 |
QList< QPair<CConcept*,bool> > checkConNegList; |
| 474 |
checkConNegList.append(QPair<CConcept*,bool>(concept,negated)); |
| 475 |
|
| 476 |
while (!checkConNegList.isEmpty()) { |
| 477 |
QPair<CConcept*,bool> conNegPair(checkConNegList.takeFirst()); |
| 478 |
CConcept* con = conNegPair.first; |
| 479 |
bool conNeg = conNegPair.second; |
| 480 |
CRole* role = con->getRole(); |
| 481 |
if (role) { |
| 482 |
if (role->getRoleTag() == 1) { |
| 483 |
structureFlags.mUniversalRoleOccurence = true; |
| 484 |
} |
| 485 |
CSortedNegLinker<CRole*>* superRoleIt = role->getIndirectSuperRoleList(); |
| 486 |
while (superRoleIt) { |
| 487 |
CRole* superRole = superRoleIt->getData(); |
| 488 |
CSortedNegLinker<CConcept*>* domConIt = superRole->getDomainConceptList(); |
| 489 |
while (domConIt) { |
| 490 |
CConcept* domCon = domConIt->getData(); |
| 491 |
bool domConNeg = domConIt->isNegated(); |
| 492 |
if (!singleConNegSet.contains(QPair<CConcept*,bool>(domCon,domConNeg))) { |
| 493 |
singleConNegSet.insert(QPair<CConcept*,bool>(domCon,domConNeg)); |
| 494 |
checkConNegList.append(QPair<CConcept*,bool>(domCon,domConNeg)); |
| 495 |
} |
| 496 |
domConIt = domConIt->getNext(); |
| 497 |
} |
| 498 |
CSortedNegLinker<CConcept*>* ranConIt = superRole->getRangeConceptList(); |
| 499 |
if (ranConIt) { |
| 500 |
structureFlags.mValidEL = false; |
| 501 |
while (ranConIt) { |
| 502 |
CConcept* ranCon = ranConIt->getData(); |
| 503 |
bool ranConNeg = ranConIt->isNegated(); |
| 504 |
if (!singleConNegSet.contains(QPair<CConcept*,bool>(ranCon,ranConNeg))) { |
| 505 |
singleConNegSet.insert(QPair<CConcept*,bool>(ranCon,ranConNeg)); |
| 506 |
checkConNegList.append(QPair<CConcept*,bool>(ranCon,ranConNeg)); |
| 507 |
} |
| 508 |
ranConIt = ranConIt->getNext(); |
| 509 |
} |
| 510 |
} |
| 511 |
superRoleIt = superRoleIt->getNext(); |
| 512 |
} |
| 513 |
} |
| 514 |
CIndividual* indi = con->getNominalIndividual(); |
| 515 |
if (indi) { |
| 516 |
structureFlags.mValidEL = false; |
| 517 |
structureFlags.mNominalOccurence = true; |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
cint64 opCode = con->getOperatorCode(); |
| 522 |
CConceptOperator* conOperator = con->getConceptOperator(); |
| 523 |
cint64 param = con->getParameter(); |
| 524 |
cint64 opCount = con->getOperandCount(); |
| 525 |
if (!con->hasClassName()) { |
| 526 |
if (!conNeg && (opCode == CCOR) && opCount > 1 || conNeg && (opCode == CCAND || opCode == CCEQ) && opCount > 1) { |
| 527 |
structureFlags.mValidDeterministic = false; |
| 528 |
structureFlags.mValidEL = false; |
| 529 |
|
| 530 |
} else if (!conNeg && (opCode == CCATMOST) || conNeg && (opCode == CCATLEAST)) { |
| 531 |
structureFlags.mValidEL = false; |
| 532 |
if (opCount >= 1 || !conNeg && (opCode == CCATMOST) && param > 1 || conNeg && (opCode == CCATLEAST) && param > 2) { |
| 533 |
structureFlags.mValidDeterministic = false; |
| 534 |
} |
| 535 |
} else { |
| 536 |
if (!existRoleHash) { |
| 537 |
if (!conNeg && opCode == CCALL) { |
| 538 |
structureFlags.mValidEL = false; |
| 539 |
} |
| 540 |
} |
| 541 |
// TODO: check el, SOME r. and SOME r^-1 is not allowed |
| 542 |
// TODO: check el, ALL r. translated into automata concept AQALL also not allowed |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
if (existRoleHash) { |
| 547 |
if (conNeg && (opCode == CCSOME) || !conNeg && (conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_ALL_AQALL_TYPE))) { |
| 548 |
if (existRoleHash->contains(role)) { |
| 549 |
if (existRoleHash->value(role) == true) { |
| 550 |
structureFlags.mValidEL = false; |
| 551 |
} |
| 552 |
} else { |
| 553 |
existRoleHash->insert(role,false); |
| 554 |
} |
| 555 |
} |
| 556 |
if (conNeg && (opCode == CCALL) || !conNeg && (opCode == CCSOME || opCode == CCAQSOME)) { |
| 557 |
if (existRoleHash->contains(role)) { |
| 558 |
if (existRoleHash->value(role) == false) { |
| 559 |
structureFlags.mValidEL = false; |
| 560 |
} |
| 561 |
} else { |
| 562 |
existRoleHash->insert(role,true); |
| 563 |
} |
| 564 |
} |
| 565 |
} |
| 566 |
if (conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_DATATYPE_RELATED_TYPE)) { |
| 567 |
structureFlags.mValidEL = false; |
| 568 |
} |
| 569 |
|
| 570 |
bool inspectOperandsNegated = false; |
| 571 |
bool inspectOnlySameNegation = false; |
| 572 |
if (opCode == CCAQCHOOCE) { |
| 573 |
inspectOnlySameNegation = true; |
| 574 |
} |
| 575 |
if (conNeg && (opCode == CCSOME || opCode == CCALL || opCode == CCAND || opCode == CCEQ || opCode == CCOR)) { |
| 576 |
inspectOperandsNegated = true; |
| 577 |
} |
| 578 |
cint64 inspectOperandCount = opCount; |
| 579 |
if (opCode == CCVARBINDJOIN || opCode == CCPBINDCYCLE || conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_IMPL_TYPE)) { |
| 580 |
inspectOperandCount = 1; |
| 581 |
} |
| 582 |
CSortedNegLinker<CConcept*>* opConIt = con->getOperandList(); |
| 583 |
while (opConIt) { |
| 584 |
CConcept* opCon = opConIt->getData(); |
| 585 |
bool opConNeg = opConIt->isNegated()^inspectOperandsNegated; |
| 586 |
if (inspectOperandCount-- > 0) { |
| 587 |
if (!inspectOnlySameNegation || opConNeg == conNeg) { |
| 588 |
if (!singleConNegSet.contains(QPair<CConcept*,bool>(opCon,opConNeg))) { |
| 589 |
singleConNegSet.insert(QPair<CConcept*,bool>(opCon,opConNeg)); |
| 590 |
checkConNegList.append(QPair<CConcept*,bool>(opCon,opConNeg)); |
| 591 |
} |
| 592 |
} |
| 593 |
} |
| 594 |
opConIt = opConIt->getNext(); |
| 595 |
} |
| 596 |
|
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
return false; |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
}; // end namespace Ontology |
| 606 |
|
| 607 |
}; // end namespace Reasoner |
| 608 |
|
| 609 |
}; // end namespace Konclude |