Debian Codegraph @

Source/Reasoner/Consistiser/CTotallyPrecomputationThread.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 "CTotallyPrecomputationThread.h"
22
23
24
25 #ifndef KONCLUDE_FORCE_STATISTIC_DEACTIVATED
26 #define KONCLUDE_PRECOMPUTATION_SATURATION_STATISTIC_OUTPUT
27 #endif
28
29
30 namespace Konclude {
31
32 namespace Reasoner {
33
34 namespace Consistiser {
35
36
37 CTotallyPrecomputationThread::CTotallyPrecomputationThread(CReasonerManager *reasonerManager) : CPrecomputationThread(reasonerManager),CLogIdentifier("::Konclude::Reasoner::Kernel::Precomputator",this) {
38 mReuseCompletionGraphCacheWriter = nullptr;
39 CCompletionGraphCache* complGraphCache = reasonerManager->getCompletionGraphCache();
40 if (complGraphCache) {
41 CReuseCompletionGraphCache* reuseComplGraphCache = dynamic_cast<CReuseCompletionGraphCache*>(complGraphCache);
42 if (reuseComplGraphCache) {
43 mReuseCompletionGraphCacheWriter = reuseComplGraphCache->createCacheWriter();
44 }
45 }
46 mBackendAssocCache = nullptr;
47 CBackendCache* backendCache = reasonerManager->getBackendAssociationCache();
48 if (backendCache) {
49 mBackendAssocCache = dynamic_cast<CBackendRepresentativeMemoryCache*>(backendCache);
50 }
51 mConfPrecomputationIndividualsRetrievalWhileSaturation = false;
52 }
53
54
55 CTotallyPrecomputationThread::~CTotallyPrecomputationThread() {
56 }
57
58
59 COntologyPrecomputationItem* CTotallyPrecomputationThread::initializeOntologyPrecomputionItem(CConcreteOntology* ontology, CConfigurationBase* config) {
60 CTotallyOntologyPrecomputationItem* item = new CTotallyOntologyPrecomputationItem();
61 item->initTotallyPrecomputationItem(ontology,config);
62
63
64 if (config) {
65 bool configErrorFlag = false;
66 cint64 processorCount = 1;
67 QString processorCountString = CConfigDataReader::readConfigString(config,"Konclude.Calculation.ProcessorCount",QString(),&configErrorFlag);
68 if (!configErrorFlag) {
69 if (processorCountString == "AUTO") {
70 processorCount = CThread::idealThreadCount();
71 } else {
72 qint64 convertedWorkerCount = processorCountString.toInt(&configErrorFlag);
73 if (configErrorFlag) {
74 processorCount = convertedWorkerCount;
75 }
76 }
77 }
78
79 bool mulConfigErrorFlag = false;
80 cint64 multiplicator = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Precomputation.TotalPrecomputor.MultipliedUnitsParallelCalculationCount",1,&mulConfigErrorFlag);
81 mConfMaxTestParallelCount = processorCount*multiplicator;
82 bool maxConfigErrorFlag = false;
83 cint64 maxParallel = CConfigDataReader::readConfigInteger(config,"Konclude.Calculation.Precomputation.TotalPrecomputor.MaximumParallelCalculationCount",1,&maxConfigErrorFlag);
84 if (!maxConfigErrorFlag) {
85 if (!mulConfigErrorFlag) {
86 mConfMaxTestParallelCount = qMin(mConfMaxTestParallelCount,maxParallel);
87 } else {
88 mConfMaxTestParallelCount = maxParallel;
89 }
90 }
91
92 } else {
93 mConfMaxTestParallelCount = 1;
94 }
95 mConfMaxTestBatchCreationCount = CConfigDataReader::readConfigInteger(config, "Konclude.Calculation.Precomputation.TotalPrecomputor.MaximumBatchJobCreationCount", -1);
96
97 mConfForceFullCompletionGraphConstruction = CConfigDataReader::readConfigBoolean(config,"Konclude.Calculation.Precomputation.ForceFullCompletionGraphConstruction",false);
98
99
100 mConfConditionalFullCompletionGraphConstruction = CConfigDataReader::readConfigBoolean(config, "Konclude.Calculation.Precomputation.ConditionalFullCompletionGraphConstruction", false);
101
102 mConfFullCGCExclusionConditionMaximumIndividualLimit = CConfigDataReader::readConfigInteger(config, "Konclude.Calculation.Precomputation.FullCompletionGraphConstruction.ExclusionCondition.MaximumIndividualLimit", 300000);
103 mConfFullCGCSuggestionConditionMaximumIndividualLimit = CConfigDataReader::readConfigInteger(config, "Konclude.Calculation.Precomputation.FullCompletionGraphConstruction.SuggestionCondition.MaximumIndividualLimit", 10000);
104
105 mConfFullCGCExclusionConditionMaximumIndividualConceptRatio = CConfigDataReader::readConfigInteger(config, "Konclude.Calculation.Precomputation.FullCompletionGraphConstruction.ExclusionCondition.MaximumIndividualConceptRatio", 5000) / 100;
106 mConfFullCGCSuggestionConditionMaximumIndividualConceptRatio = CConfigDataReader::readConfigInteger(config, "Konclude.Calculation.Precomputation.FullCompletionGraphConstruction.SuggestionCondition.MaximumIndividualConceptRatio", 500) / 100;
107
108
109 return item;
110 }
111
112
113
114 bool CTotallyPrecomputationThread::createNextTest() {
115
116
117 COntologyPrecomputationItem* loopOntPreCompItem = 0;
118 bool workTestCreated = false;
119 while (!workTestCreated && !mProcessingOntItemList.isEmpty()) {
120 COntologyPrecomputationItem* ontPreCompItem = mProcessingOntItemList.first();
121
122 if (ontPreCompItem == loopOntPreCompItem) {
123 // don't run into infinite loop without doing something
124 break;
125 }
126
127 CTotallyOntologyPrecomputationItem* totallyPreCompItem = (CTotallyOntologyPrecomputationItem*)ontPreCompItem;
128
129
130 bool failDebug = false;
131 if (!workTestCreated && totallyPreCompItem->isConsistenceStepRequired()) {
132 if (!totallyPreCompItem->isConsistenceStepFinished()) {
133 if (totallyPreCompItem->areConsistenceStepProcessingRequirementSatisfied()) {
134
135 if (!totallyPreCompItem->hasConceptSaturationPrecomputationCreated()) {
136 LOG(INFO,getLogDomain(),logTr("Preparing concept saturation."),this);
137
138 CConcreteOntology* ontology = totallyPreCompItem->getOntology();
139 totallyPreCompItem->setSaturationStepRunning(true);
140 createSaturationConstructionJob(totallyPreCompItem);
141 totallyPreCompItem->setSaturationComputationRunning(true);
142 totallyPreCompItem->setConceptSaturationPrecomputationCreated(true);
143
144 addIdentifiedRemainingConsistencyRequiredConcepts(totallyPreCompItem);
145 addRequiredSaturationIndividuals(totallyPreCompItem);
146
147 bool fullCompletionGraphConstruction = false;
148 bool forceCompletionGraphConstruction = false;
149 if (mConfForceFullCompletionGraphConstruction || !totallyPreCompItem->hasIndividualsSaturated()) {
150 forceCompletionGraphConstruction = fullCompletionGraphConstruction = true;
151 }
152 if (!fullCompletionGraphConstruction) {
153 forceCompletionGraphConstruction = fullCompletionGraphConstruction |= totallyPreCompItem->getOntology()->getStructureSummary()->hasGroundingOccurrence();
154 }
155
156 if (!mConfForceFullCompletionGraphConstruction && mConfConditionalFullCompletionGraphConstruction) {
157 cint64 indiCount = ontology->getABox()->getNextIndividualId();
158 cint64 conceptCount = ontology->getTBox()->getConceptCount();
159 double indiConRatio = (double)indiCount / (double)conceptCount;
160
161 // check whether no exclusion limit/condition is satisfied
162 if (indiCount < mConfFullCGCExclusionConditionMaximumIndividualLimit && indiConRatio < mConfFullCGCExclusionConditionMaximumIndividualConceptRatio) {
163 // check whether at least one suggestion condition is satisfied
164 if (indiCount < mConfFullCGCSuggestionConditionMaximumIndividualLimit || indiConRatio < mConfFullCGCSuggestionConditionMaximumIndividualConceptRatio) {
165 fullCompletionGraphConstruction = true;
166 LOG(INFO, getLogDomain(), logTr("Enabling full completion graph construction for %1 individuals with %2 individuals to concepts ratio.").arg(indiCount).arg(indiConRatio), this);
167 }
168 }
169
170 }
171
172 totallyPreCompItem->setFullCompletionGraphConstruction(fullCompletionGraphConstruction);
173 totallyPreCompItem->setForceCompletionGraphConstruction(forceCompletionGraphConstruction);
174
175 }
176
177
178 if (totallyPreCompItem->hasRemainingConsistencyRequiredSaturationConcepts() && !totallyPreCompItem->isSaturationComputationRunning()) {
179 if (saturateRemainingConsistencyRequiredConcepts(totallyPreCompItem)) {
180 totallyPreCompItem->setSaturationComputationRunning(true);
181 workTestCreated = true;
182 }
183 }
184
185
186 if (totallyPreCompItem->hasRemainingRequiredSaturationIndividuals() && !totallyPreCompItem->hasClashedSaturationIndividuals() && (!totallyPreCompItem->isSaturationComputationRunning() || totallyPreCompItem->hasIndividualSaturationRunning())) {
187 if (!isAllAssertionIndividualSaturationSufficient(totallyPreCompItem) || totallyPreCompItem->isIndividualStepRequired() || totallyPreCompItem->isFullCompletionGraphConstruction() || totallyPreCompItem->isForceCompletionGraphConstruction()) {
188 if (saturateRemainingRequiredSaturationIndividuals(totallyPreCompItem)) {
189 totallyPreCompItem->incIndividualSaturationRunningCount();
190 totallyPreCompItem->setSaturationComputationRunning(true);
191 totallyPreCompItem->setIndividualStepRunning(true);
192 workTestCreated = true;
193 }
194 }
195 }
196
197
198
199 if (!totallyPreCompItem->isSaturationComputationRunning()) {
200 if (totallyPreCompItem->failAfterConsistencyConceptSaturation()) {
201 totallyPreCompItem->getConsistencePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED);
202 totallyPreCompItem->getConsistencePrecomputationStep()->setStepFinished(true);
203 failDebug |= true;
204 } else {
205 if (!isAllAssertionIndividualSaturationSufficient(totallyPreCompItem) || totallyPreCompItem->isIndividualStepRequired()) {
206 if (!totallyPreCompItem->hasAllIndividualPrecomputationCreated() && !totallyPreCompItem->hasClashedSaturationIndividuals() && !totallyPreCompItem->hasIndividualPrecomputationClashed() && !totallyPreCompItem->isSaturationComputationRunning() && !totallyPreCompItem->hasIndividualSaturationRunning()) {
207 if (createIndividualPrecomputationCheck(totallyPreCompItem)) {
208 totallyPreCompItem->setIndividualStepRunning(true);
209 totallyPreCompItem->setIndividualComputationRunning(true);
210 totallyPreCompItem->incIndividualComputationRunningCount();
211 workTestCreated = true;
212 } else {
213 if (totallyPreCompItem->hasAllIncompletelyHandledIndividualsRetrieved()) {
214 totallyPreCompItem->setAllIndividualPrecomputationCreated(true);
215 if (!totallyPreCompItem->isIndividualComputationRunning()) {
216 totallyPreCompItem->setIndividualPrecomputationChecked(true);
217 }
218 }
219 }
220 }
221 }
222 }
223 }
224
225
226 if (!failDebug && !totallyPreCompItem->hasConsistenceCheckCreated() && !totallyPreCompItem->isSaturationComputationRunning() && !totallyPreCompItem->isIndividualComputationRunning() && !totallyPreCompItem->isPrecompuationRetrievingIncompletelyHandledIndividuals()) {
227 LOG(INFO,getLogDomain(),logTr("Precompute ontology consistency."),this);
228 totallyPreCompItem->setConsistenceCheckCreated(true);
229 workTestCreated = createConsistencePrecomputationCheck(totallyPreCompItem);
230 }
231
232 if (totallyPreCompItem->hasConsistenceCheched()) {
233 LOG(INFO,getLogDomain(),logTr("Consistency computation completed."),this);
234 totallyPreCompItem->setSaturationStepRunning(false);
235 totallyPreCompItem->getConsistencePrecomputationStep()->setStepFinished(true);
236
237 COntologyProcessingStatistics* ontProcStats = totallyPreCompItem->getConsistencePrecomputationStep()->getProcessingStepData()->getProcessingStatistics(true);
238 ontProcStats->setProcessingCountStatisticValue("consistency-checking-time",totallyPreCompItem->getInitializationTime()->elapsed());
239
240 if (totallyPreCompItem->failAfterConsistencyChecking()) {
241 totallyPreCompItem->getConsistencePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED);
242 failDebug |= true;
243 } else {
244
245 if (totallyPreCompItem->getOntology()->getConsistence()->isOntologyConsistent()) {
246 totallyPreCompItem->getConsistencePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSSUCESSFULL);
247 } else {
248 totallyPreCompItem->getConsistencePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSSUCESSFULL | COntologyProcessingStatus::PSINCONSITENT);
249 }
250 }
251
252 }
253
254 } else {
255 totallyPreCompItem->getConsistencePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED | COntologyProcessingStatus::PSFAILEDREQUIREMENT);
256 totallyPreCompItem->getConsistencePrecomputationStep()->setStepFinished(true);
257 }
258 } else {
259 totallyPreCompItem->getConsistencePrecomputationStep()->submitRequirementsUpdate();
260 }
261 }
262
263
264
265
266
267
268
269 if (!workTestCreated && totallyPreCompItem->isIndividualStepRequired() && totallyPreCompItem->isConsistenceStepFinished()) {
270 if (!totallyPreCompItem->isIndividualStepFinished()) {
271 if (totallyPreCompItem->areIndividualStepProcessingRequirementSatisfied()) {
272
273 if (totallyPreCompItem->hasRemainingRequiredSaturationIndividuals() && !totallyPreCompItem->hasClashedSaturationIndividuals() && (!totallyPreCompItem->isSaturationComputationRunning() || totallyPreCompItem->hasIndividualSaturationRunning())) {
274 if (saturateRemainingRequiredSaturationIndividuals(totallyPreCompItem)) {
275 totallyPreCompItem->incIndividualSaturationRunningCount();
276 totallyPreCompItem->setSaturationComputationRunning(true);
277 totallyPreCompItem->setIndividualStepRunning(true);
278 workTestCreated = true;
279 }
280 }
281
282
283 if (!totallyPreCompItem->hasAllIndividualPrecomputationCreated() && !totallyPreCompItem->hasClashedSaturationIndividuals() && !totallyPreCompItem->hasIndividualPrecomputationClashed() && !totallyPreCompItem->isSaturationComputationRunning() && !totallyPreCompItem->hasIndividualSaturationRunning()) {
284 if (createIndividualPrecomputationCheck(totallyPreCompItem)) {
285 totallyPreCompItem->setIndividualStepRunning(true);
286 totallyPreCompItem->setIndividualComputationRunning(true);
287 totallyPreCompItem->incIndividualComputationRunningCount(1);
288 } else {
289 if (totallyPreCompItem->hasAllIncompletelyHandledIndividualsRetrieved()) {
290 totallyPreCompItem->setAllIndividualPrecomputationCreated(true);
291 if (!totallyPreCompItem->isIndividualComputationRunning()) {
292 totallyPreCompItem->setIndividualPrecomputationChecked(true);
293 }
294 }
295 }
296 }
297
298
299 if ((totallyPreCompItem->hasIndividualPrecomputationChecked() || (totallyPreCompItem->hasClashedSaturationIndividuals() || totallyPreCompItem->hasIndividualPrecomputationClashed())) && !totallyPreCompItem->isIndividualComputationRunning()) {
300 totallyPreCompItem->setIndividualStepRunning(false);
301 totallyPreCompItem->getIndividualPrecomputationStep()->setStepFinished(true);
302 if (totallyPreCompItem->hasClashedSaturationIndividuals() || totallyPreCompItem->hasIndividualPrecomputationClashed()) {
303 totallyPreCompItem->getIndividualPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED);
304 } else {
305 totallyPreCompItem->getIndividualPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSSUCESSFULL);
306 }
307 }
308
309 } else {
310 totallyPreCompItem->setIndividualStepRunning(false);
311 totallyPreCompItem->getIndividualPrecomputationStep()->setStepFinished(true);
312 totallyPreCompItem->getIndividualPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED | COntologyProcessingStatus::PSFAILEDREQUIREMENT);
313 }
314 } else {
315 totallyPreCompItem->getIndividualPrecomputationStep()->submitRequirementsUpdate();
316 }
317 }
318
319
320
321
322
323
324 if (!workTestCreated && totallyPreCompItem->isOccurrenceStatisticsStepRequired() && totallyPreCompItem->isConsistenceStepFinished() && !totallyPreCompItem->isSaturationStepRunning() && !totallyPreCompItem->isIndividualComputationRunning() && !totallyPreCompItem->isSaturationComputationRunning()) {
325 if (!totallyPreCompItem->isOccurrenceStatisticsStepFinished()) {
326 if (totallyPreCompItem->areOccurrenceStatisticsStepProcessingRequirementSatisfied()) {
327
328 if (!totallyPreCompItem->getCalculationConfiguration()->isOccurrenceStatisticsCollectionActivated()) {
329 totallyPreCompItem->setSaturationOccurrenceStatisticsCollectingInitialized(true);
330 totallyPreCompItem->setSaturationOccurrenceStatisticsCollected(true);
331 }
332
333 if (!totallyPreCompItem->hasSaturationOccurrenceStatisticsCollectingInitialized()) {
334 // determine concept and role occurrences in saturation graph
335 LOG(INFO, getLogDomain(), logTr("Collecting remaining occurrence statistics from saturation for ontology '%1'.").arg(ontPreCompItem->getOntology()->getTerminologyName()), getLogObject());
336 createOccurrenceStatisticsCollectingSaturationProcessingJob(totallyPreCompItem);
337 totallyPreCompItem->setSaturationOccurrenceStatisticsCollectingInitialized(true);
338 }
339
340 if (totallyPreCompItem->hasSaturationOccurrenceStatisticsCollected()) {
341 totallyPreCompItem->getOccurrenceStatisticsPrecomputationStep()->setStepFinished(true);
342 totallyPreCompItem->getOccurrenceStatisticsPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSSUCESSFULL);
343 }
344 } else {
345 totallyPreCompItem->getOccurrenceStatisticsPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED | COntologyProcessingStatus::PSFAILEDREQUIREMENT);
346 totallyPreCompItem->getOccurrenceStatisticsPrecomputationStep()->setStepFinished(true);
347 }
348 } else {
349 totallyPreCompItem->getOccurrenceStatisticsPrecomputationStep()->submitRequirementsUpdate();
350 }
351 }
352
353
354
355
356
357
358 if (!workTestCreated && totallyPreCompItem->isSaturationStepRequired() && totallyPreCompItem->isConsistenceStepFinished() && !totallyPreCompItem->hasIndividualSaturationRunning() && !totallyPreCompItem->isIndividualStepRunning() && !totallyPreCompItem->isSaturationComputationRunning() && (!totallyPreCompItem->isOccurrenceStatisticsStepRequired() || totallyPreCompItem->isOccurrenceStatisticsStepFinished())) {
359 if (!totallyPreCompItem->isSaturationStepFinished()) {
360 if (totallyPreCompItem->areSaturationStepProcessingRequirementSatisfied()) {
361
362
363 if (totallyPreCompItem->hasRemainingRequiredSaturationConcepts() && !totallyPreCompItem->isSaturationComputationRunning()) {
364 if (saturateRemainingRequiredItems(totallyPreCompItem)) {
365 totallyPreCompItem->setSaturationStepRunning(true);
366 totallyPreCompItem->setSaturationComputationRunning(true);
367 workTestCreated = true;
368 }
369 }
370
371
372 if (totallyPreCompItem->hasConceptSaturationPrecomputationChecked() && !totallyPreCompItem->isSaturationComputationRunning()) {
373 totallyPreCompItem->setSaturationStepRunning(false);
374 if (totallyPreCompItem->requiresAllConceptsSaturation()) {
375 LOG(INFO,getLogDomain(),logTr("Concept saturation finished."),this);
376 totallyPreCompItem->getSaturationPrecomputationStep()->setStepFinished(true);
377 }
378
379 CPrecomputation* precomputation = totallyPreCompItem->getPrecomputation();
380 CSaturationData* saturationData = totallyPreCompItem->getSaturationData();
381
382
383 if (totallyPreCompItem->failAfterConceptSaturation()) {
384 totallyPreCompItem->getSaturationPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED);
385 failDebug |= true;
386 } else {
387
388 if (!saturationData) {
389 LOG(ERROR,getLogDomain(),logTr("Unknow error in computation, tableau saturation for ontology '%1' failed.").arg(ontPreCompItem->getOntology()->getTerminologyName()),getLogObject());
390 totallyPreCompItem->getSaturationPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED | COntologyProcessingStatus::PSFAILEDREQUIREMENT);
391 } else {
392
393 #ifdef KONCLUDE_PRECOMPUTATION_SATURATION_STATISTIC_OUTPUT
394 logSaturationInfos(totallyPreCompItem);
395 #endif
396 extractCommonDisjunctConceptsFromPrecomputedSaturation(totallyPreCompItem);
397
398 totallyPreCompItem->getSaturationPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSSUCESSFULL);
399 }
400 }
401 }
402
403 } else {
404 totallyPreCompItem->getSaturationPrecomputationStep()->setStepFinished(true);
405 totallyPreCompItem->getSaturationPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED | COntologyProcessingStatus::PSFAILEDREQUIREMENT);
406 }
407 } else {
408 totallyPreCompItem->getSaturationPrecomputationStep()->submitRequirementsUpdate();
409 }
410 }
411
412
413
414
415
416
417
418
419
420
421 if (!workTestCreated && totallyPreCompItem->isCycleStepRequired() && totallyPreCompItem->isConsistenceStepFinished() && !totallyPreCompItem->isSaturationStepRunning() && !totallyPreCompItem->isIndividualComputationRunning() && !totallyPreCompItem->isSaturationComputationRunning()) {
422 if (!totallyPreCompItem->isCycleStepFinished()) {
423 if (totallyPreCompItem->areCycleStepProcessingRequirementSatisfied()) {
424 if (!totallyPreCompItem->hasConceptCyclePrecomputationChecked()) {
425 if (!totallyPreCompItem->hasConceptCyclePrecomputationInitialized()) {
426 CConcreteOntology* ontology = totallyPreCompItem->getOntology();
427 COntologyCoreConceptCyclesData* coreConceptCycles = ontology->getCoreConceptCyclesData();
428 bool hasConceptCycles = false;
429 if (coreConceptCycles) {
430 CBOXLIST<CConceptCycleData*>* coreConceptCycleList = coreConceptCycles->getConceptCycleList();
431 for (CBOXLIST<CConceptCycleData*>::const_iterator it = coreConceptCycleList->constBegin(), itEnd = coreConceptCycleList->constEnd(); it != itEnd; ++it) {
432 CConceptCycleData* conCycleData = *it;
433 if (mReuseCompletionGraphCacheWriter) {
434 totallyPreCompItem->addRemainingConceptCyclePrecomputation(conCycleData);
435 hasConceptCycles = true;
436 }
437 }
438 }
439
440 cint64 conceptCount = totallyPreCompItem->getOntology()->getTBox()->getConceptCount();
441 cint64 minSizeCount = qMax<cint64>(conceptCount*0.001,50);
442 totallyPreCompItem->setMinConceptCycleTestSize(minSizeCount);
443 totallyPreCompItem->setConceptCyclePrecomputationInitialized(true);
444 if (!hasConceptCycles) {
445 totallyPreCompItem->setConceptCyclePrecomputationChecked(true);
446 }
447 }
448
449 if (totallyPreCompItem->hasRemainingConceptCyclePrecomputation()) {
450 CConcreteOntology* ontology = totallyPreCompItem->getOntology();
451 COntologyCoreConceptCyclesData* coreConceptCycles = ontology->getCoreConceptCyclesData();
452 QList<CConceptCycleData*>* remConCycPreTestList = totallyPreCompItem->getRemainingConceptCyclePrecomputationList();
453 while (!workTestCreated && !remConCycPreTestList->isEmpty()) {
454 CConceptCycleData* conceptCycleData = remConCycPreTestList->takeFirst();
455 if (conceptCycleData->hasNominalConnection()) {
456 workTestCreated = createConceptCyclePrecomputation(conceptCycleData,totallyPreCompItem);
457 if (workTestCreated) {
458 LOG(INFO,getLogDomain(),logTr("Precompute core concept cycle '%1' of '%2' with '%3' concepts.").arg(conceptCycleData->getCycleID()).arg(coreConceptCycles->getConceptCycleCount()).arg(conceptCycleData->getConceptCount()),this);
459 }
460 }
461 }
462 }
463
464 if (!workTestCreated) {
465 if (!totallyPreCompItem->hasRemainingConceptCyclePrecomputation() && !totallyPreCompItem->hasCurrentPrecomputationTesting()) {
466 totallyPreCompItem->setConceptCyclePrecomputationChecked(true);
467 }
468 }
469 }
470
471 if (!workTestCreated) {
472 if (totallyPreCompItem->hasConceptCyclePrecomputationChecked()) {
473 totallyPreCompItem->getCyclePrecomputationStep()->setStepFinished(true);
474 totallyPreCompItem->getCyclePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSSUCESSFULL);
475 }
476 }
477 } else {
478 totallyPreCompItem->getCyclePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED | COntologyProcessingStatus::PSFAILEDREQUIREMENT);
479 totallyPreCompItem->getCyclePrecomputationStep()->setStepFinished(true);
480 }
481 } else {
482 totallyPreCompItem->getCyclePrecomputationStep()->submitRequirementsUpdate();
483 }
484 }
485
486
487 if (!workTestCreated) {
488 if (!totallyPreCompItem->hasRemainingProcessingRequirements()) {
489 finishOntologyPrecomputation(totallyPreCompItem);
490 mProcessingOntItemList.removeFirst();
491 } else {
492 mProcessingOntItemList.removeFirst();
493 mProcessingOntItemList.append(totallyPreCompItem);
494 loopOntPreCompItem = ontPreCompItem;
495 }
496 }
497 }
498 return workTestCreated;
499 }
500
501
502
503
504
505
506 void CTotallyPrecomputationThread::extractCommonDisjunctConceptsFromPrecomputedSaturation(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
507 LOG(INFO,getLogDomain(),logTr("Extract common disjunct concepts."),this);
508 CSaturationCommonDisjunctConceptsExtractor satCommonDisjConExt;
509 satCommonDisjConExt.extractCommonDisjunctConcepts(totallyPreCompItem->getOntology(),totallyPreCompItem->getSaturationData(),totallyPreCompItem->getSaturatedDisjunctionSet());
510 }
511
512
513
514 bool CTotallyPrecomputationThread::isAllAssertionIndividualSaturationSufficient(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
515 if (!totallyPreCompItem->hasAllAssertionIndividualSufficientSaturationChecked()) {
516 CIndividual* allAssertionIndi = totallyPreCompItem->getAllAssertionIndividual();
517 bool saturationSufficient = false;
518
519 if (allAssertionIndi) {
520 CSaturationData* saturationData = totallyPreCompItem->getSaturationData();
521 CSaturationTaskData* satTaskData = (CSaturationTaskData*)saturationData;
522 if (satTaskData) {
523 CSatisfiableCalculationTask* satCalcTask = satTaskData->getSaturationTask();
524 if (satCalcTask) {
525 CProcessingDataBox* procDataBox = satCalcTask->getProcessingDataBox();
526 if (procDataBox) {
527 CIndividualSaturationProcessNodeVector* satIndiNodeVec = procDataBox->getIndividualSaturationProcessNodeVector(false);
528 if (satIndiNodeVec) {
529 CIndividualSaturationProcessNode* allAssertionIndiNode = satIndiNodeVec->getData(allAssertionIndi->getIndividualID());
530 if (allAssertionIndiNode) {
531 CIndividualSaturationProcessNodeStatusFlags* indFlags = allAssertionIndiNode->getIndirectStatusFlags();
532 CIndividualSaturationProcessNodeStatusFlags* dirFlags = allAssertionIndiNode->getDirectStatusFlags();
533 if (!indFlags->hasClashedFlag() && indFlags->hasCompletedFlag() && dirFlags->hasCompletedFlag() && !indFlags->hasInsufficientFlag()) {
534 saturationSufficient = true;
535 }
536 }
537 }
538 }
539 }
540 }
541 }
542 if (saturationSufficient) {
543 totallyPreCompItem->setAllAssertionIndividualSaturationSufficient(true);
544 }
545 totallyPreCompItem->setAllAssertionIndividualSufficientSaturationChecked(true);
546 }
547 return totallyPreCompItem->isAllAssertionIndividualSaturationSufficient();
548 }
549
550
551 void CTotallyPrecomputationThread::logSaturationInfos(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
552 CConcreteOntology* ontology = totallyPreCompItem->getOntology();
553 CSaturationData* saturationData = totallyPreCompItem->getSaturationData();
554 CSaturationTaskData* satTaskData = (CSaturationTaskData*)saturationData;
555 if (satTaskData) {
556 CSatisfiableCalculationTask* satCalcTask = satTaskData->getSaturationTask();
557 if (satCalcTask) {
558 CProcessingDataBox* procDataBox = satCalcTask->getProcessingDataBox();
559 if (procDataBox) {
560 CIndividualSaturationProcessNodeVector* satIndiNodeVec = procDataBox->getIndividualSaturationProcessNodeVector(false);
561 if (satIndiNodeVec) {
562 cint64 saturatedCount = 0;
563 cint64 insufficientCount = 0;
564 cint64 criticalCount = 0;
565 cint64 clashedCount = 0;
566 cint64 indiCount = satIndiNodeVec->getItemCount();
567 for (cint64 indiID = 0; indiID < indiCount; ++indiID) {
568 CIndividualSaturationProcessNode* indiNode = satIndiNodeVec->getData(indiID);
569 if (indiNode && indiNode->isCompleted()) {
570 ++saturatedCount;
571 CIndividualSaturationProcessNodeStatusFlags* flags = indiNode->getIndirectStatusFlags();
572 if (flags->hasClashedFlag()) {
573 ++clashedCount;
574 }
575 if (flags->hasInsufficientFlag()) {
576 ++insufficientCount;
577 }
578 if (flags->hasCriticalFlag()) {
579 ++criticalCount;
580 }
581 }
582 }
583 LOG(INFO,getLogDomain(),logTr("Saturated %1 individual nodes, thereof %2 with clashes, %3 critical and %4 insufficient.").arg(saturatedCount).arg(clashedCount).arg(criticalCount).arg(insufficientCount),this);
584 }
585 }
586 }
587 }
588 }
589
590
591 bool CTotallyPrecomputationThread::createConceptCyclePrecomputation(CConceptCycleData* conceptCycleData, CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
592 CConcreteOntology* onto = totallyPreCompItem->getOntology();
593 CConcept* repCycleClassConcept = conceptCycleData->getRepresentativeCycleClass();
594
595 if (repCycleClassConcept) {
596
597 CSaturationConceptDataItem* conSatItem = totallyPreCompItem->getSaturationConceptDataItem(repCycleClassConcept,false,false);
598 if (conSatItem) {
599 CIndividualSaturationProcessNode* satNode = (CIndividualSaturationProcessNode*)conSatItem->getIndividualProcessNodeForConcept();
600 if (!satNode->getIndirectStatusFlags()->hasInsufficientFlag()) {
601 return false;
602 }
603 }
604
605 if (conceptCycleData->getConceptCount() >= totallyPreCompItem->getMinConceptCycleTestSize()) {
606
607 CConceptCyclePrecomputationTestingItem* conCycPrecTestItem = new CConceptCyclePrecomputationTestingItem(conceptCycleData,totallyPreCompItem);
608
609 CSatisfiableCalculationJobGenerator satCalcJobGen(onto);
610 CSatisfiableCalculationJob* satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(repCycleClassConcept);
611 CCalculationConfigurationExtension* calcConfig = totallyPreCompItem->getCalculationConfiguration();
612 satCalcJob->setCalculationConfiguration(calcConfig);
613 satCalcJob->setSatisfiableTaskPreyingAdapter(conCycPrecTestItem->getTaskPreyingAdapter());
614
615 processCalculationJob(satCalcJob,totallyPreCompItem,conCycPrecTestItem);
616 return true;
617 }
618 }
619 return false;
620 }
621
622
623
624
625
626 QList<CIndividualReference> CTotallyPrecomputationThread::getIndividualComputationList(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
627 QList<CIndividualReference> indiList;
628 CConcreteOntology* onto = totallyPreCompItem->getOntology();
629
630 CIndividualVector* indiVec = onto->getABox()->getIndividualVector(false);
631 QSet<CIndividual*>* activeIndiSet = onto->getABox()->getActiveIndividualSet(false);
632 cint64 indiCount = 0;
633 if (indiVec) {
634 indiCount = indiVec->getItemCount();
635 }
636
637 bool allIndiProRequired = true;
638 QSet<CIndividualReference>* procReqIndiSet = procReqIndiSet = totallyPreCompItem->getIncompletelyHandledIndividualSet();
639 cint64 maxTriplesIndexedIndiId = -1;
640 cint64 maxABoxIndiId = 0;
641 COntologyTriplesAssertionsAccessor* triplesAccessor = totallyPreCompItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor();
642 if (triplesAccessor) {
643 maxTriplesIndexedIndiId = totallyPreCompItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor()->getMaxIndexedIndividualId();
644 }
645 if (indiVec) {
646 cint64 indiCount = indiVec->getItemCount();
647 for (cint64 idx = 0; idx < indiCount; ++idx) {
648 CIndividual* indi = indiVec->getData(idx);
649 if (allIndiProRequired || procReqIndiSet && procReqIndiSet->contains(CIndividualReference(idx))) {
650 if (indi && activeIndiSet->contains(indi)) {
651 indiList.append(CIndividualReference(indi));
652 }
653 else if (idx <= maxTriplesIndexedIndiId) {
654 indiList.append(CIndividualReference(idx));
655 }
656 }
657 maxABoxIndiId = qMax(idx, maxABoxIndiId);
658 }
659 }
660 for (cint64 idx = maxABoxIndiId + 1; idx <= maxTriplesIndexedIndiId; ++idx) {
661 if (allIndiProRequired || procReqIndiSet && procReqIndiSet->contains(CIndividualReference(idx))) {
662 indiList.append(CIndividualReference(idx));
663 }
664 }
665
666 return indiList;
667 }
668
669
670
671
672 QList<CIndividualReference> CTotallyPrecomputationThread::getNextIndividualComputationPartList(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
673 QList<CIndividualReference> indiList;
674 CIndividualPrecomputationCoordinationHash* precomputationProcessingCoordinationHash = totallyPreCompItem->getPrecomputationProcessingCoordinationHash();
675
676 bool compuation = false;
677 bool forceCompuation = false;
678 cint64 computationLimit = totallyPreCompItem->getCurrentIncompletelyHandledIndividualComputationLimit();
679 cint64 reducedComputationLimit = computationLimit * totallyPreCompItem->getBasicPrecompuationSubsequentIndividualLimitReductionFactor();
680
681 if (totallyPreCompItem->hadBasicPrecompuationMode() && precomputationProcessingCoordinationHash->hasBasicPrecomputationFinished()) {
682 totallyPreCompItem->setBasicPrecompuationParallelizationReductionFactor(totallyPreCompItem->getBasicPrecompuationParallelizationInitializationFactor());
683 totallyPreCompItem->setBasicPrecompuationSubsequentIndividualLimitReductionFactor(totallyPreCompItem->getBasicPrecompuationSubsequentIndividualLimitReductionInitializationFactor());
684 reducedComputationLimit = computationLimit * totallyPreCompItem->getBasicPrecompuationSubsequentIndividualLimitReductionFactor();
685 precomputationProcessingCoordinationHash->setBasicPrecomputationFinished(false);
686 totallyPreCompItem->setBasicPrecompuationMode(true);
687 }
688
689 if (totallyPreCompItem->getCurrentRecomputationExpansionPropagationCuttedReductionFactor() > 0) {
690 cint64 propCutReductionCount = computationLimit * totallyPreCompItem->getCurrentRecomputationExpansionPropagationCuttedReductionFactor();
691 reducedComputationLimit -= propCutReductionCount;
692 reducedComputationLimit = qMax(reducedComputationLimit, (cint64)1);
693 }
694
695 if (totallyPreCompItem->getBasicPrecompuationParallelizationReductionFactor() > 0) {
696 if (totallyPreCompItem->getIndividualComputationRunningCount() >= 1 && totallyPreCompItem->getIndividualComputationRunningCount() >= totallyPreCompItem->getBasicPrecompuationParallelizationReductionFactor()) {
697 return indiList;
698 }
699 }
700
701
702 cint64 approxRemainingIncHandIndiCount = precomputationProcessingCoordinationHash->getApproximateRemainingIncompletelyHandledCount();
703 if (precomputationProcessingCoordinationHash->hasBasicPrecomputationMode()) {
704 compuation = true;
705 forceCompuation = true;
706 totallyPreCompItem->setBasicPrecompuationMode(true);
707 } else if (approxRemainingIncHandIndiCount > reducedComputationLimit) {
708 compuation = true;
709 } else {
710 if (!totallyPreCompItem->isPrecompuationRetrievingIncompletelyHandledIndividuals() && !totallyPreCompItem->isIndividualComputationRunning() && !totallyPreCompItem->isPrecompuationRetrievingIncompletelyHandledIndividuals()) {
711 retrieveIndividualsPrecomputation(totallyPreCompItem);
712 precomputationProcessingCoordinationHash = totallyPreCompItem->getPrecomputationProcessingCoordinationHash();
713 if (precomputationProcessingCoordinationHash->getHashRemainingCount() <= 0 && precomputationProcessingCoordinationHash->getApproximateTotalIncompletelyHandledCount() <= 0) {
714 QTime* indiPrecTimer = totallyPreCompItem->getIndividualPrecomputationTime();
715 LOG(INFO, getLogDomain(), logTr("Finished insufficiently handled individual reprocessing with representative cache in %1 ms.").arg(indiPrecTimer->elapsed()), getLogObject());
716 totallyPreCompItem->setAllIncompletelyHandledIndividualsRetrieved(true);
717 decrementUsageFromIndividualPrecomputationCoordinationHash(precomputationProcessingCoordinationHash, totallyPreCompItem);
718 precomputationProcessingCoordinationHash = nullptr;
719 totallyPreCompItem->setPrecomputationProcessingCoordinationHash(nullptr);
720 } else {
721 totallyPreCompItem->incNonPrecompuationDirectIncompletelyHandledIndividualsRetrievingStreakSize();
722 forceCompuation = true;
723 compuation = true;
724 }
725 }
726 }
727
728
729
730 if (forceCompuation || (compuation && precomputationProcessingCoordinationHash && precomputationProcessingCoordinationHash->getHashRemainingCount() >= reducedComputationLimit || compuation && approxRemainingIncHandIndiCount > reducedComputationLimit && !totallyPreCompItem->isIndividualComputationRunning())) {
731 CIndividualPrecomputationCoordinationHash* precomputationProcessingCoordinationHash = totallyPreCompItem->getPrecomputationProcessingCoordinationHash();
732 CIndividualPrecomputationCoordinationHash::const_iterator itCurr = totallyPreCompItem->getPrecomputationProcessingCoordinationHashIteratorCurrent();
733 CIndividualPrecomputationCoordinationHash::const_iterator itEnd = totallyPreCompItem->getPrecomputationProcessingCoordinationHashIteratorEnd();
734 cint64 currentCount = 0;
735 while (currentCount < reducedComputationLimit && itCurr != itEnd && precomputationProcessingCoordinationHash->getHashRemainingCount() > 0) {
736 cint64 indiId = itCurr.key();
737 CBackendIndividualRetrievalComputationUpdateCoordinationHashData* data = itCurr.value();
738 if (!data->isProcessed()) {
739 if (!data->isComputationIntegrated() && !data->isComputationOrdered()) {
740 data->setComputationOrdered(true);
741 ++currentCount;
742 indiList.append(indiId);
743 precomputationProcessingCoordinationHash->decHashRemainingCount();
744 precomputationProcessingCoordinationHash->incHashComputationCount();
745 totallyPreCompItem->setNonPrecompuationDirectIncompletelyHandledIndividualsRetrievingStreakSize(0);
746 } else if (data->isComputationIntegrated() && !data->isComputationOrdered()) {
747 data->setProcessed(true);
748 precomputationProcessingCoordinationHash->incHashProcessedCount();
749 precomputationProcessingCoordinationHash->decHashRemainingCount();
750 }
751 }
752 ++itCurr;
753 }
754 if (itCurr == itEnd) {
755 precomputationProcessingCoordinationHash->setHashRemainingCount(0);
756 }
757 }
758
759
760 if ((indiList.isEmpty()
761 || !forceCompuation && precomputationProcessingCoordinationHash->getHashRemainingCount() <= reducedComputationLimit && precomputationProcessingCoordinationHash->getApproximateRemainingIncompletelyHandledCount() > reducedComputationLimit
762 || !forceCompuation && precomputationProcessingCoordinationHash->getHashRemainingCount() <= totallyPreCompItem->getCurrentIncompletelyHandledIndividualRetrievalThreshold() && !totallyPreCompItem->isPrecompuationIncompletelyHandledIndividualsRetrievalThresholdRequested() && precomputationProcessingCoordinationHash->getApproximateRemainingIncompletelyHandledCount() > computationLimit)
763 && !totallyPreCompItem->hasAllIncompletelyHandledIndividualsRetrieved()) {
764
765 if (precomputationProcessingCoordinationHash->getHashRemainingCount() <= totallyPreCompItem->getCurrentIncompletelyHandledIndividualRetrievalThreshold()) {
766 totallyPreCompItem->setPrecompuationIncompletelyHandledIndividualsRetrievalThresholdRequested(true);
767 }
768
769 requestIndividualsPrecomputationRetrieval(totallyPreCompItem, true);
770 }
771
772 return indiList;
773 }
774
775
776 bool CTotallyPrecomputationThread::createIndividualPrecomputationCheck(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
777 CConcreteOntology* onto = totallyPreCompItem->getOntology();
778 CSatisfiableCalculationJob* satCalcJob = nullptr;
779
780 bool fullCompletionGraphConstruction = totallyPreCompItem->isFullCompletionGraphConstruction();
781 if (!fullCompletionGraphConstruction && !totallyPreCompItem->hasIndividualsSaturated()) {
782 fullCompletionGraphConstruction = true;
783 totallyPreCompItem->setFullCompletionGraphConstruction(true);
784 }
785 if (totallyPreCompItem->hasIndividualsSaturationCacheSynchronisation() && totallyPreCompItem->hasIndividualsSaturated() && totallyPreCompItem->hasALLIndividualsSaturationOrderd() && totallyPreCompItem->hasInsufficientSaturationIndividuals()) {
786 if (!fullCompletionGraphConstruction) {
787 if (!totallyPreCompItem->hasIndividualPrecomputationChecked()) {
788
789 QList<CIndividualReference> indiList;
790 indiList = getNextIndividualComputationPartList(totallyPreCompItem);
791
792 if (!indiList.isEmpty()) {
793 CIndividualPrecomputationCoordinationHash* precomputationProcessingCoordinationHash = totallyPreCompItem->getPrecomputationProcessingCoordinationHash();
794
795
796 cint64 minIndiId = CINT64_MAX;
797
798 QList<CIndividualReference> filteredIndiList = indiList;
799 QSet<CIndividualReference>* currentIndiComputationSet = totallyPreCompItem->getCurrentIndividualComputationSet();
800 for (CIndividualReference indiRef : indiList) {
801 minIndiId = qMin(minIndiId, indiRef.getIndividualID());
802 //filteredIndiList.append(indiRef);
803 //currentIndiComputationSet->insert(indiRef);
804 }
805
806 cint64 indiCompCount = filteredIndiList.size();
807 cint64 remainingLimitIncreasingIndiCompCount = totallyPreCompItem->getRemainingIncompletelyHandlingIndividualComputationLimitIncreasingCount();
808 remainingLimitIncreasingIndiCompCount -= indiCompCount;
809 cint64 currentIndiCompLimit = totallyPreCompItem->getCurrentIncompletelyHandledIndividualComputationLimit();
810 if (totallyPreCompItem->getBasicPrecompuationSubsequentIndividualLimitReductionFactor() < 1.) {
811 totallyPreCompItem->setBasicPrecompuationSubsequentIndividualLimitReductionFactor(totallyPreCompItem->getBasicPrecompuationSubsequentIndividualLimitReductionFactor() * totallyPreCompItem->getBasicPrecompuationSubsequentIndividualLimitReductionIncreasingFactor());
812 } else if (remainingLimitIncreasingIndiCompCount < 0) {
813 remainingLimitIncreasingIndiCompCount = 0;
814
815 double limitIncreasingFactor = totallyPreCompItem->getIncompletelyHandlingIndividualComputationLimitIncreasingFactor();
816
817 currentIndiCompLimit *= limitIncreasingFactor;
818 if (currentIndiCompLimit < 0) {
819 currentIndiCompLimit = CINT64_MAX;
820 }
821 totallyPreCompItem->setCurrentIncompletelyHandledIndividualComputationLimit(currentIndiCompLimit);
822
823 cint64 currentRetrievalLimit = totallyPreCompItem->getCurrentIncompletelyHandledIndividualRetrievalLimit();
824 currentRetrievalLimit *= limitIncreasingFactor;
825 if (currentRetrievalLimit < 0) {
826 currentRetrievalLimit = CINT64_MAX;
827 }
828 totallyPreCompItem->setCurrentIncompletelyHandledIndividualRetrievalLimit(currentRetrievalLimit);
829
830 }
831 totallyPreCompItem->setRemainingIncompletelyHandlingIndividualComputationLimitIncreasingCount(remainingLimitIncreasingIndiCompCount);
832
833 if (totallyPreCompItem->getBasicPrecompuationParallelizationReductionFactor() > 0) {
834 totallyPreCompItem->setBasicPrecompuationParallelizationReductionFactor(totallyPreCompItem->getBasicPrecompuationParallelizationReductionFactor() * totallyPreCompItem->getBasicPrecompuationParallelizationIncreasingFactor());
835 }
836
837 CSatisfiableCalculationJobGenerator satCalcJobGen(onto);
838 satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(QList<CIndividual*>());
839
840 CIndividualPrecomputationTestingItem* indiTestItem = new CIndividualPrecomputationTestingItem(totallyPreCompItem, precomputationProcessingCoordinationHash, totallyPreCompItem, totallyPreCompItem->getIndividualPrecomputationClashedPointer(), totallyPreCompItem->getIndividualPrecomputationExpansionLimitedReachedPointer());
841 if (precomputationProcessingCoordinationHash) {
842 precomputationProcessingCoordinationHash->incUsageCount();
843 }
844 indiTestItem->addIndividualComputations(filteredIndiList);
845 CCalculationConfigurationExtension* calcConfig = totallyPreCompItem->getCalculationConfiguration();
846 satCalcJob->setCalculationConfiguration(calcConfig);
847 CSatisfiableTaskRepresentativeBackendUpdatingAdapter* repCacheUpdAdapter = indiTestItem->getRepresentativeCacheUpdatingAdapter();
848 if (filteredIndiList.size() < currentIndiCompLimit) {
849 repCacheUpdAdapter->setAdditionalIndividualComputationSize(currentIndiCompLimit - filteredIndiList.size());
850 }
851 repCacheUpdAdapter->setFirstIndividualRecomputationId(minIndiId);
852 repCacheUpdAdapter->setRepresentativeCacheRecomputationId(totallyPreCompItem->getNextRepresentativeCacheRecomputationId());
853 satCalcJob->setSatisfiableRepresentativeBackendCacheUpdatingAdapter(repCacheUpdAdapter);
854 CIndividual* allAssertionIndi = totallyPreCompItem->getAllAssertionIndividual();
855 if (allAssertionIndi) {
856 repCacheUpdAdapter->setAllAssertionIndividualId(allAssertionIndi->getIndividualID());
857 }
858 QMap<cint64, CIndividualPrecomputationTestingItem*>* recomIdTestingItemMap = totallyPreCompItem->getRecomputationIdTestingItemMap();
859 recomIdTestingItemMap->insert(repCacheUpdAdapter->getRepresentativeCacheRecomputationId(), indiTestItem);
860
861
862 LOG(INFO, getLogDomain(), logTr("Scheduled precomputation of next %1 of approximately %2/%3 remaining insufficiently handled individuals (%4 batchs queued, %5 computing, %6 processed).").arg(filteredIndiList.size()).arg(filteredIndiList.size() + precomputationProcessingCoordinationHash->getHashRemainingCount()).arg(filteredIndiList.size() + precomputationProcessingCoordinationHash->getApproximateRemainingIncompletelyHandledCount()).arg(mCurrRunningTestParallelCount + 1).arg(precomputationProcessingCoordinationHash->getHashComputationCount()).arg(precomputationProcessingCoordinationHash->getHashProcessedCount()), getLogObject());
863
864 processCalculationJob(satCalcJob, totallyPreCompItem, indiTestItem);
865 return true;
866 }
867
868 }
869 }
870 }
871 return false;
872 }
873
874
875
876
877
878
879
880
881
882 bool CTotallyPrecomputationThread::createConsistencePrecomputationCheck(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
883 CConcreteOntology* onto = totallyPreCompItem->getOntology();
884 CSatisfiableCalculationJob* satCalcJob = nullptr;
885
886 CIndividualVector* indiVec = onto->getABox()->getIndividualVector(false);
887 QSet<CIndividual*>* activeIndiSet = onto->getABox()->getActiveIndividualSet(false);
888 cint64 indiCount = 0;
889 if (indiVec) {
890 indiCount = indiVec->getItemCount();
891 }
892 cint64 maxTriplesIndexedIndiId = -1;
893 COntologyTriplesAssertionsAccessor* triplesAccessor = totallyPreCompItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor();
894 if (triplesAccessor) {
895 maxTriplesIndexedIndiId = totallyPreCompItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor()->getMaxIndexedIndividualId();
896 }
897
898
899 bool forceCompletionGraphConstruction = totallyPreCompItem->isForceCompletionGraphConstruction();
900 bool fullCompletionGraphConstruction = totallyPreCompItem->isFullCompletionGraphConstruction();
901 bool consistencyDetected = false;
902 bool detectedConsistency = true;
903 QSet<CIndividualReference>* procReqIndiSet = procReqIndiSet = totallyPreCompItem->getIncompletelyHandledIndividualSet();
904 if (!procReqIndiSet->isEmpty()) {
905 forceCompletionGraphConstruction = true;
906 }
907 if (!forceCompletionGraphConstruction && isAllAssertionIndividualSaturationSufficient(totallyPreCompItem)) {
908 consistencyDetected = true;
909 detectedConsistency = true;
910 LOG(INFO,getLogDomain(),logTr("Trivial consistency detected with merged individual."),getLogObject());
911 } else if (totallyPreCompItem->hasClashedSaturationIndividuals()) {
912 consistencyDetected = true;
913 detectedConsistency = false;
914 LOG(INFO,getLogDomain(),logTr("Trivial inconsistency detected with individual saturation."),getLogObject());
915 } else if (!forceCompletionGraphConstruction && totallyPreCompItem->hasIndividualsSaturated() && !totallyPreCompItem->hasInsufficientSaturationIndividuals() && (indiCount > 0 || maxTriplesIndexedIndiId > 0)) {
916 consistencyDetected = true;
917 detectedConsistency = true;
918 LOG(INFO,getLogDomain(),logTr("Trivial consistency detected with individual saturation."),getLogObject());
919 } else if (!fullCompletionGraphConstruction && totallyPreCompItem->hasIndividualsSaturated() && totallyPreCompItem->hasAllIncompletelyHandledIndividualsRetrieved() && (indiCount > 0 || maxTriplesIndexedIndiId > 0)) {
920 consistencyDetected = true;
921 detectedConsistency = !totallyPreCompItem->hasIndividualPrecomputationClashed();
922 if (detectedConsistency) {
923 LOG(INFO, getLogDomain(), logTr("Consistency detected with individual precomputation."), getLogObject());
924 } else {
925 LOG(INFO, getLogDomain(), logTr("Inconsistency detected with individual precomputation."), getLogObject());
926 }
927 } else if (totallyPreCompItem->hasIndividualPrecomputationClashed()) {
928 consistencyDetected = true;
929 detectedConsistency = false;
930 LOG(INFO, getLogDomain(), logTr("Inconsistency detected with individual precomputation."), getLogObject());
931 } else {
932 QList<CIndividualReference> indiList;
933 if (!fullCompletionGraphConstruction && procReqIndiSet) {
934 indiList = procReqIndiSet->toList();
935 procReqIndiSet->clear();
936 } else {
937 indiList = getIndividualComputationList(totallyPreCompItem);
938 }
939 totallyPreCompItem->setAllIncompletelyHandledIndividualsRetrieved(true);
940 totallyPreCompItem->setFullCompletionGraphConstructed(true);
941
942 CSatisfiableCalculationJobGenerator satCalcJobGen(onto);
943 if (indiList.isEmpty()) {
944 CConcept* topConcept = onto->getTBox()->getTopConcept();
945 if (topConcept->getOperandCount() > 0) {
946 satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(topConcept);
947 } else {
948 consistencyDetected = true;
949 detectedConsistency = true;
950 }
951 } else {
952 satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(indiList);
953 }
954 }
955
956
957 CConsistence* consistence = onto->getConsistence();
958 if (!consistence) {
959 consistence = new CConsistence();
960 onto->setConsistence(consistence);
961 }
962 if (totallyPreCompItem->hasIndividualsSaturated() && totallyPreCompItem->hasALLIndividualsSaturationOrderd()) {
963 consistence->setIndividualsRepresentativelyStored(true);
964 if (!totallyPreCompItem->hasInsufficientSaturationIndividuals()) {
965 consistence->setAllIndividualsRepresentativelyStored(true);
966 } else if (totallyPreCompItem->hasAllIndividualPrecomputationCreated()) {
967 consistence->setAllIndividualsRepresentativelyStored(true);
968 }
969 }
970 totallyPreCompItem->setConsistence(consistence);
971
972 if (consistencyDetected) {
973 consistence->setOntologyConsistent(detectedConsistency);
974 totallyPreCompItem->setConsistenceCheched(true);
975 return false;
976 } else {
977 CConsistencePrecomputationTestingItem* consTestItem = new CConsistencePrecomputationTestingItem(totallyPreCompItem,totallyPreCompItem);
978 CCalculationConfigurationExtension* calcConfig = totallyPreCompItem->getCalculationConfiguration();
979 satCalcJob->setCalculationConfiguration(calcConfig);
980 satCalcJob->setSatisfiableTaskPreyingAdapter(consTestItem->getTaskPreyingAdapter());
981
982 processCalculationJob(satCalcJob,totallyPreCompItem,consTestItem);
983 return true;
984 }
985 }
986
987
988
989
990
991 void CTotallyPrecomputationThread::propagateExistInitializationFlag(CSaturationConceptDataItem* ontConSatDataItem) {
992 if (ontConSatDataItem->isPotentiallyExistInitializationConcept()) {
993 CSaturationConceptDataItem* parentOntConceptSatTestItem = ontConSatDataItem->getSpecialItemReference();
994 while (parentOntConceptSatTestItem && !parentOntConceptSatTestItem->isPotentiallyExistInitializationConcept()) {
995 parentOntConceptSatTestItem->setPotentiallyExistInitializationConcept(true);
996 parentOntConceptSatTestItem = parentOntConceptSatTestItem->getSpecialItemReference();
997 }
998 }
999 }
1000
1001
1002 void CTotallyPrecomputationThread::propagateSubsumerItemFlag(CSaturationConceptDataItem* ontClassSatTestItem) {
1003 if (ontClassSatTestItem->hasIndirectSuccessorsItems()) {
1004 CSaturationConceptDataItem* subsumerItem = ontClassSatTestItem->getSpecialItemReference();
1005 while (subsumerItem && !subsumerItem->hasIndirectSuccessorsItems()) {
1006 subsumerItem->setIndirectSuccessorsItems(true);
1007 subsumerItem = subsumerItem->getSpecialItemReference();
1008 }
1009 }
1010 }
1011
1012
1013
1014
1015
1016
1017
1018 void CTotallyPrecomputationThread::analyseConceptSaturationSubsumerExistItems(CTotallyOntologyPrecomputationItem* totallyPreCompItem, QList<CConceptNegationSaturationItem>& processList) {
1019
1020 QSet<CConceptNegationSaturationItem> processSet;
1021 for (QList<CConceptNegationSaturationItem>::const_iterator it = processList.constBegin(), itEnd = processList.constEnd(); it != itEnd; ++it) {
1022 CConceptNegationSaturationItem conNegSatItem(*it);
1023 processSet.insert(conNegSatItem);
1024 }
1025
1026 while (!processList.isEmpty()) {
1027 CConceptNegationSaturationItem conNegSatItem(processList.takeLast());
1028 CConcept* concept = conNegSatItem.getConcept();
1029 bool negated = conNegSatItem.getNegation();
1030 CSaturationConceptDataItem* ontConSatDataItem = conNegSatItem.getSaturationConceptDataItem();
1031 cint64 nOpCode = concept->getOperatorCode();
1032 cint64 opCount = concept->getOperandCount();
1033 if (!negated && (nOpCode == CCAND || nOpCode == CCSUB || nOpCode == CCEQ || ((nOpCode == CCOR) && opCount == 1)) || negated && (nOpCode == CCOR || ((nOpCode == CCAND || nOpCode == CCEQ) && opCount == 1))) {
1034
1035 CSortedNegLinker<CConcept*>* opConIt = concept->getOperandList();
1036 while (opConIt) {
1037 CConcept* opConcept = opConIt->getData();
1038 bool opNegation = opConIt->isNegated()^negated;
1039 cint64 opConOpCode = opConcept->getOperatorCode();
1040 if (!opNegation && (opConOpCode == CCEQ || opConOpCode == CCSUB || opConOpCode == CCATOM && opConcept->hasClassName())) {
1041 CSaturationConceptDataItem* subsumerClassTestItem = totallyPreCompItem->getSaturationConceptDataItem(opConcept,opNegation,false);
1042 subsumerClassTestItem->setIndirectSuccessorsItems(true);
1043 if (!ontConSatDataItem->getSpecialItemReference() && !ontConSatDataItem->isInvalidSpecialItemReference()) {
1044 ontConSatDataItem->setSpecialItemReference(subsumerClassTestItem);
1045 } else {
1046 ontConSatDataItem->setMultipleDirectPredecessorsItems(true);
1047 }
1048 } else if (!opNegation && opConOpCode == CCAND || opNegation && opConOpCode == CCOR) {
1049 if (opConcept->getOperandCount() > 1) {
1050 ontConSatDataItem->setMultipleDirectPredecessorsItems(true);
1051 }
1052 if (!processSet.contains(CConceptNegationSaturationItem(opConcept,opNegation,ontConSatDataItem))) {
1053 processSet.insert(CConceptNegationSaturationItem(opConcept,opNegation,ontConSatDataItem));
1054 processList.append(CConceptNegationSaturationItem(opConcept,opNegation,ontConSatDataItem));
1055 }
1056
1057 } else if ((!opNegation && (opConOpCode == CCSOME || opConOpCode == CCAQSOME)) || opNegation && opConOpCode == CCALL) {
1058 CRole* role = opConcept->getRole();
1059 CConcept* existConcept = opConcept->getOperandList()->getData();
1060 bool existConNegation = opConcept->getOperandList()->isNegated()^opNegation;
1061 CSaturationConceptDataItem* existConceptTestItem = nullptr;
1062 if (hasRoleRanges(totallyPreCompItem,role)) {
1063 existConceptTestItem = totallyPreCompItem->getSaturationRoleSuccessorConceptDataItem(role,existConcept,existConNegation,false);
1064 } else {
1065 existConceptTestItem = totallyPreCompItem->getSaturationConceptDataItem(existConcept,existConNegation,false);
1066 }
1067 ontConSatDataItem->addExistReferenceConceptItemList(existConceptTestItem);
1068 ontConSatDataItem->setMultipleDirectPredecessorsItems(true);
1069
1070 } else if (negated && opConOpCode == CCATMOST || !negated && opConOpCode == CCATLEAST) {
1071 CRole* role = opConcept->getRole();
1072 CConcept* existConcept = totallyPreCompItem->getOntology()->getTBox()->getTopConcept();
1073 bool existConceptNegation = false;
1074 if (opConcept->getOperandList()) {
1075 existConcept = opConcept->getOperandList()->getData();
1076 existConceptNegation = opConcept->getOperandList()->isNegated();
1077 }
1078 CSaturationConceptDataItem* existConceptTestItem = nullptr;
1079 if (hasRoleRanges(totallyPreCompItem,role)) {
1080 existConceptTestItem = totallyPreCompItem->getSaturationRoleSuccessorConceptDataItem(role,existConcept,existConceptNegation,false);
1081 } else {
1082 existConceptTestItem = totallyPreCompItem->getSaturationConceptDataItem(existConcept,existConceptNegation,false);
1083 }
1084 ontConSatDataItem->addExistReferenceConceptItemList(existConceptTestItem);
1085 ontConSatDataItem->setMultipleDirectPredecessorsItems(true);
1086
1087 } else if (opConOpCode == CCAQCHOOCE) {
1088 CSortedNegLinker<CConcept*>* opOpConIt = opConcept->getOperandList();
1089 while (opOpConIt) {
1090 if (opNegation == opOpConIt->isNegated()) {
1091 CConcept* opOpConcept = opOpConIt->getData();
1092 if (opOpConcept->getOperatorCode() == CCAQSOME) {
1093 CConcept* existConcept = opOpConcept->getOperandList()->getData();
1094 bool existConNegation = opOpConcept->getOperandList()->isNegated();
1095 CRole* role = opOpConcept->getRole();
1096 CSaturationConceptDataItem* existConceptTestItem = nullptr;
1097 if (hasRoleRanges(totallyPreCompItem,role)) {
1098 existConceptTestItem = totallyPreCompItem->getSaturationRoleSuccessorConceptDataItem(role,existConcept,existConNegation,false);
1099 } else {
1100 existConceptTestItem = totallyPreCompItem->getSaturationConceptDataItem(existConcept,existConNegation,false);
1101 }
1102 ontConSatDataItem->addExistReferenceConceptItemList(existConceptTestItem);
1103 ontConSatDataItem->setMultipleDirectPredecessorsItems(true);
1104 } else if (opOpConcept->getOperatorCode() == CCAQAND) {
1105 if (opConcept->getOperandCount() > 1) {
1106 ontConSatDataItem->setMultipleDirectPredecessorsItems(true);
1107 }
1108 if (!processSet.contains(CConceptNegationSaturationItem(opOpConcept,false,ontConSatDataItem))) {
1109 processSet.insert(CConceptNegationSaturationItem(opOpConcept,false,ontConSatDataItem));
1110 processList.append(CConceptNegationSaturationItem(opOpConcept,false,ontConSatDataItem));
1111 }
1112 }
1113 }
1114 opOpConIt = opOpConIt->getNext();
1115 }
1116 } else {
1117 ontConSatDataItem->setMultipleDirectPredecessorsItems(true);
1118 }
1119 opConIt = opConIt->getNext();
1120 }
1121 }
1122 }
1123 }
1124
1125
1126
1127 CConcept* CTotallyPrecomputationThread::getDisjunctCheckingConcept(CConcept* opConcept, bool opConNegation, bool* checkingNegation) {
1128 if (opConcept->getOperatorCode() == CCAQCHOOCE) {
1129 cint64 replaceCount = 0;
1130 CConcept* replaceCheckingConcept = nullptr;
1131 CSortedNegLinker<CConcept*>* opConceptOpLinkerIt = opConcept->getOperandList();
1132 while (opConceptOpLinkerIt) {
1133 CConcept* opOpConcept = opConceptOpLinkerIt->getData();
1134 bool opOpNegation = opConceptOpLinkerIt->isNegated();
1135 if (opOpNegation == opConNegation) {
1136 replaceCheckingConcept = opOpConcept;
1137 replaceCount++;
1138 }
1139 opConceptOpLinkerIt = opConceptOpLinkerIt->getNext();
1140 }
1141
1142 if (replaceCount == 1 && replaceCheckingConcept) {
1143 if (checkingNegation) {
1144 *checkingNegation = false;
1145 }
1146 return replaceCheckingConcept;
1147 }
1148 }
1149 return opConcept;
1150 }
1151
1152
1153 void CTotallyPrecomputationThread::extendDisjunctionsCandidateAlternativesItems(CTotallyOntologyPrecomputationItem* totallyPreCompItem, CSaturationConceptDataItem* ontConSatDataItem, QList<CSaturationConceptDataItem*>* newDisjunctionCandidateAlternativeList) {
1154 CConcept* concept = ontConSatDataItem->getSaturationConcept();
1155 bool negation = ontConSatDataItem->getSaturationNegation();
1156 QList<TConceptNegPair> conNegPairList;
1157
1158 bool directExamine = true;
1159 bool candidateAlternativeExtraction = false;
1160 if (!negation && concept->hasClassName()) {
1161 if (concept->getOperatorCode() == CCEQ) {
1162 //CBOXHASH<CConcept*,CConcept*>* eqConHash = totallyPreCompItem->getOntology()->getTBox()->getEquivalentConceptCandidateHash(false);
1163 //if (eqConHash->contains(concept)) {
1164 candidateAlternativeExtraction = true;
1165 //}
1166 }
1167 for (CSortedNegLinker<CConcept*>* opConIt = concept->getOperandList(); opConIt; opConIt = opConIt->getNext()) {
1168 CConcept* opConcept = opConIt->getData();
1169 bool opNegation = opConIt->isNegated()^negation;
1170 conNegPairList.append(TConceptNegPair(opConcept,opNegation));
1171 directExamine = false;
1172 }
1173 }
1174 if (directExamine) {
1175 conNegPairList.append(TConceptNegPair(concept,negation));
1176 }
1177
1178 while (!conNegPairList.isEmpty()) {
1179 TConceptNegPair nextConNegPair(conNegPairList.takeFirst());
1180 CConcept* nextConcept = nextConNegPair.first;
1181 bool nextNegation = nextConNegPair.second;
1182 cint64 nOpCode = nextConcept->getOperatorCode();
1183 cint64 opCount = nextConcept->getOperandCount();
1184 if (!nextNegation && (nOpCode == CCAND || (nOpCode == CCOR && opCount == 1)) || nextNegation && (nOpCode == CCOR || ((nOpCode == CCAND) && opCount == 1))) {
1185 for (CSortedNegLinker<CConcept*>* opConIt = nextConcept->getOperandList(); opConIt; opConIt = opConIt->getNext()) {
1186 CConcept* opConcept = opConIt->getData();
1187 bool opNegation = opConIt->isNegated()^nextNegation;
1188 conNegPairList.append(TConceptNegPair(opConcept,opNegation));
1189 }
1190
1191 } else if (nOpCode == CCAQCHOOCE) {
1192 for (CSortedNegLinker<CConcept*>* opConIt = nextConcept->getOperandList(); opConIt; opConIt = opConIt->getNext()) {
1193 CConcept* opConcept = opConIt->getData();
1194 bool opNegation = opConIt->isNegated();
1195 if (nextNegation == opNegation) {
1196 conNegPairList.append(TConceptNegPair(opConcept,opNegation));
1197 }
1198 if (candidateAlternativeExtraction && nextNegation != opNegation) {
1199 conNegPairList.append(TConceptNegPair(opConcept,!opNegation));
1200 }
1201 }
1202
1203 } else if (nextNegation && ((nOpCode == CCAND || nOpCode == CCEQ) && opCount > 1) || !nextNegation && nOpCode == CCOR) {
1204 // saturate all disjuncts to extract common concepts from all disjunctions
1205
1206 totallyPreCompItem->addSaturatedDisjunction(nextConcept);
1207
1208 for (CSortedNegLinker<CConcept*>* opConIt = nextConcept->getOperandList(); opConIt; opConIt = opConIt->getNext()) {
1209 CConcept* opConcept = opConIt->getData();
1210 bool opNegation = opConIt->isNegated()^nextNegation;
1211
1212 bool opCheckingNegation = opNegation;
1213 CConcept* opCheckConcept = getDisjunctCheckingConcept(opConcept, opNegation, &opCheckingNegation);
1214
1215 CConceptProcessData* conProcData = (CConceptProcessData*)opCheckConcept->getConceptData();
1216 CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking();
1217 if (!conRefSatLinking) {
1218 conRefSatLinking = new CConceptSaturationReferenceLinkingData();
1219 conProcData->setConceptReferenceLinking(conRefSatLinking);
1220 }
1221 if (conRefSatLinking->getConceptSaturationReferenceLinkingData(opCheckingNegation) == nullptr) {
1222 CSaturationConceptDataItem* conItem = totallyPreCompItem->getSaturationConceptDataItem(opCheckConcept, opCheckingNegation,true);
1223 conRefSatLinking->setSaturationReferenceLinkingData(conItem, opCheckingNegation);
1224 newDisjunctionCandidateAlternativeList->append(conItem);
1225 if (!opCheckConcept->hasClassName() || opCheckingNegation) {
1226 conItem->setInvalidSpecialItemReference(true);
1227 }
1228 }
1229 }
1230
1231
1232 CConceptProcessData* conProcData = (CConceptProcessData*)nextConcept->getConceptData();
1233 CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking();
1234 if (!conRefSatLinking) {
1235 conRefSatLinking = new CConceptSaturationReferenceLinkingData();
1236 conProcData->setConceptReferenceLinking(conRefSatLinking);
1237 }
1238 if (conRefSatLinking->getConceptSaturationReferenceLinkingData(nextNegation) == nullptr) {
1239 CSaturationConceptDataItem* conItem = totallyPreCompItem->getSaturationConceptDataItem(nextConcept,nextNegation,true);
1240 conRefSatLinking->setSaturationReferenceLinkingData(conItem,nextNegation);
1241 newDisjunctionCandidateAlternativeList->append(conItem);
1242 conItem->setInvalidSpecialItemReference(true);
1243 }
1244
1245
1246
1247 } else if (!nextNegation && (nOpCode == CCALL) || nextNegation && (nOpCode == CCSOME || nOpCode == CCAQSOME)) {
1248 if (candidateAlternativeExtraction) {
1249 // saturate pseudo models to invalidate candidates concepts
1250
1251 bool saturateNegation = !nextNegation;
1252
1253 CConceptProcessData* conProcData = (CConceptProcessData*)nextConcept->getConceptData();
1254 CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking();
1255 if (!conRefSatLinking) {
1256 conRefSatLinking = new CConceptSaturationReferenceLinkingData();
1257 conProcData->setConceptReferenceLinking(conRefSatLinking);
1258 }
1259 if (conRefSatLinking->getConceptSaturationReferenceLinkingData(saturateNegation) == nullptr) {
1260 CSaturationConceptDataItem* conItem = totallyPreCompItem->getSaturationConceptDataItem(nextConcept,saturateNegation,true);
1261 conRefSatLinking->setSaturationReferenceLinkingData(conItem,saturateNegation);
1262 newDisjunctionCandidateAlternativeList->append(conItem);
1263 conItem->setInvalidSpecialItemReference(true);
1264 }
1265 }
1266 }
1267 }
1268 }
1269
1270
1271
1272
1273 bool CTotallyPrecomputationThread::saturateRemainingRequiredItems(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
1274 cint64 saturatingConceptCount = 0;
1275 bool allConSaturReq = totallyPreCompItem->requiresAllConceptsSaturation();
1276 QList<TConceptNegPair>* reqConSatList = totallyPreCompItem->getRemainingRequiredSaturationConceptList();
1277 if (allConSaturReq) {
1278 totallyPreCompItem->setAllConceptsSaturationOrdered(true);
1279 QList<CSaturationConceptDataItem*>* satOrderdItemList = totallyPreCompItem->getSaturationOrderedItemList();
1280 for (QList<CSaturationConceptDataItem*>::const_iterator it = satOrderdItemList->constBegin(), itEnd = satOrderdItemList->constEnd(); it != itEnd; ++it) {
1281 CSaturationConceptDataItem* satConItem(*it);
1282 if (!satConItem->isItemProcessingMarked()) {
1283 ++saturatingConceptCount;
1284 satConItem->setItemProcessingMarked(true);
1285 }
1286 }
1287 } else {
1288 for (QList<TConceptNegPair>::const_iterator it = reqConSatList->constBegin(), itEnd = reqConSatList->constEnd(); it != itEnd; ++it) {
1289 const TConceptNegPair& conNegPair(*it);
1290 CConcept* concept(conNegPair.first);
1291 bool negation = conNegPair.second;
1292 saturatingConceptCount += markSaturationProcessingItems(totallyPreCompItem,nullptr,concept,negation);
1293 }
1294 }
1295 reqConSatList->clear();
1296 if (saturatingConceptCount > 0 || totallyPreCompItem->requiresNominalDelayedConceptsSaturationUpdate() && !totallyPreCompItem->hasNominalDelayedConceptsSaturationUpdated()) {
1297 totallyPreCompItem->setNominalDelayedConceptsSaturationUpdateRequired(false);
1298 totallyPreCompItem->setNominalDelayedConceptsSaturationUpdated(true);
1299 createMarkedConceptSaturationProcessingJob(totallyPreCompItem,true);
1300 return true;
1301 }
1302 return false;
1303 }
1304
1305
1306
1307 bool CTotallyPrecomputationThread::addRequiredSaturationIndividuals(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
1308 CIndividualVector* indiVec = totallyPreCompItem->getOntology()->getABox()->getIndividualVector(false);
1309 QSet<CIndividual*>* activeIndiSet = totallyPreCompItem->getOntology()->getABox()->getActiveIndividualSet(false);
1310 bool individualsAdded = false;
1311 bool saturateConcepts = CConfigDataReader::readConfigBoolean(totallyPreCompItem->getCalculationConfiguration(),"Konclude.Calculation.Optimization.ConceptSaturation",true);
1312 bool individualSaturation = CConfigDataReader::readConfigBoolean(totallyPreCompItem->getCalculationConfiguration(),"Konclude.Calculation.Optimization.IndividualSaturation",false);
1313 cint64 maxId = totallyPreCompItem->getOntology()->getABox()->getNextIndividualId(false);
1314 mBackendAssocCache->mDebugOntology = totallyPreCompItem->getOntology();
1315 mBackendAssocCache->initializeIndividualsAssociationCaching(totallyPreCompItem->getOntology()->getOntologyID(), maxId);
1316 if (saturateConcepts && individualSaturation) {
1317 if (indiVec) {
1318 cint64 indiCount = indiVec->getItemCount();
1319
1320 cint64 indiBatchCount = 5000;
1321 if (indiCount > indiBatchCount * 2) {
1322
1323 class CIndividualLinkerPair {
1324 public:
1325 CIndividualLinkerPair() {
1326 }
1327
1328 CIndividualLinkerPair(CXLinker<CIndividual*>* firstlinker, CXLinker<CIndividual*>* lastlinker, CXLinker<CIndividual*>* linkerArray, cint64 indiLinkerCount) {
1329 mFirstLinker = firstlinker;
1330 mLastLinker = lastlinker;
1331 mLinkerArray = linkerArray;
1332 mIndiLinkerCount = indiLinkerCount;
1333 }
1334
1335 CXLinker<CIndividual*>* mFirstLinker = nullptr;
1336 CXLinker<CIndividual*>* mLastLinker = nullptr;
1337
1338 CXLinker<CIndividual*>* mLinkerArray = nullptr;
1339 cint64 mIndiLinkerCount = 0;
1340 };
1341
1342 function<CIndividualLinkerPair(const QPair<cint64, cint64>& indiPosPair)> individualMapFunc =
1343 [&](const QPair<cint64, cint64>& indiPosPair) -> CIndividualLinkerPair {
1344
1345 cint64 indiStartPos = indiPosPair.first;
1346 cint64 indiEndPos = indiPosPair.second;
1347 CXLinker<CIndividual*>* firstlinker = nullptr;
1348 CXLinker<CIndividual*>* lastlinker = nullptr;
1349 CXLinker<CIndividual*>* linkerArray = new CXLinker<CIndividual *>[indiBatchCount];
1350 cint64 nextLinkerPos = 0;
1351
1352 cint64 indiLinkerCount = 0;
1353 for (cint64 indiId = indiStartPos; indiId < indiEndPos; ++indiId) {
1354 CIndividual* indi = indiVec->getData(indiId);
1355 if (indi && activeIndiSet->contains(indi)) {
1356
1357 CXLinker<CIndividual*>* linker = &linkerArray[nextLinkerPos++];
1358 linker->initLinker(indi);
1359 if (!firstlinker) {
1360 firstlinker = linker;
1361 lastlinker = linker;
1362 } else {
1363 linker->setNext(firstlinker);
1364 firstlinker = linker;
1365 }
1366 indiLinkerCount++;
1367 individualsAdded = true;
1368 }
1369 }
1370
1371 return CIndividualLinkerPair(firstlinker, lastlinker, linkerArray, indiLinkerCount);
1372 };
1373
1374
1375 function<void(CIndividualLinkerPair& reducePair, const CIndividualLinkerPair& pair)> individualReduceFunc = [&](CIndividualLinkerPair& reducePair, const CIndividualLinkerPair& pair) -> void {
1376
1377 CXLinker<CIndividual*>* firstIndiLinker = pair.mFirstLinker;
1378 CXLinker<CIndividual*>* lastIndiLinker = pair.mLastLinker;
1379
1380 if (firstIndiLinker && lastIndiLinker) {
1381 if (reducePair.mFirstLinker) {
1382 lastIndiLinker->setNext(reducePair.mFirstLinker);
1383 reducePair.mFirstLinker = firstIndiLinker;
1384 } else {
1385 reducePair.mFirstLinker = firstIndiLinker;
1386 reducePair.mLastLinker = lastIndiLinker;
1387 }
1388 reducePair.mIndiLinkerCount += pair.mIndiLinkerCount;
1389 totallyPreCompItem->addRequiredABoxSaturationIndividualLinkerArray(reducePair.mLinkerArray);
1390 }
1391 };
1392
1393 QList<QPair<cint64, cint64>> indiPosPairList;
1394 for (cint64 nextIndiPos = 0; nextIndiPos < maxId; nextIndiPos += indiBatchCount) {
1395 indiPosPairList.append(QPair<cint64, cint64>(nextIndiPos, nextIndiPos + indiBatchCount));
1396 }
1397
1398
1399 CIndividualLinkerPair indiLinkerPair = QtConcurrent::blockingMappedReduced<CIndividualLinkerPair>(indiPosPairList, individualMapFunc, individualReduceFunc);
1400 if (indiLinkerPair.mFirstLinker) {
1401 individualsAdded = true;
1402 }
1403 totallyPreCompItem->setRequiredABoxSaturationIndividualLinker(indiLinkerPair.mFirstLinker);
1404 totallyPreCompItem->setRemainingRequiredABoxSaturationIndividualCount(indiLinkerPair.mIndiLinkerCount);
1405
1406 } else {
1407
1408 QSet<TConceptNegPair> assConNegPairSet;
1409 cint64 collectedIndiCount = 0;
1410 for (cint64 indiId = 0; indiId < indiCount; ++indiId) {
1411 CIndividual* indi = indiVec->getData(indiId);
1412 if (indi && activeIndiSet->contains(indi)) {
1413 totallyPreCompItem->addRequiredABoxSaturationIndividual(indi);
1414 individualsAdded = true;
1415 ++collectedIndiCount;
1416 }
1417 }
1418 totallyPreCompItem->setRemainingRequiredABoxSaturationIndividualCount(collectedIndiCount);
1419
1420 }
1421 }
1422 totallyPreCompItem->setIndividualsSaturated(true);
1423 } else {
1424 totallyPreCompItem->setIndividualsSaturated(false);
1425 }
1426 return individualsAdded;
1427 }
1428
1429
1430
1431 bool CTotallyPrecomputationThread::addIdentifiedRemainingConsistencyRequiredConcepts(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
1432
1433 bool constConReqSatAdded = false;
1434 bool saturateConcepts = CConfigDataReader::readConfigBoolean(totallyPreCompItem->getCalculationConfiguration(),"Konclude.Calculation.Optimization.ConceptSaturation",true);
1435
1436 if (saturateConcepts) {
1437 CConcept* topConcept = totallyPreCompItem->getOntology()->getTBox()->getTopConcept();
1438 if (topConcept->getOperandList() != nullptr) {
1439 totallyPreCompItem->addConsistencyRequiredSaturationConcept(topConcept,false);
1440 constConReqSatAdded = true;
1441 }
1442 CIndividualVector* indiVec = totallyPreCompItem->getOntology()->getABox()->getIndividualVector(false);
1443 QSet<CIndividual*>* activeIndiSet = totallyPreCompItem->getOntology()->getABox()->getActiveIndividualSet(false);
1444 QSet<TConceptNegPair> assConNegPairSet;
1445 QSet<CRole*> assRoleSet;
1446 QSet<CRole*> dataRoleSet;
1447 bool createAllAssertionIndi = false;
1448 if (indiVec) {
1449 cint64 indiCount = indiVec->getItemCount();
1450
1451 for (cint64 indiId = 0; indiId < indiCount; ++indiId) {
1452 CIndividual* indi = indiVec->getData(indiId);
1453 if (indi && activeIndiSet->contains(indi)) {
1454 createAllAssertionIndi = true;
1455 for (CConceptAssertionLinker* conAssLinkIt = indi->getAssertionConceptLinker(); conAssLinkIt; conAssLinkIt = conAssLinkIt->getNext()) {
1456 CConcept* assCon = conAssLinkIt->getData();
1457 bool assConNeg = conAssLinkIt->isNegated();
1458 if (assCon->getOperatorCode() == CCNOMINAL) {
1459 if (assCon->getNominalIndividual() != indi || assConNeg && assCon->getNominalIndividual() == indi) {
1460 assConNegPairSet.insert(TConceptNegPair(assCon,assConNeg));
1461 }
1462 } else {
1463 assConNegPairSet.insert(TConceptNegPair(assCon,assConNeg));
1464 }
1465 }
1466 for (CRoleAssertionLinker* roleAssLinkIt = indi->getAssertionRoleLinker(); roleAssLinkIt; roleAssLinkIt = roleAssLinkIt->getNext()) {
1467 CRole* role = roleAssLinkIt->getRole();
1468 assRoleSet.insert(role);
1469 }
1470 for (CDataAssertionLinker* dataAssLinkIt = indi->getAssertionDataLinker(); dataAssLinkIt; dataAssLinkIt = dataAssLinkIt->getNext()) {
1471 CRole* role = dataAssLinkIt->getRole();
1472 dataRoleSet.insert(role);
1473 }
1474
1475 }
1476 }
1477 }
1478
1479 COntologyTriplesData* ontTripleData = totallyPreCompItem->getOntology()->getOntologyTriplesData();
1480 if (ontTripleData && ontTripleData->getTripleAssertionAccessor()) {
1481 COntologyTriplesAssertionsAccessor* assertionAccessor = ontTripleData->getTripleAssertionAccessor();
1482 if (assertionAccessor->getIndexedIndividualCount() > 0) {
1483 createAllAssertionIndi = true;
1484 CTriplesAssertedConceptsExtendingSetVisitor assertedConceptsVisitor(&assConNegPairSet);
1485 assertionAccessor->visitAllAssertedConcepts(&assertedConceptsVisitor);
1486 CTriplesAssertedRolesExtendingSetVisitor assertedRolesVisitor(&assRoleSet);
1487 assertionAccessor->visitAllAssertedObjectRoles(&assertedRolesVisitor);
1488
1489 CTriplesAssertedRolesExtendingSetVisitor assertedDataRolesVisitor(&dataRoleSet);
1490 assertionAccessor->visitAllAssertedDataRoles(&assertedDataRolesVisitor);
1491 }
1492 }
1493
1494 if (!dataRoleSet.isEmpty()) {
1495 for (CRole* dataRole : dataRoleSet) {
1496 for (CSortedNegLinker<CRole*>* superDataRoleIt = dataRole->getIndirectSuperRoleList(); superDataRoleIt; superDataRoleIt = superDataRoleIt->getNext()) {
1497 CRole* superDataRole = superDataRoleIt->getData();
1498 for (CSortedNegLinker<CConcept*>* domainConLinkerIt = superDataRole->getDomainRangeConceptList(superDataRoleIt->isNegated()); domainConLinkerIt; domainConLinkerIt = domainConLinkerIt->getNext()) {
1499 CConcept* domainCon = domainConLinkerIt->getData();
1500 bool domainConNegation = domainConLinkerIt->isNegated();
1501 assConNegPairSet.insert(TConceptNegPair(domainCon, domainConNegation));
1502 }
1503 }
1504 }
1505 totallyPreCompItem->setAllAssertionIndividualSufficientSaturationChecked(true);
1506 totallyPreCompItem->setAllAssertionIndividualSaturationSufficient(false);
1507 }
1508
1509
1510
1511
1512 if (createAllAssertionIndi && (!assConNegPairSet.isEmpty() || !assRoleSet.isEmpty())) {
1513 CIndividual* tmpAllAssertionIndi = new CIndividual();
1514 tmpAllAssertionIndi->initIndividual(totallyPreCompItem->getOntology()->getABox()->getNextIndividualId(false));
1515 tmpAllAssertionIndi->setTemporaryFakeIndividual(true);
1516
1517 for (QSet<TConceptNegPair>::const_iterator it = assConNegPairSet.constBegin(), itEnd = assConNegPairSet.constEnd(); it != itEnd; ++it) {
1518 constConReqSatAdded = true;
1519 TConceptNegPair assConNegPair(*it);
1520 totallyPreCompItem->addConsistencyRequiredSaturationConcept(assConNegPair.first, assConNegPair.second);
1521 CConceptAssertionLinker* tmpConAssLinker = new CConceptAssertionLinker();
1522 tmpConAssLinker->initNegLinker(assConNegPair.first, assConNegPair.second);
1523 tmpAllAssertionIndi->addAssertionConceptLinker(tmpConAssLinker);
1524 }
1525 for (QSet<CRole*>::const_iterator it = assRoleSet.constBegin(), itEnd = assRoleSet.constEnd(); it != itEnd; ++it) {
1526 CRole* role(*it);
1527 CRoleAssertionLinker* tmpRoleAssLinker = new CRoleAssertionLinker();
1528 tmpRoleAssLinker->initRoleAssertionLinker(role, tmpAllAssertionIndi);
1529 tmpAllAssertionIndi->addAssertionRoleLinker(tmpRoleAssLinker);
1530 }
1531 totallyPreCompItem->setAllAssertionIndividual(tmpAllAssertionIndi);
1532 }
1533 }
1534
1535 return constConReqSatAdded;
1536 }
1537
1538
1539
1540 bool CTotallyPrecomputationThread::saturateRemainingConsistencyRequiredConcepts(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
1541 cint64 saturatingConceptCount = 0;
1542 QList<TConceptNegPair>* reqConSatList = totallyPreCompItem->getRemainingConsistencyRequiredSaturationConceptList();
1543 for (QList<TConceptNegPair>::const_iterator it = reqConSatList->constBegin(), itEnd = reqConSatList->constEnd(); it != itEnd; ++it) {
1544 const TConceptNegPair& conNegPair(*it);
1545 CConcept* concept(conNegPair.first);
1546 bool negation = conNegPair.second;
1547 saturatingConceptCount += markSaturationProcessingItems(totallyPreCompItem,nullptr,concept,negation);
1548 }
1549 reqConSatList->clear();
1550 if (saturatingConceptCount > 0) {
1551 createMarkedConceptSaturationProcessingJob(totallyPreCompItem,false);
1552 return true;
1553 }
1554 return false;
1555 }
1556
1557
1558
1559 bool CTotallyPrecomputationThread::saturateRemainingRequiredSaturationIndividuals(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
1560 cint64 saturatingIndividualCount = 0;
1561
1562 QTime*& satTimer = totallyPreCompItem->getIndividualSaturationTime();
1563 if (!satTimer) {
1564 satTimer = new QTime();
1565 satTimer->start();
1566 }
1567
1568 cint64 individualSaturationCount = totallyPreCompItem->getIndividualSaturationSizeLimit();
1569 QList<CIndividual*> indiSatList;
1570 QList<CIndividual*>* reqIndiSatList = totallyPreCompItem->getRemainingRequiredABoxSaturationIndividuals();
1571 while (!reqIndiSatList->isEmpty() && saturatingIndividualCount < individualSaturationCount) {
1572 CIndividual* individual = reqIndiSatList->takeFirst();
1573 indiSatList.append(individual);
1574 totallyPreCompItem->setHandledTriplesIndividualSaturatedId(qMax(individual->getIndividualID(), totallyPreCompItem->getHandledTriplesIndividualSaturatedId()));
1575 ++saturatingIndividualCount;
1576 }
1577
1578 while (totallyPreCompItem->hasRequiredABoxSaturationIndividualLinker() && saturatingIndividualCount < individualSaturationCount) {
1579 CIndividual* individual = totallyPreCompItem->getNextRequiredABoxSaturationIndividual();
1580 indiSatList.append(individual);
1581 totallyPreCompItem->setHandledTriplesIndividualSaturatedId(qMax(individual->getIndividualID(), totallyPreCompItem->getHandledTriplesIndividualSaturatedId()));
1582 ++saturatingIndividualCount;
1583 }
1584 if (!totallyPreCompItem->hasRequiredABoxSaturationIndividualLinker()) {
1585 totallyPreCompItem->clearRequiredABoxSaturationIndividualLinkerArrays();
1586 }
1587
1588 totallyPreCompItem->decRemainingRequiredABoxSaturationIndividualCount(saturatingIndividualCount);
1589
1590 cint64 maxTriplesIndexedIndiId = -1;
1591 COntologyTriplesAssertionsAccessor* triplesAccessor = totallyPreCompItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor();
1592 if (triplesAccessor) {
1593 maxTriplesIndexedIndiId = totallyPreCompItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor()->getMaxIndexedIndividualId();
1594 }
1595 cint64 handledTriplesIndexedIndis = totallyPreCompItem->getHandledTriplesIndividualSaturatedId();
1596 bool remainingTripleIndexedIndis = handledTriplesIndexedIndis < maxTriplesIndexedIndiId;
1597
1598
1599 if (saturatingIndividualCount <= 0 && remainingTripleIndexedIndis) {
1600 cint64 newHandledCount = handledTriplesIndexedIndis + individualSaturationCount;
1601 newHandledCount = qMin(newHandledCount, maxTriplesIndexedIndiId);
1602
1603 createTripleIndexedIndividualsSaturationProcessingJob(totallyPreCompItem, handledTriplesIndexedIndis + 1, newHandledCount);
1604
1605 handledTriplesIndexedIndis = newHandledCount;
1606 totallyPreCompItem->setHandledTriplesIndividualSaturatedId(handledTriplesIndexedIndis);
1607 remainingTripleIndexedIndis = handledTriplesIndexedIndis < maxTriplesIndexedIndiId;
1608
1609 if (!totallyPreCompItem->hasRemainingRequiredABoxSaturationIndividuals() && !remainingTripleIndexedIndis) {
1610 totallyPreCompItem->setALLIndividualsSaturationOrderd(true);
1611 totallyPreCompItem->setTripleIndexedIndividualSaturated(true);
1612 }
1613 return true;
1614 } else {
1615 if (!totallyPreCompItem->hasRemainingRequiredABoxSaturationIndividuals() && !remainingTripleIndexedIndis) {
1616 totallyPreCompItem->setALLIndividualsSaturationOrderd(true);
1617 totallyPreCompItem->setTripleIndexedIndividualSaturated(true);
1618 }
1619 createIndividualSaturationProcessingJob(totallyPreCompItem, indiSatList);
1620 return true;
1621 }
1622
1623 return false;
1624 }
1625
1626 cint64 CTotallyPrecomputationThread::markSaturationProcessingItems(CTotallyOntologyPrecomputationItem* totallyPreCompItem, CSaturationConceptDataItem* startMarkingItem, CConcept* startMarkingConcept, bool startMarkingConceptNegation) {
1627
1628 cint64 markedConcepts = 0;
1629 QList<CSaturationConceptDataItem*> itemList;
1630 QList<TConceptNegPair> conNegPairList;
1631
1632 if (startMarkingItem && !startMarkingItem->isItemProcessingMarked()) {
1633 ++markedConcepts;
1634 startMarkingItem->setItemProcessingMarked(true);
1635 itemList.append(startMarkingItem);
1636 }
1637
1638 if (startMarkingConcept) {
1639 CSaturationConceptDataItem* opMarkingItem = totallyPreCompItem->getSaturationConceptDataItem(startMarkingConcept,startMarkingConceptNegation,false);
1640 if (opMarkingItem) {
1641 if (!opMarkingItem->isItemProcessingMarked()) {
1642 ++markedConcepts;
1643 opMarkingItem->setItemProcessingMarked(true);
1644 itemList.append(opMarkingItem);
1645 }
1646 } else {
1647 conNegPairList.append(TConceptNegPair(startMarkingConcept,startMarkingConceptNegation));
1648 }
1649 }
1650
1651
1652 while (!itemList.isEmpty() || !conNegPairList.isEmpty()) {
1653
1654 while (!itemList.isEmpty()) {
1655 CSaturationConceptDataItem* item = itemList.takeFirst();
1656 CConcept* nextConcept = item->getSaturationConcept();
1657 bool nextNegation = item->getSaturationNegation();
1658 conNegPairList.append(TConceptNegPair(nextConcept,nextNegation));
1659
1660 QList<CSaturationConceptDataItem*>* existRefItemList = item->getExistReferenceConceptItemList();
1661 for (QList<CSaturationConceptDataItem*>::const_iterator it2 = existRefItemList->constBegin(), it2End = existRefItemList->constEnd(); it2 != it2End; ++it2) {
1662 CSaturationConceptDataItem* existRefItem = *it2;
1663 if (!existRefItem->isItemProcessingMarked()) {
1664 ++markedConcepts;
1665 existRefItem->setItemProcessingMarked(true);
1666 itemList.append(existRefItem);
1667 }
1668 }
1669 }
1670
1671
1672 while (!conNegPairList.isEmpty()) {
1673 TConceptNegPair nextConNegPair(conNegPairList.takeFirst());
1674 CConcept* nextConcept = nextConNegPair.first;
1675 bool nextNegation = nextConNegPair.second;
1676 cint64 nOpCode = nextConcept->getOperatorCode();
1677 cint64 opCount = nextConcept->getOperandCount();
1678 if (!nextNegation && (nOpCode == CCAND || nOpCode == CCSUB || nOpCode == CCIMPLTRIG || nOpCode == CCEQ || (nOpCode == CCOR && opCount == 1) || nOpCode == CCAQSOME || nOpCode == CCSOME || nOpCode == CCATLEAST) || nextNegation && (nOpCode == CCOR || ((nOpCode == CCAND || nOpCode == CCEQ) && opCount == 1) || nOpCode == CCALL || nOpCode == CCATMOST)) {
1679 for (CSortedNegLinker<CConcept*>* opConIt = nextConcept->getOperandList(); opConIt; opConIt = opConIt->getNext()) {
1680 CConcept* opConcept = opConIt->getData();
1681 bool influenceNegation = true;
1682 if (nOpCode == CCAQSOME || nOpCode == CCATLEAST || nOpCode == CCATMOST) {
1683 influenceNegation = false;
1684 }
1685 bool opNegation = opConIt->isNegated();
1686 if (influenceNegation && nextNegation) {
1687 opNegation = !opNegation;
1688 }
1689 bool opConceptMarked = false;
1690 if (nOpCode != CCAQCHOOCE || !opNegation) {
1691 CSaturationConceptDataItem* opMarkingItem = totallyPreCompItem->getSaturationConceptDataItem(opConcept,opNegation,false);
1692 CSaturationConceptDataItem* roleOpMarkingItem = nullptr;
1693 if (nextConcept->getRole()) {
1694 CRole* role = nextConcept->getRole();
1695 roleOpMarkingItem = totallyPreCompItem->getSaturationRoleSuccessorConceptDataItem(role,opConcept,opNegation,false);
1696 }
1697 if (opMarkingItem || roleOpMarkingItem) {
1698 if (opMarkingItem && !opMarkingItem->isItemProcessingMarked()) {
1699 ++markedConcepts;
1700 opMarkingItem->setItemProcessingMarked(true);
1701 itemList.append(opMarkingItem);
1702 }
1703 if (roleOpMarkingItem && !roleOpMarkingItem->isItemProcessingMarked()) {
1704 ++markedConcepts;
1705 roleOpMarkingItem->setItemProcessingMarked(true);
1706 itemList.append(roleOpMarkingItem);
1707 }
1708 } else {
1709 conNegPairList.append(TConceptNegPair(opConcept,opNegation));
1710 }
1711 }
1712 }
1713 } else if (nOpCode == CCAQCHOOCE) {
1714 for (CSortedNegLinker<CConcept*>* opConIt = nextConcept->getOperandList(); opConIt; opConIt = opConIt->getNext()) {
1715 CConcept* opConcept = opConIt->getData();
1716 if (opConIt->isNegated() == nextNegation) {
1717 CSaturationConceptDataItem* opMarkingItem = totallyPreCompItem->getSaturationConceptDataItem(opConcept,false,false);
1718 if (opMarkingItem) {
1719 if (!opMarkingItem->isItemProcessingMarked()) {
1720 ++markedConcepts;
1721 opMarkingItem->setItemProcessingMarked(true);
1722 itemList.append(opMarkingItem);
1723 }
1724 } else {
1725 conNegPairList.append(TConceptNegPair(opConcept,false));
1726 }
1727 }
1728 }
1729 }
1730 }
1731 }
1732 return markedConcepts;
1733 }
1734
1735
1736
1737
1738 void CTotallyPrecomputationThread::orderItemsSaturationTesting(CTotallyOntologyPrecomputationItem* totallyPreCompItem, CSaturationConceptDataItem* ontConSatDataItem, QList<CSaturationConceptDataItem*>& orderedItemList, QStack<CSaturationSaturationListItem>& saturationItemStack) {
1739
1740
1741 if (!ontConSatDataItem->isOrderingQueued()) {
1742
1743 saturationItemStack.push(CSaturationSaturationListItem(ontConSatDataItem));
1744
1745
1746 while (!saturationItemStack.isEmpty()) {
1747 CSaturationSaturationListItem& topSatSatListItem = saturationItemStack.top();
1748 CSaturationConceptDataItem* topOntConSatDataItem = topSatSatListItem.mSaturationItem;
1749 QList<CSaturationConceptDataItem*>& markOderingSubsumerList = topSatSatListItem.mSaturationItemList;
1750
1751 if (!topOntConSatDataItem->isOrderingQueued()) {
1752 if (!topSatSatListItem.mSubsumerOrdered) {
1753 topSatSatListItem.mSubsumerOrdered = true;
1754
1755 // first mark all subsumer items
1756 CSaturationConceptDataItem* subsumerItem = topOntConSatDataItem;
1757 while (subsumerItem && !subsumerItem->isOrderingQueued()) {
1758 subsumerItem->setOrderingQueued(true);
1759 markOderingSubsumerList.prepend(subsumerItem);
1760 subsumerItem = subsumerItem->getSpecialItemReference();
1761 }
1762 }
1763 }
1764
1765 if (topSatSatListItem.mLastSubsumerSaturationItem) {
1766 orderedItemList.append(topSatSatListItem.mLastSubsumerSaturationItem);
1767 topSatSatListItem.mLastSubsumerSaturationItem = nullptr;
1768 }
1769
1770 if (!markOderingSubsumerList.isEmpty()) {
1771 CSaturationConceptDataItem* subsumerItem = markOderingSubsumerList.takeFirst();
1772 topSatSatListItem.mLastSubsumerSaturationItem = subsumerItem;
1773
1774 QList<CSaturationConceptDataItem*>* existRefItemList = subsumerItem->getExistReferenceConceptItemList();
1775 for (QList<CSaturationConceptDataItem*>::const_iterator it2 = existRefItemList->constBegin(), it2End = existRefItemList->constEnd(); it2 != it2End; ++it2) {
1776 CSaturationConceptDataItem* existRefItem = *it2;
1777 saturationItemStack.push(CSaturationSaturationListItem(existRefItem));
1778 }
1779 //QListIterator<CSaturationConceptDataItem*> it2(*existRefItemList);
1780 //it2.toBack();
1781 //while (it2.hasPrevious()) {
1782 // CSaturationConceptDataItem* existRefItem = it2.previous();
1783 // saturationItemStack.push(CSaturationSaturationListItem(existRefItem));
1784 //}
1785
1786
1787 } else {
1788 saturationItemStack.pop();
1789 }
1790 }
1791 }
1792
1793 //if (!ontConSatDataItem->isOrderingQueued()) {
1794
1795
1796 // // first mark all subsumer items
1797 // QList<CSaturationConceptDataItem*> markOderingSubsumerList;
1798 // CSaturationConceptDataItem* subsumerItem = ontConSatDataItem;
1799 // while (subsumerItem && !subsumerItem->isOrderingQueued()) {
1800 // subsumerItem->setOrderingQueued(true);
1801 // markOderingSubsumerList.prepend(subsumerItem);
1802 // subsumerItem = subsumerItem->getSpecialItemReference();
1803 // }
1804
1805
1806
1807 // for (QList<CSaturationConceptDataItem*>::const_iterator it1 = markOderingSubsumerList.constBegin(), it1End = markOderingSubsumerList.constEnd(); it1 != it1End; ++it1) {
1808 // CSaturationConceptDataItem* subsumerItem = *it1;
1809
1810 // QList<CSaturationConceptDataItem*>* existRefItemList = subsumerItem->getExistReferenceConceptItemList();
1811 // for (QList<CSaturationConceptDataItem*>::const_iterator it2 = existRefItemList->constBegin(), it2End = existRefItemList->constEnd(); it2 != it2End; ++it2) {
1812 // CSaturationConceptDataItem* existRefItem = *it2;
1813 // orderItemsSaturationTesting(totallyPreCompItem,existRefItem,orderedItemList);
1814 // }
1815
1816 // orderedItemList.append(subsumerItem);
1817 // }
1818
1819 //}
1820 }
1821
1822
1823 bool CTotallyPrecomputationThread::hasRoleRanges(CTotallyOntologyPrecomputationItem* totallyPreCompItem, CRole* role) {
1824 for (CSortedNegLinker<CRole*>* superRoleIt = role->getIndirectSuperRoleList(); superRoleIt; superRoleIt = superRoleIt->getNext()) {
1825 CRole* superRole = superRoleIt->getData();
1826 bool superRoleNegation = superRoleIt->isNegated();
1827 CSortedNegLinker<CConcept*>* rangeConceptLinker = superRole->getDomainRangeConceptList(!superRoleNegation);
1828 if (rangeConceptLinker) {
1829 return true;
1830 }
1831 }
1832 return false;
1833 }
1834
1835
1836
1837
1838
1839
1840
1841
1842 void CTotallyPrecomputationThread::createMarkedConceptSaturationProcessingJob(CTotallyOntologyPrecomputationItem* totallyPreCompItem, bool allowAllSaturation) {
1843 CApproximatedSaturationCalculationJob* satCalculationJob = nullptr;
1844 CConcreteOntology *onto = totallyPreCompItem->getOntology();
1845 CApproximatedSaturationCalculationJobGenerator satCalculationJobGenerator(onto);
1846 satCalculationJob = satCalculationJobGenerator.getApproximatedSaturationCalculationJob(0, totallyPreCompItem->getSaturationData());
1847
1848
1849 bool imiadelyProcessAllConcepts = totallyPreCompItem->requiresAllConceptsSaturation();
1850 if (!allowAllSaturation) {
1851 imiadelyProcessAllConcepts = false;
1852 }
1853
1854 cint64 saturationConceptCount = 0;
1855 QList<CSaturationConceptDataItem*>* orderedItemList = totallyPreCompItem->getSaturationOrderedItemList();
1856 for (QList<CSaturationConceptDataItem*>::const_iterator it = orderedItemList->constBegin(), itEnd = orderedItemList->constEnd(); it != itEnd; ++it) {
1857 CSaturationConceptDataItem* conItem = *it;
1858 CConcept* concept = conItem->getSaturationConcept();
1859 bool negation = conItem->getSaturationNegation();
1860 CRole* role = conItem->getSaturationRoleRanges();
1861 if (conItem->isItemProcessingMarked() && !conItem->isItemProcessingQueued() || imiadelyProcessAllConcepts) {
1862 conItem->setItemProcessingQueued(true);
1863 satCalculationJob = satCalculationJobGenerator.extendApproximatedSaturationCalculationJobProcessing(conItem, satCalculationJob);
1864 saturationConceptCount++;
1865 }
1866 }
1867 if (!totallyPreCompItem->isAllAssertionIndividualSaturated()) {
1868 CIndividual* allAssertionIndi = totallyPreCompItem->getAllAssertionIndividual();
1869 if (allAssertionIndi) {
1870 satCalculationJob = satCalculationJobGenerator.extendApproximatedSaturationCalculationJobProcessing(allAssertionIndi, nullptr, satCalculationJob);
1871 }
1872 totallyPreCompItem->setAllAssertionIndividualSaturated(true);
1873 }
1874
1875 LOG(INFO, getLogDomain(), logTr("Scheduled %1 concepts for saturation for ontology '%2'.").arg(saturationConceptCount).arg(totallyPreCompItem->getOntology()->getTerminologyName()), this);
1876
1877 CSaturationPrecomputationTestingItem* satTestingItem = new CSaturationPrecomputationTestingItem(totallyPreCompItem, CPrecomputationTestingItem::CONCEPTSATURATIONPRECOMPUTATIONTYPE);
1878 CCalculationConfigurationExtension* calcConfig = totallyPreCompItem->getCalculationConfiguration();
1879 satCalculationJob->setCalculationConfiguration(calcConfig);
1880 satCalculationJob->setSaturationTaskPreyingAdapter(new CTaskPreyingAdapter((CSaturationObserver*)totallyPreCompItem));
1881
1882 totallyPreCompItem->setSaturationCalculationJob(satCalculationJob);
1883 processCalculationJob(satCalculationJob, totallyPreCompItem, satTestingItem);
1884 }
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894 void CTotallyPrecomputationThread::createOccurrenceStatisticsCollectingSaturationProcessingJob(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
1895 CApproximatedSaturationCalculationJob* satCalculationJob = nullptr;
1896 CConcreteOntology *onto = totallyPreCompItem->getOntology();
1897 CApproximatedSaturationCalculationJobGenerator satCalculationJobGenerator(onto);
1898 satCalculationJob = satCalculationJobGenerator.getApproximatedSaturationCalculationJob(0,totallyPreCompItem->getSaturationData());
1899
1900
1901 CSaturationPrecomputationTestingItem* satTestingItem = new CSaturationPrecomputationTestingItem(totallyPreCompItem,CPrecomputationTestingItem::OCCURRENCESTATISTICSSATURATIONPRECOMPUTATIONTYPE);
1902 CCalculationConfigurationExtension* calcConfig = totallyPreCompItem->getCalculationConfiguration();
1903 satCalculationJob->setCalculationConfiguration(calcConfig);
1904 satCalculationJob->setOccurrenceStatisticsCollectingAdapter(new CSaturationOccurrenceStatisticsCollectingAdapter());
1905
1906 totallyPreCompItem->setSaturationCalculationJob(satCalculationJob);
1907 processCalculationJob(satCalculationJob,totallyPreCompItem,satTestingItem);
1908 }
1909
1910
1911
1912
1913
1914
1915
1916
1917 void CTotallyPrecomputationThread::createIndividualSaturationProcessingJob(CTotallyOntologyPrecomputationItem* totallyPreCompItem, const QList<CIndividual*>& individualList) {
1918 CApproximatedSaturationCalculationJob* satCalculationJob = nullptr;
1919 CConcreteOntology *onto = totallyPreCompItem->getOntology();
1920 CApproximatedSaturationCalculationJobGenerator satCalculationJobGenerator(onto);
1921 satCalculationJob = satCalculationJobGenerator.getApproximatedSaturationCalculationJob(0,totallyPreCompItem->getSaturationData());
1922 satCalculationJob->setSeparateSaturation(true);
1923
1924 cint64 nextSaturationID = totallyPreCompItem->getNextSaturationID();
1925 CSaturationIndividualDataItem* satIndiDataItemLinker = nullptr;
1926
1927 cint64 saturationIndividualCount = 0;
1928 for (QList<CIndividual*>::const_iterator it = individualList.constBegin(), itEnd = individualList.constEnd(); it != itEnd; ++it) {
1929 CIndividual* individual = *it;
1930 CSaturationIndividualDataItem* satIndiDataItem = totallyPreCompItem->takeFreeSaturationIndividualDataItem();
1931 satIndiDataItem->initConceptSaturationTestingItem(individual,nextSaturationID);
1932 satIndiDataItemLinker = satIndiDataItem->append(satIndiDataItemLinker);
1933 CIndividualProcessData* indiProcessData = (CIndividualProcessData*)individual->getIndividualData();
1934 if (indiProcessData) {
1935 indiProcessData->setSaturationReferenceLinkingData(satIndiDataItem);
1936 }
1937 satCalculationJob = satCalculationJobGenerator.extendApproximatedSaturationCalculationJobProcessing(individual,satIndiDataItem,satCalculationJob);
1938 ++saturationIndividualCount;
1939 }
1940 totallyPreCompItem->setSaturationIDIndividualDataItems(nextSaturationID,satIndiDataItemLinker);
1941 cint64 remainingRequiredABoxSaturationIndividualCount = totallyPreCompItem->getRemainingRequiredABoxSaturationIndividualCount();
1942
1943 LOG(INFO,getLogDomain(),logTr("Scheduled next %1 of %2 remaining individuals for saturation of ontology '%3' (%4 batchs queued).").arg(saturationIndividualCount).arg(saturationIndividualCount + remainingRequiredABoxSaturationIndividualCount).arg(totallyPreCompItem->getOntology()->getTerminologyName()).arg(mCurrRunningTestParallelCount + 1),this);
1944
1945 CSaturationPrecomputationTestingItem* satTestingItem = new CSaturationPrecomputationTestingItem(totallyPreCompItem,CPrecomputationTestingItem::INDIVIDUALSATURATIONPRECOMPUTATIONTYPE,nextSaturationID);
1946 CCalculationConfigurationExtension* calcConfig = totallyPreCompItem->getCalculationConfiguration();
1947 satCalculationJob->setCalculationConfiguration(calcConfig);
1948 satCalculationJob->setSaturationIndividualsAnalysationObserver(new CSaturationIndividualsAnalysingAdapter((CSaturationIndividualAnalysationObserver*)totallyPreCompItem));
1949
1950 totallyPreCompItem->setSaturationCalculationJob(satCalculationJob);
1951 processCalculationJob(satCalculationJob,totallyPreCompItem,satTestingItem);
1952 }
1953
1954
1955
1956
1957
1958 void CTotallyPrecomputationThread::createTripleIndexedIndividualsSaturationProcessingJob(CTotallyOntologyPrecomputationItem* totallyPreCompItem, cint64 startIndiId, cint64 endIndiId) {
1959 CApproximatedSaturationCalculationJob* satCalculationJob = nullptr;
1960 CConcreteOntology *onto = totallyPreCompItem->getOntology();
1961 CApproximatedSaturationCalculationJobGenerator satCalculationJobGenerator(onto);
1962 satCalculationJob = satCalculationJobGenerator.getApproximatedSaturationCalculationJob(0,totallyPreCompItem->getSaturationData());
1963 satCalculationJob->setSeparateSaturation(true);
1964
1965 cint64 nextSaturationID = totallyPreCompItem->getNextSaturationID();
1966 CSaturationIndividualDataItem* satIndiDataItemLinker = nullptr;
1967
1968 cint64 saturationIndividualCount = 0;
1969 for (cint64 indiId = startIndiId; indiId <= endIndiId; ++indiId) {
1970
1971 CSaturationIndividualDataItem* satIndiDataItem = totallyPreCompItem->takeFreeSaturationIndividualDataItem();
1972 satIndiDataItem->initConceptSaturationTestingItem(nullptr, nextSaturationID);
1973 satIndiDataItemLinker = satIndiDataItem->append(satIndiDataItemLinker);
1974
1975 satCalculationJob = satCalculationJobGenerator.extendApproximatedSaturationCalculationJobProcessing(indiId, satIndiDataItem, satCalculationJob);
1976 ++saturationIndividualCount;
1977 }
1978 totallyPreCompItem->setSaturationIDIndividualDataItems(nextSaturationID,satIndiDataItemLinker);
1979
1980 LOG(INFO,getLogDomain(),logTr("Scheduled next %1 of %2 remaining triple-indexed individuals for saturation of ontology '%3' (%4 batchs queued).").arg(saturationIndividualCount).arg(saturationIndividualCount + totallyPreCompItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor()->getMaxIndexedIndividualId() - endIndiId).arg(totallyPreCompItem->getOntology()->getTerminologyName()).arg(mCurrRunningTestParallelCount + 1),this);
1981
1982 CSaturationPrecomputationTestingItem* satTestingItem = new CSaturationPrecomputationTestingItem(totallyPreCompItem,CPrecomputationTestingItem::INDIVIDUALSATURATIONPRECOMPUTATIONTYPE,nextSaturationID);
1983 CCalculationConfigurationExtension* calcConfig = totallyPreCompItem->getCalculationConfiguration();
1984 satCalculationJob->setCalculationConfiguration(calcConfig);
1985 satCalculationJob->setSaturationIndividualsAnalysationObserver(new CSaturationIndividualsAnalysingAdapter((CSaturationIndividualAnalysationObserver*)totallyPreCompItem));
1986
1987 totallyPreCompItem->setSaturationCalculationJob(satCalculationJob);
1988 processCalculationJob(satCalculationJob,totallyPreCompItem,satTestingItem);
1989 }
1990
1991
1992
1993 void CTotallyPrecomputationThread::createSaturationConstructionJob(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
1994
1995 CTBox* tBox = totallyPreCompItem->getOntology()->getDataBoxes()->getTBox();
1996
1997 CConcreteOntology *onto = totallyPreCompItem->getOntology();
1998 CConcept* topConcept = onto->getDataBoxes()->getTopConcept();
1999 CConcept* bottomConcept = onto->getDataBoxes()->getBottomConcept();
2000 CConcept* topDataRangeConcept = tBox->getTopDataRangeConcept();
2001
2002 CConceptVector* conVec = tBox->getConceptVector();
2003
2004 LOG(INFO,getLogDomain(),logTr("Determine concepts for saturation for ontology '%1'.").arg(totallyPreCompItem->getOntology()->getTerminologyName()),this);
2005
2006
2007 CApproximatedSaturationCalculationJob* satCalculationJob = nullptr;
2008 CApproximatedSaturationCalculationJobGenerator satCalculationJobGenerator(onto);
2009
2010
2011
2012 bool saturateConcepts = CConfigDataReader::readConfigBoolean(totallyPreCompItem->getCalculationConfiguration(),"Konclude.Calculation.Optimization.ConceptSaturation",true);
2013
2014 cint64 statExistsConceptCount = 0;
2015 cint64 statClassCount = 0;
2016
2017 QList<CSaturationConceptDataItem*> existConList;
2018 QList<CSaturationConceptDataItem*> analyseExistSubsumerList;
2019 QList<CSaturationConceptDataItem*> allConItemList;
2020 QList<CSaturationConceptDataItem*> disjunctionCandidateAlternativeList;
2021
2022 cint64 conCount = conVec->getItemCount();
2023 if (saturateConcepts) {
2024 for (cint64 conIdx = 1; conIdx < conCount; ++conIdx) {
2025 CConcept* concept = conVec->getData(conIdx);
2026
2027 //if (CIRIName::getRecentIRIName(concept->getClassNameLinker()) == "file:F:/Projects/OIL/DAMLOilEd/ontologies/ka.daml#Publication") {
2028 // bool bug = true;
2029 //}
2030
2031 if (concept) {
2032 cint64 opCode = concept->getOperatorCode();
2033 if (opCode == CCSOME || opCode == CCALL || opCode == CCAQSOME || opCode == CCATLEAST || opCode == CCATMOST) {
2034 ++statExistsConceptCount;
2035 bool negation = opCode == CCALL;
2036 CRole* role = concept->getRole();
2037 CSortedNegLinker<CConcept*>* opLinker = concept->getOperandList();
2038 CConcept* opConcept = nullptr;
2039 bool opNegation = false;
2040 if (opLinker) {
2041 opConcept = opLinker->getData();
2042 if (opCode == CCATLEAST || opCode == CCATMOST) {
2043 opNegation = opLinker->isNegated();
2044 } else {
2045 opNegation = opLinker->isNegated()^negation;
2046 }
2047 } else {
2048 opConcept = topConcept;
2049 if (opCode == CCATLEAST || opCode == CCATMOST) {
2050 opNegation = false;
2051 } else {
2052 opNegation = negation;
2053 }
2054 }
2055
2056
2057 if (hasRoleRanges(totallyPreCompItem,role)) {
2058 CSaturationConceptDataItem* conItem = nullptr;
2059 conItem = totallyPreCompItem->getSaturationRoleSuccessorConceptDataItem(role,opConcept,opNegation,true);
2060 conItem->setPotentiallyExistInitializationConcept(true);
2061 existConList.append(conItem);
2062 if (role->isDataRole()) {
2063 conItem->setDataRangeConcept(true);
2064 }
2065
2066 CConceptProcessData* conProcData = (CConceptProcessData*)concept->getConceptData();
2067 CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking();
2068 if (!conRefSatLinking) {
2069 conRefSatLinking = new CConceptSaturationReferenceLinkingData();
2070 conProcData->setConceptReferenceLinking(conRefSatLinking);
2071 }
2072 if (conRefSatLinking->getExistentialSuccessorConceptSaturationReferenceLinkingData() == nullptr) {
2073 conRefSatLinking->setExistentialSuccessorConceptSaturationReferenceLinkingData(conItem);
2074 allConItemList.append(conItem);
2075 }
2076
2077 } else {
2078 CSaturationConceptDataItem* conItem = nullptr;
2079 conItem = totallyPreCompItem->getSaturationConceptDataItem(opConcept,opNegation,true);
2080 conItem->setPotentiallyExistInitializationConcept(true);
2081 existConList.append(conItem);
2082 if (role->isDataRole()) {
2083 conItem->setDataRangeConcept(true);
2084 }
2085
2086 CConceptProcessData* opConProcData = (CConceptProcessData*)opConcept->getConceptData();
2087 CConceptSaturationReferenceLinkingData* opConRefSatLinking = (CConceptSaturationReferenceLinkingData*)opConProcData->getConceptReferenceLinking();
2088 if (!opConRefSatLinking) {
2089 opConRefSatLinking = new CConceptSaturationReferenceLinkingData();
2090 opConProcData->setConceptReferenceLinking(opConRefSatLinking);
2091 }
2092 if (opConRefSatLinking->getConceptSaturationReferenceLinkingData(opNegation) == nullptr) {
2093 opConRefSatLinking->setSaturationReferenceLinkingData(conItem,opNegation);
2094 allConItemList.append(conItem);
2095 }
2096 }
2097
2098 } else if (concept->hasClassName() || concept == topDataRangeConcept) {
2099
2100 ++statClassCount;
2101 CConceptProcessData* conProcData = (CConceptProcessData*)concept->getConceptData();
2102 CConceptSaturationReferenceLinkingData* conRefSatLinking = (CConceptSaturationReferenceLinkingData*)conProcData->getConceptReferenceLinking();
2103 if (!conRefSatLinking) {
2104 conRefSatLinking = new CConceptSaturationReferenceLinkingData();
2105 conProcData->setConceptReferenceLinking(conRefSatLinking);
2106 }
2107 if (conRefSatLinking->getConceptSaturationReferenceLinkingData(false) == nullptr) {
2108 CSaturationConceptDataItem* conItem = totallyPreCompItem->getSaturationConceptDataItem(concept,false,true);
2109 conRefSatLinking->setSaturationReferenceLinkingData(conItem,false);
2110 allConItemList.append(conItem);
2111 }
2112 }
2113 }
2114 }
2115 }
2116
2117 disjunctionCandidateAlternativeList = allConItemList;
2118 while (!disjunctionCandidateAlternativeList.isEmpty()) {
2119 CSaturationConceptDataItem* conTestItem = disjunctionCandidateAlternativeList.takeFirst();
2120 QList<CSaturationConceptDataItem*> tempNewItems;
2121 extendDisjunctionsCandidateAlternativesItems(totallyPreCompItem,conTestItem,&tempNewItems);
2122 if (!tempNewItems.isEmpty()) {
2123 disjunctionCandidateAlternativeList.append(tempNewItems);
2124 allConItemList.append(tempNewItems);
2125 }
2126 }
2127
2128
2129 analyseExistSubsumerList = allConItemList;
2130
2131 QList<CConceptNegationSaturationItem> processList;
2132 // identify all items, which aren't subsumers of other items
2133 for (QList<CSaturationConceptDataItem*>::const_iterator it = analyseExistSubsumerList.constBegin(), itEnd = analyseExistSubsumerList.constEnd(); it != itEnd; ++it) {
2134 CSaturationConceptDataItem* conTestItem = *it;
2135 CConcept* concept = conTestItem->getSaturationConcept();
2136 bool conceptNegation = conTestItem->getSaturationNegation();
2137 processList.append(CConceptNegationSaturationItem(concept,conceptNegation,conTestItem));
2138 }
2139 analyseConceptSaturationSubsumerExistItems(totallyPreCompItem,processList);
2140
2141 // find all potentially subsumer items
2142 for (QList<CSaturationConceptDataItem*>::const_iterator it = analyseExistSubsumerList.constBegin(), itEnd = analyseExistSubsumerList.constEnd(); it != itEnd; ++it) {
2143 CSaturationConceptDataItem* conTestItem = *it;
2144 propagateSubsumerItemFlag(conTestItem);
2145 }
2146
2147 // find all potentially role successors, for which back propagation is necessary
2148 for (QList<CSaturationConceptDataItem*>::const_iterator it = existConList.constBegin(), itEnd = existConList.constEnd(); it != itEnd; ++it) {
2149 CSaturationConceptDataItem* conTestItem = *it;
2150 propagateExistInitializationFlag(conTestItem);
2151 }
2152
2153 QList<CSaturationConceptDataItem*> leafConList;
2154 QList<CSaturationConceptDataItem*> leafExistConList;
2155 // collect all leaf nodes
2156 for (QList<CSaturationConceptDataItem*>::const_iterator it = allConItemList.constBegin(), itEnd = allConItemList.constEnd(); it != itEnd; ++it) {
2157 CSaturationConceptDataItem* conTestItem = *it;
2158 if (!conTestItem->hasIndirectSuccessorsItems()) {
2159 if (!conTestItem->isPotentiallyExistInitializationConcept()) {
2160 leafConList.append(conTestItem);
2161 } else {
2162 leafExistConList.append(conTestItem);
2163 }
2164 }
2165 }
2166
2167
2168
2169 QList<CSaturationConceptDataItem*>* orderedItemList = totallyPreCompItem->getSaturationOrderedItemList();
2170 QStack<CSaturationSaturationListItem> saturationItemStack;
2171 // order all concepts associated to the items for efficient Saturation testing, start with the real leaf items
2172 for (QList<CSaturationConceptDataItem*>::const_iterator it = leafConList.constBegin(), itEnd = leafConList.constEnd(); it != itEnd; ++it) {
2173 CSaturationConceptDataItem* conTestItem = *it;
2174 if (!conTestItem->isOrderingQueued()) {
2175 orderItemsSaturationTesting(totallyPreCompItem,conTestItem,*orderedItemList,saturationItemStack);
2176 }
2177 }
2178 for (QList<CSaturationConceptDataItem*>::const_iterator it = leafExistConList.constBegin(), itEnd = leafExistConList.constEnd(); it != itEnd; ++it) {
2179 CSaturationConceptDataItem* conTestItem = *it;
2180 if (!conTestItem->isOrderingQueued()) {
2181 orderItemsSaturationTesting(totallyPreCompItem,conTestItem,*orderedItemList,saturationItemStack);
2182 }
2183 }
2184 for (QList<CSaturationConceptDataItem*>::const_iterator it = allConItemList.constBegin(), itEnd = allConItemList.constEnd(); it != itEnd; ++it) {
2185 CSaturationConceptDataItem* conTestItem = *it;
2186 if (!conTestItem->isOrderingQueued()) {
2187 orderItemsSaturationTesting(totallyPreCompItem,conTestItem,*orderedItemList,saturationItemStack);
2188 }
2189 }
2190
2191
2192 // set reference mode for saturation: substitute or copy
2193 QListIterator<CSaturationConceptDataItem*> reverseOrderedIt(*orderedItemList);
2194 reverseOrderedIt.toBack();
2195 CBOXHASH<CConcept*,CConcept*>* triggerImpHash = totallyPreCompItem->getOntology()->getTBox()->getTriggerImplicationHash(false);
2196 while (reverseOrderedIt.hasPrevious()) {
2197 CSaturationConceptDataItem* conTestItem = reverseOrderedIt.previous();
2198 CSaturationConceptDataItem* referencedTestItem = conTestItem->getSpecialItemReference();
2199 if (referencedTestItem) {
2200 if (!conTestItem->isPotentiallyExistInitializationConcept() && !conTestItem->hasMultipleDirectPredecessorsItems() && (!triggerImpHash || !triggerImpHash->contains(conTestItem->getSaturationConcept()))) {
2201 conTestItem->setSpecialItemReferenceMode(CSaturationConceptDataItem::SATURATIONSUBSTITUTEMODE);
2202 } else {
2203 conTestItem->setSpecialItemReferenceMode(CSaturationConceptDataItem::SATURATIONCOPYMODE);
2204 }
2205 }
2206 }
2207
2208 satCalculationJob = satCalculationJobGenerator.getApproximatedSaturationCalculationJob(0);
2209
2210
2211 cint64 mSaturationConceptCount = 0;
2212 for (QList<CSaturationConceptDataItem*>::const_iterator it = orderedItemList->constBegin(), itEnd = orderedItemList->constEnd(); it != itEnd; ++it) {
2213 CSaturationConceptDataItem* conItem = *it;
2214 CConcept* concept = conItem->getSaturationConcept();
2215 bool negation = conItem->getSaturationNegation();
2216 CRole* role = conItem->getSaturationRoleRanges();
2217 conItem->setItemProcessingQueued(false);
2218 satCalculationJob = satCalculationJobGenerator.extendApproximatedSaturationCalculationJobConstruction(role,concept,negation,false,conItem,satCalculationJob);
2219 mSaturationConceptCount++;
2220 }
2221
2222 LOG(INFO,getLogDomain(),logTr("Preparing saturation of %1 concepts for ontology '%2'.").arg(mSaturationConceptCount).arg(totallyPreCompItem->getOntology()->getTerminologyName()),this);
2223
2224 CSaturationPrecomputationTestingItem* satTestingItem = new CSaturationPrecomputationTestingItem(totallyPreCompItem,CPrecomputationTestingItem::CONCEPTSATURATIONPRECOMPUTATIONTYPE);
2225 CCalculationConfigurationExtension* calcConfig = totallyPreCompItem->getCalculationConfiguration();
2226 satCalculationJob->setCalculationConfiguration(calcConfig);
2227 satCalculationJob->setSaturationTaskPreyingAdapter(new CTaskPreyingAdapter((CSaturationObserver*)totallyPreCompItem));
2228
2229 totallyPreCompItem->setSaturationCalculationJob(satCalculationJob);
2230 processCalculationJob(satCalculationJob,totallyPreCompItem,satTestingItem);
2231 }
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248 bool CTotallyPrecomputationThread::precomputationTested(COntologyPrecomputationItem* ontPreCompItem, CPrecomputationTestingItem* preTestItem, CSaturationPrecomputationCalculatedCallbackEvent* pcce) {
2249 CTotallyOntologyPrecomputationItem* totallyPreCompItem = (CTotallyOntologyPrecomputationItem*)ontPreCompItem;
2250 if (preTestItem->getPrecomputationTestingType() == CPrecomputationTestingItem::OCCURRENCESTATISTICSSATURATIONPRECOMPUTATIONTYPE) {
2251 totallyPreCompItem->setSaturationOccurrenceStatisticsCollected(true);
2252 return true;
2253 } else if (preTestItem->getPrecomputationTestingType() == CPrecomputationTestingItem::CONCEPTSATURATIONPRECOMPUTATIONTYPE) {
2254 CSaturationPrecomputationTestingItem* satPreTestItem = (CSaturationPrecomputationTestingItem*)preTestItem;
2255 totallyPreCompItem->setConceptSaturationPrecomputationChecked(true);
2256 CPrecomputation* precomputation = totallyPreCompItem->getPrecomputation();
2257 CSaturationData* saturationData = totallyPreCompItem->getSaturationData();
2258 precomputation->setSaturationModelData(saturationData);
2259 totallyPreCompItem->setSaturationComputationRunning(false);
2260
2261 CSaturationTaskData* satTaskData = (CSaturationTaskData*)saturationData;
2262 if (satTaskData) {
2263 CSatisfiableCalculationTask* satCalcTask = satTaskData->getSaturationTask();
2264 if (satCalcTask) {
2265 CProcessingDataBox* procDataBox = satCalcTask->getProcessingDataBox();
2266 if (procDataBox) {
2267 totallyPreCompItem->setNominalDelayedConceptsSaturationUpdateRequired(procDataBox->isDelayedNominalProcessingOccured());
2268 }
2269 }
2270 }
2271
2272 return true;
2273 } else if (preTestItem->getPrecomputationTestingType() == CPrecomputationTestingItem::INDIVIDUALSATURATIONPRECOMPUTATIONTYPE) {
2274 CSaturationPrecomputationTestingItem* satPreTestItem = (CSaturationPrecomputationTestingItem*)preTestItem;
2275 cint64 saturationID = satPreTestItem->getSaturationID();
2276 totallyPreCompItem->releaseSaturationIDIndividualDataItems(saturationID);
2277 totallyPreCompItem->decIndividualSaturationRunningCount();
2278
2279
2280
2281 if (!totallyPreCompItem->hasIndividualSaturationRunning()) {
2282 totallyPreCompItem->setSaturationComputationRunning(false);
2283
2284 if (totallyPreCompItem->hasIndividualsSaturated() && totallyPreCompItem->hasALLIndividualsSaturationOrderd()) {
2285
2286 if (!totallyPreCompItem->hasIndividualsSaturationCacheSynchronisation()) {
2287
2288
2289 CIndividualPrecomputationCoordinationHash* procCoordHash = totallyPreCompItem->getPrecomputationProcessingCoordinationHash();
2290 if (!totallyPreCompItem->isPrecompuationRetrievingIncompletelyHandledIndividuals()) {
2291
2292 if (!procCoordHash || procCoordHash->isEmpty()) {
2293
2294 synchronouslyRetrieveIndividualsPrecomputation(totallyPreCompItem, ontPreCompItem);
2295
2296 } else {
2297
2298 QTime*& indiPrecTimer = totallyPreCompItem->getIndividualPrecomputationTime();
2299 if (!indiPrecTimer) {
2300 indiPrecTimer = new QTime();
2301 indiPrecTimer->start();
2302 }
2303 totallyPreCompItem->setIndividualsSaturationCacheSynchronisation(true);
2304 QTime* indiSatTimer = totallyPreCompItem->getIndividualSaturationTime();
2305 LOG(INFO, getLogDomain(), logTr("Individual saturation finished in %2, preparing processing of %1 previusly received insufficiently saturated individuals.").arg(procCoordHash->size()).arg(indiSatTimer->elapsed()), getLogObject());
2306
2307 }
2308
2309 } else {
2310 QTime* indiSatTimer = totallyPreCompItem->getIndividualSaturationTime();
2311 LOG(INFO, getLogDomain(), logTr("Individual saturation finished in %1 ms, waiting first insufficient individuals retrieval.").arg(indiSatTimer->elapsed()), getLogObject());
2312 }
2313
2314 }
2315
2316
2317 CConsistence* consistence = totallyPreCompItem->getConsistence();
2318 if (consistence) {
2319 consistence->setIndividualsRepresentativelyStored(true);
2320 if (!totallyPreCompItem->hasInsufficientSaturationIndividuals()) {
2321 consistence->setAllIndividualsRepresentativelyStored(true);
2322 }
2323 }
2324 }
2325 }
2326
2327 if (mConfPrecomputationIndividualsRetrievalWhileSaturation && !totallyPreCompItem->hasIndividualsSaturationCacheSynchronisation() && totallyPreCompItem->hasALLIndividualsSaturationOrderd() && !totallyPreCompItem->hasIndividualsSaturationAllOrderedCacheRetrieved() && totallyPreCompItem->hasInsufficientSaturationIndividuals()) {
2328 bool fullCompletionGraphConstruction = totallyPreCompItem->isFullCompletionGraphConstruction();
2329 if (!fullCompletionGraphConstruction) {
2330 totallyPreCompItem->setIndividualsSaturationAllOrderedCacheRetrieved(true);
2331 requestIndividualsPrecomputationRetrieval(totallyPreCompItem, false);
2332 }
2333 }
2334
2335 return true;
2336 }
2337 return false;
2338 }
2339
2340
2341
2342 void CTotallyPrecomputationThread::synchronouslyRetrieveIndividualsPrecomputation(CTotallyOntologyPrecomputationItem* totallyPreCompItem, COntologyPrecomputationItem* ontPreCompItem) {
2343 totallyPreCompItem->setIndividualsSaturationCacheSynchronisation(true);
2344
2345 cint64 limit = totallyPreCompItem->getCurrentIncompletelyHandledIndividualRetrievalLimit();
2346
2347
2348 bool fullCompletionGraphConstruction = totallyPreCompItem->isFullCompletionGraphConstruction();
2349 if (fullCompletionGraphConstruction) {
2350 limit = -1;
2351 }
2352 totallyPreCompItem->setPrecompuationRetrievingIncompletelyHandledIndividuals(true);
2353 totallyPreCompItem->setFirstIncompletelyHandledIndividualsRetrieved(true);
2354 CIndividualPrecomputationCoordinationHash* newRetrievalCoordHash = new CIndividualPrecomputationCoordinationHash();
2355 newRetrievalCoordHash->incUsageCount();
2356 mBackendAssocCache->getIncompletlyAssociationCachedIndividuals(ontPreCompItem->getOntology()->getOntologyID(), nullptr, newRetrievalCoordHash, true, false, limit);
2357 totallyPreCompItem->setPrecompuationRetrievingIncompletelyHandledIndividuals(false);
2358 if (newRetrievalCoordHash->size() > 0) {
2359 totallyPreCompItem->setRemainingIncompletelyHandlingIndividualComputationLimitIncreasingCount(newRetrievalCoordHash->getApproximateTotalIncompletelyHandledCount());
2360
2361 QTime*& indiPrecTimer = totallyPreCompItem->getIndividualPrecomputationTime();
2362 if (!indiPrecTimer) {
2363 indiPrecTimer = new QTime();
2364 indiPrecTimer->start();
2365 }
2366
2367 QTime* indiSatTimer = totallyPreCompItem->getIndividualSaturationTime();
2368 LOG(INFO, getLogDomain(), logTr("Individual saturation finished in %2, preparing processing of first %1 insufficiently saturated individuals.").arg(newRetrievalCoordHash->size()).arg(indiSatTimer->elapsed()), getLogObject());
2369 totallyPreCompItem->setPrecomputationProcessingCoordinationHash(newRetrievalCoordHash);
2370 totallyPreCompItem->setPrecomputationProcessingCoordinationHashIteratorCurrent(newRetrievalCoordHash->constBegin());
2371 totallyPreCompItem->setPrecomputationProcessingCoordinationHashIteratorEnd(newRetrievalCoordHash->constEnd());
2372
2373 } else {
2374
2375 QTime* indiSatTimer = totallyPreCompItem->getIndividualSaturationTime();
2376 LOG(INFO, getLogDomain(), logTr("Individual saturation finished in %1 ms without insufficient individuals.").arg(indiSatTimer->elapsed()), getLogObject());
2377
2378 decrementUsageFromIndividualPrecomputationCoordinationHash(newRetrievalCoordHash, totallyPreCompItem);
2379 totallyPreCompItem->setAllIncompletelyHandledIndividualsRetrieved(true);
2380 }
2381 }
2382
2383
2384 bool CTotallyPrecomputationThread::retrieveIndividualsPrecomputation(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
2385 if (!totallyPreCompItem->isPrecompuationRetrievingIncompletelyHandledIndividuals()) {
2386 totallyPreCompItem->setPrecompuationRetrievingIncompletelyHandledIndividuals(true);
2387 cint64 limit = totallyPreCompItem->getCurrentIncompletelyHandledIndividualRetrievalLimit();
2388 CIndividualPrecomputationCoordinationHash* newRetrievalCoordHash = new CIndividualPrecomputationCoordinationHash();
2389 newRetrievalCoordHash->incUsageCount();
2390 totallyPreCompItem->setPrecomputationRetrievalCoordinationHash(newRetrievalCoordHash);
2391 bool refillRetrievalCoordHash = totallyPreCompItem->getNonPrecompuationDirectIncompletelyHandledIndividualsRetrievingStreakSize() > 1;
2392 mBackendAssocCache->getIncompletlyAssociationCachedIndividuals(totallyPreCompItem->getOntology()->getOntologyID(), totallyPreCompItem->getPrecomputationProcessingCoordinationHash(), newRetrievalCoordHash, true, refillRetrievalCoordHash, limit);
2393 precomputationIndividualsRetrieved(totallyPreCompItem, true);
2394 return true;
2395 } else {
2396 return false;
2397 }
2398 }
2399
2400
2401
2402 bool CTotallyPrecomputationThread::requestIndividualsPrecomputationRetrieval(CTotallyOntologyPrecomputationItem* totallyPreCompItem, bool allIndividualsSaturated) {
2403 if (!totallyPreCompItem->isPrecompuationRetrievingIncompletelyHandledIndividuals()) {
2404 totallyPreCompItem->setPrecompuationRetrievingIncompletelyHandledIndividuals(true);
2405 cint64 limit = totallyPreCompItem->getCurrentIncompletelyHandledIndividualRetrievalLimit();
2406 CIndividualPrecomputationCoordinationHash* newRetrievalCoordHash = new CIndividualPrecomputationCoordinationHash();
2407 newRetrievalCoordHash->incUsageCount();
2408 totallyPreCompItem->setPrecomputationRetrievalCoordinationHash(newRetrievalCoordHash);
2409 CIndividualPrecomputationCoordinationHash* procCoordHash = totallyPreCompItem->getPrecomputationProcessingCoordinationHash();
2410 mBackendAssocCache->getIncompletlyAssociationCachedIndividuals(totallyPreCompItem->getOntology()->getOntologyID(), procCoordHash, newRetrievalCoordHash, allIndividualsSaturated, false, limit, new CRetrievedPrecomputationIndividualsCallbackEvent(this, totallyPreCompItem));
2411 if (procCoordHash) {
2412 LOG(INFO, getLogDomain(), logTr("Requesting more insufficiently handled individuals from representative cache, only %1 of appxoximately %2 remaining, %3 computing, %4 processed.").arg(totallyPreCompItem->getPrecomputationProcessingCoordinationHash()->getHashRemainingCount())
2413 .arg(totallyPreCompItem->getPrecomputationProcessingCoordinationHash()->getApproximateRemainingIncompletelyHandledCount()).arg(totallyPreCompItem->getPrecomputationProcessingCoordinationHash()->getHashComputationCount()).arg(totallyPreCompItem->getPrecomputationProcessingCoordinationHash()->getHashProcessedCount()), getLogObject());
2414 } else {
2415 LOG(INFO, getLogDomain(), logTr("Requesting first insufficiently handled individuals from representative cache."), getLogObject());
2416 }
2417 return true;
2418 } else {
2419 return false;
2420 }
2421 }
2422
2423
2424 bool CTotallyPrecomputationThread::precomputationIndividualsRetrieved(COntologyPrecomputationItem* ontPreCompItem, CRetrievedPrecomputationIndividualsCallbackEvent* pcce) {
2425 CTotallyOntologyPrecomputationItem* totallyPreCompItem = (CTotallyOntologyPrecomputationItem*)ontPreCompItem;
2426 precomputationIndividualsRetrieved(totallyPreCompItem, false);
2427 CIndividualPrecomputationCoordinationHash* coordHash = totallyPreCompItem->getPrecomputationProcessingCoordinationHash();
2428 cint64 computationLimit = totallyPreCompItem->getCurrentIncompletelyHandledIndividualComputationLimit();
2429 if (coordHash && coordHash->getHashRemainingCount() >= computationLimit || !totallyPreCompItem->isIndividualComputationRunning()) {
2430 doNextPendingTests();
2431 }
2432 return true;
2433 }
2434
2435
2436 bool CTotallyPrecomputationThread::precomputationIndividualsRetrieved(COntologyPrecomputationItem* ontPreCompItem, bool directly) {
2437 CTotallyOntologyPrecomputationItem* totallyPreCompItem = (CTotallyOntologyPrecomputationItem*)ontPreCompItem;
2438 CIndividualPrecomputationCoordinationHash* prevHash = totallyPreCompItem->getPrecomputationProcessingCoordinationHash();
2439 CIndividualPrecomputationCoordinationHash* newHash = totallyPreCompItem->getPrecomputationRetrievalCoordinationHash();
2440
2441 totallyPreCompItem->setPrecomputationProcessingCoordinationHashIteratorCurrent(newHash->constBegin());
2442 totallyPreCompItem->setPrecomputationProcessingCoordinationHashIteratorEnd(newHash->constEnd());
2443
2444 totallyPreCompItem->setPrecompuationIncompletelyHandledIndividualsRetrievalThresholdRequested(false);
2445 totallyPreCompItem->setCurrentIncompletelyHandledIndividualRetrievalThreshold(newHash->getHashRemainingCount() * totallyPreCompItem->getCurrentIncompletelyHandledIndividualRetrievalThresholdFactor());
2446
2447 if (prevHash) {
2448 #ifdef KONCLUDE_DEBUG_PRECOMPUTATION_SCHEDULING_LOGS
2449 LOG(INFO, getLogDomain(), logTr("prev hash: %1 insufficiently handled individuals, now at %2 computation, %3 processed, %4 correction, %5 total insufficient, %6 approx remain insufficient.").arg(prevHash->getHashRemainingCount()).arg(prevHash->getHashComputationCount()).arg(prevHash->getHashProcessedCount()).arg(prevHash->getApproximateCorrectionIncompletelyHandledCount()).arg(prevHash->getApproximateTotalIncompletelyHandledCount()).arg(prevHash->getApproximateRemainingIncompletelyHandledCount()), getLogObject());
2450 #endif // KONCLUDE_DEBUG_PRECOMPUTATION_SCHEDULING_LOGS
2451 newHash->incHashRemainingCount(prevHash->getHashRemainingCount());
2452 newHash->incHashProcessedCount(prevHash->getHashProcessedCount());
2453 newHash->incHashComputationCount(prevHash->getHashComputationCount());
2454 }
2455 #ifdef KONCLUDE_DEBUG_PRECOMPUTATION_SCHEDULING_LOGS
2456 LOG(INFO, getLogDomain(), logTr("new hash: %1 insufficiently handled individuals, now at %2 computation, %3 processed, %4 correction, %5 total insufficient, %6 approx remain insufficient.").arg(newHash->getHashRemainingCount()).arg(newHash->getHashComputationCount()).arg(newHash->getHashProcessedCount()).arg(newHash->getApproximateCorrectionIncompletelyHandledCount()).arg(newHash->getApproximateTotalIncompletelyHandledCount()).arg(newHash->getApproximateRemainingIncompletelyHandledCount()), getLogObject());
2457 #endif // KONCLUDE_DEBUG_PRECOMPUTATION_SCHEDULING_LOGS
2458
2459 totallyPreCompItem->setPrecomputationRetrievalCoordinationHash(nullptr);
2460 totallyPreCompItem->setPrecomputationProcessingCoordinationHash(newHash);
2461 totallyPreCompItem->setPrecompuationRetrievingIncompletelyHandledIndividuals(false);
2462
2463 if (!totallyPreCompItem->hasFirstIncompletelyHandledIndividualsRetrieved()) {
2464 totallyPreCompItem->setFirstIncompletelyHandledIndividualsRetrieved(true);
2465
2466 totallyPreCompItem->setRemainingIncompletelyHandlingIndividualComputationLimitIncreasingCount(newHash->getApproximateTotalIncompletelyHandledCount());
2467
2468 if (!totallyPreCompItem->hasIndividualSaturationRunning()) {
2469
2470 if (newHash->getHashRemainingCount() <= 0) {
2471 synchronouslyRetrieveIndividualsPrecomputation(totallyPreCompItem, ontPreCompItem);
2472 } else {
2473
2474 QTime*& indiPrecTimer = totallyPreCompItem->getIndividualPrecomputationTime();
2475 if (!indiPrecTimer) {
2476 indiPrecTimer = new QTime();
2477 indiPrecTimer->start();
2478 }
2479 totallyPreCompItem->setIndividualsSaturationCacheSynchronisation(true);
2480 LOG(INFO, getLogDomain(), logTr("Retrieved first %1 insufficiently handled individuals from representative cache, scheduling processing.").arg(newHash->getHashRemainingCount()), getLogObject());
2481 }
2482 }
2483 } else {
2484 if (directly) {
2485 LOG(INFO, getLogDomain(), logTr("Retrieved %1 insufficiently handled individuals directly from representative cache, scheduling processing.").arg(newHash->getHashRemainingCount()), getLogObject());
2486 } else {
2487 LOG(INFO, getLogDomain(), logTr("Retrieved %1 insufficiently handled individuals asynchronly from representative cache, scheduling processing.").arg(newHash->getHashRemainingCount()), getLogObject());
2488 }
2489 }
2490 decrementUsageFromIndividualPrecomputationCoordinationHash(prevHash, totallyPreCompItem);
2491 return true;
2492 }
2493
2494
2495
2496 bool CTotallyPrecomputationThread::decrementUsageFromIndividualPrecomputationCoordinationHash(CIndividualPrecomputationCoordinationHash* indiPrecompCoordHash, CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
2497 if (indiPrecompCoordHash) {
2498 indiPrecompCoordHash->decUsageCount();
2499 if (indiPrecompCoordHash->getUsageCount() == 0) {
2500 for (CIndividualPrecomputationCoordinationHash::iterator it = indiPrecompCoordHash->begin(), itEnd = indiPrecompCoordHash->end(); it != itEnd; ++it) {
2501 CBackendIndividualRetrievalComputationUpdateCoordinationHashData*& data = it.value();
2502 data->decUsageCount();
2503 if (data->getUsageCount() == 0) {
2504 delete data;
2505 data = nullptr;
2506 }
2507 }
2508 delete indiPrecompCoordHash;
2509 return true;
2510 }
2511 }
2512 return false;
2513 }
2514
2515
2516
2517 bool CTotallyPrecomputationThread::determineMinimumNextConceptID(CConsistence* consistence, COntologyPrecomputationItem* ontPreCompItem) {
2518 CConsistenceTaskData* consTaskData = (CConsistenceTaskData*)consistence->getConsistenceModelData();
2519 if (consTaskData) {
2520 CSatisfiableCalculationTask* detTask = consTaskData->getDeterministicSatisfiableTask();
2521 CSatisfiableCalculationTask* nonDetTask = consTaskData->getCompletionGraphCachedSatisfiableTask();
2522 CConceptVector* extendedConVec = nonDetTask->getProcessingDataBox()->getExtendedConceptVector(false);
2523 if (extendedConVec) {
2524 cint64 minNextId = extendedConVec->getItemCount();
2525 ontPreCompItem->getOntology()->getTBox()->setMinimalNextConceptID(minNextId);
2526 return true;
2527 }
2528 }
2529 return false;
2530 }
2531
2532
2533 bool CTotallyPrecomputationThread::precomputationTested(COntologyPrecomputationItem* ontPreCompItem, CPrecomputationTestingItem* preTestItem, CPrecomputationCalculatedCallbackEvent* pcce) {
2534 CTotallyOntologyPrecomputationItem* totallyPreCompItem = (CTotallyOntologyPrecomputationItem*)ontPreCompItem;
2535 if (preTestItem->getPrecomputationTestingType() == CPrecomputationTestingItem::CONSISTENCEPRECOMPUTATIONTYPE) {
2536 CConsistencePrecomputationTestingItem* consPreTestItem = (CConsistencePrecomputationTestingItem*)preTestItem;
2537 totallyPreCompItem->setIndividualStepRunning(false);
2538 totallyPreCompItem->setIndividualPrecomputationChecked(true);
2539 totallyPreCompItem->setConsistenceCheched(true);
2540
2541 if (pcce->hasCalculationError()) {
2542 LOG(ERROR,getLogDomain(),logTr("Error in computation, consistency testing for ontology '%1' failed.").arg(ontPreCompItem->getOntology()->getTerminologyName()),getLogObject());
2543 totallyPreCompItem->getConsistencePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED);
2544 totallyPreCompItem->getIndividualPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED);
2545 } else {
2546 CConsistence* consistence = totallyPreCompItem->getConsistence();
2547 consistence->setConsistenceModelData(totallyPreCompItem->getConsistenceData());
2548 consistence->setOntologyConsistent(pcce->getTestResultSatisfiable());
2549 determineMinimumNextConceptID(consistence, ontPreCompItem);
2550
2551 if (consistence->isOntologyConsistent()) {
2552 CIndividualPrecomputationCoordinationHash* newRetrievalCoordHash = new CIndividualPrecomputationCoordinationHash();
2553 mBackendAssocCache->getIncompletlyAssociationCachedIndividuals(totallyPreCompItem->getOntology()->getOntologyID(), nullptr, newRetrievalCoordHash, true, false, -1);
2554 if (!newRetrievalCoordHash->isEmpty()) {
2555 LOG(WARN, getLogDomain(), logTr("Representative cache has incompletely processed individuals although individual computation finished and ontology is consistent."), getLogObject());
2556 }
2557 delete newRetrievalCoordHash;
2558 }
2559 }
2560 return true;
2561
2562 } else if (preTestItem->getPrecomputationTestingType() == CPrecomputationTestingItem::INDIVIDUALPRECOMPUTATIONTYPE) {
2563 CIndividualPrecomputationTestingItem* indiPreTestItem = (CIndividualPrecomputationTestingItem*)preTestItem;
2564 totallyPreCompItem->decIndividualComputationRunningCount();
2565
2566 bool expansionPropagationCutted = indiPreTestItem->getRepresentativeCacheUpdatingAdapter()->isExpansionPropagationCutted();
2567 if (expansionPropagationCutted) {
2568 totallyPreCompItem->incRecomputationExpansionPropagationCuttedCount(1);
2569 totallyPreCompItem->incCurrentRecomputationExpansionPropagationCuttedReductionFactor(totallyPreCompItem->getRecomputationExpansionPropagationCuttedReductionIncreaseFactor());
2570 } else {
2571 totallyPreCompItem->decCurrentRecomputationExpansionPropagationCuttedReductionFactor(totallyPreCompItem->getRecomputationExpansionPropagationCuttedReductionRecoveryFactor());
2572 }
2573
2574 QMap<cint64, CIndividualPrecomputationTestingItem*>* recomIdTestingItemMap = totallyPreCompItem->getRecomputationIdTestingItemMap();
2575 recomIdTestingItemMap->remove(indiPreTestItem->getRepresentativeCacheUpdatingAdapter()->getRepresentativeCacheRecomputationId());
2576 totallyPreCompItem->decMaxHandledRecomputationIdRemainingReporting();
2577 if (totallyPreCompItem->getMaxHandledRecomputationIdRemainingReporting() <= 0 && !recomIdTestingItemMap->isEmpty()) {
2578 cint64 firstRecomputationId = recomIdTestingItemMap->constBegin().key();
2579 totallyPreCompItem->setMaxHandledRecomputationIdRemainingReporting(50);
2580 mBackendAssocCache->reportMaximumHandledRecomputationId(totallyPreCompItem->getOntology()->getOntologyID(), firstRecomputationId-1);
2581 }
2582
2583 CIndividualPrecomputationCoordinationHash* precomputationProcessingCoordinationHash = totallyPreCompItem->getPrecomputationProcessingCoordinationHash();
2584 if (!precomputationProcessingCoordinationHash) {
2585 precomputationProcessingCoordinationHash = indiPreTestItem->getIndividualComputationCoordinationHash();
2586 }
2587 QSet<CIndividualReference>* currentIndiComputationSet = totallyPreCompItem->getCurrentIndividualComputationSet();
2588 QList<CIndividualReference>* computedIndiList = indiPreTestItem->getIndividualComputationList();
2589 for (CIndividualReference indiRef : *indiPreTestItem->getIndividualComputationList()) {
2590 //currentIndiComputationSet->remove(indiRef);
2591 if (precomputationProcessingCoordinationHash) {
2592 precomputationProcessingCoordinationHash->decHashComputationCount();
2593 precomputationProcessingCoordinationHash->incHashProcessedCount();
2594 CBackendIndividualRetrievalComputationUpdateCoordinationHashData* data = (*precomputationProcessingCoordinationHash)[indiRef.getIndividualID()];
2595 if (data) {
2596 data->setProcessed(true);
2597 }
2598 }
2599 }
2600 CIndividualPrecomputationCoordinationHash* testPrecomputationProcessingCoordinationHash = indiPreTestItem->getIndividualComputationCoordinationHash();
2601 decrementUsageFromIndividualPrecomputationCoordinationHash(testPrecomputationProcessingCoordinationHash, totallyPreCompItem);
2602
2603 #ifdef KONCLUDE_DEBUG_PRECOMPUTATION_SCHEDULING_LOGS
2604 LOG(INFO, getLogDomain(), logTr("%7 individuals precomputed, remaining coordination hash: %1 insufficiently handled individuals, now at %2 computation, %3 processed, %4 correction, %5 total insufficient, %6 approx remain insufficient.").arg(precomputationProcessingCoordinationHash->getHashRemainingCount()).arg(precomputationProcessingCoordinationHash->getHashComputationCount()).arg(precomputationProcessingCoordinationHash->getHashProcessedCount()).arg(precomputationProcessingCoordinationHash->getApproximateCorrectionIncompletelyHandledCount()).arg(precomputationProcessingCoordinationHash->getApproximateTotalIncompletelyHandledCount()).arg(precomputationProcessingCoordinationHash->getApproximateRemainingIncompletelyHandledCount()).arg(computedIndiList->count()), getLogObject());
2605 #endif // KONCLUDE_DEBUG_PRECOMPUTATION_SCHEDULING_LOGS
2606
2607
2608 if (!pcce->getTestResultSatisfiable()) {
2609 totallyPreCompItem->setIndividualPrecomputationClashed(true);
2610 }
2611
2612 if (!totallyPreCompItem->isIndividualComputationRunning() && totallyPreCompItem->hasAllIndividualPrecomputationCreated()) {
2613 totallyPreCompItem->setIndividualStepRunning(false);
2614 totallyPreCompItem->setIndividualComputationRunning(false);
2615 totallyPreCompItem->setIndividualPrecomputationChecked(true);
2616 totallyPreCompItem->setConsistenceCheched(true);
2617
2618 CConsistence* consistence = totallyPreCompItem->getConsistence();
2619 if (consistence) {
2620 consistence->setAllIndividualsRepresentativelyStored(true);
2621 }
2622 }
2623
2624 if (pcce->hasCalculationError()) {
2625 if (!totallyPreCompItem->hasIndividualPrecomputationClashed()) {
2626 LOG(ERROR, getLogDomain(), logTr("Error in computation, individual precomputation for ontology '%1' failed.").arg(ontPreCompItem->getOntology()->getTerminologyName()), getLogObject());
2627 totallyPreCompItem->getConsistencePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED);
2628 totallyPreCompItem->getIndividualPrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED);
2629 }
2630 } else if (indiPreTestItem->getTaskPreyingAdapter()) {
2631 CConsistence* consistence = totallyPreCompItem->getConsistence();
2632 if (consistence) {
2633 consistence->setConsistenceModelData(totallyPreCompItem->getConsistenceData());
2634 consistence->setOntologyConsistent(!totallyPreCompItem->hasIndividualPrecomputationClashed());
2635 determineMinimumNextConceptID(consistence, ontPreCompItem);
2636 }
2637 }
2638 return true;
2639
2640 } else if (preTestItem->getPrecomputationTestingType() == CPrecomputationTestingItem::CONCEPTCYCLEPRECOMPUTATIONTYPE) {
2641 CConceptCyclePrecomputationTestingItem* conCyclePreTestItem = (CConceptCyclePrecomputationTestingItem*)preTestItem;
2642 CConceptCycleData* conCycleData = conCyclePreTestItem->getConceptCycleData();
2643 CBOXSET<CConcept*>* classCycleSet = conCycleData->getCycleClassSet();
2644
2645 if (pcce->hasCalculationError()) {
2646 LOG(ERROR,getLogDomain(),logTr("Error in computation, cyclic concept graph caching for ontology '%1' failed.").arg(ontPreCompItem->getOntology()->getTerminologyName()),getLogObject());
2647 totallyPreCompItem->setConsistenceCheched(true);
2648 totallyPreCompItem->getCyclePrecomputationStep()->submitRequirementsUpdate(COntologyProcessingStatus::PSFAILED);
2649 } else {
2650 if (pcce->getTestResultSatisfiable()) {
2651 // insert into cache
2652 CTempMemoryPoolContainerAllocationManager tmpMemMan(mContext.getMemoryPoolProvider());
2653 CContextBase* tmpContext = CObjectParameterizingAllocator< CContextBase,CMemoryAllocationManager* >::allocateAndConstructAndParameterize(&tmpMemMan,&tmpMemMan);
2654
2655 CCACHINGLIST<CCacheValue>* cacheValueList = CObjectParameterizingAllocator< CCACHINGLIST<CCacheValue>,CContext* >::allocateAndConstructAndParameterize(&tmpMemMan,tmpContext);
2656 for (CBOXSET<CConcept*>::const_iterator it = classCycleSet->constBegin(), itEnd = classCycleSet->constEnd(); it != itEnd; ++it) {
2657 CConcept* classConcept(*it);
2658 CCacheValue cacheValue(classConcept->getConceptTag(),(cint64)classConcept,CCacheValue::CACHEVALTAGANDCONCEPT);
2659 cacheValueList->append(cacheValue);
2660 }
2661
2662 CReuseCompletionGraphCacheEntryExpandWriteData* writeData = CObjectAllocator<CReuseCompletionGraphCacheEntryExpandWriteData>::allocateAndConstruct(&tmpMemMan);
2663 writeData->initExpandWriteData(cacheValueList,cacheValueList,conCyclePreTestItem->getJobInstantiation());
2664 mReuseCompletionGraphCacheWriter->writeExpandCache(writeData,tmpMemMan.takeMemoryPools());
2665
2666 }
2667 }
2668
2669 if (!totallyPreCompItem->hasRemainingConceptCyclePrecomputation() && !totallyPreCompItem->hasCurrentPrecomputationTesting()) {
2670 totallyPreCompItem->setConceptCyclePrecomputationChecked(true);
2671 }
2672
2673 }
2674 return false;
2675 }
2676
2677
2678 bool CTotallyPrecomputationThread::finishOntologyPrecomputation(CTotallyOntologyPrecomputationItem* totallyPreCompItem) {
2679 CConcreteOntology* ontology = totallyPreCompItem->getOntology();
2680 if (totallyPreCompItem->areAllStepFinished()) {
2681 totallyPreCompItem->setPrecomputationFinished(true);
2682
2683 CPrecomputation* precomputation = ontology->getPrecomputation();
2684 precomputation->setPrecomputed(true);
2685 }
2686
2687 CConsistenceStatisticsCollectionStrings* classifStatCollStrings = totallyPreCompItem->getConsistenceStatisticsCollectionStrings();
2688 CPrecomputation* precomputation = ontology->getPrecomputation();
2689 if (precomputation) {
2690 precomputation->setPrecomputationStatistics(classifStatCollStrings);
2691 }
2692
2693 CConsistence* consistence = ontology->getConsistence();
2694 if (consistence) {
2695 consistence->setConsistenceStatistics(classifStatCollStrings);
2696 }
2697
2698 totallyPreCompItem->doPrecomputationFinishedCallback(true);
2699
2700 mActiveOntItemSet.remove(totallyPreCompItem);
2701 mInactiveOntItemSet.insert(totallyPreCompItem);
2702 return true;
2703 }
2704
2705
2706
2707
2708
2709
2710 }; // end namespace Consistiser
2711
2712 }; // end namespace Reasoner
2713
2714 }; // end namespace Konclude