Debian Codegraph @

Source/Reasoner/Classifier/COptimizedSubClassSubsumptionClassifierThread.cpp

raw
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 "COptimizedSubClassSubsumptionClassifierThread.h"
22
23 namespace Konclude {
24
25 namespace Reasoner {
26
27 namespace Classifier {
28
29
30 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGCOUTOUTPUT
31 #define OPTIMIZEDSUBCLASSCLASSIFIERDEBUGB
32 #endif
33 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGCOUTOUTPUT
34 #define OPTIMIZEDSUBCLASSCLASSIFIERDEBUGB
35 #endif
36 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGBOXDESCRIPTION
37 #define OPTIMIZEDSUBCLASSCLASSIFIERDEBUGB
38 #endif
39 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION
40 #define OPTIMIZEDSUBCLASSCLASSIFIERDEBUGB
41 #endif
42
43 COptimizedSubClassSubsumptionClassifierThread::COptimizedSubClassSubsumptionClassifierThread(CReasonerManager *reasonerManager)
44 : CSubsumptionClassifierThread(reasonerManager), CLogIdentifier("::Konclude::Reasoner::Kernel::Classifier::OptimizedSubClassSubsumptionClassifierThread",this) {
45 satTestedCount = 0;
46 totalToTestCount = 0;
47 mClassificationCount = 0;
48
49 mSatNodeExpCacheReader = nullptr;
50 mSatNodeExpCache = dynamic_cast<CSaturationNodeAssociatedExpansionCache*>(reasonerManager->getSaturationAssociationExpansionCache());
51 if (mSatNodeExpCache) {
52 mSatNodeExpCacheReader = mSatNodeExpCache->createCacheReader();
53 }
54
55 mStatFastSubClassCheckCacheTryCount = 0;
56 mStatFastSubClassCheckCacheSuccCount = 0;
57 }
58
59
60 COptimizedSubClassSubsumptionClassifierThread::~COptimizedSubClassSubsumptionClassifierThread() {
61 }
62
63
64 CTaxonomy *COptimizedSubClassSubsumptionClassifierThread::createEmptyTaxonomyForOntology(CConcreteOntology *ontology, CConfigurationBase *config) {
65 CTBox *tBox = ontology->getTBox();
66 CConceptVector *conVec = tBox->getConceptVector();
67 CConcept *topConcept = conVec->getData(1);
68 CConcept *bottomConcept = conVec->getData(0);
69 CPartialPruningTaxonomy *tax = new CPartialPruningTaxonomy(topConcept,bottomConcept);
70 return tax->readConfig(config);
71 }
72
73
74 void COptimizedSubClassSubsumptionClassifierThread::readCalculationConfig(CCalculationConfigurationExtension *config) {
75 if (config) {
76 bool configErrorFlag = false;
77 cint64 processorCount = 1;
78 QString processorCountString = CConfigDataReader::readConfigString(config,"Konclude.Calculation.ProcessorCount",QString(),&configErrorFlag);
79 if (!configErrorFlag) {
80 if (processorCountString == "AUTO") {
81 processorCount = CThread::idealThreadCount();
82 } else {
83 qint64 convertedWorkerCount = processorCountString.toInt(&configErrorFlag);
84 if (configErrorFlag) {
85 processorCount = convertedWorkerCount;
86 }
87 }
88 }
89
90 bool mulConfigErrorFlag = false;
91 cint64 multiplicator = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Classification.OptimizedSubClassSubsumptionClassifier.MultipliedUnitsParallelSatisfiableCalculationCount",1,&mulConfigErrorFlag);
92 confMaxTestParallelCount = processorCount*multiplicator;
93 bool maxConfigErrorFlag = false;
94 cint64 maxParallel = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Classification.OptimizedSubClassSubsumptionClassifier.MaximumParallelSatisfiableCalculationCount",1,&maxConfigErrorFlag);
95 if (!maxConfigErrorFlag) {
96 if (!mulConfigErrorFlag) {
97 confMaxTestParallelCount = qMin(confMaxTestParallelCount,maxParallel);
98 } else {
99 confMaxTestParallelCount = maxParallel;
100 }
101 }
102 } else {
103 confMaxTestParallelCount = 1;
104 }
105 }
106
107
108
109 CSubsumptionClassifierThread *COptimizedSubClassSubsumptionClassifierThread::scheduleOntologyClassification(CConcreteOntology *ontology, CClassificationCalculationSupport *classificationSupport, CConfigurationBase *config) {
110
111 CTaxonomy *taxonomy = createEmptyTaxonomyForOntology(ontology,config);
112 COptimizedSubClassOntologyClassificationItem *ontClassItem = new COptimizedSubClassOntologyClassificationItem(config,statistics);
113 ontClassItem->initTaxonomyConcepts(ontology,taxonomy);
114 ontItemList.append(ontClassItem);
115 processingOntItemList.append(ontClassItem);
116 ontItemHash.insert(ontology,ontClassItem);
117
118 readCalculationConfig(ontClassItem->getCalculationConfiguration());
119
120 if (CConfigDataReader::readConfigBoolean(ontClassItem->getCalculationConfiguration(),"Konclude.Calculation.Classification.IndividualDependenceTracking",true)) {
121 ontClassItem->setIndividualDependenceTrackingCollector(new CIndividualDependenceTrackingCollector());
122 }
123
124 CPartialPruningTaxonomy *parTax = dynamic_cast<CPartialPruningTaxonomy *>(taxonomy);
125 if (parTax) {
126 COntologyClassClassificationItem *ontClassItem = (COntologyClassClassificationItem*)ontItemHash.value(ontology);
127 parTax->createStatistics(ontClassItem->getClassifierStatistics());
128 }
129
130 createObviousSubsumptionSatisfiableTestingOrder(ontClassItem);
131
132 if (satTestedCount == totalToTestCount) {
133 satTestedCount = 0;
134 totalToTestCount = ontClassItem->getRemainingSatisfiableTestsCount();
135 classStartTime.start();
136 } else {
137 totalToTestCount += ontClassItem->getRemainingSatisfiableTestsCount();
138 }
139 ++mClassificationCount;
140 return this;
141 }
142
143
144
145
146 void COptimizedSubClassSubsumptionClassifierThread::createObviousSubsumptionSatisfiableTestingOrder(COptimizedSubClassOntologyClassificationItem* ontClassItem) {
147 CPrecomputation* precomputation = ontClassItem->getOntology()->getPrecomputation();
148 CSaturationData* saturationData = precomputation->getSaturationModelData();
149
150 bool subsumerSaturationExtraction = CConfigDataReader::readConfigBoolean(ontClassItem->getCalculationConfiguration(),"Konclude.Calculation.Classification.SaturationSubsumerExtraction",true);
151
152 if (saturationData && subsumerSaturationExtraction) {
153 createObviousSubsumptionSatisfiableTestingOrderFromSaturationData(ontClassItem);
154 } else {
155 createObviousSubsumptionSatisfiableTestingOrderFromBuildData(ontClassItem);
156 }
157 }
158
159
160
161
162 void COptimizedSubClassSubsumptionClassifierThread::createObviousSubsumptionSatisfiableTestingOrderFromSaturationData(COptimizedSubClassOntologyClassificationItem* ontClassItem) {
163
164 CTBox *tBox = ontClassItem->getOntology()->getDataBoxes()->getTBox();
165 CBOXHASH<CConcept*,CConcept*>* candidateEqConHash = tBox->getCandidateEquivalentConceptHash(false);
166 CBOXHASH<CConcept*,CConcept*>* eqConCandidateHash = tBox->getEquivalentConceptCandidateHash(false);
167 CBOXSET<CConcept*>* eqConNonCandidateSet = tBox->getEquivalentConceptNonCandidateSet(false);
168
169 CConcreteOntology *onto = ontClassItem->getOntology();
170 CConcept *topConcept = onto->getDataBoxes()->getTopConcept();
171 CConcept *bottomConcept = onto->getDataBoxes()->getBottomConcept();
172
173
174 QHash<CConcept*,COptimizedSubClassSatisfiableTestingItem*>* conceptSatItemHash = ontClassItem->getConceptSatisfiableTestItemHash();
175 QList<COptimizedSubClassSatisfiableTestingItem*>* satTestItemContainer = ontClassItem->getConceptSatisfiableTestItemContainer();
176
177 COptimizedSubClassSatisfiableTestingItem* topItem = ontClassItem->getConceptSatisfiableTestItem(topConcept,true);
178 COptimizedSubClassSatisfiableTestingItem* bottomItem = ontClassItem->getConceptSatisfiableTestItem(bottomConcept,true);
179
180 ontClassItem->initTopBottomSatisfiableTestingItems(topItem,bottomItem);
181
182 QList<COptimizedSubClassSatisfiableTestingItem*>* nextItemList = ontClassItem->getNextSatisfiableTestingItemList();
183 QSet<COptimizedSubClassSatisfiableTestingItem*>* nextCandItemSet = ontClassItem->getNextCandidateSatisfiableTestingItemSet();
184 QSet<COptimizedSubClassSatisfiableTestingItem*>* remainingCandItemSet = ontClassItem->getRemainingCandidateSatisfiableTestingItemSet();
185
186 if (topConcept->getOperandList()) {
187 // has not absorbed GCIs
188 nextItemList->append(topItem);
189 }
190 bool invalidatedConRefLinking = false;
191
192 QHash<CConcept*,CClassificationSatisfiableCalculationConceptReferenceLinking*>* conRefLinkDataHash = ontClassItem->getConceptReferenceLinkingDataHash();
193 QList<CConcept*> extClassConceptList;
194 CPrecomputedSaturationSubsumerExtractor* precSatSubsumerExtractor = ontClassItem->getPrecomputedSaturationSubsumerExtractor(true);
195
196 CBOXSET<CConcept*> *conceptHash = tBox->getActiveClassConceptSet(false);
197 if (conceptHash) {
198 for (CBOXSET<CConcept*>::const_iterator it = conceptHash->constBegin(), itEnd = conceptHash->constEnd(); it != itEnd; ++it) {
199 CConcept *concept = (*it);
200 if (concept && concept != topConcept && concept != bottomConcept || (concept == topConcept && topConcept->getOperandList())) {
201 COptimizedSubClassSatisfiableTestingItem* subsumerItem = ontClassItem->getConceptSatisfiableTestItem(concept,true);
202
203 CConceptProcessData* conProcData = (CConceptProcessData*)concept->getConceptData();
204 CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking();
205 if (!conRefSatLinking) {
206 conRefSatLinking = new CConceptSaturationReferenceLinkingData();
207 conProcData->setConceptReferenceLinking(conRefSatLinking);
208 }
209
210 conRefLinkDataHash->insert(concept,subsumerItem);
211
212 if (conRefSatLinking->getClassifierReferenceLinkingData() || invalidatedConRefLinking) {
213 conProcData->setInvalidatedReferenceLinking(true);
214 } else {
215 conRefSatLinking->setClassifierReferenceLinkingData(subsumerItem);
216 }
217 extClassConceptList.append(concept);
218 }
219 }
220 }
221
222
223 for (QList<CConcept*>::const_iterator it = extClassConceptList.constBegin(), itEnd = extClassConceptList.constEnd(); it != itEnd; ++it) {
224 CConcept* concept(*it);
225 CConceptProcessData* conProcData = (CConceptProcessData*)concept->getConceptData();
226 CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking();
227 COptimizedSubClassSatisfiableTestingItem* classItem = (COptimizedSubClassSatisfiableTestingItem*)conRefSatLinking->getClassifierReferenceLinkingData();
228
229 bool unsatisfiableFlag = false;
230 bool insufficientFlag = false;
231 bool incompleteProcessingFlag = false;
232
233 if (precSatSubsumerExtractor->getConceptFlags(concept,&unsatisfiableFlag,&insufficientFlag,&incompleteProcessingFlag)) {
234 if (!unsatisfiableFlag) {
235 bool possibleSubsumerFlag = false;
236 precSatSubsumerExtractor->extractSubsumers(concept,classItem,&possibleSubsumerFlag,ontClassItem->getIndividualDependenceTrackingCollector(),classItem);
237 cint64 foundSubsumerCount = classItem->getSubsumingConceptItemCount();
238 classItem->setUnprocessedPredecessorItems(foundSubsumerCount);
239 if (!insufficientFlag) {
240 classItem->setResultSatisfiableDerivated(true);
241 }
242 ontClassItem->incRemainingSatisfiableTestsCount();
243 remainingCandItemSet->insert(classItem);
244 if (foundSubsumerCount <= 0) {
245 nextItemList->append(classItem);
246 }
247 } else {
248 ontClassItem->incRemainingSatisfiableTestsCount();
249 classItem->setResultUnsatisfiableDerivated(true);
250 nextItemList->append(classItem);
251 }
252 }
253 }
254
255 }
256
257
258
259
260 void COptimizedSubClassSubsumptionClassifierThread::createObviousSubsumptionSatisfiableTestingOrderFromBuildData(COptimizedSubClassOntologyClassificationItem* ontClassItem) {
261
262 CTBox *tBox = ontClassItem->getOntology()->getDataBoxes()->getTBox();
263 CBOXHASH<CConcept*,CConcept*>* candidateEqConHash = tBox->getCandidateEquivalentConceptHash(false);
264 CBOXHASH<CConcept*,CConcept*>* eqConCandidateHash = tBox->getEquivalentConceptCandidateHash(false);
265 CBOXSET<CConcept*>* eqConNonCandidateSet = tBox->getEquivalentConceptNonCandidateSet(false);
266
267 CConcreteOntology *onto = ontClassItem->getOntology();
268 CConcept *topConcept = onto->getDataBoxes()->getTopConcept();
269 CConcept *bottomConcept = onto->getDataBoxes()->getBottomConcept();
270
271
272 QHash<CConcept*,COptimizedSubClassSatisfiableTestingItem*>* conceptSatItemHash = ontClassItem->getConceptSatisfiableTestItemHash();
273 QList<COptimizedSubClassSatisfiableTestingItem*>* satTestItemContainer = ontClassItem->getConceptSatisfiableTestItemContainer();
274
275 COptimizedSubClassSatisfiableTestingItem* topItem = ontClassItem->getConceptSatisfiableTestItem(topConcept,true);
276 COptimizedSubClassSatisfiableTestingItem* bottomItem = ontClassItem->getConceptSatisfiableTestItem(bottomConcept,true);
277
278 ontClassItem->initTopBottomSatisfiableTestingItems(topItem,bottomItem);
279
280 QList<COptimizedSubClassSatisfiableTestingItem*>* nextItemList = ontClassItem->getNextSatisfiableTestingItemList();
281 QSet<COptimizedSubClassSatisfiableTestingItem*>* nextCandItemSet = ontClassItem->getNextCandidateSatisfiableTestingItemSet();
282 QSet<COptimizedSubClassSatisfiableTestingItem*>* remainingCandItemSet = ontClassItem->getRemainingCandidateSatisfiableTestingItemSet();
283
284 CConcept* univConnNomValueConcept = tBox->getUniversalConnectionNominalValueConcept();
285
286 if (topConcept->getOperandList() || univConnNomValueConcept) {
287 // has not absorbed GCIs
288 nextItemList->append(topItem);
289 }
290
291 bool invalidatedConRefLinking = false;
292
293
294 QHash<CConcept*,CClassificationSatisfiableCalculationConceptReferenceLinking*>* conRefLinkDataHash = ontClassItem->getConceptReferenceLinkingDataHash();
295
296 CBOXSET<CConcept*> *conceptHash = tBox->getActiveClassConceptSet(false);
297 if (conceptHash) {
298 for (CBOXSET<CConcept*>::const_iterator it = conceptHash->constBegin(), itEnd = conceptHash->constEnd(); it != itEnd; ++it) {
299 CConcept *concept = (*it);
300 if (concept && concept != topConcept && concept != bottomConcept || (concept == topConcept && topConcept->getOperandList())) {
301 QSet<QPair<CConcept *,bool> > conSet;
302 QList<QPair<CConcept *,bool> > conList;
303 QSet<CConcept*> conSubsumSet;
304 conList.append(QPair<CConcept *,bool>(concept,false));
305 conSet.insert(QPair<CConcept *,bool>(concept,false));
306 while (!conList.isEmpty()) {
307 QPair<CConcept *,bool> conNegPair = conList.takeFirst();
308 CConcept *con = conNegPair.first;
309 bool neg = conNegPair.second;
310 qint64 conOpCode = con->getProcessingOperatorTag();
311 cint64 opCount = con->getOperandCount();
312 cint64 param = con->getParameter();
313 if (conOpCode == CCAND && (!neg || neg && opCount <= 1) || conOpCode == CCOR && (neg || !neg && opCount <= 1)) {
314 CSortedNegLinker<CConcept *> *opConIt = con->getOperandList();
315 while (opConIt) {
316 CConcept *opCon = opConIt->getData();
317 bool opNeg = opConIt->isNegated();
318 QPair<CConcept *,bool> opConNegPair(opCon,neg ^ opNeg);
319 if (opCon->hasClassName()) {
320 if (neg ^ opNeg) {
321 if (!conSet.contains(opConNegPair)) {
322 conSet.insert(opConNegPair);
323 conList.append(opConNegPair);
324 }
325 } else {
326 conSubsumSet.insert(opCon);
327 }
328 } else {
329 if (!conSet.contains(opConNegPair)) {
330 conSet.insert(opConNegPair);
331 conList.append(opConNegPair);
332 }
333 }
334 opConIt = opConIt->getNext();
335 }
336 } else if (!neg && (conOpCode == CCSOME || conOpCode == CCATLEAST && param >= 1) || neg && (conOpCode == CCALL || conOpCode == CCATMOST && param >= 2)) {
337 CRole* role = con->getRole();
338 CSortedNegLinker<CRole*>* superRoleIt = role->getIndirectSuperRoleList();
339 while (superRoleIt) {
340 CRole* superRole = superRoleIt->getData();
341 bool superRoleNeg = superRoleIt->isNegated();
342
343 CSortedNegLinker<CConcept*>* domainConIt = superRole->getDomainRangeConceptList(superRoleNeg);
344 while (domainConIt) {
345 CConcept *domCon = domainConIt->getData();
346 bool opDomNeg = domainConIt->isNegated();
347 QPair<CConcept *,bool> domConNegPair(domCon,neg ^ opDomNeg);
348 if (domCon->hasClassName()) {
349 if (neg ^ opDomNeg) {
350 if (!conSet.contains(domConNegPair)) {
351 conSet.insert(domConNegPair);
352 conList.append(domConNegPair);
353 }
354 } else {
355 conSubsumSet.insert(domCon);
356 }
357 } else {
358 if (!conSet.contains(domConNegPair)) {
359 conSet.insert(domConNegPair);
360 conList.append(domConNegPair);
361 }
362 }
363
364 domainConIt = domainConIt->getNext();
365 }
366
367 superRoleIt = superRoleIt->getNext();
368 }
369 } else if (!neg && (conOpCode == CCNOMINAL)) {
370 CIndividual* individual = con->getNominalIndividual();
371 CConceptAssertionLinker* assConLinkIt = individual->getAssertionConceptLinker();
372 while (assConLinkIt) {
373 CConcept* assCon = assConLinkIt->getData();
374 bool assConNeg = assConLinkIt->isNegated();
375
376 QPair<CConcept *,bool> assConNegPair(assCon,neg ^ assConNeg);
377 if (assCon->hasClassName()) {
378 if (neg ^ assConNeg) {
379 if (!conSet.contains(assConNegPair)) {
380 conSet.insert(assConNegPair);
381 conList.append(assConNegPair);
382 }
383 } else {
384 conSubsumSet.insert(assCon);
385 }
386 } else {
387 if (!conSet.contains(assConNegPair)) {
388 conSet.insert(assConNegPair);
389 conList.append(assConNegPair);
390 }
391 }
392
393 assConLinkIt = assConLinkIt->getNext();
394 }
395 }
396 }
397
398
399 //QString iriClassNameString = CIRIName::getRecentIRIName(concept->getClassNameLinker());
400 //if (iriClassNameString == "http://www.owllink.org/testsuite/galen#Haem") {
401 // bool bug = true;
402 //}
403
404
405 COptimizedSubClassSatisfiableTestingItem* subsumerItem = ontClassItem->getConceptSatisfiableTestItem(concept,true);
406
407 CConceptProcessData* conProcData = (CConceptProcessData*)concept->getConceptData();
408 CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking();
409 if (!conRefSatLinking) {
410 conRefSatLinking = new CConceptSaturationReferenceLinkingData();
411 conProcData->setConceptReferenceLinking(conRefSatLinking);
412 }
413
414 conRefLinkDataHash->insert(concept,subsumerItem);
415
416 if (conRefSatLinking->getClassifierReferenceLinkingData() || invalidatedConRefLinking) {
417 conProcData->setInvalidatedReferenceLinking(true);
418 } else {
419 conRefSatLinking->setClassifierReferenceLinkingData(subsumerItem);
420 }
421
422
423 bool foundSubsumingConcepts = false;
424 for (QSet<CConcept*>::const_iterator it = conSubsumSet.constBegin(), itEnd = conSubsumSet.constEnd(); it != itEnd; ++it) {
425 CConcept* subsumedConcept = *it;
426 COptimizedSubClassSatisfiableTestingItem* subsumedItem = ontClassItem->getConceptSatisfiableTestItem(subsumedConcept,true);
427 subsumedItem->addSuccessorSatisfiableTestItem(subsumerItem);
428 subsumerItem->incUnprocessedPredecessorItems();
429 foundSubsumingConcepts = true;
430 }
431
432 ontClassItem->incRemainingSatisfiableTestsCount();
433
434 remainingCandItemSet->insert(subsumerItem);
435 if (!foundSubsumingConcepts) {
436 nextItemList->append(subsumerItem);
437 }
438
439
440 }
441 }
442 }
443 }
444
445
446 QString COptimizedSubClassSubsumptionClassifierThread::getStatusString() {
447 statUpdateMutex.lock();
448 QString string = statusString;
449 string.detach();
450 statUpdateMutex.unlock();
451 return string;
452 }
453
454
455
456 CClassificationProgress* COptimizedSubClassSubsumptionClassifierThread::getClassificationProgress() {
457 if (satTestedCount != totalToTestCount) {
458 cint64 testedClasses = satTestedCount;
459 cint64 totalClasses = totalToTestCount;
460 cint64 elapsedTime = classStartTime.elapsed();
461 double remainingMilliSeconds = 0.;
462 double progessPercent = 0.;
463 if (elapsedTime <= 0 && testedClasses > 0) {
464 remainingMilliSeconds = 0.;
465 } else {
466 remainingMilliSeconds = ((double)elapsedTime / (double)satTestedCount) * (totalToTestCount-testedClasses);
467 }
468 if (totalClasses <= 0) {
469 progessPercent = 0.;
470 } else {
471 progessPercent = ((double)testedClasses / (double)totalClasses) * 100.;
472 }
473 cint64 classificCount = mClassificationCount;
474 mClassifyProgess.setClassificationCount(classificCount);
475 mClassifyProgess.setProgessPercent(progessPercent);
476 mClassifyProgess.setRemainingMilliSeconds(remainingMilliSeconds);
477 mClassifyProgess.setTestedSatisfiable(testedClasses);
478 mClassifyProgess.setTotalSatisfiable(totalClasses);
479 } else {
480 mClassifyProgess.setProgessPercent(0.);
481 mClassifyProgess.setRemainingMilliSeconds(0.);
482 mClassifyProgess.setTestedSatisfiable(satTestedCount);
483 mClassifyProgess.setTotalSatisfiable(totalToTestCount);
484 }
485 return &mClassifyProgess;
486 }
487
488
489
490 bool COptimizedSubClassSubsumptionClassifierThread::createNextSubsumtionTest() {
491
492
493 COntologyClassificationItem *loopOntClassItem = 0;
494 bool workTestCreated = false;
495 while (!workTestCreated && !processingOntItemList.isEmpty()) {
496 COntologyClassificationItem *ontClassItem = processingOntItemList.first();
497
498 if (ontClassItem == loopOntClassItem) {
499 // don't run into infinite loop without doing something
500 break;
501 }
502
503 COptimizedSubClassOntologyClassificationItem *optSubClassItem = (COptimizedSubClassOntologyClassificationItem *)ontClassItem;
504
505
506 while (!workTestCreated && optSubClassItem->hasRemainingSatisfiableTests() && !optSubClassItem->isTaxonomyConstructionFailed()) {
507 // get next satisfiable test
508
509 QList<COptimizedSubClassSatisfiableTestingItem*>* nextItemList = optSubClassItem->getNextSatisfiableTestingItemList();
510 QSet<COptimizedSubClassSatisfiableTestingItem*>* nextCandItemSet = optSubClassItem->getNextCandidateSatisfiableTestingItemSet();
511 QSet<COptimizedSubClassSatisfiableTestingItem*>* remainingCandItemSet = optSubClassItem->getRemainingCandidateSatisfiableTestingItemSet();
512
513
514 COptimizedSubClassSatisfiableTestingItem* nextSatTestItem = nullptr;
515 if (!nextItemList->isEmpty()) {
516 nextSatTestItem = nextItemList->takeFirst();
517 remainingCandItemSet->remove(nextSatTestItem);
518 nextCandItemSet->remove(nextSatTestItem);
519
520 } else if (!nextCandItemSet->isEmpty()) {
521 COptimizedSubClassSatisfiableTestingItem* minItem = nullptr;
522 cint64 minUnpPredCount = 0;
523 cint64 maxItCount = 100;
524 for (QSet<COptimizedSubClassSatisfiableTestingItem*>::const_iterator it = nextCandItemSet->constBegin(), itEnd = nextCandItemSet->constEnd(); it != itEnd && maxItCount > 0; ++it, --maxItCount) {
525 COptimizedSubClassSatisfiableTestingItem* item = (*it);
526 cint64 predCount = item->getUnprocessedPredecessorItemCount();
527 if (!minItem || minUnpPredCount < predCount) {
528 minUnpPredCount = predCount;
529 minItem = item;
530 }
531 }
532 nextSatTestItem = minItem;
533 remainingCandItemSet->remove(nextSatTestItem);
534 nextCandItemSet->remove(nextSatTestItem);
535
536 } else if (!remainingCandItemSet->isEmpty()) {
537 COptimizedSubClassSatisfiableTestingItem* minItem = nullptr;
538 //cint64 minUnpPredCount = 0;
539 //for (QSet<COptimizedSubClassSatisfiableTestingItem*>::const_iterator it = remainingCandItemSet->constBegin(), itEnd = remainingCandItemSet->constEnd(); it != itEnd; ++it) {
540 // COptimizedSubClassSatisfiableTestingItem* item = (*it);
541 // cint64 predCount = item->getUnprocessedPredecessorItemCount();
542 // if (!minItem || minUnpPredCount < predCount) {
543 // minUnpPredCount = predCount;
544 // minItem = item;
545 // }
546 //}
547 //nextSatTestItem = minItem;
548 //remainingCandItemSet->remove(nextSatTestItem);
549 QSet<COptimizedSubClassSatisfiableTestingItem*>::const_iterator itNext = remainingCandItemSet->constBegin();
550 nextSatTestItem = *itNext;
551 remainingCandItemSet->remove(nextSatTestItem);
552 }
553
554
555 if (nextSatTestItem && !nextSatTestItem->isSatisfiableTestOrdered()) {
556 optSubClassItem->decRemainingSatisfiableTestsCount();
557 optSubClassItem->incRunningSatisfiableTestsCount();
558 if (calculateSatisfiable(optSubClassItem,nextSatTestItem)) {
559 workTestCreated = true;
560 } else {
561 interpreteSatisfiableResult(optSubClassItem,nextSatTestItem->getSatisfiableConcept(),nextSatTestItem->getSatisfiableTestedResult());
562 }
563 }
564 }
565
566
567 if (!workTestCreated) {
568 if (optSubClassItem->hasAllSatisfiableTestsCompleted() || optSubClassItem->isTaxonomyConstructionFailed()) {
569 finishOntologyClassification(optSubClassItem);
570 processingOntItemList.removeFirst();
571 } else {
572 processingOntItemList.removeFirst();
573 processingOntItemList.append(ontClassItem);
574 loopOntClassItem = ontClassItem;
575 }
576 }
577 }
578 return workTestCreated;
579 }
580
581
582
583 bool COptimizedSubClassSubsumptionClassifierThread::calculateSatisfiable(COptimizedSubClassOntologyClassificationItem *optSubClassItem, COptimizedSubClassSatisfiableTestingItem* nextSatTestItem) {
584 CSatisfiableCalculationJob* satCalcJob = nullptr;
585 CClassClassificationComputationItem *workItem = 0;
586
587 CConcept* concept = nextSatTestItem->getSatisfiableConcept();
588 nextSatTestItem->setSatisfiableTestOrdered(true);
589
590 bool satisfiableFlag = false;
591
592 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGB
593 QString iriClassNameString = CIRIName::getRecentIRIName(concept->getClassNameLinker());
594 #endif
595 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION
596 statUpdateMutex.lock();
597 statusString = QString("[%2/%3] Calculating, is '%1' satisfiable").arg(iriClassNameString).arg(optSubClassItem->getClassifierStatistics()->getTestedSatisfiableCount()).arg(optSubClassItem->getClassifierStatistics()->getTotalSatisfiableCount());
598 statUpdateMutex.unlock();
599 #endif
600 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGLOGOUTPUT
601 LOG(INFO,getLogDomain(),QString("Calculating whether '%1' is satisfiable").arg(iriClassNameString),this);
602 #endif
603 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGCOUTOUTPUT
604 cout<<QString("Calculating whether '%1' is satisfiable").arg(iriClassNameString).toLocal8Bit().data()<<endl<<endl;
605 #endif
606
607 //if (iriClassNameString == "http://www.owllink.org/testsuite/galen#Haem") {
608 // bool bug = true;
609 //}
610
611
612 if (nextSatTestItem->isResultSatisfiableDerivated()) {
613 satisfiableFlag = true;
614 nextSatTestItem->setSatisfiableTested(true);
615 nextSatTestItem->setSatisfiableTestedResult(true);
616 return false;
617 }
618 if (nextSatTestItem->isResultUnsatisfiableDerivated()) {
619 satisfiableFlag = false;
620 nextSatTestItem->setSatisfiableTested(true);
621 nextSatTestItem->setSatisfiableTestedResult(false);
622 return false;
623 }
624 CPrecomputedSaturationSubsumerExtractor* precSatSubsumerExtractor = optSubClassItem->getPrecomputedSaturationSubsumerExtractor(false);
625 bool unsatisfiableFlag = false;
626 if (precSatSubsumerExtractor && precSatSubsumerExtractor->getConceptFlags(concept,&unsatisfiableFlag,nullptr,nullptr) && unsatisfiableFlag) {
627 satisfiableFlag = false;
628 nextSatTestItem->setSatisfiableTested(true);
629 nextSatTestItem->setSatisfiableTestedResult(false);
630 return false;
631 }
632 if (fastSatisfiableOnlySubClassPrecheckTest(optSubClassItem,nextSatTestItem,&satisfiableFlag)) {
633 nextSatTestItem->setSatisfiableTested(true);
634 nextSatTestItem->setSatisfiableTestedResult(satisfiableFlag);
635 return false;
636 }
637
638 CSatisfiableCalculationJobGenerator satCalcJobGen(optSubClassItem->getOntology());
639 satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(concept);
640 QHash<CSatisfiableCalculationJob *, CClassClassificationComputationItem *> *workHash = optSubClassItem->getWorkItemHash();
641
642 CClassifierStatistics *ontClassStat = optSubClassItem->getClassifierStatistics();
643 if (ontClassStat) {
644 ontClassStat->incCalculatedTestedSatisfiableCount(1);
645 }
646
647 workItem = new CClassClassificationComputationItem(satCalcJob,concept);
648 workHash->insertMulti(satCalcJob,workItem);
649 workOntItemHash.insert(workItem,optSubClassItem);
650
651 QHash<CConcept*,CClassificationSatisfiableCalculationConceptReferenceLinking*>* conRefLinkDataHash = optSubClassItem->getConceptReferenceLinkingDataHash();
652
653
654 satCalcJob->setSatisfiableClassificationMessageAdapter(new CSatisfiableTaskClassificationMessageAdapter(concept,optSubClassItem->getOntology(),this,nullptr,
655 CSatisfiableTaskClassificationMessageAdapter::EFEXTRACTSUBSUMERSROOTNODE |
656 CSatisfiableTaskClassificationMessageAdapter::EFEXTRACTOTHERNODESSINGLEDEPENDENCY |
657 CSatisfiableTaskClassificationMessageAdapter::EFEXTRACTSUBSUMERSOTHERNODES));
658
659 if (optSubClassItem->getIndividualDependenceTrackingCollector()) {
660 satCalcJob->setSatisfiableTaskIndividualDependenceTrackingAdapter(new CSatisfiableTaskIndividualDependenceTrackingAdapter(optSubClassItem->getIndividualDependenceTrackingCollector(),nextSatTestItem));
661 }
662
663 optSubClassItem->incCurrentCalculatingCount();
664 processCalculationJob(satCalcJob,optSubClassItem,workItem);
665 return true;
666 }
667
668
669
670
671
672
673 CIndividualSaturationProcessNode* COptimizedSubClassSubsumptionClassifierThread::getSaturationIndividualNodeForConcept(CConcept* concept, bool negated) {
674 CIndividualSaturationProcessNode* node = nullptr;
675 CConceptData* conceptData = concept->getConceptData();
676 if (conceptData) {
677 CConceptProcessData* conProcData = (CConceptProcessData*)conceptData;
678 CConceptReferenceLinking* conRefLinking = conProcData->getConceptReferenceLinking();
679 if (conRefLinking) {
680 CConceptSaturationReferenceLinkingData* confSatRefLinkingData = (CConceptSaturationReferenceLinkingData*)conRefLinking;
681 CSaturationConceptReferenceLinking* satCalcRefLinkData = confSatRefLinkingData->getConceptSaturationReferenceLinkingData(negated);
682 if (satCalcRefLinkData) {
683 node = (CIndividualSaturationProcessNode*)satCalcRefLinkData->getIndividualProcessNodeForConcept();
684 }
685 }
686 }
687 return node;
688 }
689
690
691 bool COptimizedSubClassSubsumptionClassifierThread::hasCachedSaturationIndividualNodeAssociatedExpansionProplematicConcept(CCacheEntry* cacheEntry, CConcept* testingConcept) {
692 if (!cacheEntry) {
693 return true;
694 }
695 CSaturationNodeAssociatedExpansionCacheEntry* satNodeExpCacheEntry = (CSaturationNodeAssociatedExpansionCacheEntry*)cacheEntry;
696
697 CSaturationNodeAssociatedDeterministicConceptExpansion* detExp = satNodeExpCacheEntry->getDeterministicConceptExpansion();
698 CSaturationNodeAssociatedNondeterministicConceptExpansion* ndetExpLinker = satNodeExpCacheEntry->getNondeterministicConceptExpansionLinker();
699 if (!detExp && !ndetExpLinker) {
700 return true;
701 }
702 CCacheValue cacheValue(mSatNodeExpCacheReader->getCacheValue(testingConcept,true));
703 if (detExp) {
704 CSaturationNodeAssociatedConceptLinker* cacheValueExpLinker = detExp->getConceptExpansionLinker(&cacheValue);
705 if (cacheValueExpLinker) {
706 return true;
707 }
708 }
709 if (ndetExpLinker && (!detExp || detExp->requiresNonDeterministicExpansion())) {
710 bool allNonDetExpansionsProblematic = true;
711 for (CSaturationNodeAssociatedNondeterministicConceptExpansion* ndetExpLinkerIt = ndetExpLinker; allNonDetExpansionsProblematic && ndetExpLinkerIt; ndetExpLinkerIt = ndetExpLinkerIt->getNext()) {
712 CSaturationNodeAssociatedConceptLinker* ndetCacheValueExpLinker = ndetExpLinkerIt->getConceptExpansionLinker(&cacheValue);
713 if (!ndetCacheValueExpLinker) {
714 allNonDetExpansionsProblematic = false;
715 }
716 }
717 if (allNonDetExpansionsProblematic) {
718 return true;
719 }
720 }
721 return false;
722 }
723
724
725 CCacheEntry* COptimizedSubClassSubsumptionClassifierThread::getAssociatedSaturationCacheEntry(COptimizedSubClassSatisfiableTestingItem* classConItem) {
726 CCacheEntry* cacheEntry = classConItem->getFastSatisfiabilityTestedSaturationCacheEntry();
727 if (!cacheEntry) {
728 CConcept* concept = classConItem->getSatisfiableConcept();
729 CIndividualSaturationProcessNode* satNode = getSaturationIndividualNodeForConcept(concept,false);
730 cacheEntry = mSatNodeExpCacheReader->getCacheEntry(satNode);
731 classConItem->setFastSatisfiabilityTestedSaturationCacheEntry(cacheEntry);
732 }
733 return cacheEntry;
734 }
735
736
737
738
739 bool COptimizedSubClassSubsumptionClassifierThread::fastSatisfiableOnlySubClassPrecheckTest(COptimizedSubClassOntologyClassificationItem *optSubClassItem, COptimizedSubClassSatisfiableTestingItem* nextSatTestItem, bool* isSatisfiableFlag) {
740 QHash<CConcept*,COptimizedSubClassSatisfiableTestingItem*>* conceptSatItemHash = optSubClassItem->getConceptSatisfiableTestItemHash();
741 CBOXHASH<CConcept*,CConcept*>* triggerImpHash = optSubClassItem->getOntology()->getTBox()->getTriggerImplicationHash(false);
742 CConcept* concept = nextSatTestItem->getSatisfiableConcept();
743
744
745 //QString className = CIRIName::getRecentIRIName(concept->getClassNameLinker());
746 //if (className == "galen#Salmonella" || className == "http://www.owllink.org/testsuite/galen#SalmonellaGroupA") {
747 // bool bug = true;
748 //}
749
750 bool satFlag = false;
751 bool testComplete = false;
752 if (concept->getOperatorCode() == CCSUB) {
753 cint64 conCount = concept->getOperandCount();
754 if (conCount == 1) {
755 CSortedNegLinker<CConcept*>* opLinkerIt = concept->getOperandList();
756 CConcept* firstConcept = opLinkerIt->getData();
757 cint64 firstOpCode = firstConcept->getOperatorCode();
758 CConcept* subClassConcept = nullptr;
759 if (!opLinkerIt->isNegated() && (firstOpCode == CCATOM || firstOpCode == CCSUB || firstOpCode == CCEQ)) {
760 subClassConcept = firstConcept;
761 }
762
763 if ((!triggerImpHash || !triggerImpHash->contains(concept)) && subClassConcept) {
764 COptimizedSubClassSatisfiableTestingItem* subClassConItem = conceptSatItemHash->value(subClassConcept);
765 if (subClassConItem && subClassConItem->isSatisfiableTested()) {
766 if (!triggerImpHash || !triggerImpHash->contains(subClassConcept)) {
767
768 ++mStatFastSubClassCheckCacheTryCount;
769 CCacheEntry* superCacheEntry = getAssociatedSaturationCacheEntry(subClassConItem);
770 if (!hasCachedSaturationIndividualNodeAssociatedExpansionProplematicConcept(superCacheEntry,concept)) {
771 nextSatTestItem->setFastSatisfiabilityTestedSaturationCacheEntry(superCacheEntry);
772 nextSatTestItem->setSuccessfullyFastSatisfiabilityTested(true);
773 ++mStatFastSubClassCheckCacheSuccCount;
774
775 QList<COptimizedSubClassSatisfiableTestingItem*>* subsumedSubsumingConList = subClassConItem->getSubsumingConceptItemList();
776 for (QList<COptimizedSubClassSatisfiableTestingItem*>::const_iterator it = subsumedSubsumingConList->constBegin(), itEnd = subsumedSubsumingConList->constEnd(); it != itEnd; ++it) {
777 COptimizedSubClassSatisfiableTestingItem* subsumedItem = (*it);
778 if (subClassConItem != subsumedItem && subsumedItem != nextSatTestItem) {
779 nextSatTestItem->addSubsumingConceptItem(subsumedItem);
780 }
781 }
782 nextSatTestItem->addSubsumingConceptItem(subClassConItem);
783 satFlag = subClassConItem->getSatisfiableTestedResult();
784 testComplete = true;
785 }
786 }
787 }
788 }
789 }
790 } else if (concept->getOperatorCode() == CCATOM) {
791
792 COptimizedSubClassSatisfiableTestingItem* topClassConItem = optSubClassItem->getTopConceptSatisfiableTestItem();
793 if (topClassConItem) {
794 CCacheEntry* topCacheEntry = getAssociatedSaturationCacheEntry(topClassConItem);
795 ++mStatFastSubClassCheckCacheTryCount;
796 if (!hasCachedSaturationIndividualNodeAssociatedExpansionProplematicConcept(topCacheEntry,concept)) {
797 nextSatTestItem->setFastSatisfiabilityTestedSaturationCacheEntry(topCacheEntry);
798 nextSatTestItem->setSuccessfullyFastSatisfiabilityTested(true);
799 ++mStatFastSubClassCheckCacheSuccCount;
800
801 satFlag = true;
802 testComplete = true;
803 }
804 }
805 }
806 if (satFlag && isSatisfiableFlag) {
807 *isSatisfiableFlag = true;
808 }
809 return testComplete;
810 }
811
812
813
814
815
816 CSubsumptionClassifierThread *COptimizedSubClassSubsumptionClassifierThread::processCalculationJob(CSatisfiableCalculationJob* job, COntologyClassClassificationItem *ontClassItem, CClassClassificationComputationItem* workItem) {
817 CClassificationCalculationStatisticsCollection* statColl = nullptr;
818 if (ontClassItem->isCollectProcessStatisticsActivated()) {
819 statColl = ontClassItem->getCalculationStatisticsCollection();
820 }
821 job->setCalclulationStatisticsCollector(statColl);
822 CTestCalculatedCallbackEvent *testResultCallback = new CTestCalculatedCallbackEvent(this,job,workItem,statColl);
823 job->setCalculationConfiguration(ontClassItem->getCalculationConfiguration());
824 CSubsumptionClassifierThread::processCalculationJob(job,ontClassItem,testResultCallback);
825 return this;
826 }
827
828
829
830 bool COptimizedSubClassSubsumptionClassifierThread::processToldClassificationMessage(COntologyClassificationItem *ontClassItem, CClassificationMessageData* messageDataLinker, CMemoryPool* memoryPools) {
831 COptimizedSubClassOntologyClassificationItem *optSubClassItem = (COptimizedSubClassOntologyClassificationItem *)ontClassItem;
832 CClassificationMessageData* messageDataLinkerIt = messageDataLinker;
833 while (messageDataLinkerIt) {
834 CClassificationMessageData* messageData = messageDataLinkerIt;
835 if (messageData->getClassificationMessageDataType() == CClassificationMessageData::TELLCLASSSUBSUMPTION) {
836 CClassificationClassSubsumptionMessageData* subsumMessageData = (CClassificationClassSubsumptionMessageData*)messageData;
837 CConcept* subsumedConcept = subsumMessageData->getSubsumedConcept();
838 CCLASSSUBSUMPTIONMESSAGELIST<CConcept*>* subsumerList = subsumMessageData->getClassSubsumerList();
839
840 COptimizedSubClassSatisfiableTestingItem* subsumedItem = nullptr;
841 subsumedItem = optSubClassItem->getConceptSatisfiableTestItem(subsumedConcept);
842
843
844 //QString iriClassNameString = CIRIName::getRecentIRIName(subsumedItem->getSatisfiableConcept()->getClassNameLinker());
845 //if (iriClassNameString == "http://www.owllink.org/testsuite/galen#LowerLobeOfLeftLung") {
846 // bool bug = true;
847 //}
848
849
850 if (subsumerList) {
851 for (CCLASSSUBSUMPTIONMESSAGELIST<CConcept*>::const_iterator it = subsumerList->constBegin(), itEnd = subsumerList->constEnd(); it != itEnd; ++it) {
852 CConcept* subsumerConcept(*it);
853 COptimizedSubClassSatisfiableTestingItem* subsumerItem = optSubClassItem->getConceptSatisfiableTestItem(subsumerConcept);
854 subsumedItem->addSubsumingConceptItem(subsumerItem);
855 }
856 }
857
858 subsumedItem->setResultSatisfiableDerivated(true);
859
860 }
861 messageDataLinkerIt = messageDataLinkerIt->getNext();
862 }
863 return true;
864 }
865
866
867 bool COptimizedSubClassSubsumptionClassifierThread::interpreteToldSubsumptionResult(COntologyClassClassificationItem *ontClassItem, const QList<QPair<CConcept *,CConcept *> > &subSumRelList, bool isSubSum) {
868 CConcept *lastConcept = nullptr;
869 COptimizedSubClassOntologyClassificationItem *optSubClassItem = (COptimizedSubClassOntologyClassificationItem *)ontClassItem;
870 COptimizedSubClassSatisfiableTestingItem* subsumerItem = nullptr;
871
872 for (QList<QPair<CConcept *,CConcept *> >::const_iterator it = subSumRelList.constBegin(), itEnd = subSumRelList.constEnd(); it != itEnd; ++it) {
873 CConcept *subsumerConcept = it->first;
874 if (lastConcept != subsumerConcept) {
875 lastConcept = subsumerConcept;
876 subsumerItem = optSubClassItem->getConceptSatisfiableTestItem(subsumerConcept);
877 }
878 CConcept *subsumedConcept = it->second;
879 if (isSubSum) {
880 COptimizedSubClassSatisfiableTestingItem* subsumedItem = optSubClassItem->getConceptSatisfiableTestItem(subsumedConcept);
881 subsumerItem->addSubsumingConceptItem(subsumedItem);
882 }
883 }
884 return true;
885 }
886
887
888 bool COptimizedSubClassSubsumptionClassifierThread::interpreteSubsumptionResult(COntologyClassClassificationItem *ontClassItem, CConcept *subsumerConcept, CConcept *subsumedConcept, bool isSubsumption) {
889 return false;
890 }
891
892
893 bool COptimizedSubClassSubsumptionClassifierThread::interpreteSatisfiableResult(COntologyClassClassificationItem *ontClassItem, CConcept *satisfiableConcept, bool isSatis) {
894 COptimizedSubClassOntologyClassificationItem *optSubClassItem = (COptimizedSubClassOntologyClassificationItem *)ontClassItem;
895
896 CClassifierStatistics *ontClassStat = optSubClassItem->getClassifierStatistics();
897 if (ontClassStat) {
898 ontClassStat->incToldSatisfiableCount(1);
899 }
900
901 ++satTestedCount;
902
903 optSubClassItem->decRunningSatisfiableTestsCount();
904
905 COptimizedSubClassSatisfiableTestingItem* satTestedItem = optSubClassItem->getConceptSatisfiableTestItem(satisfiableConcept);
906 satTestedItem->setSatisfiableTested(true);
907 satTestedItem->setSatisfiableTestedResult(isSatis);
908
909 COptimizedSubClassSatisfiableTestingItem* topItem = optSubClassItem->getTopConceptSatisfiableTestItem();
910
911 if (isSatis) {
912 // update processing lists
913 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGB
914 QString iriClassNameString = CIRIName::getRecentIRIName(satisfiableConcept->getClassNameLinker());
915 satTestedConList.append(iriClassNameString);
916 #endif
917 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGLOGOUTPUT
918 LOG(INFO,getLogDomain(),QString("[%1 / %2] Calculated: '%3' is satisfiable").arg(satTestedCount).arg(totalToTestCount).arg(iriClassNameString),this);
919 #endif
920 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION
921 statUpdateMutex.lock();
922 statusString = QString("Interpreting, '%1' is satisfiable").arg(iriClassNameString);
923 statUpdateMutex.unlock();
924 #endif
925 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGCOUTOUTPUT
926 cout<<QString("Calculated: '%1' is satisfiable").arg(iriClassNameString).toLocal8Bit().data()<<endl<<endl;
927 #endif
928
929 optSubClassItem->addSatisfiableConceptItem(satTestedItem);
930
931 } else {
932 CTaxonomy *tax = optSubClassItem->getTaxonomy();
933 if (topItem) {
934 tax->setConceptSatisfiable(satisfiableConcept,false);
935 } else {
936 tax->getBottomHierarchyNode()->addEquivalentConcept(satisfiableConcept);
937 tax->updateNodeEquivalences(tax->getBottomHierarchyNode());
938 }
939 }
940
941 QList<COptimizedSubClassSatisfiableTestingItem*>* nextItemList = optSubClassItem->getNextSatisfiableTestingItemList();
942 QSet<COptimizedSubClassSatisfiableTestingItem*>* nextCandItemSet = optSubClassItem->getNextCandidateSatisfiableTestingItemSet();
943 QSet<COptimizedSubClassSatisfiableTestingItem*>* remainingCandItemSet = optSubClassItem->getRemainingCandidateSatisfiableTestingItemSet();
944
945
946 QList<COptimizedSubClassSatisfiableTestingItem*>* succItemList = satTestedItem->getSuccessorItemList();
947 for (QList<COptimizedSubClassSatisfiableTestingItem*>::const_iterator it = succItemList->constBegin(), itEnd = succItemList->constEnd(); it != itEnd; ++it) {
948 COptimizedSubClassSatisfiableTestingItem* succItem = *it;
949 if (!isSatis) {
950 succItem->setResultUnsatisfiableDerivated(true);
951 }
952 succItem->decUnprocessedPredecessorItems();
953 if (succItem->hasOnlyProcessedPredecessorItems()) {
954 nextItemList->append(succItem);
955 } else {
956 nextCandItemSet->insert(succItem);
957 }
958 }
959
960 return false;
961 }
962
963
964 bool COptimizedSubClassSubsumptionClassifierThread::interpreteTestResults(CTestCalculatedCallbackEvent *testResult) {
965 CSatisfiableCalculationJob *satCalcJob = testResult->getSatisfiableCalculationJob();
966 bool testSat = testResult->getTestResultSatisfiable();
967 CClassClassificationComputationItem *workItem = (CClassClassificationComputationItem*)testResult->getClassificationWorkItem();
968
969 COntologyClassClassificationItem *ontClassItem = workOntItemHash.value(workItem);
970 if (ontClassItem) {
971
972 QHash<CSatisfiableCalculationJob *, CClassClassificationComputationItem *> *workHash = ontClassItem->getWorkItemHash();
973
974 CTaxonomy *taxonomy = ontClassItem->getTaxonomy();
975
976 if (workItem) {
977 ontClassItem->decCurrentCalculatingCount();
978 if (workItem->isTestValid()) {
979 if (testResult->hasCalculationError()) {
980 LOG(ERROR,getLogDomain(),logTr("Error in computation, classification for ontology '%1' failed.").arg(ontClassItem->getOntology()->getTerminologyName()),getLogObject());
981 ontClassItem->setTaxonomyConstructionFailed();
982
983 } else {
984 if (workItem->isConceptSatisfiableTest()) {
985 interpreteSatisfiableResult(ontClassItem,workItem->getSatisfiableTestedConcept(),testSat);
986 }
987 }
988 }
989 QHash<CSatisfiableCalculationJob *, CClassClassificationComputationItem *>::iterator itWorkItem = workHash->find(satCalcJob);
990 while (itWorkItem != workHash->end()) {
991 if (itWorkItem.value() == workItem) {
992 workHash->erase(itWorkItem);
993 break;
994 }
995 ++itWorkItem;
996 }
997 delete workItem;
998 }
999 workOntItemHash.remove(workItem);
1000
1001 CClassificationCalculationStatisticsCollection* statisticCollection = testResult->getUsedStatisticsCollection();
1002 if (statisticCollection) {
1003 ontClassItem->reuseCalculationStatisticsCollection(statisticCollection);
1004 }
1005
1006 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGTAXONOMYCOUTOUTPUT
1007 QString taxString = taxonomy->getConceptHierarchyString();
1008 cout<<taxString.toLocal8Bit().data()<<endl<<endl;
1009 #endif
1010 }
1011
1012 return true;
1013 }
1014
1015
1016 bool COptimizedSubClassSubsumptionClassifierThread::finishOntologyClassification(COntologyClassClassificationItem *ontClassItem) {
1017
1018 if (!ontClassItem->isTaxonomyConstructed() && !ontClassItem->isTaxonomyConstructionFailed()) {
1019
1020 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGLOGOUTPUT
1021 LOG(INFO,getLogDomain(),QString("Building Class Taxonomy"),this);
1022 #endif
1023
1024 // build taxonomy
1025
1026 COptimizedSubClassOntologyClassificationItem *optSubClassItem = (COptimizedSubClassOntologyClassificationItem *)ontClassItem;
1027 QList<COptimizedSubClassSatisfiableTestingItem*>* satItemList = optSubClassItem->getSatisfiableConceptItemList();
1028
1029 CTaxonomy *tax = optSubClassItem->getTaxonomy();
1030
1031 QList<COptimizedSubClassSatisfiableTestingItem*> itemList;
1032
1033 COptimizedSubClassSatisfiableTestingItem* topItem = optSubClassItem->getTopConceptSatisfiableTestItem();
1034 CHierarchyNode* topHierNode = tax->getTopHierarchyNode();
1035 CHierarchyNode* bottomHierNode = tax->getBottomHierarchyNode();
1036
1037
1038
1039 cint64 topSubsumingItemCount = topItem->getSubsumingConceptItemCount();
1040 topItem->setSatisfiableConceptHierarchyNode(topHierNode);
1041 if (topSubsumingItemCount) {
1042 QList<COptimizedSubClassSatisfiableTestingItem*>* subsumingConceptItemList = topItem->sortSubsumingConceptItemList();
1043 for (QList<COptimizedSubClassSatisfiableTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); subsumedIt != subsumedItEnd; ++subsumedIt) {
1044 COptimizedSubClassSatisfiableTestingItem* subsumedConceptItem = *subsumedIt;
1045 // mark as equivalent
1046 subsumedConceptItem->setEquivalentItem(true);
1047 topHierNode->addEquivalentConcept(subsumedConceptItem->getSatisfiableConcept());
1048 tax->updateNodeEquivalences(topHierNode);
1049 }
1050 }
1051
1052
1053 for (QList<COptimizedSubClassSatisfiableTestingItem*>::const_iterator it = satItemList->constBegin(), itEnd = satItemList->constEnd(); it != itEnd; ++it) {
1054 COptimizedSubClassSatisfiableTestingItem* item = *it;
1055 if (!item->isEquivalentItem() && item != topItem) {
1056
1057 CHierarchyNode* itemNode = tax->getHierarchyNode(item->getSatisfiableConcept(),true);
1058 item->setSatisfiableConceptHierarchyNode(itemNode);
1059 cint64 itemSubsumingCount = item->getSubsumingConceptItemCount();
1060 itemList.append(item);
1061 if (itemSubsumingCount > topSubsumingItemCount) {
1062 QList<COptimizedSubClassSatisfiableTestingItem*>* subsumingConceptItemList = item->sortSubsumingConceptItemList();
1063 for (QList<COptimizedSubClassSatisfiableTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd(); subsumedIt != subsumedItEnd; ++subsumedIt) {
1064 COptimizedSubClassSatisfiableTestingItem* subsumedConceptItem = *subsumedIt;
1065 cint64 subsumedItemSubsumingCount = subsumedConceptItem->getSubsumingConceptItemCount();
1066 if (subsumedItemSubsumingCount == itemSubsumingCount) {
1067 // mark as equivalent
1068 subsumedConceptItem->setEquivalentItem(true);
1069 itemNode->addEquivalentConcept(subsumedConceptItem->getSatisfiableConcept());
1070 tax->updateNodeEquivalences(itemNode);
1071 } else {
1072 break;
1073 }
1074 }
1075 }
1076 }
1077 }
1078
1079
1080 for (QList<COptimizedSubClassSatisfiableTestingItem*>::const_iterator it = itemList.constBegin(), itEnd = itemList.constEnd(); it != itEnd; ++it) {
1081 COptimizedSubClassSatisfiableTestingItem* item = *it;
1082
1083 if (!item->isEquivalentItem() && item != topItem) {
1084 cint64 itemSubsumingCount = item->getSubsumingConceptItemCount();
1085 CHierarchyNode* itemHierNode = item->getSatisfiableConceptHierarchyNode();
1086
1087 //QString iriClassNameString = CIRIName::getRecentIRIName(item->getSatisfiableConcept()->getClassNameLinker());
1088 //if (iriClassNameString == "http://www.owllink.org/testsuite/galen#LowerLobeOfLeftLung") {
1089 // bool bug = true;
1090 //}
1091
1092
1093 QList<COptimizedSubClassSatisfiableTestingItem*>* subsumingConceptItemList = item->getSubsumingConceptItemList();
1094 QList<COptimizedSubClassSatisfiableTestingItem*>::const_iterator subsumedIt = subsumingConceptItemList->constBegin(), subsumedItEnd = subsumingConceptItemList->constEnd();
1095
1096 cint64 eqCount = 0;
1097 cint64 remainingSubsumingCount = itemSubsumingCount;
1098 // remove direct equivalences
1099 while (subsumedIt != subsumedItEnd) {
1100 COptimizedSubClassSatisfiableTestingItem* subsumedConceptItem = *subsumedIt;
1101 cint64 subsumedItemSubsumingCount = subsumedConceptItem->getSubsumingConceptItemCount();
1102 if (subsumedItemSubsumingCount != itemSubsumingCount) {
1103 break;
1104 } else {
1105 ++eqCount;
1106 ++subsumedIt;
1107 --remainingSubsumingCount;
1108 }
1109 }
1110
1111 while (subsumedIt != subsumedItEnd && (*subsumedIt)->isEquivalentItem()) {
1112 ++subsumedIt;
1113 }
1114
1115 // find first parent
1116 if (subsumedIt == subsumedItEnd) {
1117 // no parent, use top as parent
1118 itemHierNode->makeParent(topHierNode);
1119 } else {
1120 itemHierNode->addPredecessorNode(topHierNode);
1121 QList<COptimizedSubClassSatisfiableTestingItem*> parentItemList;
1122 while (subsumedIt != subsumedItEnd) {
1123 COptimizedSubClassSatisfiableTestingItem* subsumedConceptItem = *subsumedIt;
1124 if (!subsumedConceptItem->isEquivalentItem()) {
1125 subsumedConceptItem->setPredecessorItem(true);
1126 CHierarchyNode* subsumedHierNode = subsumedConceptItem->getSatisfiableConceptHierarchyNode();
1127 itemHierNode->makeParent(subsumedHierNode);
1128 parentItemList.append(subsumedConceptItem);
1129 remainingSubsumingCount -= subsumedConceptItem->getSubsumingConceptItemCount()+1;
1130 ++subsumedIt;
1131 break;
1132 } else {
1133 ++subsumedIt;
1134 }
1135 }
1136
1137 bool searchForMoreParents = remainingSubsumingCount > 0;
1138 while (subsumedIt != subsumedItEnd) {
1139 COptimizedSubClassSatisfiableTestingItem* subsumedConceptItem = *subsumedIt;
1140 if (!subsumedConceptItem->isEquivalentItem()) {
1141 bool predOfOnePrevParent = false;
1142 if (searchForMoreParents) {
1143 for (QList<COptimizedSubClassSatisfiableTestingItem*>::const_iterator parentIt = parentItemList.constBegin(), parentItEnd = parentItemList.constEnd(); parentIt != parentItEnd && !predOfOnePrevParent; ++parentIt) {
1144 COptimizedSubClassSatisfiableTestingItem* parentItem = *parentIt;
1145 if (parentItem->getSubsumingConceptItemSet()->contains(subsumedConceptItem)) {
1146 predOfOnePrevParent = true;
1147 }
1148 }
1149 }
1150 subsumedConceptItem->setPredecessorItem(true);
1151 CHierarchyNode* subsumedHierNode = subsumedConceptItem->getSatisfiableConceptHierarchyNode();
1152 if (!predOfOnePrevParent && searchForMoreParents) {
1153 itemHierNode->makeParent(subsumedHierNode);
1154 parentItemList.append(subsumedConceptItem);
1155 } else {
1156 itemHierNode->addPredecessorNode(subsumedHierNode);
1157 }
1158 }
1159 ++subsumedIt;
1160 }
1161 }
1162 }
1163 }
1164
1165 for (QList<COptimizedSubClassSatisfiableTestingItem*>::const_iterator it = itemList.constBegin(), itEnd = itemList.constEnd(); it != itEnd; ++it) {
1166 COptimizedSubClassSatisfiableTestingItem* item = *it;
1167 if (!item->isPredecessorItem() && !item->isEquivalentItem()) {
1168 CHierarchyNode* itemHierNode = item->getSatisfiableConceptHierarchyNode();
1169 bottomHierNode->makeParent(itemHierNode);
1170 }
1171 }
1172
1173
1174
1175 #ifdef OPTIMIZEDSUBCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION
1176 statUpdateMutex.lock();
1177 statusString = QString("Finished ontology classification");
1178 statUpdateMutex.unlock();
1179 #endif
1180 CTaxonomy *taxonomy = ontClassItem->getTaxonomy();
1181 CConcreteOntology *ontology = ontClassItem->getOntology();
1182
1183
1184 CClassification* classification = ontology->getClassification();
1185 if (classification) {
1186 CClassConceptClassification* classConClassification = ontClassItem->getClassConceptClassification();
1187 CClassificationStatisticsCollectionStrings* classifStatCollStrings = ontClassItem->getClassificationStatisticsCollectionStrings();
1188 CClassifierStatistics* classifierStats = ontClassItem->getClassifierStatistics();
1189 classifStatCollStrings->addProcessingStatistics("class-classification-total-satisfiable-test-count",classifierStats->getTotalSatisfiableCount());
1190 classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-tested-count",classifierStats->getTestedSatisfiableCount());
1191 classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-pseudo-model-merged-tested-count",classifierStats->getPseudoModelMergedTestedSatisfiableCount());
1192 classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-derivate-tested-count",classifierStats->getDerivatedTestedSatisfiableCount());
1193 classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-calculated-tested-count",classifierStats->getCalculatedTestedSatisfiableCount());
1194 classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-pruned-tested-count",classifierStats->getPrunedTestedSatisfiableCount());
1195 classifStatCollStrings->addProcessingStatistics("class-classification-satisfiable-told-tested-count",classifierStats->getToldSatisfiableCount()-classifierStats->getCalculatedTestedSatisfiableCount());
1196 classifStatCollStrings->addProcessingStatistics("class-classification-total-subsumption-test-count",classifierStats->getTotalSatisfiableCount()*(classifierStats->getTotalSatisfiableCount()-1));
1197 classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-tested-count",classifierStats->getTestedSubsumptionCount());
1198 classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-pseudo-model-merged-tested-count",classifierStats->getPseudoModelMergedTestedSubsumptionCount());
1199 classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-subclass-tested-count",classifierStats->getSubclassTestedSubsumptionCount());
1200 classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-subclass-identifier-occur-tested-count",classifierStats->getSubclassIdentifierOccurTestedSubsumptionCount());
1201 classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-derivate-tested-count",classifierStats->getDerivatedTestedSubsumptionCount());
1202 classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-calculated-tested-count",classifierStats->getCalculatedTestedSubsumptionCount());
1203 classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-pruned-tested-count",classifierStats->getPrunedTestedSubsumptionCount());
1204 classifStatCollStrings->addProcessingStatistics("class-classification-subsumption-told-tested-count",classifierStats->getToldSubsumptionCount()-classifierStats->getCalculatedTestedSubsumptionCount());
1205 classConClassification->setClassConceptTaxonomy(taxonomy);
1206 classConClassification->setClassificationStatistics(classifStatCollStrings);
1207 if (ontClassItem->getIndividualDependenceTrackingCollector()) {
1208 classConClassification->setDependentIndividualsTracking(ontClassItem->getIndividualDependenceTrackingCollector()->getExtendingIndividualDependenceTracking());
1209 }
1210 classification->setClassConceptClassification(classConClassification);
1211 }
1212 ontology->setConceptTaxonomy(taxonomy);
1213
1214 ontClassItem->setHasRemainingTests(false);
1215
1216 taxonomy->setTaxonomyComplete(true);
1217 --mClassificationCount;
1218 LOG(INFO,getLogDomain(),logTr("Ontology '%1' classified with %2 satisfiable tests.").arg(ontology->getTerminologyName()).arg(ontClassItem->getCalcedSatisfiableCount()),getLogObject());
1219 }
1220 ontClassItem->submitTaxonomyConstructed();
1221 ontClassItem->doClassifiedCallback();
1222 return true;
1223 }
1224
1225
1226
1227
1228 }; // end namespace Classifier
1229
1230 }; // end namespace Reasoner
1231
1232 }; // end namespace Konclude