| 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 "COptimizedKPSetClassSubsumptionClassifierThread.h" |
| 22 |
|
| 23 |
namespace Konclude { |
| 24 |
|
| 25 |
namespace Reasoner { |
| 26 |
|
| 27 |
namespace Classifier { |
| 28 |
|
| 29 |
|
| 30 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCOUTOUTPUT |
| 31 |
#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGB |
| 32 |
#endif |
| 33 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCOUTOUTPUT |
| 34 |
#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGB |
| 35 |
#endif |
| 36 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGBOXDESCRIPTION |
| 37 |
#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGB |
| 38 |
#endif |
| 39 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION |
| 40 |
#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGB |
| 41 |
#endif |
| 42 |
|
| 43 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGB |
| 44 |
#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(a) |
| 45 |
#else |
| 46 |
#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(a) |
| 47 |
#endif |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
//#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(a) a |
| 52 |
|
| 53 |
|
| 54 |
COptimizedKPSetClassSubsumptionClassifierThread::COptimizedKPSetClassSubsumptionClassifierThread(CReasonerManager *reasonerManager) |
| 55 |
: CSubsumptionClassifierThread(reasonerManager), CLogIdentifier("::Konclude::Reasoner::Kernel::Classifier::OptimizedKPSetClassSubsumptionClassifierThread",this) { |
| 56 |
satTestedCount = 0; |
| 57 |
totalToSatTestClassCount = 0; |
| 58 |
mClassificationCount = 0; |
| 59 |
subsumTestedCount = 0; |
| 60 |
totalToSubsumTestCount = 0; |
| 61 |
|
| 62 |
mConfPossSubsumCalcOrderConceptSorted = true; |
| 63 |
mConfPossSubsumCalcOrderFewestSubsumptionSorted = false; |
| 64 |
|
| 65 |
mConfPossSubsumCalcOrderTopDown = true; |
| 66 |
mConfPossSubsumCalcOrderBottomUp = false; |
| 67 |
|
| 68 |
mConfPossSubsumPseudoModelPretest = true; |
| 69 |
mConfPossSubsumPseudoModelTest = true; |
| 70 |
mConfWriteDebuggingData = false; |
| 71 |
|
| 72 |
mStatProcesedSubsumMessCount = 0; |
| 73 |
mStatProcesedPossSubsumInitMessCount = 0; |
| 74 |
mStatProcesedPossSubsumUpdateMessCount = 0; |
| 75 |
mStatProcesedPseudoModelMessCount = 0; |
| 76 |
|
| 77 |
mInterpretedSubsumptionCalculationCount = 0; |
| 78 |
mOrderedSubsumptionCalculationCount = 0; |
| 79 |
mPseudoModelPretestSubsumptionCalculationCount = 0; |
| 80 |
mCreatedCalculationTaskCount = 0; |
| 81 |
mRecievedCallbackCount = 0; |
| 82 |
|
| 83 |
mSatNodeExpCacheReader = nullptr; |
| 84 |
mSatNodeExpCache = dynamic_cast<CSaturationNodeAssociatedExpansionCache*>(reasonerManager->getSaturationAssociationExpansionCache()); |
| 85 |
if (mSatNodeExpCache) { |
| 86 |
mSatNodeExpCacheReader = mSatNodeExpCache->createCacheReader(); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
COptimizedKPSetClassSubsumptionClassifierThread::~COptimizedKPSetClassSubsumptionClassifierThread() { |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
CTaxonomy *COptimizedKPSetClassSubsumptionClassifierThread::createEmptyTaxonomyForOntology(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 96 |
CTBox *tBox = ontology->getTBox(); |
| 97 |
CConceptVector *conVec = tBox->getConceptVector(); |
| 98 |
CConcept *topConcept = conVec->getData(1); |
| 99 |
CConcept *bottomConcept = conVec->getData(0); |
| 100 |
CPartialPruningTaxonomy *tax = new CPartialPruningTaxonomy(topConcept,bottomConcept); |
| 101 |
return tax->readConfig(config); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
void COptimizedKPSetClassSubsumptionClassifierThread::readCalculationConfig(CCalculationConfigurationExtension *config) { |
| 106 |
if (config) { |
| 107 |
bool configErrorFlag = false; |
| 108 |
cint64 processorCount = 1; |
| 109 |
QString processorCountString = CConfigDataReader::readConfigString(config,"Konclude.Calculation.ProcessorCount",QString(),&configErrorFlag); |
| 110 |
if (!configErrorFlag) { |
| 111 |
if (processorCountString == "AUTO") { |
| 112 |
processorCount = CThread::idealThreadCount(); |
| 113 |
} else { |
| 114 |
qint64 convertedWorkerCount = processorCountString.toInt(&configErrorFlag); |
| 115 |
if (configErrorFlag) { |
| 116 |
processorCount = convertedWorkerCount; |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
bool mulConfigErrorFlag = false; |
| 122 |
cint64 multiplicator = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Classification.OptimizedKPSetClassSubsumptionClassifier.MultipliedUnitsParallelSatisfiableCalculationCount",1,&mulConfigErrorFlag); |
| 123 |
confMaxTestParallelCount = processorCount*multiplicator; |
| 124 |
bool maxConfigErrorFlag = false; |
| 125 |
cint64 maxParallel = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Classification.OptimizedKPSetClassSubsumptionClassifier.MaximumParallelSatisfiableCalculationCount",1,&maxConfigErrorFlag); |
| 126 |
if (!maxConfigErrorFlag) { |
| 127 |
if (!mulConfigErrorFlag) { |
| 128 |
confMaxTestParallelCount = qMin(confMaxTestParallelCount,maxParallel); |
| 129 |
} else { |
| 130 |
confMaxTestParallelCount = maxParallel; |
| 131 |
} |
| 132 |
} |
| 133 |
double factor = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Classification.OptimizedKPSetClassSubsumptionClassifier.ParallelSatisfiableCalculationCreationFactor",1000)/1000.; |
| 134 |
confMinTestParallelCount = confMaxTestParallelCount*factor; |
| 135 |
|
| 136 |
mConfWriteDebuggingData = CConfigDataReader::readConfigBoolean(config,"Konclude.Debugging.WriteDebuggingData",false); |
| 137 |
|
| 138 |
} else { |
| 139 |
confMaxTestParallelCount = 1; |
| 140 |
confMinTestParallelCount = 1; |
| 141 |
mConfWriteDebuggingData = false; |
| 142 |
} |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
COptimizedKPSetClassOntologyClassificationItem* COptimizedKPSetClassSubsumptionClassifierThread::createOntologyClassificationItem(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 147 |
return new COptimizedKPSetClassOntologyClassificationItem(config,statistics); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
CSubsumptionClassifierThread *COptimizedKPSetClassSubsumptionClassifierThread::scheduleOntologyClassification(CConcreteOntology *ontology, CClassificationCalculationSupport *classificationSupport, CConfigurationBase *config) { |
| 152 |
|
| 153 |
|
| 154 |
CTaxonomy *taxonomy = createEmptyTaxonomyForOntology(ontology,config); |
| 155 |
COptimizedKPSetClassOntologyClassificationItem *ontClassItem = createOntologyClassificationItem(ontology,config); |
| 156 |
ontClassItem->initTaxonomyConcepts(ontology,taxonomy); |
| 157 |
ontItemList.append(ontClassItem); |
| 158 |
processingOntItemList.append(ontClassItem); |
| 159 |
ontItemHash.insert(ontology,ontClassItem); |
| 160 |
|
| 161 |
readCalculationConfig(ontClassItem->getCalculationConfiguration()); |
| 162 |
|
| 163 |
if (CConfigDataReader::readConfigBoolean(ontClassItem->getCalculationConfiguration(),"Konclude.Calculation.Classification.IndividualDependenceTracking",true)) { |
| 164 |
ontClassItem->setIndividualDependenceTrackingCollector(new CIndividualDependenceTrackingCollector()); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
CPartialPruningTaxonomy *parTax = dynamic_cast<CPartialPruningTaxonomy *>(taxonomy); |
| 169 |
if (parTax) { |
| 170 |
COntologyClassClassificationItem *ontClassItem = (COntologyClassClassificationItem*)ontItemHash.value(ontology); |
| 171 |
parTax->createStatistics(ontClassItem->getClassifierStatistics()); |
| 172 |
} |
| 173 |
|
| 174 |
createObviousSubsumptionSatisfiableTestingOrder(ontClassItem); |
| 175 |
|
| 176 |
if (satTestedCount == totalToSatTestClassCount) { |
| 177 |
satTestedCount = 0; |
| 178 |
totalToSatTestClassCount = ontClassItem->getRemainingSatisfiableTestsCount(); |
| 179 |
classStartTime.start(); |
| 180 |
} else { |
| 181 |
totalToSatTestClassCount += ontClassItem->getRemainingSatisfiableTestsCount(); |
| 182 |
} |
| 183 |
++mClassificationCount; |
| 184 |
return this; |
| 185 |
} |
| 186 |
|
| 187 |
void COptimizedKPSetClassSubsumptionClassifierThread::createObviousSubsumptionSatisfiableTestingOrder(COptimizedKPSetClassOntologyClassificationItem* ontClassItem) { |
| 188 |
CPrecomputation* precomputation = ontClassItem->getOntology()->getPrecomputation(); |
| 189 |
CSaturationData* saturationData = precomputation->getSaturationModelData(); |
| 190 |
|
| 191 |
bool subsumerSaturationExtraction = CConfigDataReader::readConfigBoolean(ontClassItem->getCalculationConfiguration(),"Konclude.Calculation.Classification.SaturationSubsumerExtraction",true); |
| 192 |
|
| 193 |
if (saturationData && subsumerSaturationExtraction) { |
| 194 |
createObviousSubsumptionSatisfiableTestingOrderFromSaturationData(ontClassItem); |
| 195 |
} else { |
| 196 |
createObviousSubsumptionSatisfiableTestingOrderFromBuildData(ontClassItem); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
void COptimizedKPSetClassSubsumptionClassifierThread::createObviousSubsumptionSatisfiableTestingOrderFromSaturationData(COptimizedKPSetClassOntologyClassificationItem* ontClassItem) { |
| 204 |
|
| 205 |
CTBox *tBox = ontClassItem->getOntology()->getDataBoxes()->getTBox(); |
| 206 |
CBOXHASH<CConcept*,CConcept*>* candidateEqConHash = tBox->getCandidateEquivalentConceptHash(false); |
| 207 |
CBOXHASH<CConcept*,CConcept*>* eqConCandidateHash = tBox->getEquivalentConceptCandidateHash(false); |
| 208 |
CBOXSET<CConcept*>* eqConNonCandidateSet = tBox->getEquivalentConceptNonCandidateSet(false); |
| 209 |
|
| 210 |
CConcreteOntology *onto = ontClassItem->getOntology(); |
| 211 |
CConcept *topConcept = onto->getDataBoxes()->getTopConcept(); |
| 212 |
CConcept *bottomConcept = onto->getDataBoxes()->getBottomConcept(); |
| 213 |
|
| 214 |
|
| 215 |
QHash<CConcept*,COptimizedKPSetClassTestingItem*>* conceptSatItemHash = ontClassItem->getConceptSatisfiableTestItemHash(); |
| 216 |
QList<COptimizedKPSetClassTestingItem*>* satTestItemContainer = ontClassItem->getConceptSatisfiableTestItemContainer(); |
| 217 |
|
| 218 |
COptimizedKPSetClassTestingItem* topItem = ontClassItem->getConceptSatisfiableTestItem(topConcept,true); |
| 219 |
COptimizedKPSetClassTestingItem* bottomItem = ontClassItem->getConceptSatisfiableTestItem(bottomConcept,true); |
| 220 |
|
| 221 |
ontClassItem->initTopBottomSatisfiableTestingItems(topItem,bottomItem); |
| 222 |
|
| 223 |
QList<COptimizedKPSetClassTestingItem*>* nextItemList = ontClassItem->getNextSatisfiableTestingItemList(); |
| 224 |
QSet<COptimizedKPSetClassTestingItem*>* nextCandItemSet = ontClassItem->getNextCandidateSatisfiableTestingItemSet(); |
| 225 |
QSet<COptimizedKPSetClassTestingItem*>* remainingCandItemSet = ontClassItem->getRemainingCandidateSatisfiableTestingItemSet(); |
| 226 |
|
| 227 |
|
| 228 |
CConcept* univConnNomValueConcept = tBox->getUniversalConnectionNominalValueConcept(); |
| 229 |
|
| 230 |
bool testTopConcept = false; |
| 231 |
if (topConcept->getOperandList() || eqConNonCandidateSet && !eqConNonCandidateSet->isEmpty() || univConnNomValueConcept) { |
| 232 |
// has not absorbed GCIs |
| 233 |
nextItemList->append(topItem); |
| 234 |
testTopConcept = true; |
| 235 |
} else { |
| 236 |
topItem->setPossibleSubsumptionMapInitialized(true); |
| 237 |
} |
| 238 |
|
| 239 |
bool invalidatedConRefLinking = false; |
| 240 |
|
| 241 |
QSet<CConcept*>* equivConNonCandSet = ontClassItem->getEquivaltentConceptNonCandidateSet(); |
| 242 |
CBOXHASH<CConcept*,CConcept*>* equivConCandidateHash = ontClassItem->getEquivalentConceptCandidateHash(); |
| 243 |
if (eqConCandidateHash) { |
| 244 |
for (CBOXHASH<CConcept*,CConcept*>::const_iterator it = eqConCandidateHash->constBegin(), itEnd = eqConCandidateHash->constEnd(); it != itEnd; ++it) { |
| 245 |
CConcept* eqCon = it.key(); |
| 246 |
CConcept* candCon = it.value(); |
| 247 |
equivConCandidateHash->insert(eqCon,candCon); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
QHash<CConcept*,CClassificationSatisfiableCalculationConceptReferenceLinking*>* conRefLinkDataHash = ontClassItem->getConceptReferenceLinkingDataHash(); |
| 253 |
QList<COptimizedKPSetClassTestingItem*> extClassConceptItemList; |
| 254 |
CPrecomputedSaturationSubsumerExtractor* precSatSubsumerExtractor = ontClassItem->getPrecomputedSaturationSubsumerExtractor(true); |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
CBOXSET<CConcept*> *conceptHash = tBox->getActiveClassConceptSet(false); |
| 259 |
if (conceptHash) { |
| 260 |
for (CBOXSET<CConcept*>::const_iterator it = conceptHash->constBegin(), itEnd = conceptHash->constEnd(); it != itEnd; ++it) { |
| 261 |
CConcept *concept = (*it); |
| 262 |
if (concept && concept != topConcept && concept != bottomConcept || (concept == topConcept && testTopConcept)) { |
| 263 |
if (concept->getOperatorCode() == CCEQ) { |
| 264 |
if (!eqConCandidateHash || !eqConCandidateHash->contains(concept)) { |
| 265 |
equivConNonCandSet->insert(concept); |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
COptimizedKPSetClassTestingItem* classItem = ontClassItem->getConceptSatisfiableTestItem(concept,true); |
| 270 |
|
| 271 |
CConceptProcessData* conProcData = (CConceptProcessData*)concept->getConceptData(); |
| 272 |
CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking(); |
| 273 |
if (!conRefSatLinking) { |
| 274 |
conRefSatLinking = new CConceptSaturationReferenceLinkingData(); |
| 275 |
conProcData->setConceptReferenceLinking(conRefSatLinking); |
| 276 |
} |
| 277 |
|
| 278 |
conRefLinkDataHash->insert(concept,classItem); |
| 279 |
|
| 280 |
if (conRefSatLinking->getClassifierReferenceLinkingData() || invalidatedConRefLinking) { |
| 281 |
conProcData->setInvalidatedReferenceLinking(true); |
| 282 |
} else { |
| 283 |
conRefSatLinking->setClassifierReferenceLinkingData(classItem); |
| 284 |
} |
| 285 |
extClassConceptItemList.append(classItem); |
| 286 |
} |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator it = extClassConceptItemList.constBegin(), itEnd = extClassConceptItemList.constEnd(); it != itEnd; ++it) { |
| 293 |
COptimizedKPSetClassTestingItem* classItem = (*it); |
| 294 |
CConcept* concept = classItem->getTestingConcept(); |
| 295 |
|
| 296 |
bool unsatisfiableFlag = false; |
| 297 |
bool insufficientFlag = false; |
| 298 |
bool incompleteProcessedFlag = false; |
| 299 |
|
| 300 |
|
| 301 |
//QString iriClassNameString = CIRIName::getRecentIRIName(concept->getClassNameLinker()); |
| 302 |
//if (iriClassNameString == "http://owl.man.ac.uk/2005/07/sssw/people#sheep") { |
| 303 |
// bool bug = true; |
| 304 |
//} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
if (!classItem->isSatisfiableTested()) { |
| 309 |
if (precSatSubsumerExtractor->getConceptFlags(concept,&unsatisfiableFlag,&insufficientFlag,&incompleteProcessedFlag)) { |
| 310 |
if (!unsatisfiableFlag) { |
| 311 |
bool possibleSubsumerFlag = false; |
| 312 |
precSatSubsumerExtractor->extractSubsumers(concept,classItem,&possibleSubsumerFlag,ontClassItem->getIndividualDependenceTrackingCollector(),classItem); |
| 313 |
if (incompleteProcessedFlag) { |
| 314 |
QSet<CConcept*> conSubsumSet = getSubsumerSetFromBuildData(concept,ontClassItem); |
| 315 |
for (QSet<CConcept*>::const_iterator it = conSubsumSet.constBegin(), itEnd = conSubsumSet.constEnd(); it != itEnd; ++it) { |
| 316 |
CConcept* subsumerConcept = *it; |
| 317 |
COptimizedKPSetClassTestingItem* subsumerItem = ontClassItem->getConceptSatisfiableTestItem(subsumerConcept,true); |
| 318 |
classItem->addSubsumingConceptItem(subsumerItem); |
| 319 |
} |
| 320 |
} |
| 321 |
if (equivConNonCandSet && !equivConNonCandSet->isEmpty()) { |
| 322 |
for (CBOXSET<CConcept*>::const_iterator eqConIt = equivConNonCandSet->constBegin(), eqConItEnd = equivConNonCandSet->constEnd(); !possibleSubsumerFlag && eqConIt != eqConItEnd; ++eqConIt) { |
| 323 |
CConcept* eqCon = *eqConIt; |
| 324 |
CConceptProcessData* eqConProcData = (CConceptProcessData*)eqCon->getConceptData(); |
| 325 |
CConceptSaturationReferenceLinkingData* eqConRefSatLinking = (CConceptSaturationReferenceLinkingData*)eqConProcData->getConceptReferenceLinking(); |
| 326 |
COptimizedKPSetClassTestingItem* eqClassItem = (COptimizedKPSetClassTestingItem*)eqConRefSatLinking->getClassifierReferenceLinkingData(); |
| 327 |
if (!classItem->hasSubsumerConceptItem(eqClassItem)) { |
| 328 |
possibleSubsumerFlag = true; |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
cint64 foundSubsumerCount = 0; |
| 333 |
QList<COptimizedKPSetClassTestingItem*>* subsumerItemList = classItem->getSubsumingConceptItemList(); |
| 334 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator subsubItemIt = subsumerItemList->constBegin(), itEnd = subsumerItemList->constEnd(); subsubItemIt != itEnd; ++subsubItemIt) { |
| 335 |
COptimizedKPSetClassTestingItem* subsumerItem(*subsubItemIt); |
| 336 |
++foundSubsumerCount; |
| 337 |
subsumerItem->addSuccessorSatisfiableTestItem(classItem); |
| 338 |
} |
| 339 |
classItem->setUnprocessedPredecessorItems(foundSubsumerCount); |
| 340 |
if (!insufficientFlag && !possibleSubsumerFlag && !incompleteProcessedFlag) { |
| 341 |
classItem->setResultSatisfiableDerivated(true); |
| 342 |
classItem->setPossibleSubsumptionMapInitialized(true); |
| 343 |
} |
| 344 |
ontClassItem->incRemainingSatisfiableTestsCount(); |
| 345 |
remainingCandItemSet->insert(classItem); |
| 346 |
if (foundSubsumerCount <= 0) { |
| 347 |
nextItemList->append(classItem); |
| 348 |
} |
| 349 |
} else { |
| 350 |
ontClassItem->incRemainingSatisfiableTestsCount(); |
| 351 |
classItem->setResultUnsatisfiableDerivated(true); |
| 352 |
nextItemList->append(classItem); |
| 353 |
} |
| 354 |
} else { |
| 355 |
bool foundSubsumingConcepts = false; |
| 356 |
QSet<CConcept*> conSubsumSet = getSubsumerSetFromBuildData(concept,ontClassItem); |
| 357 |
for (QSet<CConcept*>::const_iterator it = conSubsumSet.constBegin(), itEnd = conSubsumSet.constEnd(); it != itEnd; ++it) { |
| 358 |
CConcept* subsumedConcept = *it; |
| 359 |
COptimizedKPSetClassTestingItem* subsumerItem = ontClassItem->getConceptSatisfiableTestItem(subsumedConcept,true); |
| 360 |
subsumerItem->addSuccessorSatisfiableTestItem(classItem); |
| 361 |
classItem->incUnprocessedPredecessorItems(); |
| 362 |
foundSubsumingConcepts = true; |
| 363 |
} |
| 364 |
|
| 365 |
ontClassItem->incRemainingSatisfiableTestsCount(); |
| 366 |
|
| 367 |
remainingCandItemSet->insert(classItem); |
| 368 |
if (!foundSubsumingConcepts) { |
| 369 |
nextItemList->append(classItem); |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
QSet<CConcept*> COptimizedKPSetClassSubsumptionClassifierThread::getSubsumerSetFromBuildData(CConcept* concept, COptimizedKPSetClassOntologyClassificationItem* ontClassItem) { |
| 382 |
QSet<QPair<CConcept *,bool> > conSet; |
| 383 |
QList<QPair<CConcept *,bool> > conList; |
| 384 |
QSet<CConcept*> conSubsumSet; |
| 385 |
conList.append(QPair<CConcept *,bool>(concept,false)); |
| 386 |
conSet.insert(QPair<CConcept *,bool>(concept,false)); |
| 387 |
while (!conList.isEmpty()) { |
| 388 |
QPair<CConcept *,bool> conNegPair = conList.takeFirst(); |
| 389 |
CConcept *con = conNegPair.first; |
| 390 |
bool neg = conNegPair.second; |
| 391 |
qint64 conOpCode = con->getProcessingOperatorTag(); |
| 392 |
cint64 opCount = con->getOperandCount(); |
| 393 |
cint64 param = con->getParameter(); |
| 394 |
if (conOpCode == CCAND && (!neg || neg && opCount <= 1) || conOpCode == CCOR && (neg || !neg && opCount <= 1)) { |
| 395 |
CSortedNegLinker<CConcept *> *opConIt = con->getOperandList(); |
| 396 |
while (opConIt) { |
| 397 |
CConcept *opCon = opConIt->getData(); |
| 398 |
bool opNeg = opConIt->isNegated(); |
| 399 |
QPair<CConcept *,bool> opConNegPair(opCon,neg ^ opNeg); |
| 400 |
if (opCon->hasClassName()) { |
| 401 |
if (neg ^ opNeg) { |
| 402 |
if (!conSet.contains(opConNegPair)) { |
| 403 |
conSet.insert(opConNegPair); |
| 404 |
conList.append(opConNegPair); |
| 405 |
} |
| 406 |
} else { |
| 407 |
conSubsumSet.insert(opCon); |
| 408 |
} |
| 409 |
} else { |
| 410 |
if (!conSet.contains(opConNegPair)) { |
| 411 |
conSet.insert(opConNegPair); |
| 412 |
conList.append(opConNegPair); |
| 413 |
} |
| 414 |
} |
| 415 |
opConIt = opConIt->getNext(); |
| 416 |
} |
| 417 |
} else if (!neg && (conOpCode == CCSOME || conOpCode == CCATLEAST && param >= 1) || neg && (conOpCode == CCALL || conOpCode == CCATMOST && param >= 2)) { |
| 418 |
CRole* role = con->getRole(); |
| 419 |
CSortedNegLinker<CRole*>* superRoleIt = role->getIndirectSuperRoleList(); |
| 420 |
while (superRoleIt) { |
| 421 |
CRole* superRole = superRoleIt->getData(); |
| 422 |
bool superRoleNeg = superRoleIt->isNegated(); |
| 423 |
|
| 424 |
CSortedNegLinker<CConcept*>* domainConIt = superRole->getDomainRangeConceptList(superRoleNeg); |
| 425 |
while (domainConIt) { |
| 426 |
CConcept *domCon = domainConIt->getData(); |
| 427 |
bool opDomNeg = domainConIt->isNegated(); |
| 428 |
QPair<CConcept *,bool> domConNegPair(domCon,neg ^ opDomNeg); |
| 429 |
if (domCon->hasClassName()) { |
| 430 |
if (neg ^ opDomNeg) { |
| 431 |
if (!conSet.contains(domConNegPair)) { |
| 432 |
conSet.insert(domConNegPair); |
| 433 |
conList.append(domConNegPair); |
| 434 |
} |
| 435 |
} else { |
| 436 |
conSubsumSet.insert(domCon); |
| 437 |
} |
| 438 |
} else { |
| 439 |
if (!conSet.contains(domConNegPair)) { |
| 440 |
conSet.insert(domConNegPair); |
| 441 |
conList.append(domConNegPair); |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
domainConIt = domainConIt->getNext(); |
| 446 |
} |
| 447 |
|
| 448 |
superRoleIt = superRoleIt->getNext(); |
| 449 |
} |
| 450 |
} else if (!neg && (conOpCode == CCNOMINAL)) { |
| 451 |
CIndividual* individual = con->getNominalIndividual(); |
| 452 |
CConceptAssertionLinker* assConLinkIt = individual->getAssertionConceptLinker(); |
| 453 |
while (assConLinkIt) { |
| 454 |
CConcept* assCon = assConLinkIt->getData(); |
| 455 |
bool assConNeg = assConLinkIt->isNegated(); |
| 456 |
|
| 457 |
QPair<CConcept *,bool> assConNegPair(assCon,neg ^ assConNeg); |
| 458 |
if (assCon->hasClassName()) { |
| 459 |
if (neg ^ assConNeg) { |
| 460 |
if (!conSet.contains(assConNegPair)) { |
| 461 |
conSet.insert(assConNegPair); |
| 462 |
conList.append(assConNegPair); |
| 463 |
} |
| 464 |
} else { |
| 465 |
conSubsumSet.insert(assCon); |
| 466 |
} |
| 467 |
} else { |
| 468 |
if (!conSet.contains(assConNegPair)) { |
| 469 |
conSet.insert(assConNegPair); |
| 470 |
conList.append(assConNegPair); |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
assConLinkIt = assConLinkIt->getNext(); |
| 475 |
} |
| 476 |
} |
| 477 |
} |
| 478 |
return conSubsumSet; |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
void COptimizedKPSetClassSubsumptionClassifierThread::createObviousSubsumptionSatisfiableTestingOrderFromBuildData(COptimizedKPSetClassOntologyClassificationItem* ontClassItem) { |
| 484 |
|
| 485 |
CTBox *tBox = ontClassItem->getOntology()->getDataBoxes()->getTBox(); |
| 486 |
CBOXHASH<CConcept*,CConcept*>* candidateEqConHash = tBox->getCandidateEquivalentConceptHash(false); |
| 487 |
CBOXHASH<CConcept*,CConcept*>* eqConCandidateHash = tBox->getEquivalentConceptCandidateHash(false); |
| 488 |
CBOXSET<CConcept*>* eqConNonCandidateSet = tBox->getEquivalentConceptNonCandidateSet(false); |
| 489 |
|
| 490 |
CConcreteOntology *onto = ontClassItem->getOntology(); |
| 491 |
CConcept *topConcept = onto->getDataBoxes()->getTopConcept(); |
| 492 |
CConcept *bottomConcept = onto->getDataBoxes()->getBottomConcept(); |
| 493 |
|
| 494 |
|
| 495 |
QHash<CConcept*,COptimizedKPSetClassTestingItem*>* conceptSatItemHash = ontClassItem->getConceptSatisfiableTestItemHash(); |
| 496 |
QList<COptimizedKPSetClassTestingItem*>* satTestItemContainer = ontClassItem->getConceptSatisfiableTestItemContainer(); |
| 497 |
|
| 498 |
COptimizedKPSetClassTestingItem* topItem = ontClassItem->getConceptSatisfiableTestItem(topConcept,true); |
| 499 |
COptimizedKPSetClassTestingItem* bottomItem = ontClassItem->getConceptSatisfiableTestItem(bottomConcept,true); |
| 500 |
|
| 501 |
ontClassItem->initTopBottomSatisfiableTestingItems(topItem,bottomItem); |
| 502 |
|
| 503 |
QList<COptimizedKPSetClassTestingItem*>* nextItemList = ontClassItem->getNextSatisfiableTestingItemList(); |
| 504 |
QSet<COptimizedKPSetClassTestingItem*>* nextCandItemSet = ontClassItem->getNextCandidateSatisfiableTestingItemSet(); |
| 505 |
QSet<COptimizedKPSetClassTestingItem*>* remainingCandItemSet = ontClassItem->getRemainingCandidateSatisfiableTestingItemSet(); |
| 506 |
|
| 507 |
CConcept* univConnNomValueConcept = tBox->getUniversalConnectionNominalValueConcept(); |
| 508 |
|
| 509 |
bool testTopConcept = true; |
| 510 |
if (topConcept->getOperandList() || eqConNonCandidateSet && !eqConNonCandidateSet->isEmpty() || univConnNomValueConcept) { |
| 511 |
// has not absorbed GCIs |
| 512 |
nextItemList->append(topItem); |
| 513 |
testTopConcept = true; |
| 514 |
} else { |
| 515 |
topItem->setPossibleSubsumptionMapInitialized(true); |
| 516 |
} |
| 517 |
|
| 518 |
bool invalidatedConRefLinking = false; |
| 519 |
|
| 520 |
QSet<CConcept*>* equivConNonCandSet = ontClassItem->getEquivaltentConceptNonCandidateSet(); |
| 521 |
CBOXHASH<CConcept*,CConcept*>* equivConCandidateHash = ontClassItem->getEquivalentConceptCandidateHash(); |
| 522 |
if (eqConCandidateHash) { |
| 523 |
for (CBOXHASH<CConcept*,CConcept*>::const_iterator it = eqConCandidateHash->constBegin(), itEnd = eqConCandidateHash->constEnd(); it != itEnd; ++it) { |
| 524 |
CConcept* eqCon = it.key(); |
| 525 |
CConcept* candCon = it.value(); |
| 526 |
equivConCandidateHash->insert(eqCon,candCon); |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
QHash<CConcept*,CClassificationSatisfiableCalculationConceptReferenceLinking*>* conRefLinkDataHash = ontClassItem->getConceptReferenceLinkingDataHash(); |
| 532 |
|
| 533 |
CBOXSET<CConcept*> *conceptHash = tBox->getActiveClassConceptSet(false); |
| 534 |
if (conceptHash) { |
| 535 |
for (CBOXSET<CConcept*>::const_iterator it = conceptHash->constBegin(), itEnd = conceptHash->constEnd(); it != itEnd; ++it) { |
| 536 |
CConcept *concept = (*it); |
| 537 |
if (concept && concept != topConcept && concept != bottomConcept || (concept == topConcept && testTopConcept)) { |
| 538 |
if (concept->getOperatorCode() == CCEQ) { |
| 539 |
if (!eqConCandidateHash || !eqConCandidateHash->contains(concept)) { |
| 540 |
equivConNonCandSet->insert(concept); |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
QSet<CConcept*> conSubsumSet = getSubsumerSetFromBuildData(concept,ontClassItem); |
| 546 |
|
| 547 |
//QString iriClassNameString = CIRIName::getRecentIRIName(concept->getClassNameLinker()); |
| 548 |
//if (iriClassNameString == "http://www.owllink.org/testsuite/galen#Haem") { |
| 549 |
// bool bug = true; |
| 550 |
//} |
| 551 |
|
| 552 |
|
| 553 |
COptimizedKPSetClassTestingItem* subsumerItem = ontClassItem->getConceptSatisfiableTestItem(concept,true); |
| 554 |
|
| 555 |
CConceptProcessData* conProcData = (CConceptProcessData*)concept->getConceptData(); |
| 556 |
CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking(); |
| 557 |
if (!conRefSatLinking) { |
| 558 |
conRefSatLinking = new CConceptSaturationReferenceLinkingData(); |
| 559 |
conProcData->setConceptReferenceLinking(conRefSatLinking); |
| 560 |
} |
| 561 |
|
| 562 |
conRefLinkDataHash->insert(concept,subsumerItem); |
| 563 |
|
| 564 |
if (conRefSatLinking->getClassifierReferenceLinkingData() || invalidatedConRefLinking) { |
| 565 |
conProcData->setInvalidatedReferenceLinking(true); |
| 566 |
} else { |
| 567 |
conRefSatLinking->setClassifierReferenceLinkingData(subsumerItem); |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
bool foundSubsumingConcepts = false; |
| 572 |
for (QSet<CConcept*>::const_iterator it = conSubsumSet.constBegin(), itEnd = conSubsumSet.constEnd(); it != itEnd; ++it) { |
| 573 |
CConcept* subsumedConcept = *it; |
| 574 |
COptimizedKPSetClassTestingItem* subsumedItem = ontClassItem->getConceptSatisfiableTestItem(subsumedConcept,true); |
| 575 |
subsumedItem->addSuccessorSatisfiableTestItem(subsumerItem); |
| 576 |
subsumerItem->incUnprocessedPredecessorItems(); |
| 577 |
foundSubsumingConcepts = true; |
| 578 |
} |
| 579 |
|
| 580 |
ontClassItem->incRemainingSatisfiableTestsCount(); |
| 581 |
|
| 582 |
remainingCandItemSet->insert(subsumerItem); |
| 583 |
if (!foundSubsumingConcepts) { |
| 584 |
nextItemList->append(subsumerItem); |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
} |
| 589 |
} |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
QString COptimizedKPSetClassSubsumptionClassifierThread::getStatusString() { |
| 596 |
statUpdateMutex.lock(); |
| 597 |
QString string = statusString; |
| 598 |
string.detach(); |
| 599 |
statUpdateMutex.unlock(); |
| 600 |
return string; |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
CClassificationProgress* COptimizedKPSetClassSubsumptionClassifierThread::getClassificationProgress() { |
| 606 |
if (satTestedCount != totalToSatTestClassCount || subsumTestedCount != totalToSubsumTestCount) { |
| 607 |
cint64 tested = satTestedCount + subsumTestedCount; |
| 608 |
cint64 total = totalToSatTestClassCount + totalToSubsumTestCount; |
| 609 |
cint64 elapsedTime = classStartTime.elapsed(); |
| 610 |
double remainingMilliSeconds = 0.; |
| 611 |
double progessPercent = 0.; |
| 612 |
if (elapsedTime <= 0 && total > 0) { |
| 613 |
remainingMilliSeconds = 0.; |
| 614 |
} else { |
| 615 |
remainingMilliSeconds = ((double)elapsedTime / (double)tested) * (total-tested); |
| 616 |
} |
| 617 |
if (total <= 0) { |
| 618 |
progessPercent = 0.; |
| 619 |
} else { |
| 620 |
progessPercent = ((double)tested / (double)total) * 100.; |
| 621 |
} |
| 622 |
cint64 classificCount = mClassificationCount; |
| 623 |
mClassifyProgess.setClassificationCount(classificCount); |
| 624 |
mClassifyProgess.setProgessPercent(progessPercent); |
| 625 |
mClassifyProgess.setRemainingMilliSeconds(remainingMilliSeconds); |
| 626 |
mClassifyProgess.setTestedSatisfiable(satTestedCount); |
| 627 |
mClassifyProgess.setTotalSatisfiable(totalToSatTestClassCount); |
| 628 |
mClassifyProgess.setTestedSubsumptions(subsumTestedCount); |
| 629 |
mClassifyProgess.setTotalSubsumptions(totalToSubsumTestCount); |
| 630 |
} else { |
| 631 |
mClassifyProgess.setProgessPercent(0.); |
| 632 |
mClassifyProgess.setRemainingMilliSeconds(0.); |
| 633 |
mClassifyProgess.setTestedSatisfiable(satTestedCount); |
| 634 |
mClassifyProgess.setTotalSatisfiable(totalToSatTestClassCount); |
| 635 |
mClassifyProgess.setTestedSubsumptions(subsumTestedCount); |
| 636 |
mClassifyProgess.setTotalSubsumptions(totalToSubsumTestCount); |
| 637 |
} |
| 638 |
return &mClassifyProgess; |
| 639 |
} |
| 640 |
|
| 641 |
bool itemSortLessSubsumptionsThan(const COptimizedKPSetClassTestingItem* item1, const COptimizedKPSetClassTestingItem* item2) { |
| 642 |
return item1->getSubsumingConceptItemCount() < item2->getSubsumingConceptItemCount(); |
| 643 |
} |
| 644 |
|
| 645 |
bool itemSortMoreSubsumptionsThan(const COptimizedKPSetClassTestingItem* item1, const COptimizedKPSetClassTestingItem* item2) { |
| 646 |
return item1->getSubsumingConceptItemCount() > item2->getSubsumingConceptItemCount(); |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
void COptimizedKPSetClassSubsumptionClassifierThread::testDebugPossibleSubsumerCorrectCounted(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem) { |
| 652 |
QList<COptimizedKPSetClassTestingItem*>* classList = optKPSetClassificationItem->getConceptSatisfiableTestItemContainer(); |
| 653 |
cint64 totalCount = 0; |
| 654 |
foreach (COptimizedKPSetClassTestingItem* item, *classList) { |
| 655 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 656 |
if (possSubsumMap) { |
| 657 |
cint64 mapCount = 0; |
| 658 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 659 |
COptimizedKPSetClassPossibleSubsumptionData* data = it.value(); |
| 660 |
if (data->isSubsumptionUnknown() || data->isUpdateRequired()) { |
| 661 |
mapCount++; |
| 662 |
totalCount++; |
| 663 |
} |
| 664 |
} |
| 665 |
if (mapCount != possSubsumMap->getRemainingPossibleSubsumptionCount()) { |
| 666 |
bool bug = true; |
| 667 |
} |
| 668 |
} |
| 669 |
} |
| 670 |
if (totalCount != optKPSetClassificationItem->getRemainingPossibleSubsumptionTestsCount()) { |
| 671 |
bool bug = true; |
| 672 |
} |
| 673 |
|
| 674 |
} |
| 675 |
|
| 676 |
void COptimizedKPSetClassSubsumptionClassifierThread::testDebugPossibleSubsumerCorrectReferenced(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem) { |
| 677 |
QList<COptimizedKPSetClassTestingItem*>* classList = optKPSetClassificationItem->getSatisfiableConceptItemList(); |
| 678 |
if (mConfPossSubsumCalcOrderBottomUp) { |
| 679 |
QSet<COptimizedKPSetClassTestingItem*>* remItemSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionClassTestingSet(); |
| 680 |
foreach (COptimizedKPSetClassTestingItem* item, *classList) { |
| 681 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 682 |
if (possSubsumMap) { |
| 683 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 684 |
COptimizedKPSetClassPossibleSubsumptionData* data = it.value(); |
| 685 |
if (data->isSubsumptionUnknown() || data->isUpdateRequired()) { |
| 686 |
COptimizedKPSetClassTestingItem* possSubsumerItem = data->getClassItem(); |
| 687 |
if (!possSubsumerItem->getPossibleSubsumedSet(false)->contains(item) && !optKPSetClassificationItem->getCurrentPossibleSubsumptionTestingItemSet()->contains(possSubsumerItem)) { |
| 688 |
bool bug = true; |
| 689 |
} |
| 690 |
if (!remItemSet->contains(possSubsumerItem) && !optKPSetClassificationItem->getCurrentPossibleSubsumptionTestingItemSet()->contains(possSubsumerItem)) { |
| 691 |
bool bug = true; |
| 692 |
} |
| 693 |
} |
| 694 |
} |
| 695 |
} |
| 696 |
} |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
QString COptimizedKPSetClassSubsumptionClassifierThread::createDebugKPSetString(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, const QString& filename) { |
| 702 |
QString debugString; |
| 703 |
QList<COptimizedKPSetClassTestingItem*>* classList = optKPSetClassificationItem->getSatisfiableConceptItemList(); |
| 704 |
foreach (COptimizedKPSetClassTestingItem* item, *classList) { |
| 705 |
QString iriClassNameString = CIRIName::getRecentIRIName(item->getTestingConcept()->getClassNameLinker()); |
| 706 |
QString classDebugString = QString("Class: %1\r\n").arg(iriClassNameString); |
| 707 |
QString subsumString; |
| 708 |
foreach (COptimizedKPSetClassTestingItem* subsumItem, *item->getSubsumingConceptItemList()) { |
| 709 |
QString subsumIRIClassNameString = CIRIName::getRecentIRIName(subsumItem->getTestingConcept()->getClassNameLinker()); |
| 710 |
if (subsumString.isEmpty()) { |
| 711 |
subsumString += subsumIRIClassNameString; |
| 712 |
} else { |
| 713 |
subsumString += QString(", %1").arg(subsumIRIClassNameString); |
| 714 |
} |
| 715 |
} |
| 716 |
classDebugString += QString("Subsumer Classes: %1\r\n").arg(subsumString); |
| 717 |
|
| 718 |
QString possSubsumString; |
| 719 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 720 |
if (possSubsumMap) { |
| 721 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 722 |
COptimizedKPSetClassPossibleSubsumptionData* data = it.value(); |
| 723 |
QString subsumIRIClassNameString = CIRIName::getRecentIRIName(data->getClassItem()->getTestingConcept()->getClassNameLinker()); |
| 724 |
QString possString; |
| 725 |
if (data->isSubsumptionConfirmed()) { |
| 726 |
possString = "s"; |
| 727 |
} else if (data->isSubsumptionInvalided()) { |
| 728 |
possString = "n"; |
| 729 |
} else { |
| 730 |
possString = "u"; |
| 731 |
} |
| 732 |
|
| 733 |
if (possSubsumString.isEmpty()) { |
| 734 |
possSubsumString += QString("%1(%2)").arg(subsumIRIClassNameString).arg(possString); |
| 735 |
} else { |
| 736 |
possSubsumString += QString(", %1(%2)").arg(subsumIRIClassNameString).arg(possString); |
| 737 |
} |
| 738 |
} |
| 739 |
} |
| 740 |
classDebugString += QString("Possible Subsumer Classes: %1\r\n\r\n\r\n").arg(possSubsumString); |
| 741 |
|
| 742 |
debugString += classDebugString; |
| 743 |
} |
| 744 |
|
| 745 |
QFile file(filename); |
| 746 |
if (file.open(QIODevice::WriteOnly)) { |
| 747 |
file.write(debugString.toLocal8Bit()); |
| 748 |
file.close(); |
| 749 |
} |
| 750 |
|
| 751 |
return debugString; |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
bool COptimizedKPSetClassSubsumptionClassifierThread::createNextSubsumtionTest() { |
| 756 |
|
| 757 |
|
| 758 |
COntologyClassificationItem *loopOntClassItem = 0; |
| 759 |
bool workTestCreated = false; |
| 760 |
while (!workTestCreated && !processingOntItemList.isEmpty()) { |
| 761 |
COntologyClassificationItem *ontClassItem = processingOntItemList.first(); |
| 762 |
|
| 763 |
if (ontClassItem == loopOntClassItem) { |
| 764 |
// don't run into infinite loop without doing something |
| 765 |
break; |
| 766 |
} |
| 767 |
|
| 768 |
COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetClassOntologyClassificationItem *)ontClassItem; |
| 769 |
|
| 770 |
if (!optKPSetClassificationItem->hasSatisfiableTestingPhaseFinished() && !optKPSetClassificationItem->isTaxonomyConstructionFailed()) { |
| 771 |
|
| 772 |
while (!workTestCreated && optKPSetClassificationItem->hasRemainingSatisfiableTests()) { |
| 773 |
// get next satisfiable test |
| 774 |
|
| 775 |
QList<COptimizedKPSetClassTestingItem*>* nextItemList = optKPSetClassificationItem->getNextSatisfiableTestingItemList(); |
| 776 |
QSet<COptimizedKPSetClassTestingItem*>* nextCandItemSet = optKPSetClassificationItem->getNextCandidateSatisfiableTestingItemSet(); |
| 777 |
QSet<COptimizedKPSetClassTestingItem*>* remainingCandItemSet = optKPSetClassificationItem->getRemainingCandidateSatisfiableTestingItemSet(); |
| 778 |
|
| 779 |
|
| 780 |
COptimizedKPSetClassTestingItem* nextSatTestItem = nullptr; |
| 781 |
if (!nextItemList->isEmpty()) { |
| 782 |
nextSatTestItem = nextItemList->takeFirst(); |
| 783 |
remainingCandItemSet->remove(nextSatTestItem); |
| 784 |
nextCandItemSet->remove(nextSatTestItem); |
| 785 |
|
| 786 |
} else if (!nextCandItemSet->isEmpty()) { |
| 787 |
COptimizedKPSetClassTestingItem* minItem = nullptr; |
| 788 |
cint64 minUnpPredCount = 0; |
| 789 |
cint64 maxItCount = 100; |
| 790 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = nextCandItemSet->constBegin(), itEnd = nextCandItemSet->constEnd(); it != itEnd && maxItCount > 0; ++it, --maxItCount) { |
| 791 |
COptimizedKPSetClassTestingItem* item = (*it); |
| 792 |
cint64 predCount = item->getUnprocessedPredecessorItemCount(); |
| 793 |
if (!minItem || predCount < minUnpPredCount) { |
| 794 |
minUnpPredCount = predCount; |
| 795 |
minItem = item; |
| 796 |
} |
| 797 |
} |
| 798 |
nextSatTestItem = minItem; |
| 799 |
remainingCandItemSet->remove(nextSatTestItem); |
| 800 |
nextCandItemSet->remove(nextSatTestItem); |
| 801 |
|
| 802 |
} else if (!remainingCandItemSet->isEmpty()) { |
| 803 |
COptimizedKPSetClassTestingItem* minItem = nullptr; |
| 804 |
//cint64 minUnpPredCount = 0; |
| 805 |
//for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = remainingCandItemSet->constBegin(), itEnd = remainingCandItemSet->constEnd(); it != itEnd; ++it) { |
| 806 |
// COptimizedKPSetClassTestingItem* item = (*it); |
| 807 |
// cint64 predCount = item->getUnprocessedPredecessorItemCount(); |
| 808 |
// if (!minItem || minUnpPredCount < predCount) { |
| 809 |
// minUnpPredCount = predCount; |
| 810 |
// minItem = item; |
| 811 |
// } |
| 812 |
//} |
| 813 |
//nextSatTestItem = minItem; |
| 814 |
QSet<COptimizedKPSetClassTestingItem*>::const_iterator itNext = remainingCandItemSet->constBegin(); |
| 815 |
nextSatTestItem = *itNext; |
| 816 |
remainingCandItemSet->remove(nextSatTestItem); |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
if (nextSatTestItem && !nextSatTestItem->isSatisfiableTestOrdered()) { |
| 821 |
optKPSetClassificationItem->decRemainingSatisfiableTestsCount(); |
| 822 |
optKPSetClassificationItem->incRunningSatisfiableTestsCount(); |
| 823 |
if (calculateSatisfiable(optKPSetClassificationItem,nextSatTestItem)) { |
| 824 |
workTestCreated = true; |
| 825 |
} else { |
| 826 |
interpreteSatisfiableResult(optKPSetClassificationItem,nextSatTestItem->getTestingConcept(),nextSatTestItem->getSatisfiableTestedResult()); |
| 827 |
} |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
if (!workTestCreated) { |
| 833 |
if (optKPSetClassificationItem->hasAllSatisfiableTestsCompleted()) { |
| 834 |
optKPSetClassificationItem->setSatisfiableTestingPhaseFinished(true); |
| 835 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 836 |
// initialize possible subsumption testing phase |
| 837 |
|
| 838 |
|
| 839 |
cint64 remainingSubSumTestCount = 0; |
| 840 |
|
| 841 |
QSet<COptimizedKPSetClassTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionClassTestingSet(); |
| 842 |
|
| 843 |
QList<COptimizedKPSetClassTestingItem*>* nextItemList = optKPSetClassificationItem->getNextPossibleSubsumptionTestingItemList(); |
| 844 |
|
| 845 |
COptimizedKPSetClassTestingItem* topItem = optKPSetClassificationItem->getTopConceptSatisfiableTestItem(); |
| 846 |
COptimizedKPSetClassTestingItem* bottomItem = optKPSetClassificationItem->getBottomConceptSatisfiableTestItem(); |
| 847 |
|
| 848 |
if (topItem) { |
| 849 |
topItem->setPropagationConnected(true); |
| 850 |
} |
| 851 |
|
| 852 |
QList<COptimizedKPSetClassTestingItem*> classList(*optKPSetClassificationItem->getSatisfiableConceptItemList()); |
| 853 |
qSort(classList.begin(),classList.end(),itemSortLessSubsumptionsThan); |
| 854 |
QList<COptimizedKPSetClassTestingItem*> resevePossSubsumClassList; |
| 855 |
foreach (COptimizedKPSetClassTestingItem* item, classList) { |
| 856 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubSumMap = item->getPossibleSubsumptionMap(false); |
| 857 |
if (possSubSumMap && possSubSumMap->hasRemainingPossibleSubsumptions()) { |
| 858 |
if (mConfPossSubsumCalcOrderTopDown) { |
| 859 |
nextItemList->append(item); |
| 860 |
remTestingSet->insert(item); |
| 861 |
} |
| 862 |
remainingSubSumTestCount += possSubSumMap->getRemainingPossibleSubsumptionCount(); |
| 863 |
resevePossSubsumClassList.append(item); |
| 864 |
} |
| 865 |
if (!item->isPossibleSubsumptionMapInitialized()) { |
| 866 |
bool bug = true; |
| 867 |
} |
| 868 |
|
| 869 |
QList<COptimizedKPSetClassTestingItem*>* subsumerList = item->getSubsumingConceptItemList(); |
| 870 |
COptimizedKPSetClassTestingItem* maxSubsumerItem = nullptr; |
| 871 |
cint64 maxSubsumerCount = 0; |
| 872 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator it = subsumerList->constBegin(), itEnd = subsumerList->constEnd(); it != itEnd; ++it) { |
| 873 |
COptimizedKPSetClassTestingItem* subsumerItem = *it; |
| 874 |
if (!maxSubsumerItem || subsumerItem->getSubsumingConceptItemCount() > maxSubsumerCount) { |
| 875 |
maxSubsumerCount = subsumerItem->getSubsumingConceptItemCount(); |
| 876 |
maxSubsumerItem = subsumerItem; |
| 877 |
} |
| 878 |
} |
| 879 |
if (!maxSubsumerItem) { |
| 880 |
maxSubsumerItem = topItem; |
| 881 |
} |
| 882 |
|
| 883 |
bool upPropConnected = false; |
| 884 |
QSet<COptimizedKPSetClassTestingItem*>* upPropSet = item->getUpPropagationItemSet(); |
| 885 |
if (item != topItem) { |
| 886 |
upPropSet->insert(maxSubsumerItem); |
| 887 |
maxSubsumerItem->addDownPropagationItem(item); |
| 888 |
upPropConnected |= maxSubsumerItem->isPropagationConnected(); |
| 889 |
} |
| 890 |
|
| 891 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator itSub = subsumerList->constBegin(), itSubEnd = subsumerList->constEnd(); itSub != itSubEnd; ++itSub) { |
| 892 |
COptimizedKPSetClassTestingItem* subsumerItem = *itSub; |
| 893 |
bool alreadySubsumed = false; |
| 894 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator itProp = upPropSet->constBegin(), itPropEnd = upPropSet->constEnd(); !alreadySubsumed && itProp != itPropEnd; ++itProp) { |
| 895 |
COptimizedKPSetClassTestingItem* propItem = *itProp; |
| 896 |
if (propItem == subsumerItem || propItem->hasSubsumerConceptItem(subsumerItem)) { |
| 897 |
alreadySubsumed = true; |
| 898 |
} |
| 899 |
} |
| 900 |
if (!alreadySubsumed) { |
| 901 |
upPropSet->insert(subsumerItem); |
| 902 |
subsumerItem->addDownPropagationItem(item); |
| 903 |
upPropConnected |= subsumerItem->isPropagationConnected(); |
| 904 |
} |
| 905 |
} |
| 906 |
if (!upPropConnected) { |
| 907 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator itSub = subsumerList->constBegin(), itSubEnd = subsumerList->constEnd(); itSub != itSubEnd && !upPropConnected; ++itSub) { |
| 908 |
COptimizedKPSetClassTestingItem* subsumerItem = *itSub; |
| 909 |
if (subsumerItem->isPropagationConnected()) { |
| 910 |
upPropSet->insert(subsumerItem); |
| 911 |
subsumerItem->addDownPropagationItem(item); |
| 912 |
upPropConnected |= subsumerItem->isPropagationConnected(); |
| 913 |
} |
| 914 |
} |
| 915 |
if (!upPropConnected) { |
| 916 |
upPropSet->insert(topItem); |
| 917 |
topItem->addDownPropagationItem(item); |
| 918 |
upPropConnected |= topItem->isPropagationConnected(); |
| 919 |
} |
| 920 |
} |
| 921 |
item->setPropagationConnected(upPropConnected); |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
} |
| 926 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 927 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(createDebugKPSetString(optKPSetClassificationItem,"./Debugging/Classification/classkpsets-inital.txt")); |
| 928 |
|
| 929 |
|
| 930 |
foreach (COptimizedKPSetClassTestingItem* item, classList) { |
| 931 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 932 |
QSet<COptimizedKPSetClassTestingItem*>* upPropSet = item->getUpPropagationItemSet(); |
| 933 |
if (!possSubsumMap && item->isPossibleSubsumptionMapInitialized()) { |
| 934 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator itProp = upPropSet->constBegin(), itPropEnd = upPropSet->constEnd(); itProp != itPropEnd; ++itProp) { |
| 935 |
COptimizedKPSetClassTestingItem* upPropItem = *itProp; |
| 936 |
|
| 937 |
COptimizedKPSetClassPossibleSubsumptionMap* upPropItemPossSubsumMap = upPropItem->getPossibleSubsumptionMap(false); |
| 938 |
if (upPropItemPossSubsumMap) { |
| 939 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator itUpPoss = upPropItemPossSubsumMap->constBegin(), itUpPossEnd = upPropItemPossSubsumMap->constEnd(); itUpPoss != itUpPossEnd; ++itUpPoss) { |
| 940 |
COptimizedKPSetClassPossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 941 |
if (!item->hasSubsumerConceptItem(upPossData->getClassItem()) && item != upPossData->getClassItem()) { |
| 942 |
if (!upPossData->isSubsumptionInvalided()) { |
| 943 |
upPossData->setSubsumptionInvalid(true); |
| 944 |
if (upPossData->isUpdateRequired()) { |
| 945 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 946 |
} |
| 947 |
} |
| 948 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 949 |
} |
| 950 |
} |
| 951 |
} |
| 952 |
} |
| 953 |
} else { |
| 954 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator itProp = upPropSet->constBegin(), itPropEnd = upPropSet->constEnd(); itProp != itPropEnd; ++itProp) { |
| 955 |
COptimizedKPSetClassTestingItem* upPropItem = *itProp; |
| 956 |
|
| 957 |
COptimizedKPSetClassPossibleSubsumptionMap* upPropItemPossSubsumMap = upPropItem->getPossibleSubsumptionMap(false); |
| 958 |
if (upPropItemPossSubsumMap) { |
| 959 |
COptimizedKPSetClassPossibleSubsumptionMap::const_iterator itUpPoss = upPropItemPossSubsumMap->constBegin(), itUpPossEnd = upPropItemPossSubsumMap->constEnd(); |
| 960 |
if (possSubsumMap) { |
| 961 |
COptimizedKPSetClassPossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); |
| 962 |
while (itPoss != itPossEnd && itUpPoss != itUpPossEnd) { |
| 963 |
CConcept* possCon = itPoss.key().getConcept(); |
| 964 |
CConcept* possUpCon = itUpPoss.key().getConcept(); |
| 965 |
if (possCon->getConceptTag() == possUpCon->getConceptTag()) { |
| 966 |
++itPoss; |
| 967 |
++itUpPoss; |
| 968 |
} else if (possCon->getConceptTag() < possUpCon->getConceptTag()) { |
| 969 |
++itPoss; |
| 970 |
} else if (possCon->getConceptTag() > possUpCon->getConceptTag()) { |
| 971 |
COptimizedKPSetClassPossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 972 |
if (!item->hasSubsumerConceptItem(upPossData->getClassItem()) && item != upPossData->getClassItem()) { |
| 973 |
if (!upPossData->isSubsumptionInvalided()) { |
| 974 |
upPossData->setSubsumptionInvalid(true); |
| 975 |
if (upPossData->isUpdateRequired()) { |
| 976 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 977 |
} |
| 978 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 979 |
} |
| 980 |
} |
| 981 |
++itUpPoss; |
| 982 |
} |
| 983 |
} |
| 984 |
} |
| 985 |
while (itUpPoss != itUpPossEnd) { |
| 986 |
COptimizedKPSetClassPossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 987 |
if (!item->hasSubsumerConceptItem(upPossData->getClassItem()) && item != upPossData->getClassItem()) { |
| 988 |
if (!upPossData->isSubsumptionInvalided()) { |
| 989 |
upPossData->setSubsumptionInvalid(true); |
| 990 |
if (upPossData->isUpdateRequired()) { |
| 991 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 992 |
} |
| 993 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 994 |
} |
| 995 |
} |
| 996 |
++itUpPoss; |
| 997 |
} |
| 998 |
} |
| 999 |
} |
| 1000 |
} |
| 1001 |
} |
| 1002 |
|
| 1003 |
foreach (COptimizedKPSetClassTestingItem* item, resevePossSubsumClassList) { |
| 1004 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 1005 |
if (possSubsumMap) { |
| 1006 |
if (possSubsumMap->hasRemainingPossibleSubsumptions()) { |
| 1007 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 1008 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = it.value(); |
| 1009 |
|
| 1010 |
if (mConfPossSubsumPseudoModelPretest) { |
| 1011 |
if (possSubsumData->isSubsumptionUnknown()) { |
| 1012 |
bool isSubsumptionFlag = false; |
| 1013 |
if (fastPseudoModelSubsumptionClassPrecheckTest(optKPSetClassificationItem,item,possSubsumData->getClassItem(),&isSubsumptionFlag)) { |
| 1014 |
CClassifierStatistics* ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 1015 |
if (ontClassStat) { |
| 1016 |
ontClassStat->incPseudoModelMergedTestedSubsumptionCount(1); |
| 1017 |
} |
| 1018 |
if (!isSubsumptionFlag) { |
| 1019 |
optKPSetClassificationItem->incRunningPossibleSubsumptionTestsCount(); |
| 1020 |
possSubsumData->setSubsumptionInvalid(true); |
| 1021 |
++mPseudoModelPretestSubsumptionCalculationCount; |
| 1022 |
interpreteSubsumptionResult(optKPSetClassificationItem,item->getTestingConcept(),possSubsumData->getClassItem()->getTestingConcept(),possSubsumData->isSubsumptionConfirmed()); |
| 1023 |
} |
| 1024 |
} |
| 1025 |
} |
| 1026 |
} |
| 1027 |
if (mConfPossSubsumCalcOrderBottomUp) { |
| 1028 |
if (possSubsumData->isSubsumptionUnknown() || possSubsumData->isUpdateRequired()) { |
| 1029 |
COptimizedKPSetClassTestingItem* possSubsumerItem = possSubsumData->getClassItem(); |
| 1030 |
possSubsumerItem->getPossibleSubsumedSet(true)->insert(item); |
| 1031 |
if (!remTestingSet->contains(possSubsumerItem)) { |
| 1032 |
remTestingSet->insert(possSubsumerItem); |
| 1033 |
nextItemList->append(possSubsumerItem); |
| 1034 |
} |
| 1035 |
} |
| 1036 |
} |
| 1037 |
} |
| 1038 |
} |
| 1039 |
} |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
if (mConfPossSubsumCalcOrderBottomUp) { |
| 1044 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = remTestingSet->constBegin(), itEnd = remTestingSet->constEnd(); it != itEnd; ++it) { |
| 1045 |
COptimizedKPSetClassTestingItem* possSubsumerItem = *it; |
| 1046 |
QList<COptimizedKPSetClassTestingItem*>* subsumersSortedList = new QList<COptimizedKPSetClassTestingItem*>(possSubsumerItem->getPossibleSubsumedSet(false)->toList()); |
| 1047 |
qSort(subsumersSortedList->begin(),subsumersSortedList->end(),itemSortMoreSubsumptionsThan); |
| 1048 |
possSubsumerItem->setPossibleSubsumedList(subsumersSortedList); |
| 1049 |
} |
| 1050 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectReferenced(optKPSetClassificationItem)); |
| 1051 |
} |
| 1052 |
|
| 1053 |
if (mConfWriteDebuggingData) { |
| 1054 |
createDebugKPSetString(optKPSetClassificationItem,"./Debugging/Classification/classkpsets-inital-pruned.txt"); |
| 1055 |
} |
| 1056 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(createDebugKPSetString(optKPSetClassificationItem,"./Debugging/Classification/classkpsets-inital-pruned.txt")); |
| 1057 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1058 |
|
| 1059 |
} |
| 1060 |
} |
| 1061 |
} |
| 1062 |
|
| 1063 |
if (optKPSetClassificationItem->hasSatisfiableTestingPhaseFinished() && !optKPSetClassificationItem->hasPossibleSubsumptionTestingPhaseFinished() && !optKPSetClassificationItem->isTaxonomyConstructionFailed()) { |
| 1064 |
|
| 1065 |
QList<COptimizedKPSetClassTestingItem*>* nextItemList = optKPSetClassificationItem->getNextPossibleSubsumptionTestingItemList(); |
| 1066 |
QSet<COptimizedKPSetClassTestingItem*>* currentItemSet = optKPSetClassificationItem->getCurrentPossibleSubsumptionTestingItemSet(); |
| 1067 |
|
| 1068 |
bool canContinueSearchingForTests = true; |
| 1069 |
|
| 1070 |
while (!workTestCreated && optKPSetClassificationItem->hasRemainingPossibleSubsumptionTests() && canContinueSearchingForTests) { |
| 1071 |
// get next possible subsumption test |
| 1072 |
canContinueSearchingForTests = false; |
| 1073 |
|
| 1074 |
COptimizedKPSetClassTestingItem* nextPossSubsumTestItem = nullptr; |
| 1075 |
if (!nextItemList->isEmpty()) { |
| 1076 |
nextPossSubsumTestItem = nextItemList->takeFirst(); |
| 1077 |
} |
| 1078 |
|
| 1079 |
if (nextPossSubsumTestItem) { |
| 1080 |
canContinueSearchingForTests = true; |
| 1081 |
|
| 1082 |
if (mConfPossSubsumCalcOrderTopDown) { |
| 1083 |
|
| 1084 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumerMap = nextPossSubsumTestItem->getPossibleSubsumptionMap(false); |
| 1085 |
if (possSubsumerMap && possSubsumerMap->hasRemainingPossibleSubsumptions()) { |
| 1086 |
|
| 1087 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumCalcData = getNextPossibleSubsumptionCalculation(optKPSetClassificationItem,nextPossSubsumTestItem); |
| 1088 |
if (possSubsumCalcData) { |
| 1089 |
currentItemSet->insert(nextPossSubsumTestItem); |
| 1090 |
optKPSetClassificationItem->incRunningPossibleSubsumptionTestsCount(); |
| 1091 |
|
| 1092 |
if (calculateSubsumption(optKPSetClassificationItem,nextPossSubsumTestItem,possSubsumCalcData->getClassItem(),possSubsumCalcData)) { |
| 1093 |
workTestCreated = true; |
| 1094 |
} else { |
| 1095 |
interpreteSubsumptionResult(optKPSetClassificationItem,nextPossSubsumTestItem->getTestingConcept(),possSubsumCalcData->getClassItem()->getTestingConcept(),possSubsumCalcData->isSubsumptionConfirmed()); |
| 1096 |
} |
| 1097 |
} |
| 1098 |
} else { |
| 1099 |
QSet<COptimizedKPSetClassTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionClassTestingSet(); |
| 1100 |
remTestingSet->remove(nextPossSubsumTestItem); |
| 1101 |
} |
| 1102 |
|
| 1103 |
} else if (mConfPossSubsumCalcOrderBottomUp) { |
| 1104 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumCalcData = nullptr; |
| 1105 |
COptimizedKPSetClassTestingItem* possSubsumedItem = nullptr; |
| 1106 |
|
| 1107 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1108 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectReferenced(optKPSetClassificationItem)); |
| 1109 |
|
| 1110 |
CConcept* possSubsumerConcept = nextPossSubsumTestItem->getTestingConcept(); |
| 1111 |
CConcept* candidateConcept = possSubsumerConcept; |
| 1112 |
if (possSubsumerConcept->getOperatorCode() == CCEQ) { |
| 1113 |
candidateConcept = optKPSetClassificationItem->getEquivalentConceptCandidateHash()->value(possSubsumerConcept); |
| 1114 |
if (!candidateConcept) { |
| 1115 |
candidateConcept = possSubsumerConcept; |
| 1116 |
} |
| 1117 |
} |
| 1118 |
|
| 1119 |
QList<COptimizedKPSetClassTestingItem*>* possSubsumedSortedList = nextPossSubsumTestItem->getPossibleSubsumedList(); |
| 1120 |
if (possSubsumedSortedList && !possSubsumedSortedList->isEmpty()) { |
| 1121 |
while (!possSubsumCalcData && !possSubsumedSortedList->isEmpty()) { |
| 1122 |
possSubsumedItem = possSubsumedSortedList->takeFirst(); |
| 1123 |
if (nextPossSubsumTestItem->getPossibleSubsumedSet(false)->contains(possSubsumedItem)) { |
| 1124 |
nextPossSubsumTestItem->getPossibleSubsumedSet(false)->remove(possSubsumedItem); |
| 1125 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumerMap = possSubsumedItem->getPossibleSubsumptionMap(false); |
| 1126 |
if (possSubsumerMap && possSubsumerMap->hasRemainingPossibleSubsumptions()) { |
| 1127 |
possSubsumCalcData = possSubsumerMap->value(CConceptTagComparer(candidateConcept)); |
| 1128 |
} |
| 1129 |
} |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
if (possSubsumCalcData) { |
| 1134 |
//if ((possSubsumCalcData->isUpdateRequired() || possSubsumCalcData->isSubsumptionUnknown())) { |
| 1135 |
currentItemSet->insert(nextPossSubsumTestItem); |
| 1136 |
optKPSetClassificationItem->incRunningPossibleSubsumptionTestsCount(); |
| 1137 |
|
| 1138 |
|
| 1139 |
//QString iriClassNameString1 = CIRIName::getRecentIRIName(possSubsumedItem->getTestingConcept()->getClassNameLinker()); |
| 1140 |
//QString iriClassNameString2 = CIRIName::getRecentIRIName(nextPossSubsumTestItem->getTestingConcept()->getClassNameLinker()); |
| 1141 |
//if (iriClassNameString2 == "http://www.owllink.org/testsuite/npt8-D#TransitionMetalAtom" && iriClassNameString1 == "http://www.owllink.org/testsuite/npt8-D#TitaniumFamilyAtom") { |
| 1142 |
// bool bug = true; |
| 1143 |
//} |
| 1144 |
|
| 1145 |
//if (subsumCalcedSet.contains(QPair<CConcept*,CConcept*>(possSubsumedItem->getTestingConcept(),nextPossSubsumTestItem->getTestingConcept()))) { |
| 1146 |
// bool bug = true; |
| 1147 |
//} |
| 1148 |
//subsumCalcedSet.insert(QPair<CConcept*,CConcept*>(possSubsumedItem->getTestingConcept(),nextPossSubsumTestItem->getTestingConcept())); |
| 1149 |
|
| 1150 |
if (calculateSubsumption(optKPSetClassificationItem,possSubsumedItem,nextPossSubsumTestItem,possSubsumCalcData)) { |
| 1151 |
workTestCreated = true; |
| 1152 |
} else { |
| 1153 |
interpreteSubsumptionResult(optKPSetClassificationItem,possSubsumedItem->getTestingConcept(),nextPossSubsumTestItem->getTestingConcept(),possSubsumCalcData->isSubsumptionConfirmed()); |
| 1154 |
} |
| 1155 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectReferenced(optKPSetClassificationItem)); |
| 1156 |
//} |
| 1157 |
} else { |
| 1158 |
QSet<COptimizedKPSetClassTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionClassTestingSet(); |
| 1159 |
remTestingSet->remove(nextPossSubsumTestItem); |
| 1160 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectReferenced(optKPSetClassificationItem)); |
| 1161 |
} |
| 1162 |
|
| 1163 |
} |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
if (!workTestCreated && currentItemSet->isEmpty()) { |
| 1168 |
optKPSetClassificationItem->setPossibleSubsumptionTestingPhaseFinished(true); |
| 1169 |
} |
| 1170 |
} |
| 1171 |
|
| 1172 |
|
| 1173 |
if (!workTestCreated) { |
| 1174 |
if (optKPSetClassificationItem->hasPossibleSubsumptionTestingPhaseFinished() || optKPSetClassificationItem->isTaxonomyConstructionFailed()) { |
| 1175 |
finishOntologyClassification(optKPSetClassificationItem); |
| 1176 |
processingOntItemList.removeFirst(); |
| 1177 |
} else { |
| 1178 |
processingOntItemList.removeFirst(); |
| 1179 |
processingOntItemList.append(ontClassItem); |
| 1180 |
loopOntClassItem = ontClassItem; |
| 1181 |
} |
| 1182 |
} |
| 1183 |
} |
| 1184 |
return workTestCreated; |
| 1185 |
} |
| 1186 |
|
| 1187 |
|
| 1188 |
COptimizedKPSetClassPossibleSubsumptionData* COptimizedKPSetClassSubsumptionClassifierThread::getNextPossibleSubsumptionCalculation(COptimizedKPSetClassOntologyClassificationItem *ontClassItem, COptimizedKPSetClassTestingItem* classItem) { |
| 1189 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumer = nullptr; |
| 1190 |
// I don't know which is the best, simply return the first one |
| 1191 |
// sort by subsumer count? |
| 1192 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumerMap = classItem->getPossibleSubsumptionMap(false); |
| 1193 |
if (possSubsumerMap) { |
| 1194 |
if (mConfPossSubsumCalcOrderConceptSorted) { |
| 1195 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator it = possSubsumerMap->constBegin(), itEnd = possSubsumerMap->constEnd(); !possSubsumer && it != itEnd; ++it) { |
| 1196 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = it.value(); |
| 1197 |
if (possSubsumData->isSubsumptionUnknown()) { |
| 1198 |
possSubsumer = possSubsumData; |
| 1199 |
} else if (possSubsumData->isUpdateRequired()) { |
| 1200 |
prunePossibleSubsumptions(ontClassItem,classItem,possSubsumData); |
| 1201 |
} |
| 1202 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(ontClassItem)); |
| 1203 |
} |
| 1204 |
} |
| 1205 |
} |
| 1206 |
return possSubsumer; |
| 1207 |
} |
| 1208 |
|
| 1209 |
|
| 1210 |
bool COptimizedKPSetClassSubsumptionClassifierThread::calculateSatisfiable(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetClassTestingItem* nextSatTestItem) { |
| 1211 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 1212 |
CClassClassificationComputationItem *workItem = 0; |
| 1213 |
|
| 1214 |
CConcept* concept = nextSatTestItem->getTestingConcept(); |
| 1215 |
nextSatTestItem->setSatisfiableTestOrdered(true); |
| 1216 |
|
| 1217 |
bool satisfiableFlag = false; |
| 1218 |
|
| 1219 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGB |
| 1220 |
QString iriClassNameString = CIRIName::getRecentIRIName(concept->getClassNameLinker()); |
| 1221 |
#endif |
| 1222 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION |
| 1223 |
statUpdateMutex.lock(); |
| 1224 |
statusString = QString("[%2/%3] Calculating, is '%1' satisfiable").arg(iriClassNameString).arg(optKPSetClassificationItem->getClassifierStatistics()->getTestedSatisfiableCount()).arg(optKPSetClassificationItem->getClassifierStatistics()->getTotalSatisfiableCount()); |
| 1225 |
statUpdateMutex.unlock(); |
| 1226 |
#endif |
| 1227 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGLOGOUTPUT |
| 1228 |
LOG(INFO,getLogDomain(),QString("Calculating whether '%1' is satisfiable").arg(iriClassNameString),this); |
| 1229 |
#endif |
| 1230 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCOUTOUTPUT |
| 1231 |
cout<<QString("Calculating whether '%1' is satisfiable").arg(iriClassNameString).toLocal8Bit().data()<<endl<<endl; |
| 1232 |
#endif |
| 1233 |
|
| 1234 |
//if (iriClassNameString == "http://www.semanticweb.org/ontologies/2010/9/Ontology1288387737869.owl#middle-man") { |
| 1235 |
// bool bug = true; |
| 1236 |
//} |
| 1237 |
|
| 1238 |
|
| 1239 |
if (nextSatTestItem->isResultSatisfiableDerivated()) { |
| 1240 |
satisfiableFlag = true; |
| 1241 |
nextSatTestItem->setSatisfiableTested(true); |
| 1242 |
nextSatTestItem->setSatisfiableTestedResult(true); |
| 1243 |
return false; |
| 1244 |
} |
| 1245 |
if (nextSatTestItem->isResultUnsatisfiableDerivated()) { |
| 1246 |
satisfiableFlag = false; |
| 1247 |
nextSatTestItem->setSatisfiableTested(true); |
| 1248 |
nextSatTestItem->setSatisfiableTestedResult(false); |
| 1249 |
return false; |
| 1250 |
} |
| 1251 |
CPrecomputedSaturationSubsumerExtractor* precSatSubsumerExtractor = optKPSetClassificationItem->getPrecomputedSaturationSubsumerExtractor(false); |
| 1252 |
bool unsatisfiableFlag = false; |
| 1253 |
if (precSatSubsumerExtractor && precSatSubsumerExtractor->getConceptFlags(concept,&unsatisfiableFlag,nullptr,nullptr) && unsatisfiableFlag) { |
| 1254 |
satisfiableFlag = false; |
| 1255 |
nextSatTestItem->setSatisfiableTested(true); |
| 1256 |
nextSatTestItem->setSatisfiableTestedResult(false); |
| 1257 |
return false; |
| 1258 |
} |
| 1259 |
if (fastSatisfiableOnlySubClassPrecheckTest(optKPSetClassificationItem,nextSatTestItem,&satisfiableFlag)) { |
| 1260 |
nextSatTestItem->setSatisfiableTested(true); |
| 1261 |
nextSatTestItem->setSatisfiableTestedResult(satisfiableFlag); |
| 1262 |
return false; |
| 1263 |
} |
| 1264 |
|
| 1265 |
CSatisfiableCalculationJobGenerator satCalcJobGen(optKPSetClassificationItem->getOntology()); |
| 1266 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(concept); |
| 1267 |
QHash<CSatisfiableCalculationJob *, CClassClassificationComputationItem *> *workHash = optKPSetClassificationItem->getWorkItemHash(); |
| 1268 |
|
| 1269 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 1270 |
if (ontClassStat) { |
| 1271 |
ontClassStat->incCalculatedTestedSatisfiableCount(1); |
| 1272 |
} |
| 1273 |
|
| 1274 |
workItem = new CClassClassificationComputationItem(satCalcJob,concept); |
| 1275 |
workHash->insertMulti(satCalcJob,workItem); |
| 1276 |
workOntItemHash.insert(workItem,optKPSetClassificationItem); |
| 1277 |
|
| 1278 |
QHash<CConcept*,CClassificationSatisfiableCalculationConceptReferenceLinking*>* conRefLinkDataHash = optKPSetClassificationItem->getConceptReferenceLinkingDataHash(); |
| 1279 |
cint64 extFlags = CSatisfiableTaskClassificationMessageAdapter::EFEXTRACTALL; |
| 1280 |
// TODO: set extraction flags |
| 1281 |
|
| 1282 |
|
| 1283 |
satCalcJob->setSatisfiableClassificationMessageAdapter(new CSatisfiableTaskClassificationMessageAdapter(concept,optKPSetClassificationItem->getOntology(),this,conRefLinkDataHash,extFlags)); |
| 1284 |
|
| 1285 |
optKPSetClassificationItem->incCurrentCalculatingCount(); |
| 1286 |
if (optKPSetClassificationItem->getIndividualDependenceTrackingCollector()) { |
| 1287 |
satCalcJob->setSatisfiableTaskIndividualDependenceTrackingAdapter(new CSatisfiableTaskIndividualDependenceTrackingAdapter(optKPSetClassificationItem->getIndividualDependenceTrackingCollector(),nextSatTestItem)); |
| 1288 |
} |
| 1289 |
processCalculationJob(satCalcJob,optKPSetClassificationItem,workItem); |
| 1290 |
++mCreatedCalculationTaskCount; |
| 1291 |
return true; |
| 1292 |
} |
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
bool COptimizedKPSetClassSubsumptionClassifierThread::calculateSubsumption(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetClassTestingItem* subsumedItem, COptimizedKPSetClassTestingItem* possSubsumerItem, COptimizedKPSetClassPossibleSubsumptionData* possSubsumData) { |
| 1299 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 1300 |
CClassClassificationComputationItem *workItem = 0; |
| 1301 |
++mOrderedSubsumptionCalculationCount; |
| 1302 |
|
| 1303 |
CConcept* subsumedConcept = subsumedItem->getTestingConcept(); |
| 1304 |
CConcept* subsumerConcept = possSubsumerItem->getTestingConcept(); |
| 1305 |
|
| 1306 |
bool isSubsumptionFlag = false; |
| 1307 |
bool precheckedSubsum = false; |
| 1308 |
|
| 1309 |
|
| 1310 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGB |
| 1311 |
QString iriClassNameString1 = CIRIName::getRecentIRIName(subsumedConcept->getClassNameLinker()); |
| 1312 |
QString iriClassNameString2 = CIRIName::getRecentIRIName(subsumerConcept->getClassNameLinker()); |
| 1313 |
#endif |
| 1314 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION |
| 1315 |
statUpdateMutex.lock(); |
| 1316 |
statusString = QString("Calculating, is '%1' subsumed by '%2'").arg(iriClassNameString1).arg(iriClassNameString2); |
| 1317 |
statUpdateMutex.unlock(); |
| 1318 |
#endif |
| 1319 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGLOGOUTPUT |
| 1320 |
LOG(INFO,getLogDomain(),QString("Calculating whether '%1' is subsumed by '%2'").arg(iriClassNameString1).arg(iriClassNameString2),this); |
| 1321 |
#endif |
| 1322 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCOUTOUTPUT |
| 1323 |
cout<<QString("Calculating whether '%1' is subsumed by '%2'").arg(iriClassNameString1).arg(iriClassNameString2).toLocal8Bit().data()<<endl<<endl; |
| 1324 |
#endif |
| 1325 |
|
| 1326 |
|
| 1327 |
//if (iriClassNameString1 == "http://krono.act.uji.es/people/Ernesto/qimage-ontology/OntologyQimage.owl#Image_type" && iriClassNameString2 == "http://krono.act.uji.es/people/Ernesto/qimage-ontology/QimageUJIDescriptions.owl#Image_with_uji_office_door" ) { |
| 1328 |
// bool bug = true; |
| 1329 |
//} |
| 1330 |
|
| 1331 |
|
| 1332 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 1333 |
if (possSubsumData && possSubsumData->isSubsumptionKnown()) { |
| 1334 |
return false; |
| 1335 |
} else if (possSubsumData && subsumedItem->hasSubsumerConceptItem(possSubsumerItem)) { |
| 1336 |
possSubsumData->setSubsumptionConfirmed(true); |
| 1337 |
return false; |
| 1338 |
} else if (mConfPossSubsumPseudoModelTest && fastPseudoModelSubsumptionClassPrecheckTest(optKPSetClassificationItem,subsumedItem,possSubsumerItem,&isSubsumptionFlag)) { |
| 1339 |
if (ontClassStat) { |
| 1340 |
ontClassStat->incPseudoModelMergedTestedSubsumptionCount(1); |
| 1341 |
} |
| 1342 |
return false; |
| 1343 |
} |
| 1344 |
|
| 1345 |
CSatisfiableCalculationJobGenerator satCalcJobGen(optKPSetClassificationItem->getOntology()); |
| 1346 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(subsumedConcept,false,subsumerConcept,true); |
| 1347 |
QHash<CSatisfiableCalculationJob *, CClassClassificationComputationItem *> *workHash = optKPSetClassificationItem->getWorkItemHash(); |
| 1348 |
|
| 1349 |
if (ontClassStat) { |
| 1350 |
ontClassStat->incCalculatedTestedSubsumptionCount(1); |
| 1351 |
ontClassStat->incToldSubsumptionCount(1); |
| 1352 |
} |
| 1353 |
|
| 1354 |
workItem = new CClassClassificationComputationItem(satCalcJob,subsumerConcept,subsumedConcept); |
| 1355 |
workHash->insertMulti(satCalcJob,workItem); |
| 1356 |
workOntItemHash.insert(workItem,optKPSetClassificationItem); |
| 1357 |
|
| 1358 |
QHash<CConcept*,CClassificationSatisfiableCalculationConceptReferenceLinking*>* conRefLinkDataHash = optKPSetClassificationItem->getConceptReferenceLinkingDataHash(); |
| 1359 |
cint64 extFlags = CSatisfiableTaskClassificationMessageAdapter::EFEXTRACTSUBSUMERSOTHERNODES | |
| 1360 |
CSatisfiableTaskClassificationMessageAdapter::EFEXTRACTPOSSIBLESUBSUMERSROOTNODE | |
| 1361 |
CSatisfiableTaskClassificationMessageAdapter::EFEXTRACTPOSSIBLESUBSUMERSOTHERNODES | |
| 1362 |
CSatisfiableTaskClassificationMessageAdapter::EFEXTRACTOTHERNODESMULTIPLEDEPENDENCY; |
| 1363 |
// TODO: set extraction flags |
| 1364 |
|
| 1365 |
satCalcJob->setSatisfiableClassificationMessageAdapter(new CSatisfiableTaskClassificationMessageAdapter(subsumedConcept,optKPSetClassificationItem->getOntology(),this,conRefLinkDataHash,extFlags)); |
| 1366 |
if (optKPSetClassificationItem->getIndividualDependenceTrackingCollector()) { |
| 1367 |
satCalcJob->setSatisfiableTaskIndividualDependenceTrackingAdapter(new CSatisfiableTaskIndividualDependenceTrackingAdapter(optKPSetClassificationItem->getIndividualDependenceTrackingCollector(),subsumedItem)); |
| 1368 |
} |
| 1369 |
|
| 1370 |
optKPSetClassificationItem->incCurrentCalculatingCount(); |
| 1371 |
processCalculationJob(satCalcJob,optKPSetClassificationItem,workItem); |
| 1372 |
optKPSetClassificationItem->incCalculatedPossibleSubsumerCount(); |
| 1373 |
++mCreatedCalculationTaskCount; |
| 1374 |
return true; |
| 1375 |
} |
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
CIndividualSaturationProcessNode* COptimizedKPSetClassSubsumptionClassifierThread::getSaturationIndividualNodeForConcept(CConcept* concept, bool negated) { |
| 1381 |
CIndividualSaturationProcessNode* node = nullptr; |
| 1382 |
CConceptData* conceptData = concept->getConceptData(); |
| 1383 |
if (conceptData) { |
| 1384 |
CConceptProcessData* conProcData = (CConceptProcessData*)conceptData; |
| 1385 |
CConceptReferenceLinking* conRefLinking = conProcData->getConceptReferenceLinking(); |
| 1386 |
if (conRefLinking) { |
| 1387 |
CConceptSaturationReferenceLinkingData* confSatRefLinkingData = (CConceptSaturationReferenceLinkingData*)conRefLinking; |
| 1388 |
CSaturationConceptReferenceLinking* satCalcRefLinkData = confSatRefLinkingData->getConceptSaturationReferenceLinkingData(negated); |
| 1389 |
if (satCalcRefLinkData) { |
| 1390 |
node = (CIndividualSaturationProcessNode*)satCalcRefLinkData->getIndividualProcessNodeForConcept(); |
| 1391 |
} |
| 1392 |
} |
| 1393 |
} |
| 1394 |
return node; |
| 1395 |
} |
| 1396 |
|
| 1397 |
|
| 1398 |
bool COptimizedKPSetClassSubsumptionClassifierThread::hasCachedSaturationIndividualNodeAssociatedExpansionProplematicConcept(CCacheEntry* cacheEntry, CConcept* testingConcept) { |
| 1399 |
if (!cacheEntry) { |
| 1400 |
return true; |
| 1401 |
} |
| 1402 |
CSaturationNodeAssociatedExpansionCacheEntry* satNodeExpCacheEntry = (CSaturationNodeAssociatedExpansionCacheEntry*)cacheEntry; |
| 1403 |
|
| 1404 |
CSaturationNodeAssociatedDeterministicConceptExpansion* detExp = satNodeExpCacheEntry->getDeterministicConceptExpansion(); |
| 1405 |
CSaturationNodeAssociatedNondeterministicConceptExpansion* ndetExpLinker = satNodeExpCacheEntry->getNondeterministicConceptExpansionLinker(); |
| 1406 |
if (!detExp && !ndetExpLinker) { |
| 1407 |
return true; |
| 1408 |
} |
| 1409 |
CCacheValue cacheValue(mSatNodeExpCacheReader->getCacheValue(testingConcept,true)); |
| 1410 |
if (detExp) { |
| 1411 |
CSaturationNodeAssociatedConceptLinker* cacheValueExpLinker = detExp->getConceptExpansionLinker(&cacheValue); |
| 1412 |
if (cacheValueExpLinker) { |
| 1413 |
return true; |
| 1414 |
} |
| 1415 |
} |
| 1416 |
if (ndetExpLinker && (!detExp || detExp->requiresNonDeterministicExpansion())) { |
| 1417 |
bool allNonDetExpansionsProblematic = true; |
| 1418 |
for (CSaturationNodeAssociatedNondeterministicConceptExpansion* ndetExpLinkerIt = ndetExpLinker; allNonDetExpansionsProblematic && ndetExpLinkerIt; ndetExpLinkerIt = ndetExpLinkerIt->getNext()) { |
| 1419 |
CSaturationNodeAssociatedConceptLinker* ndetCacheValueExpLinker = ndetExpLinkerIt->getConceptExpansionLinker(&cacheValue); |
| 1420 |
if (!ndetCacheValueExpLinker) { |
| 1421 |
allNonDetExpansionsProblematic = false; |
| 1422 |
} |
| 1423 |
} |
| 1424 |
if (allNonDetExpansionsProblematic) { |
| 1425 |
return true; |
| 1426 |
} |
| 1427 |
} |
| 1428 |
return false; |
| 1429 |
} |
| 1430 |
|
| 1431 |
|
| 1432 |
CCacheEntry* COptimizedKPSetClassSubsumptionClassifierThread::getAssociatedSaturationCacheEntry(COptimizedKPSetClassTestingItem* classConItem) { |
| 1433 |
CCacheEntry* cacheEntry = classConItem->getFastSatisfiabilityTestedSaturationCacheEntry(); |
| 1434 |
if (!cacheEntry) { |
| 1435 |
CConcept* concept = classConItem->getTestingConcept(); |
| 1436 |
CIndividualSaturationProcessNode* satNode = getSaturationIndividualNodeForConcept(concept,false); |
| 1437 |
cacheEntry = mSatNodeExpCacheReader->getCacheEntry(satNode); |
| 1438 |
classConItem->setFastSatisfiabilityTestedSaturationCacheEntry(cacheEntry); |
| 1439 |
} |
| 1440 |
return cacheEntry; |
| 1441 |
} |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
bool COptimizedKPSetClassSubsumptionClassifierThread::fastSatisfiableOnlySubClassPrecheckTest(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetClassTestingItem* nextSatTestItem, bool* isSatisfiableFlag) { |
| 1447 |
QHash<CConcept*,COptimizedKPSetClassTestingItem*>* conceptSatItemHash = optKPSetClassificationItem->getConceptSatisfiableTestItemHash(); |
| 1448 |
CBOXHASH<CConcept*,CConcept*>* triggerImpHash = optKPSetClassificationItem->getOntology()->getTBox()->getTriggerImplicationHash(false); |
| 1449 |
CConcept* concept = nextSatTestItem->getTestingConcept(); |
| 1450 |
bool satFlag = false; |
| 1451 |
bool testComplete = false; |
| 1452 |
if (concept->getOperatorCode() == CCSUB) { |
| 1453 |
cint64 conCount = concept->getOperandCount(); |
| 1454 |
if (conCount == 1) { |
| 1455 |
CSortedNegLinker<CConcept*>* opLinkerIt = concept->getOperandList(); |
| 1456 |
CConcept* firstConcept = opLinkerIt->getData(); |
| 1457 |
cint64 firstOpCode = firstConcept->getOperatorCode(); |
| 1458 |
CConcept* superClassConcept = nullptr; |
| 1459 |
if (!opLinkerIt->isNegated() && (firstOpCode == CCATOM || firstOpCode == CCSUB || firstOpCode == CCEQ)) { |
| 1460 |
superClassConcept = firstConcept; |
| 1461 |
} |
| 1462 |
|
| 1463 |
if ((!triggerImpHash || !triggerImpHash->contains(concept)) && superClassConcept) { |
| 1464 |
COptimizedKPSetClassTestingItem* superClassConItem = conceptSatItemHash->value(superClassConcept); |
| 1465 |
if (superClassConItem && superClassConItem->isSatisfiableTested()) { |
| 1466 |
if (!triggerImpHash || !triggerImpHash->contains(superClassConcept)) { |
| 1467 |
|
| 1468 |
|
| 1469 |
CCacheEntry* superCacheEntry = getAssociatedSaturationCacheEntry(superClassConItem); |
| 1470 |
if (!hasCachedSaturationIndividualNodeAssociatedExpansionProplematicConcept(superCacheEntry,concept)) { |
| 1471 |
nextSatTestItem->setFastSatisfiabilityTestedSaturationCacheEntry(superCacheEntry); |
| 1472 |
nextSatTestItem->setSuccessfullyFastSatisfiabilityTested(true); |
| 1473 |
|
| 1474 |
|
| 1475 |
QList<COptimizedKPSetClassTestingItem*>* subsumedSubsumingConList = superClassConItem->getSubsumingConceptItemList(); |
| 1476 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator it = subsumedSubsumingConList->constBegin(), itEnd = subsumedSubsumingConList->constEnd(); it != itEnd; ++it) { |
| 1477 |
COptimizedKPSetClassTestingItem* subsumedItem = (*it); |
| 1478 |
if (nextSatTestItem != subsumedItem && superClassConItem != subsumedItem) { |
| 1479 |
nextSatTestItem->addSubsumingConceptItem(subsumedItem); |
| 1480 |
} |
| 1481 |
} |
| 1482 |
nextSatTestItem->addSubsumingConceptItem(superClassConItem); |
| 1483 |
satFlag = superClassConItem->getSatisfiableTestedResult(); |
| 1484 |
testComplete = true; |
| 1485 |
|
| 1486 |
if (superClassConItem->isClassPseudoModelInitalized()) { |
| 1487 |
CClassificationClassPseudoModel* superClassPMModel = superClassConItem->getClassPseudoModel(); |
| 1488 |
CClassificationClassPseudoModel* classPMModel = nextSatTestItem->getClassPseudoModel(); |
| 1489 |
|
| 1490 |
CTempMemoryPoolContainerAllocationManager tempMemoryPoolConAllocMan(mContext.getMemoryPoolAllocationManager()); |
| 1491 |
CContext* tmpContext = CObjectParameterizingAllocator< CContextBase,CMemoryAllocationManager* >::allocateAndConstructAndParameterize(&tempMemoryPoolConAllocMan,&tempMemoryPoolConAllocMan); |
| 1492 |
CClassificationClassPseudoModelHash* pmModelHash = CObjectParameterizingAllocator< CClassificationClassPseudoModelHash,CContext* >::allocateAndConstructAndParameterize(&tempMemoryPoolConAllocMan,tmpContext); |
| 1493 |
pmModelHash->initPseudoModelHash(superClassPMModel->getPseudoModelHash()); |
| 1494 |
CClassificationClassPseudoModelData* pmModelData = pmModelHash->getPseudoModelData(0,true); |
| 1495 |
|
| 1496 |
CClassificationClassPseudoModelConceptMap* pmModelConMap = pmModelData->getPseudoModelConceptMap(true); |
| 1497 |
CClassificationClassPseudoModelConceptData& pmModelConData = (*pmModelConMap)[CConceptTagComparer(concept)]; |
| 1498 |
pmModelConData.setDeterministic(true); |
| 1499 |
|
| 1500 |
optKPSetClassificationItem->addMemoryPools(tempMemoryPoolConAllocMan.takeMemoryPools()); |
| 1501 |
classPMModel->setPseudoModelHash(pmModelHash); |
| 1502 |
nextSatTestItem->setClassPseudoModelInitalized(true); |
| 1503 |
} |
| 1504 |
|
| 1505 |
if (superClassConItem->isPossibleSubsumptionMapInitialized()) { |
| 1506 |
COptimizedKPSetClassPossibleSubsumptionMap* superPosSubsumMap = superClassConItem->getPossibleSubsumptionMap(false); |
| 1507 |
if (superPosSubsumMap && !nextSatTestItem->isPossibleSubsumptionMapInitialized()) { |
| 1508 |
COptimizedKPSetClassPossibleSubsumptionMap* subPosSubsumMap = nextSatTestItem->getPossibleSubsumptionMap(true); |
| 1509 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator it = superPosSubsumMap->constBegin(), itEnd = superPosSubsumMap->constEnd(); it != itEnd; ++it) { |
| 1510 |
CConcept* con = it.key().getConcept(); |
| 1511 |
COptimizedKPSetClassPossibleSubsumptionData* data = it.value(); |
| 1512 |
if (data->isSubsumptionUnknown() && !nextSatTestItem->hasSubsumerConceptItem(data->getClassItem()) && nextSatTestItem != data->getClassItem()) { |
| 1513 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = new COptimizedKPSetClassPossibleSubsumptionData(data->getClassItem()); |
| 1514 |
subPosSubsumMap->insert(CConceptTagComparer(con),possSubsumData); |
| 1515 |
incRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,subPosSubsumMap); |
| 1516 |
} |
| 1517 |
} |
| 1518 |
} |
| 1519 |
nextSatTestItem->setPossibleSubsumptionMapInitialized(true); |
| 1520 |
} |
| 1521 |
} |
| 1522 |
} |
| 1523 |
} |
| 1524 |
} |
| 1525 |
} |
| 1526 |
} else if (concept->getOperatorCode() == CCATOM) { |
| 1527 |
COptimizedKPSetClassTestingItem* topClassConItem = optKPSetClassificationItem->getTopConceptSatisfiableTestItem(); |
| 1528 |
if (topClassConItem->isPossibleSubsumptionMapInitialized()) { |
| 1529 |
|
| 1530 |
CCacheEntry* topCacheEntry = getAssociatedSaturationCacheEntry(topClassConItem); |
| 1531 |
if (!hasCachedSaturationIndividualNodeAssociatedExpansionProplematicConcept(topCacheEntry,concept)) { |
| 1532 |
|
| 1533 |
nextSatTestItem->setFastSatisfiabilityTestedSaturationCacheEntry(topCacheEntry); |
| 1534 |
nextSatTestItem->setSuccessfullyFastSatisfiabilityTested(true); |
| 1535 |
|
| 1536 |
satFlag = true; |
| 1537 |
testComplete = true; |
| 1538 |
CClassificationClassPseudoModel* classPMModel = nextSatTestItem->getClassPseudoModel(); |
| 1539 |
|
| 1540 |
CTempMemoryPoolContainerAllocationManager tempMemoryPoolConAllocMan(mContext.getMemoryPoolAllocationManager()); |
| 1541 |
CContext* tmpContext = CObjectParameterizingAllocator< CContextBase,CMemoryAllocationManager* >::allocateAndConstructAndParameterize(&tempMemoryPoolConAllocMan,&tempMemoryPoolConAllocMan); |
| 1542 |
CClassificationClassPseudoModelHash* pmModelHash = CObjectParameterizingAllocator< CClassificationClassPseudoModelHash,CContext* >::allocateAndConstructAndParameterize(&tempMemoryPoolConAllocMan,tmpContext); |
| 1543 |
CClassificationClassPseudoModelData* pmModelData = pmModelHash->getPseudoModelData(0,true); |
| 1544 |
|
| 1545 |
CClassificationClassPseudoModelConceptMap* pmModelConMap = pmModelData->getPseudoModelConceptMap(true); |
| 1546 |
CClassificationClassPseudoModelConceptData& pmModelConData = (*pmModelConMap)[CConceptTagComparer(concept)]; |
| 1547 |
pmModelConData.setDeterministic(true); |
| 1548 |
|
| 1549 |
optKPSetClassificationItem->addMemoryPools(tempMemoryPoolConAllocMan.takeMemoryPools()); |
| 1550 |
classPMModel->setPseudoModelHash(pmModelHash); |
| 1551 |
nextSatTestItem->setClassPseudoModelInitalized(true); |
| 1552 |
|
| 1553 |
|
| 1554 |
COptimizedKPSetClassPossibleSubsumptionMap* superPosSubsumMap = topClassConItem->getPossibleSubsumptionMap(false); |
| 1555 |
if (superPosSubsumMap && !nextSatTestItem->isPossibleSubsumptionMapInitialized()) { |
| 1556 |
COptimizedKPSetClassPossibleSubsumptionMap* subPosSubsumMap = nextSatTestItem->getPossibleSubsumptionMap(true); |
| 1557 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator it = superPosSubsumMap->constBegin(), itEnd = superPosSubsumMap->constEnd(); it != itEnd; ++it) { |
| 1558 |
CConcept* con = it.key().getConcept(); |
| 1559 |
COptimizedKPSetClassPossibleSubsumptionData* data = it.value(); |
| 1560 |
if (data->isSubsumptionUnknown() && !nextSatTestItem->hasSubsumerConceptItem(data->getClassItem()) && nextSatTestItem != data->getClassItem()) { |
| 1561 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = new COptimizedKPSetClassPossibleSubsumptionData(data->getClassItem()); |
| 1562 |
subPosSubsumMap->insert(CConceptTagComparer(con),possSubsumData); |
| 1563 |
incRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,subPosSubsumMap); |
| 1564 |
} |
| 1565 |
} |
| 1566 |
} |
| 1567 |
nextSatTestItem->setPossibleSubsumptionMapInitialized(true); |
| 1568 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1569 |
} |
| 1570 |
} |
| 1571 |
} |
| 1572 |
if (satFlag && isSatisfiableFlag) { |
| 1573 |
*isSatisfiableFlag = true; |
| 1574 |
} |
| 1575 |
return testComplete; |
| 1576 |
} |
| 1577 |
|
| 1578 |
|
| 1579 |
void COptimizedKPSetClassSubsumptionClassifierThread::incRemainingPossibleSubsumptionTestingCount(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetClassPossibleSubsumptionMap* posSubsumMap) { |
| 1580 |
optKPSetClassificationItem->incPossibleSubsumerCount(); |
| 1581 |
optKPSetClassificationItem->incRemainingPossibleSubsumptionTestsCount(); |
| 1582 |
posSubsumMap->incRemainingPossibleSubsumptionCount(); |
| 1583 |
++totalToSubsumTestCount; |
| 1584 |
} |
| 1585 |
|
| 1586 |
|
| 1587 |
void COptimizedKPSetClassSubsumptionClassifierThread::decRemainingPossibleSubsumptionTestingCount(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetClassPossibleSubsumptionMap* posSubsumMap, bool subsumptionConfirmed) { |
| 1588 |
if (subsumptionConfirmed) { |
| 1589 |
optKPSetClassificationItem->incTruePossibleSubsumerCount(); |
| 1590 |
} else { |
| 1591 |
optKPSetClassificationItem->incFalsePossibleSubsumerCount(); |
| 1592 |
} |
| 1593 |
optKPSetClassificationItem->decRemainingPossibleSubsumptionTestsCount(); |
| 1594 |
posSubsumMap->decRemainingPossibleSubsumptionCount(); |
| 1595 |
++subsumTestedCount; |
| 1596 |
} |
| 1597 |
|
| 1598 |
|
| 1599 |
bool COptimizedKPSetClassSubsumptionClassifierThread::fastPseudoModelSubsumptionClassPrecheckTest(COptimizedKPSetClassOntologyClassificationItem *optSubClassItem, COptimizedKPSetClassTestingItem* subsumedItem, COptimizedKPSetClassTestingItem* subsumerItem, bool* isSubsumptionFlag) { |
| 1600 |
if (subsumedItem->isClassPseudoModelInitalized() && subsumerItem->isClassPseudoModelInitalized()) { |
| 1601 |
CClassificationClassPseudoModel* subsumedPM = subsumedItem->getClassPseudoModel(); |
| 1602 |
CClassificationClassPseudoModel* subsumerPM = subsumerItem->getClassPseudoModel(); |
| 1603 |
|
| 1604 |
|
| 1605 |
CClassificationClassPseudoModelHash* subsumedPMHash = subsumedPM->getPseudoModelHash(); |
| 1606 |
CClassificationClassPseudoModelHash* subsumerPMHash = subsumerPM->getPseudoModelHash(); |
| 1607 |
|
| 1608 |
CClassificationClassPseudoModelData* subsumedPMData = subsumedPMHash->getPseudoModelData(0,false); |
| 1609 |
CClassificationClassPseudoModelData* subsumerPMData = subsumerPMHash->getPseudoModelData(0,false); |
| 1610 |
|
| 1611 |
if (subsumedPMData && subsumerPMData) { |
| 1612 |
bool isSubSumPossible = isPseudoModelSubsumerPossible(optSubClassItem,subsumedPMData,subsumedPMHash,subsumerPMData,subsumerPMHash); |
| 1613 |
if (!isSubSumPossible) { |
| 1614 |
if (isSubsumptionFlag) { |
| 1615 |
*isSubsumptionFlag = false; |
| 1616 |
} |
| 1617 |
return true; |
| 1618 |
} |
| 1619 |
} |
| 1620 |
return false; |
| 1621 |
} |
| 1622 |
return false; |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
bool COptimizedKPSetClassSubsumptionClassifierThread::isPseudoModelSubsumerPossible(COptimizedKPSetClassOntologyClassificationItem *optSubClassItem, CClassificationClassPseudoModelData* subsumedPMData, CClassificationClassPseudoModelHash* subsumedPMHash, CClassificationClassPseudoModelData* subsumerPMData, CClassificationClassPseudoModelHash* subsumerPMHash) { |
| 1627 |
if (subsumedPMData->hasValidConceptMap() && subsumerPMData->hasValidConceptMap()) { |
| 1628 |
CClassificationClassPseudoModelConceptMap* subsumedConMap = subsumedPMData->getPseudoModelConceptMap(false); |
| 1629 |
CClassificationClassPseudoModelConceptMap* subsumerConMap = subsumerPMData->getPseudoModelConceptMap(false); |
| 1630 |
if (subsumedConMap && subsumerConMap) { |
| 1631 |
CClassificationClassPseudoModelConceptMap::const_iterator it1 = subsumerConMap->constBegin(), it1End = subsumerConMap->constEnd(); |
| 1632 |
CClassificationClassPseudoModelConceptMap::const_iterator it2 = subsumedConMap->constBegin(), it2End = subsumedConMap->constEnd(); |
| 1633 |
while (it1 != it1End && it2 != it2End) { |
| 1634 |
CConcept* concept1 = it1.key().getConcept(); |
| 1635 |
CConcept* concept2 = it2.key().getConcept(); |
| 1636 |
cint64 con1Tag = concept1->getConceptTag(); |
| 1637 |
cint64 con2Tag = concept2->getConceptTag(); |
| 1638 |
if (con2Tag < con1Tag) { |
| 1639 |
++it2; |
| 1640 |
} else if (con2Tag == con1Tag) { |
| 1641 |
++it1; |
| 1642 |
++it2; |
| 1643 |
} else if (con2Tag > con1Tag) { |
| 1644 |
if (it1.value().isDeterministic()) { |
| 1645 |
// in the possible subsumed model is missing a concept, subsumption is not possible |
| 1646 |
return false; |
| 1647 |
} |
| 1648 |
++it1; |
| 1649 |
} |
| 1650 |
} |
| 1651 |
while (it1 != it1End) { |
| 1652 |
if (it1.value().isDeterministic()) { |
| 1653 |
return false; |
| 1654 |
} |
| 1655 |
++it1; |
| 1656 |
} |
| 1657 |
} |
| 1658 |
} |
| 1659 |
if (subsumedPMData->hasValidRoleMap() && subsumerPMData->hasValidRoleMap()) { |
| 1660 |
CClassificationClassPseudoModelRoleMap* subsumedRoleMap = subsumedPMData->getPseudoModelRoleMap(false); |
| 1661 |
CClassificationClassPseudoModelRoleMap* subsumerRoleMap = subsumerPMData->getPseudoModelRoleMap(false); |
| 1662 |
if (subsumedRoleMap && subsumerRoleMap) { |
| 1663 |
CClassificationClassPseudoModelRoleMap::const_iterator it1 = subsumerRoleMap->constBegin(), it1End = subsumerRoleMap->constEnd(); |
| 1664 |
CClassificationClassPseudoModelRoleMap::const_iterator it2 = subsumedRoleMap->constBegin(), it2End = subsumedRoleMap->constEnd(); |
| 1665 |
while (it1 != it1End && it2 != it2End) { |
| 1666 |
CRole* role1 = it1.key().getRole(); |
| 1667 |
CRole* role2 = it2.key().getRole(); |
| 1668 |
cint64 role1Tag = role1->getRoleTag(); |
| 1669 |
cint64 role2Tag = role2->getRoleTag(); |
| 1670 |
if (role2Tag < role1Tag) { |
| 1671 |
++it2; |
| 1672 |
} else if (role2Tag == role1Tag) { |
| 1673 |
const CClassificationClassPseudoModelRoleData& role1Data = it1.value(); |
| 1674 |
const CClassificationClassPseudoModelRoleData& role2Data = it2.value(); |
| 1675 |
if (!role1Data.isPossibleSubsumerOf(role2Data)) { |
| 1676 |
// some cardinalities are not satisfy the subsumption condition |
| 1677 |
return false; |
| 1678 |
} |
| 1679 |
cint64 succ1ID = role1Data.getSuccessorModelID(); |
| 1680 |
cint64 succ2ID = role2Data.getSuccessorModelID(); |
| 1681 |
CClassificationClassPseudoModelData* succ1ModelData = subsumerPMHash->getPseudoModelData(succ1ID,false); |
| 1682 |
CClassificationClassPseudoModelData* succ2ModelData = subsumedPMHash->getPseudoModelData(succ2ID,false); |
| 1683 |
if (succ1ModelData && succ2ModelData) { |
| 1684 |
if (!isPseudoModelSubsumerPossible(optSubClassItem,succ2ModelData,subsumedPMHash,succ1ModelData,subsumerPMHash)) { |
| 1685 |
return false; |
| 1686 |
} |
| 1687 |
} |
| 1688 |
++it1; |
| 1689 |
++it2; |
| 1690 |
} else if (role2Tag > role1Tag) { |
| 1691 |
if (it1.value().isDeterministic()) { |
| 1692 |
// in the possible subsumed model is missing a concept, subsumption is not possible |
| 1693 |
return false; |
| 1694 |
} |
| 1695 |
++it1; |
| 1696 |
} |
| 1697 |
} |
| 1698 |
while (it1 != it1End) { |
| 1699 |
if (it1.value().isDeterministic()) { |
| 1700 |
return false; |
| 1701 |
} |
| 1702 |
++it1; |
| 1703 |
} |
| 1704 |
|
| 1705 |
} |
| 1706 |
} |
| 1707 |
return true; |
| 1708 |
} |
| 1709 |
|
| 1710 |
|
| 1711 |
CSubsumptionClassifierThread *COptimizedKPSetClassSubsumptionClassifierThread::processCalculationJob(CSatisfiableCalculationJob* job, COntologyClassClassificationItem *ontClassItem, CClassClassificationComputationItem* workItem) { |
| 1712 |
CClassificationCalculationStatisticsCollection* statColl = nullptr; |
| 1713 |
if (ontClassItem->isCollectProcessStatisticsActivated()) { |
| 1714 |
statColl = ontClassItem->getCalculationStatisticsCollection(); |
| 1715 |
} |
| 1716 |
job->setCalclulationStatisticsCollector(statColl); |
| 1717 |
CTestCalculatedCallbackEvent *testResultCallback = new CTestCalculatedCallbackEvent(this,job,workItem,statColl); |
| 1718 |
job->setCalculationConfiguration(ontClassItem->getCalculationConfiguration()); |
| 1719 |
CSubsumptionClassifierThread::processCalculationJob(job,ontClassItem,testResultCallback,false); |
| 1720 |
return this; |
| 1721 |
} |
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
bool COptimizedKPSetClassSubsumptionClassifierThread::processToldClassificationMessage(COntologyClassificationItem *ontClassItem, CClassificationMessageData* messageDataLinker, CMemoryPool* memoryPools) { |
| 1726 |
COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetClassOntologyClassificationItem *)ontClassItem; |
| 1727 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1728 |
CClassificationMessageData* messageDataLinkerIt = messageDataLinker; |
| 1729 |
while (messageDataLinkerIt) { |
| 1730 |
CClassificationMessageData* messageData = messageDataLinkerIt; |
| 1731 |
if (messageData->getClassificationMessageDataType() == CClassificationMessageData::TELLCLASSSUBSUMPTION) { |
| 1732 |
++mStatProcesedSubsumMessCount; |
| 1733 |
CClassificationClassSubsumptionMessageData* subsumMessageData = (CClassificationClassSubsumptionMessageData*)messageData; |
| 1734 |
CConcept* subsumedConcept = subsumMessageData->getSubsumedConcept(); |
| 1735 |
CCLASSSUBSUMPTIONMESSAGELIST<CConcept*>* subsumerList = subsumMessageData->getClassSubsumerList(); |
| 1736 |
|
| 1737 |
COptimizedKPSetClassTestingItem* subsumedItem = nullptr; |
| 1738 |
subsumedItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(subsumedConcept); |
| 1739 |
|
| 1740 |
|
| 1741 |
//QString iriClassNameString = CIRIName::getRecentIRIName(subsumedItem->getTestingConcept()->getClassNameLinker()); |
| 1742 |
//if (iriClassNameString == "http://www.owllink.org/testsuite/galen#LowerLobeOfLeftLung") { |
| 1743 |
// bool bug = true; |
| 1744 |
//} |
| 1745 |
|
| 1746 |
|
| 1747 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = subsumedItem->getPossibleSubsumptionMap(false); |
| 1748 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1749 |
if (subsumerList) { |
| 1750 |
for (CCLASSSUBSUMPTIONMESSAGELIST<CConcept*>::const_iterator it = subsumerList->constBegin(), itEnd = subsumerList->constEnd(); it != itEnd; ++it) { |
| 1751 |
CConcept* subsumerConcept(*it); |
| 1752 |
COptimizedKPSetClassTestingItem* subsumerItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(subsumerConcept); |
| 1753 |
if (subsumedItem != subsumerItem) { |
| 1754 |
subsumedItem->addSubsumingConceptItem(subsumerItem); |
| 1755 |
if (possSubsumMap) { |
| 1756 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = possSubsumMap->value(subsumerConcept,nullptr); |
| 1757 |
if (possSubsumData) { |
| 1758 |
if (!possSubsumData->isSubsumptionConfirmed()) { |
| 1759 |
possSubsumData->setSubsumptionConfirmed(true); |
| 1760 |
|
| 1761 |
if (possSubsumData->isUpdateRequired()) { |
| 1762 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possSubsumData); |
| 1763 |
} |
| 1764 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1765 |
} |
| 1766 |
} |
| 1767 |
} |
| 1768 |
propagateDownSubsumption(optKPSetClassificationItem,subsumedItem,subsumerItem); |
| 1769 |
} |
| 1770 |
} |
| 1771 |
} |
| 1772 |
//if (!possSubsumMap || !possSubsumMap->hasRemainingPossibleSubsumptions()) { |
| 1773 |
subsumedItem->setResultSatisfiableDerivated(true); |
| 1774 |
//} |
| 1775 |
|
| 1776 |
} else if (messageData->getClassificationMessageDataType() == CClassificationMessageData::TELLCLASSINITIALIZEPOSSIBLESUBSUM) { |
| 1777 |
++mStatProcesedPossSubsumInitMessCount; |
| 1778 |
CClassificationInitializePossibleClassSubsumptionMessageData* possSubsumMessageData = (CClassificationInitializePossibleClassSubsumptionMessageData*)messageData; |
| 1779 |
CConcept* subsumedConcept = possSubsumMessageData->getSubsumedConcept(); |
| 1780 |
CCLASSPOSSIBLESUBSUMPTIONMESSAGELIST<CClassificationInitializePossibleClassSubsumptionData*>* possSubsumerList = possSubsumMessageData->getClassPossibleSubsumerList(); |
| 1781 |
bool eqConceptsNonCandidatePossSubsumers = possSubsumMessageData->hasEqConceptsNonCandidatePossSubsumers(); |
| 1782 |
CCLASSPOSSIBLESUBSUMPTIONMESSAGELIST<CConcept*>* eqConNonCandPossSubsumerList = possSubsumMessageData->getClassEqConceptNonCandidatePossibleSubsumerList(); |
| 1783 |
|
| 1784 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGB |
| 1785 |
QString iriClassNameString = CIRIName::getRecentIRIName(subsumedConcept->getClassNameLinker()); |
| 1786 |
possSubsumInitConList.append(iriClassNameString); |
| 1787 |
#endif |
| 1788 |
|
| 1789 |
|
| 1790 |
COptimizedKPSetClassTestingItem* subsumedItem = nullptr; |
| 1791 |
subsumedItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(subsumedConcept); |
| 1792 |
|
| 1793 |
QSet<CConcept*>* equivConNonCandidateSet = optKPSetClassificationItem->getEquivaltentConceptNonCandidateSet(); |
| 1794 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = subsumedItem->getPossibleSubsumptionMap(false); |
| 1795 |
if (equivConNonCandidateSet->isEmpty() && (!possSubsumerList || possSubsumerList->empty())) { |
| 1796 |
if (possSubsumMap) { |
| 1797 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 1798 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = it.value(); |
| 1799 |
if (possSubsumData->isSubsumptionUnknown()) { |
| 1800 |
possSubsumData->setSubsumptionInvalid(true); |
| 1801 |
if (possSubsumData->isUpdateRequired()) { |
| 1802 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possSubsumData); |
| 1803 |
} |
| 1804 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1805 |
} |
| 1806 |
} |
| 1807 |
} |
| 1808 |
} else { |
| 1809 |
if (!subsumedItem->isPossibleSubsumptionMapInitialized() || possSubsumMap) { |
| 1810 |
possSubsumMap = subsumedItem->getPossibleSubsumptionMap(true); |
| 1811 |
CBOXHASH<CConcept*,CConcept*>* equivConCandidateHash = optKPSetClassificationItem->getEquivalentConceptCandidateHash(); |
| 1812 |
if (possSubsumMap->isEmpty()) { |
| 1813 |
// initialize the possible subsumption map |
| 1814 |
if (possSubsumerList) { |
| 1815 |
for (CCLASSPOSSIBLESUBSUMPTIONMESSAGELIST<CClassificationInitializePossibleClassSubsumptionData*>::const_iterator it = possSubsumerList->constBegin(), itEnd = possSubsumerList->constEnd(); it != itEnd; ++it) { |
| 1816 |
CClassificationInitializePossibleClassSubsumptionData* possSubsumDataIt = *it; |
| 1817 |
if (possSubsumDataIt->isPossibleSubsumerValid()) { |
| 1818 |
CConcept* possSubsumConcept = possSubsumDataIt->getPossibleSubsumerConcept(); |
| 1819 |
if (possSubsumConcept->getOperatorCode() != CCEQ || !equivConCandidateHash->contains(possSubsumConcept)) { |
| 1820 |
COptimizedKPSetClassTestingItem* possSubsumItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(possSubsumConcept); |
| 1821 |
if (!subsumedItem->hasSubsumerConceptItem(possSubsumItem) && subsumedItem != possSubsumItem) { |
| 1822 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = new COptimizedKPSetClassPossibleSubsumptionData(possSubsumItem); |
| 1823 |
possSubsumMap->insert(CConceptTagComparer(possSubsumConcept),possSubsumData); |
| 1824 |
incRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap); |
| 1825 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1826 |
} |
| 1827 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1828 |
} |
| 1829 |
} |
| 1830 |
} |
| 1831 |
} |
| 1832 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1833 |
if (eqConceptsNonCandidatePossSubsumers) { |
| 1834 |
if (eqConNonCandPossSubsumerList) { |
| 1835 |
for (CCLASSPOSSIBLESUBSUMPTIONMESSAGELIST<CConcept*>::const_iterator it = eqConNonCandPossSubsumerList->constBegin(), itEnd = eqConNonCandPossSubsumerList->constEnd(); it != itEnd; ++it) { |
| 1836 |
CConcept* eqConcept = *it; |
| 1837 |
COptimizedKPSetClassTestingItem* possEqSubsumItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(eqConcept); |
| 1838 |
if (!subsumedItem->hasSubsumerConceptItem(possEqSubsumItem) && subsumedItem != possEqSubsumItem) { |
| 1839 |
if (!possSubsumMap->contains(CConceptTagComparer(eqConcept))) { |
| 1840 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = new COptimizedKPSetClassPossibleSubsumptionData(possEqSubsumItem); |
| 1841 |
possSubsumMap->insert(CConceptTagComparer(eqConcept),possSubsumData); |
| 1842 |
incRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap); |
| 1843 |
} |
| 1844 |
} |
| 1845 |
} |
| 1846 |
} |
| 1847 |
} else { |
| 1848 |
for (QSet<CConcept*>::const_iterator it = equivConNonCandidateSet->constBegin(), itEnd = equivConNonCandidateSet->constEnd(); it != itEnd; ++it) { |
| 1849 |
CConcept* eqConcept = *it; |
| 1850 |
COptimizedKPSetClassTestingItem* possEqSubsumItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(eqConcept); |
| 1851 |
if (!subsumedItem->hasSubsumerConceptItem(possEqSubsumItem) && subsumedItem != possEqSubsumItem) { |
| 1852 |
if (!possSubsumMap->contains(CConceptTagComparer(eqConcept))) { |
| 1853 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = new COptimizedKPSetClassPossibleSubsumptionData(possEqSubsumItem); |
| 1854 |
possSubsumMap->insert(CConceptTagComparer(eqConcept),possSubsumData); |
| 1855 |
incRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap); |
| 1856 |
} |
| 1857 |
} |
| 1858 |
} |
| 1859 |
} |
| 1860 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1861 |
|
| 1862 |
// prune ancestor items |
| 1863 |
QSet<COptimizedKPSetClassTestingItem*>* upPropSet = subsumedItem->getUpPropagationItemSet(); |
| 1864 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = upPropSet->constBegin(), itEnd = upPropSet->constEnd(); it != itEnd; ++it) { |
| 1865 |
COptimizedKPSetClassTestingItem* upPropItem = *it; |
| 1866 |
COptimizedKPSetClassPossibleSubsumptionMap* upPropItemPossSubsumMap = upPropItem->getPossibleSubsumptionMap(false); |
| 1867 |
if (upPropItemPossSubsumMap) { |
| 1868 |
COptimizedKPSetClassPossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); |
| 1869 |
COptimizedKPSetClassPossibleSubsumptionMap::const_iterator itUpPoss = upPropItemPossSubsumMap->constBegin(), itUpPossEnd = upPropItemPossSubsumMap->constEnd(); |
| 1870 |
while (itPoss != itPossEnd && itUpPoss != itUpPossEnd) { |
| 1871 |
CConcept* possCon = itPoss.key().getConcept(); |
| 1872 |
CConcept* possUpCon = itUpPoss.key().getConcept(); |
| 1873 |
if (possCon->getConceptTag() == possUpCon->getConceptTag()) { |
| 1874 |
++itPoss; |
| 1875 |
++itUpPoss; |
| 1876 |
} else if (possCon->getConceptTag() < possUpCon->getConceptTag()) { |
| 1877 |
++itPoss; |
| 1878 |
} else if (possCon->getConceptTag() > possUpCon->getConceptTag()) { |
| 1879 |
COptimizedKPSetClassPossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 1880 |
if (!subsumedItem->hasSubsumerConceptItem(upPossData->getClassItem()) && subsumedItem != upPossData->getClassItem()) { |
| 1881 |
if (!upPossData->isSubsumptionInvalided()) { |
| 1882 |
upPossData->setSubsumptionInvalid(true); |
| 1883 |
if (upPossData->isUpdateRequired()) { |
| 1884 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 1885 |
} |
| 1886 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1887 |
} |
| 1888 |
} |
| 1889 |
++itUpPoss; |
| 1890 |
} |
| 1891 |
} |
| 1892 |
while (itUpPoss != itUpPossEnd) { |
| 1893 |
COptimizedKPSetClassPossibleSubsumptionData* upPossData = itUpPoss.value(); |
| 1894 |
if (!subsumedItem->hasSubsumerConceptItem(upPossData->getClassItem()) && subsumedItem != upPossData->getClassItem()) { |
| 1895 |
if (!upPossData->isSubsumptionInvalided()) { |
| 1896 |
upPossData->setSubsumptionInvalid(true); |
| 1897 |
if (upPossData->isUpdateRequired()) { |
| 1898 |
prunePossibleSubsumptions(optKPSetClassificationItem,upPropItem,upPossData); |
| 1899 |
} |
| 1900 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1901 |
} |
| 1902 |
} |
| 1903 |
++itUpPoss; |
| 1904 |
} |
| 1905 |
} |
| 1906 |
} |
| 1907 |
|
| 1908 |
// prune descendant items |
| 1909 |
QSet<COptimizedKPSetClassTestingItem*>* downPropSet = subsumedItem->getDownPropagationItemSet(); |
| 1910 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = downPropSet->constBegin(), itEnd = downPropSet->constEnd(); it != itEnd; ++it) { |
| 1911 |
COptimizedKPSetClassTestingItem* downPropItem = *it; |
| 1912 |
COptimizedKPSetClassPossibleSubsumptionMap* downPropItemPossSubsumMap = downPropItem->getPossibleSubsumptionMap(false); |
| 1913 |
if (downPropItemPossSubsumMap) { |
| 1914 |
COptimizedKPSetClassPossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); |
| 1915 |
COptimizedKPSetClassPossibleSubsumptionMap::const_iterator itDownPoss = downPropItemPossSubsumMap->constBegin(), itDownPossEnd = downPropItemPossSubsumMap->constEnd(); |
| 1916 |
while (itPoss != itPossEnd && itDownPoss != itDownPossEnd) { |
| 1917 |
CConcept* possCon = itPoss.key().getConcept(); |
| 1918 |
CConcept* possDownCon = itDownPoss.key().getConcept(); |
| 1919 |
if (possCon->getConceptTag() == possDownCon->getConceptTag()) { |
| 1920 |
++itPoss; |
| 1921 |
++itDownPoss; |
| 1922 |
} else if (possDownCon->getConceptTag() < possCon->getConceptTag()) { |
| 1923 |
++itDownPoss; |
| 1924 |
} else if (possDownCon->getConceptTag() > possCon->getConceptTag()) { |
| 1925 |
COptimizedKPSetClassPossibleSubsumptionData* possData = itPoss.value(); |
| 1926 |
if (!downPropItem->hasSubsumerConceptItem(possData->getClassItem()) && downPropItem != possData->getClassItem()) { |
| 1927 |
if (!possData->isSubsumptionInvalided()) { |
| 1928 |
possData->setSubsumptionInvalid(true); |
| 1929 |
if (possData->isUpdateRequired()) { |
| 1930 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 1931 |
} |
| 1932 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1933 |
} |
| 1934 |
} |
| 1935 |
++itPoss; |
| 1936 |
} |
| 1937 |
} |
| 1938 |
while (itPoss != itPossEnd) { |
| 1939 |
COptimizedKPSetClassPossibleSubsumptionData* possData = itDownPoss.value(); |
| 1940 |
if (!downPropItem->hasSubsumerConceptItem(possData->getClassItem()) && downPropItem != possData->getClassItem()) { |
| 1941 |
if (!possData->isSubsumptionInvalided()) { |
| 1942 |
possData->setSubsumptionInvalid(true); |
| 1943 |
if (possData->isUpdateRequired()) { |
| 1944 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 1945 |
} |
| 1946 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1947 |
} |
| 1948 |
} |
| 1949 |
++itPoss; |
| 1950 |
} |
| 1951 |
} else if (downPropItem->isPossibleSubsumptionMapInitialized()) { |
| 1952 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); itPoss != itPossEnd; ++itPoss) { |
| 1953 |
COptimizedKPSetClassPossibleSubsumptionData* possData = itPoss.value(); |
| 1954 |
if (!downPropItem->hasSubsumerConceptItem(possData->getClassItem()) && downPropItem != possData->getClassItem()) { |
| 1955 |
if (!possData->isSubsumptionInvalided()) { |
| 1956 |
possData->setSubsumptionInvalid(true); |
| 1957 |
if (possData->isUpdateRequired()) { |
| 1958 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 1959 |
} |
| 1960 |
} |
| 1961 |
} |
| 1962 |
} |
| 1963 |
} |
| 1964 |
} |
| 1965 |
|
| 1966 |
} else { |
| 1967 |
// prune the possible subsumption map |
| 1968 |
COptimizedKPSetClassPossibleSubsumptionMap::const_iterator itPoss = possSubsumMap->constBegin(), itPossEnd = possSubsumMap->constEnd(); |
| 1969 |
if (possSubsumerList) { |
| 1970 |
CCLASSPOSSIBLESUBSUMPTIONMESSAGELIST<CClassificationInitializePossibleClassSubsumptionData*>::const_iterator itNew = possSubsumerList->constBegin(), itNewEnd = possSubsumerList->constEnd(); |
| 1971 |
while (itPoss != itPossEnd && itNew != itNewEnd) { |
| 1972 |
COptimizedKPSetClassPossibleSubsumptionData* possData = itPoss.value(); |
| 1973 |
CConcept* possCon = itPoss.key().getConcept(); |
| 1974 |
CClassificationInitializePossibleClassSubsumptionData* possNewSubsumDataIt = *itNew; |
| 1975 |
if (possNewSubsumDataIt->isPossibleSubsumerValid()) { |
| 1976 |
CConcept* newCon = possNewSubsumDataIt->getPossibleSubsumerConcept(); |
| 1977 |
if (possCon->getConceptTag() == newCon->getConceptTag()) { |
| 1978 |
++itPoss; |
| 1979 |
++itNew; |
| 1980 |
} else if (possCon->getConceptTag() < newCon->getConceptTag()) { |
| 1981 |
if (possCon->getOperatorCode() != CCEQ) { |
| 1982 |
if (!possData->isSubsumptionInvalided()) { |
| 1983 |
possData->setSubsumptionInvalid(true); |
| 1984 |
if (possData->isUpdateRequired()) { |
| 1985 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 1986 |
} |
| 1987 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 1988 |
} |
| 1989 |
} |
| 1990 |
++itPoss; |
| 1991 |
} else if (possCon->getConceptTag() > newCon->getConceptTag()) { |
| 1992 |
++itNew; |
| 1993 |
} |
| 1994 |
} else { |
| 1995 |
++itNew; |
| 1996 |
} |
| 1997 |
} |
| 1998 |
} |
| 1999 |
while (itPoss != itPossEnd) { |
| 2000 |
COptimizedKPSetClassPossibleSubsumptionData* possData = itPoss.value(); |
| 2001 |
CConcept* possCon = itPoss.key().getConcept(); |
| 2002 |
if (possCon->getOperatorCode() != CCEQ) { |
| 2003 |
if (!possData->isSubsumptionInvalided()) { |
| 2004 |
possData->setSubsumptionInvalid(true); |
| 2005 |
if (possData->isUpdateRequired()) { |
| 2006 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possData); |
| 2007 |
} |
| 2008 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 2009 |
} |
| 2010 |
} |
| 2011 |
++itPoss; |
| 2012 |
} |
| 2013 |
} |
| 2014 |
} |
| 2015 |
} |
| 2016 |
subsumedItem->setPossibleSubsumptionMapInitialized(true); |
| 2017 |
|
| 2018 |
|
| 2019 |
} else if (messageData->getClassificationMessageDataType() == CClassificationMessageData::TELLCLASSUPDATEPOSSIBLESUBSUM) { |
| 2020 |
++mStatProcesedPossSubsumUpdateMessCount; |
| 2021 |
CClassificationUpdatePossibleClassSubsumptionMessageData* possSubsumMessageData = (CClassificationUpdatePossibleClassSubsumptionMessageData*)messageData; |
| 2022 |
CConcept* subsumedConcept = possSubsumMessageData->getSubsumedConcept(); |
| 2023 |
|
| 2024 |
COptimizedKPSetClassTestingItem* subsumedItem = nullptr; |
| 2025 |
subsumedItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(subsumedConcept); |
| 2026 |
|
| 2027 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = subsumedItem->getPossibleSubsumptionMap(false); |
| 2028 |
if (possSubsumMap && !possSubsumMap->empty()) { |
| 2029 |
possSubsumMap = subsumedItem->getPossibleSubsumptionMap(true); |
| 2030 |
for (COptimizedKPSetClassPossibleSubsumptionMap::const_iterator it = possSubsumMap->constBegin(), itEnd = possSubsumMap->constEnd(); it != itEnd; ++it) { |
| 2031 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = it.value(); |
| 2032 |
if (possSubsumData->isUpdateRequired()) { |
| 2033 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possSubsumData); |
| 2034 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 2035 |
} |
| 2036 |
} |
| 2037 |
} |
| 2038 |
} else if (messageData->getClassificationMessageDataType() == CClassificationMessageData::TELLCLASSPSEUDOMODELIDENTIFIERS) { |
| 2039 |
++mStatProcesedPseudoModelMessCount; |
| 2040 |
CClassificationPseudoModelIdentifierMessageData* pmMessageData = (CClassificationPseudoModelIdentifierMessageData*)messageData; |
| 2041 |
CConcept* pmConcept = pmMessageData->getPseudoModelConcept(); |
| 2042 |
CMemoryPool* pmMemoryPools = pmMessageData->getPseudoModelMemoryPools(); |
| 2043 |
CClassificationClassPseudoModelHash* pmHash = pmMessageData->getPseudoModelHash(); |
| 2044 |
|
| 2045 |
COptimizedKPSetClassTestingItem* pmItem = nullptr; |
| 2046 |
pmItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(pmConcept); |
| 2047 |
pmItem->getClassPseudoModel()->setPseudoModelHash(pmHash); |
| 2048 |
pmItem->setClassPseudoModelInitalized(true); |
| 2049 |
|
| 2050 |
optKPSetClassificationItem->addMemoryPools(pmMemoryPools); |
| 2051 |
|
| 2052 |
} |
| 2053 |
messageDataLinkerIt = messageDataLinkerIt->getNext(); |
| 2054 |
} |
| 2055 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 2056 |
return true; |
| 2057 |
} |
| 2058 |
|
| 2059 |
|
| 2060 |
bool COptimizedKPSetClassSubsumptionClassifierThread::interpreteToldSubsumptionResult(COntologyClassClassificationItem *ontClassItem, const QList<QPair<CConcept *,CConcept *> > &subSumRelList, bool isSubSum) { |
| 2061 |
CConcept *lastConcept = nullptr; |
| 2062 |
COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetClassOntologyClassificationItem *)ontClassItem; |
| 2063 |
COptimizedKPSetClassTestingItem* subsumerItem = nullptr; |
| 2064 |
|
| 2065 |
for (QList<QPair<CConcept *,CConcept *> >::const_iterator it = subSumRelList.constBegin(), itEnd = subSumRelList.constEnd(); it != itEnd; ++it) { |
| 2066 |
CConcept *subsumerConcept = it->first; |
| 2067 |
if (lastConcept != subsumerConcept) { |
| 2068 |
lastConcept = subsumerConcept; |
| 2069 |
subsumerItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(subsumerConcept); |
| 2070 |
} |
| 2071 |
CConcept *subsumedConcept = it->second; |
| 2072 |
if (isSubSum) { |
| 2073 |
COptimizedKPSetClassTestingItem* subsumedItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(subsumedConcept); |
| 2074 |
subsumerItem->addSubsumingConceptItem(subsumedItem); |
| 2075 |
} |
| 2076 |
} |
| 2077 |
return true; |
| 2078 |
} |
| 2079 |
|
| 2080 |
|
| 2081 |
bool COptimizedKPSetClassSubsumptionClassifierThread::interpreteSubsumptionResult(COntologyClassClassificationItem *ontClassItem, CConcept *subsumedConcept, CConcept *subsumerConcept, bool isSubsumption) { |
| 2082 |
COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetClassOntologyClassificationItem *)ontClassItem; |
| 2083 |
|
| 2084 |
++mInterpretedSubsumptionCalculationCount; |
| 2085 |
CConcept* candidateConcept = subsumerConcept; |
| 2086 |
|
| 2087 |
if (subsumerConcept->getOperatorCode() == CCEQ) { |
| 2088 |
candidateConcept = optKPSetClassificationItem->getEquivalentConceptCandidateHash()->value(subsumerConcept); |
| 2089 |
if (!candidateConcept) { |
| 2090 |
candidateConcept = subsumerConcept; |
| 2091 |
} |
| 2092 |
} |
| 2093 |
|
| 2094 |
optKPSetClassificationItem->decRunningPossibleSubsumptionTestsCount(); |
| 2095 |
|
| 2096 |
COptimizedKPSetClassTestingItem* subsumedItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(subsumedConcept); |
| 2097 |
COptimizedKPSetClassTestingItem* subsumerItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(subsumerConcept); |
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
//QString iriClassNameString1 = CIRIName::getRecentIRIName(subsumedConcept->getClassNameLinker()); |
| 2102 |
//QString iriClassNameString2 = CIRIName::getRecentIRIName(subsumerConcept->getClassNameLinker()); |
| 2103 |
//if (iriClassNameString1 == "http://krono.act.uji.es/people/Ernesto/qimage-ontology/OntologyQimage.owl#Image_type" && iriClassNameString2 == "http://krono.act.uji.es/people/Ernesto/qimage-ontology/QimageUJIDescriptions.owl#Image_with_uji_office_door") { |
| 2104 |
// bool bug = false; |
| 2105 |
// if (bug) { |
| 2106 |
// calculateSubsumption(optKPSetClassificationItem, subsumedItem, subsumerItem, nullptr); |
| 2107 |
// return false; |
| 2108 |
// } |
| 2109 |
//} |
| 2110 |
|
| 2111 |
//if (iriClassNameString1 == "http://www.bootstrep.eu/ontology/GRO#BindingOfProteinToProteinBindingSiteOfDNA" && iriClassNameString2 == "http://www.bootstrep.eu/ontology/GRO#DNAProteinInteraction") { |
| 2112 |
// bool isSubsumptionFlag = false; |
| 2113 |
// if (fastPseudoModelSubsumptionClassPrecheckTest(optKPSetClassificationItem,subsumedItem,subsumerItem,&isSubsumptionFlag)) { |
| 2114 |
// if (isSubsumptionFlag != isSubsumption) { |
| 2115 |
// while (true) { |
| 2116 |
// fastPseudoModelSubsumptionClassPrecheckTest(optKPSetClassificationItem,subsumedItem,subsumerItem,&isSubsumptionFlag); |
| 2117 |
// } |
| 2118 |
// } |
| 2119 |
// } |
| 2120 |
//} |
| 2121 |
|
| 2122 |
|
| 2123 |
COptimizedKPSetClassTestingItem* topItem = optKPSetClassificationItem->getTopConceptSatisfiableTestItem(); |
| 2124 |
|
| 2125 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = subsumedItem->getPossibleSubsumptionMap(false); |
| 2126 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = nullptr; |
| 2127 |
if (possSubsumMap) { |
| 2128 |
possSubsumData = possSubsumMap->value(candidateConcept); |
| 2129 |
} |
| 2130 |
|
| 2131 |
if (isSubsumption) { |
| 2132 |
optKPSetClassificationItem->incCalculatedTruePossibleSubsumerCount(); |
| 2133 |
if (possSubsumData) { |
| 2134 |
possSubsumData->setSubsumptionConfirmed(true); |
| 2135 |
} |
| 2136 |
subsumedItem->addSubsumingConceptItem(subsumerItem); |
| 2137 |
subsumedItem->addUpPropagationItem(subsumerItem); |
| 2138 |
subsumerItem->addDownPropagationItem(subsumedItem); |
| 2139 |
propagateDownSubsumption(optKPSetClassificationItem,subsumedItem,subsumerItem); |
| 2140 |
} else { |
| 2141 |
|
| 2142 |
//if (CIRIName::getRecentIRIName(possSubsumData->getClassItem()->getTestingConcept()->getClassNameLinker()) == "http://www.loria.fr/~coulet/ontology/snpontology/version1.6/snpontology_full.owl#haplotype") { |
| 2143 |
// LOG(ERROR,getLogDomain(),logTr("Calcualted non subsumption with haplotype for item %1.").arg(CIRIName::getRecentIRIName(subsumedItem->getTestingConcept()->getClassNameLinker())),getLogObject()); |
| 2144 |
// bool bug = true; |
| 2145 |
//} |
| 2146 |
|
| 2147 |
|
| 2148 |
optKPSetClassificationItem->incCalculatedFalsePossibleSubsumerCount(); |
| 2149 |
if (possSubsumData) { |
| 2150 |
possSubsumData->setSubsumptionInvalid(true); |
| 2151 |
} |
| 2152 |
} |
| 2153 |
|
| 2154 |
if (possSubsumData && possSubsumData->isUpdateRequired()) { |
| 2155 |
prunePossibleSubsumptions(optKPSetClassificationItem,subsumedItem,possSubsumData); |
| 2156 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 2157 |
} |
| 2158 |
|
| 2159 |
|
| 2160 |
QList<COptimizedKPSetClassTestingItem*>* nextItemList = optKPSetClassificationItem->getNextPossibleSubsumptionTestingItemList(); |
| 2161 |
QSet<COptimizedKPSetClassTestingItem*>* currentItemSet = optKPSetClassificationItem->getCurrentPossibleSubsumptionTestingItemSet(); |
| 2162 |
if (mConfPossSubsumCalcOrderTopDown) { |
| 2163 |
if (currentItemSet->contains(subsumedItem)) { |
| 2164 |
currentItemSet->remove(subsumedItem); |
| 2165 |
if (possSubsumMap) { |
| 2166 |
if (possSubsumMap->hasRemainingPossibleSubsumptions()) { |
| 2167 |
nextItemList->prepend(subsumedItem); |
| 2168 |
} else { |
| 2169 |
QSet<COptimizedKPSetClassTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionClassTestingSet(); |
| 2170 |
remTestingSet->remove(subsumedItem); |
| 2171 |
} |
| 2172 |
} |
| 2173 |
} |
| 2174 |
} |
| 2175 |
if (mConfPossSubsumCalcOrderBottomUp) { |
| 2176 |
if (currentItemSet->contains(subsumerItem)) { |
| 2177 |
currentItemSet->remove(subsumerItem); |
| 2178 |
if (subsumerItem->hasRemainingPossibleSubsumedItems()) { |
| 2179 |
QSet<COptimizedKPSetClassTestingItem*>* remPossSubsumedItemSet = subsumerItem->getPossibleSubsumedSet(false); |
| 2180 |
QList<COptimizedKPSetClassTestingItem*>* remPossSubsumedItemList = subsumerItem->getPossibleSubsumedList(); |
| 2181 |
nextItemList->prepend(subsumerItem); |
| 2182 |
|
| 2183 |
QSet<COptimizedKPSetClassTestingItem*>* upPropSet = subsumedItem->getUpPropagationItemSet(); |
| 2184 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator itUp = upPropSet->constBegin(), itUpEnd = upPropSet->constEnd(); itUp != itUpEnd; ++itUp) { |
| 2185 |
COptimizedKPSetClassTestingItem* upItem = *itUp; |
| 2186 |
if (remPossSubsumedItemSet->contains(upItem)) { |
| 2187 |
remPossSubsumedItemList->prepend(upItem); |
| 2188 |
} |
| 2189 |
} |
| 2190 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectReferenced(optKPSetClassificationItem)); |
| 2191 |
|
| 2192 |
} else { |
| 2193 |
QSet<COptimizedKPSetClassTestingItem*>* remTestingSet = optKPSetClassificationItem->getRemainingPossibleSubsumptionClassTestingSet(); |
| 2194 |
remTestingSet->remove(subsumerItem); |
| 2195 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectReferenced(optKPSetClassificationItem)); |
| 2196 |
} |
| 2197 |
} |
| 2198 |
} |
| 2199 |
return true; |
| 2200 |
} |
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
bool COptimizedKPSetClassSubsumptionClassifierThread::prunePossibleSubsumptions(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetClassTestingItem* item, COptimizedKPSetClassPossibleSubsumptionData* possSubsumData) { |
| 2205 |
|
| 2206 |
//if (possSubsumData->isSubsumptionInvalided()) { |
| 2207 |
// //if (CIRIName::getRecentIRIName(item->getTestingConcept()->getClassNameLinker()) == "http://www.w3.org/2002/07/owl#Thing") { |
| 2208 |
// if (CIRIName::getRecentIRIName(possSubsumData->getClassItem()->getTestingConcept()->getClassNameLinker()) == "http://www.loria.fr/~coulet/ontology/snpontology/version1.6/snpontology_full.owl#haplotype") { |
| 2209 |
// LOG(ERROR,getLogDomain(),logTr("Pruned haplotype for item %1.").arg(CIRIName::getRecentIRIName(item->getTestingConcept()->getClassNameLinker())),getLogObject()); |
| 2210 |
// bool bug = true; |
| 2211 |
// } |
| 2212 |
// //} |
| 2213 |
//} |
| 2214 |
|
| 2215 |
if (possSubsumData->isUpdateRequired()) { |
| 2216 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 2217 |
possSubsumData->setSubsumptionUpdated(true); |
| 2218 |
decRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap,true); |
| 2219 |
if (possSubsumData->isSubsumptionConfirmed()) { |
| 2220 |
// is subsuming |
| 2221 |
COptimizedKPSetClassTestingItem* subsumerItem = possSubsumData->getClassItem(); |
| 2222 |
CConcept* subsumerConcept = subsumerItem->getTestingConcept(); |
| 2223 |
// establish the subsumption for all successor nodes |
| 2224 |
QSet<COptimizedKPSetClassTestingItem*>* downPropSet = item->getDownPropagationItemSet(); |
| 2225 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = downPropSet->constBegin(), itEnd = downPropSet->constEnd(); it != itEnd; ++it) { |
| 2226 |
COptimizedKPSetClassTestingItem* downPropItem = *it; |
| 2227 |
pruneDownSubsumption(optKPSetClassificationItem,downPropItem,subsumerConcept); |
| 2228 |
} |
| 2229 |
if (subsumerConcept->getOperatorCode() == CCEQ) { |
| 2230 |
CConcept* candidateConcept = optKPSetClassificationItem->getEquivalentConceptCandidateHash()->value(subsumerConcept); |
| 2231 |
if (candidateConcept) { |
| 2232 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = downPropSet->constBegin(), itEnd = downPropSet->constEnd(); it != itEnd; ++it) { |
| 2233 |
COptimizedKPSetClassTestingItem* downPropItem = *it; |
| 2234 |
pruneDownSubsumption(optKPSetClassificationItem,downPropItem,candidateConcept); |
| 2235 |
} |
| 2236 |
} |
| 2237 |
} |
| 2238 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 2239 |
return true; |
| 2240 |
} else { |
| 2241 |
// is not subsuming |
| 2242 |
COptimizedKPSetClassTestingItem* notSubsumerItem = possSubsumData->getClassItem(); |
| 2243 |
CConcept* notSubsumerConcept = notSubsumerItem->getTestingConcept(); |
| 2244 |
// establish the subsumption for all successor nodes |
| 2245 |
QSet<COptimizedKPSetClassTestingItem*>* upPropSet = item->getUpPropagationItemSet(); |
| 2246 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = upPropSet->constBegin(), itEnd = upPropSet->constEnd(); it != itEnd; ++it) { |
| 2247 |
COptimizedKPSetClassTestingItem* upPropItem = *it; |
| 2248 |
pruneUpNotSubsumption(optKPSetClassificationItem,upPropItem,notSubsumerConcept); |
| 2249 |
} |
| 2250 |
if (notSubsumerConcept->getOperatorCode() == CCEQ) { |
| 2251 |
CConcept* candidateConcept = optKPSetClassificationItem->getEquivalentConceptCandidateHash()->value(notSubsumerConcept); |
| 2252 |
if (candidateConcept) { |
| 2253 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = upPropSet->constBegin(), itEnd = upPropSet->constEnd(); it != itEnd; ++it) { |
| 2254 |
COptimizedKPSetClassTestingItem* upPropItem = *it; |
| 2255 |
pruneUpNotSubsumption(optKPSetClassificationItem,upPropItem,candidateConcept); |
| 2256 |
} |
| 2257 |
} |
| 2258 |
} |
| 2259 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(testDebugPossibleSubsumerCorrectCounted(optKPSetClassificationItem)); |
| 2260 |
return true; |
| 2261 |
|
| 2262 |
} |
| 2263 |
} |
| 2264 |
return false; |
| 2265 |
} |
| 2266 |
|
| 2267 |
|
| 2268 |
bool COptimizedKPSetClassSubsumptionClassifierThread::propagateDownSubsumption(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetClassTestingItem* item, COptimizedKPSetClassTestingItem* subsumerItem) { |
| 2269 |
bool propagated = false; |
| 2270 |
QSet<COptimizedKPSetClassTestingItem*>* downPropSet = item->getDownPropagationItemSet(); |
| 2271 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = downPropSet->constBegin(), itEnd = downPropSet->constEnd(); it != itEnd; ++it) { |
| 2272 |
COptimizedKPSetClassTestingItem* downPropItem = *it; |
| 2273 |
if (!downPropItem->hasSubsumerConceptItem(subsumerItem) && downPropItem != subsumerItem) { |
| 2274 |
downPropItem->addSubsumingConceptItem(subsumerItem); |
| 2275 |
propagateDownSubsumption(optKPSetClassificationItem,downPropItem,subsumerItem); |
| 2276 |
propagated = true; |
| 2277 |
} |
| 2278 |
} |
| 2279 |
return propagated; |
| 2280 |
} |
| 2281 |
|
| 2282 |
|
| 2283 |
bool COptimizedKPSetClassSubsumptionClassifierThread::pruneDownSubsumption(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetClassTestingItem* item, CConcept* subsumerConcept) { |
| 2284 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 2285 |
if (possSubsumMap) { |
| 2286 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = possSubsumMap->value(subsumerConcept); |
| 2287 |
if (possSubsumData && !possSubsumData->isSubsumptionConfirmed()) { |
| 2288 |
possSubsumData->setSubsumptionConfirmed(true); |
| 2289 |
possSubsumData->setSubsumptionUpdated(true); |
| 2290 |
decRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap,true); |
| 2291 |
|
| 2292 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 2293 |
if (ontClassStat) { |
| 2294 |
ontClassStat->incDerivatedTestedSubsumptionCount(1); |
| 2295 |
} |
| 2296 |
|
| 2297 |
QSet<COptimizedKPSetClassTestingItem*>* downPropSet = item->getDownPropagationItemSet(); |
| 2298 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = downPropSet->constBegin(), itEnd = downPropSet->constEnd(); it != itEnd; ++it) { |
| 2299 |
COptimizedKPSetClassTestingItem* downPropItem = *it; |
| 2300 |
pruneDownSubsumption(optKPSetClassificationItem,downPropItem,subsumerConcept); |
| 2301 |
} |
| 2302 |
return true; |
| 2303 |
} |
| 2304 |
} |
| 2305 |
return false; |
| 2306 |
} |
| 2307 |
|
| 2308 |
|
| 2309 |
bool COptimizedKPSetClassSubsumptionClassifierThread::pruneUpNotSubsumption(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetClassTestingItem* item, CConcept* notSubsumerConcept) { |
| 2310 |
COptimizedKPSetClassPossibleSubsumptionMap* possSubsumMap = item->getPossibleSubsumptionMap(false); |
| 2311 |
if (possSubsumMap) { |
| 2312 |
COptimizedKPSetClassPossibleSubsumptionData* possSubsumData = possSubsumMap->value(notSubsumerConcept); |
| 2313 |
if (possSubsumData && !possSubsumData->isSubsumptionInvalided()) { |
| 2314 |
possSubsumData->setSubsumptionInvalid(true); |
| 2315 |
possSubsumData->setSubsumptionUpdated(true); |
| 2316 |
decRemainingPossibleSubsumptionTestingCount(optKPSetClassificationItem,possSubsumMap,false); |
| 2317 |
|
| 2318 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 2319 |
if (ontClassStat) { |
| 2320 |
ontClassStat->incPrunedTestedSubsumptionCount(1); |
| 2321 |
} |
| 2322 |
|
| 2323 |
QSet<COptimizedKPSetClassTestingItem*>* upPropSet = item->getUpPropagationItemSet(); |
| 2324 |
for (QSet<COptimizedKPSetClassTestingItem*>::const_iterator it = upPropSet->constBegin(), itEnd = upPropSet->constEnd(); it != itEnd; ++it) { |
| 2325 |
COptimizedKPSetClassTestingItem* upPropItem = *it; |
| 2326 |
pruneUpNotSubsumption(optKPSetClassificationItem,upPropItem,notSubsumerConcept); |
| 2327 |
} |
| 2328 |
return true; |
| 2329 |
} |
| 2330 |
} |
| 2331 |
return false; |
| 2332 |
} |
| 2333 |
|
| 2334 |
|
| 2335 |
bool COptimizedKPSetClassSubsumptionClassifierThread::interpreteSatisfiableResult(COntologyClassClassificationItem *ontClassItem, CConcept *satisfiableConcept, bool isSatis) { |
| 2336 |
COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetClassOntologyClassificationItem *)ontClassItem; |
| 2337 |
|
| 2338 |
CClassifierStatistics *ontClassStat = optKPSetClassificationItem->getClassifierStatistics(); |
| 2339 |
if (ontClassStat) { |
| 2340 |
ontClassStat->incToldSatisfiableCount(1); |
| 2341 |
} |
| 2342 |
|
| 2343 |
++satTestedCount; |
| 2344 |
|
| 2345 |
optKPSetClassificationItem->decRunningSatisfiableTestsCount(); |
| 2346 |
|
| 2347 |
COptimizedKPSetClassTestingItem* satTestedItem = optKPSetClassificationItem->getConceptSatisfiableTestItem(satisfiableConcept); |
| 2348 |
//if (CIRIName::getRecentIRIName(satisfiableConcept->getClassNameLinker()) == "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#WineFlavor" && !isSatis || unsatComputed) { |
| 2349 |
// bool bug = true; |
| 2350 |
// unsatComputed = true; |
| 2351 |
|
| 2352 |
// if (!isSatis) { |
| 2353 |
// unsatCount++; |
| 2354 |
// } else { |
| 2355 |
// satCount++; |
| 2356 |
// } |
| 2357 |
|
| 2358 |
// calculateSatisfiable(optKPSetClassificationItem,satTestedItem); |
| 2359 |
// return false; |
| 2360 |
//} |
| 2361 |
|
| 2362 |
|
| 2363 |
satTestedItem->setSatisfiableTested(true); |
| 2364 |
satTestedItem->setSatisfiableTestedResult(isSatis); |
| 2365 |
|
| 2366 |
COptimizedKPSetClassTestingItem* topItem = optKPSetClassificationItem->getTopConceptSatisfiableTestItem(); |
| 2367 |
|
| 2368 |
if (isSatis) { |
| 2369 |
// update processing lists |
| 2370 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGB |
| 2371 |
QString iriClassNameString = CIRIName::getRecentIRIName(satisfiableConcept->getClassNameLinker()); |
| 2372 |
satTestedConList.append(iriClassNameString); |
| 2373 |
#endif |
| 2374 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGLOGOUTPUT |
| 2375 |
LOG(INFO,getLogDomain(),QString("[%1 / %2] Calculated: '%3' is satisfiable").arg(satTestedCount).arg(totalToSatTestClassCount).arg(iriClassNameString),this); |
| 2376 |
#endif |
| 2377 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION |
| 2378 |
statUpdateMutex.lock(); |
| 2379 |
statusString = QString("Interpreting, '%1' is satisfiable").arg(iriClassNameString); |
| 2380 |
statUpdateMutex.unlock(); |
| 2381 |
#endif |
| 2382 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCOUTOUTPUT |
| 2383 |
cout<<QString("Calculated: '%1' is satisfiable").arg(iriClassNameString).toLocal8Bit().data()<<endl<<endl; |
| 2384 |
#endif |
| 2385 |
|
| 2386 |
optKPSetClassificationItem->addSatisfiableConceptItem(satTestedItem); |
| 2387 |
|
| 2388 |
} else { |
| 2389 |
CTaxonomy *tax = optKPSetClassificationItem->getTaxonomy(); |
| 2390 |
if (topItem) { |
| 2391 |
tax->setConceptSatisfiable(satisfiableConcept,false); |
| 2392 |
} else { |
| 2393 |
tax->getBottomHierarchyNode()->addEquivalentConcept(satisfiableConcept); |
| 2394 |
tax->updateNodeEquivalences(tax->getBottomHierarchyNode()); |
| 2395 |
} |
| 2396 |
} |
| 2397 |
|
| 2398 |
QList<COptimizedKPSetClassTestingItem*>* nextItemList = optKPSetClassificationItem->getNextSatisfiableTestingItemList(); |
| 2399 |
QSet<COptimizedKPSetClassTestingItem*>* nextCandItemSet = optKPSetClassificationItem->getNextCandidateSatisfiableTestingItemSet(); |
| 2400 |
QSet<COptimizedKPSetClassTestingItem*>* remainingCandItemSet = optKPSetClassificationItem->getRemainingCandidateSatisfiableTestingItemSet(); |
| 2401 |
|
| 2402 |
|
| 2403 |
QList<COptimizedKPSetClassTestingItem*>* subSumItemList = satTestedItem->getSubsumingConceptItemList(); |
| 2404 |
QList<COptimizedKPSetClassTestingItem*>* succItemList = satTestedItem->getSuccessorItemList(); |
| 2405 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator it = succItemList->constBegin(), itEnd = succItemList->constEnd(); it != itEnd; ++it) { |
| 2406 |
COptimizedKPSetClassTestingItem* succItem = *it; |
| 2407 |
if (!isSatis) { |
| 2408 |
succItem->setResultUnsatisfiableDerivated(true); |
| 2409 |
} else { |
| 2410 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator itSubsum = subSumItemList->constBegin(), itSubsumEnd = subSumItemList->constEnd(); itSubsum != itSubsumEnd; ++itSubsum) { |
| 2411 |
COptimizedKPSetClassTestingItem* subusmerItem = *itSubsum; |
| 2412 |
if (succItem != subusmerItem) { |
| 2413 |
succItem->addSubsumingConceptItem(subusmerItem); |
| 2414 |
} |
| 2415 |
} |
| 2416 |
} |
| 2417 |
succItem->decUnprocessedPredecessorItems(); |
| 2418 |
if (succItem->hasOnlyProcessedPredecessorItems()) { |
| 2419 |
nextItemList->append(succItem); |
| 2420 |
} else { |
| 2421 |
nextCandItemSet->insert(succItem); |
| 2422 |
} |
| 2423 |
} |
| 2424 |
|
| 2425 |
return false; |
| 2426 |
} |
| 2427 |
|
| 2428 |
|
| 2429 |
bool COptimizedKPSetClassSubsumptionClassifierThread::interpreteTestResults(CTestCalculatedCallbackEvent *testResult) { |
| 2430 |
CSatisfiableCalculationJob *satCalcJob = testResult->getSatisfiableCalculationJob(); |
| 2431 |
bool testSat = testResult->getTestResultSatisfiable(); |
| 2432 |
CClassClassificationComputationItem *workItem = (CClassClassificationComputationItem*)testResult->getClassificationWorkItem(); |
| 2433 |
++mRecievedCallbackCount; |
| 2434 |
|
| 2435 |
|
| 2436 |
COntologyClassClassificationItem *ontClassItem = workOntItemHash.value(workItem); |
| 2437 |
if (ontClassItem) { |
| 2438 |
|
| 2439 |
QHash<CSatisfiableCalculationJob *, CClassClassificationComputationItem *> *workHash = ontClassItem->getWorkItemHash(); |
| 2440 |
|
| 2441 |
CTaxonomy *taxonomy = ontClassItem->getTaxonomy(); |
| 2442 |
|
| 2443 |
if (workItem) { |
| 2444 |
ontClassItem->decCurrentCalculatingCount(); |
| 2445 |
if (workItem->isTestValid()) { |
| 2446 |
|
| 2447 |
if (testResult->hasCalculationError()) { |
| 2448 |
LOG(ERROR,getLogDomain(),logTr("Error in computation, classification for ontology '%1' failed.").arg(ontClassItem->getOntology()->getTerminologyName()),getLogObject()); |
| 2449 |
ontClassItem->setTaxonomyConstructionFailed(); |
| 2450 |
|
| 2451 |
} else { |
| 2452 |
|
| 2453 |
if (workItem->isConceptSatisfiableTest()) { |
| 2454 |
interpreteSatisfiableResult(ontClassItem,workItem->getSatisfiableTestedConcept(),testSat); |
| 2455 |
} else if (workItem->isConceptSubsumptionTest()) { |
| 2456 |
interpreteSubsumptionResult(ontClassItem,workItem->getSubsumedTestedConcept(),workItem->getSubsumerTestedConcept(),!testSat); |
| 2457 |
} |
| 2458 |
} |
| 2459 |
} |
| 2460 |
QHash<CSatisfiableCalculationJob *, CClassClassificationComputationItem *>::iterator itWorkItem = workHash->find(satCalcJob); |
| 2461 |
while (itWorkItem != workHash->end()) { |
| 2462 |
if (itWorkItem.value() == workItem) { |
| 2463 |
workHash->erase(itWorkItem); |
| 2464 |
break; |
| 2465 |
} |
| 2466 |
++itWorkItem; |
| 2467 |
} |
| 2468 |
delete workItem; |
| 2469 |
delete satCalcJob; |
| 2470 |
} |
| 2471 |
workOntItemHash.remove(workItem); |
| 2472 |
|
| 2473 |
|
| 2474 |
CClassificationCalculationStatisticsCollection* statisticCollection = testResult->getUsedStatisticsCollection(); |
| 2475 |
if (statisticCollection) { |
| 2476 |
ontClassItem->reuseCalculationStatisticsCollection(statisticCollection); |
| 2477 |
} |
| 2478 |
|
| 2479 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGTAXONOMYCOUTOUTPUT |
| 2480 |
QString taxString = taxonomy->getConceptHierarchyString(); |
| 2481 |
cout<<taxString.toLocal8Bit().data()<<endl<<endl; |
| 2482 |
#endif |
| 2483 |
} |
| 2484 |
|
| 2485 |
|
| 2486 |
return true; |
| 2487 |
} |
| 2488 |
|
| 2489 |
|
| 2490 |
bool COptimizedKPSetClassSubsumptionClassifierThread::finishOntologyClassification(COntologyClassClassificationItem *ontClassItem) { |
| 2491 |
|
| 2492 |
if (!ontClassItem->isTaxonomyConstructed() && !ontClassItem->isTaxonomyConstructionFailed()) { |
| 2493 |
|
| 2494 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGLOGOUTPUT |
| 2495 |
LOG(INFO,getLogDomain(),QString("Building Class Taxonomy"),this); |
| 2496 |
#endif |
| 2497 |
CTaxonomy *taxonomy = ontClassItem->getTaxonomy(); |
| 2498 |
CConcreteOntology *ontology = ontClassItem->getOntology(); |
| 2499 |
LOG(INFO,getLogDomain(),logTr("Starting Transitive Reduction for Ontology '%1'.").arg(ontology->getTerminologyName()),getLogObject()); |
| 2500 |
|
| 2501 |
// build taxonomy |
| 2502 |
|
| 2503 |
COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem = (COptimizedKPSetClassOntologyClassificationItem *)ontClassItem; |
| 2504 |
QList<COptimizedKPSetClassTestingItem*>* satItemList = optKPSetClassificationItem->getSatisfiableConceptItemList(); |
| 2505 |
if (mConfWriteDebuggingData) { |
| 2506 |
createDebugKPSetString(optKPSetClassificationItem, "./Debugging/Classification/classkpsets-final.txt"); |
| 2507 |
} |
| 2508 |
OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCONSISTENCYTEST(createDebugKPSetString(optKPSetClassificationItem,"./Debugging/Classification/classkpsets-final.txt")); |
| 2509 |
|
| 2510 |
CTaxonomy *tax = optKPSetClassificationItem->getTaxonomy(); |
| 2511 |
|
| 2512 |
QList<COptimizedKPSetClassTestingItem*> itemList; |
| 2513 |
|
| 2514 |
COptimizedKPSetClassTestingItem* topItem = optKPSetClassificationItem->getTopConceptSatisfiableTestItem(); |
| 2515 |
CHierarchyNode* topHierNode = tax->getTopHierarchyNode(); |
| 2516 |
CHierarchyNode* bottomHierNode = tax->getBottomHierarchyNode(); |
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
cint64 topSubsumingItemCount = topItem->getSubsumingConceptItemCount(); |
| 2521 |
topItem->setSatisfiableConceptHierarchyNode(topHierNode); |
| 2522 |
if (topSubsumingItemCount) { |
| 2523 |
QList<COptimizedKPSetClassTestingItem*>* subsumingConceptItemList = topItem->sortSubsumingConceptItemList(); |
| 2524 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); subsumedIt != subsumedItEnd; ++subsumedIt) { |
| 2525 |
COptimizedKPSetClassTestingItem* subsumedConceptItem = *subsumedIt; |
| 2526 |
// mark as equivalent |
| 2527 |
subsumedConceptItem->setEquivalentItem(true); |
| 2528 |
topHierNode->addEquivalentConcept(subsumedConceptItem->getTestingConcept()); |
| 2529 |
tax->updateNodeEquivalences(topHierNode); |
| 2530 |
} |
| 2531 |
} |
| 2532 |
|
| 2533 |
LOG(INFO,getLogDomain(),logTr("Sorting classes for Ontology '%1'.").arg(ontology->getTerminologyName()),getLogObject()); |
| 2534 |
|
| 2535 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator it = satItemList->constBegin(), itEnd = satItemList->constEnd(); it != itEnd; ++it) { |
| 2536 |
COptimizedKPSetClassTestingItem* item = *it; |
| 2537 |
|
| 2538 |
//QString iriClassNameString = CIRIName::getRecentIRIName(item->getTestingConcept()->getClassNameLinker()); |
| 2539 |
//if (iriClassNameString == "http://ontology.dumontierlab.com/UnitRaisedToPower") { |
| 2540 |
// bool bug = true; |
| 2541 |
//} |
| 2542 |
|
| 2543 |
if (!item->isEquivalentItem() && item != topItem) { |
| 2544 |
CHierarchyNode* itemNode = tax->getHierarchyNode(item->getTestingConcept(),true); |
| 2545 |
item->setSatisfiableConceptHierarchyNode(itemNode); |
| 2546 |
cint64 itemSubsumingCount = item->getSubsumingConceptItemCount(); |
| 2547 |
itemList.append(item); |
| 2548 |
if (itemSubsumingCount > topSubsumingItemCount) { |
| 2549 |
QList<COptimizedKPSetClassTestingItem*>* subsumingConceptItemList = item->sortSubsumingConceptItemList(); |
| 2550 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); subsumedIt != subsumedItEnd; ++subsumedIt) { |
| 2551 |
COptimizedKPSetClassTestingItem* subsumedConceptItem = *subsumedIt; |
| 2552 |
cint64 subsumedItemSubsumingCount = subsumedConceptItem->getSubsumingConceptItemCount(); |
| 2553 |
if (subsumedItemSubsumingCount == itemSubsumingCount) { |
| 2554 |
// mark as equivalent |
| 2555 |
subsumedConceptItem->setEquivalentItem(true); |
| 2556 |
itemNode->addEquivalentConcept(subsumedConceptItem->getTestingConcept()); |
| 2557 |
tax->updateNodeEquivalences(itemNode); |
| 2558 |
} else { |
| 2559 |
break; |
| 2560 |
} |
| 2561 |
} |
| 2562 |
} |
| 2563 |
} |
| 2564 |
} |
| 2565 |
|
| 2566 |
LOG(INFO,getLogDomain(),logTr("Transitive Reduction for Ontology '%1'.").arg(ontology->getTerminologyName()),getLogObject()); |
| 2567 |
|
| 2568 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator it = itemList.constBegin(), itEnd = itemList.constEnd(); it != itEnd; ++it) { |
| 2569 |
COptimizedKPSetClassTestingItem* item = *it; |
| 2570 |
|
| 2571 |
//QString iriClassNameString = CIRIName::getRecentIRIName(item->getTestingConcept()->getClassNameLinker()); |
| 2572 |
//if (iriClassNameString == "http://usefulinc.com/ns/doap#Project") { |
| 2573 |
// bool bug = true; |
| 2574 |
//} |
| 2575 |
|
| 2576 |
if (!item->isEquivalentItem() && item != topItem) { |
| 2577 |
cint64 itemSubsumingCount = item->getSubsumingConceptItemCount(); |
| 2578 |
CHierarchyNode* itemHierNode = item->getSatisfiableConceptHierarchyNode(); |
| 2579 |
|
| 2580 |
QList<COptimizedKPSetClassTestingItem*>* subsumingConceptItemList = item->getSubsumingConceptItemList(); |
| 2581 |
QList<COptimizedKPSetClassTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); |
| 2582 |
|
| 2583 |
cint64 eqCount = 0; |
| 2584 |
cint64 remainingSubsumingCount = itemSubsumingCount; |
| 2585 |
// remove direct equivalences |
| 2586 |
while (subsumedIt != subsumedItEnd) { |
| 2587 |
COptimizedKPSetClassTestingItem* subsumedConceptItem = *subsumedIt; |
| 2588 |
cint64 subsumedItemSubsumingCount = subsumedConceptItem->getSubsumingConceptItemCount(); |
| 2589 |
if (itemSubsumingCount != subsumedItemSubsumingCount) { |
| 2590 |
break; |
| 2591 |
} else { |
| 2592 |
++eqCount; |
| 2593 |
++subsumedIt; |
| 2594 |
--remainingSubsumingCount; |
| 2595 |
} |
| 2596 |
} |
| 2597 |
|
| 2598 |
while (subsumedIt != subsumedItEnd && (*subsumedIt)->isEquivalentItem()) { |
| 2599 |
++subsumedIt; |
| 2600 |
} |
| 2601 |
|
| 2602 |
// find first parent |
| 2603 |
if (subsumedIt == subsumedItEnd) { |
| 2604 |
// no parent, use top as parent |
| 2605 |
itemHierNode->makeParent(topHierNode); |
| 2606 |
} else { |
| 2607 |
itemHierNode->addPredecessorNode(topHierNode); |
| 2608 |
QList<COptimizedKPSetClassTestingItem*> parentItemList; |
| 2609 |
while (subsumedIt != subsumedItEnd) { |
| 2610 |
COptimizedKPSetClassTestingItem* subsumedConceptItem = *subsumedIt; |
| 2611 |
if (!subsumedConceptItem->isEquivalentItem()) { |
| 2612 |
subsumedConceptItem->setPredecessorItem(true); |
| 2613 |
CHierarchyNode* subsumedHierNode = subsumedConceptItem->getSatisfiableConceptHierarchyNode(); |
| 2614 |
itemHierNode->makeParent(subsumedHierNode); |
| 2615 |
parentItemList.append(subsumedConceptItem); |
| 2616 |
remainingSubsumingCount -= subsumedConceptItem->getSubsumingConceptItemCount()+1; |
| 2617 |
++subsumedIt; |
| 2618 |
break; |
| 2619 |
} else { |
| 2620 |
++subsumedIt; |
| 2621 |
} |
| 2622 |
} |
| 2623 |
|
| 2624 |
bool searchForMoreParents = remainingSubsumingCount > 0; |
| 2625 |
while (subsumedIt != subsumedItEnd) { |
| 2626 |
COptimizedKPSetClassTestingItem* subsumedConceptItem = *subsumedIt; |
| 2627 |
if (!subsumedConceptItem->isEquivalentItem()) { |
| 2628 |
bool predOfOnePrevParent = false; |
| 2629 |
if (searchForMoreParents) { |
| 2630 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator parentIt = parentItemList.constBegin(), parentItEnd = parentItemList.constEnd(); parentIt != parentItEnd && !predOfOnePrevParent; ++parentIt) { |
| 2631 |
COptimizedKPSetClassTestingItem* parentItem = *parentIt; |
| 2632 |
if (parentItem->getSubsumingConceptItemSet()->contains(subsumedConceptItem)) { |
| 2633 |
predOfOnePrevParent = true; |
| 2634 |
} |
| 2635 |
} |
| 2636 |
} |
| 2637 |
subsumedConceptItem->setPredecessorItem(true); |
| 2638 |
CHierarchyNode* subsumedHierNode = subsumedConceptItem->getSatisfiableConceptHierarchyNode(); |
| 2639 |
if (!predOfOnePrevParent && searchForMoreParents) { |
| 2640 |
itemHierNode->makeParent(subsumedHierNode); |
| 2641 |
parentItemList.append(subsumedConceptItem); |
| 2642 |
} else { |
| 2643 |
itemHierNode->addPredecessorNode(subsumedHierNode); |
| 2644 |
} |
| 2645 |
} |
| 2646 |
++subsumedIt; |
| 2647 |
} |
| 2648 |
} |
| 2649 |
} |
| 2650 |
} |
| 2651 |
|
| 2652 |
for (QList<COptimizedKPSetClassTestingItem*>::const_iterator it = itemList.constBegin(), itEnd = itemList.constEnd(); it != itEnd; ++it) { |
| 2653 |
COptimizedKPSetClassTestingItem* item = *it; |
| 2654 |
if (!item->isPredecessorItem() && !item->isEquivalentItem()) { |
| 2655 |
CHierarchyNode* itemHierNode = item->getSatisfiableConceptHierarchyNode(); |
| 2656 |
bottomHierNode->makeParent(itemHierNode); |
| 2657 |
} |
| 2658 |
} |
| 2659 |
|
| 2660 |
LOG(INFO,getLogDomain(),logTr("Collect statistics for Ontology '%1'.").arg(ontology->getTerminologyName()),getLogObject()); |
| 2661 |
|
| 2662 |
|
| 2663 |
#ifdef OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION |
| 2664 |
statUpdateMutex.lock(); |
| 2665 |
statusString = QString("Finished ontology classification"); |
| 2666 |
statUpdateMutex.unlock(); |
| 2667 |
#endif |
| 2668 |
|
| 2669 |
|
| 2670 |
CClassification* classification = ontology->getClassification(); |
| 2671 |
if (classification) { |
| 2672 |
CClassConceptClassification* classConClassification = ontClassItem->getClassConceptClassification(); |
| 2673 |
addClassificationStatistics(ontClassItem,classConClassification); |
| 2674 |
if (ontClassItem->getIndividualDependenceTrackingCollector()) { |
| 2675 |
classConClassification->setDependentIndividualsTracking(ontClassItem->getIndividualDependenceTrackingCollector()->getExtendingIndividualDependenceTracking()); |
| 2676 |
} |
| 2677 |
classConClassification->setClassConceptTaxonomy(taxonomy); |
| 2678 |
CClassificationStatisticsCollectionStrings* classifStatCollStrings = ontClassItem->getClassificationStatisticsCollectionStrings(); |
| 2679 |
classConClassification->setClassificationStatistics(classifStatCollStrings); |
| 2680 |
classification->setClassConceptClassification(classConClassification); |
| 2681 |
} |
| 2682 |
ontology->setConceptTaxonomy(taxonomy); |
| 2683 |
|
| 2684 |
ontClassItem->setHasRemainingTests(false); |
| 2685 |
taxonomy->setTaxonomyComplete(true); |
| 2686 |
|
| 2687 |
--mClassificationCount; |
| 2688 |
LOG(INFO,getLogDomain(),logTr("Ontology '%1' classified.").arg(ontology->getTerminologyName()),getLogObject()); |
| 2689 |
LOG(INFO,getLogDomain(),logTr("Used %1 satisfiable tests, %2 pseudo model merged subsumption tests and %3 calculated subsumption tests.").arg(ontClassItem->getCalcedSatisfiableCount()).arg(ontClassItem->getClassifierStatistics()->getPseudoModelMergedTestedSubsumptionCount()).arg(ontClassItem->getClassifierStatistics()->getCalculatedTestedSubsumptionCount()),getLogObject()); |
| 2690 |
LOG(INFO,getLogDomain(),logTr("Confirmed %1 of %2 possible subsumer concepts.").arg(optKPSetClassificationItem->getTruePossibleSubsumerCount()).arg(optKPSetClassificationItem->getPossibleSubsumerCount()),getLogObject()); |
| 2691 |
LOG(INFO,getLogDomain(),logTr("Confirmed %1 and invalidated %2 possible subsumer concepts with calculation.").arg(optKPSetClassificationItem->getCalculatedTruePossibleSubsumerCount()).arg(optKPSetClassificationItem->getFalsePossibleSubsumerCount()),getLogObject()); |
| 2692 |
} |
| 2693 |
ontClassItem->submitTaxonomyConstructed(); |
| 2694 |
ontClassItem->doClassifiedCallback(); |
| 2695 |
return true; |
| 2696 |
} |
| 2697 |
|
| 2698 |
|
| 2699 |
bool COptimizedKPSetClassSubsumptionClassifierThread::addClassificationStatistics(COntologyClassClassificationItem *ontClassItem, CClassConceptClassification* classConClassification) { |
| 2700 |
CClassificationStatisticsCollectionStrings* classifStatCollStrings = ontClassItem->getClassificationStatisticsCollectionStrings(); |
| 2701 |
CClassifierStatistics* classifierStats = ontClassItem->getClassifierStatistics(); |
| 2702 |
classifStatCollStrings->addProcessingStatistics("class-classification-total-satisfiable-test-count",classifierStats->getTotalSatisfiableCount()); |
| 2703 |
classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-tested-count",classifierStats->getTestedSatisfiableCount()); |
| 2704 |
classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-pseudo-model-merged-tested-count",classifierStats->getPseudoModelMergedTestedSatisfiableCount()); |
| 2705 |
classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-derivation-tested-count",classifierStats->getDerivatedTestedSatisfiableCount()); |
| 2706 |
classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-calculated-tested-count",classifierStats->getCalculatedTestedSatisfiableCount()); |
| 2707 |
classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-pruned-tested-count",classifierStats->getPrunedTestedSatisfiableCount()); |
| 2708 |
classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-told-tested-count",classifierStats->getToldSatisfiableCount()-classifierStats->getCalculatedTestedSatisfiableCount()); |
| 2709 |
classifStatCollStrings->addProcessingStatistics("class-classification-total-subsumption-test-count",classifierStats->getTotalSatisfiableCount()*(classifierStats->getTotalSatisfiableCount()-1)); |
| 2710 |
classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-tested-count",classifierStats->getTestedSubsumptionCount()); |
| 2711 |
classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-pseudo-model-merged-tested-count",classifierStats->getPseudoModelMergedTestedSubsumptionCount()); |
| 2712 |
classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-subclass-tested-count",classifierStats->getSubclassTestedSubsumptionCount()); |
| 2713 |
classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-subclass-identifier-occur-tested-count",classifierStats->getSubclassIdentifierOccurTestedSubsumptionCount()); |
| 2714 |
classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-derivation-tested-count",classifierStats->getDerivatedTestedSubsumptionCount()); |
| 2715 |
classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-calculated-tested-count",classifierStats->getCalculatedTestedSubsumptionCount()); |
| 2716 |
classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-pruned-tested-count",classifierStats->getPrunedTestedSubsumptionCount()); |
| 2717 |
classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-told-tested-count",classifierStats->getToldSubsumptionCount()-classifierStats->getCalculatedTestedSubsumptionCount()); |
| 2718 |
classifStatCollStrings->addProcessingStatistics("class-classification-time",ontClassItem->getInitializationTime()->elapsed()); |
| 2719 |
|
| 2720 |
COntologyProcessingStatistics* ontProcStats = ontClassItem->getClassificationProcessingStep()->getProcessingStatistics(true); |
| 2721 |
ontProcStats->setProcessingCountStatisticValue("class-classification-time",ontClassItem->getInitializationTime()->elapsed()); |
| 2722 |
|
| 2723 |
COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem = dynamic_cast<COptimizedKPSetClassOntologyClassificationItem*>(ontClassItem); |
| 2724 |
if (optKPSetClassificationItem) { |
| 2725 |
addIndividualDependencyTrackingStatistics(optKPSetClassificationItem); |
| 2726 |
} |
| 2727 |
return true; |
| 2728 |
} |
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
COptimizedKPSetClassSubsumptionClassifierThread* COptimizedKPSetClassSubsumptionClassifierThread::addIndividualDependencyTrackingStatistics(COptimizedKPSetClassOntologyClassificationItem *optKPSetClassificationItem, const QString& classificationTypeString) { |
| 2733 |
if (optKPSetClassificationItem->getIndividualDependenceTrackingCollector()) { |
| 2734 |
CClassificationStatisticsCollectionStrings* classifStatCollStrings = optKPSetClassificationItem->getClassificationStatisticsCollectionStrings(); |
| 2735 |
CIndividualDependenceTracking* indiDepTack = optKPSetClassificationItem->getIndividualDependenceTrackingCollector()->getExtendingIndividualDependenceTracking(); |
| 2736 |
if (indiDepTack) { |
| 2737 |
classifStatCollStrings->addProcessingStatistics(QString("%1-tracked-node-dependency-size").arg(classificationTypeString),indiDepTack->getDependenceSize()); |
| 2738 |
classifStatCollStrings->addProcessingStatistics(QString("%1-tracked-node-dependency-count").arg(classificationTypeString),1); |
| 2739 |
} |
| 2740 |
} |
| 2741 |
return this; |
| 2742 |
} |
| 2743 |
}; // end namespace Classifier |
| 2744 |
|
| 2745 |
}; // end namespace Reasoner |
| 2746 |
|
| 2747 |
}; // end namespace Konclude |