| 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 "COptimizedKPSetRoleSubsumptionClassifierThread.h" |
| 22 |
|
| 23 |
namespace Konclude { |
| 24 |
|
| 25 |
namespace Reasoner { |
| 26 |
|
| 27 |
namespace Classifier { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
COptimizedKPSetRoleSubsumptionClassifierThread::COptimizedKPSetRoleSubsumptionClassifierThread(CReasonerManager *reasonerManager, bool dataRoleClassification) |
| 34 |
: CSubsumptionClassifierThread(reasonerManager), CLogIdentifier("::Konclude::Reasoner::Kernel::Classifier::OptimizedKPSetRoleSubsumptionClassifierThread",this) { |
| 35 |
satTestedCount = 0; |
| 36 |
totalToSatTestClassCount = 0; |
| 37 |
mClassificationCount = 0; |
| 38 |
subsumTestedCount = 0; |
| 39 |
totalToSubsumTestCount = 0; |
| 40 |
|
| 41 |
mConfPossSubsumCalcOrderRoleSorted = true; |
| 42 |
mConfPossSubsumCalcOrderFewestSubsumptionSorted = false; |
| 43 |
|
| 44 |
mConfPossSubsumCalcOrderTopDown = true; |
| 45 |
mConfPossSubsumCalcOrderBottomUp = false; |
| 46 |
|
| 47 |
mConfPossSubsumPseudoModelPretest = true; |
| 48 |
mConfPossSubsumPseudoModelTest = true; |
| 49 |
mConfWriteDebuggingData = false; |
| 50 |
|
| 51 |
mStatProcesedSubsumMessCount = 0; |
| 52 |
mStatProcesedPossSubsumInitMessCount = 0; |
| 53 |
mStatProcesedPossSubsumUpdateMessCount = 0; |
| 54 |
mStatProcesedPseudoModelMessCount = 0; |
| 55 |
|
| 56 |
mInterpretedSubsumptionCalculationCount = 0; |
| 57 |
mOrderedSubsumptionCalculationCount = 0; |
| 58 |
mPseudoModelPretestSubsumptionCalculationCount = 0; |
| 59 |
mCreatedCalculationTaskCount = 0; |
| 60 |
mRecievedCallbackCount = 0; |
| 61 |
|
| 62 |
mDataRolesClassification = dataRoleClassification; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
COptimizedKPSetRoleSubsumptionClassifierThread::~COptimizedKPSetRoleSubsumptionClassifierThread() { |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
CRolePropertiesHierarchy *COptimizedKPSetRoleSubsumptionClassifierThread::createInitialHierarchyForOntology(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 71 |
CRBox* rBox = ontology->getRBox(); |
| 72 |
CRole* topRole = nullptr; |
| 73 |
CRole* bottomRole = nullptr; |
| 74 |
bool classifyDataRoles = mDataRolesClassification; |
| 75 |
if (classifyDataRoles) { |
| 76 |
topRole = rBox->getTopDataRole(); |
| 77 |
bottomRole = rBox->getBottomDataRole(); |
| 78 |
} else { |
| 79 |
topRole = rBox->getTopObjectRole(); |
| 80 |
bottomRole = rBox->getBottomObjectRole(); |
| 81 |
} |
| 82 |
CRolePropertiesHierarchy *hierarchy = new CRolePropertiesHierarchy(topRole,bottomRole); |
| 83 |
return hierarchy; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
void COptimizedKPSetRoleSubsumptionClassifierThread::readCalculationConfig(CCalculationConfigurationExtension *config) { |
| 88 |
if (config) { |
| 89 |
bool configErrorFlag = false; |
| 90 |
cint64 processorCount = 1; |
| 91 |
QString processorCountString = CConfigDataReader::readConfigString(config,"Konclude.Calculation.ProcessorCount",QString(),&configErrorFlag); |
| 92 |
if (!configErrorFlag) { |
| 93 |
if (processorCountString == "AUTO") { |
| 94 |
processorCount = CThread::idealThreadCount(); |
| 95 |
} else { |
| 96 |
qint64 convertedWorkerCount = processorCountString.toInt(&configErrorFlag); |
| 97 |
if (configErrorFlag) { |
| 98 |
processorCount = convertedWorkerCount; |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
bool mulConfigErrorFlag = false; |
| 104 |
cint64 multiplicator = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Classification.OptimizedKPSetRoleSubsumptionClassifier.MultipliedUnitsParallelSatisfiableCalculationCount",1,&mulConfigErrorFlag); |
| 105 |
confMaxTestParallelCount = processorCount*multiplicator; |
| 106 |
bool maxConfigErrorFlag = false; |
| 107 |
cint64 maxParallel = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Classification.OptimizedKPSetRoleSubsumptionClassifier.MaximumParallelSatisfiableCalculationCount",1,&maxConfigErrorFlag); |
| 108 |
if (!maxConfigErrorFlag) { |
| 109 |
if (!mulConfigErrorFlag) { |
| 110 |
confMaxTestParallelCount = qMin(confMaxTestParallelCount,maxParallel); |
| 111 |
} else { |
| 112 |
confMaxTestParallelCount = maxParallel; |
| 113 |
} |
| 114 |
} |
| 115 |
double factor = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Classification.OptimizedKPSetRoleSubsumptionClassifier.ParallelSatisfiableCalculationCreationFactor",1000)/1000.; |
| 116 |
confMinTestParallelCount = confMaxTestParallelCount*factor; |
| 117 |
|
| 118 |
mConfWriteDebuggingData = CConfigDataReader::readConfigBoolean(config,"Konclude.Debugging.WriteDebuggingData",false); |
| 119 |
|
| 120 |
} else { |
| 121 |
confMaxTestParallelCount = 1; |
| 122 |
confMinTestParallelCount = 1; |
| 123 |
mConfWriteDebuggingData = false; |
| 124 |
} |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
COptimizedKPSetRoleSubsumptionClassifierThread* COptimizedKPSetRoleSubsumptionClassifierThread::createInitialSubsumptionSatisfiabilityTestingOrderFromBuildData(COptimizedKPSetRoleOntologyClassificationItem* ontPropItem) { |
| 133 |
CConcreteOntology* ontology = ontPropItem->getOntology(); |
| 134 |
CConcept* topConcept = ontology->getTBox()->getTopConcept(); |
| 135 |
|
| 136 |
CRBox *rBox = ontology->getRBox(); |
| 137 |
|
| 138 |
CRole* topRole = nullptr; |
| 139 |
CRole* bottomRole = nullptr; |
| 140 |
|
| 141 |
bool classifyDataRoles = ontPropItem->isDataRolesClassification(); |
| 142 |
if (classifyDataRoles) { |
| 143 |
topRole = rBox->getTopDataRole(); |
| 144 |
bottomRole = rBox->getBottomDataRole(); |
| 145 |
} else { |
| 146 |
topRole = rBox->getTopObjectRole(); |
| 147 |
bottomRole = rBox->getBottomObjectRole(); |
| 148 |
} |
| 149 |
|
| 150 |
cint64 satRoleCount = 1; |
| 151 |
CBOXSET<CRole*>* activeRoleHash = rBox->getActivePropertyRoleSet(false); |
| 152 |
if (activeRoleHash) { |
| 153 |
for (CBOXSET<CRole*>::const_iterator it = activeRoleHash->constBegin(), itEnd = activeRoleHash->constEnd(); it != itEnd; ++it) { |
| 154 |
CRole *role = (*it); |
| 155 |
if (role->isDataRole() == classifyDataRoles) { |
| 156 |
if (role && role != topRole && role != bottomRole) { |
| 157 |
++satRoleCount; |
| 158 |
ontPropItem->getRoleSatisfiableTestItem(role,true); |
| 159 |
|
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
CClassifierStatistics* statistics = ontPropItem->getClassifierStatistics(); |
| 166 |
statistics->incTotalSatisfiableTestCount(satRoleCount); |
| 167 |
|
| 168 |
|
| 169 |
COptimizedKPSetRoleTestingItem* topRoleItem = ontPropItem->getRoleSatisfiableTestItem(topRole,true); |
| 170 |
COptimizedKPSetRoleTestingItem* bottomRoleItem = ontPropItem->getRoleSatisfiableTestItem(bottomRole,true); |
| 171 |
|
| 172 |
ontPropItem->initTopBottomSatisfiableTestingItems(topRoleItem,bottomRoleItem); |
| 173 |
|
| 174 |
CConcept* univConnNomValueConcept = ontology->getTBox()->getUniversalConnectionNominalValueConcept(); |
| 175 |
|
| 176 |
QList<COptimizedKPSetRoleTestingItem*>* nextItemList = ontPropItem->getNextSatisfiableTestingItemList(); |
| 177 |
QSet<COptimizedKPSetRoleTestingItem*>* nextCandItemSet = ontPropItem->getNextCandidateSatisfiableTestingItemSet(); |
| 178 |
QSet<COptimizedKPSetRoleTestingItem*>* remainingCandItemSet = ontPropItem->getRemainingCandidateSatisfiableTestingItemSet(); |
| 179 |
|
| 180 |
QList<COptimizedKPSetRoleTestingItem*>* roleItemList = ontPropItem->getRoleSatisfiableTestItemList(); |
| 181 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator it = roleItemList->constBegin(), itEnd = roleItemList->constEnd(); it != itEnd; ++it) { |
| 182 |
COptimizedKPSetRoleTestingItem* roleItem(*it); |
| 183 |
if (roleItem != bottomRoleItem) { |
| 184 |
|
| 185 |
CRole* role = roleItem->getTestingRole(); |
| 186 |
bool complex = false; |
| 187 |
for (CSortedNegLinker<CRole*>* superRoleIt = role->getIndirectSuperRoleList(); superRoleIt; superRoleIt = superRoleIt->getNext()) { |
| 188 |
CRole* superRole = superRoleIt->getData(); |
| 189 |
|
| 190 |
if (!superRoleIt->isNegated() && superRole != topRole && superRole != role) { |
| 191 |
COptimizedKPSetRoleTestingItem* superRoleItem = ontPropItem->getRoleSatisfiableTestItem(superRole); |
| 192 |
if (superRoleItem) { |
| 193 |
roleItem->addSubsumerRoleItem(superRoleItem); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
if (superRole->getDomainConceptList()) { |
| 198 |
complex = true; |
| 199 |
} |
| 200 |
if (superRole->getRangeConceptList()) { |
| 201 |
complex = true; |
| 202 |
} |
| 203 |
if (topConcept->getOperandList() || univConnNomValueConcept) { |
| 204 |
complex = true; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
cint64 foundSubsumerCount = 0; |
| 209 |
ontPropItem->incRemainingSatisfiableTestsCount(); |
| 210 |
if (!complex) { |
| 211 |
roleItem->setResultSatisfiableDerivated(true); |
| 212 |
roleItem->setPossibleSubsumptionMapInitialized(true); |
| 213 |
} else { |
| 214 |
|
| 215 |
for (CSortedNegLinker<CRole*>* superRoleIt = role->getSuperRoleList(); superRoleIt; superRoleIt = superRoleIt->getNext()) { |
| 216 |
CRole* superRole = superRoleIt->getData(); |
| 217 |
if (!superRoleIt->isNegated()) { |
| 218 |
COptimizedKPSetRoleTestingItem* superRoleItem = ontPropItem->getRoleSatisfiableTestItem(superRole); |
| 219 |
if (superRoleItem) { |
| 220 |
foundSubsumerCount++; |
| 221 |
superRoleItem->addSuccessorSatisfiableTestItem(roleItem); |
| 222 |
roleItem->incUnprocessedPredecessorItems(); |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
if (foundSubsumerCount) { |
| 229 |
nextItemList->append(roleItem); |
| 230 |
} else { |
| 231 |
nextCandItemSet->insert(roleItem); |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
return this; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
CConcept* COptimizedKPSetRoleSubsumptionClassifierThread::createTemporaryConcept(CConcreteOntology* tmpRoleRealOntology) { |
| 245 |
CConceptVector* conVec = tmpRoleRealOntology->getTBox()->getConceptVector(); |
| 246 |
CConcept* concept = CObjectAllocator< CConcept >::allocateAndConstruct(tmpRoleRealOntology->getOntologyContext()->getMemoryAllocationManager()); |
| 247 |
concept->initConcept(); |
| 248 |
|
| 249 |
cint64 newConTag = tmpRoleRealOntology->getTBox()->getNextConceptID(); |
| 250 |
|
| 251 |
concept->setConceptTag(newConTag); |
| 252 |
conVec->setData(concept->getConceptTag(),concept); |
| 253 |
return concept; |
| 254 |
} |
| 255 |
|
| 256 |
void COptimizedKPSetRoleSubsumptionClassifierThread::addTemporaryConceptOperand(CConcept* concept, CConcept* opConcept, bool negated, CConcreteOntology* tmpRoleRealOntology) { |
| 257 |
CSortedNegLinker<CConcept*>* opConLinker = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(tmpRoleRealOntology->getOntologyContext()->getMemoryAllocationManager()); |
| 258 |
opConLinker->init(opConcept,negated); |
| 259 |
concept->addOperandLinker(opConLinker); |
| 260 |
concept->incOperandCount(); |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
COptimizedKPSetRoleSubsumptionClassifierThread* COptimizedKPSetRoleSubsumptionClassifierThread::createTemporaryRoleClassificationOntology(COptimizedKPSetRoleOntologyClassificationItem* item) { |
| 266 |
CConcreteOntology* ontology = item->getOntology(); |
| 267 |
CConcreteOntology* tmpRoleRealOntology = item->getTemporaryRoleClassificationOntology(); |
| 268 |
if (!tmpRoleRealOntology) { |
| 269 |
tmpRoleRealOntology = new CConcreteOntology(ontology,ontology->getConfiguration()); |
| 270 |
tmpRoleRealOntology->setOntologyID(ontology->getOntologyID()); |
| 271 |
tmpRoleRealOntology->setConsistence(ontology->getConsistence()); |
| 272 |
tmpRoleRealOntology->getTBox()->setMinimalNextConceptID(ontology->getTBox()->getMinimalNextConceptID()); |
| 273 |
|
| 274 |
QSet<CConcept*> compTransformConceptSet; |
| 275 |
QHash<CConcept*,COptimizedKPSetRoleTestingItem*>* markerConRolInsItemHash = item->getMarkerConceptInstancesItemHash(); |
| 276 |
|
| 277 |
CABox* abox = item->getOntology()->getABox(); |
| 278 |
|
| 279 |
CABox* tempRoleRealAbox = tmpRoleRealOntology->getABox(); |
| 280 |
CIndividualVector* indiVec = tempRoleRealAbox->getIndividualVector(true); |
| 281 |
|
| 282 |
CIndividual* tmpIndiProp = new CIndividual(); |
| 283 |
tmpIndiProp->initIndividual(tempRoleRealAbox->getNextIndividualId(true)); |
| 284 |
indiVec->setData(tmpIndiProp->getIndividualID(),tmpIndiProp); |
| 285 |
CIndividual* tmpIndiMarker = new CIndividual(); |
| 286 |
tmpIndiMarker->initIndividual(tempRoleRealAbox->getNextIndividualId(true)); |
| 287 |
indiVec->setData(tmpIndiMarker->getIndividualID(),tmpIndiMarker); |
| 288 |
tmpIndiProp->setTemporaryFakeIndividual(true); |
| 289 |
tmpIndiMarker->setTemporaryFakeIndividual(true); |
| 290 |
|
| 291 |
|
| 292 |
item->setTemporaryMarkerIndividual(tmpIndiMarker); |
| 293 |
item->setTemporaryPropagationIndividual(tmpIndiProp); |
| 294 |
|
| 295 |
CConcept* allPropConcept = createTemporaryConcept(tmpRoleRealOntology); |
| 296 |
allPropConcept->setOperatorCode(CCAND); |
| 297 |
|
| 298 |
|
| 299 |
COptimizedKPSetRoleTestingItem* topRoleInstItem = item->getTopRoleSatisfiableTestItem(); |
| 300 |
COptimizedKPSetRoleTestingItem* bottomRoleInstItem = item->getBottomRoleSatisfiableTestItem(); |
| 301 |
QList<COptimizedKPSetRoleTestingItem*>* roleItemList = item->getRoleSatisfiableTestItemList(); |
| 302 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator itemIt = roleItemList->constBegin(), itemItEnd = roleItemList->constEnd(); itemIt != itemItEnd; ++itemIt) { |
| 303 |
COptimizedKPSetRoleTestingItem* roleItem(*itemIt); |
| 304 |
if (roleItem != bottomRoleInstItem) { |
| 305 |
CRole* role = roleItem->getTestingRole(); |
| 306 |
|
| 307 |
CConcept* markerConcept = createTemporaryConcept(tmpRoleRealOntology); |
| 308 |
markerConcept->setOperatorCode(CCMARKER); |
| 309 |
markerConcept->setRole(role); |
| 310 |
|
| 311 |
CConcept* existConcept = createTemporaryConcept(tmpRoleRealOntology); |
| 312 |
existConcept->setOperatorCode(CCVALUE); |
| 313 |
existConcept->setRole(role); |
| 314 |
existConcept->setNominalIndividual(tmpIndiMarker); |
| 315 |
roleItem->setTemporaryExistConcept(existConcept); |
| 316 |
|
| 317 |
CConcept* propConcept = createTemporaryConcept(tmpRoleRealOntology); |
| 318 |
propConcept->setOperatorCode(CCALL); |
| 319 |
propConcept->setRole(role); |
| 320 |
addTemporaryConceptOperand(propConcept,markerConcept,false,tmpRoleRealOntology); |
| 321 |
|
| 322 |
addTemporaryConceptOperand(allPropConcept,propConcept,false,tmpRoleRealOntology); |
| 323 |
roleItem->setTemporaryMarkerConcept(markerConcept); |
| 324 |
markerConRolInsItemHash->insert(markerConcept,roleItem); |
| 325 |
roleItem->setTemporaryPropagationConcept(propConcept); |
| 326 |
if (role->isComplexRole()) { |
| 327 |
compTransformConceptSet.insert(propConcept); |
| 328 |
} |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
if (!compTransformConceptSet.isEmpty()) { |
| 333 |
CPreProcessContextBase* preprocessContext = new CPreProcessContextBase(tmpRoleRealOntology,ontology->getConfiguration()); |
| 334 |
CRoleChainAutomataTransformationPreProcess* roleChainAutomataTransformPreprocessor = new CRoleChainAutomataTransformationPreProcess(); |
| 335 |
roleChainAutomataTransformPreprocessor->preprocess(tmpRoleRealOntology,&compTransformConceptSet,preprocessContext); |
| 336 |
delete preprocessContext; |
| 337 |
delete roleChainAutomataTransformPreprocessor; |
| 338 |
} |
| 339 |
|
| 340 |
item->setTemporaryRoleClassificationOntology(tmpRoleRealOntology); |
| 341 |
item->setTemporaryAllPropagationConcept(allPropConcept); |
| 342 |
} |
| 343 |
return this; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
CSubsumptionClassifierThread *COptimizedKPSetRoleSubsumptionClassifierThread::scheduleOntologyClassification(CConcreteOntology *ontology, CClassificationCalculationSupport *classificationSupport, CConfigurationBase *config) { |
| 350 |
|
| 351 |
|
| 352 |
CRolePropertiesHierarchy* hierarchy = createInitialHierarchyForOntology(ontology,config); |
| 353 |
|
| 354 |
COptimizedKPSetRoleOntologyClassificationItem *ontPropItem = new COptimizedKPSetRoleOntologyClassificationItem(config,statistics); |
| 355 |
ontPropItem->initClassificationItem(ontology,hierarchy,mDataRolesClassification); |
| 356 |
ontItemList.append(ontPropItem); |
| 357 |
processingOntItemList.append(ontPropItem); |
| 358 |
ontItemHash.insert(ontology,ontPropItem); |
| 359 |
|
| 360 |
readCalculationConfig(ontPropItem->getCalculationConfiguration()); |
| 361 |
|
| 362 |
if (CConfigDataReader::readConfigBoolean(ontPropItem->getCalculationConfiguration(),"Konclude.Calculation.Classification.IndividualDependenceTracking",true)) { |
| 363 |
ontPropItem->setIndividualDependenceTrackingCollector(new CIndividualDependenceTrackingCollector()); |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
createInitialSubsumptionSatisfiabilityTestingOrderFromBuildData(ontPropItem); |
| 369 |
createTemporaryRoleClassificationOntology(ontPropItem); |
| 370 |
|
| 371 |
if (satTestedCount == totalToSatTestClassCount) { |
| 372 |
satTestedCount = 0; |
| 373 |
totalToSatTestClassCount = ontPropItem->getRemainingSatisfiableTestsCount(); |
| 374 |
classStartTime.start(); |
| 375 |
} else { |
| 376 |
totalToSatTestClassCount += ontPropItem->getRemainingSatisfiableTestsCount(); |
| 377 |
} |
| 378 |
++mClassificationCount; |
| 379 |
|
| 380 |
return this; |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
QString COptimizedKPSetRoleSubsumptionClassifierThread::getStatusString() { |
| 389 |
statUpdateMutex.lock(); |
| 390 |
QString string = statusString; |
| 391 |
string.detach(); |
| 392 |
statUpdateMutex.unlock(); |
| 393 |
return string; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
CClassificationProgress* COptimizedKPSetRoleSubsumptionClassifierThread::getClassificationProgress() { |
| 399 |
if (satTestedCount != totalToSatTestClassCount || subsumTestedCount != totalToSubsumTestCount) { |
| 400 |
cint64 tested = satTestedCount + subsumTestedCount; |
| 401 |
cint64 total = totalToSatTestClassCount + totalToSubsumTestCount; |
| 402 |
cint64 elapsedTime = classStartTime.elapsed(); |
| 403 |
double remainingMilliSeconds = 0.; |
| 404 |
double progessPercent = 0.; |
| 405 |
if (elapsedTime <= 0 && total > 0) { |
| 406 |
remainingMilliSeconds = 0.; |
| 407 |
} else { |
| 408 |
remainingMilliSeconds = ((double)elapsedTime / (double)tested) * (total-tested); |
| 409 |
} |
| 410 |
if (total <= 0) { |
| 411 |
progessPercent = 0.; |
| 412 |
} else { |
| 413 |
progessPercent = ((double)tested / (double)total) * 100.; |
| 414 |
} |
| 415 |
cint64 classificCount = mClassificationCount; |
| 416 |
mClassifyProgess.setClassificationCount(classificCount); |
| 417 |
mClassifyProgess.setProgessPercent(progessPercent); |
| 418 |
mClassifyProgess.setRemainingMilliSeconds(remainingMilliSeconds); |
| 419 |
mClassifyProgess.setTestedSatisfiable(satTestedCount); |
| 420 |
mClassifyProgess.setTotalSatisfiable(totalToSatTestClassCount); |
| 421 |
mClassifyProgess.setTestedSubsumptions(subsumTestedCount); |
| 422 |
mClassifyProgess.setTotalSubsumptions(totalToSubsumTestCount); |
| 423 |
} else { |
| 424 |
mClassifyProgess.setProgessPercent(0.); |
| 425 |
mClassifyProgess.setRemainingMilliSeconds(0.); |
| 426 |
mClassifyProgess.setTestedSatisfiable(satTestedCount); |
| 427 |
mClassifyProgess.setTotalSatisfiable(totalToSatTestClassCount); |
| 428 |
mClassifyProgess.setTestedSubsumptions(subsumTestedCount); |
| 429 |
mClassifyProgess.setTotalSubsumptions(totalToSubsumTestCount); |
| 430 |
} |
| 431 |
return &mClassifyProgess; |
| 432 |
} |
| 433 |
|
| 434 |
bool itemSortLessSubsumptionsThan(const COptimizedKPSetRoleTestingItem* item1, const COptimizedKPSetRoleTestingItem* item2) { |
| 435 |
return item1->getSubsumerRoleItemCount() < item2->getSubsumerRoleItemCount(); |
| 436 |
} |
| 437 |
|
| 438 |
bool itemSortMoreSubsumptionsThan(const COptimizedKPSetRoleTestingItem* item1, const COptimizedKPSetRoleTestingItem* item2) { |
| 439 |
return item1->getSubsumerRoleItemCount() > item2->getSubsumerRoleItemCount(); |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
void COptimizedKPSetRoleSubsumptionClassifierThread::testDebugPossibleSubsumerCorrectCounted(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem) { |
| 445 |
QList<COptimizedKPSetRoleTestingItem*>* classList = optKPSetClassificationItem->getRoleSatisfiableTestItemList(); |
| 446 |
cint64 totalCount = 0; |
| 447 |
foreach (COptimizedKPSetRoleTestingItem* item, *classList) { |
| 448 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 449 |
if (possSubsumMap) { |
| 450 |
cint64 mapCount = 0; |
| 451 |
for (COptimizedKPSetRolePossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 452 |
COptimizedKPSetRolePossibleSubsumptionData* data = it.value(); |
| 453 |
if (data->isSubsumptionUnknown() || data->isUpdateRequired()) { |
| 454 |
mapCount++; |
| 455 |
totalCount++; |
| 456 |
} |
| 457 |
} |
| 458 |
if (mapCount != possSubsumMap->getRemainingPossibleSubsumptionCount()) { |
| 459 |
bool bug = true; |
| 460 |
} |
| 461 |
} |
| 462 |
} |
| 463 |
if (totalCount != optKPSetClassificationItem->getRemainingPossibleSubsumptionTestsCount()) { |
| 464 |
bool bug = true; |
| 465 |
} |
| 466 |
|
| 467 |
} |
| 468 |
|
| 469 |
void COptimizedKPSetRoleSubsumptionClassifierThread::testDebugPossibleSubsumerCorrectReferenced(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem) { |
| 470 |
QList<COptimizedKPSetRoleTestingItem*>* classList = optKPSetClassificationItem->getRoleSatisfiableTestItemList(); |
| 471 |
if (mConfPossSubsumCalcOrderBottomUp) { |
| 472 |
QSet<COptimizedKPSetRoleTestingItem*>* remItemSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionTestingSet(); |
| 473 |
foreach (COptimizedKPSetRoleTestingItem* item, *classList) { |
| 474 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 475 |
if (possSubsumMap) { |
| 476 |
for (COptimizedKPSetRolePossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 477 |
COptimizedKPSetRolePossibleSubsumptionData* data = it.value(); |
| 478 |
if (data->isSubsumptionUnknown() || data->isUpdateRequired()) { |
| 479 |
COptimizedKPSetRoleTestingItem* possSubsumerItem = data->getTestingItem(); |
| 480 |
if (!possSubsumerItem->getPossibleSubsumerSet(false)->contains(item) && !optKPSetClassificationItem->getCurrentPossibleSubsumptionTestingItemSet()->contains(possSubsumerItem)) { |
| 481 |
bool bug = true; |
| 482 |
} |
| 483 |
if (!remItemSet->contains(possSubsumerItem) && !optKPSetClassificationItem->getCurrentPossibleSubsumptionTestingItemSet()->contains(possSubsumerItem)) { |
| 484 |
bool bug = true; |
| 485 |
} |
| 486 |
} |
| 487 |
} |
| 488 |
} |
| 489 |
} |
| 490 |
} |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
QString COptimizedKPSetRoleSubsumptionClassifierThread::createDebugKPSetString(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, const QString& filename) { |
| 495 |
QString debugString; |
| 496 |
QList<COptimizedKPSetRoleTestingItem*>* propertyList = optKPSetClassificationItem->getRoleSatisfiableTestItemList(); |
| 497 |
foreach (COptimizedKPSetRoleTestingItem* item, *propertyList) { |
| 498 |
QString iriPropertyNameString = CIRIName::getRecentIRIName(item->getTestingRole()->getPropertyNameLinker()); |
| 499 |
QString propertyDebugString = QString("Property: %1\r\n").arg(iriPropertyNameString); |
| 500 |
QString subsumString; |
| 501 |
foreach (COptimizedKPSetRoleTestingItem* subsumItem, *item->getSubsumerRoleItemList()) { |
| 502 |
QString subsumIRIPropertyNameString = CIRIName::getRecentIRIName(subsumItem->getTestingRole()->getPropertyNameLinker()); |
| 503 |
if (subsumString.isEmpty()) { |
| 504 |
subsumString += subsumIRIPropertyNameString; |
| 505 |
} else { |
| 506 |
subsumString += QString(", %1").arg(subsumIRIPropertyNameString); |
| 507 |
} |
| 508 |
} |
| 509 |
propertyDebugString += QString("Subsumer Roles: %1\r\n").arg(subsumString); |
| 510 |
|
| 511 |
QString possSubsumString; |
| 512 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 513 |
if (possSubsumMap) { |
| 514 |
for (COptimizedKPSetRolePossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 515 |
COptimizedKPSetRolePossibleSubsumptionData* data = it.value(); |
| 516 |
QString subsumIRIPropertyNameString = CIRIName::getRecentIRIName(data->getTestingItem()->getTestingRole()->getPropertyNameLinker()); |
| 517 |
QString possString; |
| 518 |
if (data->isSubsumptionConfirmed()) { |
| 519 |
possString = "s"; |
| 520 |
} else if (data->isSubsumptionInvalided()) { |
| 521 |
possString = "n"; |
| 522 |
} else { |
| 523 |
possString = "u"; |
| 524 |
} |
| 525 |
|
| 526 |
if (possSubsumString.isEmpty()) { |
| 527 |
possSubsumString += QString("%1(%2)").arg(subsumIRIPropertyNameString).arg(possString); |
| 528 |
} else { |
| 529 |
possSubsumString += QString(", %1(%2)").arg(subsumIRIPropertyNameString).arg(possString); |
| 530 |
} |
| 531 |
} |
| 532 |
} |
| 533 |
propertyDebugString += QString("Possible Subsumer Roles: %1\r\n\r\n\r\n").arg(possSubsumString); |
| 534 |
|
| 535 |
debugString += propertyDebugString; |
| 536 |
} |
| 537 |
|
| 538 |
QFile file(filename); |
| 539 |
if (file.open(QIODevice::WriteOnly)) { |
| 540 |
file.write(debugString.toLocal8Bit()); |
| 541 |
file.close(); |
| 542 |
} |
| 543 |
|
| 544 |
return debugString; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::createNextSubsumtionTest() { |
| 549 |
|
| 550 |
|
| 551 |
COntologyPropertyRoleClassificationItem *loopontPropItem = 0; |
| 552 |
bool workTestCreated = false; |
| 553 |
while (!workTestCreated && !processingOntItemList.isEmpty()) { |
| 554 |
COptimizedKPSetRoleOntologyClassificationItem *ontPropItem = (COptimizedKPSetRoleOntologyClassificationItem*)processingOntItemList.first(); |
| 555 |
|
| 556 |
if (ontPropItem == loopontPropItem) { |
| 557 |
// don't run into infinite loop without doing something |
| 558 |
break; |
| 559 |
} |
| 560 |
|
| 561 |
COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetRoleOntologyClassificationItem *)ontPropItem; |
| 562 |
|
| 563 |
if (!optKPSetClassificationItem->hasSatisfiableTestingPhaseFinished() && !ontPropItem->isHierarchyConstructionFailed()) { |
| 564 |
|
| 565 |
while (!workTestCreated && optKPSetClassificationItem->hasRemainingSatisfiableTests()) { |
| 566 |
// get next satisfiable test |
| 567 |
|
| 568 |
QList<COptimizedKPSetRoleTestingItem*>* nextItemList = optKPSetClassificationItem->getNextSatisfiableTestingItemList(); |
| 569 |
QSet<COptimizedKPSetRoleTestingItem*>* nextCandItemSet = optKPSetClassificationItem->getNextCandidateSatisfiableTestingItemSet(); |
| 570 |
QSet<COptimizedKPSetRoleTestingItem*>* remainingCandItemSet = optKPSetClassificationItem->getRemainingCandidateSatisfiableTestingItemSet(); |
| 571 |
|
| 572 |
|
| 573 |
COptimizedKPSetRoleTestingItem* nextSatTestItem = nullptr; |
| 574 |
if (!nextItemList->isEmpty()) { |
| 575 |
nextSatTestItem = nextItemList->takeFirst(); |
| 576 |
remainingCandItemSet->remove(nextSatTestItem); |
| 577 |
nextCandItemSet->remove(nextSatTestItem); |
| 578 |
|
| 579 |
} else if (!nextCandItemSet->isEmpty()) { |
| 580 |
COptimizedKPSetRoleTestingItem* minItem = nullptr; |
| 581 |
cint64 minUnpPredCount = 0; |
| 582 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator it = nextCandItemSet->constBegin(), itEnd = nextCandItemSet->constEnd(); it != itEnd; ++it) { |
| 583 |
COptimizedKPSetRoleTestingItem* item = (*it); |
| 584 |
cint64 predCount = item->getUnprocessedPredecessorItemCount(); |
| 585 |
if (!minItem || minUnpPredCount < predCount) { |
| 586 |
minUnpPredCount = predCount; |
| 587 |
minItem = item; |
| 588 |
} |
| 589 |
} |
| 590 |
nextSatTestItem = minItem; |
| 591 |
remainingCandItemSet->remove(nextSatTestItem); |
| 592 |
nextCandItemSet->remove(nextSatTestItem); |
| 593 |
|
| 594 |
} else if (!remainingCandItemSet->isEmpty()) { |
| 595 |
COptimizedKPSetRoleTestingItem* minItem = nullptr; |
| 596 |
QSet<COptimizedKPSetRoleTestingItem*>::const_iterator itNext = remainingCandItemSet->constBegin(); |
| 597 |
nextSatTestItem = *itNext; |
| 598 |
remainingCandItemSet->remove(nextSatTestItem); |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
if (nextSatTestItem && !nextSatTestItem->isSatisfiableTestOrdered()) { |
| 603 |
optKPSetClassificationItem->decRemainingSatisfiableTestsCount(); |
| 604 |
optKPSetClassificationItem->incRunningSatisfiableTestsCount(); |
| 605 |
if (calculateSatisfiable(optKPSetClassificationItem,nextSatTestItem)) { |
| 606 |
workTestCreated = true; |
| 607 |
} else { |
| 608 |
interpreteSatisfiableResult(optKPSetClassificationItem,nextSatTestItem->getTestingRole(),nextSatTestItem->getSatisfiableTestedResult()); |
| 609 |
} |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
if (!workTestCreated) { |
| 615 |
if (optKPSetClassificationItem->hasAllSatisfiableTestsCompleted()) { |
| 616 |
optKPSetClassificationItem->setSatisfiableTestingPhaseFinished(true); |
| 617 |
// initialize possible subsumption testing phase |
| 618 |
|
| 619 |
|
| 620 |
cint64 remainingSubSumTestCount = 0; |
| 621 |
|
| 622 |
QSet<COptimizedKPSetRoleTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionTestingSet(); |
| 623 |
|
| 624 |
QList<COptimizedKPSetRoleTestingItem*>* nextItemList = optKPSetClassificationItem->getNextPossibleSubsumptionTestingItemList(); |
| 625 |
|
| 626 |
COptimizedKPSetRoleTestingItem* topItem = optKPSetClassificationItem->getTopRoleSatisfiableTestItem(); |
| 627 |
COptimizedKPSetRoleTestingItem* bottomItem = optKPSetClassificationItem->getBottomRoleSatisfiableTestItem(); |
| 628 |
|
| 629 |
topItem->setPropagationConnected(true); |
| 630 |
|
| 631 |
QList<COptimizedKPSetRoleTestingItem*> propList(*optKPSetClassificationItem->getRoleSatisfiableTestItemList()); |
| 632 |
qSort(propList.begin(),propList.end(),itemSortLessSubsumptionsThan); |
| 633 |
QList<COptimizedKPSetRoleTestingItem*> resevePossSubsumClassList; |
| 634 |
foreach (COptimizedKPSetRoleTestingItem* item, propList) { |
| 635 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubSumMap = item->getPossibleSubsumptionMap(false); |
| 636 |
if (possSubSumMap && possSubSumMap->hasRemainingPossibleSubsumptions()) { |
| 637 |
if (mConfPossSubsumCalcOrderTopDown) { |
| 638 |
nextItemList->append(item); |
| 639 |
remTestingSet->insert(item); |
| 640 |
} |
| 641 |
remainingSubSumTestCount += possSubSumMap->getRemainingPossibleSubsumptionCount(); |
| 642 |
resevePossSubsumClassList.append(item); |
| 643 |
} |
| 644 |
if (!item->isPossibleSubsumptionMapInitialized()) { |
| 645 |
bool bug = true; |
| 646 |
} |
| 647 |
|
| 648 |
QList<COptimizedKPSetRoleTestingItem*>* subsumerList = item->getSubsumerRoleItemList(); |
| 649 |
COptimizedKPSetRoleTestingItem* maxSubsumerItem = nullptr; |
| 650 |
cint64 maxSubsumerCount = 0; |
| 651 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator it = subsumerList->constBegin(), itEnd = subsumerList->constEnd(); it != itEnd; ++it) { |
| 652 |
COptimizedKPSetRoleTestingItem* subsumerItem = *it; |
| 653 |
if (!maxSubsumerItem || subsumerItem->getSubsumerRoleItemCount() > maxSubsumerCount) { |
| 654 |
maxSubsumerCount = subsumerItem->getSubsumerRoleItemCount(); |
| 655 |
maxSubsumerItem = subsumerItem; |
| 656 |
} |
| 657 |
} |
| 658 |
if (!maxSubsumerItem) { |
| 659 |
maxSubsumerItem = topItem; |
| 660 |
} |
| 661 |
|
| 662 |
bool upPropConnected = false; |
| 663 |
QSet<COptimizedKPSetRoleTestingItem*>* upPropSet = item->getUpPropagationItemSet(); |
| 664 |
if (item != topItem) { |
| 665 |
upPropSet->insert(maxSubsumerItem); |
| 666 |
maxSubsumerItem->addDownPropagationItem(item); |
| 667 |
upPropConnected |= maxSubsumerItem->isPropagationConnected(); |
| 668 |
} |
| 669 |
|
| 670 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator itSub = subsumerList->constBegin(), itSubEnd = subsumerList->constEnd(); itSub != itSubEnd; ++itSub) { |
| 671 |
COptimizedKPSetRoleTestingItem* subsumerItem = *itSub; |
| 672 |
bool alreadySubsumed = false; |
| 673 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator itProp = upPropSet->constBegin(), itPropEnd = upPropSet->constEnd(); !alreadySubsumed && itProp != itPropEnd; ++itProp) { |
| 674 |
COptimizedKPSetRoleTestingItem* propItem = *itProp; |
| 675 |
if (propItem == subsumerItem || propItem->hasSubsumerRoleItem(subsumerItem)) { |
| 676 |
alreadySubsumed = true; |
| 677 |
} |
| 678 |
} |
| 679 |
if (!alreadySubsumed) { |
| 680 |
upPropSet->insert(subsumerItem); |
| 681 |
subsumerItem->addDownPropagationItem(item); |
| 682 |
upPropConnected |= subsumerItem->isPropagationConnected(); |
| 683 |
} |
| 684 |
} |
| 685 |
if (!upPropConnected) { |
| 686 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator itSub = subsumerList->constBegin(), itSubEnd = subsumerList->constEnd(); itSub != itSubEnd && !upPropConnected; ++itSub) { |
| 687 |
COptimizedKPSetRoleTestingItem* subsumerItem = *itSub; |
| 688 |
if (subsumerItem->isPropagationConnected()) { |
| 689 |
upPropSet->insert(subsumerItem); |
| 690 |
subsumerItem->addDownPropagationItem(item); |
| 691 |
upPropConnected |= subsumerItem->isPropagationConnected(); |
| 692 |
} |
| 693 |
} |
| 694 |
if (!upPropConnected) { |
| 695 |
upPropSet->insert(topItem); |
| 696 |
topItem->addDownPropagationItem(item); |
| 697 |
upPropConnected |= topItem->isPropagationConnected(); |
| 698 |
} |
| 699 |
} |
| 700 |
item->setPropagationConnected(upPropConnected); |
| 701 |
|
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
foreach (COptimizedKPSetRoleTestingItem* item, propList) { |
| 706 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 707 |
QSet<COptimizedKPSetRoleTestingItem*>* upPropSet = item->getUpPropagationItemSet(); |
| 708 |
if (!possSubsumMap && item->isPossibleSubsumptionMapInitialized()) { |
| 709 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator itProp = upPropSet->constBegin(), itPropEnd = upPropSet->constEnd(); itProp != itPropEnd; ++itProp) { |
| 710 |
COptimizedKPSetRoleTestingItem* upPropItem = *itProp; |
| 711 |
|
| 712 |
COptimizedKPSetRolePossibleSubsumptionMap* upPropItemPossSubsumMap = upPropItem->getPossibleSubsumptionMap(false); |
| 713 |
if (upPropItemPossSubsumMap) { |
| 714 |
for (COptimizedKPSetRolePossibleSubsumptionMap::const_iterator itUpPoss = upPropItemPossSubsumMap->constBegin(), itUpPossEnd = upPropItemPossSubsumMap->constEnd(); itUpPoss != itUpPossEnd; ++itUpPoss) { |
| 715 |
COptimizedKPSetRolePossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 716 |
if (!item->hasSubsumerRoleItem(upPossData->getTestingItem()) && item != upPossData->getTestingItem()) { |
| 717 |
if (!upPossData->isSubsumptionInvalided()) { |
| 718 |
upPossData->setSubsumptionInvalid(true); |
| 719 |
if (upPossData->isUpdateRequired()) { |
| 720 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 721 |
} |
| 722 |
} |
| 723 |
} |
| 724 |
} |
| 725 |
} |
| 726 |
} |
| 727 |
} else { |
| 728 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator itProp = upPropSet->constBegin(), itPropEnd = upPropSet->constEnd(); itProp != itPropEnd; ++itProp) { |
| 729 |
COptimizedKPSetRoleTestingItem* upPropItem = *itProp; |
| 730 |
|
| 731 |
COptimizedKPSetRolePossibleSubsumptionMap* upPropItemPossSubsumMap = upPropItem->getPossibleSubsumptionMap(false); |
| 732 |
if (upPropItemPossSubsumMap) { |
| 733 |
COptimizedKPSetRolePossibleSubsumptionMap::const_iterator itUpPoss = upPropItemPossSubsumMap->constBegin(), itUpPossEnd = upPropItemPossSubsumMap->constEnd(); |
| 734 |
if (possSubsumMap) { |
| 735 |
COptimizedKPSetRolePossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); |
| 736 |
while (itPoss != itPossEnd && itUpPoss != itUpPossEnd) { |
| 737 |
CRole* possRole = itPoss.key().getRole(); |
| 738 |
CRole* possUpRole = itUpPoss.key().getRole(); |
| 739 |
if (possRole->getRoleTag() == possUpRole->getRoleTag()) { |
| 740 |
++itPoss; |
| 741 |
++itUpPoss; |
| 742 |
} else if (possRole->getRoleTag() < possUpRole->getRoleTag()) { |
| 743 |
++itPoss; |
| 744 |
} else if (possRole->getRoleTag() > possUpRole->getRoleTag()) { |
| 745 |
COptimizedKPSetRolePossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 746 |
if (!item->hasSubsumerRoleItem(upPossData->getTestingItem()) && item != upPossData->getTestingItem()) { |
| 747 |
if (!upPossData->isSubsumptionInvalided()) { |
| 748 |
upPossData->setSubsumptionInvalid(true); |
| 749 |
if (upPossData->isUpdateRequired()) { |
| 750 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 751 |
} |
| 752 |
} |
| 753 |
} |
| 754 |
++itUpPoss; |
| 755 |
} |
| 756 |
} |
| 757 |
} |
| 758 |
while (itUpPoss != itUpPossEnd) { |
| 759 |
COptimizedKPSetRolePossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 760 |
if (!item->hasSubsumerRoleItem(upPossData->getTestingItem()) && item != upPossData->getTestingItem()) { |
| 761 |
if (!upPossData->isSubsumptionInvalided()) { |
| 762 |
upPossData->setSubsumptionInvalid(true); |
| 763 |
if (upPossData->isUpdateRequired()) { |
| 764 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 765 |
} |
| 766 |
} |
| 767 |
} |
| 768 |
++itUpPoss; |
| 769 |
} |
| 770 |
} |
| 771 |
} |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
foreach (COptimizedKPSetRoleTestingItem* item, resevePossSubsumClassList) { |
| 776 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 777 |
if (possSubsumMap) { |
| 778 |
if (possSubsumMap->hasRemainingPossibleSubsumptions()) { |
| 779 |
for (COptimizedKPSetRolePossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 780 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumData = it.value(); |
| 781 |
|
| 782 |
if (mConfPossSubsumCalcOrderBottomUp) { |
| 783 |
if (possSubsumData->isSubsumptionUnknown() || possSubsumData->isUpdateRequired()) { |
| 784 |
COptimizedKPSetRoleTestingItem* possSubsumerItem = possSubsumData->getTestingItem(); |
| 785 |
possSubsumerItem->getPossibleSubsumerSet(true)->insert(item); |
| 786 |
if (!remTestingSet->contains(possSubsumerItem)) { |
| 787 |
remTestingSet->insert(possSubsumerItem); |
| 788 |
nextItemList->append(possSubsumerItem); |
| 789 |
} |
| 790 |
} |
| 791 |
} |
| 792 |
} |
| 793 |
} |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
if (mConfPossSubsumCalcOrderBottomUp) { |
| 799 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator it = remTestingSet->constBegin(), itEnd = remTestingSet->constEnd(); it != itEnd; ++it) { |
| 800 |
COptimizedKPSetRoleTestingItem* possSubsumerItem = *it; |
| 801 |
QList<COptimizedKPSetRoleTestingItem*>* subsumersSortedList = new QList<COptimizedKPSetRoleTestingItem*>(possSubsumerItem->getPossibleSubsumerSet(false)->toList()); |
| 802 |
qSort(subsumersSortedList->begin(),subsumersSortedList->end(),itemSortMoreSubsumptionsThan); |
| 803 |
possSubsumerItem->setPossibleSubsumedList(subsumersSortedList); |
| 804 |
} |
| 805 |
} |
| 806 |
|
| 807 |
if (mConfWriteDebuggingData) { |
| 808 |
createDebugKPSetString(optKPSetClassificationItem,"./Debugging/Classification/propertykpsets-inital-pruned.txt"); |
| 809 |
} |
| 810 |
|
| 811 |
} |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
if (optKPSetClassificationItem->hasSatisfiableTestingPhaseFinished() && !optKPSetClassificationItem->hasPossibleSubsumptionTestingPhaseFinished() && !ontPropItem->isHierarchyConstructionFailed()) { |
| 816 |
|
| 817 |
QList<COptimizedKPSetRoleTestingItem*>* nextItemList = optKPSetClassificationItem->getNextPossibleSubsumptionTestingItemList(); |
| 818 |
QSet<COptimizedKPSetRoleTestingItem*>* currentItemSet = optKPSetClassificationItem->getCurrentPossibleSubsumptionTestingItemSet(); |
| 819 |
|
| 820 |
bool canContinueSearchingForTests = true; |
| 821 |
|
| 822 |
while (!workTestCreated && optKPSetClassificationItem->hasRemainingPossibleSubsumptionTests() && canContinueSearchingForTests) { |
| 823 |
// get next possible subsumption test |
| 824 |
canContinueSearchingForTests = false; |
| 825 |
|
| 826 |
COptimizedKPSetRoleTestingItem* nextPossSubsumTestItem = nullptr; |
| 827 |
if (!nextItemList->isEmpty()) { |
| 828 |
nextPossSubsumTestItem = nextItemList->takeFirst(); |
| 829 |
} |
| 830 |
|
| 831 |
if (nextPossSubsumTestItem) { |
| 832 |
canContinueSearchingForTests = true; |
| 833 |
|
| 834 |
if (mConfPossSubsumCalcOrderTopDown) { |
| 835 |
|
| 836 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumerMap = nextPossSubsumTestItem->getPossibleSubsumptionMap(false); |
| 837 |
if (possSubsumerMap && possSubsumerMap->hasRemainingPossibleSubsumptions()) { |
| 838 |
|
| 839 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumCalcData = getNextPossibleSubsumptionCalculation(optKPSetClassificationItem,nextPossSubsumTestItem); |
| 840 |
if (possSubsumCalcData) { |
| 841 |
currentItemSet->insert(nextPossSubsumTestItem); |
| 842 |
optKPSetClassificationItem->incRunningPossibleSubsumptionTestsCount(); |
| 843 |
|
| 844 |
if (calculateSubsumption(optKPSetClassificationItem,nextPossSubsumTestItem,possSubsumCalcData->getTestingItem(),possSubsumCalcData)) { |
| 845 |
workTestCreated = true; |
| 846 |
} else { |
| 847 |
interpreteSubsumptionResult(optKPSetClassificationItem,nextPossSubsumTestItem->getTestingRole(),possSubsumCalcData->getTestingItem()->getTestingRole(),possSubsumCalcData->isSubsumptionConfirmed()); |
| 848 |
} |
| 849 |
} |
| 850 |
} else { |
| 851 |
QSet<COptimizedKPSetRoleTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionTestingSet(); |
| 852 |
remTestingSet->remove(nextPossSubsumTestItem); |
| 853 |
} |
| 854 |
|
| 855 |
} else if (mConfPossSubsumCalcOrderBottomUp) { |
| 856 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumCalcData = nullptr; |
| 857 |
COptimizedKPSetRoleTestingItem* possSubsumedItem = nullptr; |
| 858 |
|
| 859 |
|
| 860 |
CRole* possSubsumerRole = nextPossSubsumTestItem->getTestingRole(); |
| 861 |
CRole* candidateRole = possSubsumerRole; |
| 862 |
|
| 863 |
QList<COptimizedKPSetRoleTestingItem*>* possSubsumedSortedList = nextPossSubsumTestItem->getPossibleSubsumerList(); |
| 864 |
if (possSubsumedSortedList && !possSubsumedSortedList->isEmpty()) { |
| 865 |
while (!possSubsumCalcData && !possSubsumedSortedList->isEmpty()) { |
| 866 |
possSubsumedItem = possSubsumedSortedList->takeFirst(); |
| 867 |
if (nextPossSubsumTestItem->getPossibleSubsumerSet(false)->contains(possSubsumedItem)) { |
| 868 |
nextPossSubsumTestItem->getPossibleSubsumerSet(false)->remove(possSubsumedItem); |
| 869 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumerMap = possSubsumedItem->getPossibleSubsumptionMap(false); |
| 870 |
if (possSubsumerMap && possSubsumerMap->hasRemainingPossibleSubsumptions()) { |
| 871 |
possSubsumCalcData = possSubsumerMap->value(CRoleTagComparer(candidateRole)); |
| 872 |
} |
| 873 |
} |
| 874 |
} |
| 875 |
} |
| 876 |
|
| 877 |
if (possSubsumCalcData) { |
| 878 |
//if ((possSubsumCalcData->isUpdateRequired() || possSubsumCalcData->isSubsumptionUnknown())) { |
| 879 |
currentItemSet->insert(nextPossSubsumTestItem); |
| 880 |
optKPSetClassificationItem->incRunningPossibleSubsumptionTestsCount(); |
| 881 |
|
| 882 |
if (calculateSubsumption(optKPSetClassificationItem,possSubsumedItem,nextPossSubsumTestItem,possSubsumCalcData)) { |
| 883 |
workTestCreated = true; |
| 884 |
} else { |
| 885 |
interpreteSubsumptionResult(optKPSetClassificationItem,possSubsumedItem->getTestingRole(),nextPossSubsumTestItem->getTestingRole(),possSubsumCalcData->isSubsumptionConfirmed()); |
| 886 |
} |
| 887 |
//} |
| 888 |
} else { |
| 889 |
QSet<COptimizedKPSetRoleTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionTestingSet(); |
| 890 |
remTestingSet->remove(nextPossSubsumTestItem); |
| 891 |
} |
| 892 |
|
| 893 |
} |
| 894 |
} |
| 895 |
} |
| 896 |
|
| 897 |
if (!workTestCreated && currentItemSet->isEmpty()) { |
| 898 |
optKPSetClassificationItem->setPossibleSubsumptionTestingPhaseFinished(true); |
| 899 |
} |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
if (!workTestCreated) { |
| 904 |
if (optKPSetClassificationItem->hasPossibleSubsumptionTestingPhaseFinished() || ontPropItem->isHierarchyConstructionFailed()) { |
| 905 |
finishOntologyClassification(ontPropItem); |
| 906 |
processingOntItemList.removeFirst(); |
| 907 |
} else { |
| 908 |
processingOntItemList.removeFirst(); |
| 909 |
processingOntItemList.append(ontPropItem); |
| 910 |
loopontPropItem = ontPropItem; |
| 911 |
} |
| 912 |
} |
| 913 |
} |
| 914 |
return workTestCreated; |
| 915 |
} |
| 916 |
|
| 917 |
|
| 918 |
COptimizedKPSetRolePossibleSubsumptionData* COptimizedKPSetRoleSubsumptionClassifierThread::getNextPossibleSubsumptionCalculation(COptimizedKPSetRoleOntologyClassificationItem *ontPropItem, COptimizedKPSetRoleTestingItem* classItem) { |
| 919 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumer = nullptr; |
| 920 |
// I don't know which is the best, simply return the first one |
| 921 |
// sort by subsumer count? |
| 922 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumerMap = classItem->getPossibleSubsumptionMap(false); |
| 923 |
if (possSubsumerMap) { |
| 924 |
if (mConfPossSubsumCalcOrderRoleSorted) { |
| 925 |
for (COptimizedKPSetRolePossibleSubsumptionMap::const_iterator it = possSubsumerMap->constBegin(), itEnd = possSubsumerMap->constEnd(); !possSubsumer && it != itEnd; ++it) { |
| 926 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumData = it.value(); |
| 927 |
if (possSubsumData->isSubsumptionUnknown()) { |
| 928 |
possSubsumer = possSubsumData; |
| 929 |
} else if (possSubsumData->isUpdateRequired()) { |
| 930 |
prunePossibleSubsumptions(ontPropItem,classItem,possSubsumData); |
| 931 |
} |
| 932 |
} |
| 933 |
} |
| 934 |
} |
| 935 |
return possSubsumer; |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::calculateSatisfiable(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* nextSatTestItem) { |
| 940 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 941 |
CPropertyClassificationComputationItem *workItem = 0; |
| 942 |
|
| 943 |
|
| 944 |
//if (CIRIName::getRecentIRIName(nextSatTestItem->getTestingRole()->getPropertyNameLinker()) == "http://www.owllink.org/testsuite/particle-D#Neutrino" || CIRIName::getRecentIRIName(nextSatTestItem->getTestingRole()->getPropertyNameLinker()) == "http://www.co-ode.org/roberts/family-tree.owl#isBrotherInLawOf") { |
| 945 |
// bool bug = true; |
| 946 |
//} |
| 947 |
|
| 948 |
|
| 949 |
CConcept* existConcept = nextSatTestItem->getTemporaryExistConcept(); |
| 950 |
CConcept* allPropConcept = optKPSetClassificationItem->getTemporaryAllPropagationConcept(); |
| 951 |
|
| 952 |
|
| 953 |
nextSatTestItem->setSatisfiableTestOrdered(true); |
| 954 |
|
| 955 |
bool satisfiableFlag = false; |
| 956 |
|
| 957 |
if (nextSatTestItem->isResultSatisfiableDerivated()) { |
| 958 |
satisfiableFlag = true; |
| 959 |
nextSatTestItem->setSatisfiableTested(true); |
| 960 |
nextSatTestItem->setSatisfiableTestedResult(true); |
| 961 |
return false; |
| 962 |
} |
| 963 |
if (nextSatTestItem->isResultUnsatisfiableDerivated()) { |
| 964 |
satisfiableFlag = false; |
| 965 |
nextSatTestItem->setSatisfiableTested(true); |
| 966 |
nextSatTestItem->setSatisfiableTestedResult(false); |
| 967 |
return false; |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
CIndividual* tmpIndiPropagation = optKPSetClassificationItem->getTemporaryPropagationIndividual(); |
| 972 |
CIndividual* tmpIndiMarker = optKPSetClassificationItem->getTemporaryMarkerIndividual(); |
| 973 |
CRole* role = nextSatTestItem->getTestingRole(); |
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
CSatisfiableCalculationJobGenerator satCalcJobGen(optKPSetClassificationItem->getOntology()); |
| 978 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(existConcept,false,tmpIndiPropagation,satCalcJob); |
| 979 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(allPropConcept,false,tmpIndiPropagation,satCalcJob); |
| 980 |
if (optKPSetClassificationItem->isDataRolesClassification()) { |
| 981 |
CConcept* topDataConcept = optKPSetClassificationItem->getOntology()->getTBox()->getTopDataRangeConcept(); |
| 982 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(topDataConcept,false,tmpIndiMarker,satCalcJob); |
| 983 |
} else { |
| 984 |
CConcept* topConcept = optKPSetClassificationItem->getOntology()->getTBox()->getTopConcept(); |
| 985 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(topConcept,false,tmpIndiMarker,satCalcJob); |
| 986 |
} |
| 987 |
|
| 988 |
QHash<CSatisfiableCalculationJob*,CPropertyClassificationComputationItem*> *workHash = optKPSetClassificationItem->getComputationItemHash(); |
| 989 |
|
| 990 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 991 |
if (ontClassStat) { |
| 992 |
ontClassStat->incCalculatedTestedSatisfiableCount(1); |
| 993 |
} |
| 994 |
|
| 995 |
workItem = new CPropertyClassificationComputationItem(satCalcJob,role); |
| 996 |
workHash->insertMulti(satCalcJob,workItem); |
| 997 |
workOntItemHash.insert(workItem,optKPSetClassificationItem); |
| 998 |
|
| 999 |
satCalcJob->setSatisfiableClassificationRoleMarkedMessageAdapter(new CSatisfiableTaskClassificationRoleMarkedMessageAdapter(role,tmpIndiPropagation,tmpIndiMarker,optKPSetClassificationItem->getOntology(),this)); |
| 1000 |
|
| 1001 |
optKPSetClassificationItem->incCurrentCalculatingCount(); |
| 1002 |
if (optKPSetClassificationItem->getIndividualDependenceTrackingCollector()) { |
| 1003 |
satCalcJob->setSatisfiableTaskIndividualDependenceTrackingAdapter(new CSatisfiableTaskIndividualDependenceTrackingAdapter(optKPSetClassificationItem->getIndividualDependenceTrackingCollector())); |
| 1004 |
} |
| 1005 |
|
| 1006 |
processCalculationJob(satCalcJob,optKPSetClassificationItem,workItem); |
| 1007 |
|
| 1008 |
|
| 1009 |
++mCreatedCalculationTaskCount; |
| 1010 |
return true; |
| 1011 |
} |
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::calculateSubsumption(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* subsumedItem, COptimizedKPSetRoleTestingItem* possSubsumerItem, COptimizedKPSetRolePossibleSubsumptionData* possSubsumData) { |
| 1018 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 1019 |
CPropertyClassificationComputationItem *workItem = 0; |
| 1020 |
++mOrderedSubsumptionCalculationCount; |
| 1021 |
|
| 1022 |
CRole* subsumedRole = subsumedItem->getTestingRole(); |
| 1023 |
CRole* subsumerRole = possSubsumerItem->getTestingRole(); |
| 1024 |
|
| 1025 |
bool isSubsumptionFlag = false; |
| 1026 |
bool precheckedSubsum = false; |
| 1027 |
|
| 1028 |
|
| 1029 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 1030 |
if (possSubsumData && possSubsumData->isSubsumptionKnown()) { |
| 1031 |
return false; |
| 1032 |
} else if (possSubsumData && subsumedItem->hasSubsumerRoleItem(possSubsumerItem)) { |
| 1033 |
possSubsumData->setSubsumptionConfirmed(true); |
| 1034 |
return false; |
| 1035 |
} |
| 1036 |
|
| 1037 |
CIndividual* tmpIndiPropagation = optKPSetClassificationItem->getTemporaryPropagationIndividual(); |
| 1038 |
CIndividual* tmpIndiMarker = optKPSetClassificationItem->getTemporaryMarkerIndividual(); |
| 1039 |
CConcept* existConcept = subsumedItem->getTemporaryExistConcept(); |
| 1040 |
CConcept* propagationConcept = possSubsumerItem->getTemporaryPropagationConcept(); |
| 1041 |
|
| 1042 |
CSatisfiableCalculationJobGenerator satCalcJobGen(optKPSetClassificationItem->getOntology()); |
| 1043 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(existConcept,false,tmpIndiPropagation,satCalcJob); |
| 1044 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(propagationConcept,false,tmpIndiPropagation,satCalcJob); |
| 1045 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(possSubsumerItem->getTemporaryMarkerConcept(),true,tmpIndiMarker,satCalcJob); |
| 1046 |
if (optKPSetClassificationItem->isDataRolesClassification()) { |
| 1047 |
CConcept* topDataConcept = optKPSetClassificationItem->getOntology()->getTBox()->getTopDataRangeConcept(); |
| 1048 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(topDataConcept,false,tmpIndiMarker,satCalcJob); |
| 1049 |
} else { |
| 1050 |
CConcept* topConcept = optKPSetClassificationItem->getOntology()->getTBox()->getTopConcept(); |
| 1051 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(topConcept,false,tmpIndiMarker,satCalcJob); |
| 1052 |
} |
| 1053 |
|
| 1054 |
|
| 1055 |
QHash<CSatisfiableCalculationJob *, CPropertyClassificationComputationItem *> *workHash = optKPSetClassificationItem->getComputationItemHash(); |
| 1056 |
|
| 1057 |
if (ontClassStat) { |
| 1058 |
ontClassStat->incCalculatedTestedSubsumptionCount(1); |
| 1059 |
ontClassStat->incToldSubsumptionCount(1); |
| 1060 |
} |
| 1061 |
|
| 1062 |
workItem = new CPropertyClassificationComputationItem(satCalcJob,subsumerRole,subsumedRole); |
| 1063 |
workHash->insertMulti(satCalcJob,workItem); |
| 1064 |
workOntItemHash.insert(workItem,optKPSetClassificationItem); |
| 1065 |
|
| 1066 |
|
| 1067 |
if (optKPSetClassificationItem->getIndividualDependenceTrackingCollector()) { |
| 1068 |
satCalcJob->setSatisfiableTaskIndividualDependenceTrackingAdapter(new CSatisfiableTaskIndividualDependenceTrackingAdapter(optKPSetClassificationItem->getIndividualDependenceTrackingCollector())); |
| 1069 |
} |
| 1070 |
|
| 1071 |
optKPSetClassificationItem->incCurrentCalculatingCount(); |
| 1072 |
processCalculationJob(satCalcJob,optKPSetClassificationItem,workItem); |
| 1073 |
optKPSetClassificationItem->incCalculatedPossibleSubsumerCount(); |
| 1074 |
++mCreatedCalculationTaskCount; |
| 1075 |
return true; |
| 1076 |
} |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
void COptimizedKPSetRoleSubsumptionClassifierThread::incRemainingPossibleSubsumptionTestingCount(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRolePossibleSubsumptionMap* posSubsumMap) { |
| 1085 |
optKPSetClassificationItem->incPossibleSubsumerCount(); |
| 1086 |
optKPSetClassificationItem->incRemainingPossibleSubsumptionTestsCount(); |
| 1087 |
posSubsumMap->incRemainingPossibleSubsumptionCount(); |
| 1088 |
++totalToSubsumTestCount; |
| 1089 |
} |
| 1090 |
|
| 1091 |
|
| 1092 |
void COptimizedKPSetRoleSubsumptionClassifierThread::decRemainingPossibleSubsumptionTestingCount(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRolePossibleSubsumptionMap* posSubsumMap, bool subsumptionConfirmed) { |
| 1093 |
if (subsumptionConfirmed) { |
| 1094 |
optKPSetClassificationItem->incTruePossibleSubsumerCount(); |
| 1095 |
} else { |
| 1096 |
optKPSetClassificationItem->incFalsePossibleSubsumerCount(); |
| 1097 |
} |
| 1098 |
optKPSetClassificationItem->decRemainingPossibleSubsumptionTestsCount(); |
| 1099 |
posSubsumMap->decRemainingPossibleSubsumptionCount(); |
| 1100 |
++subsumTestedCount; |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
CSubsumptionClassifierThread *COptimizedKPSetRoleSubsumptionClassifierThread::processCalculationJob(CSatisfiableCalculationJob* job, COntologyPropertyRoleClassificationItem *ontPropItem, CPropertyClassificationComputationItem* workItem) { |
| 1107 |
CClassificationCalculationStatisticsCollection* statColl = nullptr; |
| 1108 |
if (ontPropItem->isCollectProcessStatisticsActivated()) { |
| 1109 |
statColl = ontPropItem->getCalculationStatisticsCollection(); |
| 1110 |
} |
| 1111 |
job->setCalclulationStatisticsCollector(statColl); |
| 1112 |
CTestCalculatedCallbackEvent *testResultCallback = new CTestCalculatedCallbackEvent(this,job,workItem,statColl); |
| 1113 |
job->setCalculationConfiguration(ontPropItem->getCalculationConfiguration()); |
| 1114 |
CSubsumptionClassifierThread::processCalculationJob(job,ontPropItem,testResultCallback,false); |
| 1115 |
return this; |
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::processToldClassificationMessage(COntologyClassificationItem *ontPropItem, CClassificationMessageData* messageDataLinker, CMemoryPool* memoryPools) { |
| 1121 |
COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetRoleOntologyClassificationItem *)ontPropItem; |
| 1122 |
CClassificationMessageData* messageDataLinkerIt = messageDataLinker; |
| 1123 |
while (messageDataLinkerIt) { |
| 1124 |
CClassificationMessageData* messageData = messageDataLinkerIt; |
| 1125 |
if (messageData->getClassificationMessageDataType() == CClassificationMessageData::TELLPROPERTYSUBSUMPTION) { |
| 1126 |
++mStatProcesedSubsumMessCount; |
| 1127 |
CClassificationPropertySubsumptionMessageData* subsumMessageData = (CClassificationPropertySubsumptionMessageData*)messageData; |
| 1128 |
CRole* subsumedRole = subsumMessageData->getSubsumedRole(); |
| 1129 |
CPROPERTYSUBSUMPTIONMESSAGELIST<CRole*>* subsumerList = subsumMessageData->getPropertySubsumerList(); |
| 1130 |
|
| 1131 |
COptimizedKPSetRoleTestingItem* subsumedItem = nullptr; |
| 1132 |
subsumedItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(subsumedRole); |
| 1133 |
|
| 1134 |
CRole* topRole = optKPSetClassificationItem->getTopRoleSatisfiableTestItem()->getTestingRole(); |
| 1135 |
|
| 1136 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = subsumedItem->getPossibleSubsumptionMap(false); |
| 1137 |
if (subsumerList) { |
| 1138 |
for (CPROPERTYSUBSUMPTIONMESSAGELIST<CRole*>::const_iterator it = subsumerList->constBegin(), itEnd = subsumerList->constEnd(); it != itEnd; ++it) { |
| 1139 |
CRole* subsumerRole(*it); |
| 1140 |
if (subsumerRole != topRole) { |
| 1141 |
COptimizedKPSetRoleTestingItem* subsumerItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(subsumerRole); |
| 1142 |
if (subsumedItem != subsumerItem) { |
| 1143 |
subsumedItem->addSubsumerRoleItem(subsumerItem); |
| 1144 |
if (possSubsumMap) { |
| 1145 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumData = possSubsumMap->value(subsumerRole,nullptr); |
| 1146 |
if (possSubsumData) { |
| 1147 |
if (!possSubsumData->isSubsumptionConfirmed()) { |
| 1148 |
possSubsumData->setSubsumptionConfirmed(true); |
| 1149 |
|
| 1150 |
if (possSubsumData->isUpdateRequired()) { |
| 1151 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possSubsumData); |
| 1152 |
} |
| 1153 |
} |
| 1154 |
} |
| 1155 |
} |
| 1156 |
propagateDownSubsumption(optKPSetClassificationItem,subsumedItem,subsumerItem); |
| 1157 |
} |
| 1158 |
} |
| 1159 |
} |
| 1160 |
} |
| 1161 |
subsumedItem->setResultSatisfiableDerivated(true); |
| 1162 |
|
| 1163 |
} else if (messageData->getClassificationMessageDataType() == CClassificationMessageData::TELLCLASSINITIALIZEPOSSIBLESUBSUM) { |
| 1164 |
++mStatProcesedPossSubsumInitMessCount; |
| 1165 |
CClassificationInitializePossiblePropertySubsumptionMessageData* possSubsumMessageData = (CClassificationInitializePossiblePropertySubsumptionMessageData*)messageData; |
| 1166 |
CRole* subsumedRole = possSubsumMessageData->getSubsumedRole(); |
| 1167 |
CPROPERTYPOSSIBLESUBSUMPTIONMESSAGELIST<CClassificationInitializePossiblePropertySubsumptionData*>* possSubsumerList = possSubsumMessageData->getPropertyPossibleSubsumerList(); |
| 1168 |
|
| 1169 |
|
| 1170 |
COptimizedKPSetRoleTestingItem* subsumedItem = nullptr; |
| 1171 |
subsumedItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(subsumedRole); |
| 1172 |
CRole* topRole = optKPSetClassificationItem->getTopRoleSatisfiableTestItem()->getTestingRole(); |
| 1173 |
|
| 1174 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = subsumedItem->getPossibleSubsumptionMap(false); |
| 1175 |
if (!possSubsumerList || possSubsumerList->empty()) { |
| 1176 |
if (possSubsumMap) { |
| 1177 |
for (COptimizedKPSetRolePossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 1178 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumData = it.value(); |
| 1179 |
if (possSubsumData->isSubsumptionUnknown()) { |
| 1180 |
possSubsumData->setSubsumptionInvalid(true); |
| 1181 |
if (possSubsumData->isUpdateRequired()) { |
| 1182 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possSubsumData); |
| 1183 |
} |
| 1184 |
} |
| 1185 |
} |
| 1186 |
} |
| 1187 |
} else { |
| 1188 |
if (!subsumedItem->isPossibleSubsumptionMapInitialized() || possSubsumMap) { |
| 1189 |
possSubsumMap = subsumedItem->getPossibleSubsumptionMap(true); |
| 1190 |
if (possSubsumMap->isEmpty()) { |
| 1191 |
// initialize the possible subsumption map |
| 1192 |
if (possSubsumerList) { |
| 1193 |
for (CPROPERTYPOSSIBLESUBSUMPTIONMESSAGELIST<CClassificationInitializePossiblePropertySubsumptionData*>::const_iterator it = possSubsumerList->constBegin(), itEnd = possSubsumerList->constEnd(); it != itEnd; ++it) { |
| 1194 |
CClassificationInitializePossiblePropertySubsumptionData* possSubsumDataIt = *it; |
| 1195 |
if (possSubsumDataIt->isPossibleSubsumerValid()) { |
| 1196 |
CRole* possSubsumRole = possSubsumDataIt->getPossibleSubsumerRole(); |
| 1197 |
COptimizedKPSetRoleTestingItem* possSubsumItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(possSubsumRole); |
| 1198 |
if (possSubsumRole != topRole && subsumedItem != possSubsumItem && !subsumedItem->hasSubsumerRoleItem(possSubsumItem)) { |
| 1199 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumData = new COptimizedKPSetRolePossibleSubsumptionData(possSubsumItem); |
| 1200 |
possSubsumMap->insert(CRoleTagComparer(possSubsumRole),possSubsumData); |
| 1201 |
incRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap); |
| 1202 |
} |
| 1203 |
} |
| 1204 |
} |
| 1205 |
} |
| 1206 |
|
| 1207 |
|
| 1208 |
// prune ancestor items |
| 1209 |
QSet<COptimizedKPSetRoleTestingItem*>* upPropSet = subsumedItem->getUpPropagationItemSet(); |
| 1210 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator it = upPropSet->constBegin(), itEnd = upPropSet->constEnd(); it != itEnd; ++it) { |
| 1211 |
COptimizedKPSetRoleTestingItem* upPropItem = *it; |
| 1212 |
COptimizedKPSetRolePossibleSubsumptionMap* upPropItemPossSubsumMap = upPropItem->getPossibleSubsumptionMap(false); |
| 1213 |
if (upPropItemPossSubsumMap) { |
| 1214 |
COptimizedKPSetRolePossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); |
| 1215 |
COptimizedKPSetRolePossibleSubsumptionMap::const_iterator itUpPoss = upPropItemPossSubsumMap->constBegin(), itUpPossEnd = upPropItemPossSubsumMap->constEnd(); |
| 1216 |
while (itPoss != itPossEnd && itUpPoss != itUpPossEnd) { |
| 1217 |
CRole* possRole = itPoss.key().getRole(); |
| 1218 |
CRole* possUpRole = itUpPoss.key().getRole(); |
| 1219 |
if (possRole->getRoleTag() == possUpRole->getRoleTag()) { |
| 1220 |
++itPoss; |
| 1221 |
++itUpPoss; |
| 1222 |
} else if (possRole->getRoleTag() < possUpRole->getRoleTag()) { |
| 1223 |
++itPoss; |
| 1224 |
} else if (possRole->getRoleTag() > possUpRole->getRoleTag()) { |
| 1225 |
COptimizedKPSetRolePossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 1226 |
if (!subsumedItem->hasSubsumerRoleItem(upPossData->getTestingItem()) && subsumedItem != upPossData->getTestingItem()) { |
| 1227 |
if (!upPossData->isSubsumptionInvalided()) { |
| 1228 |
upPossData->setSubsumptionInvalid(true); |
| 1229 |
if (upPossData->isUpdateRequired()) { |
| 1230 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 1231 |
} |
| 1232 |
} |
| 1233 |
} |
| 1234 |
++itUpPoss; |
| 1235 |
} |
| 1236 |
} |
| 1237 |
while (itUpPoss != itUpPossEnd) { |
| 1238 |
COptimizedKPSetRolePossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 1239 |
if (!subsumedItem->hasSubsumerRoleItem(upPossData->getTestingItem()) && subsumedItem != upPossData->getTestingItem()) { |
| 1240 |
if (!upPossData->isSubsumptionInvalided()) { |
| 1241 |
upPossData->setSubsumptionInvalid(true); |
| 1242 |
if (upPossData->isUpdateRequired()) { |
| 1243 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 1244 |
} |
| 1245 |
} |
| 1246 |
} |
| 1247 |
++itUpPoss; |
| 1248 |
} |
| 1249 |
} |
| 1250 |
} |
| 1251 |
|
| 1252 |
// prune descendant items |
| 1253 |
QSet<COptimizedKPSetRoleTestingItem*>* downPropSet = subsumedItem->getDownPropagationItemSet(); |
| 1254 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator it = downPropSet->constBegin(), itEnd = downPropSet->constEnd(); it != itEnd; ++it) { |
| 1255 |
COptimizedKPSetRoleTestingItem* downPropItem = *it; |
| 1256 |
COptimizedKPSetRolePossibleSubsumptionMap* downPropItemPossSubsumMap = downPropItem->getPossibleSubsumptionMap(false); |
| 1257 |
if (downPropItemPossSubsumMap) { |
| 1258 |
COptimizedKPSetRolePossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); |
| 1259 |
COptimizedKPSetRolePossibleSubsumptionMap::const_iterator itDownPoss = downPropItemPossSubsumMap->constBegin(), itDownPossEnd = downPropItemPossSubsumMap->constEnd(); |
| 1260 |
while (itPoss != itPossEnd && itDownPoss != itDownPossEnd) { |
| 1261 |
CRole* possRole = itPoss.key().getRole(); |
| 1262 |
CRole* possDownRole = itDownPoss.key().getRole(); |
| 1263 |
if (possRole->getRoleTag() == possDownRole->getRoleTag()) { |
| 1264 |
++itPoss; |
| 1265 |
++itDownPoss; |
| 1266 |
} else if (possDownRole->getRoleTag() < possRole->getRoleTag()) { |
| 1267 |
++itDownPoss; |
| 1268 |
} else if (possDownRole->getRoleTag() > possRole->getRoleTag()) { |
| 1269 |
COptimizedKPSetRolePossibleSubsumptionData* possData = itPoss.value(); |
| 1270 |
if (!downPropItem->hasSubsumerRoleItem(possData->getTestingItem()) && downPropItem != possData->getTestingItem()) { |
| 1271 |
if (!possData->isSubsumptionInvalided()) { |
| 1272 |
possData->setSubsumptionInvalid(true); |
| 1273 |
if (possData->isUpdateRequired()) { |
| 1274 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 1275 |
} |
| 1276 |
} |
| 1277 |
} |
| 1278 |
++itPoss; |
| 1279 |
} |
| 1280 |
} |
| 1281 |
while (itPoss != itPossEnd) { |
| 1282 |
COptimizedKPSetRolePossibleSubsumptionData* possData = itDownPoss.value(); |
| 1283 |
if (!downPropItem->hasSubsumerRoleItem(possData->getTestingItem()) && downPropItem != possData->getTestingItem()) { |
| 1284 |
if (!possData->isSubsumptionInvalided()) { |
| 1285 |
possData->setSubsumptionInvalid(true); |
| 1286 |
if (possData->isUpdateRequired()) { |
| 1287 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 1288 |
} |
| 1289 |
} |
| 1290 |
} |
| 1291 |
++itPoss; |
| 1292 |
} |
| 1293 |
} else if (downPropItem->isPossibleSubsumptionMapInitialized()) { |
| 1294 |
for (COptimizedKPSetRolePossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); itPoss != itPossEnd; ++itPoss) { |
| 1295 |
COptimizedKPSetRolePossibleSubsumptionData* possData = itPoss.value(); |
| 1296 |
if (!downPropItem->hasSubsumerRoleItem(possData->getTestingItem()) && downPropItem != possData->getTestingItem()) { |
| 1297 |
if (!possData->isSubsumptionInvalided()) { |
| 1298 |
possData->setSubsumptionInvalid(true); |
| 1299 |
if (possData->isUpdateRequired()) { |
| 1300 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 1301 |
} |
| 1302 |
} |
| 1303 |
} |
| 1304 |
} |
| 1305 |
} |
| 1306 |
} |
| 1307 |
|
| 1308 |
} else { |
| 1309 |
// prune the possible subsumption map |
| 1310 |
COptimizedKPSetRolePossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); |
| 1311 |
if (possSubsumerList) { |
| 1312 |
CPROPERTYPOSSIBLESUBSUMPTIONMESSAGELIST<CClassificationInitializePossiblePropertySubsumptionData*>::const_iterator itNew = possSubsumerList->constBegin(), itNewEnd = possSubsumerList->constEnd(); |
| 1313 |
while (itPoss != itPossEnd && itNew != itNewEnd) { |
| 1314 |
COptimizedKPSetRolePossibleSubsumptionData* possData = itPoss.value(); |
| 1315 |
CRole* possRole = itPoss.key().getRole(); |
| 1316 |
CClassificationInitializePossiblePropertySubsumptionData* possNewSubsumDataIt = *itNew; |
| 1317 |
if (possNewSubsumDataIt->isPossibleSubsumerValid()) { |
| 1318 |
CRole* newRole = possNewSubsumDataIt->getPossibleSubsumerRole(); |
| 1319 |
if (possRole->getRoleTag() == newRole->getRoleTag()) { |
| 1320 |
++itPoss; |
| 1321 |
++itNew; |
| 1322 |
} else if (possRole->getRoleTag() < newRole->getRoleTag()) { |
| 1323 |
if (!possData->isSubsumptionInvalided()) { |
| 1324 |
possData->setSubsumptionInvalid(true); |
| 1325 |
if (possData->isUpdateRequired()) { |
| 1326 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 1327 |
} |
| 1328 |
} |
| 1329 |
++itPoss; |
| 1330 |
} else if (possRole->getRoleTag() > newRole->getRoleTag()) { |
| 1331 |
++itNew; |
| 1332 |
} |
| 1333 |
} else { |
| 1334 |
++itNew; |
| 1335 |
} |
| 1336 |
} |
| 1337 |
} |
| 1338 |
while (itPoss != itPossEnd) { |
| 1339 |
COptimizedKPSetRolePossibleSubsumptionData* possData = itPoss.value(); |
| 1340 |
CRole* possRole = itPoss.key().getRole(); |
| 1341 |
if (!possData->isSubsumptionInvalided()) { |
| 1342 |
possData->setSubsumptionInvalid(true); |
| 1343 |
if (possData->isUpdateRequired()) { |
| 1344 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 1345 |
} |
| 1346 |
} |
| 1347 |
++itPoss; |
| 1348 |
} |
| 1349 |
} |
| 1350 |
} |
| 1351 |
} |
| 1352 |
subsumedItem->setPossibleSubsumptionMapInitialized(true); |
| 1353 |
|
| 1354 |
|
| 1355 |
} else if (messageData->getClassificationMessageDataType() == CClassificationMessageData::TELLPROPERTYUPDATEPOSSIBLESUBSUM) { |
| 1356 |
++mStatProcesedPossSubsumUpdateMessCount; |
| 1357 |
CClassificationUpdatePossiblePropertySubsumptionMessageData* possSubsumMessageData = (CClassificationUpdatePossiblePropertySubsumptionMessageData*)messageData; |
| 1358 |
CRole* subsumedRole = possSubsumMessageData->getSubsumedRole(); |
| 1359 |
|
| 1360 |
COptimizedKPSetRoleTestingItem* subsumedItem = nullptr; |
| 1361 |
subsumedItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(subsumedRole); |
| 1362 |
|
| 1363 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = subsumedItem->getPossibleSubsumptionMap(false); |
| 1364 |
if (possSubsumMap && !possSubsumMap->empty()) { |
| 1365 |
possSubsumMap = subsumedItem->getPossibleSubsumptionMap(true); |
| 1366 |
for (COptimizedKPSetRolePossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 1367 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumData = it.value(); |
| 1368 |
if (possSubsumData->isUpdateRequired()) { |
| 1369 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possSubsumData); |
| 1370 |
} |
| 1371 |
} |
| 1372 |
} |
| 1373 |
} |
| 1374 |
messageDataLinkerIt = messageDataLinkerIt->getNext(); |
| 1375 |
} |
| 1376 |
return true; |
| 1377 |
} |
| 1378 |
|
| 1379 |
|
| 1380 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::interpreteToldSubsumptionResult(COntologyPropertyRoleClassificationItem *ontPropItem, const QList< QPair<CRole*,CRole*> > &subSumRelList, bool isSubSum) { |
| 1381 |
CRole *lastRole = nullptr; |
| 1382 |
COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetRoleOntologyClassificationItem *)ontPropItem; |
| 1383 |
COptimizedKPSetRoleTestingItem* subsumerItem = nullptr; |
| 1384 |
|
| 1385 |
for (QList< QPair<CRole*,CRole*> >::const_iterator it = subSumRelList.constBegin(), itEnd = subSumRelList.constEnd(); it != itEnd; ++it) { |
| 1386 |
CRole *subsumerRole = it->first; |
| 1387 |
if (lastRole != subsumerRole) { |
| 1388 |
lastRole = subsumerRole; |
| 1389 |
subsumerItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(subsumerRole); |
| 1390 |
} |
| 1391 |
CRole *subsumedRole = it->second; |
| 1392 |
if (isSubSum) { |
| 1393 |
COptimizedKPSetRoleTestingItem* subsumedItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(subsumedRole); |
| 1394 |
subsumerItem->addSubsumerRoleItem(subsumedItem); |
| 1395 |
} |
| 1396 |
} |
| 1397 |
return true; |
| 1398 |
} |
| 1399 |
|
| 1400 |
|
| 1401 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::interpreteSubsumptionResult(COntologyPropertyRoleClassificationItem *ontPropItem, CRole *subsumedRole, CRole *subsumerRole, bool isSubsumption) { |
| 1402 |
COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetRoleOntologyClassificationItem *)ontPropItem; |
| 1403 |
|
| 1404 |
++mInterpretedSubsumptionCalculationCount; |
| 1405 |
|
| 1406 |
optKPSetClassificationItem->decRunningPossibleSubsumptionTestsCount(); |
| 1407 |
|
| 1408 |
COptimizedKPSetRoleTestingItem* subsumedItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(subsumedRole); |
| 1409 |
COptimizedKPSetRoleTestingItem* subsumerItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(subsumerRole); |
| 1410 |
|
| 1411 |
|
| 1412 |
//QString iriPropertyNameString1 = CIRIName::getRecentIRIName(subsumedRole->getPropertyNameLinker()); |
| 1413 |
//QString iriPropertyNameString2 = CIRIName::getRecentIRIName(subsumerRole->getPropertyNameLinker()); |
| 1414 |
//if (iriPropertyNameString1 == "http://www.bootstrep.eu/ontology/GRO#BindingOfProteinToProteinBindingSiteOfDNA" && iriPropertyNameString2 == "http://www.bootstrep.eu/ontology/GRO#DNAProteinInteraction" && !isSubsumption) { |
| 1415 |
// bool bug = true; |
| 1416 |
// calculateSubsumption(optKPSetPropertyificationItem,subsumedItem,subsumerItem,nullptr); |
| 1417 |
//} |
| 1418 |
|
| 1419 |
|
| 1420 |
COptimizedKPSetRoleTestingItem* topItem = optKPSetClassificationItem->getTopRoleSatisfiableTestItem(); |
| 1421 |
|
| 1422 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = subsumedItem->getPossibleSubsumptionMap(false); |
| 1423 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumData = nullptr; |
| 1424 |
if (possSubsumMap) { |
| 1425 |
possSubsumData = possSubsumMap->value(subsumerRole); |
| 1426 |
} |
| 1427 |
|
| 1428 |
if (isSubsumption) { |
| 1429 |
optKPSetClassificationItem->incCalculatedTruePossibleSubsumerCount(); |
| 1430 |
if (possSubsumData) { |
| 1431 |
possSubsumData->setSubsumptionConfirmed(true); |
| 1432 |
} |
| 1433 |
subsumedItem->addSubsumerRoleItem(subsumerItem); |
| 1434 |
subsumedItem->addUpPropagationItem(subsumerItem); |
| 1435 |
subsumerItem->addDownPropagationItem(subsumedItem); |
| 1436 |
propagateDownSubsumption(optKPSetClassificationItem,subsumedItem,subsumerItem); |
| 1437 |
} else { |
| 1438 |
|
| 1439 |
optKPSetClassificationItem->incCalculatedFalsePossibleSubsumerCount(); |
| 1440 |
if (possSubsumData) { |
| 1441 |
possSubsumData->setSubsumptionInvalid(true); |
| 1442 |
} |
| 1443 |
} |
| 1444 |
|
| 1445 |
if (possSubsumData && possSubsumData->isUpdateRequired()) { |
| 1446 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possSubsumData); |
| 1447 |
} |
| 1448 |
|
| 1449 |
|
| 1450 |
QList<COptimizedKPSetRoleTestingItem*>* nextItemList = optKPSetClassificationItem->getNextPossibleSubsumptionTestingItemList(); |
| 1451 |
QSet<COptimizedKPSetRoleTestingItem*>* currentItemSet = optKPSetClassificationItem->getCurrentPossibleSubsumptionTestingItemSet(); |
| 1452 |
if (mConfPossSubsumCalcOrderTopDown) { |
| 1453 |
if (currentItemSet->contains(subsumedItem)) { |
| 1454 |
currentItemSet->remove(subsumedItem); |
| 1455 |
if (possSubsumMap) { |
| 1456 |
if (possSubsumMap->hasRemainingPossibleSubsumptions()) { |
| 1457 |
nextItemList->prepend(subsumedItem); |
| 1458 |
} else { |
| 1459 |
QSet<COptimizedKPSetRoleTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionTestingSet(); |
| 1460 |
remTestingSet->remove(subsumedItem); |
| 1461 |
} |
| 1462 |
} |
| 1463 |
} |
| 1464 |
} |
| 1465 |
if (mConfPossSubsumCalcOrderBottomUp) { |
| 1466 |
if (currentItemSet->contains(subsumerItem)) { |
| 1467 |
currentItemSet->remove(subsumerItem); |
| 1468 |
if (subsumerItem->hasRemainingPossibleSubsumedItems()) { |
| 1469 |
QSet<COptimizedKPSetRoleTestingItem*>* remPossSubsumedItemSet = subsumerItem->getPossibleSubsumerSet(false); |
| 1470 |
QList<COptimizedKPSetRoleTestingItem*>* remPossSubsumedItemList = subsumerItem->getPossibleSubsumerList(); |
| 1471 |
nextItemList->prepend(subsumerItem); |
| 1472 |
|
| 1473 |
QSet<COptimizedKPSetRoleTestingItem*>* upPropSet = subsumedItem->getUpPropagationItemSet(); |
| 1474 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator itUp = upPropSet->constBegin(), itUpEnd = upPropSet->constEnd(); itUp != itUpEnd; ++itUp) { |
| 1475 |
COptimizedKPSetRoleTestingItem* upItem = *itUp; |
| 1476 |
if (remPossSubsumedItemSet->contains(upItem)) { |
| 1477 |
remPossSubsumedItemList->prepend(upItem); |
| 1478 |
} |
| 1479 |
} |
| 1480 |
|
| 1481 |
} else { |
| 1482 |
QSet<COptimizedKPSetRoleTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionTestingSet(); |
| 1483 |
remTestingSet->remove(subsumerItem); |
| 1484 |
} |
| 1485 |
} |
| 1486 |
} |
| 1487 |
return true; |
| 1488 |
} |
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::prunePossibleSubsumptions(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* item, COptimizedKPSetRolePossibleSubsumptionData* possSubsumData) { |
| 1493 |
|
| 1494 |
if (possSubsumData->isUpdateRequired()) { |
| 1495 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 1496 |
possSubsumData->setSubsumptionUpdated(true); |
| 1497 |
decRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap,true); |
| 1498 |
if (possSubsumData->isSubsumptionConfirmed()) { |
| 1499 |
// is subsuming |
| 1500 |
COptimizedKPSetRoleTestingItem* subsumerItem = possSubsumData->getTestingItem(); |
| 1501 |
CRole* subsumerRole = subsumerItem->getTestingRole(); |
| 1502 |
// establish the subsumption for all successor nodes |
| 1503 |
QSet<COptimizedKPSetRoleTestingItem*>* downPropSet = item->getDownPropagationItemSet(); |
| 1504 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator it = downPropSet->constBegin(), itEnd = downPropSet->constEnd(); it != itEnd; ++it) { |
| 1505 |
COptimizedKPSetRoleTestingItem* downPropItem = *it; |
| 1506 |
pruneDownSubsumption(optKPSetClassificationItem,downPropItem,subsumerRole); |
| 1507 |
} |
| 1508 |
return true; |
| 1509 |
} else { |
| 1510 |
// is not subsuming |
| 1511 |
COptimizedKPSetRoleTestingItem* notSubsumerItem = possSubsumData->getTestingItem(); |
| 1512 |
CRole* notSubsumerRole = notSubsumerItem->getTestingRole(); |
| 1513 |
// establish the subsumption for all successor nodes |
| 1514 |
QSet<COptimizedKPSetRoleTestingItem*>* upPropSet = item->getUpPropagationItemSet(); |
| 1515 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator it = upPropSet->constBegin(), itEnd = upPropSet->constEnd(); it != itEnd; ++it) { |
| 1516 |
COptimizedKPSetRoleTestingItem* upPropItem = *it; |
| 1517 |
pruneUpNotSubsumption(optKPSetClassificationItem,upPropItem,notSubsumerRole); |
| 1518 |
} |
| 1519 |
|
| 1520 |
return true; |
| 1521 |
|
| 1522 |
} |
| 1523 |
} |
| 1524 |
return false; |
| 1525 |
} |
| 1526 |
|
| 1527 |
|
| 1528 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::propagateDownSubsumption(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* item, COptimizedKPSetRoleTestingItem* subsumerItem) { |
| 1529 |
bool propagated = false; |
| 1530 |
QSet<COptimizedKPSetRoleTestingItem*>* downPropSet = item->getDownPropagationItemSet(); |
| 1531 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator it = downPropSet->constBegin(), itEnd = downPropSet->constEnd(); it != itEnd; ++it) { |
| 1532 |
COptimizedKPSetRoleTestingItem* downPropItem = *it; |
| 1533 |
if (!downPropItem->hasSubsumerRoleItem(subsumerItem) && downPropItem != subsumerItem) { |
| 1534 |
downPropItem->addSubsumerRoleItem(subsumerItem); |
| 1535 |
propagateDownSubsumption(optKPSetClassificationItem,downPropItem,subsumerItem); |
| 1536 |
propagated = true; |
| 1537 |
} |
| 1538 |
} |
| 1539 |
return propagated; |
| 1540 |
} |
| 1541 |
|
| 1542 |
|
| 1543 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::pruneDownSubsumption(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* item, CRole* subsumerRole) { |
| 1544 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 1545 |
if (possSubsumMap) { |
| 1546 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumData = possSubsumMap->value(subsumerRole); |
| 1547 |
if (possSubsumData && !possSubsumData->isSubsumptionConfirmed()) { |
| 1548 |
possSubsumData->setSubsumptionConfirmed(true); |
| 1549 |
possSubsumData->setSubsumptionUpdated(true); |
| 1550 |
decRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap,true); |
| 1551 |
|
| 1552 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 1553 |
if (ontClassStat) { |
| 1554 |
ontClassStat->incDerivatedTestedSubsumptionCount(1); |
| 1555 |
} |
| 1556 |
|
| 1557 |
QSet<COptimizedKPSetRoleTestingItem*>* downPropSet = item->getDownPropagationItemSet(); |
| 1558 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator it = downPropSet->constBegin(), itEnd = downPropSet->constEnd(); it != itEnd; ++it) { |
| 1559 |
COptimizedKPSetRoleTestingItem* downPropItem = *it; |
| 1560 |
pruneDownSubsumption(optKPSetClassificationItem,downPropItem,subsumerRole); |
| 1561 |
} |
| 1562 |
return true; |
| 1563 |
} |
| 1564 |
} |
| 1565 |
return false; |
| 1566 |
} |
| 1567 |
|
| 1568 |
|
| 1569 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::pruneUpNotSubsumption(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* item, CRole* notSubsumerRole) { |
| 1570 |
COptimizedKPSetRolePossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 1571 |
if (possSubsumMap) { |
| 1572 |
COptimizedKPSetRolePossibleSubsumptionData* possSubsumData = possSubsumMap->value(notSubsumerRole); |
| 1573 |
if (possSubsumData && !possSubsumData->isSubsumptionInvalided()) { |
| 1574 |
possSubsumData->setSubsumptionInvalid(true); |
| 1575 |
possSubsumData->setSubsumptionUpdated(true); |
| 1576 |
decRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap,false); |
| 1577 |
|
| 1578 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 1579 |
if (ontClassStat) { |
| 1580 |
ontClassStat->incPrunedTestedSubsumptionCount(1); |
| 1581 |
} |
| 1582 |
|
| 1583 |
QSet<COptimizedKPSetRoleTestingItem*>* upPropSet = item->getUpPropagationItemSet(); |
| 1584 |
for (QSet<COptimizedKPSetRoleTestingItem*>::const_iterator it = upPropSet->constBegin(), itEnd = upPropSet->constEnd(); it != itEnd; ++it) { |
| 1585 |
COptimizedKPSetRoleTestingItem* upPropItem = *it; |
| 1586 |
pruneUpNotSubsumption(optKPSetClassificationItem,upPropItem,notSubsumerRole); |
| 1587 |
} |
| 1588 |
return true; |
| 1589 |
} |
| 1590 |
} |
| 1591 |
return false; |
| 1592 |
} |
| 1593 |
|
| 1594 |
|
| 1595 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::interpreteSatisfiableResult(COntologyPropertyRoleClassificationItem *ontPropItem, CRole *satisfiableRole, bool isSatis) { |
| 1596 |
COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetRoleOntologyClassificationItem *)ontPropItem; |
| 1597 |
|
| 1598 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 1599 |
if (ontClassStat) { |
| 1600 |
ontClassStat->incToldSatisfiableCount(1); |
| 1601 |
} |
| 1602 |
|
| 1603 |
++satTestedCount; |
| 1604 |
|
| 1605 |
optKPSetClassificationItem->decRunningSatisfiableTestsCount(); |
| 1606 |
|
| 1607 |
COptimizedKPSetRoleTestingItem* satTestedItem = optKPSetClassificationItem->getRoleSatisfiableTestItem(satisfiableRole); |
| 1608 |
//if (CIRIName::getRecentIRIName(satisfiableRole->getPropertyNameLinker()) == "http://www.gdst.uqam.ca/Documents/Ontologies/HIT/Equipment_SH_Ontology.owl#Folding_chair" && !isSatis) { |
| 1609 |
// bool bug = true; |
| 1610 |
// calculateSatisfiable(optKPSetClassificationItem,satTestedItem); |
| 1611 |
// return false; |
| 1612 |
//} |
| 1613 |
|
| 1614 |
|
| 1615 |
satTestedItem->setSatisfiableTested(true); |
| 1616 |
satTestedItem->setSatisfiableTestedResult(isSatis); |
| 1617 |
|
| 1618 |
|
| 1619 |
if (isSatis) { |
| 1620 |
optKPSetClassificationItem->addSatisfiableRoleItem(satTestedItem); |
| 1621 |
|
| 1622 |
} else { |
| 1623 |
CRolePropertiesHierarchy* hierarchy = optKPSetClassificationItem->getHierarchy(); |
| 1624 |
hierarchy->getBottomHierarchyNode()->addEquivalentElement(satisfiableRole); |
| 1625 |
hierarchy->updateNodeEquivalentElements(hierarchy->getBottomHierarchyNode()); |
| 1626 |
} |
| 1627 |
|
| 1628 |
QList<COptimizedKPSetRoleTestingItem*>* nextItemList = optKPSetClassificationItem->getNextSatisfiableTestingItemList(); |
| 1629 |
QSet<COptimizedKPSetRoleTestingItem*>* nextCandItemSet = optKPSetClassificationItem->getNextCandidateSatisfiableTestingItemSet(); |
| 1630 |
QSet<COptimizedKPSetRoleTestingItem*>* remainingCandItemSet = optKPSetClassificationItem->getRemainingCandidateSatisfiableTestingItemSet(); |
| 1631 |
|
| 1632 |
|
| 1633 |
QList<COptimizedKPSetRoleTestingItem*>* subSumItemList = satTestedItem->getSubsumerRoleItemList(); |
| 1634 |
QList<COptimizedKPSetRoleTestingItem*>* succItemList = satTestedItem->getSuccessorItemList(); |
| 1635 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator it = succItemList->constBegin(), itEnd = succItemList->constEnd(); it != itEnd; ++it) { |
| 1636 |
COptimizedKPSetRoleTestingItem* succItem = *it; |
| 1637 |
if (!isSatis) { |
| 1638 |
succItem->setResultUnsatisfiableDerivated(true); |
| 1639 |
} else { |
| 1640 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator itSubsum = subSumItemList->constBegin(), itSubsumEnd = subSumItemList->constEnd(); itSubsum != itSubsumEnd; ++itSubsum) { |
| 1641 |
COptimizedKPSetRoleTestingItem* subusmerItem = *itSubsum; |
| 1642 |
if (succItem != subusmerItem) { |
| 1643 |
succItem->addSubsumerRoleItem(subusmerItem); |
| 1644 |
} |
| 1645 |
} |
| 1646 |
} |
| 1647 |
succItem->decUnprocessedPredecessorItems(); |
| 1648 |
if (succItem->hasOnlyProcessedPredecessorItems()) { |
| 1649 |
nextItemList->append(succItem); |
| 1650 |
} else { |
| 1651 |
nextCandItemSet->insert(succItem); |
| 1652 |
} |
| 1653 |
} |
| 1654 |
|
| 1655 |
return false; |
| 1656 |
} |
| 1657 |
|
| 1658 |
|
| 1659 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::interpreteTestResults(CTestCalculatedCallbackEvent *testResult) { |
| 1660 |
CSatisfiableCalculationJob *satCalcJob = testResult->getSatisfiableCalculationJob(); |
| 1661 |
bool testSat = testResult->getTestResultSatisfiable(); |
| 1662 |
CPropertyClassificationComputationItem *workItem = (CPropertyClassificationComputationItem*)testResult->getClassificationWorkItem(); |
| 1663 |
++mRecievedCallbackCount; |
| 1664 |
|
| 1665 |
|
| 1666 |
COntologyPropertyRoleClassificationItem *ontPropItem = workOntItemHash.value(workItem); |
| 1667 |
if (ontPropItem) { |
| 1668 |
|
| 1669 |
QHash<CSatisfiableCalculationJob *, CPropertyClassificationComputationItem *> *workHash = ontPropItem->getComputationItemHash(); |
| 1670 |
|
| 1671 |
if (workItem) { |
| 1672 |
ontPropItem->decCurrentCalculatingCount(); |
| 1673 |
|
| 1674 |
if (testResult->hasCalculationError()) { |
| 1675 |
LOG(ERROR,getLogDomain(),logTr("Error in computation, role classification for ontology '%1' failed.").arg(ontPropItem->getOntology()->getTerminologyName()),getLogObject()); |
| 1676 |
ontPropItem->setHierarchyConstructionFailed(); |
| 1677 |
|
| 1678 |
} else { |
| 1679 |
|
| 1680 |
if (workItem->isRoleSatisfiableTest()) { |
| 1681 |
interpreteSatisfiableResult(ontPropItem,workItem->getSatisfiableTestedRole(),testSat); |
| 1682 |
} else if (workItem->isRoleSubsumptionTest()) { |
| 1683 |
interpreteSubsumptionResult(ontPropItem,workItem->getSubsumedTestedRole(),workItem->getSubsumerTestedRole(),!testSat); |
| 1684 |
} |
| 1685 |
} |
| 1686 |
QHash<CSatisfiableCalculationJob *, CPropertyClassificationComputationItem *>::iterator itWorkItem = workHash->find(satCalcJob); |
| 1687 |
while (itWorkItem != workHash->end()) { |
| 1688 |
if (itWorkItem.value() == workItem) { |
| 1689 |
workHash->erase(itWorkItem); |
| 1690 |
break; |
| 1691 |
} |
| 1692 |
++itWorkItem; |
| 1693 |
} |
| 1694 |
delete workItem; |
| 1695 |
delete satCalcJob; |
| 1696 |
} |
| 1697 |
workOntItemHash.remove(workItem); |
| 1698 |
|
| 1699 |
|
| 1700 |
CClassificationCalculationStatisticsCollection* statisticCollection = testResult->getUsedStatisticsCollection(); |
| 1701 |
if (statisticCollection) { |
| 1702 |
ontPropItem->reuseCalculationStatisticsCollection(statisticCollection); |
| 1703 |
} |
| 1704 |
} |
| 1705 |
|
| 1706 |
return true; |
| 1707 |
} |
| 1708 |
|
| 1709 |
|
| 1710 |
bool COptimizedKPSetRoleSubsumptionClassifierThread::finishOntologyClassification(COntologyPropertyRoleClassificationItem *ontPropItem) { |
| 1711 |
|
| 1712 |
if (!ontPropItem->isHierarchyConstructed() && !ontPropItem->isHierarchyConstructionFailed()) { |
| 1713 |
|
| 1714 |
CConcreteOntology *ontology = ontPropItem->getOntology(); |
| 1715 |
LOG(INFO,getLogDomain(),logTr("Starting Transitive Reduction for Ontology '%1'.").arg(ontology->getTerminologyName()),getLogObject()); |
| 1716 |
|
| 1717 |
// build taxonomy |
| 1718 |
|
| 1719 |
COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetRoleOntologyClassificationItem *)ontPropItem; |
| 1720 |
QList<COptimizedKPSetRoleTestingItem*>* satItemList = optKPSetClassificationItem->getSatisfiableRoleItemList(); |
| 1721 |
|
| 1722 |
CRolePropertiesHierarchy* hierarchy = optKPSetClassificationItem->getHierarchy(); |
| 1723 |
|
| 1724 |
QList<COptimizedKPSetRoleTestingItem*> itemList; |
| 1725 |
|
| 1726 |
COptimizedKPSetRoleTestingItem* topItem = optKPSetClassificationItem->getTopRoleSatisfiableTestItem(); |
| 1727 |
CRolePropertiesHierarchyNode* topHierNode = hierarchy->getTopHierarchyNode(); |
| 1728 |
CRolePropertiesHierarchyNode* bottomHierNode = hierarchy->getBottomHierarchyNode(); |
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
cint64 topSubsumingItemCount = topItem->getSubsumerRoleItemCount(); |
| 1733 |
topItem->setSatisfiableRoleHierarchyNode(topHierNode); |
| 1734 |
if (topSubsumingItemCount) { |
| 1735 |
QList<COptimizedKPSetRoleTestingItem*>* subsumingConceptItemList = topItem->sortSubsumingConceptItemList(); |
| 1736 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); subsumedIt != subsumedItEnd; ++subsumedIt) { |
| 1737 |
COptimizedKPSetRoleTestingItem* subsumedConceptItem = *subsumedIt; |
| 1738 |
// mark as equivalent |
| 1739 |
subsumedConceptItem->setEquivalentItem(true); |
| 1740 |
topHierNode->addEquivalentElement(subsumedConceptItem->getTestingRole()); |
| 1741 |
} |
| 1742 |
hierarchy->updateNodeEquivalentElements(topHierNode); |
| 1743 |
} |
| 1744 |
|
| 1745 |
LOG(INFO,getLogDomain(),logTr("Sorting roles for Ontology '%1'.").arg(ontology->getTerminologyName()),getLogObject()); |
| 1746 |
|
| 1747 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator it = satItemList->constBegin(), itEnd = satItemList->constEnd(); it != itEnd; ++it) { |
| 1748 |
COptimizedKPSetRoleTestingItem* item = *it; |
| 1749 |
|
| 1750 |
if (!item->isEquivalentItem() && item != topItem) { |
| 1751 |
CRolePropertiesHierarchyNode* itemNode = hierarchy->getHierarchyNode(item->getTestingRole(),true); |
| 1752 |
item->setSatisfiableRoleHierarchyNode(itemNode); |
| 1753 |
cint64 itemSubsumingCount = item->getSubsumerRoleItemCount(); |
| 1754 |
itemList.append(item); |
| 1755 |
if (itemSubsumingCount > topSubsumingItemCount) { |
| 1756 |
QList<COptimizedKPSetRoleTestingItem*>* subsumingConceptItemList = item->sortSubsumingConceptItemList(); |
| 1757 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); subsumedIt != subsumedItEnd; ++subsumedIt) { |
| 1758 |
COptimizedKPSetRoleTestingItem* subsumedConceptItem = *subsumedIt; |
| 1759 |
cint64 subsumedItemSubsumingCount = subsumedConceptItem->getSubsumerRoleItemCount(); |
| 1760 |
if (subsumedItemSubsumingCount == itemSubsumingCount) { |
| 1761 |
// mark as equivalent |
| 1762 |
subsumedConceptItem->setEquivalentItem(true); |
| 1763 |
itemNode->addEquivalentElement(subsumedConceptItem->getTestingRole()); |
| 1764 |
} else { |
| 1765 |
break; |
| 1766 |
} |
| 1767 |
} |
| 1768 |
} |
| 1769 |
hierarchy->updateNodeEquivalentElements(itemNode); |
| 1770 |
} |
| 1771 |
} |
| 1772 |
|
| 1773 |
LOG(INFO,getLogDomain(),logTr("Transitive Reduction for Ontology '%1'.").arg(ontology->getTerminologyName()),getLogObject()); |
| 1774 |
|
| 1775 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator it = itemList.constBegin(), itEnd = itemList.constEnd(); it != itEnd; ++it) { |
| 1776 |
COptimizedKPSetRoleTestingItem* item = *it; |
| 1777 |
|
| 1778 |
if (!item->isEquivalentItem() && item != topItem) { |
| 1779 |
cint64 itemSubsumingCount = item->getSubsumerRoleItemCount(); |
| 1780 |
CRolePropertiesHierarchyNode* itemHierNode = item->getSatisfiableRoleHierarchyNode(); |
| 1781 |
|
| 1782 |
QList<COptimizedKPSetRoleTestingItem*>* subsumingConceptItemList = item->getSubsumerRoleItemList(); |
| 1783 |
QList<COptimizedKPSetRoleTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); |
| 1784 |
|
| 1785 |
cint64 eqCount = 0; |
| 1786 |
cint64 remainingSubsumingCount = itemSubsumingCount; |
| 1787 |
// remove direct equivalences |
| 1788 |
while (subsumedIt != subsumedItEnd) { |
| 1789 |
COptimizedKPSetRoleTestingItem* subsumedConceptItem = *subsumedIt; |
| 1790 |
cint64 subsumedItemSubsumingCount = subsumedConceptItem->getSubsumerRoleItemCount(); |
| 1791 |
if (itemSubsumingCount != subsumedItemSubsumingCount) { |
| 1792 |
break; |
| 1793 |
} else { |
| 1794 |
++eqCount; |
| 1795 |
++subsumedIt; |
| 1796 |
--remainingSubsumingCount; |
| 1797 |
} |
| 1798 |
} |
| 1799 |
|
| 1800 |
while (subsumedIt != subsumedItEnd && (*subsumedIt)->isEquivalentItem()) { |
| 1801 |
++subsumedIt; |
| 1802 |
} |
| 1803 |
|
| 1804 |
// find first parent |
| 1805 |
if (subsumedIt == subsumedItEnd) { |
| 1806 |
// no parent, use top as parent |
| 1807 |
itemHierNode->makeParent(topHierNode); |
| 1808 |
} else { |
| 1809 |
itemHierNode->addPredecessorNode(topHierNode); |
| 1810 |
QList<COptimizedKPSetRoleTestingItem*> parentItemList; |
| 1811 |
while (subsumedIt != subsumedItEnd) { |
| 1812 |
COptimizedKPSetRoleTestingItem* subsumedConceptItem = *subsumedIt; |
| 1813 |
if (!subsumedConceptItem->isEquivalentItem()) { |
| 1814 |
subsumedConceptItem->setPredecessorItem(true); |
| 1815 |
CRolePropertiesHierarchyNode* subsumedHierNode = subsumedConceptItem->getSatisfiableRoleHierarchyNode(); |
| 1816 |
itemHierNode->makeParent(subsumedHierNode); |
| 1817 |
parentItemList.append(subsumedConceptItem); |
| 1818 |
remainingSubsumingCount -= subsumedConceptItem->getSubsumerRoleItemCount()+1; |
| 1819 |
++subsumedIt; |
| 1820 |
break; |
| 1821 |
} else { |
| 1822 |
++subsumedIt; |
| 1823 |
} |
| 1824 |
} |
| 1825 |
|
| 1826 |
bool searchForMoreParents = remainingSubsumingCount > 0; |
| 1827 |
while (subsumedIt != subsumedItEnd) { |
| 1828 |
COptimizedKPSetRoleTestingItem* subsumedConceptItem = *subsumedIt; |
| 1829 |
if (!subsumedConceptItem->isEquivalentItem()) { |
| 1830 |
bool predOfOnePrevParent = false; |
| 1831 |
if (searchForMoreParents) { |
| 1832 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator parentIt = parentItemList.constBegin(), parentItEnd = parentItemList.constEnd(); parentIt != parentItEnd && !predOfOnePrevParent; ++parentIt) { |
| 1833 |
COptimizedKPSetRoleTestingItem* parentItem = *parentIt; |
| 1834 |
if (parentItem->getSubsumerRoleItemSet()->contains(subsumedConceptItem)) { |
| 1835 |
predOfOnePrevParent = true; |
| 1836 |
} |
| 1837 |
} |
| 1838 |
} |
| 1839 |
subsumedConceptItem->setPredecessorItem(true); |
| 1840 |
CRolePropertiesHierarchyNode* subsumedHierNode = subsumedConceptItem->getSatisfiableRoleHierarchyNode(); |
| 1841 |
if (!predOfOnePrevParent && searchForMoreParents) { |
| 1842 |
itemHierNode->makeParent(subsumedHierNode); |
| 1843 |
parentItemList.append(subsumedConceptItem); |
| 1844 |
} else { |
| 1845 |
itemHierNode->addPredecessorNode(subsumedHierNode); |
| 1846 |
} |
| 1847 |
} |
| 1848 |
++subsumedIt; |
| 1849 |
} |
| 1850 |
} |
| 1851 |
} |
| 1852 |
} |
| 1853 |
|
| 1854 |
for (QList<COptimizedKPSetRoleTestingItem*>::const_iterator it = itemList.constBegin(), itEnd = itemList.constEnd(); it != itEnd; ++it) { |
| 1855 |
COptimizedKPSetRoleTestingItem* item = *it; |
| 1856 |
if (!item->isPredecessorItem() && !item->isEquivalentItem()) { |
| 1857 |
CRolePropertiesHierarchyNode* itemHierNode = item->getSatisfiableRoleHierarchyNode(); |
| 1858 |
bottomHierNode->makeParent(itemHierNode); |
| 1859 |
} |
| 1860 |
} |
| 1861 |
|
| 1862 |
LOG(INFO,getLogDomain(),logTr("Collect statistics for Ontology '%1'.").arg(ontology->getTerminologyName()),getLogObject()); |
| 1863 |
|
| 1864 |
|
| 1865 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION |
| 1866 |
statUpdateMutex.lock(); |
| 1867 |
statusString = QString("Finished ontology role classification"); |
| 1868 |
statUpdateMutex.unlock(); |
| 1869 |
#endif |
| 1870 |
|
| 1871 |
|
| 1872 |
CClassification* classification = ontology->getClassification(); |
| 1873 |
if (classification) { |
| 1874 |
CPropertyRoleClassification* propRoleClassification = ontPropItem->getPropertyRoleClassification(); |
| 1875 |
CClassificationStatisticsCollectionStrings* classifStatCollStrings = ontPropItem->getClassificationStatisticsCollectionStrings(); |
| 1876 |
CClassifierStatistics* classifierStats = ontPropItem->getClassifierStatistics(); |
| 1877 |
classifStatCollStrings->addProcessingStatistics("role-classification-total-satisfiable-test-count",classifierStats->getTotalSatisfiableCount()); |
| 1878 |
classifStatCollStrings->addProcessingStatistics("role-classification-satisfiable-tested-count",classifierStats->getTestedSatisfiableCount()); |
| 1879 |
classifStatCollStrings->addProcessingStatistics("role-classification-satisfiable-derivate-tested-count",classifierStats->getDerivatedTestedSatisfiableCount()); |
| 1880 |
classifStatCollStrings->addProcessingStatistics("role-classification-satisfiable-calculated-tested-count",classifierStats->getCalculatedTestedSatisfiableCount()); |
| 1881 |
classifStatCollStrings->addProcessingStatistics("role-classification-satisfiable-pruned-tested-count",classifierStats->getPrunedTestedSatisfiableCount()); |
| 1882 |
classifStatCollStrings->addProcessingStatistics("role-classification-satisfiable-told-tested-count",classifierStats->getToldSatisfiableCount()-classifierStats->getCalculatedTestedSatisfiableCount()); |
| 1883 |
classifStatCollStrings->addProcessingStatistics("role-classification-total-subsumption-test-count",classifierStats->getTotalSatisfiableCount()*(classifierStats->getTotalSatisfiableCount()-1)); |
| 1884 |
classifStatCollStrings->addProcessingStatistics("role-classification-subsumption-tested-count",classifierStats->getTestedSubsumptionCount()); |
| 1885 |
classifStatCollStrings->addProcessingStatistics("role-classification-subsumption-subproperty-tested-count",classifierStats->getSubclassTestedSubsumptionCount()); |
| 1886 |
classifStatCollStrings->addProcessingStatistics("role-classification-subsumption-subproperty-identifier-occur-tested-count",classifierStats->getSubclassIdentifierOccurTestedSubsumptionCount()); |
| 1887 |
classifStatCollStrings->addProcessingStatistics("role-classification-subsumption-derivate-tested-count",classifierStats->getDerivatedTestedSubsumptionCount()); |
| 1888 |
classifStatCollStrings->addProcessingStatistics("role-classification-subsumption-calculated-tested-count",classifierStats->getCalculatedTestedSubsumptionCount()); |
| 1889 |
classifStatCollStrings->addProcessingStatistics("role-classification-subsumption-pruned-tested-count",classifierStats->getPrunedTestedSubsumptionCount()); |
| 1890 |
classifStatCollStrings->addProcessingStatistics("role-classification-subsumption-told-tested-count",classifierStats->getToldSubsumptionCount()-classifierStats->getCalculatedTestedSubsumptionCount()); |
| 1891 |
propRoleClassification->setRolePropertiesHierarchy(hierarchy); |
| 1892 |
propRoleClassification->setClassificationStatistics(classifStatCollStrings); |
| 1893 |
classification->setPropertyRoleClassification(propRoleClassification,optKPSetClassificationItem->isDataRolesClassification()); |
| 1894 |
} |
| 1895 |
|
| 1896 |
ontPropItem->setHasRemainingTests(false); |
| 1897 |
|
| 1898 |
--mClassificationCount; |
| 1899 |
LOG(INFO,getLogDomain(),logTr("Roles of ontology '%1' classified.").arg(ontology->getTerminologyName()),getLogObject()); |
| 1900 |
LOG(INFO,getLogDomain(),logTr("Used %1 satisfiable tests and %3 calculated subsumption tests.").arg(ontPropItem->getCalcedSatisfiableCount()).arg(ontPropItem->getClassifierStatistics()->getCalculatedTestedSubsumptionCount()),getLogObject()); |
| 1901 |
LOG(INFO,getLogDomain(),logTr("Confirmed %1 of %2 possible subsumer roles.").arg(optKPSetClassificationItem->getTruePossibleSubsumerCount()).arg(optKPSetClassificationItem->getPossibleSubsumerCount()),getLogObject()); |
| 1902 |
LOG(INFO,getLogDomain(),logTr("Confirmed %1 and invalidated %2 possible subsumer roles with calculation.").arg(optKPSetClassificationItem->getCalculatedTruePossibleSubsumerCount()).arg(optKPSetClassificationItem->getFalsePossibleSubsumerCount()),getLogObject()); |
| 1903 |
} |
| 1904 |
ontPropItem->submitHierarchyConstructed(); |
| 1905 |
ontPropItem->doClassifiedCallback(); |
| 1906 |
return true; |
| 1907 |
} |
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
}; // end namespace Classifier |
| 1912 |
|
| 1913 |
}; // end namespace Reasoner |
| 1914 |
|
| 1915 |
}; // end namespace Konclude |