| 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 "COptimizedClassExtractedSaturationSubsumptionClassifierThread.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Classifier { |
| 29 |
|
| 30 |
|
| 31 |
COptimizedClassExtractedSaturationSubsumptionClassifierThread::COptimizedClassExtractedSaturationSubsumptionClassifierThread(CReasonerManager *reasonerManager) |
| 32 |
: CSubsumptionClassifierThread(reasonerManager), CLogIdentifier("::Konclude::Reasoner::Kernel::Classifier::OptimizedClassExtractedSaturationSubsumptionClassifierThread",this) { |
| 33 |
mClassificationCount = 0; |
| 34 |
satTestedCount = 0; |
| 35 |
totalToTestCount = 0; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
COptimizedClassExtractedSaturationSubsumptionClassifierThread::~COptimizedClassExtractedSaturationSubsumptionClassifierThread() { |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
CTaxonomy *COptimizedClassExtractedSaturationSubsumptionClassifierThread::createEmptyTaxonomyForOntology(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 44 |
CTBox *tBox = ontology->getTBox(); |
| 45 |
CConceptVector *conVec = tBox->getConceptVector(); |
| 46 |
CConcept *topConcept = conVec->getData(1); |
| 47 |
CConcept *bottomConcept = conVec->getData(0); |
| 48 |
CPartialPruningTaxonomy *tax = new CPartialPruningTaxonomy(topConcept,bottomConcept); |
| 49 |
return tax->readConfig(config); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
void COptimizedClassExtractedSaturationSubsumptionClassifierThread::readCalculationConfig(CCalculationConfigurationExtension *config) { |
| 54 |
mTransitiveReductionAddAllPredecessors = CConfigDataReader::readConfigBoolean(config,"Konclude.Calculation.Classification.TransitiveReduction.AddAllPredecessors",true); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
CSubsumptionClassifierThread *COptimizedClassExtractedSaturationSubsumptionClassifierThread::scheduleOntologyClassification(CConcreteOntology *ontology, CClassificationCalculationSupport *classificationSupport, CConfigurationBase *config) { |
| 60 |
|
| 61 |
CTaxonomy *taxonomy = createEmptyTaxonomyForOntology(ontology,config); |
| 62 |
COptimizedClassExtractedSaturationOntologyClassificationItem *ontClassItem = new COptimizedClassExtractedSaturationOntologyClassificationItem(config,statistics); |
| 63 |
ontClassItem->initTaxonomyConcepts(ontology,taxonomy); |
| 64 |
ontItemList.append(ontClassItem); |
| 65 |
processingOntItemList.append(ontClassItem); |
| 66 |
ontItemHash.insert(ontology,ontClassItem); |
| 67 |
|
| 68 |
CCalculationConfigurationExtension* calcConfig = ontClassItem->getCalculationConfiguration(); |
| 69 |
|
| 70 |
readCalculationConfig(calcConfig); |
| 71 |
|
| 72 |
if (CConfigDataReader::readConfigBoolean(ontClassItem->getCalculationConfiguration(),"Konclude.Calculation.Classification.IndividualDependenceTracking",true)) { |
| 73 |
ontClassItem->setIndividualDependenceTrackingCollector(new CIndividualDependenceTrackingCollector()); |
| 74 |
} |
| 75 |
|
| 76 |
CPartialPruningTaxonomy *parTax = dynamic_cast<CPartialPruningTaxonomy *>(taxonomy); |
| 77 |
if (parTax) { |
| 78 |
COntologyClassClassificationItem *ontClassItem = (COntologyClassClassificationItem*)ontItemHash.value(ontology); |
| 79 |
parTax->createStatistics(ontClassItem->getClassifierStatistics()); |
| 80 |
} |
| 81 |
|
| 82 |
readSubsumptionFromPrecomputedSaturation(ontClassItem); |
| 83 |
|
| 84 |
if (satTestedCount == totalToTestCount) { |
| 85 |
satTestedCount = 0; |
| 86 |
totalToTestCount = 1; |
| 87 |
classStartTime.start(); |
| 88 |
} else { |
| 89 |
totalToTestCount += 1; |
| 90 |
} |
| 91 |
++mClassificationCount; |
| 92 |
return this; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
void COptimizedClassExtractedSaturationSubsumptionClassifierThread::readSubsumptionFromPrecomputedSaturation(COptimizedClassExtractedSaturationOntologyClassificationItem* ontClassItem) { |
| 99 |
CTBox *tBox = ontClassItem->getOntology()->getDataBoxes()->getTBox(); |
| 100 |
|
| 101 |
CConcreteOntology *onto = ontClassItem->getOntology(); |
| 102 |
CConcept *topConcept = onto->getDataBoxes()->getTopConcept(); |
| 103 |
CConcept *bottomConcept = onto->getDataBoxes()->getBottomConcept(); |
| 104 |
|
| 105 |
CConceptVector* conVec = tBox->getConceptVector(); |
| 106 |
|
| 107 |
LOG(INFO,getLogDomain(),logTr("Read subsumers from precomputed saturation for ontology '%1'.").arg(ontClassItem->getOntology()->getTerminologyName()),getLogObject()); |
| 108 |
|
| 109 |
|
| 110 |
QHash<CConcept*,COptimizedClassExtractedSaturationSatisfiableTestingItem*>* conceptSatItemHash = ontClassItem->getClassSatisfiableTestItemHash(); |
| 111 |
QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>* satTestItemContainer = ontClassItem->getClassSatisfiableTestItemList(); |
| 112 |
|
| 113 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* topItem = ontClassItem->getClassSatisfiableTestItem(topConcept,true); |
| 114 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* bottomItem = ontClassItem->getClassSatisfiableTestItem(bottomConcept,true); |
| 115 |
|
| 116 |
ontClassItem->initTopBottomSatisfiableTestingItems(topItem,bottomItem); |
| 117 |
CTaxonomy *tax = ontClassItem->getTaxonomy(); |
| 118 |
CHierarchyNode* bottomHierNode = tax->getBottomHierarchyNode(); |
| 119 |
|
| 120 |
CPrecomputedSaturationSubsumerExtractor precSatSubsumerExtractor(onto); |
| 121 |
|
| 122 |
QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*> extClassItemList; |
| 123 |
|
| 124 |
CBOXSET<CConcept*> *conceptHash = tBox->getActiveClassConceptSet(false); |
| 125 |
if (conceptHash) { |
| 126 |
cint64 conCount = conVec->getItemCount(); |
| 127 |
for (cint64 conIdx = 1; conIdx < conCount; ++conIdx) { |
| 128 |
CConcept* concept = conVec->getData(conIdx); |
| 129 |
|
| 130 |
if (concept) { |
| 131 |
if (concept->hasClassName() && conceptHash->contains(concept)) { |
| 132 |
bool unsatFlag = false; |
| 133 |
bool insuffFlag = false; |
| 134 |
bool incProcFlag = false; |
| 135 |
precSatSubsumerExtractor.getConceptFlags(concept,&unsatFlag,&insuffFlag,&incProcFlag); |
| 136 |
|
| 137 |
if (unsatFlag) { |
| 138 |
bottomHierNode->addEquivalentConcept(concept); |
| 139 |
} else { |
| 140 |
CConceptProcessData* conProcData = (CConceptProcessData*)concept->getConceptData(); |
| 141 |
CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking(); |
| 142 |
if (!conRefSatLinking) { |
| 143 |
conRefSatLinking = new CConceptSaturationReferenceLinkingData(); |
| 144 |
conProcData->setConceptReferenceLinking(conRefSatLinking); |
| 145 |
} |
| 146 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* classItem = ontClassItem->getClassSatisfiableTestItem(concept,true); |
| 147 |
conRefSatLinking->setClassifierReferenceLinkingData(classItem); |
| 148 |
|
| 149 |
extClassItemList.append(classItem); |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
for (QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>::const_iterator it = extClassItemList.constBegin(), itEnd = extClassItemList.constEnd(); it != itEnd; ++it) { |
| 158 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* classExtTestItem(*it); |
| 159 |
CConcept* concept = classExtTestItem->getTestingConcept(); |
| 160 |
cint64 subsumerCount = precSatSubsumerExtractor.getSubsumerCount(concept); |
| 161 |
classExtTestItem->setExtractionSubsumerCount(subsumerCount); |
| 162 |
} |
| 163 |
|
| 164 |
ontClassItem->decCurrentCalculatingCount(); |
| 165 |
++satTestedCount; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* getItemForConcept(CConcept* concept) { |
| 170 |
CConceptProcessData* conProcData = (CConceptProcessData*)concept->getConceptData(); |
| 171 |
if (conProcData) { |
| 172 |
CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking(); |
| 173 |
if (conRefSatLinking) { |
| 174 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* classItem = (COptimizedClassExtractedSaturationSatisfiableTestingItem*)conRefSatLinking->getClassifierReferenceLinkingData(); |
| 175 |
return classItem; |
| 176 |
} |
| 177 |
} |
| 178 |
return nullptr; |
| 179 |
} |
| 180 |
|
| 181 |
bool isDirectSubsumer(CConcept* concept, CConcept* subsumerConcept) { |
| 182 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* classItem = getItemForConcept(concept);; |
| 183 |
if (classItem) { |
| 184 |
cint64 conSubsumerCount = classItem->getExtractionSubsumerCount(); |
| 185 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* subsumerClassItem = getItemForConcept(subsumerConcept); |
| 186 |
if (subsumerClassItem) { |
| 187 |
cint64 subsumerConSubsumerCount = subsumerClassItem->getExtractionSubsumerCount(); |
| 188 |
if (subsumerConSubsumerCount == conSubsumerCount-1) { |
| 189 |
return true; |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
return false; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
QString COptimizedClassExtractedSaturationSubsumptionClassifierThread::getStatusString() { |
| 198 |
statUpdateMutex.lock(); |
| 199 |
QString string = statusString; |
| 200 |
string.detach(); |
| 201 |
statUpdateMutex.unlock(); |
| 202 |
return string; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
CClassificationProgress* COptimizedClassExtractedSaturationSubsumptionClassifierThread::getClassificationProgress() { |
| 208 |
if (satTestedCount != totalToTestCount) { |
| 209 |
cint64 testedClasses = satTestedCount; |
| 210 |
cint64 totalClasses = totalToTestCount; |
| 211 |
cint64 elapsedTime = classStartTime.elapsed(); |
| 212 |
double remainingMilliSeconds = 0.; |
| 213 |
double progessPercent = 0.; |
| 214 |
if (elapsedTime <= 0 && testedClasses > 0) { |
| 215 |
remainingMilliSeconds = 0.; |
| 216 |
} else { |
| 217 |
remainingMilliSeconds = ((double)elapsedTime / (double)satTestedCount) * (totalToTestCount-testedClasses); |
| 218 |
} |
| 219 |
if (totalClasses <= 0) { |
| 220 |
progessPercent = 0.; |
| 221 |
} else { |
| 222 |
progessPercent = ((double)testedClasses / (double)totalClasses) * 100.; |
| 223 |
} |
| 224 |
cint64 classificCount = mClassificationCount; |
| 225 |
mClassifyProgess.setClassificationCount(classificCount); |
| 226 |
mClassifyProgess.setProgessPercent(progessPercent); |
| 227 |
mClassifyProgess.setRemainingMilliSeconds(remainingMilliSeconds); |
| 228 |
mClassifyProgess.setTestedSatisfiable(testedClasses); |
| 229 |
mClassifyProgess.setTotalSatisfiable(totalClasses); |
| 230 |
} else { |
| 231 |
mClassifyProgess.setProgessPercent(0.); |
| 232 |
mClassifyProgess.setRemainingMilliSeconds(0.); |
| 233 |
mClassifyProgess.setTestedSatisfiable(satTestedCount); |
| 234 |
mClassifyProgess.setTotalSatisfiable(totalToTestCount); |
| 235 |
} |
| 236 |
return &mClassifyProgess; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
bool COptimizedClassExtractedSaturationSubsumptionClassifierThread::createNextSubsumtionTest() { |
| 242 |
|
| 243 |
|
| 244 |
COntologyClassificationItem *loopOntClassItem = 0; |
| 245 |
bool workTestCreated = false; |
| 246 |
while (!workTestCreated && !processingOntItemList.isEmpty()) { |
| 247 |
COntologyClassificationItem *ontClassItem = processingOntItemList.first(); |
| 248 |
|
| 249 |
if (ontClassItem == loopOntClassItem) { |
| 250 |
// don't run into infinite loop without doing something |
| 251 |
break; |
| 252 |
} |
| 253 |
|
| 254 |
COptimizedClassExtractedSaturationOntologyClassificationItem *optSubClassItem = (COptimizedClassExtractedSaturationOntologyClassificationItem *)ontClassItem; |
| 255 |
|
| 256 |
|
| 257 |
if (!workTestCreated) { |
| 258 |
if (optSubClassItem || optSubClassItem->isTaxonomyConstructionFailed()) { |
| 259 |
finishOntologyClassification(optSubClassItem); |
| 260 |
processingOntItemList.removeFirst(); |
| 261 |
} else { |
| 262 |
processingOntItemList.removeFirst(); |
| 263 |
processingOntItemList.append(ontClassItem); |
| 264 |
loopOntClassItem = ontClassItem; |
| 265 |
} |
| 266 |
} |
| 267 |
} |
| 268 |
return workTestCreated; |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
bool COptimizedClassExtractedSaturationSubsumptionClassifierThread::interpreteTestResults(CTestCalculatedCallbackEvent *testResult) { |
| 275 |
return false; |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
bool itemSortLessThan(const COptimizedClassExtractedSaturationSatisfiableTestingItem* item1, const COptimizedClassExtractedSaturationSatisfiableTestingItem* item2) { |
| 281 |
return item1->getExtractionSubsumerCount() < item2->getExtractionSubsumerCount(); |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
bool COptimizedClassExtractedSaturationSubsumptionClassifierThread::finishOntologyClassification(COntologyClassClassificationItem *ontClassItem) { |
| 287 |
|
| 288 |
if (!ontClassItem->isTaxonomyConstructed() && !ontClassItem->isTaxonomyConstructionFailed()) { |
| 289 |
CTaxonomy *taxonomy = ontClassItem->getTaxonomy(); |
| 290 |
CConcreteOntology *ontology = ontClassItem->getOntology(); |
| 291 |
|
| 292 |
LOG(INFO,getLogDomain(),logTr("Building class taxonomy for ontology '%1'.").arg(ontology->getTerminologyName()),getLogObject()); |
| 293 |
|
| 294 |
#ifdef OPTIMIZEDCLASSEXTRACTEDSATURATIONCLASSIFIERDEBUGLOGOUTPUT |
| 295 |
LOG(INFO,getLogDomain(),QString("Building Class Taxonomy"),this); |
| 296 |
#endif |
| 297 |
|
| 298 |
|
| 299 |
// build taxonomy |
| 300 |
|
| 301 |
COptimizedClassExtractedSaturationOntologyClassificationItem *optSubClassItem = (COptimizedClassExtractedSaturationOntologyClassificationItem *)ontClassItem; |
| 302 |
QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>* satItemList = optSubClassItem->getClassSatisfiableTestItemList(); |
| 303 |
|
| 304 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* bottomItem = optSubClassItem->getBottomConceptSatisfiableTestItem(); |
| 305 |
|
| 306 |
CTaxonomy *tax = optSubClassItem->getTaxonomy(); |
| 307 |
|
| 308 |
QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*> itemList; |
| 309 |
|
| 310 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* topItem = optSubClassItem->getTopConceptSatisfiableTestItem(); |
| 311 |
CHierarchyNode* topHierNode = tax->getTopHierarchyNode(); |
| 312 |
CHierarchyNode* bottomHierNode = tax->getBottomHierarchyNode(); |
| 313 |
|
| 314 |
CPrecomputedSaturationSubsumerExtractor precSatSubsumerExtractor(ontology); |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
cint64 topSubsumingItemCount = topItem->getExtractionSubsumerCount(); |
| 319 |
topItem->setSatisfiableConceptHierarchyNode(topHierNode); |
| 320 |
if (topSubsumingItemCount > 0) { |
| 321 |
precSatSubsumerExtractor.extractSubsumers(topItem->getTestingConcept(),topItem); |
| 322 |
QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>* subsumingConceptItemList = topItem->sortSubsumingConceptItemList(); |
| 323 |
for (QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); subsumedIt != subsumedItEnd; ++subsumedIt) { |
| 324 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* subsumedConceptItem = *subsumedIt; |
| 325 |
// mark as equivalent |
| 326 |
subsumedConceptItem->setEquivalentItem(true); |
| 327 |
topHierNode->addEquivalentConcept(subsumedConceptItem->getTestingConcept()); |
| 328 |
tax->updateNodeEquivalences(topHierNode); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
qSort(satItemList->begin(),satItemList->end(),itemSortLessThan); |
| 334 |
|
| 335 |
|
| 336 |
for (QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>::const_iterator it = satItemList->constBegin(), itEnd = satItemList->constEnd(); it != itEnd; ++it) { |
| 337 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* item = *it; |
| 338 |
if (!item->isEquivalentItem() && item != bottomItem && item != topItem) { |
| 339 |
CHierarchyNode* itemNode = tax->getHierarchyNode(item->getTestingConcept(),true); |
| 340 |
item->setSatisfiableConceptHierarchyNode(itemNode); |
| 341 |
cint64 itemSubsumingCount = item->getExtractionSubsumerCount(); |
| 342 |
itemList.append(item); |
| 343 |
if (itemSubsumingCount > topSubsumingItemCount) { |
| 344 |
|
| 345 |
CConcept* directSubsumerConcept = precSatSubsumerExtractor.getDirectSubsumerCount(item->getTestingConcept(),&isDirectSubsumer); |
| 346 |
bool requiresDetailedSubsumerSearch = true; |
| 347 |
if (directSubsumerConcept) { |
| 348 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* directSubsumerItem = getItemForConcept(directSubsumerConcept); |
| 349 |
if (!directSubsumerItem->isEquivalentItem()) { |
| 350 |
item->setDirectSubsumer(directSubsumerItem); |
| 351 |
requiresDetailedSubsumerSearch = false; |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
if (requiresDetailedSubsumerSearch) { |
| 356 |
precSatSubsumerExtractor.extractSubsumers(item->getTestingConcept(),item); |
| 357 |
QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>* subsumingConceptItemList = item->sortSubsumingConceptItemList(); |
| 358 |
for (QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); subsumedIt != subsumedItEnd; ++subsumedIt) { |
| 359 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* subsumedConceptItem = *subsumedIt; |
| 360 |
cint64 subsumedItemSubsumingCount = subsumedConceptItem->getExtractionSubsumerCount(); |
| 361 |
if (subsumedItemSubsumingCount == itemSubsumingCount) { |
| 362 |
// mark as equivalent |
| 363 |
subsumedConceptItem->setEquivalentItem(true); |
| 364 |
itemNode->addEquivalentConcept(subsumedConceptItem->getTestingConcept()); |
| 365 |
tax->updateNodeEquivalences(itemNode); |
| 366 |
} else { |
| 367 |
break; |
| 368 |
} |
| 369 |
} |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
for (QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>::const_iterator it = itemList.constBegin(), itEnd = itemList.constEnd(); it != itEnd; ++it) { |
| 377 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* item = *it; |
| 378 |
if (!item->isEquivalentItem() && item != topItem) { |
| 379 |
cint64 itemSubsumingCount = item->getExtractionSubsumerCount(); |
| 380 |
CHierarchyNode* itemHierNode = item->getSatisfiableConceptHierarchyNode(); |
| 381 |
|
| 382 |
if (item->hasDirectSubsumer()) { |
| 383 |
if (mTransitiveReductionAddAllPredecessors) { |
| 384 |
itemHierNode->addPredecessorNode(topHierNode); |
| 385 |
} |
| 386 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* directSubsumerItem = item->getDirectSubsumer(); |
| 387 |
directSubsumerItem->setPredecessorItem(true); |
| 388 |
CHierarchyNode* subsumedHierNode = directSubsumerItem->getSatisfiableConceptHierarchyNode(); |
| 389 |
itemHierNode->makeParent(subsumedHierNode); |
| 390 |
QSet<CHierarchyNode*>* predSet = subsumedHierNode->getPredecessorNodeSet(); |
| 391 |
if (mTransitiveReductionAddAllPredecessors) { |
| 392 |
for (QSet<CHierarchyNode*>::const_iterator itPred = predSet->constBegin(), itPredEnd = predSet->constEnd(); itPred != itPredEnd; ++itPred) { |
| 393 |
CHierarchyNode* predNode(*itPred); |
| 394 |
itemHierNode->addPredecessorNode(predNode); |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
} else { |
| 399 |
QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>* subsumingConceptItemList = item->getSubsumingConceptItemList(); |
| 400 |
QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); |
| 401 |
|
| 402 |
cint64 eqCount = 0; |
| 403 |
cint64 remainingSubsumingCount = itemSubsumingCount; |
| 404 |
// remove direct equivalences |
| 405 |
while (subsumedIt != subsumedItEnd) { |
| 406 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* subsumedConceptItem = *subsumedIt; |
| 407 |
cint64 subsumedItemSubsumingCount = subsumedConceptItem->getExtractionSubsumerCount(); |
| 408 |
if (subsumedItemSubsumingCount != itemSubsumingCount) { |
| 409 |
break; |
| 410 |
} else { |
| 411 |
++eqCount; |
| 412 |
++subsumedIt; |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
while (subsumedIt != subsumedItEnd && (*subsumedIt)->isEquivalentItem()) { |
| 417 |
++subsumedIt; |
| 418 |
} |
| 419 |
|
| 420 |
// find first parent |
| 421 |
if (subsumedIt == subsumedItEnd) { |
| 422 |
// no parent, use top as parent |
| 423 |
itemHierNode->makeParent(topHierNode); |
| 424 |
} else { |
| 425 |
while (subsumedIt != subsumedItEnd) { |
| 426 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* subsumedConceptItem = *subsumedIt; |
| 427 |
if (!subsumedConceptItem->isEquivalentItem()) { |
| 428 |
remainingSubsumingCount -= makeParentAddPredeccessors(item,subsumedConceptItem,remainingSubsumingCount,true); |
| 429 |
++subsumedIt; |
| 430 |
break; |
| 431 |
} else { |
| 432 |
++subsumedIt; |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
while (subsumedIt != subsumedItEnd && (remainingSubsumingCount > 0)) { |
| 438 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* subsumedConceptItem = *subsumedIt; |
| 439 |
if (!subsumedConceptItem->isEquivalentItem()) { |
| 440 |
|
| 441 |
remainingSubsumingCount -= makeParentAddPredeccessors(item,subsumedConceptItem,remainingSubsumingCount,false); |
| 442 |
} |
| 443 |
++subsumedIt; |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
//bool searchForMoreParents = remainingSubsumingCount > 0; |
| 448 |
//while (subsumedIt != subsumedItEnd) { |
| 449 |
// COptimizedClassExtractedSaturationSatisfiableTestingItem* subsumedConceptItem = *subsumedIt; |
| 450 |
// if (!subsumedConceptItem->isEquivalentItem()) { |
| 451 |
// bool predOfOnePrevParent = false; |
| 452 |
// if (searchForMoreParents) { |
| 453 |
// for (QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>::const_iterator parentIt = parentItemList.constBegin(), parentItEnd = parentItemList.constEnd(); parentIt != parentItEnd && !predOfOnePrevParent; ++parentIt) { |
| 454 |
// COptimizedClassExtractedSaturationSatisfiableTestingItem* parentItem = *parentIt; |
| 455 |
// if (precSatSubsumerExtractor.hasSubsumerConcept(parentItem->getTestingConcept(),subsumedConceptItem->getTestingConcept())) { |
| 456 |
// predOfOnePrevParent = true; |
| 457 |
// } |
| 458 |
// } |
| 459 |
// } |
| 460 |
// subsumedConceptItem->setPredecessorItem(true); |
| 461 |
// CHierarchyNode* subsumedHierNode = subsumedConceptItem->getSatisfiableConceptHierarchyNode(); |
| 462 |
// if (!predOfOnePrevParent && searchForMoreParents) { |
| 463 |
// itemHierNode->makeParent(subsumedHierNode); |
| 464 |
// parentItemList.append(subsumedConceptItem); |
| 465 |
// } else { |
| 466 |
// if (mTransitiveReductionAddAllPredecessors) { |
| 467 |
// itemHierNode->addPredecessorNode(subsumedHierNode); |
| 468 |
// } |
| 469 |
// } |
| 470 |
// } |
| 471 |
// ++subsumedIt; |
| 472 |
//} |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
for (QList<COptimizedClassExtractedSaturationSatisfiableTestingItem*>::const_iterator it = itemList.constBegin(), itEnd = itemList.constEnd(); it != itEnd; ++it) { |
| 480 |
COptimizedClassExtractedSaturationSatisfiableTestingItem* item = *it; |
| 481 |
if (!item->isPredecessorItem() && !item->isEquivalentItem()) { |
| 482 |
CHierarchyNode* itemHierNode = item->getSatisfiableConceptHierarchyNode(); |
| 483 |
bottomHierNode->makeParent(itemHierNode); |
| 484 |
} |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
#ifdef OPTIMIZEDCLASSEXTRACTEDSATURATIONCLASSIFIERDEBUGSTATUSDESCRIPTION |
| 489 |
statUpdateMutex.lock(); |
| 490 |
statusString = QString("Finished ontology classification"); |
| 491 |
statUpdateMutex.unlock(); |
| 492 |
#endif |
| 493 |
|
| 494 |
|
| 495 |
CClassification* classification = ontology->getClassification(); |
| 496 |
if (classification) { |
| 497 |
CClassConceptClassification* classConClassification = ontClassItem->getClassConceptClassification(); |
| 498 |
CClassificationStatisticsCollectionStrings* classifStatCollStrings = ontClassItem->getClassificationStatisticsCollectionStrings(); |
| 499 |
CClassifierStatistics* classifierStats = ontClassItem->getClassifierStatistics(); |
| 500 |
classifStatCollStrings->addProcessingStatistics("class-classification-total-satisfiable-test-count",classifierStats->getTotalSatisfiableCount()); |
| 501 |
classConClassification->setClassConceptTaxonomy(taxonomy); |
| 502 |
classConClassification->setClassificationStatistics(classifStatCollStrings); |
| 503 |
if (ontClassItem->getIndividualDependenceTrackingCollector()) { |
| 504 |
classConClassification->setDependentIndividualsTracking(ontClassItem->getIndividualDependenceTrackingCollector()->getExtendingIndividualDependenceTracking()); |
| 505 |
} |
| 506 |
classification->setClassConceptClassification(classConClassification); |
| 507 |
} |
| 508 |
ontology->setConceptTaxonomy(taxonomy); |
| 509 |
|
| 510 |
ontClassItem->setHasRemainingTests(false); |
| 511 |
|
| 512 |
taxonomy->setTaxonomyComplete(true); |
| 513 |
--mClassificationCount; |
| 514 |
LOG(INFO,getLogDomain(),logTr("Ontology '%1' classified.").arg(ontology->getTerminologyName()),getLogObject()); |
| 515 |
} |
| 516 |
ontClassItem->submitTaxonomyConstructed(); |
| 517 |
ontClassItem->doClassifiedCallback(); |
| 518 |
return true; |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
bool COptimizedClassExtractedSaturationSubsumptionClassifierThread::processCustomsEvents(QEvent::Type type, CCustomEvent *event) { |
| 526 |
if (CSubsumptionClassifierThread::processCustomsEvents(type,event)) { |
| 527 |
return true; |
| 528 |
} |
| 529 |
return false; |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
cint64 COptimizedClassExtractedSaturationSubsumptionClassifierThread::makeParentAddPredeccessors(COptimizedClassExtractedSaturationSatisfiableTestingItem* conceptItem, COptimizedClassExtractedSaturationSatisfiableTestingItem* subsumedConceptItem, cint64 remainingSubsumingResolvingCount, bool firstResolve) { |
| 535 |
CHierarchyNode* node = conceptItem->getSatisfiableConceptHierarchyNode(); |
| 536 |
CHierarchyNode* newParentNode = subsumedConceptItem->getSatisfiableConceptHierarchyNode(); |
| 537 |
cint64 resolvedExtSubsumerCount = 0; |
| 538 |
if (!node->hasPredecessorNode(newParentNode)) { |
| 539 |
if (firstResolve) { |
| 540 |
resolvedExtSubsumerCount = subsumedConceptItem->getExtractionSubsumerCount(); |
| 541 |
} else { |
| 542 |
resolvedExtSubsumerCount = newParentNode->getEquivalentConceptCount(); |
| 543 |
} |
| 544 |
node->addParentNode(newParentNode); |
| 545 |
newParentNode->addChildNode(node); |
| 546 |
if (mTransitiveReductionAddAllPredecessors || resolvedExtSubsumerCount != remainingSubsumingResolvingCount) { |
| 547 |
resolvedExtSubsumerCount = 0; |
| 548 |
QList<CHierarchyNode*> predAddList; |
| 549 |
predAddList.append(newParentNode); |
| 550 |
while (!predAddList.isEmpty()) { |
| 551 |
CHierarchyNode* nextPredNode = predAddList.takeFirst(); |
| 552 |
if (!node->hasPredecessorNode(nextPredNode)) { |
| 553 |
node->addPredecessorNode(nextPredNode); |
| 554 |
//nextPredNode->addSuccessorNode(node); |
| 555 |
resolvedExtSubsumerCount += nextPredNode->getEquivalentConceptCount(); |
| 556 |
QSet<CHierarchyNode*>* nextParentPredSet = nextPredNode->getParentNodeSet(); |
| 557 |
for (QSet<CHierarchyNode*>::const_iterator it = nextParentPredSet->constBegin(), itEnd = nextParentPredSet->constEnd(); it != itEnd; ++it) { |
| 558 |
CHierarchyNode* nextPredPredNode(*it); |
| 559 |
predAddList.append(nextPredPredNode); |
| 560 |
} |
| 561 |
} |
| 562 |
} |
| 563 |
} else { |
| 564 |
node->makePredecessor(newParentNode); |
| 565 |
} |
| 566 |
} |
| 567 |
return resolvedExtSubsumerCount; |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
}; // end namespace Classifier |
| 572 |
|
| 573 |
}; // end namespace Reasoner |
| 574 |
|
| 575 |
}; // end namespace Konclude |