| 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 "CReasonerManagerThread.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Manager { |
| 31 |
|
| 32 |
|
| 33 |
CReasonerManagerThread::CReasonerManagerThread(CWatchDog *threadWatchDog) : CIntervalThread("Reasoner-Manager",threadWatchDog) { |
| 34 |
mWatchDog = threadWatchDog; |
| 35 |
mCalculationManager = 0; |
| 36 |
mPrecomputationManager = 0; |
| 37 |
mPreprocessingManager = 0; |
| 38 |
mRealizationManager = 0; |
| 39 |
mAnswererManager = 0; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
CReasonerManager *CReasonerManagerThread::initializeManager(CConfigurationProvider *configurationProvider) { |
| 44 |
//stopThread(); |
| 45 |
|
| 46 |
configProvider = configurationProvider; |
| 47 |
|
| 48 |
classificationMan = CConfigManagerReader::readClassificationManagerConfig(configProvider); |
| 49 |
|
| 50 |
bool configErrorFlag = false; |
| 51 |
mWorkControllerCount = 1; |
| 52 |
QString workerCountString = CConfigDataReader::readConfigString(configProvider,"Konclude.Calculation.WorkerCount",QString(),&configErrorFlag); |
| 53 |
if (!configErrorFlag) { |
| 54 |
if (workerCountString == "AUTO") { |
| 55 |
mWorkControllerCount = CThread::idealThreadCount(); |
| 56 |
} else { |
| 57 |
qint64 convertedWorkerCount = workerCountString.toInt(&configErrorFlag); |
| 58 |
if (configErrorFlag) { |
| 59 |
mWorkControllerCount = convertedWorkerCount; |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
configErrorFlag = false; |
| 64 |
cint64 processorCount = 0; |
| 65 |
QString processorCountString = CConfigDataReader::readConfigString(configProvider,"Konclude.Calculation.ProcessorCount",QString(),&configErrorFlag); |
| 66 |
if (!configErrorFlag) { |
| 67 |
if (processorCountString == "AUTO") { |
| 68 |
processorCount = CThread::idealThreadCount(); |
| 69 |
} else { |
| 70 |
qint64 convertedWorkerCount = processorCountString.toInt(&configErrorFlag); |
| 71 |
if (configErrorFlag) { |
| 72 |
processorCount = convertedWorkerCount; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
mWorkControllerCount = qMax(processorCount,mWorkControllerCount); |
| 77 |
|
| 78 |
mConfgAdaptThreadPoolToWorkerCount = CConfigDataReader::readConfigBoolean(configProvider, "Konclude.Calculation.AdaptThreadPoolSizeProcessorCount", true); |
| 79 |
mBlockThreadPoolThreadCount = CConfigDataReader::readConfigBoolean(configProvider, "Konclude.Calculation.BlockingThreadPoolThreadsCount", 1); |
| 80 |
|
| 81 |
|
| 82 |
//if (!isRunning()) { |
| 83 |
mWatchDog = 0; |
| 84 |
unsatCache = 0; |
| 85 |
mSatExpCache = 0; |
| 86 |
mReuseCompGraphCache = 0; |
| 87 |
mSatNodeExpCache = 0; |
| 88 |
//} |
| 89 |
mPrecomputationManager = new CPrecomputationManager(this); |
| 90 |
mPreprocessingManager = new CPreprocessingManager(this); |
| 91 |
mRealizationManager = new CRealizationManager(this); |
| 92 |
mRequirementExpander = new COntologyProcessingRequirementExpander(); |
| 93 |
|
| 94 |
startThread(); |
| 95 |
|
| 96 |
return this; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
CReasonerManagerThread::~CReasonerManagerThread() { |
| 102 |
stopThread(); |
| 103 |
} |
| 104 |
|
| 105 |
CReasonerManager* CReasonerManagerThread::reasoningSatisfiableCalcualtionJob(CSatisfiableCalculationJob* satCalcJob, CCallbackData* callback) { |
| 106 |
postEvent(new CReasoningSatisfiableCalculationJobEvent(satCalcJob,callback)); |
| 107 |
return this; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
CJobSatisfiableResult* CReasonerManagerThread::reasoningSatisfiableCalcualtionJob(CSatisfiableCalculationJob* satCalcJob) { |
| 113 |
CJobSatisfiableCallbackContextData* satCalcData = nullptr; |
| 114 |
CBlockingCallbackData callback; |
| 115 |
postEvent(new CReasoningSatisfiableCalculationJobEvent(satCalcJob,&callback)); |
| 116 |
callback.waitForCallback(); |
| 117 |
satCalcData = (CJobSatisfiableCallbackContextData*)callback.takeCallbackDataContext(); |
| 118 |
return satCalcData; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
CReasonerManager *CReasonerManagerThread::reasoningQuery(CQuery *query, CCallbackData *callback) { |
| 123 |
postEvent(new CCalcQueryEvent(query,callback)); |
| 124 |
return this; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
CReasonerManager *CReasonerManagerThread::reasoningQuery(CQuery *query) { |
| 129 |
CBlockingCallbackData callback; |
| 130 |
postEvent(new CCalcQueryEvent(query,&callback)); |
| 131 |
callback.waitForCallback(); |
| 132 |
return this; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
CReasonerManager *CReasonerManagerThread::prepareOntology(CConcreteOntology* ontology, const QList<COntologyProcessingRequirement*>& reqList, CCallbackData *callback) { |
| 137 |
postEvent(new CPrepareOntologyEvent(ontology,reqList,callback)); |
| 138 |
return this; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
CReasonerManager *CReasonerManagerThread::prepareOntology(CConcreteOntology* ontology, const QList<COntologyProcessingRequirement*>& reqList) { |
| 143 |
CBlockingCallbackData callback; |
| 144 |
postEvent(new CPrepareOntologyEvent(ontology,reqList,&callback)); |
| 145 |
callback.waitForCallback(); |
| 146 |
return this; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
CUnsatisfiableCache *CReasonerManagerThread::getUnsatisfiableCache() { |
| 153 |
return unsatCache; |
| 154 |
} |
| 155 |
|
| 156 |
CCompletionGraphCache *CReasonerManagerThread::getCompletionGraphCache() { |
| 157 |
return mReuseCompGraphCache; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
CSaturationCache* CReasonerManagerThread::getSaturationAssociationExpansionCache() { |
| 162 |
return mSatNodeExpCache; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
CBackendCache* CReasonerManagerThread::getBackendAssociationCache() { |
| 167 |
return mBackendAssCache; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
COccurrenceStatisticsCache* CReasonerManagerThread::getOccurrenceStatisticsCache() { |
| 172 |
return mOccStatsCache; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
CCalculationManager *CReasonerManagerThread::getCalculationManager() { |
| 177 |
return mCalculationManager; |
| 178 |
} |
| 179 |
|
| 180 |
CPrecomputationManager* CReasonerManagerThread::getPrecomputationManager() { |
| 181 |
return mPrecomputationManager; |
| 182 |
} |
| 183 |
|
| 184 |
CPreprocessingManager* CReasonerManagerThread::getPreprocessingManager() { |
| 185 |
return mPreprocessingManager; |
| 186 |
} |
| 187 |
|
| 188 |
CRealizationManager* CReasonerManagerThread::getRealizationManager() { |
| 189 |
return mRealizationManager; |
| 190 |
} |
| 191 |
|
| 192 |
void CReasonerManagerThread::readConfig(CConfigurationBase *config) { |
| 193 |
|
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
CTaskHandleAlgorithm *CReasonerManagerThread::createTaskHandleAlgorithm() { |
| 199 |
CUnsatisfiableCacheHandler* unsatCacheHandler = nullptr; |
| 200 |
CSatisfiableExpanderCacheHandler* satExpCacheHandler = nullptr; |
| 201 |
CReuseCompletionGraphCacheHandler* reuseCompGraphCacheHandler = nullptr; |
| 202 |
CSaturationNodeExpansionCacheHandler* satNodeCacheHandler = nullptr; |
| 203 |
CComputedConsequencesCacheHandler* compConsCachHandler = nullptr; |
| 204 |
CSaturationNodeBackendAssociationCacheHandler* backendAssCacheHandler = nullptr; |
| 205 |
CIndividualNodeBackendCacheHandler* backendCacheHandler = nullptr; |
| 206 |
COccurrenceStatisticsCacheHandler* occStatsCacheHandler = nullptr; |
| 207 |
CSatisfiableTaskSaturationOccurrenceStatisticsCollector* satTaskOccStatCollector = nullptr; |
| 208 |
if (unsatCache) { |
| 209 |
unsatCacheHandler = new CUnsatisfiableCacheHandler(unsatCache->getCacheReader(),unsatCache->getCacheWriter()); |
| 210 |
} |
| 211 |
if (mSatExpCache) { |
| 212 |
satExpCacheHandler = new CSatisfiableExpanderCacheHandler(mSatExpCache->createCacheReader(),mSatExpCache->createCacheWriter()); |
| 213 |
} |
| 214 |
if (mReuseCompGraphCache) { |
| 215 |
reuseCompGraphCacheHandler = new CReuseCompletionGraphCacheHandler(mReuseCompGraphCache->createCacheReader(),mReuseCompGraphCache->createCacheWriter()); |
| 216 |
} |
| 217 |
if (mSatNodeExpCache) { |
| 218 |
satNodeCacheHandler = new CSaturationNodeExpansionCacheHandler(mSatNodeExpCache->createCacheReader(),mSatNodeExpCache->createCacheWriter()); |
| 219 |
} |
| 220 |
if (mCompConsCache) { |
| 221 |
compConsCachHandler = new CComputedConsequencesCacheHandler(mCompConsCache->createCacheReader(),mCompConsCache->createCacheWriter()); |
| 222 |
} |
| 223 |
COccurrenceStatisticsCacheWriter* occStatsCacheWriter = nullptr; |
| 224 |
if (mOccStatsCache) { |
| 225 |
occStatsCacheWriter = mOccStatsCache->createCacheWriter(); |
| 226 |
satTaskOccStatCollector = new CSatisfiableTaskSaturationOccurrenceStatisticsCollector(occStatsCacheWriter); |
| 227 |
occStatsCacheHandler = new COccurrenceStatisticsCacheHandler(occStatsCacheWriter); |
| 228 |
} |
| 229 |
if (mBackendAssCache) { |
| 230 |
CBackendRepresentativeMemoryCacheWriter* backAssCacheWriter = mBackendAssCache->createCacheWriter(); |
| 231 |
CBackendRepresentativeMemoryCacheReader* backAssCacheReader = mBackendAssCache->createCacheReader(); |
| 232 |
backendAssCacheHandler = new CSaturationNodeBackendAssociationCacheHandler(backAssCacheReader, backAssCacheWriter, occStatsCacheWriter); |
| 233 |
backendCacheHandler = new CIndividualNodeBackendCacheHandler(backAssCacheReader, backAssCacheWriter); |
| 234 |
} |
| 235 |
CCalculationTableauApproximationSaturationTaskHandleAlgorithm* approxSatHandleAlg = new CCalculationTableauApproximationSaturationTaskHandleAlgorithm(backendAssCacheHandler, satTaskOccStatCollector); |
| 236 |
CCalculationTableauCompletionTaskHandleAlgorithm* compTaskHandleAlg = new CCalculationTableauCompletionTaskHandleAlgorithm(unsatCacheHandler,satExpCacheHandler,reuseCompGraphCacheHandler,satNodeCacheHandler,compConsCachHandler,backendCacheHandler, occStatsCacheHandler); |
| 237 |
return new CCalculationChooseTaskHandleAlgorithm(compTaskHandleAlg,approxSatHandleAlg); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
void CReasonerManagerThread::threadStarted() { |
| 243 |
CIntervalThread::threadStarted(); |
| 244 |
// generate worker framework |
| 245 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Initializing reasoner. Creating calculation context."),this); |
| 246 |
|
| 247 |
if (mConfgAdaptThreadPoolToWorkerCount) { |
| 248 |
QThreadPool::globalInstance()->setMaxThreadCount(mWorkControllerCount); |
| 249 |
} |
| 250 |
if (mBlockThreadPoolThreadCount > 0) { |
| 251 |
for (cint64 i = 0; i < mBlockThreadPoolThreadCount; ++i) { |
| 252 |
QtConcurrent::run(QThreadPool::globalInstance(), [&]() { |
| 253 |
mBlockThreadPoolThreadsBlockingSemaphore.acquire(1); |
| 254 |
mBlockThreadPoolThreadsReleasingSemaphore.release(1); |
| 255 |
}); |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
unsatCache = new COccurrenceUnsatisfiableCache(mWorkControllerCount+2); |
| 260 |
mSatExpCache = new CSignatureSatisfiableExpanderCache(configProvider->getCurrentConfiguration()); |
| 261 |
mReuseCompGraphCache = new CReuseCompletionGraphCache(); |
| 262 |
mSatNodeExpCache = new CSaturationNodeAssociatedExpansionCache(configProvider->getCurrentConfiguration()); |
| 263 |
mCompConsCache = new CComputedConsequencesCache(configProvider->getCurrentConfiguration()); |
| 264 |
mBackendAssCache = new CBackendRepresentativeMemoryCache(configProvider->getCurrentConfiguration()); |
| 265 |
mOccStatsCache = new COccurrenceStatisticsCache(configProvider->getCurrentConfiguration()); |
| 266 |
|
| 267 |
CConfigDependedCalculationFactory* calcFactory = new CConfigDependedCalculationFactory(this); |
| 268 |
CCalculationManager* calculationManager = calcFactory->createCalculationManager(configProvider); |
| 269 |
calcFactory->initializeManager(calculationManager,configProvider); |
| 270 |
mCalculationManager = calculationManager; |
| 271 |
|
| 272 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Reasoner initialized with %1 processing unit(s).").arg(mWorkControllerCount),this); |
| 273 |
|
| 274 |
startTimerWithInterval(PROGRESSQUERYTIMER,10000); |
| 275 |
} |
| 276 |
|
| 277 |
void CReasonerManagerThread::threadStopped() { |
| 278 |
CIntervalThread::threadStopped(); |
| 279 |
|
| 280 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Closing Reasoner."),this); |
| 281 |
|
| 282 |
//QThread::msleep(50); |
| 283 |
|
| 284 |
delete mCalculationManager; |
| 285 |
delete mPrecomputationManager; |
| 286 |
delete mPreprocessingManager; |
| 287 |
delete mRealizationManager; |
| 288 |
|
| 289 |
if (unsatCache) { |
| 290 |
unsatCache->stopThread(true); |
| 291 |
delete unsatCache; |
| 292 |
} |
| 293 |
if (mSatExpCache) { |
| 294 |
mSatExpCache->stopThread(true); |
| 295 |
delete mSatExpCache; |
| 296 |
} |
| 297 |
if (mReuseCompGraphCache) { |
| 298 |
mReuseCompGraphCache->stopThread(true); |
| 299 |
delete mReuseCompGraphCache; |
| 300 |
} |
| 301 |
if (mSatNodeExpCache) { |
| 302 |
mSatNodeExpCache->stopThread(true); |
| 303 |
delete mSatNodeExpCache; |
| 304 |
} |
| 305 |
|
| 306 |
if (mBlockThreadPoolThreadCount > 0) { |
| 307 |
mBlockThreadPoolThreadsBlockingSemaphore.release(mBlockThreadPoolThreadCount); |
| 308 |
mBlockThreadPoolThreadsReleasingSemaphore.acquire(mBlockThreadPoolThreadCount); |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Reasoner closed."),this); |
| 314 |
|
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
void CReasonerManagerThread::logQueryProgressUpdates() { |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
bool CReasonerManagerThread::processTimer(qint64 timerID) { |
| 324 |
if (timerID == PROGRESSQUERYTIMER) { |
| 325 |
logQueryProgressUpdates(); |
| 326 |
return true; |
| 327 |
} |
| 328 |
return false; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
const QList<COntologyRequirementPair> CReasonerManagerThread::getRequirementsForQuery(CQuery* query) { |
| 334 |
QList<COntologyRequirementPair> ontReqList; |
| 335 |
CSatisfiableCalculationJobsQuery* jobQuery = dynamic_cast<CSatisfiableCalculationJobsQuery*>(query); |
| 336 |
if (jobQuery) { |
| 337 |
QList<COntologyProcessingRequirement*> reqList; |
| 338 |
reqList.append(mRequirementExpander->getRequiredIndividualPrecomputationOntologyProcessingStepRequirement()); |
| 339 |
CQUERYLIST<CCalculationJob*> jobList(jobQuery->getJobList()); |
| 340 |
foreach (CCalculationJob* calcJob, jobList) { |
| 341 |
CConcreteOntology* ontology = calcJob->getOntology(); |
| 342 |
|
| 343 |
QList<COntologyProcessingRequirement*> ontSpecReqList = mRequirementExpander->getUnsatisfiedRequirementsExpanded(reqList,ontology); |
| 344 |
foreach (COntologyProcessingRequirement* ontReq, ontSpecReqList) { |
| 345 |
ontReqList.append(COntologyRequirementPair(ontology,ontReq)); |
| 346 |
} |
| 347 |
|
| 348 |
CSatisfiableCalculationJob* satCalcJob = dynamic_cast<CSatisfiableCalculationJob*>(calcJob); |
| 349 |
if (satCalcJob) { |
| 350 |
for (CSatisfiableCalculationConstruct* satCalcConstIt = satCalcJob->getSatisfiableCalculationConstructs(); satCalcConstIt; satCalcConstIt = satCalcConstIt->getNextConstruct()) { |
| 351 |
CSatisfiableCalculationConceptConstruct* satCalcConConstruct = dynamic_cast<CSatisfiableCalculationConceptConstruct*>(satCalcConstIt); |
| 352 |
if (satCalcConConstruct) { |
| 353 |
for (CXSortedNegLinker<CConcept*>* conConstIt = satCalcConConstruct->getConstructConceptLinker(); conConstIt; conConstIt = conConstIt->getNext()) { |
| 354 |
CConcept* concept = conConstIt->getData(); |
| 355 |
bool conceptNegation = conConstIt->isNegated(); |
| 356 |
COntologyProcessingConceptSaturationRequirement* conSatReq = new COntologyProcessingConceptSaturationRequirement(concept,conceptNegation); |
| 357 |
ontReqList.append(COntologyRequirementPair(ontology,conSatReq)); |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
} |
| 364 |
} |
| 365 |
CConsistencePremisingQuery* consQuery = dynamic_cast<CConsistencePremisingQuery*>(query); |
| 366 |
if (consQuery) { |
| 367 |
CConcreteOntology* ontology = consQuery->getOntology(); |
| 368 |
QList<COntologyProcessingRequirement*> reqList; |
| 369 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSCONSISTENCY)); |
| 370 |
reqList = mRequirementExpander->getUnsatisfiedRequirementsExpanded(reqList,ontology); |
| 371 |
foreach (COntologyProcessingRequirement* ontReq, reqList) { |
| 372 |
ontReqList.append(COntologyRequirementPair(ontology,ontReq)); |
| 373 |
} |
| 374 |
} |
| 375 |
CTaxonomyPremisingQuery* taxQuery = dynamic_cast<CTaxonomyPremisingQuery*>(query); |
| 376 |
if (taxQuery) { |
| 377 |
CConcreteOntology* ontology = taxQuery->getOntology(); |
| 378 |
QList<COntologyProcessingRequirement*> reqList; |
| 379 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSCLASSCLASSIFY)); |
| 380 |
reqList = mRequirementExpander->getUnsatisfiedRequirementsExpanded(reqList,ontology); |
| 381 |
foreach (COntologyProcessingRequirement* ontReq, reqList) { |
| 382 |
ontReqList.append(COntologyRequirementPair(ontology,ontReq)); |
| 383 |
} |
| 384 |
} |
| 385 |
CClassificationPremisingQuery* classQuery = dynamic_cast<CClassificationPremisingQuery*>(query); |
| 386 |
if (classQuery) { |
| 387 |
CConcreteOntology* ontology = classQuery->getOntology(); |
| 388 |
QList<COntologyProcessingRequirement*> reqList; |
| 389 |
if (classQuery->isConceptClassificationRequired()) { |
| 390 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSCLASSCLASSIFY)); |
| 391 |
} |
| 392 |
if (classQuery->isObjectRoleClassificationRequired()) { |
| 393 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSOBJECTROPERTYCLASSIFY)); |
| 394 |
} |
| 395 |
if (classQuery->isDataRoleClassificationRequired()) { |
| 396 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSDATAROPERTYCLASSIFY)); |
| 397 |
} |
| 398 |
reqList = mRequirementExpander->getUnsatisfiedRequirementsExpanded(reqList,ontology); |
| 399 |
foreach (COntologyProcessingRequirement* ontReq, reqList) { |
| 400 |
ontReqList.append(COntologyRequirementPair(ontology,ontReq)); |
| 401 |
} |
| 402 |
} |
| 403 |
CRealizationPremisingQuery* realQuery = dynamic_cast<CRealizationPremisingQuery*>(query); |
| 404 |
if (realQuery) { |
| 405 |
CConcreteOntology* ontology = realQuery->getOntology(); |
| 406 |
QList<COntologyProcessingRequirement*> reqList; |
| 407 |
if (realQuery->isDynamicRealisationRequired()) { |
| 408 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSCLASSCLASSIFY)); |
| 409 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSOBJECTROPERTYCLASSIFY)); |
| 410 |
reqList.append(realQuery->getDynamicRealizationRequirement()); |
| 411 |
} else { |
| 412 |
if (realQuery->isSameIndividualRealisationRequired()) { |
| 413 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSSAMEINDIVIDUALSREALIZE)); |
| 414 |
} |
| 415 |
if (realQuery->isConceptRealisationRequired()) { |
| 416 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSCONCEPTREALIZE)); |
| 417 |
} |
| 418 |
if (realQuery->isRoleRealisationRequired()) { |
| 419 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSROLEREALIZE)); |
| 420 |
} |
| 421 |
} |
| 422 |
reqList = mRequirementExpander->getUnsatisfiedRequirementsExpanded(reqList,ontology); |
| 423 |
foreach (COntologyProcessingRequirement* ontReq, reqList) { |
| 424 |
ontReqList.append(COntologyRequirementPair(ontology,ontReq)); |
| 425 |
} |
| 426 |
} |
| 427 |
CComplexAnsweringQuery* complexAnsweringQuery = dynamic_cast<CComplexAnsweringQuery*>(query); |
| 428 |
if (complexAnsweringQuery) { |
| 429 |
CConcreteOntology* ontology = complexAnsweringQuery->getBaseOntology(); |
| 430 |
QList<COntologyProcessingRequirement*> reqList; |
| 431 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSANSWERCOMPLEXQUERY)); |
| 432 |
|
| 433 |
CComplexConceptAnsweringQuery* complexConceptAnsweringQuery = dynamic_cast<CComplexConceptAnsweringQuery*>(complexAnsweringQuery); |
| 434 |
if (complexConceptAnsweringQuery) { |
| 435 |
if (complexConceptAnsweringQuery->isSuperClassNodesComputationRequired() || complexConceptAnsweringQuery->isSubClassNodesComputationRequired() || complexConceptAnsweringQuery->isEquivalentClassNodesComputationRequired() || complexConceptAnsweringQuery->isInstancesComputationRequired()) { |
| 436 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSCLASSCLASSIFY)); |
| 437 |
} |
| 438 |
if (complexConceptAnsweringQuery->isInstancesComputationRequired()) { |
| 439 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSOBJECTROPERTYCLASSIFY)); |
| 440 |
//reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSSAMEINDIVIDUALSREALIZE)); |
| 441 |
} |
| 442 |
} |
| 443 |
CComplexVariablesAnsweringQuery* compVarAnsweringQuery = dynamic_cast<CComplexVariablesAnsweringQuery*>(complexAnsweringQuery); |
| 444 |
if (compVarAnsweringQuery) { |
| 445 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSOBJECTROPERTYCLASSIFY)); |
| 446 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSCLASSCLASSIFY)); |
| 447 |
} |
| 448 |
CComplexAxiomsDataPropertyVariablesAnsweringQuery* compDataPropVarAnsweringQuery = dynamic_cast<CComplexAxiomsDataPropertyVariablesAnsweringQuery*>(complexAnsweringQuery); |
| 449 |
if (compDataPropVarAnsweringQuery) { |
| 450 |
reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSDATAROPERTYCLASSIFY)); |
| 451 |
} |
| 452 |
|
| 453 |
//reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSCLASSCLASSIFY)); |
| 454 |
//reqList.append(mRequirementExpander->getCompletedDefaultOntologyProcessingStepRequirement(COntologyProcessingStep::OPSOBJECTROPERTYCLASSIFY)); |
| 455 |
reqList = mRequirementExpander->getUnsatisfiedRequirementsExpanded(reqList, ontology); |
| 456 |
foreach(COntologyProcessingRequirement* ontReq, reqList) { |
| 457 |
ontReqList.append(COntologyRequirementPair(ontology, ontReq)); |
| 458 |
} |
| 459 |
} |
| 460 |
return ontReqList; |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
void CReasonerManagerThread::continueRequirementProcessing(CRequirementPreparingData* reqData, CConcreteOntology* ontology) { |
| 466 |
COntologyRequirementPreparingData* ontReqPrepData = reqData->getOntologyRequirementPreparingData(ontology); |
| 467 |
if (!ontReqPrepData->mCheckingReqList.isEmpty()) { |
| 468 |
|
| 469 |
cint64 checkingTime = ontReqPrepData->mCheckingTimer.elapsed(); |
| 470 |
if (ontReqPrepData->mCheckingProcessorType == COntologyProcessingStep::OPPREPROCESSOR) { |
| 471 |
if (!mProcessingEndMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPPREPROCESSOR))) { |
| 472 |
mProcessingEndMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPPREPROCESSOR)); |
| 473 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Finished preprocessing in %2 ms for ontology '%1'.").arg(ontology->getOntologyName()).arg(checkingTime),this); |
| 474 |
} |
| 475 |
} else if (ontReqPrepData->mCheckingProcessorType == COntologyProcessingStep::OPPRECOMPUTER) { |
| 476 |
if (!mProcessingEndMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPPRECOMPUTER))) { |
| 477 |
mProcessingEndMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPPRECOMPUTER)); |
| 478 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Finished precomputing in %2 ms for ontology '%1'.").arg(ontology->getOntologyName()).arg(checkingTime),this); |
| 479 |
} |
| 480 |
} else if (ontReqPrepData->mCheckingProcessorType == COntologyProcessingStep::OPCLASSCLASSIFIER) { |
| 481 |
if (!mProcessingEndMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPCLASSCLASSIFIER))) { |
| 482 |
mProcessingEndMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPCLASSCLASSIFIER)); |
| 483 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Finished class classification in %2 ms for ontology '%1'.").arg(ontology->getOntologyName()).arg(checkingTime),this); |
| 484 |
} |
| 485 |
} else if (ontReqPrepData->mCheckingProcessorType == COntologyProcessingStep::OPOBJECTPROPERTYCLASSIFIER) { |
| 486 |
if (!mProcessingEndMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPOBJECTPROPERTYCLASSIFIER))) { |
| 487 |
mProcessingEndMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPOBJECTPROPERTYCLASSIFIER)); |
| 488 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Finished object property classification in %2 ms for ontology '%1'.").arg(ontology->getOntologyName()).arg(checkingTime),this); |
| 489 |
} |
| 490 |
} else if (ontReqPrepData->mCheckingProcessorType == COntologyProcessingStep::OPDATAPROPERTYCLASSIFIER) { |
| 491 |
if (!mProcessingEndMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPDATAPROPERTYCLASSIFIER))) { |
| 492 |
mProcessingEndMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPDATAPROPERTYCLASSIFIER)); |
| 493 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Finished data property classification in %2 ms for ontology '%1'.").arg(ontology->getOntologyName()).arg(checkingTime),this); |
| 494 |
} |
| 495 |
} else if (ontReqPrepData->mCheckingProcessorType == COntologyProcessingStep::OPREALIZER) { |
| 496 |
if (!mProcessingEndMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPREALIZER))) { |
| 497 |
mProcessingEndMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPREALIZER)); |
| 498 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Finished (lazy) realization in %2 ms for ontology '%1'.").arg(ontology->getOntologyName()).arg(checkingTime),this); |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
for (QList<COntologyProcessingRequirement*>::const_iterator it = ontReqPrepData->mCheckingReqList.constBegin(), itEnd = ontReqPrepData->mCheckingReqList.constEnd(); it != itEnd; ++it) { |
| 504 |
COntologyProcessingRequirement* ontProReq(*it); |
| 505 |
if (!ontProReq->isRequirementSatisfied(ontology)) { |
| 506 |
ontReqPrepData->mFailedReqList.append(ontProReq); |
| 507 |
} else { |
| 508 |
reqData->mSatisfiedReqList.append(COntologyRequirementPair(ontology,ontProReq)); |
| 509 |
} |
| 510 |
} |
| 511 |
ontReqPrepData->mCheckingReqList.clear(); |
| 512 |
} |
| 513 |
if (!ontReqPrepData->mFailedReqList.isEmpty()) { |
| 514 |
for (QList<COntologyProcessingRequirement*>::const_iterator it = ontReqPrepData->mFailedReqList.constBegin(), itEnd = ontReqPrepData->mFailedReqList.constEnd(); it != itEnd; ++it) { |
| 515 |
COntologyProcessingRequirement* failedReqData(*it); |
| 516 |
const QString& failureString = failedReqData->getRequirementFailureString(ontology); |
| 517 |
if (!failureString.isEmpty()) { |
| 518 |
LOG(ERROR,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("%1").arg(failureString),this); |
| 519 |
} |
| 520 |
reqData->mFailedReqList.append(COntologyRequirementPair(ontology,failedReqData)); |
| 521 |
} |
| 522 |
ontReqPrepData->mFailedReqList.clear(); |
| 523 |
ontReqPrepData->mRequirementsProcessed = true; |
| 524 |
reqData->mDepCount--; |
| 525 |
reqData->mRequirementFailed = true; |
| 526 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Requirements for ontology '%1' not satisfied.").arg(ontology->getOntologyName()),this); |
| 527 |
} |
| 528 |
|
| 529 |
if (!reqData->mRequirementFailed) { |
| 530 |
if (!ontReqPrepData->mPreprocessorReqList.isEmpty()) { |
| 531 |
if (!mProcessingStartMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPPREPROCESSOR))) { |
| 532 |
mProcessingStartMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPPREPROCESSOR)); |
| 533 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Preprocessing ontology '%1'.").arg(ontology->getOntologyName()),this); |
| 534 |
} |
| 535 |
CConfigurationBase* config = ontology->getConfiguration(); |
| 536 |
CPreprocessor* preprocessor = mPreprocessingManager->getPreprocessor(ontology,config); |
| 537 |
CRequirementProcessedCallbackEvent* reqProcCallbackEvent = new CRequirementProcessedCallbackEvent(this,ontology,reqData, COntologyProcessingStep::OPPREPROCESSOR); |
| 538 |
preprocessor->preprocess(ontology,config,ontReqPrepData->mPreprocessorReqList,reqProcCallbackEvent); |
| 539 |
ontReqPrepData->mCheckingReqList = ontReqPrepData->mPreprocessorReqList; |
| 540 |
ontReqPrepData->mPreprocessorReqList.clear(); |
| 541 |
ontReqPrepData->mCheckingProcessorType = COntologyProcessingStep::OPPREPROCESSOR; |
| 542 |
ontReqPrepData->mCheckingTimer.start(); |
| 543 |
} else if (!ontReqPrepData->mPrecomputorReqList.isEmpty()) { |
| 544 |
QString exprString = QString(", expressiveness '%2'").arg(ontology->getStructureSummary()->getExpressivenessString()); |
| 545 |
if (!mProcessingStartMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPPRECOMPUTER))) { |
| 546 |
mProcessingStartMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPPRECOMPUTER)); |
| 547 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Precomputing ontology '%1'%2.").arg(ontology->getOntologyName()).arg(exprString),this); |
| 548 |
} |
| 549 |
CConfigurationBase* config = ontology->getConfiguration(); |
| 550 |
CPrecomputator* precomputer = mPrecomputationManager->getPrecomputator(ontology,config); |
| 551 |
CRequirementProcessedCallbackEvent* reqProcCallbackEvent = new CRequirementProcessedCallbackEvent(this,ontology,reqData, COntologyProcessingStep::OPPRECOMPUTER); |
| 552 |
precomputer->precompute(ontology,config,ontReqPrepData->mPrecomputorReqList,reqProcCallbackEvent); |
| 553 |
ontReqPrepData->mCheckingReqList = ontReqPrepData->mPrecomputorReqList; |
| 554 |
ontReqPrepData->mCheckingProcessorType = COntologyProcessingStep::OPPRECOMPUTER; |
| 555 |
ontReqPrepData->mCheckingTimer.start(); |
| 556 |
ontReqPrepData->mPrecomputorReqList.clear(); |
| 557 |
} else if (!ontReqPrepData->mClassClassifierReqList.isEmpty()) { |
| 558 |
QString exprString = QString(", expressiveness '%2'").arg(ontology->getStructureSummary()->getExpressivenessString()); |
| 559 |
if (!mProcessingStartMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPCLASSCLASSIFIER))) { |
| 560 |
mProcessingStartMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPCLASSCLASSIFIER)); |
| 561 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Classifying ontology '%1'%2.").arg(ontology->getOntologyName()).arg(exprString),this); |
| 562 |
} |
| 563 |
CConfigurationBase* config = ontology->getConfiguration(); |
| 564 |
CSubsumptionClassifier* classClassifier = classificationMan->getClassClassifier(ontology,config); |
| 565 |
CRequirementProcessedCallbackEvent* reqProcCallbackEvent = new CRequirementProcessedCallbackEvent(this,ontology,reqData, COntologyProcessingStep::OPCLASSCLASSIFIER); |
| 566 |
classClassifier->classify(ontology,config,ontReqPrepData->mClassClassifierReqList,reqProcCallbackEvent); |
| 567 |
ontReqPrepData->mCheckingReqList = ontReqPrepData->mClassClassifierReqList; |
| 568 |
ontReqPrepData->mCheckingProcessorType = COntologyProcessingStep::OPCLASSCLASSIFIER; |
| 569 |
ontReqPrepData->mCheckingTimer.start(); |
| 570 |
ontReqPrepData->mClassClassifierReqList.clear(); |
| 571 |
} else if (!ontReqPrepData->mObjectPropertyClassifierReqList.isEmpty()) { |
| 572 |
QString exprString = QString(", expressiveness '%2'").arg(ontology->getStructureSummary()->getExpressivenessString()); |
| 573 |
if (!mProcessingStartMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPOBJECTPROPERTYCLASSIFIER))) { |
| 574 |
mProcessingStartMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPOBJECTPROPERTYCLASSIFIER)); |
| 575 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Classifying object properties for ontology '%1'%2.").arg(ontology->getOntologyName()).arg(exprString),this); |
| 576 |
} |
| 577 |
CConfigurationBase* config = ontology->getConfiguration(); |
| 578 |
CSubsumptionClassifier* objectPropertyClassifier = classificationMan->getObjectPropertyClassifier(ontology,config); |
| 579 |
CRequirementProcessedCallbackEvent* reqProcCallbackEvent = new CRequirementProcessedCallbackEvent(this,ontology,reqData, COntologyProcessingStep::OPOBJECTPROPERTYCLASSIFIER); |
| 580 |
objectPropertyClassifier->classify(ontology,config,ontReqPrepData->mObjectPropertyClassifierReqList,reqProcCallbackEvent); |
| 581 |
ontReqPrepData->mCheckingReqList = ontReqPrepData->mObjectPropertyClassifierReqList; |
| 582 |
ontReqPrepData->mCheckingProcessorType = COntologyProcessingStep::OPOBJECTPROPERTYCLASSIFIER; |
| 583 |
ontReqPrepData->mCheckingTimer.start(); |
| 584 |
ontReqPrepData->mObjectPropertyClassifierReqList.clear(); |
| 585 |
} else if (!ontReqPrepData->mDataPropertyClassifierReqList.isEmpty()) { |
| 586 |
QString exprString = QString(", expressiveness '%2'").arg(ontology->getStructureSummary()->getExpressivenessString()); |
| 587 |
if (!mProcessingStartMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPDATAPROPERTYCLASSIFIER))) { |
| 588 |
mProcessingStartMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPDATAPROPERTYCLASSIFIER)); |
| 589 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Classifying data properties for ontology '%1'%2.").arg(ontology->getOntologyName()).arg(exprString),this); |
| 590 |
} |
| 591 |
CConfigurationBase* config = ontology->getConfiguration(); |
| 592 |
CSubsumptionClassifier* dataPropertyClassifier = classificationMan->getDataPropertyClassifier(ontology,config); |
| 593 |
CRequirementProcessedCallbackEvent* reqProcCallbackEvent = new CRequirementProcessedCallbackEvent(this,ontology,reqData, COntologyProcessingStep::OPDATAPROPERTYCLASSIFIER); |
| 594 |
dataPropertyClassifier->classify(ontology,config,ontReqPrepData->mDataPropertyClassifierReqList,reqProcCallbackEvent); |
| 595 |
ontReqPrepData->mCheckingReqList = ontReqPrepData->mDataPropertyClassifierReqList; |
| 596 |
ontReqPrepData->mCheckingProcessorType = COntologyProcessingStep::OPDATAPROPERTYCLASSIFIER; |
| 597 |
ontReqPrepData->mCheckingTimer.start(); |
| 598 |
ontReqPrepData->mDataPropertyClassifierReqList.clear(); |
| 599 |
} else if (!ontReqPrepData->mRealizerReqList.isEmpty()) { |
| 600 |
QString exprString = QString(", expressiveness '%2'").arg(ontology->getStructureSummary()->getExpressivenessString()); |
| 601 |
if (!mProcessingStartMessageSet.contains(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPREALIZER))) { |
| 602 |
mProcessingStartMessageSet.insert(QPair<CConcreteOntology*,COntologyProcessingStep::PROCESSORTYPE>(ontology,COntologyProcessingStep::OPREALIZER)); |
| 603 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Realizing ontology '%1'%2.").arg(ontology->getOntologyName()).arg(exprString),this); |
| 604 |
} |
| 605 |
CConfigurationBase* config = ontology->getConfiguration(); |
| 606 |
CRealizer* realizer = mRealizationManager->getRealizer(ontology,config); |
| 607 |
CRequirementProcessedCallbackEvent* reqProcCallbackEvent = new CRequirementProcessedCallbackEvent(this,ontology,reqData, COntologyProcessingStep::OPREALIZER); |
| 608 |
realizer->realize(ontology,config,ontReqPrepData->mRealizerReqList,reqProcCallbackEvent); |
| 609 |
ontReqPrepData->mCheckingReqList = ontReqPrepData->mRealizerReqList; |
| 610 |
ontReqPrepData->mCheckingProcessorType = COntologyProcessingStep::OPREALIZER; |
| 611 |
ontReqPrepData->mCheckingTimer.start(); |
| 612 |
ontReqPrepData->mRealizerReqList.clear(); |
| 613 |
} else if (!ontReqPrepData->mAnswererReqList.isEmpty()) { |
| 614 |
QString exprString = QString(", expressiveness '%2'").arg(ontology->getStructureSummary()->getExpressivenessString()); |
| 615 |
if (!mProcessingStartMessageSet.contains(QPair<CConcreteOntology*, COntologyProcessingStep::PROCESSORTYPE>(ontology, COntologyProcessingStep::OPANSWERER))) { |
| 616 |
mProcessingStartMessageSet.insert(QPair<CConcreteOntology*, COntologyProcessingStep::PROCESSORTYPE>(ontology, COntologyProcessingStep::OPANSWERER)); |
| 617 |
LOG(INFO, "::Konclude::Reasoner::Kernel::ReasonerManager", logTr("Initializing complex query answering for ontology '%1'%2.").arg(ontology->getOntologyName()).arg(exprString), this); |
| 618 |
} |
| 619 |
CConfigurationBase* config = ontology->getConfiguration(); |
| 620 |
bool created = false; |
| 621 |
if (!mAnswererManager) { |
| 622 |
mAnswererManager = new CAnsweringManagerThread(this, config); |
| 623 |
created = true; |
| 624 |
} |
| 625 |
CRequirementProcessedCallbackEvent* reqProcCallbackEvent = new CRequirementProcessedCallbackEvent(this, ontology, reqData, COntologyProcessingStep::OPANSWERER); |
| 626 |
ontology->getProcessingSteps()->getOntologyProcessingStepDataVector()->getProcessingStepData(COntologyProcessingStep::OPSANSWERCOMPLEXQUERY)->getProcessingStatus()->setProcessingFlags(COntologyProcessingStatus::PSCOMPLETELYYPROCESSED); |
| 627 |
ontology->getProcessingSteps()->getOntologyProcessingStepDataVector()->getProcessingStepData(COntologyProcessingStep::OPSANSWERCOMPLEXQUERY)->getProcessingStatus()->setErrorFlags(COntologyProcessingStatus::PSSUCESSFULL); |
| 628 |
ontReqPrepData->mCheckingReqList = ontReqPrepData->mAnswererReqList; |
| 629 |
ontReqPrepData->mCheckingProcessorType = COntologyProcessingStep::OPANSWERER; |
| 630 |
ontReqPrepData->mCheckingTimer.start(); |
| 631 |
ontReqPrepData->mAnswererReqList.clear(); |
| 632 |
if (created) { |
| 633 |
mAnswererManager->prepareAnswering(ontology, reqProcCallbackEvent); |
| 634 |
} else if (!mAnswererPrepared) { |
| 635 |
mAnswererPreparedCallbackQueue.append(reqProcCallbackEvent); |
| 636 |
} else { |
| 637 |
reqProcCallbackEvent->doCallback(); |
| 638 |
} |
| 639 |
} else { |
| 640 |
reqData->mDepCount--; |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
if (reqData->mDepCount <= 0) { |
| 645 |
if (reqData->mQuery) { |
| 646 |
initiateQueryReasoning(reqData->mQuery,reqData->mCallback,reqData->mReasoningData,reqData->mFailedReqList); |
| 647 |
} else { |
| 648 |
CCallbackData* callback = reqData->mCallback; |
| 649 |
if (callback) { |
| 650 |
callback->doCallback(); |
| 651 |
} |
| 652 |
delete reqData; |
| 653 |
} |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
void CReasonerManagerThread::prepareOntologyReasoning(CPrepareOntologyEvent* poe) { |
| 659 |
CConcreteOntology* ontology = poe->getOntology(); |
| 660 |
CCallbackData* callbackData = poe->getCallbackData(); |
| 661 |
if (ontology) { |
| 662 |
QList<COntologyProcessingRequirement*> reqList(*poe->getOntologyProcessingRequirementList()); |
| 663 |
reqList = mRequirementExpander->getUnsatisfiedRequirementsExpanded(reqList,ontology); |
| 664 |
if (!reqList.isEmpty()) { |
| 665 |
// satisfy query requirements first |
| 666 |
CRequirementPreparingData* reqPrepData = new CRequirementPreparingData(callbackData,nullptr,nullptr); |
| 667 |
for (QList<COntologyProcessingRequirement*>::const_iterator it = reqList.constBegin(), itEnd = reqList.constEnd(); it != itEnd; ++it) { |
| 668 |
COntologyProcessingRequirement* requirement = *it; |
| 669 |
COntologyRequirementPreparingData* ontReqPrepData = reqPrepData->getOntologyRequirementPreparingData(ontology); |
| 670 |
ontReqPrepData->addOntologyRequirement(requirement); |
| 671 |
} |
| 672 |
reqPrepData->mDepCount = reqPrepData->mOntoReqDataHash.count(); |
| 673 |
mProcessingRequirementsSet.insert(reqPrepData); |
| 674 |
|
| 675 |
continueRequirementProcessing(reqPrepData,ontology); |
| 676 |
} else { |
| 677 |
if (callbackData) { |
| 678 |
callbackData->doCallback(); |
| 679 |
} |
| 680 |
} |
| 681 |
} else { |
| 682 |
LOG(ERROR,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Ontology not specified for processing requirements."),this); |
| 683 |
if (callbackData) { |
| 684 |
callbackData->doCallback(); |
| 685 |
} |
| 686 |
} |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
void CReasonerManagerThread::prepareQueryReasoning(CCalcQueryEvent *cqe) { |
| 691 |
CQuery* query = cqe->getQuery(); |
| 692 |
CCallbackData* callbackData = cqe->getCallbackData(); |
| 693 |
|
| 694 |
CReasoningTaskData* reasoningData = new CReasoningTaskData(); |
| 695 |
|
| 696 |
QList<COntologyRequirementPair> reqList(getRequirementsForQuery(query)); |
| 697 |
if (reqList.isEmpty()) { |
| 698 |
initiateQueryReasoning(query,callbackData,reasoningData,QList<COntologyRequirementPair>()); |
| 699 |
} else { |
| 700 |
// satisfy query requirements first |
| 701 |
CRequirementPreparingData* reqPrepData = new CRequirementPreparingData(callbackData,query,reasoningData); |
| 702 |
reasoningData->mReqPrepData = reqPrepData; |
| 703 |
for (QList<COntologyRequirementPair>::const_iterator it = reqList.constBegin(), itEnd = reqList.constEnd(); it != itEnd; ++it) { |
| 704 |
COntologyRequirementPair ontReqPair(*it); |
| 705 |
CConcreteOntology* ontology = ontReqPair.mOntology; |
| 706 |
COntologyProcessingRequirement* requirement = ontReqPair.mRequirement; |
| 707 |
COntologyRequirementPreparingData* ontReqPrepData = reqPrepData->getOntologyRequirementPreparingData(ontology); |
| 708 |
ontReqPrepData->addOntologyRequirement(requirement); |
| 709 |
} |
| 710 |
reqPrepData->mDepCount = reqPrepData->mOntoReqDataHash.count(); |
| 711 |
mProcessingRequirementsSet.insert(reqPrepData); |
| 712 |
|
| 713 |
if (reqPrepData->mDepCount <= 0) { |
| 714 |
initiateQueryReasoning(query,callbackData,reasoningData,reqPrepData->mFailedReqList); |
| 715 |
} else { |
| 716 |
for (QHash<CConcreteOntology*,COntologyRequirementPreparingData*>::const_iterator it = reqPrepData->mOntoReqDataHash.constBegin(), itEnd = reqPrepData->mOntoReqDataHash.constEnd(); it != itEnd; ++it) { |
| 717 |
CConcreteOntology* ontology = it.key(); |
| 718 |
COntologyRequirementPreparingData* ontReqRepData = it.value(); |
| 719 |
continueRequirementProcessing(reqPrepData,ontology); |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
} |
| 724 |
|
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
void CReasonerManagerThread::initiateQueryReasoning(CQuery* query, CCallbackData* callbackData, CReasoningTaskData* reasoningData, const QList<COntologyRequirementPair>& failedRequirementList) { |
| 729 |
reasoningData->mStartTime.start(); |
| 730 |
updateBeginingCalculationStatistics(reasoningData); |
| 731 |
|
| 732 |
if (!failedRequirementList.isEmpty()) { |
| 733 |
CConcreteOntology* ontology = nullptr; |
| 734 |
for (QList<COntologyRequirementPair>::const_iterator it = failedRequirementList.constBegin(), itEnd = failedRequirementList.constEnd(); it != itEnd; ++it) { |
| 735 |
ontology = it->mOntology; |
| 736 |
COntologyProcessingRequirement* requirement(it->mRequirement); |
| 737 |
query->addErrorString(QString("Processing requirements for Ontology '%1' for Query '%2' failed.").arg(ontology->getOntologyName()).arg(query->getQueryName())); |
| 738 |
|
| 739 |
if (ontology) { |
| 740 |
CConsistence* cons = ontology->getConsistence(); |
| 741 |
if (cons) { |
| 742 |
if (!cons->isOntologyConsistent()) { |
| 743 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Ontology '%1' for Query '%2' is inconsistent.").arg(ontology->getOntologyName()).arg(query->getQueryName()),this); |
| 744 |
|
| 745 |
query->addQueryError(new CQueryInconsitentOntologyError(ontology)); |
| 746 |
} |
| 747 |
} |
| 748 |
} |
| 749 |
} |
| 750 |
if (ontology) { |
| 751 |
updateFinishingCalculationStatistics(reasoningData,query->getQueryStatistics(),ontology->getConfiguration()); |
| 752 |
} else { |
| 753 |
updateFinishingCalculationStatistics(reasoningData,query->getQueryStatistics()); |
| 754 |
} |
| 755 |
|
| 756 |
CCallbackData* callback = callbackData; |
| 757 |
if (callback) { |
| 758 |
callback->doCallback(); |
| 759 |
} |
| 760 |
delete reasoningData; |
| 761 |
|
| 762 |
} else { |
| 763 |
|
| 764 |
|
| 765 |
CSatisfiableCalculationJobsQuery* jobQuery = dynamic_cast<CSatisfiableCalculationJobsQuery*>(query); |
| 766 |
if (jobQuery) { |
| 767 |
|
| 768 |
|
| 769 |
CQUERYLIST<CCalculationJob*> jobList(jobQuery->getJobList()); |
| 770 |
bool jobCalculated = false; |
| 771 |
cint64 depCount = 0; |
| 772 |
CConcreteOntology* ontology = nullptr; |
| 773 |
FOREACHIT (CCalculationJob* calcJob, jobList) { |
| 774 |
CSatisfiableCalculationJob* satCalcJob = dynamic_cast<CSatisfiableCalculationJob*>(calcJob); |
| 775 |
if (satCalcJob) { |
| 776 |
depCount++; |
| 777 |
CJobSatisfiableCallbackContextData* satCallbackData = new CJobSatisfiableCallbackContextData(satCalcJob); |
| 778 |
CQueryJobCalculatedSatisfiableCallbackEvent* callback = new CQueryJobCalculatedSatisfiableCallbackEvent(this,jobQuery,satCallbackData); |
| 779 |
mCalculationManager->calculateJob(satCalcJob,callback); |
| 780 |
mCalcJobSet.insert(satCalcJob); |
| 781 |
jobCalculated = true; |
| 782 |
|
| 783 |
ontology = satCalcJob->getOntology(); |
| 784 |
} |
| 785 |
} |
| 786 |
|
| 787 |
reasoningData->mCallback = callbackData; |
| 788 |
reasoningData->mDepCount = depCount; |
| 789 |
mReasoningTaskDataHash.insert((cint64)query,reasoningData); |
| 790 |
mCalculatingQuerySet.insert(query); |
| 791 |
|
| 792 |
reasoningData->mFinQueryCallback = new CCalcedQueryEvent(this,jobQuery); |
| 793 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Processing Query '%1'.").arg(query->getQueryName()),this); |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
CIsTriviallyConsistentQuery* trivConsQuery = dynamic_cast<CIsTriviallyConsistentQuery *>(query); |
| 802 |
if (trivConsQuery) { |
| 803 |
reasoningData->mCallback = callbackData; |
| 804 |
CConcreteOntology* ontology = trivConsQuery->getOntology(); |
| 805 |
trivConsQuery->constructResult(ontology->getBuildData()); |
| 806 |
|
| 807 |
qint64 mSecs = reasoningData->mStartTime.elapsed(); |
| 808 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Query '%1' processed in '%2' ms.").arg(trivConsQuery->getQueryName()).arg(mSecs),this); |
| 809 |
|
| 810 |
CCallbackData* callback = reasoningData->mCallback; |
| 811 |
if (callback) { |
| 812 |
callback->doCallback(); |
| 813 |
} |
| 814 |
delete reasoningData; |
| 815 |
} |
| 816 |
|
| 817 |
CConsistencePremisingQuery* consQuery = dynamic_cast<CConsistencePremisingQuery *>(query); |
| 818 |
if (consQuery) { |
| 819 |
reasoningData->mCallback = callbackData; |
| 820 |
CQueryStatistics* queryStats = consQuery->getQueryStatistics(); |
| 821 |
CConcreteOntology* ontology = consQuery->getOntology(); |
| 822 |
if (queryStats) { |
| 823 |
CConsistenceStatistics* consStats = ontology->getConsistence()->getConsistenceStatistics(); |
| 824 |
if (consStats) { |
| 825 |
foreach(QString statName, consStats->getStatisticsNameStringList()) { |
| 826 |
cint64 statValue = consStats->getStatisticIntegerValue(statName); |
| 827 |
queryStats->addProcessingStatistics(statName, statValue); |
| 828 |
} |
| 829 |
} |
| 830 |
} |
| 831 |
updateFinishingCalculationStatistics(reasoningData,queryStats,ontology->getConfiguration()); |
| 832 |
|
| 833 |
consQuery->constructResult(ontology->getConsistence()); |
| 834 |
|
| 835 |
qint64 mSecs = reasoningData->mStartTime.elapsed(); |
| 836 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Query '%1' processed in '%2' ms.").arg(consQuery->getQueryName()).arg(mSecs),this); |
| 837 |
|
| 838 |
CCallbackData* callback = reasoningData->mCallback; |
| 839 |
if (callback) { |
| 840 |
callback->doCallback(); |
| 841 |
} |
| 842 |
delete reasoningData; |
| 843 |
} |
| 844 |
|
| 845 |
|
| 846 |
CTaxonomyPremisingQuery *taxQuery = dynamic_cast<CTaxonomyPremisingQuery *>(query); |
| 847 |
if (taxQuery) { |
| 848 |
reasoningData->mCallback = callbackData; |
| 849 |
|
| 850 |
CQueryStatistics* queryStats = taxQuery->getQueryStatistics(); |
| 851 |
CConcreteOntology* ontology = taxQuery->getOntology(); |
| 852 |
if (queryStats) { |
| 853 |
CClassConceptClassification* classConClassif = ontology->getClassification()->getClassConceptClassification(); |
| 854 |
if (classConClassif) { |
| 855 |
CClassificationStatistics* classifStats = classConClassif->getClassificationStatistics(); |
| 856 |
if (classifStats) { |
| 857 |
foreach(QString statName, classifStats->getStatisticsNameStringList()) { |
| 858 |
cint64 statValue = classifStats->getStatisticIntegerValue(statName); |
| 859 |
queryStats->addProcessingStatistics(statName, statValue); |
| 860 |
} |
| 861 |
} |
| 862 |
} |
| 863 |
} |
| 864 |
updateFinishingCalculationStatistics(reasoningData,queryStats,ontology->getConfiguration()); |
| 865 |
|
| 866 |
taxQuery->constructResult(ontology->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()); |
| 867 |
|
| 868 |
qint64 mSecs = reasoningData->mStartTime.elapsed(); |
| 869 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Query '%1' processed in '%2' ms.").arg(taxQuery->getQueryName()).arg(mSecs),this); |
| 870 |
|
| 871 |
|
| 872 |
CCallbackData* callback = reasoningData->mCallback; |
| 873 |
if (callback) { |
| 874 |
callback->doCallback(); |
| 875 |
} |
| 876 |
delete reasoningData; |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
CClassificationPremisingQuery* classQuery = dynamic_cast<CClassificationPremisingQuery*>(query); |
| 881 |
if (classQuery) { |
| 882 |
reasoningData->mCallback = callbackData; |
| 883 |
|
| 884 |
CQueryStatistics* queryStats = classQuery->getQueryStatistics(); |
| 885 |
CConcreteOntology* ontology = classQuery->getOntology(); |
| 886 |
|
| 887 |
updateFinishingCalculationStatistics(reasoningData,queryStats,ontology->getConfiguration()); |
| 888 |
|
| 889 |
classQuery->constructResult(ontology->getClassification()); |
| 890 |
|
| 891 |
qint64 mSecs = reasoningData->mStartTime.elapsed(); |
| 892 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Query '%1' processed in '%2' ms.").arg(classQuery->getQueryName()).arg(mSecs),this); |
| 893 |
|
| 894 |
CCallbackData* callback = reasoningData->mCallback; |
| 895 |
if (callback) { |
| 896 |
callback->doCallback(); |
| 897 |
} |
| 898 |
delete reasoningData; |
| 899 |
} |
| 900 |
|
| 901 |
|
| 902 |
CRealizationPremisingQuery* realQuery = dynamic_cast<CRealizationPremisingQuery *>(query); |
| 903 |
if (realQuery) { |
| 904 |
reasoningData->mCallback = callbackData; |
| 905 |
|
| 906 |
CQueryStatistics* queryStats = realQuery->getQueryStatistics(); |
| 907 |
CConcreteOntology* ontology = realQuery->getOntology(); |
| 908 |
|
| 909 |
updateFinishingCalculationStatistics(reasoningData,queryStats,ontology->getConfiguration()); |
| 910 |
|
| 911 |
realQuery->constructResult(ontology->getRealization()); |
| 912 |
|
| 913 |
qint64 mSecs = reasoningData->mStartTime.elapsed(); |
| 914 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Query '%1' processed in '%2' ms.").arg(realQuery->getQueryName()).arg(mSecs),this); |
| 915 |
|
| 916 |
|
| 917 |
CCallbackData* callback = reasoningData->mCallback; |
| 918 |
if (callback) { |
| 919 |
callback->doCallback(); |
| 920 |
} |
| 921 |
delete reasoningData; |
| 922 |
} |
| 923 |
|
| 924 |
|
| 925 |
CComplexAnsweringQuery* compAnsQuery = dynamic_cast<CComplexAnsweringQuery *>(query); |
| 926 |
if (compAnsQuery) { |
| 927 |
reasoningData->mCallback = callbackData; |
| 928 |
|
| 929 |
CConcreteOntology* ontology = compAnsQuery->getBaseOntology(); |
| 930 |
|
| 931 |
CCallbackData* callback = reasoningData->mCallback; |
| 932 |
|
| 933 |
bool confCollectProcessStatistics = CConfigDataReader::readConfigBoolean(ontology->getConfiguration(), "Konclude.Calculation.Answering.CollectProcessStatistics", false); |
| 934 |
if (confCollectProcessStatistics) { |
| 935 |
reasoningData->mFinQueryCallback = new CCalcedQueryEvent(this, compAnsQuery); |
| 936 |
mReasoningTaskDataHash.insert((cint64)query, reasoningData); |
| 937 |
callback = reasoningData->mFinQueryCallback; |
| 938 |
} |
| 939 |
|
| 940 |
mAnswererManager->answerComplexQuery(compAnsQuery, callback); |
| 941 |
if (!confCollectProcessStatistics) { |
| 942 |
delete reasoningData; |
| 943 |
} |
| 944 |
} |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
void CReasonerManagerThread::prepareSatisfiableBoxReasoning(CReasoningSatisfiableCalculationJobEvent *cbse) { |
| 952 |
|
| 953 |
CSatisfiableCalculationJob* calcJob = cbse->getSatisfiableCalculationJob(); |
| 954 |
CCallbackData* callbackData = cbse->getCallbackData(); |
| 955 |
|
| 956 |
|
| 957 |
CJobSatisfiableCallbackContextData* satCallbackData = (CJobSatisfiableCallbackContextData*)callbackData->getCallbackDataContext(); |
| 958 |
if (!satCallbackData) { |
| 959 |
satCallbackData = new CJobSatisfiableCallbackContextData(calcJob); |
| 960 |
} |
| 961 |
CJobCalculatedSatisfiableCallbackEvent* callback = new CJobCalculatedSatisfiableCallbackEvent(this,satCallbackData); |
| 962 |
mCalculationManager->calculateJob(calcJob,callback); |
| 963 |
mCalcJobSet.insert(calcJob); |
| 964 |
|
| 965 |
CReasoningTaskData* reasoningData = new CReasoningTaskData(); |
| 966 |
reasoningData->mCallback = callbackData; |
| 967 |
mReasoningTaskDataHash.insert((cint64)calcJob,reasoningData); |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
bool CReasonerManagerThread::updateBeginingCalculationStatistics(CReasoningTaskData* reaTaskData, CConfiguration* config) { |
| 973 |
if (!config) { |
| 974 |
config = configProvider->getCurrentConfiguration(); |
| 975 |
} |
| 976 |
if (CConfigDataReader::readConfigBoolean(config,"Konclude.Query.Statistics.CollectCalculationStatistics",false)) { |
| 977 |
QHash<QString,cint64>* mBeginStatHash = mCalculationManager->getCalculationStatistics(); |
| 978 |
reaTaskData->mCalcStat = mBeginStatHash; |
| 979 |
return true; |
| 980 |
} |
| 981 |
return false; |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
bool CReasonerManagerThread::updateFinishingCalculationStatistics(CReasoningTaskData* reaTaskData, CQueryStatistics* queryStat, CConfiguration* config) { |
| 987 |
if (queryStat) { |
| 988 |
if (!config) { |
| 989 |
config = configProvider->getCurrentConfiguration(); |
| 990 |
} |
| 991 |
if (CConfigDataReader::readConfigBoolean(config,"Konclude.Query.Statistics.CollectCalculationStatistics",false)) { |
| 992 |
QHash<QString,cint64>* mBeginStatHash = reaTaskData->mCalcStat; |
| 993 |
if (mBeginStatHash) { |
| 994 |
QHash<QString,cint64>* mFinishStatHash = mCalculationManager->getCalculationStatistics(); |
| 995 |
for (QHash<QString,cint64>::const_iterator itF = mFinishStatHash->constBegin(), itFEnd = mFinishStatHash->constEnd(); itF != itFEnd; ++itF) { |
| 996 |
QString statName = itF.key(); |
| 997 |
cint64 finVal = itF.value(); |
| 998 |
cint64 begVal = 0;//mBeginStatHash->value(statName); |
| 999 |
queryStat->addProcessingStatistics(statName,finVal-begVal); |
| 1000 |
} |
| 1001 |
delete mFinishStatHash; |
| 1002 |
} |
| 1003 |
queryStat->addProcessingStatistics("calculation-reasoning-time",reaTaskData->mStartTime.elapsed()); |
| 1004 |
} |
| 1005 |
if (CConfigDataReader::readConfigBoolean(config,"Konclude.Query.Statistics.CollectProcessingStepsStatistics",false) && reaTaskData->mReqPrepData) { |
| 1006 |
QSet<COntologyProcessingStatistics*> addedStatSet; |
| 1007 |
for (QList<COntologyRequirementPair>::const_iterator it = reaTaskData->mReqPrepData->mSatisfiedReqList.constBegin(), itEnd = reaTaskData->mReqPrepData->mSatisfiedReqList.constEnd(); it != itEnd; ++it) { |
| 1008 |
COntologyRequirementPair ontReqPair(*it); |
| 1009 |
CConcreteOntology* ontology = ontReqPair.mOntology; |
| 1010 |
COntologyProcessingRequirement* requirement = ontReqPair.mRequirement; |
| 1011 |
COntologyProcessingStepRequirement* ontProcStepRequirement = dynamic_cast<COntologyProcessingStepRequirement*>(requirement); |
| 1012 |
if (ontProcStepRequirement) { |
| 1013 |
COntologyProcessingStepData* procStepData = ontology->getProcessingSteps()->getOntologyProcessingStepDataVector()->getProcessingStepData(ontProcStepRequirement->getRequiredProcessingStep()->getOntologyProcessingType()); |
| 1014 |
if (procStepData) { |
| 1015 |
COntologyProcessingStatistics* procStepStatistics = procStepData->getProcessingStatistics(false); |
| 1016 |
if (procStepStatistics && !addedStatSet.contains(procStepStatistics)) { |
| 1017 |
addedStatSet.insert(procStepStatistics); |
| 1018 |
queryStat->addProcessingStatistics(procStepStatistics); |
| 1019 |
} |
| 1020 |
} |
| 1021 |
} |
| 1022 |
} |
| 1023 |
} |
| 1024 |
return true; |
| 1025 |
} |
| 1026 |
return false; |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
void CReasonerManagerThread::finishSatisfiableBoxReasoning(CJobCalculatedSatisfiableCallbackEvent *cbsce) { |
| 1036 |
CJobSatisfiableCallbackContextData *contextData = (CJobSatisfiableCallbackContextData *)cbsce->getCallbackDataContext(); |
| 1037 |
|
| 1038 |
CSatisfiableCalculationJob* satCalcJob = contextData->getSatisfiableCalculationJob(); |
| 1039 |
bool satisfiable = contextData->isSatisfiable(); |
| 1040 |
bool calcError = contextData->hasCalculationError(); |
| 1041 |
|
| 1042 |
if (calcError) { |
| 1043 |
LOG(ERROR,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Error while calculating job."),this); |
| 1044 |
QString errorString = mCalculationManager->getCalculationErrorString(contextData->getCalculationErrorCode()); |
| 1045 |
if (!errorString.isEmpty()) { |
| 1046 |
LOG(ERROR,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Calculation Error: '%1'.").arg(errorString),this); |
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
| 1050 |
CReasoningTaskData* reasoningData = mReasoningTaskDataHash.value((cint64)satCalcJob,nullptr); |
| 1051 |
reasoningData->mDepCount--; |
| 1052 |
CCallbackData* callback = reasoningData->mCallback; |
| 1053 |
if (callback) { |
| 1054 |
callback->setCallbackDataContext(cbsce->takeCallbackDataContext()); |
| 1055 |
callback->doCallback(); |
| 1056 |
} |
| 1057 |
mReasoningTaskDataHash.remove((cint64)satCalcJob); |
| 1058 |
delete reasoningData; |
| 1059 |
mCalcJobSet.remove(satCalcJob); |
| 1060 |
} |
| 1061 |
|
| 1062 |
|
| 1063 |
QString CReasonerManagerThread::getLoggingCalculationStatisticsMemorySizeString(cint64 memSize) { |
| 1064 |
QString memString; |
| 1065 |
if (memSize > 10*1024*1024) { |
| 1066 |
memString = QString("%1 MByte").arg(memSize/(1024*1024)); |
| 1067 |
} else if (memSize > 10*1024) { |
| 1068 |
memString = QString("%1 KByte").arg(memSize/(1024)); |
| 1069 |
} else { |
| 1070 |
memString = QString("%1 Byte").arg(memSize); |
| 1071 |
} |
| 1072 |
return memString; |
| 1073 |
} |
| 1074 |
|
| 1075 |
QString CReasonerManagerThread::getLoggingCalculationStatisticsTimeSizeString(double milliseconds) { |
| 1076 |
QString compTimeString; |
| 1077 |
if (milliseconds > 2*1000*60*60*24*356) { |
| 1078 |
compTimeString = QString("%1 y").arg(milliseconds/(1000*60*60*24*356)); |
| 1079 |
} else if (milliseconds > 2*1000*60*60*24) { |
| 1080 |
compTimeString = QString("%1 d").arg(milliseconds/(1000*60*60*24)); |
| 1081 |
} else if (milliseconds > 10*1000*60*60) { |
| 1082 |
compTimeString = QString("%1 h").arg(milliseconds/(1000*60*60)); |
| 1083 |
} else if (milliseconds > 10*1000*60) { |
| 1084 |
compTimeString = QString("%1 m").arg(milliseconds/(1000*60)); |
| 1085 |
} else if (milliseconds > 10*1000) { |
| 1086 |
compTimeString = QString("%1 s").arg(milliseconds/(1000)); |
| 1087 |
} else { |
| 1088 |
compTimeString = QString("%1 ms").arg(milliseconds); |
| 1089 |
} |
| 1090 |
return compTimeString; |
| 1091 |
} |
| 1092 |
|
| 1093 |
void CReasonerManagerThread::loggingCalculationStatistics() { |
| 1094 |
QHash<QString,cint64>* mCalcStatHash = mCalculationManager->getCalculationStatistics(); |
| 1095 |
if (mCalcStatHash) { |
| 1096 |
QString compTime = getLoggingCalculationStatisticsTimeSizeString(mCalcStatHash->value("calculation-computing-time")); |
| 1097 |
QString memCons = getLoggingCalculationStatisticsMemorySizeString(mCalcStatHash->value("calculation-memory-consumption")); |
| 1098 |
QString memRes = getLoggingCalculationStatisticsMemorySizeString(mCalcStatHash->value("calculation-memory-reservation")); |
| 1099 |
QString statString = QString("Up to now calculation computing time: %1, calculation memory consumption: %2.") |
| 1100 |
.arg(compTime) |
| 1101 |
.arg(memCons); |
| 1102 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString,this); |
| 1103 |
delete mCalcStatHash; |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
|
| 1108 |
void CReasonerManagerThread::finishQuerySatisfiableBoxReasoning(CQueryJobCalculatedSatisfiableCallbackEvent *cbsce) { |
| 1109 |
CJobSatisfiableCallbackContextData *contextData = (CJobSatisfiableCallbackContextData *)cbsce->getCallbackDataContext(); |
| 1110 |
CSatisfiableCalculationJobsQuery* jobQuery = cbsce->getSatisfiableCalclulationJobsQuery(); |
| 1111 |
CSatisfiableCalculationJob* satCalcJob = contextData->getSatisfiableCalculationJob(); |
| 1112 |
bool satisfiable = contextData->isSatisfiable(); |
| 1113 |
bool calcError = contextData->hasCalculationError(); |
| 1114 |
|
| 1115 |
if (calcError) { |
| 1116 |
LOG(ERROR,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Error while calculating job for query '%1'.").arg(jobQuery->getQueryName()),this); |
| 1117 |
QString errorString = mCalculationManager->getCalculationErrorString(contextData->getCalculationErrorCode()); |
| 1118 |
if (!errorString.isEmpty()) { |
| 1119 |
LOG(ERROR,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Calculation Error: '%1'.").arg(errorString),this); |
| 1120 |
jobQuery->addErrorString("Calculation error: "+errorString); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
|
| 1125 |
CReasoningTaskData* reasoningQueryData = mReasoningTaskDataHash.value((cint64)jobQuery,nullptr); |
| 1126 |
updateFinishingCalculationStatistics(reasoningQueryData,jobQuery->getQueryStatistics()); |
| 1127 |
QString newAnswerString; |
| 1128 |
|
| 1129 |
bool queryFinished = false; |
| 1130 |
if (!reasoningQueryData->mAnswered) { |
| 1131 |
queryFinished = jobQuery->interpreteJobSatisfiableCalculation(satCalcJob,satisfiable,calcError,&newAnswerString); |
| 1132 |
} |
| 1133 |
|
| 1134 |
CReasoningTaskData* reasoningJobData = mReasoningTaskDataHash.value((cint64)satCalcJob,nullptr); |
| 1135 |
if (reasoningJobData) { |
| 1136 |
reasoningJobData->mDepCount--; |
| 1137 |
CCallbackData* callback = reasoningJobData->mCallback; |
| 1138 |
if (callback) { |
| 1139 |
callback->setCallbackDataContext(cbsce->takeCallbackDataContext()); |
| 1140 |
callback->doCallback(); |
| 1141 |
} |
| 1142 |
mReasoningTaskDataHash.remove((cint64)satCalcJob); |
| 1143 |
delete reasoningJobData; |
| 1144 |
} |
| 1145 |
mCalcJobSet.remove(satCalcJob); |
| 1146 |
|
| 1147 |
if (--(reasoningQueryData->mDepCount) <= 0) { |
| 1148 |
reasoningQueryData->mAnswered |= queryFinished; |
| 1149 |
reasoningQueryData->mFinQueryCallback->sendEventWithAnswer(newAnswerString); |
| 1150 |
} |
| 1151 |
} |
| 1152 |
|
| 1153 |
void CReasonerManagerThread::finishQueryReasoning(CCalcedQueryEvent *cqe) { |
| 1154 |
CQuery *query = cqe->getQuery(); |
| 1155 |
CReasoningTaskData* reasoningData = mReasoningTaskDataHash.value((cint64)query,nullptr); |
| 1156 |
|
| 1157 |
CComplexAnsweringQuery* compAnsQuery = dynamic_cast<CComplexAnsweringQuery *>(query); |
| 1158 |
if (compAnsQuery) { |
| 1159 |
CQueryStatistics* queryStats = query->getQueryStatistics(); |
| 1160 |
if (queryStats) { |
| 1161 |
CAnsweringStatistics* stats = mAnswererManager->getAnsweringStatistics(compAnsQuery->getBaseOntology()); |
| 1162 |
if (stats) { |
| 1163 |
for (const QString& statName : stats->getStatisticsNameStringList()) { |
| 1164 |
cint64 statValue = stats->getStatisticIntegerValue(statName); |
| 1165 |
queryStats->addProcessingStatistics(statName, statValue); |
| 1166 |
} |
| 1167 |
delete stats; |
| 1168 |
} |
| 1169 |
updateFinishingCalculationStatistics(reasoningData, queryStats, compAnsQuery->getBaseOntology()->getConfiguration()); |
| 1170 |
} |
| 1171 |
} else { |
| 1172 |
LOG(INFO, "::Konclude::Reasoner::Kernel::ReasonerManager", logTr("Query '%1' processed. Question '%2' answered with '%3'.\r\n").arg(cqe->getQueryName()).arg(cqe->getQueryString()).arg(cqe->getAnswerString()), this); |
| 1173 |
|
| 1174 |
qint64 mSecs = reasoningData->mStartTime.elapsed(); |
| 1175 |
LOG(INFO, "::Konclude::Reasoner::Kernel::ReasonerManager", logTr("Query '%1' processed in '%2' ms.").arg(cqe->getQueryName()).arg(mSecs), this); |
| 1176 |
} |
| 1177 |
|
| 1178 |
// print calculation statistics |
| 1179 |
loggingCalculationStatistics(); |
| 1180 |
|
| 1181 |
|
| 1182 |
CCallbackData* callback = reasoningData->mCallback; |
| 1183 |
if (callback) { |
| 1184 |
callback->doCallback(); |
| 1185 |
} |
| 1186 |
mCalculatingQuerySet.remove(query); |
| 1187 |
mReasoningTaskDataHash.remove((cint64)query); |
| 1188 |
delete reasoningData; |
| 1189 |
|
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
bool CReasonerManagerThread::processCustomsEvents(QEvent::Type type, CCustomEvent *event) { |
| 1194 |
if (CIntervalThread::processCustomsEvents(type,event)) { |
| 1195 |
return true; |
| 1196 |
} else if (type == CReasoningSatisfiableCalculationJobEvent::EVENTTYPE) { |
| 1197 |
CReasoningSatisfiableCalculationJobEvent *cbse = static_cast<CReasoningSatisfiableCalculationJobEvent *>(event); |
| 1198 |
prepareSatisfiableBoxReasoning(cbse); |
| 1199 |
return true; |
| 1200 |
|
| 1201 |
} else if (type == CJobCalculatedSatisfiableCallbackEvent::EVENTTYPE) { |
| 1202 |
CJobCalculatedSatisfiableCallbackEvent *cbsce = static_cast<CJobCalculatedSatisfiableCallbackEvent *>(event); |
| 1203 |
finishSatisfiableBoxReasoning(cbsce); |
| 1204 |
return true; |
| 1205 |
|
| 1206 |
} else if (type == CQueryJobCalculatedSatisfiableCallbackEvent::EVENTTYPE) { |
| 1207 |
CQueryJobCalculatedSatisfiableCallbackEvent *cbsce = static_cast<CQueryJobCalculatedSatisfiableCallbackEvent *>(event); |
| 1208 |
finishQuerySatisfiableBoxReasoning(cbsce); |
| 1209 |
return true; |
| 1210 |
|
| 1211 |
} else if (type == CCalcQueryEvent::EVENTTYPE) { |
| 1212 |
CCalcQueryEvent *cqe = static_cast<CCalcQueryEvent *>(event); |
| 1213 |
|
| 1214 |
prepareQueryReasoning(cqe); |
| 1215 |
|
| 1216 |
return true; |
| 1217 |
|
| 1218 |
} else if (type == CPrepareOntologyEvent::EVENTTYPE) { |
| 1219 |
CPrepareOntologyEvent* poe = static_cast<CPrepareOntologyEvent *>(event); |
| 1220 |
|
| 1221 |
prepareOntologyReasoning(poe); |
| 1222 |
|
| 1223 |
return true; |
| 1224 |
|
| 1225 |
} else if (type == CCalcedQueryEvent::EVENTTYPE) { |
| 1226 |
CCalcedQueryEvent *cqe = static_cast<CCalcedQueryEvent *>(event); |
| 1227 |
|
| 1228 |
finishQueryReasoning(cqe); |
| 1229 |
|
| 1230 |
return true; |
| 1231 |
|
| 1232 |
} else if (type == CRequirementProcessedCallbackEvent::EVENTTYPE) { |
| 1233 |
CRequirementProcessedCallbackEvent* rpce = static_cast<CRequirementProcessedCallbackEvent *>(event); |
| 1234 |
CConcreteOntology* ontology = rpce->getOntology(); |
| 1235 |
CRequirementPreparingData* reqPrepData = rpce->getRequirementPreparingData(); |
| 1236 |
|
| 1237 |
continueRequirementProcessing(reqPrepData, ontology); |
| 1238 |
|
| 1239 |
|
| 1240 |
if (rpce->mProcType == COntologyProcessingStep::OPANSWERER && !mAnswererPrepared) { |
| 1241 |
mAnswererPrepared = true; |
| 1242 |
for (CRequirementProcessedCallbackEvent* prepReqData : mAnswererPreparedCallbackQueue) { |
| 1243 |
prepReqData->doCallback(); |
| 1244 |
} |
| 1245 |
mAnswererPreparedCallbackQueue.clear(); |
| 1246 |
} |
| 1247 |
|
| 1248 |
|
| 1249 |
return true; |
| 1250 |
} |
| 1251 |
|
| 1252 |
return false; |
| 1253 |
} |
| 1254 |
|
| 1255 |
|
| 1256 |
}; // end namespace Manager |
| 1257 |
|
| 1258 |
}; // end namespace Kernel |
| 1259 |
|
| 1260 |
}; // end namespace Reasoner |
| 1261 |
|
| 1262 |
}; // end namespace Konclude |