| 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 "COptimizedComplexExpressionAnsweringHandler.h" |
| 22 |
|
| 23 |
namespace Konclude { |
| 24 |
|
| 25 |
namespace Reasoner { |
| 26 |
|
| 27 |
namespace Answerer { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
COptimizedComplexExpressionAnsweringHandler::COptimizedComplexExpressionAnsweringHandler(COptimizedComplexExpressionOntologyAnsweringItem* ontoAnsweringItem) : CAnsweringHandler(), CLogDomain("::Konclude::Reasoner::Kernel::ComplexExpressionQueryAnswerer") { |
| 34 |
mOntoAnsweringItem = ontoAnsweringItem; |
| 35 |
mConfDebugTestingOntologyWriting = false; |
| 36 |
mConfInterpretNonAnswerIndividualVariablesAsAnonymousVariables = false; |
| 37 |
mConfDirectPossibleRealizationRequesting = false; |
| 38 |
mConfFailOnUnknownEntity = false; |
| 39 |
mConfAnonymousToDistinguishedVariablesConversion = true; |
| 40 |
mConfAnonymousToDistinguishedVariablesOnlyFullConversion = true; |
| 41 |
mConfUnsatisfiableNonInstanceStatisticsChecking = false; |
| 42 |
mConfOccurrenceStatisticsCollection = false; |
| 43 |
mConfRedundantlyRestrictedVariablesElimination = true; |
| 44 |
mConfAllowBindingReduction = true; |
| 45 |
mConfAllowJoiningBindingReduction = true; |
| 46 |
mConfMappingSizeBindingReduction = 5000; |
| 47 |
mConfDebugWriteVariableCompositionItems = false; |
| 48 |
mConfSamplingBasedJoinMappingSize = 1000; |
| 49 |
mConfBindingReducingForNonDistinctAnswerQueries = true; |
| 50 |
mConfDetailedMissingEntityReporting = true; |
| 51 |
|
| 52 |
mConfDistinctUnecessaryVariablesReduction = true; |
| 53 |
mConfAlwaysUnecessaryVariablesReduction = false; |
| 54 |
mConfConceptItemExpectedCountSamplingSize = 30; |
| 55 |
mConfConceptItemExpectedCountSamplingRetrievedPercentageLimit = 75.; |
| 56 |
|
| 57 |
|
| 58 |
cint64 computationThreadCount = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ConcurrentComputationThreadPoolSize", 0); |
| 59 |
if (computationThreadCount != 0) { |
| 60 |
QThreadPool::globalInstance()->setMaxThreadCount(computationThreadCount); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
mConfInterpretQueriesAsDistinct = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.InterpretQueriesAsDistinct", false); |
| 65 |
|
| 66 |
|
| 67 |
mConfInterpretNonAnswerIndividualVariablesAsAnonymousVariables = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.InterpretNonAnswerIndividualVariablesAsAnonymousVariables", false); |
| 68 |
mConfNonAnswerIndividualVariablesAsAnonymousVariablesInterpretingPrefixString = CConfigDataReader::readConfigString(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NonAnswerIndividualVariablesAsAnonymousVariablesInterpretingPrefixString", ""); |
| 69 |
|
| 70 |
|
| 71 |
mConfDebugWriteVariableCompositionItems = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Debugging.WriteAnsweringVariableCompositionItems", false); |
| 72 |
|
| 73 |
mConfSamplingBasedJoinMappingSize = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.SamplingBasedJoinMappingSize", 1000); |
| 74 |
|
| 75 |
mConfFailOnUnknownEntity = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.FailOnUnknownEntity", false); |
| 76 |
mConfExtendedLogging = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ExtendedLogging", false); |
| 77 |
mConfVariablePreAbsorption = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.QueryAbsorption.Preabsorption", true); |
| 78 |
mConfRedundantTermReduction = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.RedundantTermElimination", true); |
| 79 |
|
| 80 |
mConfAllowBindingReduction = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.AllowBindingReduction", true); |
| 81 |
mConfAllowJoiningBindingReduction = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ImplicitJoiningBindingReduction", true); |
| 82 |
mConfBindingReducingForNonDistinctAnswerQueries = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.BindingReducingForNonDistinctAnswerQueries", true); |
| 83 |
mConfMappingSizeBindingReduction = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.BindingReductionMappingSize", 5000); |
| 84 |
mConfPropagationJoining = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.PropagationJoining", true); |
| 85 |
mConfPropagationReplacement = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.PropagationReplacement", false); |
| 86 |
|
| 87 |
mConfAnonymousToDistinguishedVariablesConversion = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.AnonymousToDistinguishedVariableConversion", true); |
| 88 |
mConfAnonymousToDistinguishedVariablesOnlyFullConversion = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.AnonymousToDistinguishedVariableOnlyFullConversion", true); |
| 89 |
mConfOccurrenceStatisticsCollection = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Calculation.Optimization.OccurrenceStatisticsCollecting", true); |
| 90 |
if (mConfOccurrenceStatisticsCollection) { |
| 91 |
mConfUnsatisfiableNonInstanceStatisticsChecking = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.UnsatisfiableNonInstanceStatisticsChecking", true); |
| 92 |
} |
| 93 |
mConfRedundantlyRestrictedVariablesElimination = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.RedundantlyRestrictedVariablesElimination", true); |
| 94 |
|
| 95 |
|
| 96 |
mConfMaximumBatchMappingsComputationSize = 100000000; |
| 97 |
mConfBatchMappingsComputationSizeIncreasingFactor = 10.; |
| 98 |
mConfFirstBatchMappingsComputationSize = 10; |
| 99 |
mConfMinimalMappingsComputationSize = 1; |
| 100 |
mConfMappingsRepeatedlyInsufficientDependencyComputationIncreasingFactor = 1.3; |
| 101 |
mConfMappingsComputationUnlimitedInterpretationSize = Q_UINT64_C(100000000000000); |
| 102 |
|
| 103 |
|
| 104 |
mConfMaximumBatchMappingsComputationSize = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.MaximumBatchMappingsComputationSize", 100000000); |
| 105 |
mConfBatchMappingsComputationSizeIncreasingFactor = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.BatchMappingsComputationSizeIncreasingFactorPercent", 1000) / 100.; |
| 106 |
mConfFirstBatchMappingsComputationSize = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.FirstBatchMappingsComputationSize", 10); |
| 107 |
mConfMinimalMappingsComputationSize = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.MinimalMappingsComputationSize", 1); |
| 108 |
mConfMappingsRepeatedlyInsufficientDependencyComputationIncreasingFactor = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.MappingsRepeatedlyInsufficientDependencyComputationIncreasingFactorPercent", 130) / 100.; |
| 109 |
mConfMappingsComputationUnlimitedInterpretationSize = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.MappingsComputationUnlimitedInterpretationSize", Q_UINT64_C(100000000000000)); |
| 110 |
mConfContinueMappingsCompuationWhenResultsNotWriteable = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ContinueMappingsCompuationWhenResultsNotWriteable", false); |
| 111 |
|
| 112 |
|
| 113 |
mConfLazyExistentialPartAbsorption = true; |
| 114 |
mConfBooleanQueryExistentialPartOrdinaryEvaluation = true; |
| 115 |
|
| 116 |
mConfLazyExistentialPartAbsorption = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.LazyExistentialQueryPartAbsorption", true); |
| 117 |
mConfBooleanQueryExistentialPartOrdinaryEvaluation = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.BooleanQueryExistentialPartOrdinaryEvaluation", true); |
| 118 |
|
| 119 |
|
| 120 |
mConfConceptItemInstanceCandiateRetrievingSizeIncreaseFactor = 1.3; |
| 121 |
mConfConceptItemInstanceCandiateRetrievingMaxSize = 10000; |
| 122 |
|
| 123 |
|
| 124 |
mConfFullQueryMaterialization = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.FullQueryMaterialization", true); |
| 125 |
|
| 126 |
mConfConceptItemExpectedCountSamplingSize = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ConceptItemExpectedCountSamplingSize", 30); |
| 127 |
mConfConceptItemExpectedCountSamplingRetrievedPercentageLimit = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ConceptItemExpectedCountSamplingRetrievedPercentageLimit", 75) / 100.; |
| 128 |
|
| 129 |
mConfDistinctUnecessaryVariablesReduction = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.DistinctUnecessaryVariablesReductionBeforeAnswerGeneration", true); |
| 130 |
mConfAlwaysUnecessaryVariablesReduction = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.AlwaysUnecessaryVariablesReductionBeforeAnswerGeneration", false); |
| 131 |
|
| 132 |
|
| 133 |
mConfMaxVariableBindingPropagationsInitializationIndividualCount = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.MaxVariableMappingsPropagationsInitializationIndividualCount", 50000); |
| 134 |
mConfMaxCandidateInstancePropagationsInitializationIndividualCount = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.MaxCandidateInstancePropagationsInitializationIndividualCount", 10000); |
| 135 |
mConfSplitVariableMappingPropagationTestMaxIntegrationLimit = 10000; |
| 136 |
mConfSplitVariableMappingPropagationTestIntegrationLimitIncreaseFactor = 2.; |
| 137 |
mConfSplitVariableMappingPropagationTestInitialVariableIntegrationLimit = 2000; |
| 138 |
mConfSplitVariableMappingPropagationTestInitialTotalIntegrationLimit = 3000; |
| 139 |
//mConfSplitVariableMappingPropagationTestInitialVariableIntegrationLimit = 1500000; |
| 140 |
//mConfSplitVariableMappingPropagationTestInitialTotalIntegrationLimit = 20000000; |
| 141 |
|
| 142 |
mConfAbsorbedIndividualActivationInstanceCandidatePropagationSplitting = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Calculation.Answering.AbsorbedIndividualActivationCandidateInstancePropagationSplitting", true); |
| 143 |
|
| 144 |
|
| 145 |
mConfQueryEntailmentTestRestrictedTopPropertyPropagationSplitting = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.QueryEntailmentTestRestrictedTopPropertyPropagationSplitting", true); |
| 146 |
|
| 147 |
|
| 148 |
mConfAllowLastStepSplitComputation = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.AllowLastStepSplitComputation", true); |
| 149 |
mConfLastStepSplitComputationMappingsRequirement = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.LastStepSplitComputationMappingsRequirement", 5000000); |
| 150 |
|
| 151 |
mConfSkipConceptItemsIntegrationForPropagationOverVariables = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.SkipConceptItemsIntegrationForPropagationOverVariables", true); |
| 152 |
|
| 153 |
mAnsweringStartTime.start(); |
| 154 |
mTestingOntologyPreprocessor = new COntologyQueryExtendedConfigDependedPreProcesser(); |
| 155 |
mTestingOntologyBuilder = new CConcreteOntologyRebuildingPreparationBuilder(ontoAnsweringItem->getTestingOntology(true)); |
| 156 |
|
| 157 |
mDefaultRealizationSorting = CRealizationIndividualSorting(CRealizationIndividualSorting::SORT_TYPE_INDIVIDUAL_ID, CRealizationIndividualSorting::SORT_ORDER_ASCENDING, CRealizationIndividualSorting::SORT_GROUP_SAME_UNIQUE); |
| 158 |
mRoleFillerRealizationSorting = CRealizationIndividualSorting(CRealizationIndividualSorting::SORT_TYPE_NOTHING, CRealizationIndividualSorting::SORT_ORDER_NOTHING, CRealizationIndividualSorting::SORT_GROUP_SAME_UNIQUE); |
| 159 |
|
| 160 |
|
| 161 |
mConfNonDeterministicSatisfiableCalculationContinuation = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Calculation.Answering.NonDeterministicCachedCompletionGraphContinuationPropagationTests", true); |
| 162 |
|
| 163 |
mConfConcurrentJoining = true; |
| 164 |
|
| 165 |
mConfAutomaticConcurrentComputationActivation = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.AutomaticConcurrentComputationActivation", true); |
| 166 |
if (mConfAutomaticConcurrentComputationActivation) { |
| 167 |
mConfAutomaticConcurrentComputationActivation = false; |
| 168 |
|
| 169 |
mConfAutomaticConcurrentComputationActivation = getWorkerCountConcurrentActivation(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Calculation.WorkerCount") || getWorkerCountConcurrentActivation(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Calculation.ProcessorCount"); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
mConcurrentJoinComputationTaskCount = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ConcurrentJoinComputationTaskCount", 50); |
| 174 |
mConfConcurrentJoining = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ConcurrentJoinComputation", true) || mConfAutomaticConcurrentComputationActivation; |
| 175 |
|
| 176 |
if (mConfConcurrentJoining) { |
| 177 |
mJoinComputer = new CQtConcurrentVariableMappingsCompositionJoinComputator(); |
| 178 |
} else { |
| 179 |
mJoinComputer = new CSequentialVariableMappingsCompositionJoinComputator(); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
mConfConcurrentPropagation = false; |
| 188 |
|
| 189 |
mConcurrentPropagationComputationTaskCount = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ConcurrentPropagationComputationTaskCount", 50); |
| 190 |
mConfConcurrentPropagation = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ConcurrentPropagationComputation", true) || mConfAutomaticConcurrentComputationActivation; |
| 191 |
|
| 192 |
if (mConfConcurrentPropagation) { |
| 193 |
mPropagationComputer = new CQtConcurrentVariableMappingsCompositionPropagationComputator(); |
| 194 |
} else { |
| 195 |
mPropagationComputer = new CSequentialVariableMappingsCompositionPropagationComputator(); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
mConfConcurrentAnswerGeneration = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.ConcurrentAnswerGeneration", true) || mConfAutomaticConcurrentComputationActivation; |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
mConfNextVariablePropagationHandlingReducibleFactorIntegration = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.ReducibleFactorIntegration", true); |
| 211 |
mConfNextVariablePropagationHandlingPropertyScoresIntegration = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.PropertyScoresIntegration", true); |
| 212 |
mConfNextVariablePropagationHandlingPropertyPriorization = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.PropertyPriorization", true); |
| 213 |
mConfVariableCompositionItemRoleSampling = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.PropertyScore.VariableCompositionItemRoleSuccessorCountSampling", true); |
| 214 |
mConfForceAlwaysVariableCompositionItemRoleSampling = CConfigDataReader::readConfigBoolean(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.PropertyScore.ForceAlwaysVariableCompositionItemRoleSuccessorCountSampling", false); |
| 215 |
|
| 216 |
mConfNextVariablePropagationHandlingReducibleFactor = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.ReducibleFactorPercent", 80) / 100.; |
| 217 |
mConfNextVariablePropagationHandlingPropertyTotalScoreIntegrationPercent = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.PropertyTotalScoreIntegrationPercent", 5); |
| 218 |
mConfNextVariablePropagationHandlingPropertyInOutFactorIntegrationPercent = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.PropertySuccessorStatisticsSamplingFactorIntegrationPercent", 50); |
| 219 |
mConfVariableCompositionItemRoleSamplingCount = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.VariableCompositionItemRoleSuccessorSamplingCount", 20); |
| 220 |
mConfVariableCompositionItemRoleSamplingMappingsIncreaseSize = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.NextVariablePropagationHandlingChoise.VariableCompositionItemRoleSuccessorSamplingExpectedMappingIncreaseSize", 10000); |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
mConfAnswersCacheMaximumSizeBytes = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.AnswersCacheMaximumSizeBytes", -1); |
| 225 |
mConfAnswersCacheMaximumCount = CConfigDataReader::readConfigInteger(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.AnswersCacheMaximumCount", -1); |
| 226 |
mConfAnswersCacheUsageWeightIncrease = CConfigDataReader::readConfigDouble(ontoAnsweringItem->getCalculationConfiguration(), "Konclude.Answering.AnswersCacheUsageWeightIncreaseFactor", 1.03); |
| 227 |
|
| 228 |
|
| 229 |
readConfig(); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
bool COptimizedComplexExpressionAnsweringHandler::getWorkerCountConcurrentActivation(CCalculationConfigurationExtension* calcConfig, const QString& configName) { |
| 236 |
bool configErrorFlag = false; |
| 237 |
QString workerCountString = CConfigDataReader::readConfigString(calcConfig, configName, QString(), &configErrorFlag); |
| 238 |
if (!configErrorFlag) { |
| 239 |
if (workerCountString == "AUTO" && CThread::idealThreadCount() > 1) { |
| 240 |
return true; |
| 241 |
} else { |
| 242 |
qint64 convertedWorkerCount = workerCountString.toInt(&configErrorFlag); |
| 243 |
if (configErrorFlag && convertedWorkerCount > 1) { |
| 244 |
return true; |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
return false; |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
COptimizedComplexExpressionAnsweringHandler::~COptimizedComplexExpressionAnsweringHandler() { |
| 253 |
delete mOntoAnsweringItem; |
| 254 |
delete mTestingOntologyPreprocessor; |
| 255 |
delete mTestingOntologyBuilder; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
bool COptimizedComplexExpressionAnsweringHandler::canAnsweringComplexQuery(bool composedQuery) { |
| 272 |
return !composedQuery; |
| 273 |
} |
| 274 |
|
| 275 |
bool COptimizedComplexExpressionAnsweringHandler::canAnsweringComplexQuery(CComplexAnsweringQuery* complexAnsweringQuery) { |
| 276 |
if (dynamic_cast<CComplexAnsweringExpressionQuery*>(complexAnsweringQuery)) { |
| 277 |
return true; |
| 278 |
} |
| 279 |
return false; |
| 280 |
} |
| 281 |
|
| 282 |
bool COptimizedComplexExpressionAnsweringHandler::addAnsweringComplexQuery(CComplexAnsweringQuery* complexAnsweringQuery, CCallbackData* callback) { |
| 283 |
mPendingQueryProcessingList.append(new CComplexQueryExpressionProcessingData((CComplexAnsweringExpressionQuery*)complexAnsweringQuery, callback)); |
| 284 |
return true; |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
bool COptimizedComplexExpressionAnsweringHandler::initializeProcessing(CAnswererContext* answererContext) { |
| 290 |
if (!mOntoAnsweringItem->isOntologyBuildingAndPreprocessingPrepared()) { |
| 291 |
prepareProcessing(answererContext); |
| 292 |
} |
| 293 |
while (!mPendingQueryProcessingList.isEmpty()) { |
| 294 |
CComplexQueryExpressionProcessingData* queryData = mPendingQueryProcessingList.takeFirst(); |
| 295 |
|
| 296 |
CAnsweringHandlingStatistics* stats = mOntoAnsweringItem->getAnsweringHandlingStatistics(); |
| 297 |
if (stats) { |
| 298 |
CAnsweringHandlingStatistics* initStats = new CAnsweringHandlingStatistics(); |
| 299 |
*initStats = *stats; |
| 300 |
queryData->setQueryProcessingInitializedAnsweringStatistics(initStats); |
| 301 |
} |
| 302 |
|
| 303 |
initializeQueryProcessing(queryData,answererContext); |
| 304 |
} |
| 305 |
return true; |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
bool COptimizedComplexExpressionAnsweringHandler::prepareProcessing(CAnswererContext* answererContext) { |
| 311 |
if (!mOntoAnsweringItem->isOntologyBuildingAndPreprocessingPrepared()) { |
| 312 |
LOG(INFO, getDomain(), logTr("Preparing query answering handler."), this); |
| 313 |
mTestingOntologyBuilder->prepareRebuildingUpdates(); |
| 314 |
CConcreteOntology* testingOnto = mOntoAnsweringItem->getTestingOntology(true); |
| 315 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 316 |
LOG(INFO, getDomain(), logTr("Query answering hanlder prepared."), this); |
| 317 |
mOntoAnsweringItem->setOntologyBuildingAndPreprocessingPrepared(true); |
| 318 |
} |
| 319 |
return true; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
bool nodeSortLessPredecessorsThan(const CHierarchyNode* item1, const CHierarchyNode* item2) { |
| 324 |
return item1->getPredecessorNodeCount() < item2->getPredecessorNodeCount(); |
| 325 |
} |
| 326 |
|
| 327 |
bool nodeSortMorePredecessorsThan(const CHierarchyNode* item1, const CHierarchyNode* item2) { |
| 328 |
return item1->getPredecessorNodeCount() > item2->getPredecessorNodeCount(); |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
bool COptimizedComplexExpressionAnsweringHandler::initializeComplexConceptQueryProcessing(CComplexQueryExpressionProcessingData* queryProcessingData, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CClassTermExpression* classTermExpOfInt, bool satisfiableComputationRequired, bool superClassNodesComputationRequired, bool subClassNodesComputationRequired, bool equivalentClassNodesComputationRequired, bool subClassRealizationRequired, cint64 instanceComputationRequiredCount, COptimizedComplexConceptItem** assocConceptItem) { |
| 336 |
CConcept* testingConcept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(classTermExpOfInt); |
| 337 |
bool testingNegation = testingConcept->hasMappingNegation(); |
| 338 |
return initializeComplexConceptQueryProcessing(queryProcessingData, buildingVarItem, testingConcept, testingNegation, satisfiableComputationRequired, superClassNodesComputationRequired, subClassNodesComputationRequired, equivalentClassNodesComputationRequired, subClassRealizationRequired, instanceComputationRequiredCount, assocConceptItem); |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
bool COptimizedComplexExpressionAnsweringHandler::initializeComplexConceptQueryProcessing(CComplexQueryExpressionProcessingData* queryProcessingData, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CConcept* testingConcept, bool testingNegation, bool satisfiableComputationRequired, bool superClassNodesComputationRequired, bool subClassNodesComputationRequired, bool equivalentClassNodesComputationRequired, bool subClassRealizationRequired, cint64 instanceComputationRequiredCount, COptimizedComplexConceptItem** assocConceptItem) { |
| 345 |
bool created = false; |
| 346 |
COptimizedComplexConceptItem* conceptItem = mOntoAnsweringItem->getComplexConceptItem(testingConcept, testingNegation, true, &created); |
| 347 |
if (assocConceptItem) { |
| 348 |
*assocConceptItem = conceptItem; |
| 349 |
} |
| 350 |
if (buildingVarItem) { |
| 351 |
buildingVarItem->addUsedComplexConceptItem(conceptItem); |
| 352 |
} |
| 353 |
conceptItem->incCacheWeightedUsageFactor(mOntoAnsweringItem->getNextUsageWeight()); |
| 354 |
if (created) { |
| 355 |
|
| 356 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incCreatedComplexConceptItemsCount(); |
| 357 |
|
| 358 |
if (!mOntoAnsweringItem->getTestingOntology()->getABox()->hasUniversalConnectionIndividual()) { |
| 359 |
bool usesTopRolePropagation = checkHasNewTopRolePropagation(testingConcept, testingNegation); |
| 360 |
if (usesTopRolePropagation) { |
| 361 |
conceptItem->setTopObjectPropertyUsage(usesTopRolePropagation); |
| 362 |
} |
| 363 |
} |
| 364 |
extractAtomicSubsumerExpressions(conceptItem); |
| 365 |
searchTrivialSuperSubConceptItems(conceptItem); |
| 366 |
} |
| 367 |
if (queryProcessingData) { |
| 368 |
conceptItem->incQueryUsageCount(); |
| 369 |
queryProcessingData->setConceptItem(conceptItem); |
| 370 |
} |
| 371 |
CComplexConceptItemComputationProcess* computationProcess = conceptItem->getComputationProcess(); |
| 372 |
|
| 373 |
bool instancesDirectResolveable = true; |
| 374 |
if (instanceComputationRequiredCount != 0) { |
| 375 |
instancesDirectResolveable = false; |
| 376 |
if (checkConceptInstancesCompletelyResolveable(conceptItem, nullptr)) { |
| 377 |
instancesDirectResolveable = true; |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
bool requiresProcessing = false; |
| 383 |
subClassNodesComputationRequired |= equivalentClassNodesComputationRequired || subClassRealizationRequired; |
| 384 |
superClassNodesComputationRequired |= subClassNodesComputationRequired || !instancesDirectResolveable; |
| 385 |
satisfiableComputationRequired |= superClassNodesComputationRequired; |
| 386 |
if (satisfiableComputationRequired) { |
| 387 |
requiresProcessing |= initializeQueryProcessingStep(computationProcess->getSatisfiableClassNodesComputationProcess(true), conceptItem, queryProcessingData, buildingVarItem); |
| 388 |
} |
| 389 |
if (superClassNodesComputationRequired) { |
| 390 |
requiresProcessing |= initializeQueryProcessingStep(computationProcess->getSuperClassNodesComputationProcess(true), conceptItem, queryProcessingData, buildingVarItem); |
| 391 |
} |
| 392 |
if (subClassNodesComputationRequired) { |
| 393 |
requiresProcessing |= initializeQueryProcessingStep(computationProcess->getSubClassNodesComputationProcess(true), conceptItem, queryProcessingData, buildingVarItem); |
| 394 |
} |
| 395 |
if (equivalentClassNodesComputationRequired) { |
| 396 |
requiresProcessing |= initializeQueryProcessingStep(computationProcess->getEquivalentClassNodesComputationProcess(true), conceptItem, queryProcessingData, buildingVarItem); |
| 397 |
} |
| 398 |
if (subClassRealizationRequired) { |
| 399 |
requiresProcessing |= initializeQueryProcessingStep(computationProcess->getSubClassRealizationProcess(true), conceptItem, queryProcessingData, buildingVarItem); |
| 400 |
} |
| 401 |
if (instanceComputationRequiredCount == -1) { |
| 402 |
CComplexConceptStepInstanceComputationProcess* instanceCompStep = computationProcess->getInstancesComputationProcess(true); |
| 403 |
instanceCompStep->setAllInstanceComputationRequired(true); |
| 404 |
requiresProcessing |= initializeQueryProcessingStep(computationProcess->getInstancesComputationProcess(true), conceptItem, queryProcessingData, buildingVarItem); |
| 405 |
} else if (instanceComputationRequiredCount > 0) { |
| 406 |
CComplexConceptStepInstanceComputationProcess* instanceCompStep = computationProcess->getInstancesComputationProcess(true); |
| 407 |
if (instanceComputationRequiredCount > instanceCompStep->getComputedInstancesCount()) { |
| 408 |
|
| 409 |
CComputedItemDataNotificationLinker* notLinker = nullptr; |
| 410 |
if (queryProcessingData) { |
| 411 |
if (!notLinker) { |
| 412 |
notLinker = mOntoAnsweringItem->createComputedItemDataNotificationLinker(); |
| 413 |
} |
| 414 |
notLinker->setQueryProcessingData(queryProcessingData); |
| 415 |
queryProcessingData->setComputationStepWaiting(instanceCompStep); |
| 416 |
} |
| 417 |
if (buildingVarItem) { |
| 418 |
if (!notLinker) { |
| 419 |
notLinker = mOntoAnsweringItem->createComputedItemDataNotificationLinker(); |
| 420 |
} |
| 421 |
notLinker->setBuildingVariableItemProcessingItem(buildingVarItem); |
| 422 |
buildingVarItem->setComputationStepWaiting(instanceCompStep); |
| 423 |
} |
| 424 |
if (notLinker) { |
| 425 |
instanceCompStep->addComputedInstancesCountRequirement(instanceComputationRequiredCount, notLinker); |
| 426 |
} |
| 427 |
queueConceptItemProcessing(conceptItem, instanceCompStep); |
| 428 |
requiresProcessing = true; |
| 429 |
} |
| 430 |
} |
| 431 |
return requiresProcessing; |
| 432 |
|
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
bool COptimizedComplexExpressionAnsweringHandler::initializeQueryProcessingStep(CComplexConceptStepComputationProcess* compStep, COptimizedComplexConceptItem* conceptItem, CComplexQueryExpressionProcessingData* queryProcessingData, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 439 |
if (compStep->isComputationProcessFinished()) { |
| 440 |
return false; |
| 441 |
} else { |
| 442 |
compStep->setComputationProcessRequired(true); |
| 443 |
CComputedItemDataNotificationLinker* notLinker = nullptr; |
| 444 |
if (queryProcessingData) { |
| 445 |
if (!notLinker) { |
| 446 |
notLinker = mOntoAnsweringItem->createComputedItemDataNotificationLinker(); |
| 447 |
} |
| 448 |
notLinker->setQueryProcessingData(queryProcessingData); |
| 449 |
queryProcessingData->setComputationStepWaiting(compStep); |
| 450 |
} |
| 451 |
if (buildingVarItem) { |
| 452 |
if (!notLinker) { |
| 453 |
notLinker = mOntoAnsweringItem->createComputedItemDataNotificationLinker(); |
| 454 |
} |
| 455 |
notLinker->setBuildingVariableItemProcessingItem(buildingVarItem); |
| 456 |
buildingVarItem->setComputationStepWaiting(compStep); |
| 457 |
} |
| 458 |
if (notLinker) { |
| 459 |
compStep->addNotificationLinker(notLinker); |
| 460 |
} |
| 461 |
|
| 462 |
queueConceptItemProcessing(conceptItem, compStep); |
| 463 |
return true; |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
bool COptimizedComplexExpressionAnsweringHandler::checkHasNewTopRolePropagation(CConcept* concept, bool conceptNegation) { |
| 470 |
CRole* topRole = mOntoAnsweringItem->getTestingOntology()->getRBox()->getTopObjectRole(); |
| 471 |
QList<CConcept*> testingList; |
| 472 |
QSet<CConcept*> testedSet; |
| 473 |
testingList.append(concept); |
| 474 |
testedSet.insert(concept); |
| 475 |
while (!testingList.isEmpty()) { |
| 476 |
CConcept* testingConcept = testingList.takeFirst(); |
| 477 |
cint64 opCode = testingConcept->getOperatorCode(); |
| 478 |
|
| 479 |
CConceptOperator* conceptOperator = testingConcept->getConceptOperator(); |
| 480 |
if (conceptOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_ALL_TYPE | CConceptOperator::CCFS_SOME_TYPE)) { |
| 481 |
CRole* role = testingConcept->getRole(); |
| 482 |
if (role == topRole) { |
| 483 |
return true; |
| 484 |
} |
| 485 |
} |
| 486 |
|
| 487 |
if (opCode != CCEQ && opCode != CCSUB) { |
| 488 |
for (CSortedNegLinker<CConcept*>* opConLinkerIt = testingConcept->getOperandList(); opConLinkerIt; opConLinkerIt = opConLinkerIt->getNext()) { |
| 489 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 490 |
if (!testedSet.contains(opConcept)) { |
| 491 |
testedSet.insert(opConcept); |
| 492 |
testingList.append(opConcept); |
| 493 |
} |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
} |
| 498 |
return false; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
COptimizedComplexExpressionAnsweringHandler* COptimizedComplexExpressionAnsweringHandler::readConfig() { |
| 503 |
CCalculationConfigurationExtension* config = mOntoAnsweringItem->getCalculationConfiguration(); |
| 504 |
mConfDebugTestingOntologyWriting = config->isDebuggingWriteDataActivated(); |
| 505 |
|
| 506 |
|
| 507 |
mJoinComputer->configureComputator(mOntoAnsweringItem, this, mAnswererContext); |
| 508 |
mPropagationComputer->configureComputator(mOntoAnsweringItem, this, mAnswererContext); |
| 509 |
return this; |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
bool COptimizedComplexExpressionAnsweringHandler::checkUsesQueryOnlyKnownEntities(CConcreteOntology* expressionOntology) { |
| 515 |
COntologyBuildData* expressionOntologyBuildData = expressionOntology->getBuildData(); |
| 516 |
COntologyBuildData* baseOntologyBuildData = mOntoAnsweringItem->getOntology()->getBuildData(); |
| 517 |
if (baseOntologyBuildData->getClassEntityBuildHash()->size() != expressionOntologyBuildData->getClassEntityBuildHash()->size()) { |
| 518 |
if (mConfDetailedMissingEntityReporting) { |
| 519 |
for (CBUILDHASH<CStringRefStringHasher, CClassExpression*>::const_iterator it = expressionOntologyBuildData->getClassEntityBuildHash()->constBegin(), itEnd = expressionOntologyBuildData->getClassEntityBuildHash()->constEnd(); it != itEnd; ++it) { |
| 520 |
CClassExpression* classEx = it.value(); |
| 521 |
if (!baseOntologyBuildData->getClassEntityBuildHash()->contains(classEx->getName())) { |
| 522 |
LOG(WARN, getDomain(), logTr("Class %1 not used in queried ontology.").arg(classEx->getName()), this); |
| 523 |
return false; |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
return false; |
| 528 |
} |
| 529 |
if (baseOntologyBuildData->getDataPropertyEntityBuildHash()->size() != expressionOntologyBuildData->getDataPropertyEntityBuildHash()->size()) { |
| 530 |
return false; |
| 531 |
} |
| 532 |
if (baseOntologyBuildData->getObjectPropertyEntityBuildHash()->size() != expressionOntologyBuildData->getObjectPropertyEntityBuildHash()->size()) { |
| 533 |
if (mConfDetailedMissingEntityReporting) { |
| 534 |
for (CBUILDHASH<CStringRefStringHasher, CObjectPropertyExpression*>::const_iterator it = expressionOntologyBuildData->getObjectPropertyEntityBuildHash()->constBegin(), itEnd = expressionOntologyBuildData->getObjectPropertyEntityBuildHash()->constEnd(); it != itEnd; ++it) { |
| 535 |
CObjectPropertyExpression* objPropEx = it.value(); |
| 536 |
if (!baseOntologyBuildData->getObjectPropertyEntityBuildHash()->contains(objPropEx->getName())) { |
| 537 |
LOG(WARN, getDomain(), logTr("Object property %1 not used in queried ontology.").arg(objPropEx->getName()), this); |
| 538 |
return false; |
| 539 |
} |
| 540 |
} |
| 541 |
} |
| 542 |
return false; |
| 543 |
} |
| 544 |
if (baseOntologyBuildData->getIndividualEntityBuildHash()->size() != expressionOntologyBuildData->getIndividualEntityBuildHash()->size()) { |
| 545 |
COntologyTriplesAssertionsAccessor* indexedTriplesAssertionAccessor = mOntoAnsweringItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor(); |
| 546 |
if (indexedTriplesAssertionAccessor) { |
| 547 |
CBUILDHASH<CStringRefStringHasher, CNamedIndividualExpression*>* baseIndiEntHash = baseOntologyBuildData->getIndividualEntityBuildHash(); |
| 548 |
CBUILDHASH<CStringRefStringHasher, CNamedIndividualExpression*>* expIndiEntHash = expressionOntologyBuildData->getIndividualEntityBuildHash(); |
| 549 |
|
| 550 |
for (CBUILDHASH<CStringRefStringHasher, CNamedIndividualExpression*>::const_iterator it = expIndiEntHash->constBegin(), itEnd = expIndiEntHash->constEnd(); it != itEnd; ++it) { |
| 551 |
if (!baseIndiEntHash->contains(it.key())) { |
| 552 |
// check whether the individual is indexed in the triple stored data |
| 553 |
CNamedIndividualExpression* namedIndiEntExp = it.value(); |
| 554 |
|
| 555 |
if (!indexedTriplesAssertionAccessor->hasIndividualId(namedIndiEntExp->getName())) { |
| 556 |
return false; |
| 557 |
} |
| 558 |
|
| 559 |
} |
| 560 |
} |
| 561 |
} else { |
| 562 |
CBUILDHASH<CStringRefStringHasher, CNamedIndividualExpression*>* baseIndiEntHash = baseOntologyBuildData->getIndividualEntityBuildHash(); |
| 563 |
CBUILDHASH<CStringRefStringHasher, CNamedIndividualExpression*>* expIndiEntHash = expressionOntologyBuildData->getIndividualEntityBuildHash(); |
| 564 |
COntologyStringMapping* stringMapping = mOntoAnsweringItem->getOntology()->getStringMapping(); |
| 565 |
|
| 566 |
for (CBUILDHASH<CStringRefStringHasher, CNamedIndividualExpression*>::const_iterator it = expIndiEntHash->constBegin(), itEnd = expIndiEntHash->constEnd(); it != itEnd; ++it) { |
| 567 |
if (!baseIndiEntHash->contains(it.key())) { |
| 568 |
// check whether the individual is indexed in the triple stored data |
| 569 |
CNamedIndividualExpression* namedIndiEntExp = it.value(); |
| 570 |
|
| 571 |
if (!stringMapping->getIndividualFromName(namedIndiEntExp->getName())) { |
| 572 |
return false; |
| 573 |
} |
| 574 |
|
| 575 |
} |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
} |
| 581 |
if (baseOntologyBuildData->getDatatypeIRIBuildHash()->size() != expressionOntologyBuildData->getDatatypeIRIBuildHash()->size()) { |
| 582 |
return false; |
| 583 |
} |
| 584 |
if (baseOntologyBuildData->getAnonymousIndividualBuildHash()->size() != expressionOntologyBuildData->getAnonymousIndividualBuildHash()->size()) { |
| 585 |
return false; |
| 586 |
} |
| 587 |
return true; |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
static bool itemSortMoreHierachyDepthThan(const TDepthTermPair& item1, const TDepthTermPair& item2) { |
| 594 |
return item1.first > item2.first; |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
bool COptimizedComplexExpressionAnsweringHandler::tryEmbedVariableRestrictions(CExpressionVariable* varTesting, CExpressionVariable* varEmbedding, QHash<CExpressionVariable*, CExpressionVariable*>& varExpEmbeddingHash, |
| 602 |
const QHash<CExpressionVariable*, CAxiomExpression*>& varExpAxiomExpHash, const QSet<CExpressionVariable*>& anonymousIndiVariableSet, const QSet<CExpressionVariable*>& answerIndiVariableSet, CAnswererContext* answererContext) { |
| 603 |
|
| 604 |
if (varExpEmbeddingHash.value(varTesting) == varEmbedding) { |
| 605 |
return true; |
| 606 |
} else if (varExpEmbeddingHash.contains(varTesting)) { |
| 607 |
return false; |
| 608 |
} |
| 609 |
if (varExpEmbeddingHash.contains(varEmbedding)) { |
| 610 |
return false; |
| 611 |
} |
| 612 |
|
| 613 |
if (answerIndiVariableSet.contains(varTesting)) { |
| 614 |
return false; |
| 615 |
} |
| 616 |
|
| 617 |
if (!anonymousIndiVariableSet.contains(varTesting)) { |
| 618 |
if (anonymousIndiVariableSet.contains(varEmbedding)) { |
| 619 |
return false; |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
QSet<QPair<CObjectPropertyTermExpression*, bool>> testingObjPropExpSet; |
| 624 |
QSet<CClassTermExpression*> testingClassExpSet; |
| 625 |
QList<CObjectPropertyAssertionExpression*> remainingEmbedObjPropList; |
| 626 |
QList<CObjectPropertyAssertionExpression*> availEmbedObjPropList; |
| 627 |
|
| 628 |
CTaxonomy* classHierarchy = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy(); |
| 629 |
CRolePropertiesHierarchy* rolePropertyHierarchy = mOntoAnsweringItem->getOntology()->getClassification()->getObjectPropertyRoleClassification()->getRolePropertiesHierarchy(); |
| 630 |
|
| 631 |
|
| 632 |
for (CAxiomExpression* axExp : varExpAxiomExpHash.values(varTesting)) { |
| 633 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(axExp); |
| 634 |
if (classAssExp) { |
| 635 |
CClassTermExpression* classExp = classAssExp->getClassTermExpression(); |
| 636 |
testingClassExpSet.insert(classExp); |
| 637 |
} else { |
| 638 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(axExp); |
| 639 |
if (propAssExp) { |
| 640 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 641 |
if (varTesting == dynamic_cast<CExpressionVariable*>(propAssExp->getFirstIndividualTermExpression())) { |
| 642 |
testingObjPropExpSet.insert(QPair<CObjectPropertyTermExpression*, bool>(propExp, false)); |
| 643 |
} else { |
| 644 |
testingObjPropExpSet.insert(QPair<CObjectPropertyTermExpression*, bool>(propExp, true)); |
| 645 |
} |
| 646 |
remainingEmbedObjPropList.append(propAssExp); |
| 647 |
} else { |
| 648 |
// TODO: extend to data values/assertions |
| 649 |
return false; |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
if (!testingObjPropExpSet.isEmpty() || !testingClassExpSet.isEmpty()) { |
| 655 |
QSet<QPair<CObjectPropertyTermExpression*, bool>> embeddingObjPropExpSet; |
| 656 |
QSet<CClassTermExpression*> embeddingClassExpSet; |
| 657 |
|
| 658 |
for (CAxiomExpression* axExp : varExpAxiomExpHash.values(varEmbedding)) { |
| 659 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(axExp); |
| 660 |
if (classAssExp) { |
| 661 |
if (!testingClassExpSet.isEmpty()) { |
| 662 |
CClassTermExpression* classExp = classAssExp->getClassTermExpression(); |
| 663 |
embeddingClassExpSet.insert(classExp); |
| 664 |
} |
| 665 |
} else { |
| 666 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(axExp); |
| 667 |
if (propAssExp) { |
| 668 |
if (!testingObjPropExpSet.isEmpty()) { |
| 669 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 670 |
if (varEmbedding == dynamic_cast<CExpressionVariable*>(propAssExp->getFirstIndividualTermExpression())) { |
| 671 |
embeddingObjPropExpSet.insert(QPair<CObjectPropertyTermExpression*, bool>(propExp, false)); |
| 672 |
} else { |
| 673 |
embeddingObjPropExpSet.insert(QPair<CObjectPropertyTermExpression*, bool>(propExp, true)); |
| 674 |
} |
| 675 |
availEmbedObjPropList.append(propAssExp); |
| 676 |
} |
| 677 |
} else { |
| 678 |
// TODO: extend to data values/assertions |
| 679 |
} |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
for (QSet<CClassTermExpression*>::iterator it = testingClassExpSet.begin(), itEnd = testingClassExpSet.end(); it != itEnd; ) { |
| 685 |
CClassTermExpression* testingClassExp = *it; |
| 686 |
if (embeddingClassExpSet.contains(testingClassExp)) { |
| 687 |
it = testingClassExpSet.erase(it); |
| 688 |
} else { |
| 689 |
++it; |
| 690 |
} |
| 691 |
} |
| 692 |
|
| 693 |
for (QSet<QPair<CObjectPropertyTermExpression*, bool>>::iterator it = testingObjPropExpSet.begin(), itEnd = testingObjPropExpSet.end(); it != itEnd; ) { |
| 694 |
QPair<CObjectPropertyTermExpression*, bool> propInvPair = *it; |
| 695 |
CObjectPropertyTermExpression* testingObjPropExp = propInvPair.first; |
| 696 |
bool inversed = propInvPair.second; |
| 697 |
if (embeddingObjPropExpSet.contains(propInvPair)) { |
| 698 |
it = testingObjPropExpSet.erase(it); |
| 699 |
} else { |
| 700 |
++it; |
| 701 |
} |
| 702 |
} |
| 703 |
|
| 704 |
if (!testingClassExpSet.isEmpty()) { |
| 705 |
|
| 706 |
QSet<CHierarchyNode*> embeddingHierNodeSet; |
| 707 |
for (QSet<CClassTermExpression*>::iterator it = embeddingClassExpSet.begin(), itEnd = embeddingClassExpSet.end(); it != itEnd; ++it) { |
| 708 |
CClassTermExpression* classExp = *it; |
| 709 |
if (classHierarchy && dynamic_cast<CClassExpression*>(classExp)) { |
| 710 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(classExp); |
| 711 |
if (concept) { |
| 712 |
CHierarchyNode* hierNode = classHierarchy->getHierarchyNode(concept, false); |
| 713 |
if (hierNode) { |
| 714 |
embeddingHierNodeSet.insert(hierNode); |
| 715 |
for (CHierarchyNode* predHierNode : *hierNode->getPredecessorNodeSet()) { |
| 716 |
embeddingHierNodeSet.insert(predHierNode); |
| 717 |
} |
| 718 |
} |
| 719 |
} |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
for (QSet<CClassTermExpression*>::iterator it = testingClassExpSet.begin(), itEnd = testingClassExpSet.end(); classHierarchy && it != itEnd; ++it) { |
| 725 |
CClassTermExpression* classExp = *it; |
| 726 |
if (!dynamic_cast<CClassExpression*>(classExp)) { |
| 727 |
return false; |
| 728 |
} else { |
| 729 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(classExp); |
| 730 |
if (!concept) { |
| 731 |
return false; |
| 732 |
} else { |
| 733 |
CHierarchyNode* hierNode = classHierarchy->getHierarchyNode(concept, false); |
| 734 |
if (!hierNode) { |
| 735 |
return false; |
| 736 |
} else if (!embeddingHierNodeSet.contains(hierNode)) { |
| 737 |
return false; |
| 738 |
} |
| 739 |
} |
| 740 |
} |
| 741 |
} |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
if (!remainingEmbedObjPropList.isEmpty()) { |
| 749 |
|
| 750 |
|
| 751 |
QHash<CRolePropertiesHierarchyNode*, CObjectPropertyAssertionExpression*> embeddingHierNodeObjectPropAssHash; |
| 752 |
QHash<CRolePropertiesHierarchyNode*, CObjectPropertyAssertionExpression*> embeddingHierNodeInvObjectPropAssHash; |
| 753 |
for (CObjectPropertyAssertionExpression* propAssExp : availEmbedObjPropList) { |
| 754 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 755 |
bool inversed = true; |
| 756 |
if (varEmbedding == dynamic_cast<CExpressionVariable*>(propAssExp->getFirstIndividualTermExpression())) { |
| 757 |
inversed = false; |
| 758 |
} |
| 759 |
|
| 760 |
if (rolePropertyHierarchy) { |
| 761 |
|
| 762 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp); |
| 763 |
if (inversed && role) { |
| 764 |
role = role->getInverseRole(); |
| 765 |
} |
| 766 |
if (role) { |
| 767 |
CRolePropertiesHierarchyNode* hierNode = rolePropertyHierarchy->getHierarchyNode(role); |
| 768 |
if (hierNode) { |
| 769 |
embeddingHierNodeObjectPropAssHash.insertMulti(hierNode, propAssExp); |
| 770 |
for (CRolePropertiesHierarchyNode* predHierNode : *hierNode->getPredecessorNodeSet()) { |
| 771 |
embeddingHierNodeObjectPropAssHash.insertMulti(predHierNode, propAssExp); |
| 772 |
} |
| 773 |
} |
| 774 |
CRolePropertiesHierarchyNode* invHierNode = rolePropertyHierarchy->getHierarchyNode(role->getInverseRole()); |
| 775 |
if (invHierNode) { |
| 776 |
embeddingHierNodeInvObjectPropAssHash.insertMulti(invHierNode, propAssExp); |
| 777 |
for (CRolePropertiesHierarchyNode* predHierNode : *invHierNode->getPredecessorNodeSet()) { |
| 778 |
embeddingHierNodeInvObjectPropAssHash.insertMulti(predHierNode, propAssExp); |
| 779 |
} |
| 780 |
} |
| 781 |
} |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
if (!testingObjPropExpSet.isEmpty()) { |
| 787 |
for (QSet<QPair<CObjectPropertyTermExpression*, bool>>::iterator it = testingObjPropExpSet.begin(), itEnd = testingObjPropExpSet.end(); it != itEnd; ++it) { |
| 788 |
QPair<CObjectPropertyTermExpression*, bool> propInvPair = *it; |
| 789 |
CObjectPropertyTermExpression* testingObjPropExp = propInvPair.first; |
| 790 |
bool inversed = propInvPair.second; |
| 791 |
if (!dynamic_cast<CObjectPropertyExpression*>(testingObjPropExp)) { |
| 792 |
return false; |
| 793 |
} else { |
| 794 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(testingObjPropExp); |
| 795 |
if (inversed && role) { |
| 796 |
role = role->getInverseRole(); |
| 797 |
} |
| 798 |
if (!role) { |
| 799 |
return false; |
| 800 |
} else { |
| 801 |
CRolePropertiesHierarchyNode* hierNode = rolePropertyHierarchy->getHierarchyNode(role); |
| 802 |
if (hierNode) { |
| 803 |
if (!embeddingHierNodeObjectPropAssHash.contains(hierNode)) { |
| 804 |
return false; |
| 805 |
} |
| 806 |
} else { |
| 807 |
CRolePropertiesHierarchyNode* invHierNode = rolePropertyHierarchy->getHierarchyNode(role->getInverseRole()); |
| 808 |
if (invHierNode) { |
| 809 |
if (!embeddingHierNodeInvObjectPropAssHash.contains(invHierNode)) { |
| 810 |
return false; |
| 811 |
} |
| 812 |
} |
| 813 |
} |
| 814 |
} |
| 815 |
} |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
// assume embedding |
| 820 |
QHash<CExpressionVariable*, CExpressionVariable*> newVarExpEmbeddingHash(varExpEmbeddingHash); |
| 821 |
newVarExpEmbeddingHash.insert(varTesting, varEmbedding); |
| 822 |
if (!tryEmbedVariablesObjectPropertyAssertionList(varTesting, varEmbedding, remainingEmbedObjPropList, embeddingHierNodeObjectPropAssHash, embeddingHierNodeInvObjectPropAssHash, newVarExpEmbeddingHash, varExpAxiomExpHash, anonymousIndiVariableSet, answerIndiVariableSet, answererContext)) { |
| 823 |
return false; |
| 824 |
} |
| 825 |
varExpEmbeddingHash = newVarExpEmbeddingHash; |
| 826 |
} |
| 827 |
} |
| 828 |
|
| 829 |
return true; |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
bool COptimizedComplexExpressionAnsweringHandler::tryEmbedVariablesObjectPropertyAssertionList(CExpressionVariable* varTesting, CExpressionVariable* varEmbedding, const QList<CObjectPropertyAssertionExpression*>& remainingEmbedObjPropList, const QHash<CRolePropertiesHierarchyNode*, CObjectPropertyAssertionExpression*>& embeddingHierNodeObjectPropAssHash, const QHash<CRolePropertiesHierarchyNode*, CObjectPropertyAssertionExpression*>& embeddingHierNodeInvObjectPropAssHash, |
| 834 |
QHash<CExpressionVariable*, CExpressionVariable*>& varExpEmbeddingHash, const QHash<CExpressionVariable*, CAxiomExpression*>& varExpAxiomExpHash, const QSet<CExpressionVariable*>& anonymousIndiVariableSet, const QSet<CExpressionVariable*>& answerIndiVariableSet, CAnswererContext* answererContext) { |
| 835 |
|
| 836 |
if (!remainingEmbedObjPropList.isEmpty()) { |
| 837 |
QList<CObjectPropertyAssertionExpression*> embedObjPropList(remainingEmbedObjPropList); |
| 838 |
CRolePropertiesHierarchy* rolePropertyHierarchy = mOntoAnsweringItem->getOntology()->getClassification()->getObjectPropertyRoleClassification()->getRolePropertiesHierarchy(); |
| 839 |
|
| 840 |
CObjectPropertyAssertionExpression* propAssExp = embedObjPropList.takeFirst(); |
| 841 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 842 |
CIndividualTermExpression* otherIndiExp = propAssExp->getFirstIndividualTermExpression(); |
| 843 |
bool inversed = true; |
| 844 |
if (varTesting == dynamic_cast<CExpressionVariable*>(propAssExp->getFirstIndividualTermExpression())) { |
| 845 |
inversed = false; |
| 846 |
otherIndiExp = propAssExp->getSecondIndividualTermExpression(); |
| 847 |
} |
| 848 |
CExpressionVariable* otherVarExp = dynamic_cast<CExpressionVariable*>(otherIndiExp); |
| 849 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp); |
| 850 |
if (inversed && role) { |
| 851 |
role = role->getInverseRole(); |
| 852 |
} |
| 853 |
CRolePropertiesHierarchyNode* hierNode = rolePropertyHierarchy->getHierarchyNode(role); |
| 854 |
QList<CObjectPropertyAssertionExpression*> embeddingPropAssExpList; |
| 855 |
if (hierNode) { |
| 856 |
embeddingPropAssExpList = embeddingHierNodeObjectPropAssHash.values(hierNode); |
| 857 |
} else { |
| 858 |
CRolePropertiesHierarchyNode* invHierNode = rolePropertyHierarchy->getHierarchyNode(role->getInverseRole()); |
| 859 |
if (invHierNode) { |
| 860 |
embeddingPropAssExpList = embeddingHierNodeInvObjectPropAssHash.values(invHierNode); |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
for (CObjectPropertyAssertionExpression* embeddingPropAssExp : embeddingPropAssExpList) { |
| 867 |
CObjectPropertyTermExpression* embeddingObjPropExp = embeddingPropAssExp->getObjectPropertyTermExpression(); |
| 868 |
bool embeddingInversed = true; |
| 869 |
CIndividualTermExpression* embeddingOtherIndiExp = embeddingPropAssExp->getFirstIndividualTermExpression(); |
| 870 |
if (varEmbedding == dynamic_cast<CExpressionVariable*>(embeddingPropAssExp->getFirstIndividualTermExpression())) { |
| 871 |
embeddingInversed = false; |
| 872 |
embeddingOtherIndiExp = embeddingPropAssExp->getSecondIndividualTermExpression(); |
| 873 |
} |
| 874 |
CExpressionVariable* embeddingOtherVarExp = dynamic_cast<CExpressionVariable*>(embeddingOtherIndiExp); |
| 875 |
|
| 876 |
if (embeddingOtherVarExp && otherVarExp) { |
| 877 |
if (embeddingOtherVarExp == otherVarExp && (!varExpEmbeddingHash.contains(embeddingOtherVarExp) || varExpEmbeddingHash.value(embeddingOtherVarExp) == otherVarExp)) { |
| 878 |
QHash<CExpressionVariable*, CExpressionVariable*> newVarExpEmbeddingHash(varExpEmbeddingHash); |
| 879 |
newVarExpEmbeddingHash.insert(embeddingOtherVarExp, otherVarExp); |
| 880 |
if (tryEmbedVariablesObjectPropertyAssertionList(varTesting, varEmbedding, embedObjPropList, embeddingHierNodeObjectPropAssHash, embeddingHierNodeInvObjectPropAssHash, newVarExpEmbeddingHash, varExpAxiomExpHash, anonymousIndiVariableSet, answerIndiVariableSet, answererContext)) { |
| 881 |
varExpEmbeddingHash = newVarExpEmbeddingHash; |
| 882 |
return true; |
| 883 |
} |
| 884 |
} else { |
| 885 |
QHash<CExpressionVariable*, CExpressionVariable*> newVarExpEmbeddingHash(varExpEmbeddingHash); |
| 886 |
if (tryEmbedVariableRestrictions(otherVarExp, embeddingOtherVarExp, newVarExpEmbeddingHash, varExpAxiomExpHash, anonymousIndiVariableSet, answerIndiVariableSet, answererContext)) { |
| 887 |
if (tryEmbedVariablesObjectPropertyAssertionList(varTesting, varEmbedding, embedObjPropList, embeddingHierNodeObjectPropAssHash, embeddingHierNodeInvObjectPropAssHash, newVarExpEmbeddingHash, varExpAxiomExpHash, anonymousIndiVariableSet, answerIndiVariableSet, answererContext)) { |
| 888 |
varExpEmbeddingHash = newVarExpEmbeddingHash; |
| 889 |
return true; |
| 890 |
} |
| 891 |
} |
| 892 |
} |
| 893 |
} else if (otherIndiExp == embeddingOtherIndiExp) { |
| 894 |
if (tryEmbedVariablesObjectPropertyAssertionList(varTesting, varEmbedding, embedObjPropList, embeddingHierNodeObjectPropAssHash, embeddingHierNodeInvObjectPropAssHash, varExpEmbeddingHash, varExpAxiomExpHash, anonymousIndiVariableSet, answerIndiVariableSet, answererContext)) { |
| 895 |
return true; |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
} |
| 900 |
|
| 901 |
} else { |
| 902 |
return true; |
| 903 |
} |
| 904 |
|
| 905 |
return false; |
| 906 |
|
| 907 |
} |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
QList<CExpressionVariable*> COptimizedComplexExpressionAnsweringHandler::getRedundantlyEmbeddedVariables(QHash<CExpressionVariable*, CAxiomExpression*>& varExpAxiomExpHash, const QSet<CExpressionVariable*>& anonymousIndiVariableSet, const QSet<CExpressionVariable*>& answerIndiVariableSet, CComplexQueryExpressionProcessingData* queryProcessingData, CAnswererContext* answererContext) { |
| 913 |
|
| 914 |
CRolePropertiesHierarchy* rolePropertyHierarchy = mOntoAnsweringItem->getOntology()->getClassification()->getObjectPropertyRoleClassification()->getRolePropertiesHierarchy(); |
| 915 |
QHash<CExpressionVariable*, CExpressionVariable*> varExpEmbeddingHash; |
| 916 |
|
| 917 |
QSet<CExpressionVariable*> redundantVariableSet; |
| 918 |
CExpressionVariable* testingVarExp = nullptr; |
| 919 |
QList<TDepthTermPair> propAssExpList; |
| 920 |
for (QHash<CExpressionVariable*, CAxiomExpression*>::iterator it = varExpAxiomExpHash.begin(), itEnd = varExpAxiomExpHash.end(); it != itEnd; ++it) { |
| 921 |
CExpressionVariable* varExp = it.key(); |
| 922 |
if (varExp != testingVarExp) { |
| 923 |
if (testingVarExp && propAssExpList.size() >= 2) { |
| 924 |
|
| 925 |
qSort(propAssExpList.begin(), propAssExpList.end(), itemSortMoreHierachyDepthThan); |
| 926 |
QList<TDepthTermPair>::const_iterator itProp1 = propAssExpList.constBegin(), itPropEnd = propAssExpList.constEnd(); |
| 927 |
while (itProp1 != itPropEnd) { |
| 928 |
TDepthTermPair item1 = *itProp1; |
| 929 |
++itProp1; |
| 930 |
CObjectPropertyAssertionExpression* propAssExp1 = (CObjectPropertyAssertionExpression*)item1.second; |
| 931 |
CObjectPropertyTermExpression* propExp1 = propAssExp1->getObjectPropertyTermExpression(); |
| 932 |
CRole* role1 = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp1); |
| 933 |
CExpressionVariable* otherVarExp1 = dynamic_cast<CExpressionVariable*>(propAssExp1->getSecondIndividualTermExpression()); |
| 934 |
bool inversed1 = false; |
| 935 |
if (testingVarExp == otherVarExp1) { |
| 936 |
inversed1 = true; |
| 937 |
otherVarExp1 = dynamic_cast<CExpressionVariable*>(propAssExp1->getFirstIndividualTermExpression()); |
| 938 |
role1 = role1->getInverseRole(); |
| 939 |
} |
| 940 |
|
| 941 |
if (!varExpEmbeddingHash.contains(otherVarExp1)) { |
| 942 |
CRolePropertiesHierarchyNode* hierNode1 = rolePropertyHierarchy->getHierarchyNode(role1); |
| 943 |
CRolePropertiesHierarchyNode* invHierNode1 = rolePropertyHierarchy->getHierarchyNode(role1->getInverseRole()); |
| 944 |
|
| 945 |
|
| 946 |
QList<TDepthTermPair>::const_iterator itProp2 = propAssExpList.constBegin(); |
| 947 |
while (itProp2 != itPropEnd) { |
| 948 |
|
| 949 |
TDepthTermPair item2 = *itProp2; |
| 950 |
++itProp2; |
| 951 |
CObjectPropertyAssertionExpression* propAssExp2 = (CObjectPropertyAssertionExpression*)item2.second; |
| 952 |
if (propAssExp2 != propAssExp1) { |
| 953 |
CObjectPropertyTermExpression* propExp2 = propAssExp2->getObjectPropertyTermExpression(); |
| 954 |
CRole* role2 = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp2); |
| 955 |
CExpressionVariable* otherVarExp2 = dynamic_cast<CExpressionVariable*>(propAssExp2->getSecondIndividualTermExpression()); |
| 956 |
bool inversed2 = false; |
| 957 |
if (testingVarExp == otherVarExp2) { |
| 958 |
inversed2 = true; |
| 959 |
otherVarExp2 = dynamic_cast<CExpressionVariable*>(propAssExp2->getFirstIndividualTermExpression()); |
| 960 |
role2 = role2->getInverseRole(); |
| 961 |
} |
| 962 |
CRolePropertiesHierarchyNode* hierNode2 = rolePropertyHierarchy->getHierarchyNode(role2); |
| 963 |
CRolePropertiesHierarchyNode* invHierNode2 = rolePropertyHierarchy->getHierarchyNode(role2->getInverseRole()); |
| 964 |
|
| 965 |
|
| 966 |
if (!varExpEmbeddingHash.contains(otherVarExp2)) { |
| 967 |
if (otherVarExp1 != otherVarExp2 && (hierNode1 && hierNode2 && hierNode2->hasPredecessorNode(hierNode1) || invHierNode1 && invHierNode2 && invHierNode2->hasPredecessorNode(invHierNode1))) { |
| 968 |
if (tryEmbedVariableRestrictions(otherVarExp1, otherVarExp2, varExpEmbeddingHash, varExpAxiomExpHash, anonymousIndiVariableSet, answerIndiVariableSet, answererContext)) { |
| 969 |
break; |
| 970 |
} |
| 971 |
} |
| 972 |
} |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
} |
| 977 |
} |
| 978 |
|
| 979 |
} |
| 980 |
|
| 981 |
|
| 982 |
} |
| 983 |
propAssExpList.clear(); |
| 984 |
testingVarExp = varExp; |
| 985 |
} |
| 986 |
CAxiomExpression* axExp = it.value(); |
| 987 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(axExp); |
| 988 |
if (propAssExp) { |
| 989 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 990 |
CExpressionVariable* otherVarExp1 = dynamic_cast<CExpressionVariable*>(propAssExp->getSecondIndividualTermExpression()); |
| 991 |
CExpressionVariable* otherVarExp2 = dynamic_cast<CExpressionVariable*>(propAssExp->getFirstIndividualTermExpression()); |
| 992 |
if (otherVarExp1 && otherVarExp2 && otherVarExp1 != otherVarExp2) { |
| 993 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp); |
| 994 |
if (role && rolePropertyHierarchy) { |
| 995 |
CRolePropertiesHierarchyNode* hierNode = rolePropertyHierarchy->getHierarchyNode(role); |
| 996 |
if (hierNode) { |
| 997 |
propAssExpList.append(TDepthTermPair(hierNode->getPredecessorNodeSet()->count(), propAssExp)); |
| 998 |
} |
| 999 |
} |
| 1000 |
} |
| 1001 |
} |
| 1002 |
} |
| 1003 |
|
| 1004 |
|
| 1005 |
QList<CExpressionVariable*> redEmbVarList; |
| 1006 |
for (QHash<CExpressionVariable*, CExpressionVariable*>::const_iterator it = varExpEmbeddingHash.constBegin(), itEnd = varExpEmbeddingHash.constEnd(); it != itEnd; ++it) { |
| 1007 |
CExpressionVariable* varExp = it.key(); |
| 1008 |
CExpressionVariable* embeddedIntoVarExp = it.value(); |
| 1009 |
if (varExp != embeddedIntoVarExp) { |
| 1010 |
redEmbVarList.append(varExp); |
| 1011 |
} |
| 1012 |
} |
| 1013 |
|
| 1014 |
return redEmbVarList; |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
QList<CAxiomExpression*> COptimizedComplexExpressionAnsweringHandler::eliminateRedundantQueryTerms(const QList<CAxiomExpression*>& assExps, CComplexQueryExpressionProcessingData* queryProcessingData, CAnswererContext* answererContext) { |
| 1022 |
QList<CAxiomExpression*> redElimAssExpList; |
| 1023 |
typedef QPair<CHierarchyNode*, CIndividualTermExpression*> TConceptIndiTermPair; |
| 1024 |
typedef QPair<CRole*, QPair<CIndividualTermExpression*, CIndividualTermExpression* > > TRoleIndiTermsPair; |
| 1025 |
QSet< TConceptIndiTermPair > redundantClassAssertionSet; |
| 1026 |
QSet< TRoleIndiTermsPair > redundantRoleAssertionSet; |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
QList<TDepthTermPair> depthTermAxiomPairList; |
| 1031 |
|
| 1032 |
CTaxonomy* classHierarchy = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy(); |
| 1033 |
CRolePropertiesHierarchy* rolePropertyHierarchy = mOntoAnsweringItem->getOntology()->getClassification()->getObjectPropertyRoleClassification()->getRolePropertiesHierarchy(); |
| 1034 |
|
| 1035 |
for (CAxiomExpression* assExp : assExps) { |
| 1036 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 1037 |
if (classAssExp) { |
| 1038 |
CClassTermExpression* classExp = classAssExp->getClassTermExpression(); |
| 1039 |
bool foundHierNode = false;; |
| 1040 |
if (classHierarchy && dynamic_cast<CClassExpression*>(classExp)) { |
| 1041 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(classExp); |
| 1042 |
if (concept) { |
| 1043 |
CHierarchyNode* hierNode = classHierarchy->getHierarchyNode(concept, false); |
| 1044 |
if (hierNode) { |
| 1045 |
depthTermAxiomPairList.append(TDepthTermPair(hierNode->getPredecessorNodeCount(), classAssExp)); |
| 1046 |
foundHierNode = true; |
| 1047 |
} |
| 1048 |
} |
| 1049 |
} |
| 1050 |
if (!foundHierNode) { |
| 1051 |
redElimAssExpList.append(classAssExp); |
| 1052 |
} |
| 1053 |
|
| 1054 |
} else { |
| 1055 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 1056 |
if (propAssExp) { |
| 1057 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 1058 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp); |
| 1059 |
bool foundHierNode = false; |
| 1060 |
if (role && rolePropertyHierarchy) { |
| 1061 |
CRolePropertiesHierarchyNode* hierNode = rolePropertyHierarchy->getHierarchyNode(role); |
| 1062 |
if (hierNode) { |
| 1063 |
depthTermAxiomPairList.append(TDepthTermPair(hierNode->getPredecessorNodeSet()->count(), propAssExp)); |
| 1064 |
foundHierNode = true; |
| 1065 |
} |
| 1066 |
} |
| 1067 |
if (!foundHierNode) { |
| 1068 |
redElimAssExpList.append(classAssExp); |
| 1069 |
} |
| 1070 |
|
| 1071 |
} else { |
| 1072 |
redElimAssExpList.append(assExp); |
| 1073 |
} |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
qSort(depthTermAxiomPairList.begin(), depthTermAxiomPairList.end(), itemSortMoreHierachyDepthThan); |
| 1078 |
|
| 1079 |
for (TDepthTermPair depthTermPair : depthTermAxiomPairList) { |
| 1080 |
CAxiomExpression* assExp = depthTermPair.second; |
| 1081 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 1082 |
if (classAssExp) { |
| 1083 |
CClassTermExpression* classExp = classAssExp->getClassTermExpression(); |
| 1084 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(classExp); |
| 1085 |
CHierarchyNode* hierNode = classHierarchy->getHierarchyNode(concept, false); |
| 1086 |
if (!redundantClassAssertionSet.contains(TConceptIndiTermPair(hierNode, classAssExp->getIndividualTermExpression()))) { |
| 1087 |
redundantClassAssertionSet.insert(TConceptIndiTermPair(hierNode, classAssExp->getIndividualTermExpression())); |
| 1088 |
redElimAssExpList.append(assExp); |
| 1089 |
for (CHierarchyNode* predHierNode : *hierNode->getPredecessorNodeSet()) { |
| 1090 |
redundantClassAssertionSet.insert(TConceptIndiTermPair(predHierNode, classAssExp->getIndividualTermExpression())); |
| 1091 |
} |
| 1092 |
} |
| 1093 |
} else { |
| 1094 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 1095 |
if (propAssExp) { |
| 1096 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 1097 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp); |
| 1098 |
CRolePropertiesHierarchyNode* hierNode = rolePropertyHierarchy->getHierarchyNode(role); |
| 1099 |
|
| 1100 |
TRoleIndiTermsPair roleIndisPair(hierNode->getOneEquivalentElement(), QPair<CIndividualTermExpression*, CIndividualTermExpression* >(propAssExp->getFirstIndividualTermExpression(), propAssExp->getSecondIndividualTermExpression())); |
| 1101 |
if (!redundantRoleAssertionSet.contains(roleIndisPair)) { |
| 1102 |
redundantRoleAssertionSet.insert(roleIndisPair); |
| 1103 |
CRole* invRole = hierNode->getOneEquivalentElement()->getInverseRole(); |
| 1104 |
if (invRole) { |
| 1105 |
redundantRoleAssertionSet.insert(TRoleIndiTermsPair(invRole, QPair<CIndividualTermExpression*, CIndividualTermExpression* >(propAssExp->getSecondIndividualTermExpression(), propAssExp->getFirstIndividualTermExpression()))); |
| 1106 |
} |
| 1107 |
|
| 1108 |
redElimAssExpList.append(assExp); |
| 1109 |
for (CRolePropertiesHierarchyNode* predHierNode : *hierNode->getPredecessorNodeSet()) { |
| 1110 |
CRole* invPredRole = predHierNode->getOneEquivalentElement()->getInverseRole(); |
| 1111 |
redundantRoleAssertionSet.insert(TRoleIndiTermsPair(predHierNode->getOneEquivalentElement(), QPair<CIndividualTermExpression*, CIndividualTermExpression* >(propAssExp->getFirstIndividualTermExpression(), propAssExp->getSecondIndividualTermExpression()))); |
| 1112 |
if (invPredRole) { |
| 1113 |
redundantRoleAssertionSet.insert(TRoleIndiTermsPair(invPredRole, QPair<CIndividualTermExpression*, CIndividualTermExpression* >(propAssExp->getSecondIndividualTermExpression(), propAssExp->getFirstIndividualTermExpression()))); |
| 1114 |
} |
| 1115 |
} |
| 1116 |
} |
| 1117 |
} |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
|
| 1122 |
return redElimAssExpList; |
| 1123 |
} |
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
COptimizedComplexExpressionAnsweringHandler* COptimizedComplexExpressionAnsweringHandler::initializeQueryProcessing(CComplexQueryExpressionProcessingData* queryProcessingData, CAnswererContext* answererContext) { |
| 1129 |
CComplexAnsweringExpressionQuery* query = queryProcessingData->getQuery(); |
| 1130 |
CConcreteOntology* expOnto = query->getExrpessionOntology(); |
| 1131 |
CConcreteOntology* baseOnto = query->getBaseOntology(); |
| 1132 |
|
| 1133 |
mAnswererContext = answererContext; |
| 1134 |
|
| 1135 |
mOntoAnsweringItem->incCurrentlyAnsweringQueryCount(); |
| 1136 |
|
| 1137 |
bool queryProcessing = false; |
| 1138 |
bool queryCompleted = false; |
| 1139 |
if (!queryProcessingData->isProcessingStarted()) { |
| 1140 |
queryProcessingData->setProcessingStarted(); |
| 1141 |
} |
| 1142 |
|
| 1143 |
CComplexAnsweringExpressionQuery* complAnsQuery = dynamic_cast<CComplexAnsweringExpressionQuery*>(query); |
| 1144 |
if (!checkUsesQueryOnlyKnownEntities(complAnsQuery->getExrpessionOntology())) { |
| 1145 |
if (mConfFailOnUnknownEntity) { |
| 1146 |
failQueryProcessing(queryProcessingData, new CQueryUnknownEntityReferenceError(baseOnto)); |
| 1147 |
queryCompleted = true; |
| 1148 |
} else { |
| 1149 |
finishQueryProcessingAsUnsatisfaible(queryProcessingData); |
| 1150 |
queryCompleted = true; |
| 1151 |
} |
| 1152 |
} else { |
| 1153 |
increaseUsageWeight(); |
| 1154 |
|
| 1155 |
CConcreteOntology* testingOnto = mOntoAnsweringItem->getTestingOntology(); |
| 1156 |
if (testingOnto) { |
| 1157 |
CComplexConceptAnsweringQuery* compConQuery = dynamic_cast<CComplexConceptAnsweringQuery*>(query); |
| 1158 |
if (compConQuery) { |
| 1159 |
CBuildExpression* expOfInt = compConQuery->getExpressionOfInterest(); |
| 1160 |
mTestingOntologyBuilder->initializeBuilding(); |
| 1161 |
CBuildExpression* testingExpOfInt = mTestingOntologyBuilder->rebuildExpression(expOfInt); |
| 1162 |
mTestingOntologyBuilder->completeBuilding(); |
| 1163 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 1164 |
CClassTermExpression* classTermExpOfInt = dynamic_cast<CClassTermExpression*>(testingExpOfInt); |
| 1165 |
if (classTermExpOfInt) { |
| 1166 |
bool instanceComputationRequired = compConQuery->isInstancesComputationRequired(); |
| 1167 |
bool equivalentClassNodesComputationRequired = compConQuery->isEquivalentClassNodesComputationRequired(); |
| 1168 |
bool subClassNodesComputationRequired = compConQuery->isSubClassNodesComputationRequired(); |
| 1169 |
bool superClassNodesComputationRequired = compConQuery->isSuperClassNodesComputationRequired(); |
| 1170 |
bool satisfiableComputationRequired = compConQuery->isSatisfiableComputationRequired(); |
| 1171 |
bool direct = compConQuery->isDirect(); |
| 1172 |
|
| 1173 |
queryProcessing |= initializeComplexConceptQueryProcessing(queryProcessingData, nullptr, classTermExpOfInt, satisfiableComputationRequired, superClassNodesComputationRequired, subClassNodesComputationRequired, equivalentClassNodesComputationRequired, direct, instanceComputationRequired? -1 : 0, nullptr); |
| 1174 |
} |
| 1175 |
} |
| 1176 |
CComplexAxiomsClassVariablesAnsweringQuery* compAxClassVarQuery = dynamic_cast<CComplexAxiomsClassVariablesAnsweringQuery*>(query); |
| 1177 |
if (compAxClassVarQuery) { |
| 1178 |
initComplexAxiomsClassVariablesQuery(compAxClassVarQuery, answererContext, queryProcessingData, queryCompleted, testingOnto, queryProcessing); |
| 1179 |
} |
| 1180 |
CComplexAxiomsObjectPropertyVariablesAnsweringQuery* compAxPropVarQuery = dynamic_cast<CComplexAxiomsObjectPropertyVariablesAnsweringQuery*>(query); |
| 1181 |
if (compAxPropVarQuery) { |
| 1182 |
initComplexAxiomsObjectPropertyVariablesQuery(compAxPropVarQuery, answererContext, queryProcessingData, queryCompleted, testingOnto, queryProcessing); |
| 1183 |
} |
| 1184 |
CComplexAxiomsDataPropertyVariablesAnsweringQuery* compAxDataVarQuery = dynamic_cast<CComplexAxiomsDataPropertyVariablesAnsweringQuery*>(query); |
| 1185 |
if (compAxDataVarQuery) { |
| 1186 |
initComplexAxiomsDataPropertyVariablesQuery(compAxDataVarQuery, answererContext, queryProcessingData, queryCompleted, testingOnto, queryProcessing); |
| 1187 |
} |
| 1188 |
CComplexAssertionsIndividualVariablesAnsweringQuery* compAssIndVarQuery = dynamic_cast<CComplexAssertionsIndividualVariablesAnsweringQuery*>(query); |
| 1189 |
if (compAssIndVarQuery) { |
| 1190 |
initComplexAssertionsIndividualVariablesQuery(compAssIndVarQuery, answererContext, queryProcessingData, queryCompleted, testingOnto, queryProcessing); |
| 1191 |
} |
| 1192 |
CComplexAxiomsIndividualMixedVariablesAnsweringQuery* compAxIndMixedVarQuery = dynamic_cast<CComplexAxiomsIndividualMixedVariablesAnsweringQuery*>(query); |
| 1193 |
if (compAxIndMixedVarQuery) { |
| 1194 |
initComplexAxiomsIndividualMixedVariablesQuery(compAxIndMixedVarQuery, answererContext, queryProcessingData, queryCompleted, testingOnto, queryProcessing); |
| 1195 |
} |
| 1196 |
} |
| 1197 |
} |
| 1198 |
|
| 1199 |
if (!queryCompleted && !queryProcessing) { |
| 1200 |
finishQueryProcessing(queryProcessingData); |
| 1201 |
} |
| 1202 |
|
| 1203 |
return this; |
| 1204 |
} |
| 1205 |
|
| 1206 |
CRole* COptimizedComplexExpressionAnsweringHandler::getResolvedDataPropertyRole(CDataPropertyTermExpression* exp) { |
| 1207 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getDataPropertyTermRoleMappingHash()->value(exp); |
| 1208 |
return role; |
| 1209 |
} |
| 1210 |
|
| 1211 |
CRole* COptimizedComplexExpressionAnsweringHandler::getInverseResolvedObjectPropertyRole(CObjectPropertyTermExpression* exp) { |
| 1212 |
bool inversed = false; |
| 1213 |
exp = getInverseResolvedObjectPropertyTermExpression(exp, inversed); |
| 1214 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(exp); |
| 1215 |
if (inversed) { |
| 1216 |
role = role->getInverseRole(); |
| 1217 |
} |
| 1218 |
return role; |
| 1219 |
} |
| 1220 |
|
| 1221 |
CObjectPropertyTermExpression* COptimizedComplexExpressionAnsweringHandler::getInverseResolvedObjectPropertyTermExpression(CObjectPropertyTermExpression* exp, bool& inversed) { |
| 1222 |
inversed = false; |
| 1223 |
while (dynamic_cast<CInverseObjectPropertyOfExpression*>(exp)) { |
| 1224 |
CInverseObjectPropertyOfExpression* invObjPropEx = dynamic_cast<CInverseObjectPropertyOfExpression*>(exp); |
| 1225 |
exp = invObjPropEx->getInverseOfExpression(); |
| 1226 |
inversed = !inversed; |
| 1227 |
} |
| 1228 |
return exp; |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
void COptimizedComplexExpressionAnsweringHandler::initComplexAxiomsDataPropertyVariablesQuery(CComplexAxiomsDataPropertyVariablesAnsweringQuery* compAxPropVarQuery, CAnswererContext* answererContext, CComplexQueryExpressionProcessingData* queryProcessingData, bool &queryCompleted, CConcreteOntology* testingOnto, bool &queryProcessing) { |
| 1236 |
QList<CAxiomExpression*> assExps = *compAxPropVarQuery->getAxiomExpressions(); |
| 1237 |
|
| 1238 |
QList<CSubDataPropertyOfExpression*> dataPropSubAxiomExpsEntList; |
| 1239 |
CExpressionVariable* lastVarExpression = nullptr; |
| 1240 |
QSet<CExpressionVariable*> varExpSet; |
| 1241 |
bool unsupportedWarning = false; |
| 1242 |
|
| 1243 |
|
| 1244 |
QHash<CExpressionVariable*, CDataPropertyTermExpression*> varSuperDataPropRestrictionExpHash; |
| 1245 |
QHash<CExpressionVariable*, CDataPropertyTermExpression*> varSubDataPropRestrictionExpHash; |
| 1246 |
QHash<CExpressionVariable*, CExpressionVariable*> varSubVarSuperRestHash; |
| 1247 |
|
| 1248 |
|
| 1249 |
for (CAxiomExpression* assExp : assExps) { |
| 1250 |
bool supported = false; |
| 1251 |
CSubDataPropertyOfExpression* subDataPropOfAssExp = dynamic_cast<CSubDataPropertyOfExpression*>(assExp); |
| 1252 |
if (subDataPropOfAssExp) { |
| 1253 |
supported = true; |
| 1254 |
bool hasVariable = false; |
| 1255 |
CDataPropertyVariableExpression* subDataPropVarExp = dynamic_cast<CDataPropertyVariableExpression*>(subDataPropOfAssExp->getSubDataPropertyTermExpression()); |
| 1256 |
if (subDataPropVarExp) { |
| 1257 |
hasVariable = true; |
| 1258 |
lastVarExpression = subDataPropVarExp; |
| 1259 |
varExpSet.insert(subDataPropVarExp); |
| 1260 |
} |
| 1261 |
CObjectPropertyVariableExpression* superDataPropVarExp = dynamic_cast<CObjectPropertyVariableExpression*>(subDataPropOfAssExp->getSuperDataPropertyTermExpression()); |
| 1262 |
if (superDataPropVarExp) { |
| 1263 |
hasVariable = true; |
| 1264 |
lastVarExpression = superDataPropVarExp; |
| 1265 |
varExpSet.insert(superDataPropVarExp); |
| 1266 |
} |
| 1267 |
|
| 1268 |
if (subDataPropVarExp && !superDataPropVarExp) { |
| 1269 |
varSuperDataPropRestrictionExpHash.insertMulti(subDataPropVarExp, subDataPropOfAssExp->getSuperDataPropertyTermExpression()); |
| 1270 |
} else if (!subDataPropVarExp && superDataPropVarExp) { |
| 1271 |
varSubDataPropRestrictionExpHash.insertMulti(superDataPropVarExp, subDataPropOfAssExp->getSubDataPropertyTermExpression()); |
| 1272 |
} else if (subDataPropVarExp && superDataPropVarExp) { |
| 1273 |
varSubVarSuperRestHash.insertMulti(subDataPropVarExp, superDataPropVarExp); |
| 1274 |
} |
| 1275 |
|
| 1276 |
if (!hasVariable) { |
| 1277 |
dataPropSubAxiomExpsEntList.append(subDataPropOfAssExp); |
| 1278 |
} |
| 1279 |
} |
| 1280 |
|
| 1281 |
if (!supported) { |
| 1282 |
if (!unsupportedWarning) { |
| 1283 |
LOG(WARN, getDomain(), logTr("Query uses unsupported axiom types, which will be ignored."), this); |
| 1284 |
} |
| 1285 |
unsupportedWarning = true; |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
if (!dataPropSubAxiomExpsEntList.isEmpty()) { |
| 1290 |
for (CSubDataPropertyOfExpression* subDataPropOfAssExp : dataPropSubAxiomExpsEntList) { |
| 1291 |
CRole* subRole = getResolvedDataPropertyRole(subDataPropOfAssExp->getSubDataPropertyTermExpression()); |
| 1292 |
CRole* superRole = getResolvedDataPropertyRole(subDataPropOfAssExp->getSuperDataPropertyTermExpression()); |
| 1293 |
queryProcessing |= checkEntailmentRoleSubDataPropertyAxiom(subRole, superRole, queryProcessingData, answererContext); |
| 1294 |
} |
| 1295 |
} |
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
COptimizedComplexBuildingObjectPropertyVariableCompositionsItem* varBuildItem = new COptimizedComplexBuildingObjectPropertyVariableCompositionsItem(queryProcessingData); |
| 1301 |
|
| 1302 |
|
| 1303 |
for (CExpressionVariable* varExp : varExpSet) { |
| 1304 |
QList<CDataPropertyTermExpression*> superDataPropRestrictionExps = varSuperDataPropRestrictionExpHash.values(varExp); |
| 1305 |
QList<CDataPropertyTermExpression*> subDataPropRestrictionExps = varSubDataPropRestrictionExpHash.values(varExp); |
| 1306 |
|
| 1307 |
|
| 1308 |
for (CDataPropertyTermExpression* superDataPropRestrictionExp : superDataPropRestrictionExps) { |
| 1309 |
CRole* superRole = getResolvedDataPropertyRole(superDataPropRestrictionExp); |
| 1310 |
varBuildItem->addVariableComplexSuperRole((CPropertyVariableExpression*)varExp, superRole); |
| 1311 |
} |
| 1312 |
|
| 1313 |
for (CDataPropertyTermExpression* subDataPropRestrictionExp : subDataPropRestrictionExps) { |
| 1314 |
CRole* subrRole = getResolvedDataPropertyRole(subDataPropRestrictionExp); |
| 1315 |
varBuildItem->addVariableComplexSubRole((CPropertyVariableExpression*)varExp, subrRole); |
| 1316 |
} |
| 1317 |
|
| 1318 |
QList<CExpressionVariable*> superVarList = varSubVarSuperRestHash.values(varExp); |
| 1319 |
for (CExpressionVariable* superVarExp : superVarList) { |
| 1320 |
varBuildItem->addVariableSubSuperPropagation(varExp, superVarExp); |
| 1321 |
} |
| 1322 |
|
| 1323 |
} |
| 1324 |
|
| 1325 |
queryProcessingData->setVariableBuildingItem(varBuildItem); |
| 1326 |
queryProcessingData->incBuildingVariableItem(); |
| 1327 |
|
| 1328 |
if (!queryProcessing) { |
| 1329 |
varBuildItem->setProcessingQueued(true); |
| 1330 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(varBuildItem); |
| 1331 |
queryProcessing = true; |
| 1332 |
} |
| 1333 |
|
| 1334 |
} |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
COptimizedComplexBuildingObjectPropertyVariableCompositionsItem* COptimizedComplexExpressionAnsweringHandler::initComplexAxiomsObjectPropertyVariablesQuery(CComplexAxiomsObjectPropertyVariablesAnsweringQuery* compAxPropVarQuery, CAnswererContext* answererContext, CComplexQueryExpressionProcessingData* queryProcessingData, bool &queryCompleted, CConcreteOntology* testingOnto, bool &queryProcessing) { |
| 1341 |
QList<CAxiomExpression*> assExps = *compAxPropVarQuery->getAxiomExpressions(); |
| 1342 |
|
| 1343 |
QList<CSubObjectPropertyOfExpression*> objectPropSubAxiomExpsEntList; |
| 1344 |
CExpressionVariable* lastVarExpression = nullptr; |
| 1345 |
QSet<CExpressionVariable*> varExpSet; |
| 1346 |
bool unsupportedWarning = false; |
| 1347 |
|
| 1348 |
|
| 1349 |
QHash<CExpressionVariable*, CObjectPropertyTermExpression*> varSuperObjPropRestrictionExpHash; |
| 1350 |
QHash<CExpressionVariable*, CObjectPropertyTermExpression*> varSubObjPropRestrictionExpHash; |
| 1351 |
QHash<CExpressionVariable*, CExpressionVariable*> varSubVarSuperRestHash; |
| 1352 |
|
| 1353 |
|
| 1354 |
for (CAxiomExpression* assExp : assExps) { |
| 1355 |
bool supported = false; |
| 1356 |
CSubObjectPropertyOfExpression* subObjPropOfAssExp = dynamic_cast<CSubObjectPropertyOfExpression*>(assExp); |
| 1357 |
if (subObjPropOfAssExp) { |
| 1358 |
bool hasVariable = false; |
| 1359 |
CEXPRESSIONLIST<CObjectPropertyTermExpression*>* subObjPropList = subObjPropOfAssExp->getSubObjectPropertyTermExpressionList(); |
| 1360 |
if (subObjPropList->size() == 1) { |
| 1361 |
supported = true; |
| 1362 |
CObjectPropertyVariableExpression* subObjPropVarExp = dynamic_cast<CObjectPropertyVariableExpression*>(subObjPropList->first()); |
| 1363 |
if (subObjPropVarExp) { |
| 1364 |
hasVariable = true; |
| 1365 |
lastVarExpression = subObjPropVarExp; |
| 1366 |
varExpSet.insert(subObjPropVarExp); |
| 1367 |
} |
| 1368 |
CObjectPropertyVariableExpression* superObjPropVarExp = dynamic_cast<CObjectPropertyVariableExpression*>(subObjPropOfAssExp->getSuperObjectPropertyTermExpression()); |
| 1369 |
if (superObjPropVarExp) { |
| 1370 |
hasVariable = true; |
| 1371 |
lastVarExpression = superObjPropVarExp; |
| 1372 |
varExpSet.insert(superObjPropVarExp); |
| 1373 |
} |
| 1374 |
|
| 1375 |
if (subObjPropVarExp && !superObjPropVarExp) { |
| 1376 |
varSuperObjPropRestrictionExpHash.insertMulti(subObjPropVarExp, subObjPropOfAssExp->getSuperObjectPropertyTermExpression()); |
| 1377 |
} else if (!subObjPropVarExp && superObjPropVarExp) { |
| 1378 |
varSubObjPropRestrictionExpHash.insertMulti(superObjPropVarExp, subObjPropOfAssExp->getSubObjectPropertyTermExpressionList()->first()); |
| 1379 |
} else if (subObjPropVarExp && superObjPropVarExp) { |
| 1380 |
varSubVarSuperRestHash.insertMulti(subObjPropVarExp, superObjPropVarExp); |
| 1381 |
} |
| 1382 |
|
| 1383 |
if (!hasVariable) { |
| 1384 |
objectPropSubAxiomExpsEntList.append(subObjPropOfAssExp); |
| 1385 |
} |
| 1386 |
} |
| 1387 |
} |
| 1388 |
|
| 1389 |
if (!supported) { |
| 1390 |
if (!unsupportedWarning) { |
| 1391 |
LOG(WARN, getDomain(), logTr("Query uses unsupported axiom types, which will be ignored."), this); |
| 1392 |
} |
| 1393 |
unsupportedWarning = true; |
| 1394 |
} |
| 1395 |
} |
| 1396 |
|
| 1397 |
if (!objectPropSubAxiomExpsEntList.isEmpty()) { |
| 1398 |
for (CSubObjectPropertyOfExpression* subObjPropOfAssExp : objectPropSubAxiomExpsEntList) { |
| 1399 |
CRole* subRole = getInverseResolvedObjectPropertyRole(subObjPropOfAssExp->getSubObjectPropertyTermExpressionList()->first()); |
| 1400 |
CRole* superRole = getInverseResolvedObjectPropertyRole(subObjPropOfAssExp->getSuperObjectPropertyTermExpression()); |
| 1401 |
queryProcessing |= checkEntailmentRoleSubObjectPropertyAxiom(subRole, superRole, queryProcessingData, answererContext); |
| 1402 |
} |
| 1403 |
} |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
COptimizedComplexBuildingObjectPropertyVariableCompositionsItem* varBuildItem = new COptimizedComplexBuildingObjectPropertyVariableCompositionsItem(queryProcessingData); |
| 1409 |
|
| 1410 |
|
| 1411 |
for (CExpressionVariable* varExp : varExpSet) { |
| 1412 |
QList<CObjectPropertyTermExpression*> superObjPropRestrictionExps = varSuperObjPropRestrictionExpHash.values(varExp); |
| 1413 |
QList<CObjectPropertyTermExpression*> subObjPropRestrictionExps = varSubObjPropRestrictionExpHash.values(varExp); |
| 1414 |
|
| 1415 |
|
| 1416 |
for (CObjectPropertyTermExpression* superObjPropRestrictionExp : superObjPropRestrictionExps) { |
| 1417 |
CRole* superRole = getInverseResolvedObjectPropertyRole(superObjPropRestrictionExp); |
| 1418 |
varBuildItem->addVariableComplexSuperRole((CPropertyVariableExpression*)varExp, superRole); |
| 1419 |
} |
| 1420 |
|
| 1421 |
for (CObjectPropertyTermExpression* subObjPropRestrictionExp : subObjPropRestrictionExps) { |
| 1422 |
CRole* subrRole = getInverseResolvedObjectPropertyRole(subObjPropRestrictionExp); |
| 1423 |
varBuildItem->addVariableComplexSubRole((CPropertyVariableExpression*)varExp, subrRole); |
| 1424 |
} |
| 1425 |
|
| 1426 |
QList<CExpressionVariable*> superVarList = varSubVarSuperRestHash.values(varExp); |
| 1427 |
for (CExpressionVariable* superVarExp : superVarList) { |
| 1428 |
varBuildItem->addVariableSubSuperPropagation(varExp, superVarExp); |
| 1429 |
} |
| 1430 |
|
| 1431 |
} |
| 1432 |
|
| 1433 |
queryProcessingData->setVariableBuildingItem(varBuildItem); |
| 1434 |
queryProcessingData->incBuildingVariableItem(); |
| 1435 |
|
| 1436 |
if (!queryProcessing) { |
| 1437 |
varBuildItem->setProcessingQueued(true); |
| 1438 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(varBuildItem); |
| 1439 |
queryProcessing = true; |
| 1440 |
} |
| 1441 |
return varBuildItem; |
| 1442 |
|
| 1443 |
} |
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
COptimizedComplexBuildingClassVariableCompositionsItem* COptimizedComplexExpressionAnsweringHandler::initComplexAxiomsClassVariablesQuery(CComplexAxiomsClassVariablesAnsweringQuery* compAxClassVarQuery, CAnswererContext* answererContext, CComplexQueryExpressionProcessingData* queryProcessingData, bool &queryCompleted, CConcreteOntology* testingOnto, bool &queryProcessing) { |
| 1448 |
QList<CAxiomExpression*> assExps = *compAxClassVarQuery->getAxiomExpressions(); |
| 1449 |
|
| 1450 |
QList<CAxiomExpression*> assExpsVarList; |
| 1451 |
QList<CSubClassOfExpression*> classSubClassExpsEntList; |
| 1452 |
CExpressionVariable* lastVarExpression = nullptr; |
| 1453 |
QSet<CExpressionVariable*> varExpSet; |
| 1454 |
bool unsupportedWarning = false; |
| 1455 |
|
| 1456 |
for (CAxiomExpression* assExp : assExps) { |
| 1457 |
CSubClassOfExpression* subClasOfAssExp = dynamic_cast<CSubClassOfExpression*>(assExp); |
| 1458 |
if (subClasOfAssExp) { |
| 1459 |
bool hasVariable = false; |
| 1460 |
CClassVariableExpression* subClassVarExp = dynamic_cast<CClassVariableExpression*>(subClasOfAssExp->getFirstClassTermExpression()); |
| 1461 |
if (subClassVarExp) { |
| 1462 |
hasVariable = true; |
| 1463 |
lastVarExpression = subClassVarExp; |
| 1464 |
varExpSet.insert(subClassVarExp); |
| 1465 |
} |
| 1466 |
CClassVariableExpression* superClassVarExp = dynamic_cast<CClassVariableExpression*>(subClasOfAssExp->getSecondClassTermExpression()); |
| 1467 |
if (superClassVarExp) { |
| 1468 |
hasVariable = true; |
| 1469 |
lastVarExpression = superClassVarExp; |
| 1470 |
varExpSet.insert(superClassVarExp); |
| 1471 |
} |
| 1472 |
if (!hasVariable) { |
| 1473 |
classSubClassExpsEntList.append(subClasOfAssExp); |
| 1474 |
} else { |
| 1475 |
assExpsVarList.append(subClasOfAssExp); |
| 1476 |
} |
| 1477 |
} else { |
| 1478 |
if (!unsupportedWarning) { |
| 1479 |
LOG(WARN, getDomain(), logTr("Query uses unsupported axiom types, which will be ignored."), this); |
| 1480 |
} |
| 1481 |
unsupportedWarning = true; |
| 1482 |
} |
| 1483 |
} |
| 1484 |
|
| 1485 |
if (!classSubClassExpsEntList.isEmpty()) { |
| 1486 |
QList<QPair<CClassTermExpression*, CClassTermExpression*>> subSuperClassTestExpList; |
| 1487 |
if (!classSubClassExpsEntList.isEmpty()) { |
| 1488 |
mTestingOntologyBuilder->initializeBuilding(); |
| 1489 |
for (CSubClassOfExpression* subClasOfAssExp : classSubClassExpsEntList) { |
| 1490 |
CClassTermExpression* subClassTermExp = subClasOfAssExp->getFirstClassTermExpression(); |
| 1491 |
CClassTermExpression* superClassTermExp = subClasOfAssExp->getSecondClassTermExpression(); |
| 1492 |
subSuperClassTestExpList.append(QPair<CClassTermExpression*, CClassTermExpression*>((CClassTermExpression*)mTestingOntologyBuilder->rebuildExpression(subClassTermExp), (CClassTermExpression*)mTestingOntologyBuilder->rebuildExpression(superClassTermExp))); |
| 1493 |
} |
| 1494 |
|
| 1495 |
mTestingOntologyBuilder->completeBuilding(); |
| 1496 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 1497 |
} |
| 1498 |
|
| 1499 |
for (QPair<CClassTermExpression*, CClassTermExpression*> classIndiPair : subSuperClassTestExpList) { |
| 1500 |
CClassTermExpression* subClassTermExp = classIndiPair.first; |
| 1501 |
CClassTermExpression* superClassTermExp = classIndiPair.second; |
| 1502 |
CConcept* subConcept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(subClassTermExp); |
| 1503 |
CConcept* superConcept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(superClassTermExp); |
| 1504 |
bool subConNegation = subConcept->hasMappingNegation(); |
| 1505 |
bool superConNegation = superConcept->hasMappingNegation(); |
| 1506 |
queryProcessing |= checkEntailmentConceptSubClassAxiom(subConcept, subConNegation, superConcept, superConNegation, queryProcessingData, answererContext); |
| 1507 |
} |
| 1508 |
|
| 1509 |
} |
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
QHash<CExpressionVariable*, CBuildExpression*> varSuperClassRestrictionExpHash; |
| 1514 |
QHash<CExpressionVariable*, CBuildExpression*> varSubClassRestrictionExpHash; |
| 1515 |
QHash<CExpressionVariable*, CExpressionVariable*> varSubVarSuperRestHash; |
| 1516 |
for (CExpressionVariable* varExp : varExpSet) { |
| 1517 |
for (CAxiomExpression* assExp : assExpsVarList) { |
| 1518 |
CSubClassOfExpression* subClasOfAssExp = dynamic_cast<CSubClassOfExpression*>(assExp); |
| 1519 |
if (subClasOfAssExp) { |
| 1520 |
CClassVariableExpression* subClassVarExp = dynamic_cast<CClassVariableExpression*>(subClasOfAssExp->getFirstClassTermExpression()); |
| 1521 |
CClassVariableExpression* superClassVarExp = dynamic_cast<CClassVariableExpression*>(subClasOfAssExp->getSecondClassTermExpression()); |
| 1522 |
if (subClassVarExp && !superClassVarExp) { |
| 1523 |
varSuperClassRestrictionExpHash.insertMulti(subClassVarExp, subClasOfAssExp->getSecondClassTermExpression()); |
| 1524 |
} |
| 1525 |
if (!subClassVarExp && superClassVarExp) { |
| 1526 |
varSubClassRestrictionExpHash.insertMulti(superClassVarExp, subClasOfAssExp->getFirstClassTermExpression()); |
| 1527 |
} |
| 1528 |
if (varExp == subClassVarExp && subClassVarExp && superClassVarExp) { |
| 1529 |
varSubVarSuperRestHash.insertMulti(subClassVarExp, superClassVarExp); |
| 1530 |
} |
| 1531 |
} |
| 1532 |
} |
| 1533 |
} |
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
mTestingOntologyBuilder->initializeBuilding(); |
| 1540 |
for (CExpressionVariable* varExp : varExpSet) { |
| 1541 |
QList<CBuildExpression*> superClassRestrictionExps = varSuperClassRestrictionExpHash.values(varExp); |
| 1542 |
QList<CBuildExpression*> subClassRestrictionExps = varSubClassRestrictionExpHash.values(varExp); |
| 1543 |
|
| 1544 |
if (!superClassRestrictionExps.isEmpty()) { |
| 1545 |
QList<CBuildExpression*> instTestingExpList; |
| 1546 |
|
| 1547 |
CBuildExpression* instTestingExp = nullptr; |
| 1548 |
for (CBuildExpression* superClassExp : superClassRestrictionExps) { |
| 1549 |
instTestingExpList.append(mTestingOntologyBuilder->rebuildExpression(superClassExp)); |
| 1550 |
} |
| 1551 |
|
| 1552 |
if (instTestingExpList.size() > 1) { |
| 1553 |
instTestingExp = mTestingOntologyBuilder->getObjectIntersectionOf(instTestingExpList); |
| 1554 |
varSuperClassRestrictionExpHash.insert(varExp, instTestingExp); |
| 1555 |
} |
| 1556 |
} |
| 1557 |
|
| 1558 |
if (!subClassRestrictionExps.isEmpty()) { |
| 1559 |
QList<CBuildExpression*> instTestingExpList; |
| 1560 |
|
| 1561 |
CBuildExpression* instTestingExp = nullptr; |
| 1562 |
for (CBuildExpression* subClassExp : subClassRestrictionExps) { |
| 1563 |
instTestingExpList.append(mTestingOntologyBuilder->rebuildExpression(subClassExp)); |
| 1564 |
} |
| 1565 |
|
| 1566 |
if (instTestingExpList.size() > 1) { |
| 1567 |
instTestingExp = mTestingOntologyBuilder->getObjectIntersectionOf(instTestingExpList); |
| 1568 |
varSubClassRestrictionExpHash.insert(varExp, instTestingExp); |
| 1569 |
} |
| 1570 |
} |
| 1571 |
} |
| 1572 |
|
| 1573 |
mTestingOntologyBuilder->completeBuilding(); |
| 1574 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 1575 |
|
| 1576 |
COptimizedComplexBuildingClassVariableCompositionsItem* varBuildItem = new COptimizedComplexBuildingClassVariableCompositionsItem(queryProcessingData); |
| 1577 |
|
| 1578 |
|
| 1579 |
for (CExpressionVariable* varExp : varExpSet) { |
| 1580 |
CBuildExpression* superClassRestrictionExp = varSuperClassRestrictionExpHash.value(varExp); |
| 1581 |
CBuildExpression* subClassRestrictionExp = varSubClassRestrictionExpHash.value(varExp); |
| 1582 |
|
| 1583 |
if (superClassRestrictionExp) { |
| 1584 |
CConcept* superResConcept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value((CClassTermExpression*)superClassRestrictionExp); |
| 1585 |
bool superResConceptNegation = superResConcept->hasMappingNegation(); |
| 1586 |
|
| 1587 |
COptimizedComplexConceptItem* assocConceptItem = nullptr; |
| 1588 |
queryProcessing |= initializeComplexConceptQueryProcessing(nullptr, varBuildItem, superResConcept, superResConceptNegation, false, false, true, false, false, 0, &assocConceptItem); |
| 1589 |
|
| 1590 |
varBuildItem->addVariableComplexSuperConceptItem((CClassVariableExpression*)varExp, assocConceptItem); |
| 1591 |
} |
| 1592 |
|
| 1593 |
if (subClassRestrictionExp) { |
| 1594 |
CConcept* subResConcept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value((CClassTermExpression*)subClassRestrictionExp); |
| 1595 |
bool subResConceptNegation = subResConcept->hasMappingNegation(); |
| 1596 |
|
| 1597 |
COptimizedComplexConceptItem* assocConceptItem = nullptr; |
| 1598 |
queryProcessing |= initializeComplexConceptQueryProcessing(nullptr, varBuildItem, subResConcept, subResConceptNegation, false, true, false, false, false, 0, &assocConceptItem); |
| 1599 |
|
| 1600 |
varBuildItem->addVariableComplexSubConceptItem((CClassVariableExpression*)varExp, assocConceptItem); |
| 1601 |
} |
| 1602 |
|
| 1603 |
QList<CExpressionVariable*> superVarList = varSubVarSuperRestHash.values(varExp); |
| 1604 |
for (CExpressionVariable* superVarExp : superVarList) { |
| 1605 |
varBuildItem->addVariableSubSuperPropagation(varExp, superVarExp); |
| 1606 |
} |
| 1607 |
|
| 1608 |
} |
| 1609 |
|
| 1610 |
queryProcessingData->setVariableBuildingItem(varBuildItem); |
| 1611 |
queryProcessingData->incBuildingVariableItem(); |
| 1612 |
|
| 1613 |
if (!queryProcessing) { |
| 1614 |
varBuildItem->setProcessingQueued(true); |
| 1615 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(varBuildItem); |
| 1616 |
queryProcessing = true; |
| 1617 |
} |
| 1618 |
|
| 1619 |
return varBuildItem; |
| 1620 |
|
| 1621 |
} |
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
COptimizedComplexBuildingIndividualMixedVariableCompositionsItem* COptimizedComplexExpressionAnsweringHandler::initComplexAxiomsIndividualMixedVariablesQuery(CComplexAxiomsIndividualMixedVariablesAnsweringQuery* compAxIndMixedVarQuery, CAnswererContext* answererContext, CComplexQueryExpressionProcessingData* queryProcessingData, bool &queryCompleted, CConcreteOntology* testingOnto, bool &queryProcessing) { |
| 1628 |
QList<CAxiomExpression*> axExps = *compAxIndMixedVarQuery->getAxiomExpressions(); |
| 1629 |
QList<CExpressionVariable*>* disVarList = compAxIndMixedVarQuery->getDistinguishedVariableExpressions(); |
| 1630 |
QSet<CExpressionVariable*> disVarSet = disVarList->toSet(); |
| 1631 |
|
| 1632 |
COptimizedComplexBuildingIndividualMixedVariableCompositionsItem* varBuildItem = new COptimizedComplexBuildingIndividualMixedVariableCompositionsItem(queryProcessingData); |
| 1633 |
|
| 1634 |
bool unsupportedWarning = false; |
| 1635 |
|
| 1636 |
QList<CAxiomExpression*> propExtSubQueryPropAssList; |
| 1637 |
QList<CAxiomExpression*> subQueryIndiAssExps; |
| 1638 |
QList<CAxiomExpression*> subQueryClassAxExps; |
| 1639 |
QList<CAxiomExpression*> subQueryDisjClassAxExps; |
| 1640 |
QSet<CExpressionVariable*> extensionIndiVarExpSet; |
| 1641 |
QSet<CExpressionVariable*> extensionClassVarExpSet; |
| 1642 |
QSet<CExpressionVariable*> extensionPropertyVarExpSet; |
| 1643 |
QSet<CExpressionVariable*> subQueryIndiVarExpSet; |
| 1644 |
QHash<CExpressionVariable*,cint64> varExpOccurenceCountHash; |
| 1645 |
QList<CObjectPropertyAssertionExpression*> propExtSingleOccCheckingPropAssList; |
| 1646 |
for (CAxiomExpression* assExp : axExps) { |
| 1647 |
bool supported = false; |
| 1648 |
bool assertionAxiom = false; |
| 1649 |
|
| 1650 |
CSubClassOfExpression* subClassAxExp = dynamic_cast<CSubClassOfExpression*>(assExp); |
| 1651 |
if (subClassAxExp) { |
| 1652 |
supported = true; |
| 1653 |
subQueryClassAxExps.append(subClassAxExp); |
| 1654 |
} |
| 1655 |
//CEquivalentClassesExpression* eqClassAxExp = dynamic_cast<CEquivalentClassesExpression*>(assExp); |
| 1656 |
//if (eqClassAxExp) { |
| 1657 |
// supported = true; |
| 1658 |
// subQueryClassAxExps.append(eqClassAxExp); |
| 1659 |
//} |
| 1660 |
|
| 1661 |
|
| 1662 |
CSubObjectPropertyOfExpression* subPropAxExp = dynamic_cast<CSubObjectPropertyOfExpression*>(assExp); |
| 1663 |
if (subPropAxExp) { |
| 1664 |
|
| 1665 |
CEXPRESSIONLIST<CObjectPropertyTermExpression*>* subObjPropList = subPropAxExp->getSubObjectPropertyTermExpressionList(); |
| 1666 |
if (subObjPropList->size() == 1) { |
| 1667 |
supported = true; |
| 1668 |
propExtSubQueryPropAssList.append(subPropAxExp); |
| 1669 |
} |
| 1670 |
} |
| 1671 |
|
| 1672 |
|
| 1673 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 1674 |
if (classAssExp) { |
| 1675 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(classAssExp->getIndividualTermExpression()); |
| 1676 |
CClassVariableExpression* classVarExp = dynamic_cast<CClassVariableExpression*>(classAssExp->getClassTermExpression()); |
| 1677 |
if (indiVarExp) { |
| 1678 |
varExpOccurenceCountHash[indiVarExp]++; |
| 1679 |
} |
| 1680 |
if (classVarExp) { |
| 1681 |
varExpOccurenceCountHash[classVarExp]++; |
| 1682 |
} |
| 1683 |
if (indiVarExp && classVarExp) { |
| 1684 |
extensionIndiVarExpSet.insert(indiVarExp); |
| 1685 |
extensionClassVarExpSet.insert(classVarExp); |
| 1686 |
varBuildItem->addIndividualVariableTypeVariableExtension(indiVarExp, classVarExp); |
| 1687 |
supported = true; |
| 1688 |
} else if (!classVarExp) { |
| 1689 |
assertionAxiom = true; |
| 1690 |
supported = true; |
| 1691 |
subQueryIndiAssExps.append(classAssExp); |
| 1692 |
if (indiVarExp) { |
| 1693 |
subQueryIndiVarExpSet.insert(indiVarExp); |
| 1694 |
} |
| 1695 |
} |
| 1696 |
} |
| 1697 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 1698 |
if (propAssExp) { |
| 1699 |
bool hasVariable = false; |
| 1700 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 1701 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 1702 |
CPropertyVariableExpression* propVarExp = dynamic_cast<CPropertyVariableExpression*>(propAssExp->getObjectPropertyTermExpression()); |
| 1703 |
if (firstVarExp) { |
| 1704 |
varExpOccurenceCountHash[firstVarExp]++; |
| 1705 |
} |
| 1706 |
if (secondVarExp) { |
| 1707 |
varExpOccurenceCountHash[secondVarExp]++; |
| 1708 |
} |
| 1709 |
if (propVarExp) { |
| 1710 |
varExpOccurenceCountHash[propVarExp]++; |
| 1711 |
} |
| 1712 |
if (!propVarExp) { |
| 1713 |
assertionAxiom = true; |
| 1714 |
supported = true; |
| 1715 |
subQueryIndiAssExps.append(propAssExp); |
| 1716 |
if (firstVarExp) { |
| 1717 |
subQueryIndiVarExpSet.insert(firstVarExp); |
| 1718 |
} |
| 1719 |
if (secondVarExp) { |
| 1720 |
subQueryIndiVarExpSet.insert(secondVarExp); |
| 1721 |
} |
| 1722 |
} else if (propVarExp && firstVarExp && secondVarExp) { |
| 1723 |
if (compAxIndMixedVarQuery->isDistinctRequired() && (!disVarSet.contains(secondVarExp) || !disVarSet.contains(firstVarExp))) { |
| 1724 |
propExtSingleOccCheckingPropAssList.append(propAssExp); |
| 1725 |
supported = true; |
| 1726 |
} |
| 1727 |
} |
| 1728 |
} |
| 1729 |
CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 1730 |
if (dataPropAssExp) { |
| 1731 |
assertionAxiom = true; |
| 1732 |
bool hasVariable = false; |
| 1733 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 1734 |
CDataLiteralVariableExpression* dataVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 1735 |
CPropertyVariableExpression* propVarExp = dynamic_cast<CPropertyVariableExpression*>(dataPropAssExp->getDataPropertyTermExpression()); |
| 1736 |
if (indiVarExp) { |
| 1737 |
varExpOccurenceCountHash[indiVarExp]++; |
| 1738 |
} |
| 1739 |
if (dataVarExp) { |
| 1740 |
varExpOccurenceCountHash[dataVarExp]++; |
| 1741 |
} |
| 1742 |
if (propVarExp) { |
| 1743 |
varExpOccurenceCountHash[propVarExp]++; |
| 1744 |
} |
| 1745 |
if (!propVarExp) { |
| 1746 |
assertionAxiom = true; |
| 1747 |
supported = true; |
| 1748 |
subQueryIndiAssExps.append(dataPropAssExp); |
| 1749 |
if (indiVarExp) { |
| 1750 |
subQueryIndiVarExpSet.insert(indiVarExp); |
| 1751 |
} |
| 1752 |
if (dataVarExp) { |
| 1753 |
subQueryIndiVarExpSet.insert(dataVarExp); |
| 1754 |
} |
| 1755 |
} |
| 1756 |
} |
| 1757 |
if (!supported) { |
| 1758 |
if (!unsupportedWarning) { |
| 1759 |
LOG(WARN, getDomain(), logTr("Query uses unsupported axiom types, which will be ignored."), this); |
| 1760 |
} |
| 1761 |
unsupportedWarning = true; |
| 1762 |
} |
| 1763 |
} |
| 1764 |
|
| 1765 |
|
| 1766 |
for (CObjectPropertyAssertionExpression* propAssExp : propExtSingleOccCheckingPropAssList) { |
| 1767 |
bool supported = true; |
| 1768 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 1769 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 1770 |
CPropertyVariableExpression* propVarExp = dynamic_cast<CPropertyVariableExpression*>(propAssExp->getObjectPropertyTermExpression()); |
| 1771 |
CIndividualVariableExpression* indiVarExp = nullptr; |
| 1772 |
if (varExpOccurenceCountHash[firstVarExp] > 1) { |
| 1773 |
indiVarExp = firstVarExp; |
| 1774 |
} else { |
| 1775 |
indiVarExp = secondVarExp; |
| 1776 |
} |
| 1777 |
if (varExpOccurenceCountHash[firstVarExp] > 1 && varExpOccurenceCountHash[secondVarExp] > 1) { |
| 1778 |
supported = false; |
| 1779 |
} else { |
| 1780 |
extensionIndiVarExpSet.insert(indiVarExp); |
| 1781 |
extensionPropertyVarExpSet.insert(propVarExp); |
| 1782 |
varBuildItem->addIndividualVariablePropertyVariableExtension(indiVarExp, propVarExp); |
| 1783 |
} |
| 1784 |
if (!supported) { |
| 1785 |
if (!unsupportedWarning) { |
| 1786 |
LOG(WARN, getDomain(), logTr("Query uses unsupported axiom types, which will be ignored."), this); |
| 1787 |
} |
| 1788 |
unsupportedWarning = true; |
| 1789 |
} |
| 1790 |
} |
| 1791 |
|
| 1792 |
|
| 1793 |
if (subQueryIndiAssExps.isEmpty() && !extensionIndiVarExpSet.isEmpty()) { |
| 1794 |
mTestingOntologyBuilder->initializeBuilding(); |
| 1795 |
CClassTermExpression* topClassExp = mOntoAnsweringItem->getTestingOntology(false)->getBuildData()->getTopClassExpression(); |
| 1796 |
CIndividualVariableExpression* indiVarExp = (CIndividualVariableExpression*)*extensionIndiVarExpSet.begin(); |
| 1797 |
CAxiomExpression* axiom = mTestingOntologyBuilder->getClassAssertion(indiVarExp, topClassExp); |
| 1798 |
mTestingOntologyBuilder->completeBuilding(); |
| 1799 |
subQueryIndiAssExps.append(axiom); |
| 1800 |
} |
| 1801 |
|
| 1802 |
|
| 1803 |
if (!subQueryIndiAssExps.isEmpty()) { |
| 1804 |
QList<CExpressionVariable*> subQueryDisIndiVarList; |
| 1805 |
for (CExpressionVariable* varExp : subQueryIndiVarExpSet) { |
| 1806 |
if (disVarSet.contains(varExp) || extensionIndiVarExpSet.contains(varExp)) { |
| 1807 |
subQueryDisIndiVarList.append(varExp); |
| 1808 |
} |
| 1809 |
} |
| 1810 |
CComplexAssertionsIndividualVariablesAnsweringQuery* subIndiVarQuery = new CComplexAssertionsIndividualVariablesAnsweringQuery(mOntoAnsweringItem->getOntology(), testingOnto, subQueryIndiAssExps, subQueryDisIndiVarList, mOntoAnsweringItem->getCalculationConfiguration(), compAxIndMixedVarQuery->getQueryName() + "-Assertion-Individual-Sub-Variables-Query"); |
| 1811 |
bool subQueryCompleted = false; |
| 1812 |
bool subQueryProcessing = false; |
| 1813 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* subQueryIndiBuildItem = initComplexAssertionsIndividualVariablesQuery(subIndiVarQuery, answererContext, queryProcessingData, subQueryCompleted, testingOnto, subQueryProcessing, true); |
| 1814 |
varBuildItem->addIndividualVariableSubQueryItem(subIndiVarQuery, subQueryIndiBuildItem); |
| 1815 |
if (!subQueryCompleted) { |
| 1816 |
CComputedItemDataNotificationLinker* notLinker = mOntoAnsweringItem->createComputedItemDataNotificationLinker(); |
| 1817 |
notLinker->setBuildingVariableItemProcessingItem(varBuildItem); |
| 1818 |
subQueryIndiBuildItem->addNotificationLinker(notLinker); |
| 1819 |
varBuildItem->incWaitingSubVariableBuildingItemCount(); |
| 1820 |
} |
| 1821 |
if (subQueryProcessing) { |
| 1822 |
queryProcessing = true; |
| 1823 |
} |
| 1824 |
|
| 1825 |
|
| 1826 |
cint64 classSubQueryId = 0; |
| 1827 |
function<void(QSet<CAxiomExpression*> nextSubQueryClassAxExps, QList<CExpressionVariable*> subQueryDisClassVarList, QSet<CExpressionVariable*> handledVarExpSet)> classSubQueryHandlerFunc = [&](QSet<CAxiomExpression*> nextSubQueryClassAxExps, QList<CExpressionVariable*> subQueryDisClassVarList, QSet<CExpressionVariable*> handledVarExpSet) { |
| 1828 |
CComplexAxiomsClassVariablesAnsweringQuery* subClassVarQuery = new CComplexAxiomsClassVariablesAnsweringQuery(mOntoAnsweringItem->getOntology(), testingOnto, nextSubQueryClassAxExps.toList(), subQueryDisClassVarList, mOntoAnsweringItem->getCalculationConfiguration(), QString("%1-Assertion-Class-Sub-Variables-Query-%1").arg(compAxIndMixedVarQuery->getQueryName()).arg(classSubQueryId++)); |
| 1829 |
bool classSubQueryCompleted = false; |
| 1830 |
bool classSubQueryProcessing = false; |
| 1831 |
COptimizedComplexBuildingClassVariableCompositionsItem* subQueryClassBuildItem = initComplexAxiomsClassVariablesQuery(subClassVarQuery, answererContext, queryProcessingData, classSubQueryCompleted, testingOnto, classSubQueryProcessing); |
| 1832 |
varBuildItem->addClassVariableSubQueryItem(subClassVarQuery, subQueryClassBuildItem); |
| 1833 |
for (CExpressionVariable* varExp : handledVarExpSet) { |
| 1834 |
varBuildItem->setExtensionClassVariableSubQueryBuildingItem((CClassVariableExpression*)varExp, subQueryClassBuildItem); |
| 1835 |
} |
| 1836 |
if (!classSubQueryCompleted) { |
| 1837 |
CComputedItemDataNotificationLinker* notLinker = mOntoAnsweringItem->createComputedItemDataNotificationLinker(); |
| 1838 |
notLinker->setBuildingVariableItemProcessingItem(varBuildItem); |
| 1839 |
subQueryClassBuildItem->addNotificationLinker(notLinker); |
| 1840 |
varBuildItem->incWaitingSubVariableBuildingItemCount(); |
| 1841 |
} |
| 1842 |
if (classSubQueryProcessing) { |
| 1843 |
queryProcessing = true; |
| 1844 |
} |
| 1845 |
}; |
| 1846 |
|
| 1847 |
createIndividualMixedVariableConnectedSplitSubQueries(extensionClassVarExpSet, subQueryClassAxExps, disVarSet, extensionIndiVarExpSet, classSubQueryHandlerFunc); |
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
cint64 propertySubQueryId = 0; |
| 1853 |
function<void(QSet<CAxiomExpression*> nextSubQueryPropertyAxExps, QList<CExpressionVariable*> subQueryDisClassVarList, QSet<CExpressionVariable*> handledVarExpSet)> propertySubQueryHandlerFunc = [&](QSet<CAxiomExpression*> nextSubQueryPropertyAxExps, QList<CExpressionVariable*> subQueryDisClassVarList, QSet<CExpressionVariable*> handledVarExpSet) { |
| 1854 |
CComplexAxiomsObjectPropertyVariablesAnsweringQuery* subPropertyVarQuery = new CComplexAxiomsObjectPropertyVariablesAnsweringQuery(mOntoAnsweringItem->getOntology(), testingOnto, nextSubQueryPropertyAxExps.toList(), subQueryDisClassVarList, mOntoAnsweringItem->getCalculationConfiguration(), QString("%1-Assertion-Property-Sub-Variables-Query-%1").arg(compAxIndMixedVarQuery->getQueryName()).arg(classSubQueryId++)); |
| 1855 |
bool classSubQueryCompleted = false; |
| 1856 |
bool classSubQueryProcessing = false; |
| 1857 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* subQueryPropertyBuildItem = initComplexAxiomsObjectPropertyVariablesQuery(subPropertyVarQuery, answererContext, queryProcessingData, classSubQueryCompleted, testingOnto, classSubQueryProcessing); |
| 1858 |
varBuildItem->addPropertyVariableSubQueryItem(subPropertyVarQuery, subQueryPropertyBuildItem); |
| 1859 |
for (CExpressionVariable* varExp : handledVarExpSet) { |
| 1860 |
varBuildItem->setExtensionPropertyVariableSubQueryBuildingItem((CPropertyVariableExpression*)varExp, subQueryPropertyBuildItem); |
| 1861 |
} |
| 1862 |
if (!classSubQueryCompleted) { |
| 1863 |
CComputedItemDataNotificationLinker* notLinker = mOntoAnsweringItem->createComputedItemDataNotificationLinker(); |
| 1864 |
notLinker->setBuildingVariableItemProcessingItem(varBuildItem); |
| 1865 |
subQueryPropertyBuildItem->addNotificationLinker(notLinker); |
| 1866 |
varBuildItem->incWaitingSubVariableBuildingItemCount(); |
| 1867 |
} |
| 1868 |
if (classSubQueryProcessing) { |
| 1869 |
queryProcessing = true; |
| 1870 |
} |
| 1871 |
}; |
| 1872 |
|
| 1873 |
createIndividualMixedVariableConnectedSplitSubQueries(extensionPropertyVarExpSet, propExtSubQueryPropAssList, disVarSet, extensionIndiVarExpSet, propertySubQueryHandlerFunc); |
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
queryProcessingData->incBuildingVariableItem(); |
| 1878 |
queryProcessingData->setVariableBuildingItem(varBuildItem); |
| 1879 |
|
| 1880 |
if (!queryProcessing) { |
| 1881 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(varBuildItem); |
| 1882 |
varBuildItem->setProcessingQueued(true); |
| 1883 |
} |
| 1884 |
|
| 1885 |
} |
| 1886 |
return varBuildItem; |
| 1887 |
} |
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
void COptimizedComplexExpressionAnsweringHandler::createIndividualMixedVariableConnectedSplitSubQueries(QSet<CExpressionVariable *> extensionVarExpSet, QList<CAxiomExpression *> subQueryAxExps, QSet<CExpressionVariable *> &disVarSet, QSet<CExpressionVariable *> &extensionIndiVarExpSet, function<void(QSet<CAxiomExpression *> nextSubQueryClassAxExps, QList<CExpressionVariable *> subQueryDisClassVarList, QSet<CExpressionVariable *> handledVarExpSet)> subQueryHandlerFunc) { |
| 1893 |
QSet<CExpressionVariable*> handledExtensionVarExpSet; |
| 1894 |
for (CExpressionVariable* extVarExp : extensionVarExpSet) { |
| 1895 |
if (!handledExtensionVarExpSet.contains(extVarExp)) { |
| 1896 |
|
| 1897 |
QSet<CExpressionVariable*> handledVarExpSet; |
| 1898 |
QList<CExpressionVariable*> handlingVarExpList; |
| 1899 |
handlingVarExpList.append(extVarExp); |
| 1900 |
handledVarExpSet.insert(extVarExp); |
| 1901 |
|
| 1902 |
QSet<CAxiomExpression*> nextSubQueryAxExps; |
| 1903 |
|
| 1904 |
while (!handlingVarExpList.isEmpty()) { |
| 1905 |
CExpressionVariable* handleIndiVar = handlingVarExpList.takeFirst(); |
| 1906 |
|
| 1907 |
for (CAxiomExpression* subQuAx : subQueryAxExps) { |
| 1908 |
|
| 1909 |
if (!nextSubQueryAxExps.contains(subQuAx)) { |
| 1910 |
CSubClassOfExpression* subClassAxExp = dynamic_cast<CSubClassOfExpression*>(subQuAx); |
| 1911 |
if (subClassAxExp) { |
| 1912 |
CClassVariableExpression* firstClassVarExp = dynamic_cast<CClassVariableExpression*>(subClassAxExp->getFirstClassTermExpression()); |
| 1913 |
CClassVariableExpression* secondClassVarExp = dynamic_cast<CClassVariableExpression*>(subClassAxExp->getSecondClassTermExpression()); |
| 1914 |
if (handledVarExpSet.contains(firstClassVarExp) || handledVarExpSet.contains(secondClassVarExp)) { |
| 1915 |
nextSubQueryAxExps.insert(subClassAxExp); |
| 1916 |
|
| 1917 |
if (firstClassVarExp && !handledVarExpSet.contains(firstClassVarExp)) { |
| 1918 |
handledVarExpSet.insert(firstClassVarExp); |
| 1919 |
handlingVarExpList.append(firstClassVarExp); |
| 1920 |
} |
| 1921 |
if (secondClassVarExp && !handledVarExpSet.contains(secondClassVarExp)) { |
| 1922 |
handledVarExpSet.insert(secondClassVarExp); |
| 1923 |
handlingVarExpList.append(secondClassVarExp); |
| 1924 |
} |
| 1925 |
} |
| 1926 |
} |
| 1927 |
|
| 1928 |
CSubObjectPropertyOfExpression* subPropAxExp = dynamic_cast<CSubObjectPropertyOfExpression*>(subQuAx); |
| 1929 |
if (subPropAxExp) { |
| 1930 |
|
| 1931 |
CEXPRESSIONLIST<CObjectPropertyTermExpression*>* subObjPropList = subPropAxExp->getSubObjectPropertyTermExpressionList(); |
| 1932 |
if (subObjPropList->size() == 1) { |
| 1933 |
CObjectPropertyVariableExpression* subObjPropVarExp = dynamic_cast<CObjectPropertyVariableExpression*>(subObjPropList->first()); |
| 1934 |
CObjectPropertyVariableExpression* superObjPropVarExp = dynamic_cast<CObjectPropertyVariableExpression*>(subPropAxExp->getSuperObjectPropertyTermExpression()); |
| 1935 |
if (handledVarExpSet.contains(subObjPropVarExp) || handledVarExpSet.contains(superObjPropVarExp)) { |
| 1936 |
nextSubQueryAxExps.insert(subPropAxExp); |
| 1937 |
if (subObjPropVarExp && !handledVarExpSet.contains(subObjPropVarExp)) { |
| 1938 |
handledVarExpSet.insert(subObjPropVarExp); |
| 1939 |
handlingVarExpList.append(subObjPropVarExp); |
| 1940 |
} |
| 1941 |
if (superObjPropVarExp && !handledVarExpSet.contains(superObjPropVarExp)) { |
| 1942 |
handledVarExpSet.insert(superObjPropVarExp); |
| 1943 |
handlingVarExpList.append(superObjPropVarExp); |
| 1944 |
} |
| 1945 |
} |
| 1946 |
} |
| 1947 |
|
| 1948 |
} |
| 1949 |
} |
| 1950 |
|
| 1951 |
} |
| 1952 |
} |
| 1953 |
|
| 1954 |
|
| 1955 |
if (!nextSubQueryAxExps.isEmpty()) { |
| 1956 |
QList<CExpressionVariable*> subQueryDisVarList; |
| 1957 |
for (CExpressionVariable* varExp : extensionVarExpSet) { |
| 1958 |
if (handledVarExpSet.contains(varExp) && (disVarSet.contains(varExp) || extensionIndiVarExpSet.contains(varExp))) { |
| 1959 |
subQueryDisVarList.append(varExp); |
| 1960 |
} |
| 1961 |
} |
| 1962 |
|
| 1963 |
subQueryHandlerFunc(nextSubQueryAxExps, subQueryDisVarList, handledVarExpSet); |
| 1964 |
} |
| 1965 |
|
| 1966 |
} |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* COptimizedComplexExpressionAnsweringHandler::initComplexAssertionsIndividualVariablesQuery(CComplexAssertionsIndividualVariablesAnsweringQuery* compAssIndVarQuery, CAnswererContext* answererContext, CComplexQueryExpressionProcessingData* queryProcessingData, bool &queryCompleted, CConcreteOntology* testingOnto, bool &queryProcessing, bool forceBuildingItem) { |
| 1973 |
QList<CAxiomExpression*> assExps = *compAssIndVarQuery->getAxiomExpressions(); |
| 1974 |
QList<CExpressionVariable*>* disVarList = compAssIndVarQuery->getDistinguishedVariableExpressions(); |
| 1975 |
QSet<CExpressionVariable*> varExpSet; |
| 1976 |
QList<CClassAssertionExpression*> classAssExpsEntList; |
| 1977 |
QList<CClassAssertionExpression*> compClassAssExpsEntList; |
| 1978 |
QList<CObjectPropertyAssertionExpression*> roleAssExpsEntList; |
| 1979 |
QList<CDataPropertyAssertionExpression*> dataRoleAssExpsEntList; |
| 1980 |
QList<CAxiomExpression*> assExpsVarList; |
| 1981 |
CExpressionVariable* lastVarExpression = nullptr; |
| 1982 |
|
| 1983 |
QSet<CExpressionVariable*> answerIndiVariableSet(disVarList->toSet()); |
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
bool nonInstantiatedTerm = false; |
| 1988 |
if (mConfUnsatisfiableNonInstanceStatisticsChecking) { |
| 1989 |
nonInstantiatedTerm = identifyNonInstantiation(assExps, answerIndiVariableSet, answererContext); |
| 1990 |
} |
| 1991 |
|
| 1992 |
if (nonInstantiatedTerm) { |
| 1993 |
finishQueryProcessingAsUnsatisfaible(queryProcessingData); |
| 1994 |
queryCompleted = true; |
| 1995 |
} else { |
| 1996 |
|
| 1997 |
|
| 1998 |
if (mConfInterpretQueriesAsDistinct) { |
| 1999 |
compAssIndVarQuery->setDistinctRequired(true); |
| 2000 |
} |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
if (mConfRedundantTermReduction) { |
| 2005 |
cint64 prevCount = assExps.count(); |
| 2006 |
assExps = eliminateRedundantQueryTerms(assExps, queryProcessingData, answererContext); |
| 2007 |
cint64 newCount = assExps.count(); |
| 2008 |
if (prevCount != newCount && mConfExtendedLogging) { |
| 2009 |
LOG(INFO, getDomain(), logTr("Eliminated %1 redundant query terms.").arg(prevCount - newCount), this); |
| 2010 |
} |
| 2011 |
} |
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
for (CAxiomExpression* assExp : assExps) { |
| 2016 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 2017 |
if (classAssExp) { |
| 2018 |
CIndividualVariableExpression* varExp = dynamic_cast<CIndividualVariableExpression*>(classAssExp->getIndividualTermExpression()); |
| 2019 |
if (!varExp) { |
| 2020 |
if (classAssExp->getClassTermExpression()->getType() == CBuildExpression::BETCLASS) { |
| 2021 |
classAssExpsEntList.append(classAssExp); |
| 2022 |
} else { |
| 2023 |
compClassAssExpsEntList.append(classAssExp); |
| 2024 |
} |
| 2025 |
} else { |
| 2026 |
lastVarExpression = varExp; |
| 2027 |
assExpsVarList.append(classAssExp); |
| 2028 |
} |
| 2029 |
} |
| 2030 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 2031 |
if (propAssExp) { |
| 2032 |
bool hasVariable = false; |
| 2033 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 2034 |
if (firstVarExp) { |
| 2035 |
hasVariable = true; |
| 2036 |
lastVarExpression = firstVarExp; |
| 2037 |
} |
| 2038 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 2039 |
if (secondVarExp) { |
| 2040 |
hasVariable = true; |
| 2041 |
lastVarExpression = secondVarExp; |
| 2042 |
} |
| 2043 |
if (!hasVariable) { |
| 2044 |
roleAssExpsEntList.append(propAssExp); |
| 2045 |
} else { |
| 2046 |
assExpsVarList.append(propAssExp); |
| 2047 |
} |
| 2048 |
} |
| 2049 |
CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 2050 |
if (dataPropAssExp) { |
| 2051 |
bool hasVariable = false; |
| 2052 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 2053 |
if (indiVarExp) { |
| 2054 |
hasVariable = true; |
| 2055 |
lastVarExpression = indiVarExp; |
| 2056 |
} |
| 2057 |
CDataLiteralVariableExpression* dataVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 2058 |
if (dataVarExp) { |
| 2059 |
hasVariable = true; |
| 2060 |
lastVarExpression = dataVarExp; |
| 2061 |
} |
| 2062 |
if (!hasVariable) { |
| 2063 |
dataRoleAssExpsEntList.append(dataPropAssExp); |
| 2064 |
} else { |
| 2065 |
assExpsVarList.append(dataPropAssExp); |
| 2066 |
} |
| 2067 |
|
| 2068 |
} |
| 2069 |
} |
| 2070 |
|
| 2071 |
|
| 2072 |
QList<CVariableBindingFilteringLiteralComparison*> dataLitCompFilterList; |
| 2073 |
for (CVariableBindingFiltering* filteringLinker = compAssIndVarQuery->getResultFilteringLinker(); filteringLinker; filteringLinker = filteringLinker->getNext()) { |
| 2074 |
CVariableBindingFilteringLiteralComparison* dataLiteralCompFilter = dynamic_cast<CVariableBindingFilteringLiteralComparison*>(filteringLinker); |
| 2075 |
if (dataLiteralCompFilter && !dataLiteralCompFilter->getDataLiteral()) { |
| 2076 |
dataLitCompFilterList.append(dataLiteralCompFilter); |
| 2077 |
} |
| 2078 |
} |
| 2079 |
|
| 2080 |
|
| 2081 |
if (!classAssExpsEntList.isEmpty() || !compClassAssExpsEntList.isEmpty() || !roleAssExpsEntList.isEmpty() || !dataRoleAssExpsEntList.isEmpty() || !dataLitCompFilterList.isEmpty()) { |
| 2082 |
QList<QPair<CClassTermExpression*, CIndividualTermExpression*>> indClassInstTestExpList; |
| 2083 |
QList<QPair<CVariableBindingFilteringLiteralComparison*, CDataLiteralExpression*>> dataFilterDataLiteralExpList; |
| 2084 |
if (!compClassAssExpsEntList.isEmpty() || !dataRoleAssExpsEntList.isEmpty() || !dataLitCompFilterList.isEmpty()) { |
| 2085 |
mTestingOntologyBuilder->initializeBuilding(); |
| 2086 |
for (CClassAssertionExpression* assExp : compClassAssExpsEntList) { |
| 2087 |
CClassTermExpression* classTermExp = assExp->getClassTermExpression(); |
| 2088 |
indClassInstTestExpList.append(QPair<CClassTermExpression*, CIndividualTermExpression*>((CClassTermExpression*)mTestingOntologyBuilder->rebuildExpression(classTermExp), assExp->getIndividualTermExpression())); |
| 2089 |
} |
| 2090 |
for (CDataPropertyAssertionExpression* dataRoleAssExp : dataRoleAssExpsEntList) { |
| 2091 |
CDataPropertyTermExpression* dataPropTermExp = dataRoleAssExp->getDataPropertyTermExpression(); |
| 2092 |
CIndividualTermExpression* indiTermExp = dataRoleAssExp->getIndividualTermExpression(); |
| 2093 |
CDataLiteralExpression* dataLiteralExp = (CDataLiteralExpression*)dataRoleAssExp->getDataLiteralTermExpression(); |
| 2094 |
dataLiteralExp = (CDataLiteralExpression*)mTestingOntologyBuilder->rebuildExpression(dataLiteralExp); |
| 2095 |
indClassInstTestExpList.append(QPair<CClassTermExpression*, CIndividualTermExpression*>(mTestingOntologyBuilder->getDataHasValue(dataPropTermExp, dataLiteralExp), indiTermExp)); |
| 2096 |
} |
| 2097 |
for (CVariableBindingFilteringLiteralComparison* dataLiteralCompFilter : dataLitCompFilterList) { |
| 2098 |
CDataLiteralExpression* dataLitExp = dataLiteralCompFilter->getDataLiteralExpression(); |
| 2099 |
dataLitExp = (CDataLiteralExpression*)mTestingOntologyBuilder->rebuildExpression(dataLitExp); |
| 2100 |
dataFilterDataLiteralExpList.append(QPair<CVariableBindingFilteringLiteralComparison*, CDataLiteralExpression*>(dataLiteralCompFilter, dataLitExp)); |
| 2101 |
} |
| 2102 |
|
| 2103 |
mTestingOntologyBuilder->completeBuilding(); |
| 2104 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 2105 |
} |
| 2106 |
if (!dataFilterDataLiteralExpList.isEmpty()) { |
| 2107 |
CPreProcessContextBase preprocessingContext(mOntoAnsweringItem->getTestingOntology(), mOntoAnsweringItem->getTestingOntology()->getConfiguration()); |
| 2108 |
CDataLiteralNormalizerPreProcess dataLitNormalizer; |
| 2109 |
for (QPair<CVariableBindingFilteringLiteralComparison*, CDataLiteralExpression*> dataFilterDataLiteralExpPair : dataFilterDataLiteralExpList) { |
| 2110 |
CVariableBindingFilteringLiteralComparison* dataLiteralCompFilter = dataFilterDataLiteralExpPair.first; |
| 2111 |
CDataLiteralExpression* dataLitExp = dataFilterDataLiteralExpPair.second; |
| 2112 |
CConcept* dataConcept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getDataRangeTermConceptMappingHash()->value(dataLitExp); |
| 2113 |
CDataLiteral* dataLiteral = dataConcept->getDataLiteral(); |
| 2114 |
if (dataLiteral) { |
| 2115 |
CDataLiteralValue* dataLiteralValue = dataLiteral->getDataLiteralValue(); |
| 2116 |
if (!dataLiteralValue) { |
| 2117 |
dataLitNormalizer.preprocessDataConcept(dataConcept, mOntoAnsweringItem->getTestingOntology(), &preprocessingContext); |
| 2118 |
} |
| 2119 |
dataLiteralCompFilter->setDataLiteral(dataLiteral); |
| 2120 |
} |
| 2121 |
} |
| 2122 |
} |
| 2123 |
if (!classAssExpsEntList.isEmpty()) { |
| 2124 |
for (CClassAssertionExpression* assExp : classAssExpsEntList) { |
| 2125 |
indClassInstTestExpList.append(QPair<CClassTermExpression*, CIndividualTermExpression*>(assExp->getClassTermExpression(), assExp->getIndividualTermExpression())); |
| 2126 |
} |
| 2127 |
} |
| 2128 |
for (QPair<CClassTermExpression*, CIndividualTermExpression*> classIndiPair : indClassInstTestExpList) { |
| 2129 |
CClassTermExpression* classTermExp = classIndiPair.first; |
| 2130 |
CIndividualTermExpression* indiTermExp = classIndiPair.second; |
| 2131 |
CConcept* testingConcept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(classTermExp); |
| 2132 |
CIndividual* testingIndividual = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getIndividulTermIndiMappingHash()->value(indiTermExp); |
| 2133 |
bool testingNegation = testingConcept->hasMappingNegation(); |
| 2134 |
queryProcessing |= checkEntailmentConceptAssertion(testingConcept, testingNegation, testingIndividual, queryProcessingData, answererContext); |
| 2135 |
} |
| 2136 |
for (CObjectPropertyAssertionExpression* roleAssExp : roleAssExpsEntList) { |
| 2137 |
CObjectPropertyTermExpression* objPropTermExp = roleAssExp->getObjectPropertyTermExpression(); |
| 2138 |
CIndividualTermExpression* indiSourceTermExp = roleAssExp->getFirstIndividualTermExpression(); |
| 2139 |
CIndividualTermExpression* indiDestTermExp = roleAssExp->getSecondIndividualTermExpression(); |
| 2140 |
bool inversed = false; |
| 2141 |
while (objPropTermExp->getType() == CBuildExpression::BETINVERSEOBJECTPROPERTYOF) { |
| 2142 |
CInverseObjectPropertyOfExpression* invPropExp = (CInverseObjectPropertyOfExpression*)objPropTermExp; |
| 2143 |
objPropTermExp = invPropExp->getInverseOfExpression(); |
| 2144 |
inversed = !inversed; |
| 2145 |
} |
| 2146 |
if (inversed) { |
| 2147 |
CIndividualTermExpression* indiTermExp = indiSourceTermExp; |
| 2148 |
indiSourceTermExp = indiDestTermExp; |
| 2149 |
indiDestTermExp = indiTermExp; |
| 2150 |
} |
| 2151 |
CRole* testingRole = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(objPropTermExp); |
| 2152 |
CIndividual* testingIndividualSource = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getIndividulTermIndiMappingHash()->value(indiSourceTermExp); |
| 2153 |
CIndividual* testingIndividualDestination = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getIndividulTermIndiMappingHash()->value(indiDestTermExp); |
| 2154 |
queryProcessing |= checkEntailmentRoleAssertion(testingRole, testingIndividualSource, testingIndividualDestination, queryProcessingData, answererContext); |
| 2155 |
} |
| 2156 |
|
| 2157 |
} |
| 2158 |
|
| 2159 |
|
| 2160 |
for (CAxiomExpression* assExp : assExpsVarList) { |
| 2161 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 2162 |
if (classAssExp) { |
| 2163 |
CIndividualVariableExpression* varExp = dynamic_cast<CIndividualVariableExpression*>(classAssExp->getIndividualTermExpression()); |
| 2164 |
if (varExp) { |
| 2165 |
varExpSet.insert(varExp); |
| 2166 |
} |
| 2167 |
} |
| 2168 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 2169 |
if (propAssExp) { |
| 2170 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 2171 |
if (firstVarExp) { |
| 2172 |
varExpSet.insert(firstVarExp); |
| 2173 |
} |
| 2174 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 2175 |
if (secondVarExp) { |
| 2176 |
varExpSet.insert(secondVarExp); |
| 2177 |
} |
| 2178 |
} |
| 2179 |
CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 2180 |
if (dataPropAssExp) { |
| 2181 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 2182 |
if (indiVarExp) { |
| 2183 |
varExpSet.insert(indiVarExp); |
| 2184 |
} |
| 2185 |
CDataLiteralVariableExpression* dataVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 2186 |
if (dataVarExp) { |
| 2187 |
varExpSet.insert(dataVarExp); |
| 2188 |
} |
| 2189 |
} |
| 2190 |
|
| 2191 |
} |
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
QSet<CExpressionVariable*> initialAnonymousIndiVariableSet; |
| 2196 |
for (CExpressionVariable* varExp : varExpSet) { |
| 2197 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(varExp); |
| 2198 |
if (indiVarExp && indiVarExp->isAnonymousVariable()) { |
| 2199 |
initialAnonymousIndiVariableSet.insert(varExp); |
| 2200 |
} |
| 2201 |
if (indiVarExp && mConfInterpretNonAnswerIndividualVariablesAsAnonymousVariables && !answerIndiVariableSet.contains(varExp)) { |
| 2202 |
if (varExp->getName().startsWith(mConfNonAnswerIndividualVariablesAsAnonymousVariablesInterpretingPrefixString)) { |
| 2203 |
initialAnonymousIndiVariableSet.insert(varExp); |
| 2204 |
} |
| 2205 |
} |
| 2206 |
} |
| 2207 |
bool distinct = compAssIndVarQuery->isDistinctRequired(); |
| 2208 |
QSet<CExpressionVariable*> anonymousIndiVariableSet(initialAnonymousIndiVariableSet); |
| 2209 |
QSet<CExpressionVariable*> nonEliminatableIndiVariableSet(answerIndiVariableSet); |
| 2210 |
if (!distinct) { |
| 2211 |
for (CExpressionVariable* varExp : varExpSet) { |
| 2212 |
if (!anonymousIndiVariableSet.contains(varExp) && !answerIndiVariableSet.contains(varExp)) { |
| 2213 |
nonEliminatableIndiVariableSet.insert(varExp); |
| 2214 |
} |
| 2215 |
} |
| 2216 |
} |
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
QList<CObjectPropertyAssertionExpression*> bothVarPropAssPropagationList; |
| 2223 |
QList<CDataPropertyAssertionExpression*> bothVarDataPropAssPropagationList; |
| 2224 |
QList<CDataPropertyAssertionExpression*> onlyDataVarDataPropAssList; |
| 2225 |
QHash<CExpressionVariable*, CAxiomExpression*> varExpAxiomExpHash; |
| 2226 |
bool unsupportedWarning = false; |
| 2227 |
for (CAxiomExpression* assExp : assExpsVarList) { |
| 2228 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 2229 |
if (classAssExp) { |
| 2230 |
CIndividualVariableExpression* varExp = dynamic_cast<CIndividualVariableExpression*>(classAssExp->getIndividualTermExpression()); |
| 2231 |
if (varExp) { |
| 2232 |
varExpAxiomExpHash.insertMulti(varExp, assExp); |
| 2233 |
} |
| 2234 |
} |
| 2235 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 2236 |
if (propAssExp) { |
| 2237 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 2238 |
if (firstVarExp) { |
| 2239 |
varExpAxiomExpHash.insertMulti(firstVarExp, assExp); |
| 2240 |
} |
| 2241 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 2242 |
if (secondVarExp && secondVarExp != firstVarExp) { |
| 2243 |
varExpAxiomExpHash.insertMulti(secondVarExp, assExp); |
| 2244 |
} |
| 2245 |
if (firstVarExp && secondVarExp) { |
| 2246 |
if (!anonymousIndiVariableSet.contains(firstVarExp) && !anonymousIndiVariableSet.contains(secondVarExp)) { |
| 2247 |
bothVarPropAssPropagationList.append(propAssExp); |
| 2248 |
} |
| 2249 |
} |
| 2250 |
} |
| 2251 |
CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 2252 |
if (dataPropAssExp) { |
| 2253 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 2254 |
if (firstVarExp) { |
| 2255 |
varExpAxiomExpHash.insertMulti(firstVarExp, assExp); |
| 2256 |
} |
| 2257 |
CDataLiteralVariableExpression* dataLitVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 2258 |
if (firstVarExp && dataLitVarExp) { |
| 2259 |
if (!anonymousIndiVariableSet.contains(firstVarExp) && !anonymousIndiVariableSet.contains(dataLitVarExp)) { |
| 2260 |
bothVarDataPropAssPropagationList.append(dataPropAssExp); |
| 2261 |
} |
| 2262 |
} |
| 2263 |
if (!firstVarExp && dataLitVarExp) { |
| 2264 |
onlyDataVarDataPropAssList.append(dataPropAssExp); |
| 2265 |
} |
| 2266 |
} |
| 2267 |
if (!classAssExp && !propAssExp && !dataPropAssExp) { |
| 2268 |
if (!unsupportedWarning) { |
| 2269 |
LOG(WARN, getDomain(), logTr("Query uses unsupported axiom types, which will be ignored."), this); |
| 2270 |
} |
| 2271 |
unsupportedWarning = true; |
| 2272 |
} |
| 2273 |
} |
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
// TODO: check whether all role and concept terms of an instance query are indeed instantiated via the occurrence statistics cache |
| 2278 |
|
| 2279 |
bool allAnonymousVariables = varExpSet.size() == anonymousIndiVariableSet.size(); |
| 2280 |
QSet<CExpressionVariable*> convertedVariableSet; |
| 2281 |
bool updateIndiVarAssPropLists = tryAnonymousToIndividualVariablesConversion(anonymousIndiVariableSet, varExpSet, distinct, answererContext, varExpAxiomExpHash, allAnonymousVariables, convertedVariableSet); |
| 2282 |
|
| 2283 |
|
| 2284 |
// if individual variables are eliminated, then the remaining variables (that allow the eliminations) may have to be counted several times, which is managed by the following hash |
| 2285 |
QHash<CExpressionVariable*, cint64> variableMultipleAnswerCountingHash; |
| 2286 |
QList<CExpressionVariable*> indiIgnoreVarSet; |
| 2287 |
if (mConfRedundantlyRestrictedVariablesElimination) { |
| 2288 |
QSet<CExpressionVariable*> eliminationAllowedVarSet; |
| 2289 |
eliminationAllowedVarSet += anonymousIndiVariableSet; |
| 2290 |
QList<CExpressionVariable*> redEmbVarSet = getRedundantlyEmbeddedVariables(varExpAxiomExpHash, anonymousIndiVariableSet, nonEliminatableIndiVariableSet, queryProcessingData, answererContext); |
| 2291 |
if (!redEmbVarSet.isEmpty()) { |
| 2292 |
updateIndiVarAssPropLists = true; |
| 2293 |
indiIgnoreVarSet = redEmbVarSet; |
| 2294 |
|
| 2295 |
if (mConfExtendedLogging) { |
| 2296 |
QStringList varList; |
| 2297 |
for (CExpressionVariable* var : redEmbVarSet) { |
| 2298 |
varList.append(var->getName()); |
| 2299 |
} |
| 2300 |
LOG(INFO, getDomain(), logTr("Eliminated %1 redundantly restricted variables: %2.").arg(varList.size()).arg(varList.join(", ")), this); |
| 2301 |
} |
| 2302 |
|
| 2303 |
for (CExpressionVariable* var : redEmbVarSet) { |
| 2304 |
varExpSet.remove(var); |
| 2305 |
} |
| 2306 |
|
| 2307 |
for (QSet<CExpressionVariable*>::iterator it = anonymousIndiVariableSet.begin(), itEnd = anonymousIndiVariableSet.end(); it != itEnd; ) { |
| 2308 |
CExpressionVariable* varExp = *it; |
| 2309 |
if (redEmbVarSet.contains(varExp)) { |
| 2310 |
it = anonymousIndiVariableSet.erase(it); |
| 2311 |
} else { |
| 2312 |
++it; |
| 2313 |
} |
| 2314 |
} |
| 2315 |
} |
| 2316 |
} |
| 2317 |
|
| 2318 |
|
| 2319 |
if (updateIndiVarAssPropLists) { |
| 2320 |
bothVarPropAssPropagationList.clear(); |
| 2321 |
bothVarDataPropAssPropagationList.clear(); |
| 2322 |
onlyDataVarDataPropAssList.clear(); |
| 2323 |
varExpAxiomExpHash.clear(); |
| 2324 |
for (CAxiomExpression* assExp : assExpsVarList) { |
| 2325 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 2326 |
if (classAssExp) { |
| 2327 |
CIndividualVariableExpression* varExp = dynamic_cast<CIndividualVariableExpression*>(classAssExp->getIndividualTermExpression()); |
| 2328 |
if (varExp && !indiIgnoreVarSet.contains(varExp)) { |
| 2329 |
varExpAxiomExpHash.insertMulti(varExp, assExp); |
| 2330 |
} |
| 2331 |
} |
| 2332 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 2333 |
if (propAssExp) { |
| 2334 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 2335 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 2336 |
if (firstVarExp && !indiIgnoreVarSet.contains(firstVarExp) && (!secondVarExp || !indiIgnoreVarSet.contains(secondVarExp))) { |
| 2337 |
varExpAxiomExpHash.insertMulti(firstVarExp, assExp); |
| 2338 |
} |
| 2339 |
if (secondVarExp && secondVarExp != firstVarExp && !indiIgnoreVarSet.contains(secondVarExp) && (!firstVarExp || !indiIgnoreVarSet.contains(firstVarExp))) { |
| 2340 |
varExpAxiomExpHash.insertMulti(secondVarExp, assExp); |
| 2341 |
} |
| 2342 |
if (firstVarExp && secondVarExp && !indiIgnoreVarSet.contains(firstVarExp) && !indiIgnoreVarSet.contains(secondVarExp)) { |
| 2343 |
if (!anonymousIndiVariableSet.contains(firstVarExp) && !anonymousIndiVariableSet.contains(secondVarExp)) { |
| 2344 |
bothVarPropAssPropagationList.append(propAssExp); |
| 2345 |
} |
| 2346 |
} |
| 2347 |
} |
| 2348 |
CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 2349 |
if (dataPropAssExp) { |
| 2350 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 2351 |
if (firstVarExp && !indiIgnoreVarSet.contains(firstVarExp)) { |
| 2352 |
varExpAxiomExpHash.insertMulti(firstVarExp, assExp); |
| 2353 |
} |
| 2354 |
CDataLiteralVariableExpression* dataLitVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 2355 |
if (firstVarExp && !indiIgnoreVarSet.contains(firstVarExp) && dataLitVarExp) { |
| 2356 |
if (!anonymousIndiVariableSet.contains(firstVarExp) && !anonymousIndiVariableSet.contains(dataLitVarExp)) { |
| 2357 |
bothVarDataPropAssPropagationList.append(dataPropAssExp); |
| 2358 |
} |
| 2359 |
} |
| 2360 |
if (!firstVarExp && dataLitVarExp) { |
| 2361 |
onlyDataVarDataPropAssList.append(dataPropAssExp); |
| 2362 |
} |
| 2363 |
} |
| 2364 |
} |
| 2365 |
} |
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
if (!forceBuildingItem && varExpSet.size() == 1 && dynamic_cast<CIndividualVariableExpression*>(lastVarExpression) && !anonymousIndiVariableSet.contains(lastVarExpression)) { |
| 2372 |
// reduce to instance test |
| 2373 |
//TODO: make sure expression ontology contains inverses for all roles |
| 2374 |
LOG(INFO, getDomain(), logTr("Reducing query to single (complex) instance retrieval task."), this); |
| 2375 |
CBuildExpression* instTestingExp = nullptr; |
| 2376 |
QList<CBuildExpression*> instTestingExpList; |
| 2377 |
mTestingOntologyBuilder->initializeBuilding(); |
| 2378 |
bool onlyAtomicConcept = true; |
| 2379 |
for (CAxiomExpression* assExp : assExpsVarList) { |
| 2380 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 2381 |
if (classAssExp) { |
| 2382 |
instTestingExpList.append(mTestingOntologyBuilder->rebuildExpression(classAssExp->getClassTermExpression())); |
| 2383 |
if (!dynamic_cast<CClassExpression*>(classAssExp->getClassTermExpression())) { |
| 2384 |
onlyAtomicConcept = false; |
| 2385 |
} |
| 2386 |
} |
| 2387 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 2388 |
if (propAssExp) { |
| 2389 |
onlyAtomicConcept = false; |
| 2390 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 2391 |
CIndividualTermExpression* firstIndiExp = propAssExp->getFirstIndividualTermExpression(); |
| 2392 |
CIndividualTermExpression* secondIndiExp = propAssExp->getSecondIndividualTermExpression(); |
| 2393 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(firstIndiExp); |
| 2394 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(secondIndiExp); |
| 2395 |
if (firstVarExp && secondVarExp) { |
| 2396 |
instTestingExpList.append(mTestingOntologyBuilder->getObjectHasSelf(propExp)); |
| 2397 |
} else if (firstVarExp) { |
| 2398 |
instTestingExpList.append(mTestingOntologyBuilder->getObjectHasValue(propExp, secondIndiExp)); |
| 2399 |
} else { |
| 2400 |
instTestingExpList.append(mTestingOntologyBuilder->getObjectHasValue(mTestingOntologyBuilder->getInverseObjectPropertyOf(propExp), firstIndiExp)); |
| 2401 |
} |
| 2402 |
} |
| 2403 |
CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 2404 |
if (dataPropAssExp) { |
| 2405 |
onlyAtomicConcept = false; |
| 2406 |
CDataPropertyTermExpression* dataPropTermExp = dataPropAssExp->getDataPropertyTermExpression(); |
| 2407 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 2408 |
CDataLiteralVariableExpression* dataVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 2409 |
if (indiVarExp && !dataVarExp) { |
| 2410 |
CDataLiteralExpression* dataLiteralExp = (CDataLiteralExpression*)dataPropAssExp->getDataLiteralTermExpression(); |
| 2411 |
dataLiteralExp = (CDataLiteralExpression*)mTestingOntologyBuilder->rebuildExpression(dataLiteralExp); |
| 2412 |
instTestingExpList.append(mTestingOntologyBuilder->getDataHasValue(dataPropTermExp, dataLiteralExp)); |
| 2413 |
} |
| 2414 |
} |
| 2415 |
|
| 2416 |
//TODO: handle data assertions and data variables |
| 2417 |
} |
| 2418 |
instTestingExp = mTestingOntologyBuilder->getObjectIntersectionOf(instTestingExpList); |
| 2419 |
mTestingOntologyBuilder->completeBuilding(); |
| 2420 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 2421 |
|
| 2422 |
CClassTermExpression* classTermExpOfInt = dynamic_cast<CClassTermExpression*>(instTestingExp); |
| 2423 |
if (classTermExpOfInt) { |
| 2424 |
COptimizedComplexConceptItem* assocConceptItem = nullptr; |
| 2425 |
cint64 initialRequestingCount = 1; |
| 2426 |
if (mConfMinimalMappingsComputationSize < 0 && compAssIndVarQuery->getResultLimit() < 0) { |
| 2427 |
initialRequestingCount = -1; |
| 2428 |
} |
| 2429 |
queryProcessing |= initializeComplexConceptQueryProcessing(queryProcessingData, nullptr, classTermExpOfInt, false, false, false, false, false, initialRequestingCount, &assocConceptItem); |
| 2430 |
|
| 2431 |
if (assocConceptItem && mConfExtendedLogging) { |
| 2432 |
LOG(INFO, getDomain(), logTr("Using complex concept item %2 for computing bounds for variable %1.").arg(lastVarExpression->getName()).arg(assocConceptItem->getConceptItemId()), this); |
| 2433 |
} |
| 2434 |
} |
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
} else { |
| 2440 |
|
| 2441 |
|
| 2442 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* varBuildItem = new COptimizedComplexBuildingIndividualVariableCompositionsItem(queryProcessingData); |
| 2443 |
varBuildItem->setAllVariableSet(varExpSet); |
| 2444 |
varBuildItem->setDistinguishedVariableSet(disVarList->toSet()); |
| 2445 |
varBuildItem->setReductionDeniedVariableSet(disVarList->toSet()); |
| 2446 |
for (CVariableBindingOrdering* resultOrderingLinkerIt = compAssIndVarQuery->getResultOrderingLinker(); resultOrderingLinkerIt; resultOrderingLinkerIt = resultOrderingLinkerIt->getNext()) { |
| 2447 |
varBuildItem->getReductionDeniedVariableSet()->insert(resultOrderingLinkerIt->getOrderingVariableExpression()); |
| 2448 |
} |
| 2449 |
if (allAnonymousVariables || distinct || mConfBindingReducingForNonDistinctAnswerQueries) { |
| 2450 |
varBuildItem->setBindingsReducible(true); |
| 2451 |
} |
| 2452 |
*varBuildItem->getVariableSingleCardinalitySet() = convertedVariableSet; |
| 2453 |
varBuildItem->getVariableSingleCardinalitySet()->unite(compAssIndVarQuery->getIgnoreCardinalityVariableExpressions().toSet()); |
| 2454 |
|
| 2455 |
|
| 2456 |
CComplexAssertionsIndividualVariablesAnsweringExtendibleQuery* extCompAssIndVarQuery = dynamic_cast<CComplexAssertionsIndividualVariablesAnsweringExtendibleQuery*>(compAssIndVarQuery); |
| 2457 |
if (extCompAssIndVarQuery) { |
| 2458 |
CComplexQueryExtendibleData* extendibleData = extCompAssIndVarQuery->getExtendibleData(); |
| 2459 |
queryProcessingData->setQueryExtendibleData(extendibleData); |
| 2460 |
|
| 2461 |
if (!extendibleData->getExtendingQueryList()->isEmpty()) { |
| 2462 |
QList<CExpressionVariable*>* extendibleQueryTransferringExtractionVariableList = varBuildItem->getExtendibleQueryTransferringExtractionVariableList(); |
| 2463 |
for (CExpressionVariable* expVar : *extCompAssIndVarQuery->getDistinguishedVariableExpressions()) { |
| 2464 |
extendibleQueryTransferringExtractionVariableList->append(expVar); |
| 2465 |
} |
| 2466 |
} |
| 2467 |
} |
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
mTestingOntologyBuilder->initializeBuilding(); |
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
// do rolling up of assertions with anonymous variables |
| 2478 |
QHash<CExpressionVariable*, CBuildExpression*> varRolledUpClassExpHash; |
| 2479 |
QSet<CExpressionVariable*> rolledVarExpSet; |
| 2480 |
expressionsRollingUp(anonymousIndiVariableSet, rolledVarExpSet, varExpAxiomExpHash, testingOnto, varRolledUpClassExpHash); |
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
QHash<CExpressionVariable*, CBuildExpression*> rebuiltVarClassTermExp = rebuildVariablesClassTermExpressions(varExpSet, rolledVarExpSet, varExpAxiomExpHash, varRolledUpClassExpHash); |
| 2486 |
varBuildItem->setVariableClassTermExpressionHash(rebuiltVarClassTermExp); |
| 2487 |
|
| 2488 |
queryProcessingData->incBuildingVariableItem(); |
| 2489 |
queryProcessingData->setVariableBuildingItem(varBuildItem); |
| 2490 |
|
| 2491 |
|
| 2492 |
if (mConfFullQueryMaterialization) { |
| 2493 |
|
| 2494 |
mTestingOntologyBuilder->completeBuilding(); |
| 2495 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 2496 |
|
| 2497 |
createQueryMaterializationData(varExpSet, rolledVarExpSet, anonymousIndiVariableSet, rebuiltVarClassTermExp, varExpAxiomExpHash, allAnonymousVariables, initialAnonymousIndiVariableSet, bothVarDataPropAssPropagationList, bothVarPropAssPropagationList, onlyDataVarDataPropAssList, varBuildItem, answererContext); |
| 2498 |
|
| 2499 |
|
| 2500 |
queryProcessing = createQueryMaterializationTest(varBuildItem, answererContext); |
| 2501 |
} else { |
| 2502 |
queryProcessing = finishConceptAndAbsorptionItemsGeneration(varExpSet, rolledVarExpSet, anonymousIndiVariableSet, rebuiltVarClassTermExp, varExpAxiomExpHash, allAnonymousVariables, initialAnonymousIndiVariableSet, bothVarDataPropAssPropagationList, bothVarPropAssPropagationList, onlyDataVarDataPropAssList, varBuildItem, answererContext); |
| 2503 |
} |
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
return varBuildItem; |
| 2508 |
|
| 2509 |
} |
| 2510 |
|
| 2511 |
} |
| 2512 |
return nullptr; |
| 2513 |
} |
| 2514 |
|
| 2515 |
|
| 2516 |
|
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
bool COptimizedComplexExpressionAnsweringHandler::areConceptItemConceptsImpliedByPropertyDomains(CIndividualVariableExpression* varExp, COptimizedComplexConceptItem* conItem, const QList<CObjectPropertyAssertionExpression*>& propAssList, COptimizedComplexBuildingIndividualVariableCompositionsItem* varBuildItem, CAnswererContext* answererContext) { |
| 2521 |
QSet<TConceptNegPair> testingConSet = *conItem->getAtomicConcpetSet(); |
| 2522 |
for (CObjectPropertyAssertionExpression* propAssExp : propAssList) { |
| 2523 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 2524 |
CIndividualTermExpression* firstIndiExp = propAssExp->getFirstIndividualTermExpression(); |
| 2525 |
CIndividualTermExpression* secondIndiExp = propAssExp->getSecondIndividualTermExpression(); |
| 2526 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(firstIndiExp); |
| 2527 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(secondIndiExp); |
| 2528 |
|
| 2529 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp); |
| 2530 |
bool domain = true; |
| 2531 |
if (secondVarExp == varExp) { |
| 2532 |
domain = false; |
| 2533 |
} |
| 2534 |
|
| 2535 |
for (QSet<TConceptNegPair>::iterator it = testingConSet.begin(), itEnd = testingConSet.end(); it != itEnd; ) { |
| 2536 |
TConceptNegPair conNegPair = *it; |
| 2537 |
CConcept* concept = conNegPair.first; |
| 2538 |
bool conNeg = conNegPair.second; |
| 2539 |
if (isConceptRoleDomainRangeImplied(concept, conNeg, role, domain, answererContext)) { |
| 2540 |
it = testingConSet.erase(it); |
| 2541 |
} else { |
| 2542 |
++it; |
| 2543 |
} |
| 2544 |
} |
| 2545 |
|
| 2546 |
} |
| 2547 |
|
| 2548 |
|
| 2549 |
return testingConSet.isEmpty(); |
| 2550 |
} |
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
bool COptimizedComplexExpressionAnsweringHandler::isConceptRoleDomainRangeImplied(CConcept* concept, bool negation, CRole* role, bool domain, CAnswererContext* answererContext) { |
| 2555 |
CConcept* indiTriggerConcept = mOntoAnsweringItem->getOntology()->getTBox()->getIndividualTriggerConcept(); |
| 2556 |
CConcept* topConcept = mOntoAnsweringItem->getOntology()->getTBox()->getTopConcept(); |
| 2557 |
if ((concept->getOperatorCode() == CCSOME && !negation && !concept->getOperandList()->isNegated()) || (concept->getOperatorCode() == CCALL && negation && concept->getOperandList()->isNegated())) { |
| 2558 |
if (concept->getRole() == role && concept->getOperandCount() == 1 && concept->getOperandList()->getData() && (concept->getOperandList()->getData() == indiTriggerConcept || concept->getOperandList()->getData() == topConcept)) { |
| 2559 |
return true; |
| 2560 |
} |
| 2561 |
} |
| 2562 |
QSet<TConceptNegPair>* conSet = getRoleDomainRangeImpliedConceptSet(role, domain, answererContext); |
| 2563 |
if (conSet) { |
| 2564 |
return conSet->contains(TConceptNegPair(concept, negation)); |
| 2565 |
} |
| 2566 |
return false; |
| 2567 |
} |
| 2568 |
|
| 2569 |
|
| 2570 |
QSet<TConceptNegPair>* COptimizedComplexExpressionAnsweringHandler::getRoleDomainRangeImpliedConceptSet(CRole* role, bool domain, CAnswererContext* answererContext) { |
| 2571 |
QSet<TConceptNegPair>* conSet = nullptr; |
| 2572 |
|
| 2573 |
CRole* domainCheckingRole = role; |
| 2574 |
if (!domain) { |
| 2575 |
domainCheckingRole = domainCheckingRole->getInverseRole(); |
| 2576 |
} |
| 2577 |
|
| 2578 |
QHash<CRole*, QSet<TConceptNegPair>*>* roleDomainImpliedConceptSetHash = mOntoAnsweringItem->getRoleDomainImpliedConceptSetHash(); |
| 2579 |
if (roleDomainImpliedConceptSetHash) { |
| 2580 |
QSet<TConceptNegPair>*& domConSet = (*roleDomainImpliedConceptSetHash)[domainCheckingRole]; |
| 2581 |
if (!domConSet) { |
| 2582 |
domConSet = new QSet<TConceptNegPair>(); |
| 2583 |
|
| 2584 |
for (CSortedNegLinker<CRole*>* superRoleIt = domainCheckingRole->getIndirectSuperRoleList(); superRoleIt; superRoleIt = superRoleIt->getNext()) { |
| 2585 |
CRole* superRole = superRoleIt->getData(); |
| 2586 |
bool superRoleInversed = superRoleIt->isNegated(); |
| 2587 |
for (CSortedNegLinker<CConcept*>* domainConceptLinkerIt = superRole->getDomainRangeConceptList(superRoleInversed); domainConceptLinkerIt; domainConceptLinkerIt = domainConceptLinkerIt->getNext()) { |
| 2588 |
CConcept* domCon = domainConceptLinkerIt->getData(); |
| 2589 |
bool domConNeg = domainConceptLinkerIt->isNegated(); |
| 2590 |
|
| 2591 |
if (!domConSet->contains(TConceptNegPair(domCon, domConNeg))) { |
| 2592 |
|
| 2593 |
QList<TConceptNegPair> processingList; |
| 2594 |
QSet<TConceptNegPair> processingSet; |
| 2595 |
|
| 2596 |
processingList.append(TConceptNegPair(domCon, domConNeg)); |
| 2597 |
domConSet->insert(TConceptNegPair(domCon, domConNeg)); |
| 2598 |
|
| 2599 |
while (!processingList.isEmpty()) { |
| 2600 |
|
| 2601 |
TConceptNegPair proConNegPair = processingList.takeFirst(); |
| 2602 |
CConcept* testCon = proConNegPair.first; |
| 2603 |
bool testConNeg = proConNegPair.second; |
| 2604 |
|
| 2605 |
if (!testConNeg && testCon->hasClassName()) { |
| 2606 |
CHierarchyNode* conHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getHierarchyNode(testCon, false); |
| 2607 |
if (conHierNode) { |
| 2608 |
for (CHierarchyNode* superHierNode : *conHierNode->getParentNodeSet()) { |
| 2609 |
if (!domConSet->contains(TConceptNegPair(superHierNode->getOneEquivalentConcept(), false))) { |
| 2610 |
domConSet->insert(TConceptNegPair(superHierNode->getOneEquivalentConcept(), false)); |
| 2611 |
processingList.append(TConceptNegPair(superHierNode->getOneEquivalentConcept(), false)); |
| 2612 |
} |
| 2613 |
} |
| 2614 |
for (CConcept* eqCon : *conHierNode->getEquivalentConceptList()) { |
| 2615 |
if (!domConSet->contains(TConceptNegPair(eqCon, false))) { |
| 2616 |
domConSet->insert(TConceptNegPair(eqCon, false)); |
| 2617 |
processingList.append(TConceptNegPair(eqCon, false)); |
| 2618 |
} |
| 2619 |
} |
| 2620 |
} |
| 2621 |
} |
| 2622 |
CConceptOperator* testConOp = testCon->getConceptOperator(); |
| 2623 |
if (!testConNeg && testConOp->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_TRIG_AND_AQAND_TYPE)) { |
| 2624 |
for (CSortedNegLinker<CConcept*>* opConLinkerIt = testCon->getOperandList(); opConLinkerIt; opConLinkerIt = opConLinkerIt->getNext()) { |
| 2625 |
CConcept* opCon = opConLinkerIt->getData(); |
| 2626 |
bool opConNeg = opConLinkerIt->isNegated(); |
| 2627 |
if (!domConSet->contains(TConceptNegPair(opCon, opConNeg))) { |
| 2628 |
domConSet->insert(TConceptNegPair(opCon, opConNeg)); |
| 2629 |
processingList.append(TConceptNegPair(opCon, opConNeg)); |
| 2630 |
} |
| 2631 |
} |
| 2632 |
} |
| 2633 |
} |
| 2634 |
} |
| 2635 |
} |
| 2636 |
} |
| 2637 |
} |
| 2638 |
conSet = domConSet; |
| 2639 |
} |
| 2640 |
|
| 2641 |
return conSet; |
| 2642 |
} |
| 2643 |
|
| 2644 |
|
| 2645 |
bool COptimizedComplexExpressionAnsweringHandler::checkExistentiallyOccuringRoles(CAnswererContext* answererContext) { |
| 2646 |
QString statExistOccurRoleNamesString; |
| 2647 |
QString existOccurRoleNamesString; |
| 2648 |
QString oneExistTypeOccurRoleNamesString; |
| 2649 |
CRoleVector* roleVec = mOntoAnsweringItem->getOntology()->getRBox()->getRoleVector(false); |
| 2650 |
cint64 ontologyId = mOntoAnsweringItem->getOntology()->getOntologyID(); |
| 2651 |
COccurrenceStatisticsCacheReader* occStatsCacheReader = answererContext->getAnsweringCalculationHandler()->getOccurrenceStatisticsCacheReader(); |
| 2652 |
CRoleRealization* roleReal = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 2653 |
for (CRole* role : *mOntoAnsweringItem->getOntology()->getRBox()->getActivePropertyRoleSet(false)) { |
| 2654 |
if (!role->isDataRole()) { |
| 2655 |
COccurrenceStatisticsRoleData roleOccStatsData = occStatsCacheReader->getAccummulatedRoleDataOccurrenceStatistics(ontologyId, role->getRoleTag()); |
| 2656 |
bool oneExist = false; |
| 2657 |
if (roleOccStatsData.getExistentialInstanceOccurrencesCount() > 0) { |
| 2658 |
if (role->getNameLinker()) { |
| 2659 |
QString roleName = CIRIName::getRecentIRIName(role->getNameLinker()); |
| 2660 |
statExistOccurRoleNamesString += QString("%1\r\n").arg(roleName); |
| 2661 |
oneExist = true; |
| 2662 |
} |
| 2663 |
} |
| 2664 |
if (roleReal && roleReal->hasExistentiallyLinkedRoleInstances(role, false)) { |
| 2665 |
if (role->getNameLinker()) { |
| 2666 |
QString roleName = CIRIName::getRecentIRIName(role->getNameLinker()); |
| 2667 |
existOccurRoleNamesString += QString("%1\r\n").arg(roleName); |
| 2668 |
oneExist = true; |
| 2669 |
} |
| 2670 |
} |
| 2671 |
if (oneExist) { |
| 2672 |
QString roleName = CIRIName::getRecentIRIName(role->getNameLinker()); |
| 2673 |
oneExistTypeOccurRoleNamesString += QString("%1\r\n").arg(roleName); |
| 2674 |
} |
| 2675 |
} |
| 2676 |
} |
| 2677 |
mDebugOneExistTypeOccurRoleNamesString = oneExistTypeOccurRoleNamesString; |
| 2678 |
bool debug = true; |
| 2679 |
return debug; |
| 2680 |
} |
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
bool COptimizedComplexExpressionAnsweringHandler::tryAnonymousToIndividualVariablesConversion(QSet<CExpressionVariable *> &anonymousIndiVariableSet, QSet<CExpressionVariable *> &varExpSet, bool distinct, CAnswererContext* answererContext, QHash<CExpressionVariable *, CAxiomExpression *> &varExpAxiomExpHash, bool& allAnonymousVariables, QSet<CExpressionVariable*>& convertedVariableSet) { |
| 2685 |
#ifndef KONCLUDE_FORCE_ALL_DEBUG_DEACTIVATED |
| 2686 |
checkExistentiallyOccuringRoles(answererContext); |
| 2687 |
#endif |
| 2688 |
bool updateIndiVarAssPropLists = false; |
| 2689 |
QSet<CExpressionVariable*> backupAnonymousIndiVariableSet(anonymousIndiVariableSet); |
| 2690 |
cint64 originalAnonymousVariableCount = anonymousIndiVariableSet.size(); |
| 2691 |
if (mConfAnonymousToDistinguishedVariablesConversion && mConfOccurrenceStatisticsCollection && (allAnonymousVariables || distinct)) { |
| 2692 |
// identify those anonymous variables for which the related concept and role terms only occur on individual nodes |
| 2693 |
COccurrenceStatisticsCacheReader* occStatsCacheReader = answererContext->getAnsweringCalculationHandler()->getOccurrenceStatisticsCacheReader(); |
| 2694 |
cint64 ontologyId = mOntoAnsweringItem->getOntology()->getOntologyID(); |
| 2695 |
for (QSet<CExpressionVariable*>::iterator itAnonIndiVar = anonymousIndiVariableSet.begin(); itAnonIndiVar != anonymousIndiVariableSet.end(); ) { |
| 2696 |
|
| 2697 |
CExpressionVariable* annonyomousIndiVar(*itAnonIndiVar); |
| 2698 |
QList<CAxiomExpression*> expressions = varExpAxiomExpHash.values(annonyomousIndiVar); |
| 2699 |
bool convertAnonymousVarToIndiVar = false; |
| 2700 |
for (CAxiomExpression* assExp : expressions) { |
| 2701 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 2702 |
if (propAssExp) { |
| 2703 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 2704 |
if (dynamic_cast<CObjectPropertyExpression*>(propExp)) { |
| 2705 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 2706 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 2707 |
// TODO: correctly resolve inverses |
| 2708 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value((CObjectPropertyTermExpression*)propExp); |
| 2709 |
if (!role->isComplexRole()) { |
| 2710 |
bool inversed = true; |
| 2711 |
CIndividualVariableExpression* otherVarExp = firstVarExp; |
| 2712 |
if (firstVarExp == annonyomousIndiVar) { |
| 2713 |
otherVarExp = secondVarExp; |
| 2714 |
inversed = false; |
| 2715 |
} |
| 2716 |
if (inversed) { |
| 2717 |
role = role->getInverseRole(); |
| 2718 |
} |
| 2719 |
COccurrenceStatisticsRoleData roleOccStatsData = occStatsCacheReader->getAccummulatedRoleDataOccurrenceStatistics(ontologyId, role->getRoleTag()); |
| 2720 |
if (roleOccStatsData.getExistentialInstanceOccurrencesCount() <= 0) { |
| 2721 |
convertAnonymousVarToIndiVar = true; |
| 2722 |
break; |
| 2723 |
} |
| 2724 |
} |
| 2725 |
} |
| 2726 |
} |
| 2727 |
|
| 2728 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 2729 |
if (classAssExp) { |
| 2730 |
CClassTermExpression* classExp = classAssExp->getClassTermExpression(); |
| 2731 |
if (dynamic_cast<CClassExpression*>(classExp)) { |
| 2732 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value((CClassTermExpression*)classExp); |
| 2733 |
if (concept->getOperatorCode() == CCEQ) { |
| 2734 |
concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getTBox()->getEquivalentConceptCandidateHash(false)->value(concept); |
| 2735 |
} |
| 2736 |
COccurrenceStatisticsConceptData conceptOccStatsData = occStatsCacheReader->getAccummulatedConceptDataOccurrenceStatistics(ontologyId, concept->getConceptTag()); |
| 2737 |
if (conceptOccStatsData.getExistentialInstanceOccurrencesCount() <= 0) { |
| 2738 |
convertAnonymousVarToIndiVar = true; |
| 2739 |
break; |
| 2740 |
} |
| 2741 |
} |
| 2742 |
} |
| 2743 |
|
| 2744 |
} |
| 2745 |
|
| 2746 |
if (convertAnonymousVarToIndiVar) { |
| 2747 |
convertedVariableSet.insert(annonyomousIndiVar); |
| 2748 |
itAnonIndiVar = anonymousIndiVariableSet.erase(itAnonIndiVar); |
| 2749 |
} else { |
| 2750 |
++itAnonIndiVar; |
| 2751 |
} |
| 2752 |
|
| 2753 |
} |
| 2754 |
} |
| 2755 |
|
| 2756 |
|
| 2757 |
CRoleRealization* roleReal = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 2758 |
if (mConfAnonymousToDistinguishedVariablesConversion && roleReal && (allAnonymousVariables || distinct)) { |
| 2759 |
for (QSet<CExpressionVariable*>::iterator itAnonIndiVar = anonymousIndiVariableSet.begin(); itAnonIndiVar != anonymousIndiVariableSet.end(); ) { |
| 2760 |
bool convertToDistinguishedVariable = false; |
| 2761 |
|
| 2762 |
CExpressionVariable* annonyomousIndiVar(*itAnonIndiVar); |
| 2763 |
QList<CAxiomExpression*> expressions = varExpAxiomExpHash.values(annonyomousIndiVar); |
| 2764 |
for (CAxiomExpression* assExp : expressions) { |
| 2765 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 2766 |
if (propAssExp) { |
| 2767 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 2768 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 2769 |
if (firstVarExp && secondVarExp) { |
| 2770 |
bool inversed = false; |
| 2771 |
CIndividualVariableExpression* otherVarExp = firstVarExp; |
| 2772 |
if (firstVarExp == annonyomousIndiVar) { |
| 2773 |
otherVarExp = secondVarExp; |
| 2774 |
inversed = true; |
| 2775 |
} |
| 2776 |
if (!anonymousIndiVariableSet.contains(otherVarExp)) { |
| 2777 |
// check whether role is linking to existential individuals |
| 2778 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 2779 |
if (dynamic_cast<CObjectPropertyExpression*>(propExp)) { |
| 2780 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value((CObjectPropertyTermExpression*)propExp); |
| 2781 |
if (!roleReal->hasExistentiallyLinkedRoleInstances(role, inversed)) { |
| 2782 |
convertToDistinguishedVariable = true; |
| 2783 |
break; |
| 2784 |
} |
| 2785 |
} |
| 2786 |
} |
| 2787 |
} |
| 2788 |
} |
| 2789 |
} |
| 2790 |
|
| 2791 |
if (convertToDistinguishedVariable) { |
| 2792 |
convertedVariableSet.insert(annonyomousIndiVar); |
| 2793 |
anonymousIndiVariableSet.erase(itAnonIndiVar); |
| 2794 |
itAnonIndiVar = anonymousIndiVariableSet.begin(); |
| 2795 |
} else { |
| 2796 |
++itAnonIndiVar; |
| 2797 |
} |
| 2798 |
} |
| 2799 |
} |
| 2800 |
|
| 2801 |
cint64 reducedAnonymousVariableCount = anonymousIndiVariableSet.size(); |
| 2802 |
if (originalAnonymousVariableCount != reducedAnonymousVariableCount) { |
| 2803 |
updateIndiVarAssPropLists = true; |
| 2804 |
if (allAnonymousVariables && mConfAnonymousToDistinguishedVariablesOnlyFullConversion && reducedAnonymousVariableCount > 0) { |
| 2805 |
anonymousIndiVariableSet = backupAnonymousIndiVariableSet; |
| 2806 |
updateIndiVarAssPropLists = false; |
| 2807 |
if (mConfExtendedLogging) { |
| 2808 |
LOG(INFO, getDomain(), logTr("No conversion of anonymous variables to distinguished (non-answer) variables since it is only possible for %1.").arg(originalAnonymousVariableCount - reducedAnonymousVariableCount), this); |
| 2809 |
} |
| 2810 |
} else if (mConfExtendedLogging) { |
| 2811 |
LOG(INFO, getDomain(), logTr("Interpreting %1 anonymous variables as distinguished (non-answer) variables.").arg(originalAnonymousVariableCount - reducedAnonymousVariableCount), this); |
| 2812 |
} |
| 2813 |
} |
| 2814 |
return updateIndiVarAssPropLists; |
| 2815 |
} |
| 2816 |
|
| 2817 |
bool COptimizedComplexExpressionAnsweringHandler::finishConceptAndAbsorptionItemsGeneration(const QSet<CExpressionVariable *>& varExpSet, const QSet<CExpressionVariable *>& rolledVarExpSet, const QSet<CExpressionVariable *>& anonymousIndiVariableSet, const QHash<CExpressionVariable *, CBuildExpression *>& rebuiltVarClassTermExp, const QHash<CExpressionVariable *, CAxiomExpression *>& varExpAxiomExpHash, |
| 2818 |
bool allAnonymousVariables, const QSet<CExpressionVariable *>& initialAnonymousIndiVariableSet, const QList<CDataPropertyAssertionExpression *>& bothVarDataPropAssPropagationList, const QList<CObjectPropertyAssertionExpression *>& bothVarPropAssPropagationList, const QList<CDataPropertyAssertionExpression *>& onlyDataVarDataPropAssList, COptimizedComplexBuildingIndividualVariableCompositionsItem* varBuildItem, CAnswererContext* answererContext) { |
| 2819 |
|
| 2820 |
bool queryProcessing = false; |
| 2821 |
CConcreteOntology* testingOnto = mOntoAnsweringItem->getTestingOntology(true); |
| 2822 |
CComplexQueryExpressionProcessingData* queryProcessingData = varBuildItem->getQueryProcessingData(); |
| 2823 |
CComplexAssertionsIndividualVariablesAnsweringQuery* compAssIndVarQuery = (CComplexAssertionsIndividualVariablesAnsweringQuery*)queryProcessingData->getQuery(); |
| 2824 |
|
| 2825 |
// building complex concept expressions for concept items |
| 2826 |
QSet<CExpressionVariable*> prepareIndiVarSet; |
| 2827 |
QHash<CExpressionVariable*, CBuildExpression*> individualTriggerUpdatableHash; |
| 2828 |
QList<QPair<CIndividualVariableExpression*, CClassTermExpression*>> varClassInstTestExpList; |
| 2829 |
varClassInstTestExpList = generateConceptItemExpressions(varExpSet, rolledVarExpSet, anonymousIndiVariableSet, rebuiltVarClassTermExp, varExpAxiomExpHash, individualTriggerUpdatableHash, prepareIndiVarSet, queryProcessingData); |
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
// identify sub queries with non-distinguished variables |
| 2835 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*> absorptionBasedHandlingQueryPartDatas; |
| 2836 |
absorptionBasedHandlingQueryPartDatas = generateAbsorptionBasedQueryParts(anonymousIndiVariableSet, allAnonymousVariables, *varBuildItem->getReductionDeniedVariableSet(), rolledVarExpSet, initialAnonymousIndiVariableSet, varExpSet, prepareIndiVarSet, rebuiltVarClassTermExp, varExpAxiomExpHash); |
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
mTestingOntologyBuilder->completeBuilding(); |
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*> entailmentCheckingAbsorptionBasedHandlingQueryPartDatas; |
| 2845 |
for (COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* data : absorptionBasedHandlingQueryPartDatas) { |
| 2846 |
|
| 2847 |
if (!mConfLazyExistentialPartAbsorption) { |
| 2848 |
absorbExistentialQueryPart(data, answererContext); |
| 2849 |
|
| 2850 |
if (data->hasPreparationVariables()) { |
| 2851 |
varBuildItem->addAbsorbedBasedQueryPartItemExtensionHandling(data); |
| 2852 |
} else { |
| 2853 |
varBuildItem->addAbsorbedBasedQueryPartEntailmentCheckingHandling(data); |
| 2854 |
entailmentCheckingAbsorptionBasedHandlingQueryPartDatas.append(data); |
| 2855 |
} |
| 2856 |
} else { |
| 2857 |
varBuildItem->addAbsorbingQueryPart(data); |
| 2858 |
} |
| 2859 |
} |
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
QList<QPair<CIndividualVariableExpression*, TConceptNegPair>> varConNegInstTestExpList; |
| 2864 |
varConNegInstTestExpList = upgradeExistTopToIndividualTriggers(varClassInstTestExpList, individualTriggerUpdatableHash, answererContext); |
| 2865 |
|
| 2866 |
|
| 2867 |
if (mConfDebugTestingOntologyWriting) { |
| 2868 |
COntologyTextFormater::writeOntologyToFile(mOntoAnsweringItem->getTestingOntology(), "Debugging/Answering/Absorbed-Query-Expressions.txt"); |
| 2869 |
} |
| 2870 |
|
| 2871 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 2872 |
|
| 2873 |
queryProcessing |= schedulingConceptItemsProcessingForBuildItem(varConNegInstTestExpList, compAssIndVarQuery, varBuildItem); |
| 2874 |
varBuildItem->addVariableDataPropertyAssertions(bothVarDataPropAssPropagationList); |
| 2875 |
varBuildItem->addVariablePropertyAssertions(bothVarPropAssPropagationList); |
| 2876 |
varBuildItem->addBasicDataPropertyAssertions(onlyDataVarDataPropAssList); |
| 2877 |
|
| 2878 |
|
| 2879 |
if (mConfDebugTestingOntologyWriting) { |
| 2880 |
COntologyTextFormater::writeOntologyToFile(mOntoAnsweringItem->getTestingOntology(), "Debugging/Answering/Absorbed-Preprocessed-Query-Expressions.txt"); |
| 2881 |
} |
| 2882 |
|
| 2883 |
for (COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* data : entailmentCheckingAbsorptionBasedHandlingQueryPartDatas) { |
| 2884 |
createAbsorbedQueryPartEntailmentTest(data, queryProcessingData, answererContext); |
| 2885 |
} |
| 2886 |
|
| 2887 |
if (!queryProcessing) { |
| 2888 |
varBuildItem->setProcessingQueued(true); |
| 2889 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(varBuildItem); |
| 2890 |
queryProcessing = true; |
| 2891 |
} |
| 2892 |
return queryProcessing; |
| 2893 |
} |
| 2894 |
|
| 2895 |
|
| 2896 |
|
| 2897 |
|
| 2898 |
bool COptimizedComplexExpressionAnsweringHandler::schedulingConceptItemsProcessingForBuildItem(const QList<QPair<CIndividualVariableExpression *, TConceptNegPair>> &varConNegInstTestExpList, CComplexAssertionsIndividualVariablesAnsweringQuery* compAssIndVarQuery, COptimizedComplexBuildingIndividualVariableCompositionsItem* varBuildItem) { |
| 2899 |
bool queryProcessing = false; |
| 2900 |
for (QPair<CIndividualVariableExpression*, TConceptNegPair> varConNegPair : varConNegInstTestExpList) { |
| 2901 |
TConceptNegPair conNegPair = varConNegPair.second; |
| 2902 |
CIndividualVariableExpression* varTermExp = varConNegPair.first; |
| 2903 |
|
| 2904 |
CConcept* testingConcept = conNegPair.first; |
| 2905 |
bool testingNegation = conNegPair.second; |
| 2906 |
|
| 2907 |
cint64 requiredInstancesCount = 1; |
| 2908 |
if (varConNegInstTestExpList.size() == 1 && compAssIndVarQuery && compAssIndVarQuery->getResultLimitIncludingOffset() == -1) { |
| 2909 |
// request all if the conjunctive query can be reduced to a complex concept instances query |
| 2910 |
requiredInstancesCount = -1; |
| 2911 |
} |
| 2912 |
|
| 2913 |
COptimizedComplexConceptItem* assocConceptItem = nullptr; |
| 2914 |
queryProcessing |= initializeComplexConceptQueryProcessing(nullptr, varBuildItem, testingConcept, testingNegation, false, false, false, false, false, requiredInstancesCount, &assocConceptItem); |
| 2915 |
|
| 2916 |
if (assocConceptItem && mConfExtendedLogging) { |
| 2917 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 2918 |
assocConceptItem->debugVariableNameUseList.append(varTermExp->getName()); |
| 2919 |
#endif |
| 2920 |
LOG(INFO, getDomain(), logTr("Using complex concept item %2 for computing bounds of variable %1.").arg(varTermExp->getName()).arg(assocConceptItem->getConceptItemId()), this); |
| 2921 |
} |
| 2922 |
|
| 2923 |
varBuildItem->addVariableComplexConceptItem(varTermExp, assocConceptItem); |
| 2924 |
} |
| 2925 |
return queryProcessing; |
| 2926 |
} |
| 2927 |
|
| 2928 |
QList<QPair<CIndividualVariableExpression*, TConceptNegPair>> COptimizedComplexExpressionAnsweringHandler::upgradeExistTopToIndividualTriggers(QList<QPair<CIndividualVariableExpression *, CClassTermExpression *>> varClassInstTestExpList, QHash<CExpressionVariable *, CBuildExpression *> individualTriggerUpdatableHash, CAnswererContext* answererContext) { |
| 2929 |
QList<QPair<CIndividualVariableExpression*, TConceptNegPair>> varConNegInstTestExpList; |
| 2930 |
// upgrade \exits r.\top concepts to use individual trigger if possible |
| 2931 |
for (QPair<CIndividualVariableExpression*, CClassTermExpression*> varClassPair : varClassInstTestExpList) { |
| 2932 |
CClassTermExpression* classTermExp = varClassPair.second; |
| 2933 |
CIndividualVariableExpression* varTermExp = varClassPair.first; |
| 2934 |
|
| 2935 |
TConceptNegPair upgradedConNegPair = upgradeExistTopToIndividualTrigger(classTermExp, varTermExp, &individualTriggerUpdatableHash, answererContext); |
| 2936 |
varConNegInstTestExpList.append(QPair<CIndividualVariableExpression*, TConceptNegPair>(varTermExp, upgradedConNegPair)); |
| 2937 |
|
| 2938 |
} |
| 2939 |
return varConNegInstTestExpList; |
| 2940 |
} |
| 2941 |
|
| 2942 |
bool COptimizedComplexExpressionAnsweringHandler::identifyNonInstantiation(const QList<CAxiomExpression *>& assExps, const QSet<CExpressionVariable *> &answerIndiVariableSet, CAnswererContext* answererContext) { |
| 2943 |
// identify those anonymous variables for which the related concept and role terms only occur on individual nodes |
| 2944 |
bool nonInstantiatedTerm = false; |
| 2945 |
COccurrenceStatisticsCacheReader* occStatsCacheReader = answererContext->getAnsweringCalculationHandler()->getOccurrenceStatisticsCacheReader(); |
| 2946 |
cint64 ontologyId = mOntoAnsweringItem->getOntology()->getOntologyID(); |
| 2947 |
for (CAxiomExpression* assExp : assExps) { |
| 2948 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 2949 |
if (propAssExp) { |
| 2950 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 2951 |
if (dynamic_cast<CObjectPropertyExpression*>(propExp)) { |
| 2952 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 2953 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 2954 |
// TODO: correctly resolve inverses |
| 2955 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value((CObjectPropertyTermExpression*)propExp); |
| 2956 |
if (role && !role->isComplexRole()) { |
| 2957 |
CRole* inverseRole = role->getInverseRole(); |
| 2958 |
COccurrenceStatisticsRoleData roleOccStatsData = occStatsCacheReader->getAccummulatedRoleDataOccurrenceStatistics(ontologyId, role->getRoleTag()); |
| 2959 |
if (roleOccStatsData.getExistentialInstanceOccurrencesCount() <= 0 && roleOccStatsData.getIndividualInstanceOccurrencesCount() <= 0) { |
| 2960 |
nonInstantiatedTerm = true; |
| 2961 |
break; |
| 2962 |
} |
| 2963 |
if (roleOccStatsData.getIndividualInstanceOccurrencesCount() <= 0 && firstVarExp && answerIndiVariableSet.contains(firstVarExp)) { |
| 2964 |
nonInstantiatedTerm = true; |
| 2965 |
break; |
| 2966 |
} |
| 2967 |
if (secondVarExp && answerIndiVariableSet.contains(secondVarExp)) { |
| 2968 |
COccurrenceStatisticsRoleData roleOccStatsData = occStatsCacheReader->getAccummulatedRoleDataOccurrenceStatistics(ontologyId, inverseRole->getRoleTag()); |
| 2969 |
if (roleOccStatsData.getIndividualInstanceOccurrencesCount() <= 0) { |
| 2970 |
nonInstantiatedTerm = true; |
| 2971 |
break; |
| 2972 |
} |
| 2973 |
} |
| 2974 |
} |
| 2975 |
} |
| 2976 |
} |
| 2977 |
|
| 2978 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 2979 |
if (classAssExp) { |
| 2980 |
CClassTermExpression* classExp = classAssExp->getClassTermExpression(); |
| 2981 |
if (dynamic_cast<CClassExpression*>(classExp)) { |
| 2982 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value((CClassTermExpression*)classExp); |
| 2983 |
if (concept->getOperatorCode() == CCEQ) { |
| 2984 |
concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getTBox()->getEquivalentConceptCandidateHash(false)->value(concept); |
| 2985 |
} |
| 2986 |
if (concept) { |
| 2987 |
COccurrenceStatisticsConceptData conceptOccStatsData = occStatsCacheReader->getAccummulatedConceptDataOccurrenceStatistics(ontologyId, concept->getConceptTag()); |
| 2988 |
if (conceptOccStatsData.getExistentialInstanceOccurrencesCount() <= 0 && conceptOccStatsData.getIndividualInstanceOccurrencesCount() <= 0) { |
| 2989 |
nonInstantiatedTerm = true; |
| 2990 |
break; |
| 2991 |
} |
| 2992 |
CIndividualVariableExpression* varExp = dynamic_cast<CIndividualVariableExpression*>(classAssExp->getIndividualTermExpression()); |
| 2993 |
if (conceptOccStatsData.getIndividualInstanceOccurrencesCount() <= 0 && varExp && answerIndiVariableSet.contains(varExp)) { |
| 2994 |
nonInstantiatedTerm = true; |
| 2995 |
break; |
| 2996 |
} |
| 2997 |
} |
| 2998 |
} |
| 2999 |
} |
| 3000 |
|
| 3001 |
} |
| 3002 |
return nonInstantiatedTerm; |
| 3003 |
} |
| 3004 |
|
| 3005 |
|
| 3006 |
bool COptimizedComplexExpressionAnsweringHandler::checkNonTrivialAbsorptionPropagationExpression(CBuildExpression* expression) { |
| 3007 |
if (!expression) { |
| 3008 |
return false; |
| 3009 |
} |
| 3010 |
CClassTermExpression* classTermExp = dynamic_cast<CClassTermExpression*>(expression); |
| 3011 |
if (!classTermExp) { |
| 3012 |
return true; |
| 3013 |
} |
| 3014 |
CClassExpression* classExp = dynamic_cast<CClassExpression*>(expression); |
| 3015 |
if (classExp) { |
| 3016 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value((CClassTermExpression*)classExp); |
| 3017 |
if (concept->getOperatorCode() == CCEQ) { |
| 3018 |
return true; |
| 3019 |
} |
| 3020 |
return false; |
| 3021 |
} |
| 3022 |
CObjectIntersectionOfExpression* intOfExp = dynamic_cast<CObjectIntersectionOfExpression*>(expression); |
| 3023 |
if (intOfExp) { |
| 3024 |
for (CClassTermExpression* intClassTermExp : *intOfExp->getClassTermExpressionList()) { |
| 3025 |
if (checkNonTrivialAbsorptionPropagationExpression(intClassTermExp)) { |
| 3026 |
return true; |
| 3027 |
} |
| 3028 |
} |
| 3029 |
return false; |
| 3030 |
} |
| 3031 |
CObjectSomeValuesFromExpression* someValueOfExp = dynamic_cast<CObjectSomeValuesFromExpression*>(expression); |
| 3032 |
if (someValueOfExp) { |
| 3033 |
return checkNonTrivialAbsorptionPropagationExpression(someValueOfExp->getClassTermExpression()); |
| 3034 |
} |
| 3035 |
return true; |
| 3036 |
} |
| 3037 |
|
| 3038 |
|
| 3039 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData *> COptimizedComplexExpressionAnsweringHandler::generateAbsorptionBasedQueryParts(const QSet<CExpressionVariable *> &anonymousIndiVariableSet, bool allAnonymousVariables, QSet<CExpressionVariable *> &reductionForbiddenVarSet, const QSet<CExpressionVariable *> &rolledVarExpSet, |
| 3040 |
const QSet<CExpressionVariable *>& initialAnonymousIndiVariableSet, const QSet<CExpressionVariable *>& varExpSet, const QSet<CExpressionVariable *>& prepareIndiVarSet, const QHash<CExpressionVariable *, CBuildExpression *> &rebuiltVarClassTermExp, const QHash<CExpressionVariable *, CAxiomExpression *> &varExpAxiomExpHash) { |
| 3041 |
|
| 3042 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData *> absorptionBasedHandlingQueryPartDatas; |
| 3043 |
QSet<CExpressionVariable*> anonymVarExpSubQueryIncludedSet; |
| 3044 |
QSet<CExpressionVariable*> absorptionAnonymousInterpretedIndiVariableSet(anonymousIndiVariableSet); |
| 3045 |
// restricted variable set to only those anonymous variables that actually have to be absorbed |
| 3046 |
QSet<CExpressionVariable*> restrictedAbsorptionAnonymousInterpretedIndiVariableSet(anonymousIndiVariableSet); |
| 3047 |
if (mConfVariableAbsorptionOverFullQuery && allAnonymousVariables && !anonymousIndiVariableSet.isEmpty() && anonymousIndiVariableSet.size() != rolledVarExpSet.size()) { |
| 3048 |
absorptionAnonymousInterpretedIndiVariableSet = initialAnonymousIndiVariableSet; |
| 3049 |
} |
| 3050 |
// identify sub queries with non-distinguished variables |
| 3051 |
for (CExpressionVariable* varExp : varExpSet) { |
| 3052 |
|
| 3053 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(varExp); |
| 3054 |
|
| 3055 |
if (indiVarExp && !rolledVarExpSet.contains(indiVarExp) && !anonymVarExpSubQueryIncludedSet.contains(indiVarExp) && absorptionAnonymousInterpretedIndiVariableSet.contains(varExp)) { |
| 3056 |
|
| 3057 |
QSet<CExpressionVariable*> anonymVarExpSubQueryProcessingSet; |
| 3058 |
QList<CExpressionVariable*> anonymVarExpSubQueryProcessingList; |
| 3059 |
anonymVarExpSubQueryIncludedSet.insert(varExp); |
| 3060 |
anonymVarExpSubQueryProcessingSet.insert(varExp); |
| 3061 |
anonymVarExpSubQueryProcessingList.append(varExp); |
| 3062 |
|
| 3063 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionBasedQueryPartData = new COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData(absorptionAnonymousInterpretedIndiVariableSet, restrictedAbsorptionAnonymousInterpretedIndiVariableSet); |
| 3064 |
|
| 3065 |
while (!anonymVarExpSubQueryProcessingList.isEmpty()) { |
| 3066 |
|
| 3067 |
CExpressionVariable* processingVarExp = anonymVarExpSubQueryProcessingList.takeFirst(); |
| 3068 |
QList<CBuildExpression*> varClassExpList(rebuiltVarClassTermExp.values(processingVarExp)); |
| 3069 |
|
| 3070 |
|
| 3071 |
for (CBuildExpression* classExp: varClassExpList) { |
| 3072 |
if (checkNonTrivialAbsorptionPropagationExpression(classExp)) { |
| 3073 |
absorptionBasedQueryPartData->setNonTrivialAbsorptionPropagation(true); |
| 3074 |
break; |
| 3075 |
} |
| 3076 |
} |
| 3077 |
|
| 3078 |
reductionForbiddenVarSet.insert(processingVarExp); |
| 3079 |
if (prepareIndiVarSet.contains(processingVarExp)) { |
| 3080 |
absorptionBasedQueryPartData->getPrepareVariableSet()->insert(processingVarExp); |
| 3081 |
} |
| 3082 |
|
| 3083 |
if (absorptionAnonymousInterpretedIndiVariableSet.contains(processingVarExp)) { |
| 3084 |
|
| 3085 |
QList<CAxiomExpression*> axiomList = varExpAxiomExpHash.values(processingVarExp); |
| 3086 |
for (CAxiomExpression* assExp : axiomList) { |
| 3087 |
|
| 3088 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 3089 |
if (propAssExp) { |
| 3090 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 3091 |
CIndividualTermExpression* firstIndiExp = propAssExp->getFirstIndividualTermExpression(); |
| 3092 |
CIndividualTermExpression* secondIndiExp = propAssExp->getSecondIndividualTermExpression(); |
| 3093 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(firstIndiExp); |
| 3094 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(secondIndiExp); |
| 3095 |
if (firstVarExp == processingVarExp && secondVarExp == processingVarExp) { |
| 3096 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value((CObjectPropertyTermExpression*)propExp); |
| 3097 |
if (!role->isComplexRole()) { |
| 3098 |
varClassExpList.append(mTestingOntologyBuilder->getObjectHasSelf(propExp)); |
| 3099 |
} else { |
| 3100 |
absorptionBasedQueryPartData->addVariableSelfPropertyAssertion(propAssExp); |
| 3101 |
} |
| 3102 |
} else if (firstVarExp == processingVarExp) { |
| 3103 |
if (secondVarExp == nullptr) { |
| 3104 |
varClassExpList.append(mTestingOntologyBuilder->getObjectHasValue(propExp, secondIndiExp)); |
| 3105 |
} else if (!rolledVarExpSet.contains(secondVarExp)) { |
| 3106 |
absorptionBasedQueryPartData->addVariableNeighbouringPropertyAssertion(propAssExp); |
| 3107 |
if (!anonymVarExpSubQueryProcessingSet.contains(secondVarExp)) { |
| 3108 |
anonymVarExpSubQueryProcessingSet.insert(secondVarExp); |
| 3109 |
anonymVarExpSubQueryIncludedSet.insert(secondVarExp); |
| 3110 |
anonymVarExpSubQueryProcessingList.append(secondVarExp); |
| 3111 |
} |
| 3112 |
} |
| 3113 |
} else if (secondVarExp == processingVarExp) { |
| 3114 |
if (firstVarExp == nullptr) { |
| 3115 |
varClassExpList.append(mTestingOntologyBuilder->getObjectHasValue(mTestingOntologyBuilder->getInverseObjectPropertyOf(propExp), firstIndiExp)); |
| 3116 |
} else if (!rolledVarExpSet.contains(firstVarExp)) { |
| 3117 |
absorptionBasedQueryPartData->addVariableNeighbouringPropertyAssertion(propAssExp); |
| 3118 |
if (!anonymVarExpSubQueryProcessingSet.contains(firstVarExp)) { |
| 3119 |
anonymVarExpSubQueryProcessingSet.insert(firstVarExp); |
| 3120 |
anonymVarExpSubQueryIncludedSet.insert(firstVarExp); |
| 3121 |
anonymVarExpSubQueryProcessingList.append(firstVarExp); |
| 3122 |
} |
| 3123 |
} |
| 3124 |
} |
| 3125 |
} |
| 3126 |
|
| 3127 |
} |
| 3128 |
} |
| 3129 |
absorptionBasedQueryPartData->addVariableClassExpressions(processingVarExp, varClassExpList); |
| 3130 |
|
| 3131 |
|
| 3132 |
} |
| 3133 |
|
| 3134 |
absorptionBasedHandlingQueryPartDatas.append(absorptionBasedQueryPartData); |
| 3135 |
} |
| 3136 |
} |
| 3137 |
return absorptionBasedHandlingQueryPartDatas; |
| 3138 |
} |
| 3139 |
|
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
QHash<CExpressionVariable*, CBuildExpression*> COptimizedComplexExpressionAnsweringHandler::rebuildVariablesClassTermExpressions(const QSet<CExpressionVariable *>& varExpSet, const QSet<CExpressionVariable *> &rolledVarExpSet, QHash<CExpressionVariable *, CAxiomExpression *> &varExpAxiomExpHash, QHash<CExpressionVariable *, CBuildExpression *> &varRolledUpClassExpHash) { |
| 3148 |
|
| 3149 |
QHash<CExpressionVariable*, CBuildExpression*> rebuildVarExpClassTermExpHash; |
| 3150 |
for (CExpressionVariable* varExp : varExpSet) { |
| 3151 |
if (!rolledVarExpSet.contains(varExp)) { |
| 3152 |
QList<CBuildExpression*> instTestingExpList(varRolledUpClassExpHash.values(varExp)); |
| 3153 |
QList<CAxiomExpression*> assExplist = varExpAxiomExpHash.values(varExp); |
| 3154 |
for (CAxiomExpression* assExp : assExplist) { |
| 3155 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 3156 |
if (classAssExp) { |
| 3157 |
instTestingExpList.append(mTestingOntologyBuilder->rebuildExpression(classAssExp->getClassTermExpression())); |
| 3158 |
} |
| 3159 |
|
| 3160 |
CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 3161 |
if (dataPropAssExp) { |
| 3162 |
CDataPropertyTermExpression* dataPropTermExp = dataPropAssExp->getDataPropertyTermExpression(); |
| 3163 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 3164 |
CDataLiteralVariableExpression* dataVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 3165 |
if (indiVarExp && !dataVarExp) { |
| 3166 |
CDataLiteralExpression* dataLiteralExp = (CDataLiteralExpression*)dataPropAssExp->getDataLiteralTermExpression(); |
| 3167 |
dataLiteralExp = (CDataLiteralExpression*)mTestingOntologyBuilder->rebuildExpression(dataLiteralExp); |
| 3168 |
instTestingExpList.append(mTestingOntologyBuilder->getDataHasValue(dataPropTermExp, dataLiteralExp)); |
| 3169 |
} |
| 3170 |
} |
| 3171 |
|
| 3172 |
} |
| 3173 |
|
| 3174 |
for (CBuildExpression* exp : instTestingExpList) { |
| 3175 |
rebuildVarExpClassTermExpHash.insertMulti(varExp, exp); |
| 3176 |
} |
| 3177 |
|
| 3178 |
} |
| 3179 |
} |
| 3180 |
|
| 3181 |
|
| 3182 |
return rebuildVarExpClassTermExpHash; |
| 3183 |
} |
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
QList<QPair<CIndividualVariableExpression *, CClassTermExpression *>> COptimizedComplexExpressionAnsweringHandler::generateConceptItemExpressions(const QSet<CExpressionVariable *>& varExpSet, const QSet<CExpressionVariable *> &rolledVarExpSet, const QSet<CExpressionVariable *> &anonymousIndiVariableSet, const QHash<CExpressionVariable *, CBuildExpression *> &varRolledUpClassExpHash, |
| 3191 |
const QHash<CExpressionVariable *, CAxiomExpression *> &varExpAxiomExpHash, QHash<CExpressionVariable *, CBuildExpression *> &individualTriggerUpdatableHash, QSet<CExpressionVariable *> &prepareIndiVarSet, CComplexQueryExpressionProcessingData* queryProcessingData) { |
| 3192 |
|
| 3193 |
CConcreteOntology* testingOnto = mOntoAnsweringItem->getTestingOntology(); |
| 3194 |
CClassTermExpression* topClassTermExp = testingOnto->getBuildData()->getTopClassExpression(); |
| 3195 |
CObjectPropertyTermExpression* topObjPropExp = testingOnto->getBuildData()->getTopObjectPropertyExpression(); |
| 3196 |
CComplexAssertionsIndividualVariablesAnsweringQuery* compAssIndVarQuery = (CComplexAssertionsIndividualVariablesAnsweringQuery*)queryProcessingData->getQuery(); |
| 3197 |
|
| 3198 |
|
| 3199 |
QList<QPair<CIndividualVariableExpression *, CClassTermExpression *>> varClassInstTestExpList; |
| 3200 |
QSet<CExpressionVariable*> conceptTermOmittedIndiVarSet; |
| 3201 |
|
| 3202 |
QSet<CExpressionVariable*> conGenVarExpSet; |
| 3203 |
QList<CExpressionVariable*> conGenVarExpList; |
| 3204 |
for (CExpressionVariable* varExp : *compAssIndVarQuery->getDistinguishedVariableExpressions()) { |
| 3205 |
conGenVarExpList.append(varExp); |
| 3206 |
conGenVarExpSet.insert(varExp); |
| 3207 |
} |
| 3208 |
for (CExpressionVariable* varExp : varExpSet) { |
| 3209 |
if (!conGenVarExpSet.contains(varExp)) { |
| 3210 |
conGenVarExpSet.insert(varExp); |
| 3211 |
conGenVarExpList.prepend(varExp); |
| 3212 |
} |
| 3213 |
} |
| 3214 |
|
| 3215 |
for (CExpressionVariable* varExp : conGenVarExpList) { |
| 3216 |
|
| 3217 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(varExp); |
| 3218 |
if (indiVarExp && !rolledVarExpSet.contains(varExp) && !anonymousIndiVariableSet.contains(varExp)) { |
| 3219 |
CClassTermExpression* instTestingExp = nullptr; |
| 3220 |
QList<CBuildExpression*> instTestingExpList(varRolledUpClassExpHash.values(indiVarExp)); |
| 3221 |
|
| 3222 |
|
| 3223 |
bool conceptTermRequired = true; |
| 3224 |
QList<CAxiomExpression*> assExplist = varExpAxiomExpHash.values(varExp); |
| 3225 |
if (assExplist.size() == 1) { |
| 3226 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExplist.first()); |
| 3227 |
if (propAssExp) { |
| 3228 |
CIndividualVariableExpression* otherVarExp = nullptr; |
| 3229 |
CIndividualTermExpression* firstIndiExp = propAssExp->getFirstIndividualTermExpression(); |
| 3230 |
CIndividualTermExpression* secondIndiExp = propAssExp->getSecondIndividualTermExpression(); |
| 3231 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(firstIndiExp); |
| 3232 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(secondIndiExp); |
| 3233 |
if (firstVarExp && secondVarExp) { |
| 3234 |
otherVarExp = firstVarExp; |
| 3235 |
if (firstVarExp == indiVarExp) { |
| 3236 |
otherVarExp = secondVarExp; |
| 3237 |
} |
| 3238 |
|
| 3239 |
QList<CAxiomExpression*> otherAssExplist = varExpAxiomExpHash.values(otherVarExp); |
| 3240 |
|
| 3241 |
// currently only works if propagated correctly |
| 3242 |
if (otherAssExplist.size() == 1 && !conceptTermOmittedIndiVarSet.contains(otherVarExp)) { |
| 3243 |
conceptTermOmittedIndiVarSet.insert(indiVarExp); |
| 3244 |
conceptTermRequired = false; |
| 3245 |
} |
| 3246 |
|
| 3247 |
} |
| 3248 |
|
| 3249 |
} |
| 3250 |
} |
| 3251 |
|
| 3252 |
if (conceptTermRequired) { |
| 3253 |
for (CAxiomExpression* assExp : assExplist) { |
| 3254 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 3255 |
if (propAssExp) { |
| 3256 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 3257 |
if (propExp != topObjPropExp) { |
| 3258 |
CIndividualTermExpression* firstIndiExp = propAssExp->getFirstIndividualTermExpression(); |
| 3259 |
CIndividualTermExpression* secondIndiExp = propAssExp->getSecondIndividualTermExpression(); |
| 3260 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(firstIndiExp); |
| 3261 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(secondIndiExp); |
| 3262 |
if (firstVarExp == varExp && secondVarExp == varExp) { |
| 3263 |
instTestingExpList.append(mTestingOntologyBuilder->getObjectHasSelf(propExp)); |
| 3264 |
} else if (firstVarExp == varExp) { |
| 3265 |
if (secondVarExp == nullptr) { |
| 3266 |
instTestingExpList.append(mTestingOntologyBuilder->getObjectHasValue(propExp, secondIndiExp)); |
| 3267 |
} else { |
| 3268 |
if (!rolledVarExpSet.contains(secondVarExp)) { |
| 3269 |
CObjectSomeValuesFromExpression* someValuesFromExp = mTestingOntologyBuilder->getObjectSomeValuesFrom(propExp, topClassTermExp); |
| 3270 |
if (!anonymousIndiVariableSet.contains(secondVarExp)) { |
| 3271 |
individualTriggerUpdatableHash.insertMulti(varExp, someValuesFromExp); |
| 3272 |
} |
| 3273 |
instTestingExpList.append(someValuesFromExp); |
| 3274 |
} |
| 3275 |
} |
| 3276 |
} else if (secondVarExp == varExp) { |
| 3277 |
CObjectPropertyTermExpression* invPropExp = nullptr; |
| 3278 |
CRole* role = testingOnto->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp); |
| 3279 |
if (!role || !role->isSymmetric()) { |
| 3280 |
invPropExp = mTestingOntologyBuilder->getInverseObjectPropertyOf(propExp); |
| 3281 |
} else { |
| 3282 |
invPropExp = propExp; |
| 3283 |
} |
| 3284 |
if (firstVarExp == nullptr) { |
| 3285 |
instTestingExpList.append(mTestingOntologyBuilder->getObjectHasValue(invPropExp, firstIndiExp)); |
| 3286 |
} else { |
| 3287 |
if (!rolledVarExpSet.contains(firstVarExp)) { |
| 3288 |
CObjectSomeValuesFromExpression* someValuesFromExp = mTestingOntologyBuilder->getObjectSomeValuesFrom(invPropExp, topClassTermExp); |
| 3289 |
if (!anonymousIndiVariableSet.contains(firstVarExp)) { |
| 3290 |
individualTriggerUpdatableHash.insertMulti(varExp, someValuesFromExp); |
| 3291 |
} |
| 3292 |
instTestingExpList.append(someValuesFromExp); |
| 3293 |
} |
| 3294 |
} |
| 3295 |
} |
| 3296 |
} |
| 3297 |
} |
| 3298 |
|
| 3299 |
CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 3300 |
if (dataPropAssExp) { |
| 3301 |
CDataPropertyTermExpression* dataPropTermExp = dataPropAssExp->getDataPropertyTermExpression(); |
| 3302 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 3303 |
CDataLiteralVariableExpression* dataVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 3304 |
if (indiVarExp && dataVarExp) { |
| 3305 |
instTestingExpList.append(mTestingOntologyBuilder->getDataSomeValuesFrom(dataPropTermExp, mTestingOntologyBuilder->getTopDataRange())); |
| 3306 |
} |
| 3307 |
|
| 3308 |
} |
| 3309 |
} |
| 3310 |
|
| 3311 |
|
| 3312 |
instTestingExp = (CClassTermExpression*)mTestingOntologyBuilder->getObjectIntersectionOf(instTestingExpList); |
| 3313 |
if (instTestingExpList.size() > 1) { |
| 3314 |
instTestingExp = (CClassTermExpression*)mTestingOntologyBuilder->getObjectIntersectionOf(instTestingExpList); |
| 3315 |
} else if (instTestingExpList.isEmpty()) { |
| 3316 |
instTestingExp = mOntoAnsweringItem->getTestingOntology()->getBuildData()->getTopClassExpression(); |
| 3317 |
} else { |
| 3318 |
instTestingExp = (CClassTermExpression*)instTestingExpList.first(); |
| 3319 |
} |
| 3320 |
prepareIndiVarSet.insert(indiVarExp); |
| 3321 |
varClassInstTestExpList.append(QPair<CIndividualVariableExpression*, CClassTermExpression*>(indiVarExp, instTestingExp)); |
| 3322 |
} |
| 3323 |
|
| 3324 |
} |
| 3325 |
|
| 3326 |
} |
| 3327 |
if (!varClassInstTestExpList.isEmpty()) { |
| 3328 |
LOG(INFO, getDomain(), logTr("Building %1 class term expressions for computation of upper/lower bounds based on complex concepts.").arg(varClassInstTestExpList.size()), this); |
| 3329 |
} |
| 3330 |
return varClassInstTestExpList; |
| 3331 |
} |
| 3332 |
|
| 3333 |
void COptimizedComplexExpressionAnsweringHandler::expressionsRollingUp(QSet<CExpressionVariable *> &anonymousIndiVariableSet, QSet<CExpressionVariable *> &rolledVarExpSet, QHash<CExpressionVariable *, CAxiomExpression *> &varExpAxiomExpHash, CConcreteOntology* testingOnto, QHash<CExpressionVariable *, CBuildExpression *> &varRolledUpClassExpHash) { |
| 3334 |
QList<CExpressionVariable*> anonymousIndiVariableProcessingList = anonymousIndiVariableSet.toList(); |
| 3335 |
QSet<CExpressionVariable*> anonymousIndiVariableProcessingSet; |
| 3336 |
CClassTermExpression* topClassTermExp = testingOnto->getBuildData()->getTopClassExpression(); |
| 3337 |
while (!anonymousIndiVariableProcessingList.isEmpty()) { |
| 3338 |
|
| 3339 |
CExpressionVariable* anonyIndiVarExp = anonymousIndiVariableProcessingList.takeFirst(); |
| 3340 |
anonymousIndiVariableProcessingSet.remove(anonyIndiVarExp); |
| 3341 |
|
| 3342 |
if (!rolledVarExpSet.contains(anonyIndiVarExp)) { |
| 3343 |
cint64 propAssPropagationCount = 0; |
| 3344 |
bool rollingUpPossible = true; |
| 3345 |
QList<CAxiomExpression*> axiomList = varExpAxiomExpHash.values(anonyIndiVarExp); |
| 3346 |
for (CAxiomExpression* axiomExp : axiomList) { |
| 3347 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(axiomExp); |
| 3348 |
if (propAssExp) { |
| 3349 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 3350 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 3351 |
CIndividualVariableExpression* otherVarExp = firstVarExp; |
| 3352 |
if (anonyIndiVarExp == firstVarExp) { |
| 3353 |
otherVarExp = secondVarExp; |
| 3354 |
} |
| 3355 |
if (firstVarExp && secondVarExp && firstVarExp != secondVarExp && !rolledVarExpSet.contains(otherVarExp)) { |
| 3356 |
propAssPropagationCount++; |
| 3357 |
} |
| 3358 |
if (firstVarExp == secondVarExp) { |
| 3359 |
CRole* role = testingOnto->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propAssExp->getObjectPropertyTermExpression()); |
| 3360 |
if (role && role->isComplexRole()) { |
| 3361 |
rollingUpPossible = false; |
| 3362 |
} |
| 3363 |
} |
| 3364 |
} |
| 3365 |
} |
| 3366 |
if (propAssPropagationCount == 1 && rollingUpPossible) { |
| 3367 |
|
| 3368 |
rolledVarExpSet.insert(anonyIndiVarExp); |
| 3369 |
CClassTermExpression* rollingUpExp = nullptr; |
| 3370 |
QList<CBuildExpression*> rollingUpExpList(varRolledUpClassExpHash.values(anonyIndiVarExp)); |
| 3371 |
|
| 3372 |
bool inversedRollingUp = false; |
| 3373 |
CObjectPropertyTermExpression* rollingUpPropExpression = nullptr; |
| 3374 |
CExpressionVariable* rollingUpVarExpression = nullptr; |
| 3375 |
|
| 3376 |
for (CAxiomExpression* assExp : axiomList) { |
| 3377 |
CClassAssertionExpression* classAssExp = dynamic_cast<CClassAssertionExpression*>(assExp); |
| 3378 |
if (classAssExp) { |
| 3379 |
rollingUpExpList.append(mTestingOntologyBuilder->rebuildExpression(classAssExp->getClassTermExpression())); |
| 3380 |
} |
| 3381 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 3382 |
if (propAssExp) { |
| 3383 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 3384 |
CIndividualTermExpression* firstIndiExp = propAssExp->getFirstIndividualTermExpression(); |
| 3385 |
CIndividualTermExpression* secondIndiExp = propAssExp->getSecondIndividualTermExpression(); |
| 3386 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(firstIndiExp); |
| 3387 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(secondIndiExp); |
| 3388 |
if (firstVarExp == anonyIndiVarExp && secondVarExp == anonyIndiVarExp) { |
| 3389 |
rollingUpExpList.append(mTestingOntologyBuilder->getObjectHasSelf(propExp)); |
| 3390 |
} else if (firstVarExp == anonyIndiVarExp) { |
| 3391 |
if (secondVarExp == nullptr) { |
| 3392 |
rollingUpExpList.append(mTestingOntologyBuilder->getObjectHasValue(propExp, secondIndiExp)); |
| 3393 |
} else if (!rolledVarExpSet.contains(secondVarExp)) { |
| 3394 |
rollingUpPropExpression = propExp; |
| 3395 |
inversedRollingUp = true; |
| 3396 |
rollingUpVarExpression = secondVarExp; |
| 3397 |
} |
| 3398 |
} else if (secondVarExp == anonyIndiVarExp) { |
| 3399 |
if (firstVarExp == nullptr) { |
| 3400 |
rollingUpExpList.append(mTestingOntologyBuilder->getObjectHasValue(mTestingOntologyBuilder->getInverseObjectPropertyOf(propExp), firstIndiExp)); |
| 3401 |
} else if (!rolledVarExpSet.contains(firstVarExp)) { |
| 3402 |
rollingUpPropExpression = propExp; |
| 3403 |
inversedRollingUp = false; |
| 3404 |
rollingUpVarExpression = firstVarExp; |
| 3405 |
} |
| 3406 |
} |
| 3407 |
} |
| 3408 |
|
| 3409 |
CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 3410 |
if (dataPropAssExp) { |
| 3411 |
CDataPropertyTermExpression* dataPropTermExp = dataPropAssExp->getDataPropertyTermExpression(); |
| 3412 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 3413 |
CDataLiteralVariableExpression* dataVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 3414 |
if (indiVarExp && !dataVarExp) { |
| 3415 |
CDataLiteralExpression* dataLiteralExp = (CDataLiteralExpression*)dataPropAssExp->getDataLiteralTermExpression(); |
| 3416 |
dataLiteralExp = (CDataLiteralExpression*)mTestingOntologyBuilder->rebuildExpression(dataLiteralExp); |
| 3417 |
rollingUpExpList.append(mTestingOntologyBuilder->getDataHasValue(dataPropTermExp, dataLiteralExp)); |
| 3418 |
} |
| 3419 |
|
| 3420 |
} |
| 3421 |
} |
| 3422 |
if (rollingUpExpList.size() > 1) { |
| 3423 |
rollingUpExp = (CClassTermExpression*)mTestingOntologyBuilder->getObjectIntersectionOf(rollingUpExpList); |
| 3424 |
} else if (rollingUpExpList.size() > 0) { |
| 3425 |
rollingUpExp = (CClassTermExpression*)rollingUpExpList.first(); |
| 3426 |
} else { |
| 3427 |
rollingUpExp = topClassTermExp; |
| 3428 |
} |
| 3429 |
|
| 3430 |
CClassTermExpression* rolledUpExp = nullptr; |
| 3431 |
if (inversedRollingUp) { |
| 3432 |
rolledUpExp = mTestingOntologyBuilder->getObjectSomeValuesFrom(mTestingOntologyBuilder->getInverseObjectPropertyOf(rollingUpPropExpression), rollingUpExp); |
| 3433 |
} else { |
| 3434 |
rolledUpExp = mTestingOntologyBuilder->getObjectSomeValuesFrom(rollingUpPropExpression, rollingUpExp); |
| 3435 |
} |
| 3436 |
varRolledUpClassExpHash.insertMulti(rollingUpVarExpression, rolledUpExp); |
| 3437 |
if (anonymousIndiVariableSet.contains(rollingUpVarExpression) && !anonymousIndiVariableProcessingSet.remove(anonyIndiVarExp)) { |
| 3438 |
anonymousIndiVariableProcessingSet.insert(anonyIndiVarExp); |
| 3439 |
anonymousIndiVariableProcessingList.append(rollingUpVarExpression); |
| 3440 |
} |
| 3441 |
} |
| 3442 |
} |
| 3443 |
|
| 3444 |
} |
| 3445 |
if (mConfExtendedLogging && !rolledVarExpSet.isEmpty()) { |
| 3446 |
QStringList varList; |
| 3447 |
for (CExpressionVariable* var : rolledVarExpSet) { |
| 3448 |
varList.append(var->getName()); |
| 3449 |
} |
| 3450 |
LOG(INFO, getDomain(), logTr("Rolled-up %1 variables: %2.").arg(rolledVarExpSet.size()).arg(varList.join(", ")), this); |
| 3451 |
} |
| 3452 |
} |
| 3453 |
|
| 3454 |
TConceptNegPair COptimizedComplexExpressionAnsweringHandler::upgradeExistTopToIndividualTrigger(CClassTermExpression* classTermExp, CExpressionVariable* varTermExp, QHash<CExpressionVariable*, CBuildExpression*>* individualTriggerUpdatableHash, CAnswererContext* answererContext) { |
| 3455 |
|
| 3456 |
|
| 3457 |
QSet<TConceptNegPair> upgradableConNegSet; |
| 3458 |
for (CBuildExpression* upgradableExp : individualTriggerUpdatableHash->values(varTermExp)) { |
| 3459 |
CConcept* testingConcept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value((CClassTermExpression*)upgradableExp); |
| 3460 |
bool testingNegation = testingConcept->hasMappingNegation(); |
| 3461 |
upgradableConNegSet.insert(TConceptNegPair(testingConcept, testingNegation)); |
| 3462 |
} |
| 3463 |
|
| 3464 |
CConcept* indiTriggerConcept = mOntoAnsweringItem->getOntology()->getTBox()->getIndividualTriggerConcept(); |
| 3465 |
CConcept* topConcept = mOntoAnsweringItem->getOntology()->getTBox()->getTopConcept(); |
| 3466 |
|
| 3467 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value((CClassTermExpression*)classTermExp); |
| 3468 |
bool conceptNegation = concept->hasMappingNegation(); |
| 3469 |
|
| 3470 |
QList<TConceptNegPair> upgradeOpConList; |
| 3471 |
QList<TConceptNegPair> remainingOpConList; |
| 3472 |
QSet<TConceptNegPair> allUpgradedOpConSet; |
| 3473 |
|
| 3474 |
|
| 3475 |
|
| 3476 |
QList<TConceptNegPair> testingConList; |
| 3477 |
testingConList.append(TConceptNegPair(concept, conceptNegation)); |
| 3478 |
while (!testingConList.isEmpty()) { |
| 3479 |
TConceptNegPair testingConNegPair = testingConList.takeFirst(); |
| 3480 |
CConcept* testingConcept = testingConNegPair.first; |
| 3481 |
bool testingNegation = testingConNegPair.second; |
| 3482 |
cint64 testingConOpCode = testingConcept->getOperatorCode(); |
| 3483 |
bool upgradable = false; |
| 3484 |
bool remaining = true; |
| 3485 |
|
| 3486 |
if (!testingNegation && testingConOpCode == CCAND || testingNegation && testingConOpCode == CCOR) { |
| 3487 |
for (CSortedNegLinker<CConcept*>* opConLinkerIt = testingConcept->getOperandList(); opConLinkerIt; opConLinkerIt = opConLinkerIt->getNext()) { |
| 3488 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 3489 |
bool opConNegation = opConLinkerIt->isNegated() ^ testingNegation; |
| 3490 |
testingConList.append(TConceptNegPair(opConcept, opConNegation)); |
| 3491 |
} |
| 3492 |
remaining = false; |
| 3493 |
} else if (!testingNegation && testingConOpCode == CCSOME) { |
| 3494 |
if (testingConcept->getOperandCount() == 1) { |
| 3495 |
if (testingConcept->getOperandList()->getData() == topConcept && !testingConcept->getOperandList()->isNegated()) { |
| 3496 |
if (upgradableConNegSet.contains(TConceptNegPair(testingConcept, testingNegation))) { |
| 3497 |
upgradable = true; |
| 3498 |
} |
| 3499 |
} |
| 3500 |
} |
| 3501 |
} else if (testingNegation && testingConOpCode == CCALL) { |
| 3502 |
if (testingConcept->getOperandCount() == 1) { |
| 3503 |
if (testingConcept->getOperandList()->getData() == topConcept && testingConcept->getOperandList()->isNegated()) { |
| 3504 |
if (upgradableConNegSet.contains(TConceptNegPair(testingConcept, testingNegation))) { |
| 3505 |
upgradable = true; |
| 3506 |
} |
| 3507 |
} |
| 3508 |
} |
| 3509 |
} |
| 3510 |
if (upgradable) { |
| 3511 |
upgradeOpConList.append(TConceptNegPair(testingConcept, testingNegation)); |
| 3512 |
} else if (remaining) { |
| 3513 |
remainingOpConList.append(TConceptNegPair(testingConcept, testingNegation)); |
| 3514 |
bool originalNegation = testingNegation ^ testingConcept->hasMappingNegation(); |
| 3515 |
allUpgradedOpConSet.insert(TConceptNegPair(testingConcept, originalNegation)); |
| 3516 |
} |
| 3517 |
|
| 3518 |
} |
| 3519 |
|
| 3520 |
|
| 3521 |
QHash<TConceptNegPair, TConceptNegPair>* individualTriggerSingleConceptUpgradeHash = mOntoAnsweringItem->getIndividualTriggerSingleConceptUpgradeHash(); |
| 3522 |
QHash< QSet<TConceptNegPair>, TConceptNegPair>* individualTriggerMultiConceptUpgradeHash = mOntoAnsweringItem->getIndividualTriggerMultiConceptUpgradeHash(); |
| 3523 |
|
| 3524 |
|
| 3525 |
if (upgradeOpConList.isEmpty()) { |
| 3526 |
return TConceptNegPair(concept, conceptNegation); |
| 3527 |
} else { |
| 3528 |
|
| 3529 |
CMemoryAllocationManager* memMan = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getBoxContext()->getMemoryAllocationManager(); |
| 3530 |
CTBox* tBox = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getTBox(); |
| 3531 |
CConceptVector* conceptVec = tBox->getConceptVector(); |
| 3532 |
|
| 3533 |
QList<TConceptNegPair> upgradedOpConList; |
| 3534 |
bool allExistingUpgrade = true; |
| 3535 |
for (TConceptNegPair conNegPar : upgradeOpConList) { |
| 3536 |
CConcept* opConcept = conNegPar.first; |
| 3537 |
bool opConceptNegation = conNegPar.second; |
| 3538 |
bool originalOpConNegation = opConceptNegation ^ opConcept->hasMappingNegation(); |
| 3539 |
TConceptNegPair opConOriginalNegPair(opConcept, originalOpConNegation); |
| 3540 |
|
| 3541 |
if (!individualTriggerSingleConceptUpgradeHash->contains(opConOriginalNegPair)) { |
| 3542 |
CConcept* upgradedOpConcept = CObjectAllocator< CConcept >::allocateAndConstruct(memMan); |
| 3543 |
upgradedOpConcept->initConcept(); |
| 3544 |
cint64 nextConTag = tBox->getNextConceptID(); |
| 3545 |
upgradedOpConcept->initTag(nextConTag); |
| 3546 |
upgradedOpConcept->setOperatorCode(opConcept->getOperatorCode()); |
| 3547 |
upgradedOpConcept->setRole(opConcept->getRole()); |
| 3548 |
conceptVec->setLocalData(nextConTag, upgradedOpConcept); |
| 3549 |
|
| 3550 |
CSortedNegLinker<CConcept*>* newIndiTrigOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(memMan); |
| 3551 |
newIndiTrigOpCon->init(indiTriggerConcept, opConcept->getOperandList()->isNegated(), upgradedOpConcept->getOperandList()); |
| 3552 |
upgradedOpConcept->setOperandList(newIndiTrigOpCon); |
| 3553 |
upgradedOpConcept->incOperandCount(); |
| 3554 |
TConceptNegPair upgradedOpConNegPair(upgradedOpConcept, opConceptNegation); |
| 3555 |
individualTriggerSingleConceptUpgradeHash->insert(opConOriginalNegPair, upgradedOpConNegPair); |
| 3556 |
upgradedOpConList.append(upgradedOpConNegPair); |
| 3557 |
allUpgradedOpConSet.insert(opConOriginalNegPair); |
| 3558 |
allExistingUpgrade = false; |
| 3559 |
} else { |
| 3560 |
TConceptNegPair upgradedConNegPar = individualTriggerSingleConceptUpgradeHash->value(opConOriginalNegPair); |
| 3561 |
|
| 3562 |
CConcept* upgradedOpConcept = upgradedConNegPar.first; |
| 3563 |
bool correctedConceptNegation = upgradedConNegPar.second ^ upgradedOpConcept->hasMappingNegation(); |
| 3564 |
|
| 3565 |
allUpgradedOpConSet.insert(opConOriginalNegPair); |
| 3566 |
upgradedOpConList.append(TConceptNegPair(upgradedOpConcept, correctedConceptNegation)); |
| 3567 |
} |
| 3568 |
} |
| 3569 |
|
| 3570 |
if (allExistingUpgrade && individualTriggerMultiConceptUpgradeHash->contains(allUpgradedOpConSet)) { |
| 3571 |
return individualTriggerMultiConceptUpgradeHash->value(allUpgradedOpConSet); |
| 3572 |
} else { |
| 3573 |
|
| 3574 |
if (allUpgradedOpConSet.size() == 1) { |
| 3575 |
TConceptNegPair allUpgradedConNegPair(*upgradedOpConList.begin()); |
| 3576 |
individualTriggerMultiConceptUpgradeHash->insert(allUpgradedOpConSet, allUpgradedConNegPair); |
| 3577 |
return allUpgradedConNegPair; |
| 3578 |
} else { |
| 3579 |
|
| 3580 |
CConcept* upgradedAndConcept = CObjectAllocator< CConcept >::allocateAndConstruct(memMan); |
| 3581 |
upgradedAndConcept->initConcept(); |
| 3582 |
cint64 nextConTag = tBox->getNextConceptID(); |
| 3583 |
upgradedAndConcept->initTag(nextConTag); |
| 3584 |
upgradedAndConcept->setOperatorCode(concept->getOperatorCode()); |
| 3585 |
upgradedAndConcept->setMappingNegation(conceptNegation); |
| 3586 |
conceptVec->setLocalData(nextConTag, upgradedAndConcept); |
| 3587 |
|
| 3588 |
for (TConceptNegPair conNegPar : remainingOpConList) { |
| 3589 |
CConcept* opConcept = conNegPar.first; |
| 3590 |
bool opConceptNegation = conNegPar.second; |
| 3591 |
|
| 3592 |
CSortedNegLinker<CConcept*>* newBaseOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(memMan); |
| 3593 |
newBaseOpCon->init(opConcept, opConceptNegation, upgradedAndConcept->getOperandList()); |
| 3594 |
upgradedAndConcept->setOperandList(newBaseOpCon); |
| 3595 |
upgradedAndConcept->incOperandCount(); |
| 3596 |
} |
| 3597 |
|
| 3598 |
|
| 3599 |
for (TConceptNegPair upgradedAndConNegPar : upgradedOpConList) { |
| 3600 |
CConcept* upgradedOpConcept = upgradedAndConNegPar.first; |
| 3601 |
bool opConceptNegation = upgradedAndConNegPar.second; |
| 3602 |
|
| 3603 |
CSortedNegLinker<CConcept*>* newBaseOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(memMan); |
| 3604 |
newBaseOpCon->init(upgradedOpConcept, opConceptNegation, upgradedAndConcept->getOperandList()); |
| 3605 |
upgradedAndConcept->setOperandList(newBaseOpCon); |
| 3606 |
upgradedAndConcept->incOperandCount(); |
| 3607 |
} |
| 3608 |
TConceptNegPair allUpgradedConNegPair(upgradedAndConcept, conceptNegation); |
| 3609 |
individualTriggerMultiConceptUpgradeHash->insert(allUpgradedOpConSet, allUpgradedConNegPair); |
| 3610 |
return allUpgradedConNegPair; |
| 3611 |
} |
| 3612 |
} |
| 3613 |
|
| 3614 |
|
| 3615 |
} |
| 3616 |
} |
| 3617 |
|
| 3618 |
|
| 3619 |
|
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
|
| 3625 |
bool COptimizedComplexExpressionAnsweringHandler::ensureRoleTargetsRealization(CRole* role, bool inversed, const QSet<CIndividualReference>& individualSourceSet, COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CAnswererContext* answererContext) { |
| 3626 |
QList<COntologyProcessingRequirement*> reqList; |
| 3627 |
QList<CIndividualReference> reqIndiList; |
| 3628 |
bool targetsRealizationMissing = false; |
| 3629 |
for (CIndividualReference individualSource : individualSourceSet) { |
| 3630 |
CRoleTargetsRealizationHasher enHasher(role, individualSource, inversed); |
| 3631 |
CEntailmentVariableBuildingItemData*& varBuildData = mRoleTargetsProcDataHash[enHasher]; |
| 3632 |
if (!varBuildData) { |
| 3633 |
varBuildData = new CEntailmentVariableBuildingItemData(); |
| 3634 |
} |
| 3635 |
if (!varBuildData->mHasResult) { |
| 3636 |
targetsRealizationMissing = true; |
| 3637 |
if (!varBuildData->mHasRequested) { |
| 3638 |
COntologyProcessingRoleRealizationRequirement* roleRealReq = new COntologyProcessingRoleRealizationRequirement(role, inversed, individualSource); |
| 3639 |
reqList.append(roleRealReq); |
| 3640 |
reqIndiList.append(individualSource); |
| 3641 |
} |
| 3642 |
CXLinker<COptimizedComplexBuildingIndividualVariableCompositionsItem*>* procDataLinker = mOntoAnsweringItem->createBuildingVariableItemProcessingLinker(); |
| 3643 |
procDataLinker->setData(buildingVarItem); |
| 3644 |
varBuildData->mProcDataLinker = procDataLinker->append(varBuildData->mProcDataLinker); |
| 3645 |
buildingVarItem->incWaitingRoleTargetsRealizationCount(); |
| 3646 |
} |
| 3647 |
} |
| 3648 |
if (!reqList.isEmpty()) { |
| 3649 |
CAnsweringMessageDataRequirementCompletedRoleTargetsRealization* reqCompMess = new CAnsweringMessageDataRequirementCompletedRoleTargetsRealization(role, inversed, reqIndiList); |
| 3650 |
processRequirements(answererContext, mOntoAnsweringItem->getOntology(), reqList, reqCompMess); |
| 3651 |
} |
| 3652 |
return targetsRealizationMissing; |
| 3653 |
} |
| 3654 |
|
| 3655 |
|
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
bool COptimizedComplexExpressionAnsweringHandler::checkEntailmentRoleAssertion(CRole* role, CIndividual* individualSource, CIndividual* individualDest, CComplexQueryExpressionProcessingData* procData, CAnswererContext* answererContext) { |
| 3660 |
CEntailmentRoleAssertionHasher enHasher(role, individualSource, individualDest); |
| 3661 |
CEntailmentQueryProcessingData*& queryProcData = mRoleAssEntProcDataHash[enHasher]; |
| 3662 |
if (!queryProcData) { |
| 3663 |
queryProcData = new CEntailmentQueryProcessingData(); |
| 3664 |
} |
| 3665 |
if (queryProcData->mHasResult) { |
| 3666 |
if (!queryProcData->mEntailed) { |
| 3667 |
procData->setUnsatisfiable(true); |
| 3668 |
return false; |
| 3669 |
} else { |
| 3670 |
return false; |
| 3671 |
} |
| 3672 |
} else { |
| 3673 |
procData->incEntailmentComputation(); |
| 3674 |
if (!queryProcData->mHasRequested) { |
| 3675 |
CAnsweringMessageDataRequirementCompletedRoleAssertionEntailment* reqCompMess = new CAnsweringMessageDataRequirementCompletedRoleAssertionEntailment(queryProcData, role,individualSource,individualDest); |
| 3676 |
QList<COntologyProcessingRequirement*> reqList; |
| 3677 |
COntologyProcessingRoleRealizationRequirement* roleRealReq = new COntologyProcessingRoleRealizationRequirement(role,false,individualSource,individualDest); |
| 3678 |
reqList.append(roleRealReq); |
| 3679 |
processRequirements(answererContext, mOntoAnsweringItem->getOntology(), reqList, reqCompMess); |
| 3680 |
} |
| 3681 |
CXLinker<CComplexQueryExpressionProcessingData*>* procDataLinker = mOntoAnsweringItem->createQueryProcessingLinker(); |
| 3682 |
procDataLinker->setData(procData); |
| 3683 |
queryProcData->mProcDataLinker = procDataLinker->append(queryProcData->mProcDataLinker); |
| 3684 |
return true; |
| 3685 |
} |
| 3686 |
} |
| 3687 |
|
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
bool COptimizedComplexExpressionAnsweringHandler::checkEntailmentRoleSubObjectPropertyAxiom(CRole* subRole, CRole* superRole, CComplexQueryExpressionProcessingData* procData, CAnswererContext* answererContext) { |
| 3692 |
|
| 3693 |
if (subRole->hasPropertyName() && superRole->hasPropertyName()) { |
| 3694 |
CRolePropertiesHierarchyNode* subConHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getObjectPropertyRoleClassification()->getRolePropertiesHierarchy()->getHierarchyNode(subRole, false); |
| 3695 |
CRolePropertiesHierarchyNode* superConHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getObjectPropertyRoleClassification()->getRolePropertiesHierarchy()->getHierarchyNode(superRole, false); |
| 3696 |
|
| 3697 |
if (!subConHierNode->hasPredecessorNode(superConHierNode)) { |
| 3698 |
procData->setUnsatisfiable(true); |
| 3699 |
} |
| 3700 |
} |
| 3701 |
return false; |
| 3702 |
} |
| 3703 |
|
| 3704 |
|
| 3705 |
|
| 3706 |
|
| 3707 |
bool COptimizedComplexExpressionAnsweringHandler::checkEntailmentRoleSubDataPropertyAxiom(CRole* subRole, CRole* superRole, CComplexQueryExpressionProcessingData* procData, CAnswererContext* answererContext) { |
| 3708 |
|
| 3709 |
if (subRole->hasPropertyName() && superRole->hasPropertyName()) { |
| 3710 |
CRolePropertiesHierarchyNode* subConHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getDataPropertyRoleClassification()->getRolePropertiesHierarchy()->getHierarchyNode(subRole, false); |
| 3711 |
CRolePropertiesHierarchyNode* superConHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getDataPropertyRoleClassification()->getRolePropertiesHierarchy()->getHierarchyNode(superRole, false); |
| 3712 |
|
| 3713 |
if (!subConHierNode->hasPredecessorNode(superConHierNode)) { |
| 3714 |
procData->setUnsatisfiable(true); |
| 3715 |
} |
| 3716 |
} |
| 3717 |
return false; |
| 3718 |
} |
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
bool COptimizedComplexExpressionAnsweringHandler::checkEntailmentConceptSubClassAxiom(CConcept* subConcept, bool subConNegation, CConcept* superConcept, bool superConNegation, CComplexQueryExpressionProcessingData* procData, CAnswererContext* answererContext) { |
| 3723 |
|
| 3724 |
if (subConcept->hasClassName() && !subConNegation && superConcept->hasClassName() && !superConNegation) { |
| 3725 |
CHierarchyNode* subConHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getHierarchyNode(subConcept, false); |
| 3726 |
CHierarchyNode* superConHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getHierarchyNode(superConcept, false); |
| 3727 |
|
| 3728 |
if (!subConHierNode->hasPredecessorNode(superConHierNode)) { |
| 3729 |
procData->setUnsatisfiable(true); |
| 3730 |
} |
| 3731 |
return false; |
| 3732 |
} |
| 3733 |
|
| 3734 |
CEntailmentSubConceptAxiomHasher enHasher(subConcept, subConNegation, superConcept, superConNegation); |
| 3735 |
CEntailmentQueryProcessingData*& queryProcData = mSubConEntProcDataHash[enHasher]; |
| 3736 |
if (!queryProcData) { |
| 3737 |
queryProcData = new CEntailmentQueryProcessingData(); |
| 3738 |
} |
| 3739 |
if (queryProcData->mHasResult) { |
| 3740 |
if (!queryProcData->mEntailed) { |
| 3741 |
procData->setUnsatisfiable(true); |
| 3742 |
return false; |
| 3743 |
} else { |
| 3744 |
return false; |
| 3745 |
} |
| 3746 |
} else { |
| 3747 |
procData->incEntailmentComputation(); |
| 3748 |
|
| 3749 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 3750 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 3751 |
bool topObjectRoleUsed = false; |
| 3752 |
if (!mOntoAnsweringItem->getTestingOntology()->getABox()->hasUniversalConnectionIndividual()) { |
| 3753 |
topObjectRoleUsed |= checkHasNewTopRolePropagation(subConcept, !subConNegation); |
| 3754 |
topObjectRoleUsed |= checkHasNewTopRolePropagation(superConcept, superConNegation); |
| 3755 |
} |
| 3756 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, topObjectRoleUsed, answererContext); |
| 3757 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(subConcept, !subConNegation, superConcept, superConNegation, nullptr, satCalcJob); |
| 3758 |
CAnsweringMessageDataCalculationCompletedClassSubsumption* completedMessage = new CAnsweringMessageDataCalculationCompletedClassSubsumption(satCalcJob, queryProcData, subConcept, subConNegation, superConcept, superConNegation); |
| 3759 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incComplexConceptSubClassAxiomEntailmentTestingCount(); |
| 3760 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 3761 |
return true; |
| 3762 |
} |
| 3763 |
} |
| 3764 |
|
| 3765 |
|
| 3766 |
bool COptimizedComplexExpressionAnsweringHandler::checkEntailmentConceptAssertion(CConcept* concept, bool negation, CIndividual* individual, CComplexQueryExpressionProcessingData* procData, CAnswererContext* answererContext) { |
| 3767 |
CEntailmentConceptAssertionHasher enHasher(concept, negation, individual); |
| 3768 |
CEntailmentQueryProcessingData*& queryProcData = mConAssEntProcDataHash[enHasher]; |
| 3769 |
if (!queryProcData) { |
| 3770 |
queryProcData = new CEntailmentQueryProcessingData(); |
| 3771 |
} |
| 3772 |
if (queryProcData->mHasResult) { |
| 3773 |
if (!queryProcData->mEntailed) { |
| 3774 |
procData->setUnsatisfiable(true); |
| 3775 |
return false; |
| 3776 |
} else { |
| 3777 |
return false; |
| 3778 |
} |
| 3779 |
} else { |
| 3780 |
procData->incEntailmentComputation(); |
| 3781 |
if (concept->hasClassName() && !negation) { |
| 3782 |
if (!queryProcData->mHasRequested) { |
| 3783 |
CAnsweringMessageDataRequirementCompletedConceptAssertionEntailment* reqCompMess = new CAnsweringMessageDataRequirementCompletedConceptAssertionEntailment(queryProcData, concept, individual); |
| 3784 |
QList<COntologyProcessingRequirement*> reqList; |
| 3785 |
COntologyProcessingConceptRealizationRequirement* conRealReq = new COntologyProcessingConceptRealizationRequirement(individual, concept); |
| 3786 |
reqList.append(conRealReq); |
| 3787 |
processRequirements(answererContext, mOntoAnsweringItem->getOntology(), reqList, reqCompMess); |
| 3788 |
} |
| 3789 |
CXLinker<CComplexQueryExpressionProcessingData*>* procDataLinker = mOntoAnsweringItem->createQueryProcessingLinker(); |
| 3790 |
procDataLinker->setData(procData); |
| 3791 |
queryProcData->mProcDataLinker = procDataLinker->append(queryProcData->mProcDataLinker); |
| 3792 |
return true; |
| 3793 |
} else { |
| 3794 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 3795 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 3796 |
bool topObjectRoleUsed = false; |
| 3797 |
if (!mOntoAnsweringItem->getTestingOntology()->getABox()->hasUniversalConnectionIndividual()) { |
| 3798 |
topObjectRoleUsed = checkHasNewTopRolePropagation(concept, !negation); |
| 3799 |
} |
| 3800 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, topObjectRoleUsed, answererContext); |
| 3801 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(concept, !negation, individual, satCalcJob); |
| 3802 |
CAnsweringMessageDataCalculationCompletedInstanceEntailment* completedMessage = new CAnsweringMessageDataCalculationCompletedInstanceEntailment(satCalcJob, queryProcData, individual, concept, negation); |
| 3803 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incComplexConceptAssertionEntailmentTestingCount(); |
| 3804 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 3805 |
return true; |
| 3806 |
} |
| 3807 |
} |
| 3808 |
} |
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
bool COptimizedComplexExpressionAnsweringHandler::queueConceptItemProcessing(COptimizedComplexConceptItem* conceptItem, CComplexConceptStepComputationProcess* compStep) { |
| 3815 |
if (!conceptItem->hasQueuedProcessStep() && !compStep->isComputationProcessQueued() && !compStep->isComputationProcessProcessing()) { |
| 3816 |
conceptItem->setQueuedProcessStep(compStep); |
| 3817 |
compStep->setComputationProcessQueued(true); |
| 3818 |
COptimizedComplexConceptStepAnsweringItem* processingStep = mOntoAnsweringItem->getConceptProcessingStepItem(compStep->getComputationType()); |
| 3819 |
processingStep->addQueuedConceptItem(conceptItem); |
| 3820 |
return true; |
| 3821 |
} |
| 3822 |
return false; |
| 3823 |
} |
| 3824 |
|
| 3825 |
|
| 3826 |
bool COptimizedComplexExpressionAnsweringHandler::requeueConceptItemNextProcessing(COptimizedComplexConceptItem* conceptItem, CComplexConceptStepComputationProcess* compStep) { |
| 3827 |
conceptItem->setQueuedProcessStep(nullptr); |
| 3828 |
CComplexConceptStepComputationProcess* nextCompStep = conceptItem->getComputationProcess()->getNextConceptStepComputationProcess(compStep, true); |
| 3829 |
if (nextCompStep && !conceptItem->hasQueuedProcessStep() && !nextCompStep->isComputationProcessQueued() && !nextCompStep->isComputationProcessProcessing()) { |
| 3830 |
conceptItem->setQueuedProcessStep(nextCompStep); |
| 3831 |
nextCompStep->setComputationProcessQueued(true); |
| 3832 |
COptimizedComplexConceptStepAnsweringItem* processingStep = mOntoAnsweringItem->getConceptProcessingStepItem(nextCompStep->getComputationType()); |
| 3833 |
processingStep->addQueuedConceptItem(conceptItem); |
| 3834 |
return true; |
| 3835 |
} |
| 3836 |
return false; |
| 3837 |
} |
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
|
| 3852 |
|
| 3853 |
|
| 3854 |
|
| 3855 |
bool COptimizedComplexExpressionAnsweringHandler::failQueryProcessing(CComplexQueryExpressionProcessingData* queryProcessingData, CQueryError* queryError) { |
| 3856 |
CQuery* query = queryProcessingData->getQuery(); |
| 3857 |
QString errorString = queryError->getErrorString(); |
| 3858 |
query->addQueryError(queryError); |
| 3859 |
|
| 3860 |
queryProcessingData->setProcessingFinished(); |
| 3861 |
cint64 processingTime = queryProcessingData->getTotalProcessingTime(); |
| 3862 |
LOG(WARN, getDomain(), logTr("Complex query processing failed after %1 ms due to error '%2'.").arg(processingTime).arg(errorString), this); |
| 3863 |
|
| 3864 |
CCallbackData* callback = queryProcessingData->getCallback(); |
| 3865 |
if (callback) { |
| 3866 |
callback->doCallback(); |
| 3867 |
} |
| 3868 |
delete queryProcessingData; |
| 3869 |
mOntoAnsweringItem->decCurrentlyAnsweringQueryCount(); |
| 3870 |
return true; |
| 3871 |
} |
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
|
| 3876 |
bool COptimizedComplexExpressionAnsweringHandler::finishQueryProcessingAsUnsatisfaible(CComplexQueryExpressionProcessingData* queryProcessingData) { |
| 3877 |
CComplexAnsweringExpressionQuery* query = queryProcessingData->getQuery(); |
| 3878 |
COptimizedComplexBuildingVariableCompositionsItem* varBuildItem = queryProcessingData->getVariableBuildingItem(); |
| 3879 |
|
| 3880 |
queryProcessingData->setProcessingFinished(); |
| 3881 |
cint64 processingTime = queryProcessingData->getTotalProcessingTime(); |
| 3882 |
LOG(INFO, getDomain(), logTr("Finished unsatisfiable query processing in %1 ms.").arg(processingTime), this); |
| 3883 |
|
| 3884 |
CComplexAssertionsIndividualVariablesAnsweringQuery* compAssIndVarQuery = dynamic_cast<CComplexAssertionsIndividualVariablesAnsweringQuery*>(query); |
| 3885 |
if (compAssIndVarQuery) { |
| 3886 |
if (compAssIndVarQuery->isBooleanEntailmentResultRequired()) { |
| 3887 |
CBooleanQueryResult* entailedResult = new CBooleanQueryResult(false); |
| 3888 |
query->setQueryResult(entailedResult); |
| 3889 |
} else { |
| 3890 |
QStringList varList; |
| 3891 |
QHash<CExpressionVariable*, cint64> disVarIdHash; |
| 3892 |
cint64 nextId = 0; |
| 3893 |
for (CExpressionVariable* varExp : *compAssIndVarQuery->getDistinguishedVariableExpressions()) { |
| 3894 |
disVarIdHash.insert(varExp, nextId++); |
| 3895 |
varList.append(varExp->getName()); |
| 3896 |
} |
| 3897 |
CVariableBindingsAnswersResult* bindsAnswersResult = nullptr; |
| 3898 |
CVariableBindingsAnswersStreamingResult* existBindsAnswersStreamingResult = dynamic_cast<CVariableBindingsAnswersStreamingResult*>(query->getQueryResult()); |
| 3899 |
if (existBindsAnswersStreamingResult) { |
| 3900 |
existBindsAnswersStreamingResult->initResult(varList); |
| 3901 |
bindsAnswersResult = existBindsAnswersStreamingResult; |
| 3902 |
} else { |
| 3903 |
CVariableBindingsAnswersResult* bindsAnswersResult = new CVariableBindingsAnswersListResult(varList); |
| 3904 |
query->setQueryResult(bindsAnswersResult); |
| 3905 |
} |
| 3906 |
} |
| 3907 |
} |
| 3908 |
|
| 3909 |
|
| 3910 |
CComplexConceptAnsweringQuery* compConQuery = dynamic_cast<CComplexConceptAnsweringQuery*>(query); |
| 3911 |
if (compConQuery) { |
| 3912 |
bool flattened = compConQuery->isFlattened(); |
| 3913 |
if (compConQuery->isSatisfiableComputationRequired()) { |
| 3914 |
CBooleanQueryResult* booleanQueryResult = new CBooleanQueryResult(false); |
| 3915 |
query->setQueryResult(booleanQueryResult); |
| 3916 |
} |
| 3917 |
if (compConQuery->isSuperClassNodesComputationRequired() || compConQuery->isSubClassNodesComputationRequired()) { |
| 3918 |
CClassSynsetsResult* classSynsetsResult = new CClassSynsetsResult(); |
| 3919 |
if (compConQuery->isSuperClassNodesComputationRequired()) { |
| 3920 |
CHierarchyNode* nextNode = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getTopHierarchyNode(); |
| 3921 |
CClassSynsetResult* nextClassSynset = new CClassSynsetResult(nextNode->getEquivalentConceptStringList(false)); |
| 3922 |
classSynsetsResult->addClassSynset(nextClassSynset); |
| 3923 |
} |
| 3924 |
query->setQueryResult(classSynsetsResult); |
| 3925 |
} |
| 3926 |
if (compConQuery->isEquivalentClassNodesComputationRequired()) { |
| 3927 |
CClassSetResult* classesResult = new CClassSetResult(); |
| 3928 |
query->setQueryResult(classesResult); |
| 3929 |
} |
| 3930 |
if (compConQuery->isInstancesComputationRequired()) { |
| 3931 |
if (flattened) { |
| 3932 |
CIndividualsResult* individualResult = new CIndividualsResult(); |
| 3933 |
query->setQueryResult(individualResult); |
| 3934 |
} else { |
| 3935 |
CIndividualSynsetsResult* indiSynsResult = new CIndividualSynsetsResult(); |
| 3936 |
query->setQueryResult(indiSynsResult); |
| 3937 |
} |
| 3938 |
} |
| 3939 |
} |
| 3940 |
|
| 3941 |
if (varBuildItem) { |
| 3942 |
delete varBuildItem; |
| 3943 |
} |
| 3944 |
|
| 3945 |
|
| 3946 |
CCallbackData* callback = queryProcessingData->getCallback(); |
| 3947 |
if (callback) { |
| 3948 |
callback->doCallback(); |
| 3949 |
} |
| 3950 |
delete queryProcessingData; |
| 3951 |
mOntoAnsweringItem->decCurrentlyAnsweringQueryCount(); |
| 3952 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incTotalAnsweredQueriesCount(); |
| 3953 |
|
| 3954 |
cleanUpAnswersCache(true); |
| 3955 |
return true; |
| 3956 |
} |
| 3957 |
|
| 3958 |
|
| 3959 |
|
| 3960 |
|
| 3961 |
|
| 3962 |
bool COptimizedComplexExpressionAnsweringHandler::finishQueryProcessing(CComplexQueryExpressionProcessingData* queryProcessingData) { |
| 3963 |
CComplexAnsweringExpressionQuery* query = queryProcessingData->getQuery(); |
| 3964 |
COptimizedComplexConceptItem* conceptItem = queryProcessingData->getConceptItem(); |
| 3965 |
COptimizedComplexBuildingVariableCompositionsItem* varBuildItem = queryProcessingData->getVariableBuildingItem(); |
| 3966 |
|
| 3967 |
if (!queryProcessingData->isProcessingFinished()) { |
| 3968 |
queryProcessingData->setProcessingFinished(); |
| 3969 |
cint64 firstProcessingTime = queryProcessingData->getTotalProcessingTime(); |
| 3970 |
LOG(INFO, getDomain(), logTr("Computed first complex query result in %1 ms.").arg(firstProcessingTime), this); |
| 3971 |
} |
| 3972 |
|
| 3973 |
|
| 3974 |
|
| 3975 |
CComplexVariablesAnsweringQuery* compVarQuery = dynamic_cast<CComplexVariablesAnsweringQuery*>(query); |
| 3976 |
if (compVarQuery) { |
| 3977 |
|
| 3978 |
if (compVarQuery->isBooleanEntailmentResultRequired()) { |
| 3979 |
|
| 3980 |
CBooleanQueryResult* entailedResult = new CBooleanQueryResult(false); |
| 3981 |
if (!queryProcessingData->isUnsatisfiable()) { |
| 3982 |
if (varBuildItem && varBuildItem->isSatisfiable()) { |
| 3983 |
|
| 3984 |
CExpressionVariable* lastVarExp = varBuildItem->getLastHandledVariableExpression(); |
| 3985 |
if (!lastVarExp) { |
| 3986 |
entailedResult->setResult(true); |
| 3987 |
} else { |
| 3988 |
COptimizedComplexVariableCompositionItem* varItem = varBuildItem->getVariableLastCompositionItem(lastVarExp); |
| 3989 |
if (varItem->getVariableMapping()->getBindingCount() > 0) { |
| 3990 |
entailedResult->setResult(true); |
| 3991 |
} |
| 3992 |
} |
| 3993 |
|
| 3994 |
} |
| 3995 |
} |
| 3996 |
query->setQueryResult(entailedResult); |
| 3997 |
|
| 3998 |
} else { |
| 3999 |
|
| 4000 |
|
| 4001 |
|
| 4002 |
if ((mConfDistinctUnecessaryVariablesReduction || mConfAlwaysUnecessaryVariablesReduction) && !queryProcessingData->isUnsatisfiable()) { |
| 4003 |
CComplexAssertionsIndividualVariablesAnsweringQuery* compAssIndVarQuery = dynamic_cast<CComplexAssertionsIndividualVariablesAnsweringQuery*>(compVarQuery); |
| 4004 |
if (compAssIndVarQuery && varBuildItem && varBuildItem->isSatisfiable()) { |
| 4005 |
CExpressionVariable* lastVarExp = varBuildItem->getLastHandledVariableExpression(); |
| 4006 |
if (lastVarExp) { |
| 4007 |
COptimizedComplexVariableCompositionItem* lastVarItem = varBuildItem->getVariableLastCompositionItem(lastVarExp); |
| 4008 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = varBuildItem->getVariableItemIndexMapping(lastVarExp).value(lastVarItem); |
| 4009 |
QHash<CExpressionVariable*, cint64> varIdxHash; |
| 4010 |
|
| 4011 |
bool distinct = compAssIndVarQuery->isDistinctRequired(); |
| 4012 |
if ((distinct || mConfAlwaysUnecessaryVariablesReduction) && !compAssIndVarQuery->getResultOrderingLinker() && !compAssIndVarQuery->getResultFilteringLinker()) { |
| 4013 |
QList<cint64> mNonAnswerVariableMappingIndexList; |
| 4014 |
QSet<CExpressionVariable*> distinguishedAnswerVariableSet(compAssIndVarQuery->getDistinguishedVariableExpressions()->toSet()); |
| 4015 |
QHash<CExpressionVariable*, cint64> reductionVarExpIndHash; |
| 4016 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 4017 |
cint64 varIdx = it.key(); |
| 4018 |
CExpressionVariable* varExp = it.value(); |
| 4019 |
if (distinguishedAnswerVariableSet.contains(varExp)) { |
| 4020 |
varIdxHash.insert(varExp, varIdx); |
| 4021 |
} else { |
| 4022 |
mNonAnswerVariableMappingIndexList.append(varIdx); |
| 4023 |
reductionVarExpIndHash.insert(varExp, varIdx); |
| 4024 |
} |
| 4025 |
} |
| 4026 |
|
| 4027 |
if (!mNonAnswerVariableMappingIndexList.isEmpty()) { |
| 4028 |
bool processing = false; |
| 4029 |
buildVariableReductionItem(varBuildItem, lastVarExp, true, lastVarItem, itemIndexMapping, reductionVarExpIndHash, &processing); |
| 4030 |
if (processing) { |
| 4031 |
return false; |
| 4032 |
} |
| 4033 |
} |
| 4034 |
} |
| 4035 |
|
| 4036 |
} |
| 4037 |
} |
| 4038 |
} |
| 4039 |
|
| 4040 |
|
| 4041 |
|
| 4042 |
|
| 4043 |
|
| 4044 |
|
| 4045 |
|
| 4046 |
CAbstractComplexQueryFinishingHandler* finishingHandler = queryProcessingData->getFinishingHandler(); |
| 4047 |
|
| 4048 |
if (!finishingHandler) { |
| 4049 |
if (mConfConcurrentAnswerGeneration) { |
| 4050 |
finishingHandler = new CQtConcurrentStreamingComplexQueryFinishingHandler(queryProcessingData, mOntoAnsweringItem, mConfExtendedLogging, getDomain(), mConfMaximumBatchMappingsComputationSize, mConfFirstBatchMappingsComputationSize, mConfBatchMappingsComputationSizeIncreasingFactor, mConfContinueMappingsCompuationWhenResultsNotWriteable, mConfMappingsComputationUnlimitedInterpretationSize); |
| 4051 |
} else { |
| 4052 |
finishingHandler = new CSequentialStreamingComplexQueryFinishingHandler(queryProcessingData, mOntoAnsweringItem, mConfExtendedLogging, getDomain(), mConfMaximumBatchMappingsComputationSize, mConfFirstBatchMappingsComputationSize, mConfBatchMappingsComputationSizeIncreasingFactor, mConfContinueMappingsCompuationWhenResultsNotWriteable, mConfMappingsComputationUnlimitedInterpretationSize); |
| 4053 |
} |
| 4054 |
queryProcessingData->setFinishingHandler(finishingHandler); |
| 4055 |
finishingHandler->init(); |
| 4056 |
} |
| 4057 |
|
| 4058 |
if (finishingHandler->processQueryResults()) { |
| 4059 |
|
| 4060 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 4061 |
if (mConfDebugWriteVariableCompositionItems) { |
| 4062 |
CAbstractStreamingComplexQueryFinishingHandler* incFinishingHandler = dynamic_cast<CAbstractStreamingComplexQueryFinishingHandler*>(finishingHandler); |
| 4063 |
if (incFinishingHandler && incFinishingHandler->getResultUsingLastVariableCompositionItem()) { |
| 4064 |
debugWriteVariableMappingToFileWithHeader(varBuildItem, incFinishingHandler->getResultUsingLastVariableCompositionItem(), "last"); |
| 4065 |
|
| 4066 |
//debugCheckVariableMappingFromFile(incFinishingHandler->mVarBuildItem, incFinishingHandler->mLastVarItem); |
| 4067 |
|
| 4068 |
//debugWriteVariableMappingToFile(incFinishingHandler->mVarBuildItem, incFinishingHandler->mLastVarItem); |
| 4069 |
} |
| 4070 |
} |
| 4071 |
#endif |
| 4072 |
|
| 4073 |
|
| 4074 |
finishingHandler->finishQueryProcessing(); |
| 4075 |
delete finishingHandler; |
| 4076 |
} else { |
| 4077 |
return false; |
| 4078 |
} |
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
//QSet<QString> indi1Set; |
| 4085 |
//QSet<QString> indi2Set; |
| 4086 |
//QFile file1("./Tests/sparql-response.xml"); |
| 4087 |
//cint64 firstMissingIndiID1 = -1; |
| 4088 |
//cint64 firstMissingIndiID2 = -1; |
| 4089 |
//if (file1.open(QIODevice::ReadOnly)) { |
| 4090 |
// while (!file1.atEnd()) { |
| 4091 |
// QString line = file1.readLine().trimmed(); |
| 4092 |
// if (line.startsWith("<uri>")) { |
| 4093 |
// QString indiName = line.mid(5, line.length() - 11); |
| 4094 |
// indi1Set.insert(indiName); |
| 4095 |
// } |
| 4096 |
// } |
| 4097 |
|
| 4098 |
// auto it = bindsAnswersResult->getVariableBindingsAnswersIterator(); |
| 4099 |
// while (it->hasNext()) { |
| 4100 |
// auto binding = it->getNext(); |
| 4101 |
// auto bindIt = binding->getVariableBindingsIterator(); |
| 4102 |
// auto bindingData = bindIt->getNext(); |
| 4103 |
// QString bindingString = bindingData->getBindingString(); |
| 4104 |
// indi2Set.insert(bindingString); |
| 4105 |
// if (!indi1Set.contains(bindingString) && firstMissingIndiID2 < 0) { |
| 4106 |
// CVariableBindingStringDataResult* dataResult = dynamic_cast<CVariableBindingStringDataResult*>(bindingData); |
| 4107 |
// firstMissingIndiID2 = (cint64)dataResult->getData(); |
| 4108 |
// } |
| 4109 |
// } |
| 4110 |
|
| 4111 |
|
| 4112 |
// QStringList additionalIndis2; |
| 4113 |
// QStringList additionalIndis1; |
| 4114 |
// for (QString indi2 : indi2Set) { |
| 4115 |
// if (!indi1Set.contains(indi2)) { |
| 4116 |
// additionalIndis2.append(indi2); |
| 4117 |
// bool debug = true; |
| 4118 |
// } |
| 4119 |
// } |
| 4120 |
|
| 4121 |
// for (QString indi1 : indi1Set) { |
| 4122 |
// if (!indi2Set.contains(indi1)) { |
| 4123 |
// if (firstMissingIndiID1 < 0) { |
| 4124 |
// firstMissingIndiID1 = mOntoAnsweringItem->getOntology()->getStringMapping()->getIndividualFromName(indi1)->getIndividualID(); |
| 4125 |
// } |
| 4126 |
// additionalIndis1.append(indi1); |
| 4127 |
// bool debug = true; |
| 4128 |
// } |
| 4129 |
// } |
| 4130 |
|
| 4131 |
// if (!additionalIndis1.isEmpty() || !additionalIndis2.isEmpty()) { |
| 4132 |
// bool debug = true; |
| 4133 |
|
| 4134 |
// QHash< TConceptNegPair, COptimizedComplexConceptItem* >* conItemHash = mOntoAnsweringItem->getComplexConceptNegationItemHash(); |
| 4135 |
// for (COptimizedComplexConceptItem* conItem : *conItemHash) { |
| 4136 |
// if (conItem->getKnownInstanceItemSet() && conItem->getKnownInstanceItemSet()->size() >= 1400 && conItem->getKnownInstanceItemSet()->size() <= 2000) { |
| 4137 |
|
| 4138 |
// bool abc = true; |
| 4139 |
// while (abc) { |
| 4140 |
// initializeRealizationInstancesIterators(conItem, 1, mAnswererContext); |
| 4141 |
// auto realIt = conItem->getRealizationIterator(); |
| 4142 |
// realIt->begin(); |
| 4143 |
// cint64 currentId = realIt->currentIndividualInstanceItemReference().getIndividualID(); |
| 4144 |
|
| 4145 |
// while (currentId < firstMissingIndiID1 && !realIt->atEnd()) { |
| 4146 |
// auto copyIt = realIt; |
| 4147 |
// currentId = realIt->currentIndividualInstanceItemReference().getIndividualID(); |
| 4148 |
// if (currentId <= firstMissingIndiID1) { |
| 4149 |
// copyIt = realIt->getCopy(); |
| 4150 |
// } |
| 4151 |
// realIt->moveNext(); |
| 4152 |
// cint64 nextId = realIt->currentIndividualInstanceItemReference().getIndividualID(); |
| 4153 |
// if (nextId > firstMissingIndiID1) { |
| 4154 |
// copyIt->moveNext(); |
| 4155 |
// } |
| 4156 |
// } |
| 4157 |
|
| 4158 |
// } |
| 4159 |
|
| 4160 |
// } |
| 4161 |
// } |
| 4162 |
// } |
| 4163 |
|
| 4164 |
//} |
| 4165 |
|
| 4166 |
|
| 4167 |
} |
| 4168 |
} |
| 4169 |
if (varBuildItem) { |
| 4170 |
delete varBuildItem; |
| 4171 |
} |
| 4172 |
|
| 4173 |
|
| 4174 |
CComplexConceptAnsweringQuery* compConQuery = dynamic_cast<CComplexConceptAnsweringQuery*>(query); |
| 4175 |
if (conceptItem && compConQuery) { |
| 4176 |
bool direct = compConQuery->isDirect(); |
| 4177 |
bool flattened = compConQuery->isFlattened(); |
| 4178 |
if (compConQuery->isSatisfiableComputationRequired()) { |
| 4179 |
bool satisfiable = conceptItem->isSatisfiable(); |
| 4180 |
CBooleanQueryResult* booleanQueryResult = new CBooleanQueryResult(satisfiable); |
| 4181 |
query->setQueryResult(booleanQueryResult); |
| 4182 |
} |
| 4183 |
if (compConQuery->isSuperClassNodesComputationRequired() || compConQuery->isSubClassNodesComputationRequired()) { |
| 4184 |
CClassSynsetsResult* classSynsetsResult = new CClassSynsetsResult(); |
| 4185 |
bool subClasses = compConQuery->isSubClassNodesComputationRequired(); |
| 4186 |
bool superClasses = compConQuery->isSuperClassNodesComputationRequired(); |
| 4187 |
bool abbreviatedIRIs = false; |
| 4188 |
|
| 4189 |
|
| 4190 |
QSet<CHierarchyNode*>* visitedHierNodeSet = nullptr; |
| 4191 |
if (!direct) { |
| 4192 |
visitedHierNodeSet = new QSet<CHierarchyNode*>(); |
| 4193 |
} |
| 4194 |
QList<CHierarchyNode*> visitHierNodetList; |
| 4195 |
if (subClasses) { |
| 4196 |
QSet<CHierarchyNode*>* childNodeSet = conceptItem->getDirectSubClassNodeSet(); |
| 4197 |
for (QSet<CHierarchyNode*>::const_iterator it = childNodeSet->constBegin(), itEnd = childNodeSet->constEnd(); it != itEnd; ++it) { |
| 4198 |
CHierarchyNode* childNode(*it); |
| 4199 |
visitHierNodetList.append(childNode); |
| 4200 |
} |
| 4201 |
} |
| 4202 |
if (superClasses) { |
| 4203 |
QSet<CHierarchyNode*>* parentNodeSet = conceptItem->getDirectSuperClassNodeSet(); |
| 4204 |
for (QSet<CHierarchyNode*>::const_iterator it = parentNodeSet->constBegin(), itEnd = parentNodeSet->constEnd(); it != itEnd; ++it) { |
| 4205 |
CHierarchyNode* parentNode(*it); |
| 4206 |
visitHierNodetList.append(parentNode); |
| 4207 |
} |
| 4208 |
} |
| 4209 |
|
| 4210 |
while (!visitHierNodetList.isEmpty()) { |
| 4211 |
CHierarchyNode* nextNode = visitHierNodetList.takeFirst(); |
| 4212 |
|
| 4213 |
CClassSynsetResult* nextClassSynset = new CClassSynsetResult(nextNode->getEquivalentConceptStringList(abbreviatedIRIs)); |
| 4214 |
classSynsetsResult->addClassSynset(nextClassSynset); |
| 4215 |
|
| 4216 |
|
| 4217 |
if (!direct) { |
| 4218 |
if (subClasses) { |
| 4219 |
QSet<CHierarchyNode*>* tmpChildNodeSet = nextNode->getChildNodeSet(); |
| 4220 |
for (QSet<CHierarchyNode*>::const_iterator it = tmpChildNodeSet->constBegin(), itEnd = tmpChildNodeSet->constEnd(); it != itEnd; ++it) { |
| 4221 |
CHierarchyNode* nextChildNode(*it); |
| 4222 |
if (!visitedHierNodeSet->contains(nextChildNode)) { |
| 4223 |
visitedHierNodeSet->insert(nextChildNode); |
| 4224 |
visitHierNodetList.append(nextChildNode); |
| 4225 |
} |
| 4226 |
} |
| 4227 |
} |
| 4228 |
if (superClasses) { |
| 4229 |
QSet<CHierarchyNode*>* tmpParentNodeSet = nextNode->getParentNodeSet(); |
| 4230 |
for (QSet<CHierarchyNode*>::const_iterator it = tmpParentNodeSet->constBegin(), itEnd = tmpParentNodeSet->constEnd(); it != itEnd; ++it) { |
| 4231 |
CHierarchyNode* nextParentNode(*it); |
| 4232 |
if (!visitedHierNodeSet->contains(nextParentNode)) { |
| 4233 |
visitedHierNodeSet->insert(nextParentNode); |
| 4234 |
visitHierNodetList.append(nextParentNode); |
| 4235 |
} |
| 4236 |
} |
| 4237 |
} |
| 4238 |
} |
| 4239 |
} |
| 4240 |
delete visitedHierNodeSet; |
| 4241 |
query->setQueryResult(classSynsetsResult); |
| 4242 |
} |
| 4243 |
if (compConQuery->isEquivalentClassNodesComputationRequired()) { |
| 4244 |
CClassSetResult* classesResult = new CClassSetResult(); |
| 4245 |
QSet<CHierarchyNode*>* childNodeSet = conceptItem->getDirectSubClassNodeSet(); |
| 4246 |
QSet<CHierarchyNode*>* parentNodeSet = conceptItem->getDirectSuperClassNodeSet(); |
| 4247 |
bool abbreviatedIRIs = false; |
| 4248 |
if (parentNodeSet && childNodeSet && parentNodeSet->size() == 1 && childNodeSet->size() == 1) { |
| 4249 |
CHierarchyNode* node = (*childNodeSet->constBegin()); |
| 4250 |
if (parentNodeSet->contains(node)) { |
| 4251 |
QStringList eqClassNameList(node->getEquivalentConceptStringList(abbreviatedIRIs)); |
| 4252 |
for (QStringList::const_iterator it = eqClassNameList.constBegin(), itEnd = eqClassNameList.constEnd(); it != itEnd; ++it) { |
| 4253 |
classesResult->addClass(*it); |
| 4254 |
} |
| 4255 |
} |
| 4256 |
} |
| 4257 |
query->setQueryResult(classesResult); |
| 4258 |
} |
| 4259 |
if (compConQuery->isInstancesComputationRequired()) { |
| 4260 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 4261 |
CConceptRealization* conceptRealization = mOntoAnsweringItem->getOntology()->getRealization()->getConceptRealization(); |
| 4262 |
|
| 4263 |
COptimizedComplexConceptInstanziatedIndividualItemHash* instanceItems = conceptItem->getKnownInstanceItems(); |
| 4264 |
bool abbreviatedIRIs = false; |
| 4265 |
COptimizedComplexConceptInstanziatedIndividualItemLinker* instanceItemsLinker = nullptr; |
| 4266 |
if (instanceItems) { |
| 4267 |
instanceItemsLinker = instanceItems->getAddedRealizationIndividualInstanceItemReferenceLinker(); |
| 4268 |
} |
| 4269 |
|
| 4270 |
|
| 4271 |
if (direct) { |
| 4272 |
// TODO: make more efficient |
| 4273 |
COptimizedComplexConceptInstanziatedIndividualItemHash* directInstanceItems = new COptimizedComplexConceptInstanziatedIndividualItemHash(*instanceItems); |
| 4274 |
for (auto node : *conceptItem->getDirectSubClassNodeSet()) { |
| 4275 |
CRealizationIndividualInstanceItemReferenceIterator* instanceIt = conceptRealization->getConceptInstancesIterator(node->getOneEquivalentConcept(), false, mDefaultRealizationSorting); |
| 4276 |
instanceIt->begin(); |
| 4277 |
while (!instanceIt->atEnd()) { |
| 4278 |
CRealizationIndividualInstanceItemReference itemRef = instanceIt->currentIndividualInstanceItemReference(); |
| 4279 |
COptimizedComplexConceptInstanziatedIndividualItemLinker itemRefLinker(itemRef); |
| 4280 |
directInstanceItems->remove(&itemRefLinker); |
| 4281 |
instanceIt->moveNext(); |
| 4282 |
} |
| 4283 |
delete instanceIt; |
| 4284 |
} |
| 4285 |
|
| 4286 |
instanceItemsLinker = nullptr; |
| 4287 |
CQtManagedRestrictedModificationHash<COptimizedComplexConceptInstanziatedIndividualItemHasher, COptimizedComplexConceptInstanziatedIndividualItemLinker*>* directIndiRefLinkerHash = directInstanceItems->getIndividualInstanceItemReferenceLinkerHash(); |
| 4288 |
for (CQtManagedRestrictedModificationHash<COptimizedComplexConceptInstanziatedIndividualItemHasher, COptimizedComplexConceptInstanziatedIndividualItemLinker*>::const_iterator it = directIndiRefLinkerHash->constBegin(), itEnd = directIndiRefLinkerHash->constEnd(); it != itEnd; ++it) { |
| 4289 |
COptimizedComplexConceptInstanziatedIndividualItemLinker* itemLinker = it.value(); |
| 4290 |
COptimizedComplexConceptInstanziatedIndividualItemLinker* newLinker = new COptimizedComplexConceptInstanziatedIndividualItemLinker(itemLinker->getRealizationIndividualInstanceItemReference()); |
| 4291 |
instanceItemsLinker = newLinker->append(instanceItemsLinker); |
| 4292 |
} |
| 4293 |
} |
| 4294 |
|
| 4295 |
|
| 4296 |
if (flattened) { |
| 4297 |
CIndividualsResult* individualResult = new CIndividualsResult(); |
| 4298 |
CIndividualsResultVisitorGenerator resultGenerator(individualResult, abbreviatedIRIs, true, mOntoAnsweringItem->getOntology()->getIndividualNameResolver()); |
| 4299 |
if (instanceItemsLinker) { |
| 4300 |
for (auto itemLinker = instanceItemsLinker; itemLinker; itemLinker = itemLinker->getNext()) { |
| 4301 |
sameRealization->visitSameIndividuals(itemLinker->getRealizationIndividualInstanceItemReference(), &resultGenerator); |
| 4302 |
} |
| 4303 |
} |
| 4304 |
query->setQueryResult(individualResult); |
| 4305 |
} else { |
| 4306 |
CIndividualSynsetsResult* indiSynsResult = new CIndividualSynsetsResult(); |
| 4307 |
if (instanceItemsLinker) { |
| 4308 |
for (auto itemLinker = instanceItemsLinker; itemLinker; itemLinker = itemLinker->getNext()) { |
| 4309 |
CIndividualSynsetResult* individualSynsetResult = new CIndividualSynsetResult(); |
| 4310 |
CIndividualSynsetResultVisitorGenerator resultGenerator(individualSynsetResult, abbreviatedIRIs, true, mOntoAnsweringItem->getOntology()->getIndividualNameResolver()); |
| 4311 |
sameRealization->visitSameIndividuals(itemLinker->getRealizationIndividualInstanceItemReference(), &resultGenerator); |
| 4312 |
indiSynsResult->addIndividualSynset(individualSynsetResult); |
| 4313 |
} |
| 4314 |
} |
| 4315 |
query->setQueryResult(indiSynsResult); |
| 4316 |
} |
| 4317 |
|
| 4318 |
if (direct) { |
| 4319 |
while (instanceItemsLinker) { |
| 4320 |
COptimizedComplexConceptInstanziatedIndividualItemLinker* tmpInstanceItemsLinker = instanceItemsLinker; |
| 4321 |
instanceItemsLinker = instanceItemsLinker->getNext(); |
| 4322 |
delete tmpInstanceItemsLinker; |
| 4323 |
} |
| 4324 |
} |
| 4325 |
|
| 4326 |
} |
| 4327 |
} |
| 4328 |
if (conceptItem) { |
| 4329 |
conceptItem->decQueryUsageCount(); |
| 4330 |
} |
| 4331 |
|
| 4332 |
queryProcessingData->setProcessingFinished(); |
| 4333 |
cint64 processingTime = queryProcessingData->getTotalProcessingTime(); |
| 4334 |
|
| 4335 |
QString realReqString; |
| 4336 |
CAnsweringHandlingStatistics* stats = mOntoAnsweringItem->getAnsweringHandlingStatistics(); |
| 4337 |
if (stats) { |
| 4338 |
CAnsweringHandlingStatistics* initialStats = queryProcessingData->getQueryProcessingInitializedAnsweringStatistics(); |
| 4339 |
if (initialStats) { |
| 4340 |
cint64 reqRealReqCount = stats->getRequestedRealizationRequirementCount() - initialStats->getRequestedRealizationRequirementCount(); |
| 4341 |
if (reqRealReqCount > 0) { |
| 4342 |
realReqString += QString(", using %1 realization requests").arg(reqRealReqCount); |
| 4343 |
} |
| 4344 |
} |
| 4345 |
} |
| 4346 |
|
| 4347 |
|
| 4348 |
LOG(INFO, getDomain(), logTr("Finished processing of complex query '%3' in %1 ms%2.").arg(processingTime).arg(realReqString).arg(query->getQueryName()), this); |
| 4349 |
|
| 4350 |
CCallbackData* callback = queryProcessingData->getCallback(); |
| 4351 |
if (callback) { |
| 4352 |
callback->doCallback(); |
| 4353 |
} |
| 4354 |
CComplexQueryExtendibleData* extendibleData = queryProcessingData->getQueryExtendibleData(); |
| 4355 |
if (extendibleData) { |
| 4356 |
installQueryExtendible(extendibleData, queryProcessingData); |
| 4357 |
} else { |
| 4358 |
delete queryProcessingData; |
| 4359 |
} |
| 4360 |
mOntoAnsweringItem->decCurrentlyAnsweringQueryCount(); |
| 4361 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incTotalAnsweredQueriesCount(); |
| 4362 |
cleanUpAnswersCache(true); |
| 4363 |
return true; |
| 4364 |
} |
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
|
| 4371 |
|
| 4372 |
|
| 4373 |
|
| 4374 |
|
| 4375 |
|
| 4376 |
|
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
|
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
|
| 4385 |
|
| 4386 |
|
| 4387 |
|
| 4388 |
bool COptimizedComplexExpressionAnsweringHandler::installQueryExtendible(CComplexQueryExtendibleData* extendibleData, CComplexQueryExpressionProcessingData* queryProcessingData) { |
| 4389 |
QHash<cint64, CComplexQueryExpressionProcessingData*>* queryExtensionProcessingDataHash = mOntoAnsweringItem->getQueryExtensionProcessingDataHash(); |
| 4390 |
cint64 nextQueryExtensionId = mOntoAnsweringItem->getNextQueryExtensionId(true); |
| 4391 |
extendibleData->setExtendibleId(nextQueryExtensionId); |
| 4392 |
queryExtensionProcessingDataHash->insert(nextQueryExtensionId, queryProcessingData); |
| 4393 |
return true; |
| 4394 |
} |
| 4395 |
|
| 4396 |
|
| 4397 |
|
| 4398 |
|
| 4399 |
|
| 4400 |
|
| 4401 |
|
| 4402 |
|
| 4403 |
|
| 4404 |
|
| 4405 |
|
| 4406 |
|
| 4407 |
|
| 4408 |
|
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
|
| 4415 |
|
| 4416 |
|
| 4417 |
|
| 4418 |
|
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
|
| 4427 |
|
| 4428 |
|
| 4429 |
|
| 4430 |
|
| 4431 |
|
| 4432 |
|
| 4433 |
|
| 4434 |
|
| 4435 |
|
| 4436 |
|
| 4437 |
|
| 4438 |
|
| 4439 |
|
| 4440 |
|
| 4441 |
|
| 4442 |
|
| 4443 |
|
| 4444 |
|
| 4445 |
|
| 4446 |
|
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
|
| 4451 |
|
| 4452 |
|
| 4453 |
|
| 4454 |
|
| 4455 |
|
| 4456 |
|
| 4457 |
|
| 4458 |
|
| 4459 |
|
| 4460 |
|
| 4461 |
|
| 4462 |
|
| 4463 |
|
| 4464 |
|
| 4465 |
|
| 4466 |
|
| 4467 |
|
| 4468 |
|
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 |
|
| 4473 |
|
| 4474 |
|
| 4475 |
|
| 4476 |
|
| 4477 |
|
| 4478 |
|
| 4479 |
|
| 4480 |
|
| 4481 |
|
| 4482 |
|
| 4483 |
bool COptimizedComplexExpressionAnsweringHandler::continueCalculationCreation(CAnswererContext* answererContext) { |
| 4484 |
bool processing = false; |
| 4485 |
COptimizedComplexConceptStepAnsweringItem* conSatProcStepItem = mOntoAnsweringItem->getConceptSatisfiabilityProcessingStepItem(); |
| 4486 |
COptimizedComplexConceptStepAnsweringItem* conSuperProcStepItem = mOntoAnsweringItem->getConceptSuperClassesProcessingStepItem(); |
| 4487 |
COptimizedComplexConceptStepAnsweringItem* conSubProcStepItem = mOntoAnsweringItem->getConceptSubClassesProcessingStepItem(); |
| 4488 |
COptimizedComplexConceptStepAnsweringItem* conSubRealStepItem = mOntoAnsweringItem->getConceptSubClassesRealizationProcessingStepItem(); |
| 4489 |
COptimizedComplexConceptStepAnsweringItem* conEqProcStepItem = mOntoAnsweringItem->getConceptEquivalentClassesProcessingStepItem(); |
| 4490 |
COptimizedComplexConceptStepAnsweringItem* instancesProcStepItem = mOntoAnsweringItem->getConceptInstancesProcessingStepItem(); |
| 4491 |
QList<COptimizedComplexBuildingVariableCompositionsItem*>* buildingVarItemList = mOntoAnsweringItem->getVariableBuildingItemProcessingList(); |
| 4492 |
while (!processing && (conSatProcStepItem->hasConceptItemsQueued() || conSuperProcStepItem->hasConceptItemsQueued() || conSubProcStepItem->hasConceptItemsQueued() || conEqProcStepItem->hasConceptItemsQueued() || instancesProcStepItem->hasConceptItemsQueued() || !buildingVarItemList->isEmpty())) { |
| 4493 |
|
| 4494 |
|
| 4495 |
processing = createComplexConceptItemCalculation(processing, conSatProcStepItem, answererContext, conSuperProcStepItem, conSubProcStepItem, conSubRealStepItem, conEqProcStepItem, instancesProcStepItem); |
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
// variable items |
| 4502 |
if (!processing && !buildingVarItemList->isEmpty()) { |
| 4503 |
bool continueProcessingBuildingVarItem = false; |
| 4504 |
COptimizedComplexBuildingVariableCompositionsItem* buildVarItem = buildingVarItemList->first(); |
| 4505 |
|
| 4506 |
COptimizedComplexBuildingClassVariableCompositionsItem* buildingClassVarItem = dynamic_cast<COptimizedComplexBuildingClassVariableCompositionsItem*>(buildVarItem); |
| 4507 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* buildingPropVarItem = dynamic_cast<COptimizedComplexBuildingPropertyVariableCompositionsItem*>(buildVarItem); |
| 4508 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingIndiVarItem = dynamic_cast<COptimizedComplexBuildingIndividualVariableCompositionsItem*>(buildVarItem); |
| 4509 |
COptimizedComplexBuildingIndividualMixedVariableCompositionsItem* buildingIndiMixedVarItem = dynamic_cast<COptimizedComplexBuildingIndividualMixedVariableCompositionsItem*>(buildVarItem); |
| 4510 |
if (buildingIndiVarItem) { |
| 4511 |
|
| 4512 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem*>* absorptionHanldingQueryExtensionPropagationList = buildingIndiVarItem->getAbsorptionBasedHandlingExtensionItemPropagationList(); |
| 4513 |
if (!processing && absorptionHanldingQueryExtensionPropagationList && !absorptionHanldingQueryExtensionPropagationList->isEmpty() && buildingIndiVarItem->isSatisfiable()) { |
| 4514 |
COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationItem = absorptionHanldingQueryExtensionPropagationList->takeFirst(); |
| 4515 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHanldingQueryPart = absorptionPropagationItem->getAbsorptionBasedHandlingData(); |
| 4516 |
|
| 4517 |
absorptionPropagationItem->setSplitPropagationItemProcessingQueued(false); |
| 4518 |
if (absorptionHanldingQueryPart->hasIndividualVariables()) { |
| 4519 |
processing = createVariableBindingPropagationTest(absorptionPropagationItem, buildingIndiVarItem, answererContext, continueProcessingBuildingVarItem); |
| 4520 |
} else { |
| 4521 |
processing = createAbsorbedQueryPartEntailmentTest(absorptionPropagationItem, buildingIndiVarItem, answererContext, continueProcessingBuildingVarItem); |
| 4522 |
} |
| 4523 |
|
| 4524 |
} |
| 4525 |
} |
| 4526 |
|
| 4527 |
|
| 4528 |
bool subBuildItemProcessing = false; |
| 4529 |
QList<COptimizedComplexVariableCompositionItem*>* compositionVarItemList = buildVarItem->getComputeVariableMappingItemList(); |
| 4530 |
// variable composition items |
| 4531 |
while (!processing && !compositionVarItemList->isEmpty()) { |
| 4532 |
COptimizedComplexVariableCompositionItem* compVarItem = compositionVarItemList->takeFirst(); |
| 4533 |
startMeasuringVariableCompositionItemComputationCost(compVarItem); |
| 4534 |
compVarItem->setVariableMappingsComputationStarted(true); |
| 4535 |
|
| 4536 |
if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::CONCEPT_BASE) { |
| 4537 |
computeVariableCompositionItemFromConceptItemBase(compVarItem, buildVarItem, processing); |
| 4538 |
|
| 4539 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::CONCEPT_SUB_SUPER_CLASSES) { |
| 4540 |
computeVariableCompositionItemFromConceptItemSubSuperCLasses(compVarItem, buildVarItem); |
| 4541 |
|
| 4542 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::SUB_SUPER_CLASSES_PROPAGATION) { |
| 4543 |
computeVariableCompositionItemSubSuperClassesPropagation(compVarItem, buildVarItem); |
| 4544 |
|
| 4545 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::ROLE_SUB_SUPER_PROPERTIES) { |
| 4546 |
computeVariableCompositionItemFromRoleSubSuperProperties(compVarItem, buildVarItem); |
| 4547 |
|
| 4548 |
|
| 4549 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::SUB_SUPER_PROPERTIES_PROPAGATION) { |
| 4550 |
computeVariableCompositionItemSubSuperPropertiesPropagation(compVarItem, buildVarItem); |
| 4551 |
|
| 4552 |
|
| 4553 |
|
| 4554 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::INDIVIDUAL_TYPE_EXTENSION) { |
| 4555 |
computeVariableCompositionItemIndividualTypeExtension(compVarItem, buildingIndiMixedVarItem, processing, subBuildItemProcessing); |
| 4556 |
|
| 4557 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::INDIVIDUAL_PROPERTY_EXTENSION) { |
| 4558 |
computeVariableCompositionItemIndividualPropertyExtension(compVarItem, buildingIndiMixedVarItem, processing, subBuildItemProcessing); |
| 4559 |
|
| 4560 |
|
| 4561 |
|
| 4562 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::BINDING_REDUCTION) { |
| 4563 |
computeVariableCompositionItemReduction(compVarItem, buildVarItem); |
| 4564 |
|
| 4565 |
|
| 4566 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::BINDING_EXTRACTION) { |
| 4567 |
computeVariableCompositionItemExtraction(compVarItem, buildVarItem); |
| 4568 |
|
| 4569 |
|
| 4570 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::JOINING) { |
| 4571 |
computeVariableCompositionItemJoin(compVarItem, buildVarItem, processing); |
| 4572 |
|
| 4573 |
|
| 4574 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::ROLE_PROPAGATION || compVarItem->getCompositionType() == COptimizedComplexVariableRolePropagationJoiningItem::ROLE_PROPAGATION_JOIN || compVarItem->getCompositionType() == COptimizedComplexVariableRolePropagationReplacementItem::ROLE_PROPAGATION_REPLACEMENT) { |
| 4575 |
computeVariableCompositionItemPropagation(compVarItem, buildVarItem, answererContext, processing); |
| 4576 |
|
| 4577 |
|
| 4578 |
|
| 4579 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::DATA_LITERAL_BASE) { |
| 4580 |
computeVariableCompositionItemFromDataLiteralBase(compVarItem, answererContext, buildVarItem); |
| 4581 |
|
| 4582 |
|
| 4583 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::ABSOROPTION_BASED_EXTENSION) { |
| 4584 |
computeVariableCompositionItemAbsorptionBasedExtension(compVarItem, processing, buildingIndiVarItem, answererContext, continueProcessingBuildingVarItem); |
| 4585 |
|
| 4586 |
|
| 4587 |
|
| 4588 |
} else if (compVarItem->getCompositionType() == COptimizedComplexVariableCompositionItem::DATA_LITERAL_EXTENSION) { |
| 4589 |
computeVariableCompositionItemDataLiteralExtension(compVarItem, answererContext, buildVarItem); |
| 4590 |
|
| 4591 |
} |
| 4592 |
|
| 4593 |
compVarItem->setComputationQueued(false); |
| 4594 |
if (!processing) { |
| 4595 |
endMeasuringVariableCompositionItemComputationCost(compVarItem); |
| 4596 |
} |
| 4597 |
|
| 4598 |
} |
| 4599 |
|
| 4600 |
|
| 4601 |
|
| 4602 |
|
| 4603 |
|
| 4604 |
|
| 4605 |
|
| 4606 |
|
| 4607 |
|
| 4608 |
|
| 4609 |
|
| 4610 |
|
| 4611 |
|
| 4612 |
// building variable items |
| 4613 |
if (!subBuildItemProcessing && !processing && compositionVarItemList->isEmpty() && buildingIndiVarItem) { |
| 4614 |
processing = createIndividualVariableCompositionItemsComputation(buildingIndiVarItem, processing, continueProcessingBuildingVarItem, compositionVarItemList, answererContext); |
| 4615 |
} |
| 4616 |
|
| 4617 |
|
| 4618 |
// building classes items |
| 4619 |
if (!subBuildItemProcessing && !processing && compositionVarItemList->isEmpty() && buildingClassVarItem) { |
| 4620 |
processing = createClassVariableCompositionItemsComputation(buildingClassVarItem, processing, continueProcessingBuildingVarItem, compositionVarItemList, answererContext); |
| 4621 |
} |
| 4622 |
|
| 4623 |
// building property items |
| 4624 |
if (!subBuildItemProcessing && !processing && compositionVarItemList->isEmpty() && buildingPropVarItem) { |
| 4625 |
processing = createPropertyVariableCompositionItemsComputation(buildingPropVarItem, processing, continueProcessingBuildingVarItem, compositionVarItemList, answererContext); |
| 4626 |
} |
| 4627 |
|
| 4628 |
// building indi mixed items |
| 4629 |
if (!subBuildItemProcessing && !processing && compositionVarItemList->isEmpty() && buildingIndiMixedVarItem) { |
| 4630 |
processing = createIndividualMixedVariableCompositionItemsComputation(buildingIndiMixedVarItem, processing, continueProcessingBuildingVarItem, compositionVarItemList, answererContext); |
| 4631 |
} |
| 4632 |
|
| 4633 |
if (subBuildItemProcessing || processing && buildVarItem->isWaitingComputation() && !continueProcessingBuildingVarItem) { |
| 4634 |
buildingVarItemList->removeFirst(); |
| 4635 |
buildVarItem->setProcessingQueued(false); |
| 4636 |
} |
| 4637 |
|
| 4638 |
|
| 4639 |
if (!processing && !subBuildItemProcessing) { |
| 4640 |
if (!buildVarItem->isWaitingComputation() && (!buildVarItem->isSatisfiable() || buildVarItem->getComputeVariableMappingItemList()->isEmpty())) { |
| 4641 |
CComplexQueryExpressionProcessingData* queryProcData = buildVarItem->getQueryProcessingData(); |
| 4642 |
queryProcData->decBuildingVariableItem(); |
| 4643 |
|
| 4644 |
buildingVarItemList->removeFirst(); |
| 4645 |
buildVarItem->setProcessingQueued(false); |
| 4646 |
|
| 4647 |
CComputedItemDataNotificationLinker* notLinker = buildVarItem->takeNotificationLinker(); |
| 4648 |
if (notLinker) { |
| 4649 |
COptimizedComplexBuildingVariableCompositionsItem* depBuildVarItem = notLinker->getBuildingVariableItemProcessingItem(); |
| 4650 |
if (depBuildVarItem) { |
| 4651 |
depBuildVarItem->decWaitingSubVariableBuildingItemCount(); |
| 4652 |
if (!depBuildVarItem->isWaitingComputation() && !depBuildVarItem->isProcessingQueued()) { |
| 4653 |
depBuildVarItem->setProcessingQueued(true); |
| 4654 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(depBuildVarItem); |
| 4655 |
} |
| 4656 |
} |
| 4657 |
} |
| 4658 |
|
| 4659 |
|
| 4660 |
if (!queryProcData->hasComputation()) { |
| 4661 |
if (queryProcData->isComputationError()) { |
| 4662 |
failQueryProcessing(queryProcData, new CQueryUnspecifiedStringError("Error in computation")); |
| 4663 |
} else if (!finishQueryProcessing(queryProcData)) { |
| 4664 |
queryProcData->incBuildingVariableItem(); |
| 4665 |
if (!buildVarItem->isProcessingQueued()) { |
| 4666 |
buildVarItem->setProcessingQueued(true); |
| 4667 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(buildVarItem); |
| 4668 |
} |
| 4669 |
} |
| 4670 |
} |
| 4671 |
} |
| 4672 |
} |
| 4673 |
|
| 4674 |
|
| 4675 |
|
| 4676 |
|
| 4677 |
} |
| 4678 |
|
| 4679 |
} |
| 4680 |
|
| 4681 |
return processing; |
| 4682 |
} |
| 4683 |
|
| 4684 |
|
| 4685 |
|
| 4686 |
|
| 4687 |
bool COptimizedComplexExpressionAnsweringHandler::createComplexConceptItemCalculation(bool processing, COptimizedComplexConceptStepAnsweringItem* conSatProcStepItem, CAnswererContext* answererContext, COptimizedComplexConceptStepAnsweringItem* conSuperProcStepItem, COptimizedComplexConceptStepAnsweringItem* conSubProcStepItem, COptimizedComplexConceptStepAnsweringItem* conSubRealStepItem, COptimizedComplexConceptStepAnsweringItem* conEqProcStepItem, COptimizedComplexConceptStepAnsweringItem* instancesProcStepItem) { |
| 4688 |
// satisfiability |
| 4689 |
if (!processing && conSatProcStepItem->hasConceptItemsQueued()) { |
| 4690 |
COptimizedComplexConceptItem* conceptItem = conSatProcStepItem->takeNextQueuedConceptItem(); |
| 4691 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getSatisfiableClassNodesComputationProcess(true); |
| 4692 |
compStep->setComputationProcessQueued(false); |
| 4693 |
if (!compStep->isComputationProcessFinished()) { |
| 4694 |
if (searchSuperSubSatisfiabilityResult(conceptItem, answererContext)) { |
| 4695 |
} else if (createSatisfiabilityTest(conceptItem, answererContext)) { |
| 4696 |
processing = true; |
| 4697 |
compStep->setComputationProcessStarted(true); |
| 4698 |
compStep->setComputationProcessProcessing(true); |
| 4699 |
compStep->incCurrentlyRunningComputationCount(); |
| 4700 |
} |
| 4701 |
} |
| 4702 |
if (!processing) { |
| 4703 |
finishCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 4704 |
} |
| 4705 |
} |
| 4706 |
// super classes |
| 4707 |
if (!processing && conSuperProcStepItem->hasConceptItemsQueued()) { |
| 4708 |
COptimizedComplexConceptItem* conceptItem = conSuperProcStepItem->getNextQueuedConceptItem(); |
| 4709 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getSuperClassNodesComputationProcess(true); |
| 4710 |
processing = false; |
| 4711 |
if (!compStep->isComputationProcessFinished()) { |
| 4712 |
QList<CHierarchyNode*>* possibleClassNodeTestingList = conceptItem->getPossibleSuperClassNodeTestingList(); |
| 4713 |
if (!possibleClassNodeTestingList && !compStep->isComputationProcessStarted()) { |
| 4714 |
compStep->setComputationProcessStarted(true); |
| 4715 |
|
| 4716 |
searchSuperSubSuperClassesResult(conceptItem, answererContext); |
| 4717 |
|
| 4718 |
QSet<CConcept*>* knowSuperConceptSet = conceptItem->getKnownSuperConceptSet(); |
| 4719 |
QSet<CConcept*>* possibleSuperConceptSet = conceptItem->getPossibleSuperConceptSet(); |
| 4720 |
QSet<CHierarchyNode*>* knownSuperClassesSet = conceptItem->getKnownSuperClassNodeSet(); |
| 4721 |
QSet<CHierarchyNode*>* possibleSuperClassesSet = conceptItem->getPossibleSuperClassNodeSet(); |
| 4722 |
|
| 4723 |
|
| 4724 |
if (knowSuperConceptSet && possibleSuperConceptSet || knownSuperClassesSet && possibleSuperClassesSet) { |
| 4725 |
conceptItem->setSuperClassComputationInitializing(false); |
| 4726 |
} else { |
| 4727 |
conceptItem->setSuperClassComputationInitializing(true); |
| 4728 |
if (createSatisfiabilityTest(conceptItem, answererContext)) { |
| 4729 |
processing = true; |
| 4730 |
compStep->setComputationProcessProcessing(true); |
| 4731 |
compStep->incCurrentlyRunningComputationCount(); |
| 4732 |
} |
| 4733 |
} |
| 4734 |
} |
| 4735 |
|
| 4736 |
if (!possibleClassNodeTestingList && !conceptItem->isSuperClassComputationInitializing()) { |
| 4737 |
|
| 4738 |
QSet<CConcept*>* knowSuperConceptSet = conceptItem->getKnownSuperConceptSet(); |
| 4739 |
if (knowSuperConceptSet) { |
| 4740 |
CClassConceptClassification* classClassification = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification(); |
| 4741 |
CTaxonomy* taxonomy = classClassification->getClassConceptTaxonomy(); |
| 4742 |
QSet<CHierarchyNode*>* knownSuperClassesSet = conceptItem->getKnownSuperClassNodeSet(); |
| 4743 |
if (!knownSuperClassesSet) { |
| 4744 |
knownSuperClassesSet = new QSet<CHierarchyNode*>(); |
| 4745 |
conceptItem->setKnownSuperClassNodeSet(knownSuperClassesSet); |
| 4746 |
} |
| 4747 |
for (QSet<CConcept*>::const_iterator it = knowSuperConceptSet->constBegin(), itEnd = knowSuperConceptSet->constEnd(); it != itEnd; ++it) { |
| 4748 |
CConcept* knownSuperClass(*it); |
| 4749 |
CHierarchyNode* hierNode = taxonomy->getHierarchyNode(knownSuperClass, false); |
| 4750 |
knownSuperClassesSet->insert(hierNode); |
| 4751 |
} |
| 4752 |
delete knowSuperConceptSet; |
| 4753 |
conceptItem->setKnownSuperConceptSet(nullptr); |
| 4754 |
} |
| 4755 |
|
| 4756 |
QSet<CConcept*>* possibleSuperConceptSet = conceptItem->getPossibleSuperConceptSet(); |
| 4757 |
if (possibleSuperConceptSet) { |
| 4758 |
CClassConceptClassification* classClassification = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification(); |
| 4759 |
CTaxonomy* taxonomy = classClassification->getClassConceptTaxonomy(); |
| 4760 |
QSet<CHierarchyNode*>* knownSuperClassesSet = conceptItem->getKnownSuperClassNodeSet(); |
| 4761 |
QSet<CHierarchyNode*>* possibleSuperClassesSet = new QSet<CHierarchyNode*>(); |
| 4762 |
for (QSet<CConcept*>::const_iterator it = possibleSuperConceptSet->constBegin(), itEnd = possibleSuperConceptSet->constEnd(); it != itEnd; ++it) { |
| 4763 |
CConcept* possibleSuperClass(*it); |
| 4764 |
CHierarchyNode* hierNode = taxonomy->getHierarchyNode(possibleSuperClass, false); |
| 4765 |
if (!knownSuperClassesSet->contains(hierNode)) { |
| 4766 |
possibleSuperClassesSet->insert(hierNode); |
| 4767 |
} |
| 4768 |
} |
| 4769 |
if (conceptItem->getPossibleSuperClassNodeSet()) { |
| 4770 |
conceptItem->getPossibleSuperClassNodeSet()->intersect(*possibleSuperClassesSet); |
| 4771 |
delete possibleSuperClassesSet; |
| 4772 |
} else { |
| 4773 |
conceptItem->setPossibleSuperClassNodeSet(possibleSuperClassesSet); |
| 4774 |
} |
| 4775 |
delete possibleSuperConceptSet; |
| 4776 |
conceptItem->setPossibleSuperConceptSet(nullptr); |
| 4777 |
} |
| 4778 |
|
| 4779 |
|
| 4780 |
QSet<CHierarchyNode*>* possibleSuperClassNodeSet = conceptItem->getPossibleSuperClassNodeSet(); |
| 4781 |
if (!possibleSuperClassNodeSet || possibleSuperClassNodeSet->isEmpty()) { |
| 4782 |
QSet<CHierarchyNode*>* knownSuperClassSet = conceptItem->getKnownSuperClassNodeSet(); |
| 4783 |
if (knownSuperClassSet) { |
| 4784 |
QSet<CHierarchyNode*>* directSuperClassSet = getDirectReducedSuperNodeSet(*knownSuperClassSet); |
| 4785 |
conceptItem->setKnownSuperClassNodeSet(nullptr); |
| 4786 |
delete knownSuperClassSet; |
| 4787 |
conceptItem->setDirectSuperClassNodeSet(directSuperClassSet); |
| 4788 |
delete possibleSuperClassNodeSet; |
| 4789 |
conceptItem->setPossibleSuperClassNodeSet(nullptr); |
| 4790 |
} |
| 4791 |
finishCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 4792 |
} else { |
| 4793 |
possibleClassNodeTestingList = new QList<CHierarchyNode *>(); |
| 4794 |
for (QSet<CHierarchyNode*>::const_iterator it = possibleSuperClassNodeSet->constBegin(), itEnd = possibleSuperClassNodeSet->constEnd(); it != itEnd; ++it) { |
| 4795 |
CHierarchyNode* hierNode(*it); |
| 4796 |
possibleClassNodeTestingList->append(hierNode); |
| 4797 |
} |
| 4798 |
qSort(possibleClassNodeTestingList->begin(), possibleClassNodeTestingList->end(), nodeSortMorePredecessorsThan); |
| 4799 |
conceptItem->setPossibleSuperClassNodeTestingList(possibleClassNodeTestingList); |
| 4800 |
delete possibleSuperClassNodeSet; |
| 4801 |
conceptItem->setPossibleSuperClassNodeSet(nullptr); |
| 4802 |
} |
| 4803 |
} |
| 4804 |
if (possibleClassNodeTestingList && !possibleClassNodeTestingList->isEmpty()) { |
| 4805 |
CHierarchyNode* testingNode = possibleClassNodeTestingList->takeFirst(); |
| 4806 |
if (createSuperClassSubsumptionTest(conceptItem, testingNode, answererContext)) { |
| 4807 |
processing = true; |
| 4808 |
compStep->setComputationProcessProcessing(true); |
| 4809 |
compStep->incCurrentlyRunningComputationCount(); |
| 4810 |
} |
| 4811 |
} |
| 4812 |
if (!possibleClassNodeTestingList || possibleClassNodeTestingList->isEmpty()) { |
| 4813 |
compStep->setComputationProcessQueued(false); |
| 4814 |
conSuperProcStepItem->takeNextQueuedConceptItem(); |
| 4815 |
} |
| 4816 |
} |
| 4817 |
} |
| 4818 |
|
| 4819 |
// sub classes |
| 4820 |
if (!processing && conSubProcStepItem->hasConceptItemsQueued()) { |
| 4821 |
COptimizedComplexConceptItem* conceptItem = conSubProcStepItem->getNextQueuedConceptItem(); |
| 4822 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getSubClassNodesComputationProcess(true); |
| 4823 |
processing = false; |
| 4824 |
if (!compStep->isComputationProcessFinished()) { |
| 4825 |
if (!compStep->isComputationProcessStarted()) { |
| 4826 |
compStep->setComputationProcessStarted(true); |
| 4827 |
|
| 4828 |
searchSuperSubSubClassesResult(conceptItem, answererContext); |
| 4829 |
} |
| 4830 |
|
| 4831 |
|
| 4832 |
QList<CHierarchyNode*>* possibleClassNodeTestingList = conceptItem->getPossibleSubClassNodeTestingList(); |
| 4833 |
if (possibleClassNodeTestingList && !possibleClassNodeTestingList->isEmpty()) { |
| 4834 |
CHierarchyNode* testingNode = possibleClassNodeTestingList->takeFirst(); |
| 4835 |
QSet<CHierarchyNode*>* maxSubNodeSet = conceptItem->getMaximumSubClassNodeSet(); |
| 4836 |
if (maxSubNodeSet && maxSubNodeSet->contains(testingNode)) { |
| 4837 |
conceptItem->getDirectSubClassNodeSet()->insert(testingNode); |
| 4838 |
} else if (createSubClassSubsumptionTest(conceptItem, testingNode, answererContext)) { |
| 4839 |
processing = true; |
| 4840 |
compStep->setComputationProcessProcessing(true); |
| 4841 |
compStep->incCurrentlyRunningComputationCount(); |
| 4842 |
} |
| 4843 |
} |
| 4844 |
if (!possibleClassNodeTestingList || possibleClassNodeTestingList->isEmpty()) { |
| 4845 |
compStep->setComputationProcessQueued(false); |
| 4846 |
conSubProcStepItem->takeNextQueuedConceptItem(); |
| 4847 |
if (compStep->getCurrentlyRunningComputationCount() == 0) { |
| 4848 |
if (!conceptItem->getPossibleSubClassNodeTestingList() || conceptItem->getPossibleSubClassNodeTestingList()->isEmpty()) { |
| 4849 |
finishSubClassCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 4850 |
} |
| 4851 |
} |
| 4852 |
} |
| 4853 |
} |
| 4854 |
} |
| 4855 |
|
| 4856 |
|
| 4857 |
if (!processing && conSubRealStepItem->hasConceptItemsQueued()) { |
| 4858 |
COptimizedComplexConceptItem* conceptItem = conSubRealStepItem->getNextQueuedConceptItem(); |
| 4859 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getSubClassRealizationProcess(true); |
| 4860 |
CHierarchyNode* bottomHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getBottomHierarchyNode(); |
| 4861 |
|
| 4862 |
if (!compStep->isComputationProcessFinished()) { |
| 4863 |
if (!compStep->isComputationProcessStarted()) { |
| 4864 |
compStep->setComputationProcessStarted(true); |
| 4865 |
|
| 4866 |
QList<COntologyProcessingRequirement*> reqList; |
| 4867 |
for (CHierarchyNode* node : *conceptItem->getDirectSubClassNodeSet()) { |
| 4868 |
if (node != bottomHierNode) { |
| 4869 |
COntologyProcessingConceptRealizationRequirement* conRealReq = new COntologyProcessingConceptRealizationRequirement(CIndividualReference(), node->getOneEquivalentConcept()); |
| 4870 |
reqList.append(conRealReq); |
| 4871 |
} |
| 4872 |
} |
| 4873 |
|
| 4874 |
if (!reqList.isEmpty()) { |
| 4875 |
CAnsweringMessageDataRequirementCompletedRealization* reqCompMess = new CAnsweringMessageDataRequirementCompletedRealization(conceptItem); |
| 4876 |
processRequirements(answererContext, mOntoAnsweringItem->getOntology(), reqList, reqCompMess); |
| 4877 |
processing = true; |
| 4878 |
} else { |
| 4879 |
finishCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 4880 |
} |
| 4881 |
} |
| 4882 |
} |
| 4883 |
|
| 4884 |
} |
| 4885 |
|
| 4886 |
// equivalent classes |
| 4887 |
if (!processing && conEqProcStepItem->hasConceptItemsQueued()) { |
| 4888 |
COptimizedComplexConceptItem* conceptItem = conEqProcStepItem->takeNextQueuedConceptItem(); |
| 4889 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getEquivalentClassNodesComputationProcess(true); |
| 4890 |
compStep->setComputationProcessQueued(false); |
| 4891 |
if (!compStep->isComputationProcessStarted()) { |
| 4892 |
compStep->setComputationProcessStarted(true); |
| 4893 |
} |
| 4894 |
if (!processing) { |
| 4895 |
finishCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 4896 |
} |
| 4897 |
} |
| 4898 |
|
| 4899 |
|
| 4900 |
// instances |
| 4901 |
if (!processing && instancesProcStepItem->hasConceptItemsQueued()) { |
| 4902 |
COptimizedComplexConceptItem* conceptItem = instancesProcStepItem->getNextQueuedConceptItem(); |
| 4903 |
CComplexConceptStepInstanceComputationProcess* compStep = conceptItem->getComputationProcess()->getInstancesComputationProcess(true); |
| 4904 |
processing = false; |
| 4905 |
if (!compStep->isComputationProcessFinished() || compStep->requiresAdditionalInstanceComputation()) { |
| 4906 |
|
| 4907 |
startMeasuringComplexConceptItemComputationCost(conceptItem); |
| 4908 |
|
| 4909 |
|
| 4910 |
if (!conceptItem->isLazyRealizationInitialized()) { |
| 4911 |
conceptItem->setLazyRealizationInitialized(true); |
| 4912 |
if (initializeRealization(conceptItem, answererContext)) { |
| 4913 |
processing = true; |
| 4914 |
compStep->setComputationProcessQueued(false); |
| 4915 |
instancesProcStepItem->takeNextQueuedConceptItem(); |
| 4916 |
} |
| 4917 |
} |
| 4918 |
|
| 4919 |
cint64 newRequiredCandidateCount = 0; |
| 4920 |
if (compStep->requiresAllInstanceComputation()) { |
| 4921 |
newRequiredCandidateCount = -1; |
| 4922 |
} else { |
| 4923 |
// subtract the eliminated candidates, i.e., those instance candidates that are confirmed non-instances |
| 4924 |
cint64 possibleTestedNonInstanceCount = conceptItem->getPossibleTestedNonInstanceCount(); |
| 4925 |
cint64 realizationRetrievedInstanceCandidateCount = conceptItem->getRealizationRetrievedInstanceCandidateCount(); |
| 4926 |
cint64 requiredInstancesCount = compStep->getRequiredInstancesCount(); |
| 4927 |
newRequiredCandidateCount = requiredInstancesCount - realizationRetrievedInstanceCandidateCount + possibleTestedNonInstanceCount; |
| 4928 |
if (newRequiredCandidateCount < 0) { |
| 4929 |
newRequiredCandidateCount = 0; |
| 4930 |
} |
| 4931 |
} |
| 4932 |
|
| 4933 |
|
| 4934 |
if (conceptItem->isLazyRealizationInitialized() && !conceptItem->isLazyRealizationProcessing() && !compStep->isComputationProcessStarted()) { |
| 4935 |
compStep->setComputationProcessStarted(true); |
| 4936 |
|
| 4937 |
if (mConfExtendedLogging) { |
| 4938 |
LOG(INFO, getDomain(), logTr("Starting instance computation for complex concept item %1.").arg(conceptItem->getConceptItemId()), this); |
| 4939 |
} |
| 4940 |
|
| 4941 |
|
| 4942 |
|
| 4943 |
if (initializeRealizationInstancesIterators(conceptItem, newRequiredCandidateCount, answererContext)) { |
| 4944 |
processing = true; |
| 4945 |
compStep->setComputationProcessQueued(false); |
| 4946 |
instancesProcStepItem->takeNextQueuedConceptItem(); |
| 4947 |
} |
| 4948 |
} |
| 4949 |
|
| 4950 |
|
| 4951 |
|
| 4952 |
if (!processing && !conceptItem->isLazyRealizationProcessing() && !conceptItem->isCompletelyHandledChecked()) { |
| 4953 |
conceptItem->setCompletelyHandledChecked(true); |
| 4954 |
checkPossibleInstancesCompletelyHandled(conceptItem, answererContext); |
| 4955 |
} |
| 4956 |
|
| 4957 |
|
| 4958 |
if (!processing && compStep->isComputationProcessStarted() && !conceptItem->isLazyRealizationProcessing() && !conceptItem->isLazyRealizationInstancesRetrieved()) { |
| 4959 |
|
| 4960 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 4961 |
|
| 4962 |
if ((!possibleInstanceItemSet || possibleInstanceItemSet->isEmpty() || conceptItem->isLazyRealizationInitializationRequested()) && newRequiredCandidateCount != 0) { |
| 4963 |
conceptItem->setLazyRealizationInitializationRequested(false); |
| 4964 |
|
| 4965 |
cint64 retrievingCount = newRequiredCandidateCount; |
| 4966 |
double minRetrievingSize = conceptItem->getMinimalRetrievingInstanceItemSize(); |
| 4967 |
if (retrievingCount != -1) { |
| 4968 |
minRetrievingSize = qMin(minRetrievingSize, mConfConceptItemInstanceCandiateRetrievingMaxSize); |
| 4969 |
retrievingCount = qMax(retrievingCount, (cint64)minRetrievingSize); |
| 4970 |
} |
| 4971 |
|
| 4972 |
if (initializeKnownPossibleInstances(conceptItem, retrievingCount, answererContext)) { |
| 4973 |
conceptItem->setLazyRealizationInitializationRequested(true); |
| 4974 |
processing = true; |
| 4975 |
compStep->setComputationProcessQueued(false); |
| 4976 |
instancesProcStepItem->takeNextQueuedConceptItem(); |
| 4977 |
} else { |
| 4978 |
|
| 4979 |
if (retrievingCount != -1 && minRetrievingSize < mConfConceptItemInstanceCandiateRetrievingMaxSize) { |
| 4980 |
minRetrievingSize *= mConfConceptItemInstanceCandiateRetrievingSizeIncreaseFactor; |
| 4981 |
conceptItem->setMinimalRetrievingInstanceItemSize(minRetrievingSize); |
| 4982 |
} |
| 4983 |
|
| 4984 |
if (mConfExtendedLogging) { |
| 4985 |
|
| 4986 |
cint64 newCertainInstances = conceptItem->getLastRetrievedCertainInstanceItemCount(); |
| 4987 |
cint64 possibleInstances = 0; |
| 4988 |
QString requestedCountString = QString::number(retrievingCount); |
| 4989 |
if (newRequiredCandidateCount == -1) { |
| 4990 |
requestedCountString = QString("all"); |
| 4991 |
} |
| 4992 |
if (conceptItem->getPossibleInstanceItemSet()) { |
| 4993 |
possibleInstances = conceptItem->getPossibleInstanceItemSet()->size(); |
| 4994 |
} |
| 4995 |
mTotalPossibleInstancesCount += possibleInstances; |
| 4996 |
LOG(INFO, getDomain(), logTr("Retrieved %2 certain and %3 possible of %4 requested instances for complex concept item %1.").arg(conceptItem->getConceptItemId()).arg(newCertainInstances).arg(possibleInstances).arg(requestedCountString), this); |
| 4997 |
} |
| 4998 |
|
| 4999 |
conceptItem->setCompletelyHandledChecked(false); |
| 5000 |
conceptItem->setCandidatePropagated(false); |
| 5001 |
} |
| 5002 |
} |
| 5003 |
} |
| 5004 |
|
| 5005 |
|
| 5006 |
|
| 5007 |
//if (!processing && !conceptItem->isLazyRealizationProcessing() && !compStep->isComputationProcessStarted()) { |
| 5008 |
// compStep->setComputationProcessStarted(true); |
| 5009 |
|
| 5010 |
// searchKnownPossibleInstances(conceptItem, answererContext); |
| 5011 |
//} |
| 5012 |
|
| 5013 |
|
| 5014 |
//if (!processing && !conceptItem->isLazyRealizationProcessing() && !conceptItem->isLazyNeighbourRealizationRequested()) { |
| 5015 |
// conceptItem->setLazyNeighbourRealizationRequested(true); |
| 5016 |
// if (schedulePossibleInstancesNeighourRealization(conceptItem, answererContext)) { |
| 5017 |
// processing = true; |
| 5018 |
// compStep->setComputationProcessQueued(false); |
| 5019 |
// instancesProcStepItem->takeNextQueuedConceptItem(); |
| 5020 |
// } |
| 5021 |
//} |
| 5022 |
|
| 5023 |
|
| 5024 |
//if (!processing && !conceptItem->isLazyRealizationProcessing() && conceptItem->isLazyNeighbourRealizationPruningRequired()) { |
| 5025 |
// conceptItem->setLazyNeighbourRealizationPruningRequired(false); |
| 5026 |
// neighboursPrunePossibleInstances(conceptItem, answererContext); |
| 5027 |
//} |
| 5028 |
|
| 5029 |
|
| 5030 |
|
| 5031 |
|
| 5032 |
|
| 5033 |
if (!processing && !conceptItem->isLazyRealizationProcessing() && !conceptItem->isConceptAbsorbed()) { |
| 5034 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 5035 |
if (possibleInstanceItemSet && !possibleInstanceItemSet->isEmpty()) { |
| 5036 |
CConcreteOntology* testingOnto = mOntoAnsweringItem->getTestingOntology(); |
| 5037 |
|
| 5038 |
CConcept* reducedConcept = conceptItem->getCompletelyHandledReducedInstanceTestingConcept(); |
| 5039 |
bool reducedNegation = conceptItem->getCompletelyHandledReducedInstanceTestingConceptNegation(); |
| 5040 |
CBOXLIST<TConceptNegPair>* conceptOfInterestList = testingOnto->getTBox()->getConceptOfInterestList(true); |
| 5041 |
conceptOfInterestList->append(TConceptNegPair(reducedConcept, reducedNegation)); |
| 5042 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 5043 |
conceptItem->setConceptAbsorbed(true); |
| 5044 |
} |
| 5045 |
} |
| 5046 |
|
| 5047 |
|
| 5048 |
if (!processing && !conceptItem->isLazyRealizationProcessing() && conceptItem->isConceptAbsorbed() && !conceptItem->isCandidatePropagated()) { |
| 5049 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 5050 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceCandPropItemSet = conceptItem->getPossibleInstanceCandidatePropagationItemSet(); |
| 5051 |
if (possibleInstanceItemSet && !possibleInstanceItemSet->isEmpty() || possibleInstanceCandPropItemSet && !possibleInstanceCandPropItemSet->isEmpty()) { |
| 5052 |
|
| 5053 |
|
| 5054 |
CConcreteOntology* testingOnto = mOntoAnsweringItem->getTestingOntology(); |
| 5055 |
CBOXHASH<TConceptNegPair, CConceptOfInterestActivationTriggeringData>* activationTriggeringDataHash = testingOnto->getTBox()->getConceptOfInterestActivationTriggerDataHash(false); |
| 5056 |
if (activationTriggeringDataHash) { |
| 5057 |
CConcept* reducedConcept = conceptItem->getCompletelyHandledReducedInstanceTestingConcept(); |
| 5058 |
bool reducedNegation = conceptItem->getCompletelyHandledReducedInstanceTestingConceptNegation(); |
| 5059 |
|
| 5060 |
CConceptOfInterestActivationTriggeringData activationTriggeringData = activationTriggeringDataHash->value(TConceptNegPair(reducedConcept, reducedNegation)); |
| 5061 |
CConcept* candidateConcept = activationTriggeringData.getCandidateConcept(); |
| 5062 |
CConcept* triggeringConcept = activationTriggeringData.getTriggeringConcept(); |
| 5063 |
|
| 5064 |
if (triggeringConcept && !conceptItem->isLazyRealizationInstancesRetrieved()) { |
| 5065 |
|
| 5066 |
bool createOnePassPropagationTest = true; |
| 5067 |
for (CConceptOfInterestActivationLinker* activationLinkerIt = activationTriggeringData.getActivationLinker(); activationLinkerIt; activationLinkerIt = activationLinkerIt->getNext()) { |
| 5068 |
if (!activationLinkerIt->getActivationIndividual()) { |
| 5069 |
createOnePassPropagationTest = false; |
| 5070 |
} |
| 5071 |
} |
| 5072 |
|
| 5073 |
|
| 5074 |
if (createOnePassPropagationTest) { |
| 5075 |
compStep->setAllInstanceComputationRequired(true); |
| 5076 |
if (initializeKnownPossibleInstances(conceptItem, -1, answererContext)) { |
| 5077 |
processing = true; |
| 5078 |
compStep->setComputationProcessQueued(false); |
| 5079 |
instancesProcStepItem->takeNextQueuedConceptItem(); |
| 5080 |
} |
| 5081 |
} |
| 5082 |
} |
| 5083 |
|
| 5084 |
|
| 5085 |
if (!processing && (candidateConcept || triggeringConcept)) { |
| 5086 |
|
| 5087 |
|
| 5088 |
if (createCandidatePropagationInstanceTest(conceptItem, activationTriggeringData, answererContext)) { |
| 5089 |
processing = true; |
| 5090 |
compStep->setComputationProcessProcessing(true); |
| 5091 |
compStep->incCurrentlyRunningComputationCount(); |
| 5092 |
conceptItem->incCandidatePropagationProcessingCount(); |
| 5093 |
} |
| 5094 |
} |
| 5095 |
} |
| 5096 |
|
| 5097 |
|
| 5098 |
QSet<CRealizationIndividualInstanceItemReference>::const_iterator candIt = conceptItem->getPossibleInstanceItemSetCandidatePropagationIterator(); |
| 5099 |
possibleInstanceCandPropItemSet = conceptItem->getPossibleInstanceCandidatePropagationItemSet(); |
| 5100 |
if (possibleInstanceCandPropItemSet && candIt == possibleInstanceCandPropItemSet->constEnd()) { |
| 5101 |
conceptItem->setPossibleInstanceItemSetCandidatePropagationIteratorInitialized(false); |
| 5102 |
conceptItem->setCandidatePropagated(true); |
| 5103 |
instancesProcStepItem->takeNextQueuedConceptItem(); |
| 5104 |
} |
| 5105 |
} |
| 5106 |
} |
| 5107 |
|
| 5108 |
|
| 5109 |
|
| 5110 |
if (!processing && !conceptItem->isLazyRealizationProcessing() && !conceptItem->isCandidatePropagationProcessing()) { |
| 5111 |
|
| 5112 |
|
| 5113 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 5114 |
if (possibleInstanceItemSet && !possibleInstanceItemSet->isEmpty()) { |
| 5115 |
QSet<CRealizationIndividualInstanceItemReference>::iterator it = possibleInstanceItemSet->begin(); |
| 5116 |
CRealizationIndividualInstanceItemReference testingItem(*it); |
| 5117 |
it = possibleInstanceItemSet->erase(it); |
| 5118 |
if (createInvidiualItemInstanceTest(conceptItem, testingItem, answererContext)) { |
| 5119 |
processing = true; |
| 5120 |
compStep->setComputationProcessProcessing(true); |
| 5121 |
compStep->incCurrentlyRunningComputationCount(); |
| 5122 |
} |
| 5123 |
} |
| 5124 |
if (!possibleInstanceItemSet || possibleInstanceItemSet->isEmpty()) { |
| 5125 |
|
| 5126 |
compStep->setComputationProcessQueued(false); |
| 5127 |
instancesProcStepItem->takeNextQueuedConceptItem(); |
| 5128 |
if (compStep->getCurrentlyRunningComputationCount() == 0) { |
| 5129 |
|
| 5130 |
|
| 5131 |
if (mConfExtendedLogging) { |
| 5132 |
cint64 knownInstancesCount = 0; |
| 5133 |
if (conceptItem->getKnownInstanceItems()) { |
| 5134 |
knownInstancesCount = conceptItem->getKnownInstanceItems()->size(); |
| 5135 |
} |
| 5136 |
LOG(INFO, getDomain(), logTr("Determined %2 known instances for complex concept item %1.").arg(conceptItem->getConceptItemId()).arg(knownInstancesCount), this); |
| 5137 |
} |
| 5138 |
|
| 5139 |
|
| 5140 |
conceptItem->setLastRetrievedCertainInstanceItemCount(conceptItem->getKnownInstanceItems()->size()); |
| 5141 |
updateComputedInstancesCount(conceptItem, compStep, answererContext); |
| 5142 |
endMeasuringComplexConceptItemComputationCost(conceptItem); |
| 5143 |
|
| 5144 |
if (conceptItem->isLazyRealizationInstancesRetrieved()) { |
| 5145 |
delete conceptItem->getPossibleInstanceItemSet(); |
| 5146 |
conceptItem->setPossibleInstanceItemSet(nullptr); |
| 5147 |
finishCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 5148 |
} else { |
| 5149 |
compStep->setComputationProcessQueued(false); |
| 5150 |
conceptItem->setQueuedProcessStep(nullptr); |
| 5151 |
} |
| 5152 |
} |
| 5153 |
|
| 5154 |
} |
| 5155 |
} |
| 5156 |
} |
| 5157 |
} |
| 5158 |
|
| 5159 |
|
| 5160 |
return processing; |
| 5161 |
} |
| 5162 |
|
| 5163 |
|
| 5164 |
|
| 5165 |
bool COptimizedComplexExpressionAnsweringHandler::createClassVariableCompositionItemsComputation(COptimizedComplexBuildingClassVariableCompositionsItem* buildingVarItem, bool processing, bool& continueProcessingBuildingVarItem, QList<COptimizedComplexVariableCompositionItem *>* compositionVarItemList, CAnswererContext* answererContext) { |
| 5166 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 5167 |
|
| 5168 |
if (!buildingVarItem->isInitializedBaseConceptVariableItems()) { |
| 5169 |
QSet<CClassVariableExpression*>* remVarExpSet = buildingVarItem->getRemainingVariableExpressionSet(); |
| 5170 |
|
| 5171 |
for (CClassVariableExpression* varExp : *remVarExpSet) { |
| 5172 |
QList<COptimizedComplexConceptItem*> superConItemList = buildingVarItem->getVariableSuperConceptItems(varExp); |
| 5173 |
QList<COptimizedComplexConceptItem*> subConItemList = buildingVarItem->getVariableSubConceptItems(varExp); |
| 5174 |
|
| 5175 |
auto hanlder = [&](COptimizedComplexConceptItem* conItem, bool superClasses) { |
| 5176 |
|
| 5177 |
COptimizedComplexVariableConceptSubSuperItem* varConBaseItem = conItem->getVariableConceptSuperSubClassesItem(superClasses); |
| 5178 |
if (!varConBaseItem) { |
| 5179 |
varConBaseItem = new COptimizedComplexVariableConceptSubSuperItem(conItem, superClasses); |
| 5180 |
conItem->setVariableConceptSuperSubClassesItem(varConBaseItem, superClasses); |
| 5181 |
varConBaseItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 5182 |
varConBaseItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 5183 |
} |
| 5184 |
addUsedVariableCompositionItem(buildingVarItem, varConBaseItem); |
| 5185 |
if (!varConBaseItem->isVariableMappingsInitialized()) { |
| 5186 |
varConBaseItem->setVariableMappingsInitialized(true); |
| 5187 |
|
| 5188 |
COptimizedComplexVariableIndividualMappings* varMapping = new COptimizedComplexVariableIndividualMappingsHash(1); |
| 5189 |
varMapping->setBindingMapping(0, COptimizedComplexVariableIndividualMappings::CLASS_VARIABLE); |
| 5190 |
varConBaseItem->setVariableMapping(varMapping); |
| 5191 |
|
| 5192 |
queueVariableItemComputation(buildingVarItem, varConBaseItem); |
| 5193 |
processing = true; |
| 5194 |
} |
| 5195 |
|
| 5196 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 5197 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 5198 |
varItemIndexMapping.insert(varConBaseItem, itemIndexMapping); |
| 5199 |
itemIndexMapping->insert(0, varExp); |
| 5200 |
|
| 5201 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 5202 |
QStringList debugVariableNameStringList = debugGetItemVariableNames(buildingVarItem, varExp, varConBaseItem); |
| 5203 |
varConBaseItem->debugVariableNameStringList = debugVariableNameStringList; |
| 5204 |
varConBaseItem->debugCreationString = QString("Computation step %1").arg(varConBaseItem->getComputationStepId()) + " with [" + debugVariableNameStringList.join(", ") + "] initialized"; |
| 5205 |
debugCreationStringList += varConBaseItem->debugCreationString; |
| 5206 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 5207 |
#endif |
| 5208 |
|
| 5209 |
QSet<COptimizedComplexVariableCompositionItem*>* varConBaseItemSet = varExpVarComItemHash->value(varExp); |
| 5210 |
if (!varConBaseItemSet) { |
| 5211 |
varConBaseItemSet = new QSet<COptimizedComplexVariableCompositionItem*>(); |
| 5212 |
varExpVarComItemHash->insert(varExp, varConBaseItemSet); |
| 5213 |
} |
| 5214 |
varConBaseItemSet->insert(varConBaseItem); |
| 5215 |
|
| 5216 |
|
| 5217 |
buildingVarItem->setLastHandledVariableExpression(varExp); |
| 5218 |
buildingVarItem->updateLastHandledVariableItemAssociation(varExp, varConBaseItem); |
| 5219 |
}; |
| 5220 |
|
| 5221 |
for (COptimizedComplexConceptItem* conItem : superConItemList) { |
| 5222 |
hanlder(conItem, false); |
| 5223 |
} |
| 5224 |
for (COptimizedComplexConceptItem* conItem : subConItemList) { |
| 5225 |
hanlder(conItem, true); |
| 5226 |
} |
| 5227 |
|
| 5228 |
} |
| 5229 |
|
| 5230 |
|
| 5231 |
buildingVarItem->setInitializedBaseConceptVariableItems(true); |
| 5232 |
} |
| 5233 |
|
| 5234 |
|
| 5235 |
|
| 5236 |
QList<CClassVariableExpression*> remainVarExpList = buildingVarItem->getRemainingVariableExpressionSet()->toList(); |
| 5237 |
|
| 5238 |
while (!processing && !remainVarExpList.isEmpty()) { |
| 5239 |
|
| 5240 |
CClassVariableExpression* varExp = remainVarExpList.takeFirst(); |
| 5241 |
COptimizedComplexVariableCompositionItem* varCompItem = nullptr; |
| 5242 |
// join items |
| 5243 |
QSet<COptimizedComplexVariableCompositionItem*>* joiningVarItemSet = varExpVarComItemHash->value(varExp); |
| 5244 |
if (joiningVarItemSet->size() == 1) { |
| 5245 |
varCompItem = *joiningVarItemSet->constBegin(); |
| 5246 |
} else { |
| 5247 |
bool lastComputation = false; |
| 5248 |
varCompItem = buildJoinedVariableJoiningItems(buildingVarItem, varExp, &processing, lastComputation).first; |
| 5249 |
} |
| 5250 |
|
| 5251 |
cint64 propagatedCount = 0; |
| 5252 |
QSet<QPair<CExpressionVariable*, CExpressionVariable*>> remSubSuperPropSet = buildingVarItem->getVariableRemainingSubSuperPropagationSet(varExp); |
| 5253 |
if (!processing) { |
| 5254 |
|
| 5255 |
for (QPair<CExpressionVariable*, CExpressionVariable* > remSubSuperPropPair : remSubSuperPropSet) { |
| 5256 |
CExpressionVariable* subVar = remSubSuperPropPair.first; |
| 5257 |
CExpressionVariable* superVar = remSubSuperPropPair.second; |
| 5258 |
CExpressionVariable* otherVar = superVar; |
| 5259 |
bool superPropagation = true; |
| 5260 |
if (varExp == superVar) { |
| 5261 |
otherVar = subVar; |
| 5262 |
superPropagation = false; |
| 5263 |
} |
| 5264 |
if (remSubSuperPropSet.size() - propagatedCount == 1 || !buildingVarItem->isRemovingPropagationDisconnecting(varExp, subVar, superVar)) { |
| 5265 |
|
| 5266 |
buildVariableSubSuperPropagationItem(buildingVarItem, varExp, varCompItem, nullptr, (CClassVariableExpression*)otherVar, superPropagation, &processing, answererContext); |
| 5267 |
propagatedCount++; |
| 5268 |
buildingVarItem->removeVariableSubSuperPropagation(subVar, superVar); |
| 5269 |
buildingVarItem->setVariableExpressionUnhandled((CClassVariableExpression*)otherVar); |
| 5270 |
|
| 5271 |
} |
| 5272 |
} |
| 5273 |
|
| 5274 |
if (propagatedCount == remSubSuperPropSet.size()) { |
| 5275 |
buildingVarItem->setVariableExpressionHandled(varExp); |
| 5276 |
buildingVarItem->setLastHandledVariableExpression(varExp); |
| 5277 |
if (!processing) { |
| 5278 |
remainVarExpList = buildingVarItem->getRemainingVariableExpressionSet()->toList(); |
| 5279 |
} |
| 5280 |
} |
| 5281 |
|
| 5282 |
} |
| 5283 |
|
| 5284 |
} |
| 5285 |
|
| 5286 |
|
| 5287 |
return processing; |
| 5288 |
} |
| 5289 |
|
| 5290 |
|
| 5291 |
|
| 5292 |
|
| 5293 |
|
| 5294 |
|
| 5295 |
|
| 5296 |
|
| 5297 |
|
| 5298 |
|
| 5299 |
bool COptimizedComplexExpressionAnsweringHandler::createIndividualMixedVariableCompositionItemsComputation(COptimizedComplexBuildingIndividualMixedVariableCompositionsItem* buildingVarItem, bool processing, bool& continueProcessingBuildingVarItem, QList<COptimizedComplexVariableCompositionItem *>* compositionVarItemList, CAnswererContext* answererContext) { |
| 5300 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 5301 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* indiSubBuildingItem = buildingVarItem->getIndividualVariableSubQueryBuildingItem(); |
| 5302 |
CExpressionVariable* lastIndiVarExp = indiSubBuildingItem->getLastHandledVariableExpression(); |
| 5303 |
|
| 5304 |
if (!buildingVarItem->isInitializedVariableExtensions()) { |
| 5305 |
|
| 5306 |
COptimizedComplexVariableCompositionItem* lastIndiVarCompItem = indiSubBuildingItem->getVariableLastCompositionItem(lastIndiVarExp); |
| 5307 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* lastIndiItemIndexMapping = indiSubBuildingItem->getVariableItemIndexMapping(lastIndiVarExp).value(lastIndiVarCompItem); |
| 5308 |
buildingVarItem->setLastIndividualVariableCompositionItem(lastIndiVarCompItem); |
| 5309 |
buildingVarItem->setLastIndividualVariableCompositionItemIndexMapping(lastIndiItemIndexMapping); |
| 5310 |
QSet<COptimizedComplexVariableCompositionItem*>* compItemSet = new QSet<COptimizedComplexVariableCompositionItem *>(); |
| 5311 |
varExpVarComItemHash->insert(lastIndiVarExp, compItemSet); |
| 5312 |
if (lastIndiVarCompItem) { |
| 5313 |
compItemSet->insert(lastIndiVarCompItem); |
| 5314 |
buildingVarItem->getVariableItemIndexMapping(lastIndiVarExp).insert(lastIndiVarCompItem, lastIndiItemIndexMapping); |
| 5315 |
} |
| 5316 |
|
| 5317 |
QList<COptimizedComplexBuildingClassVariableCompositionsItem*>* subClassItemList = buildingVarItem->getSubQueryClassVariableBuildingItemList(); |
| 5318 |
for (COptimizedComplexBuildingClassVariableCompositionsItem* subClassBuildItem : *subClassItemList) { |
| 5319 |
|
| 5320 |
CExpressionVariable* lastClassVarExp = subClassBuildItem->getLastHandledVariableExpression(); |
| 5321 |
COptimizedComplexVariableCompositionItem* lastClassVarCompItem = subClassBuildItem->getVariableLastCompositionItem(lastClassVarExp); |
| 5322 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* lastIndiItemIndexMapping = subClassBuildItem->getVariableItemIndexMapping(lastClassVarExp).value(lastClassVarCompItem); |
| 5323 |
//QSet<COptimizedComplexVariableCompositionItem*>* compItemSet = new QSet<COptimizedComplexVariableCompositionItem *>(); |
| 5324 |
compItemSet->insert(lastClassVarCompItem); |
| 5325 |
//varExpVarComItemHash->insert(lastIndiVarExp, compItemSet); |
| 5326 |
buildingVarItem->getVariableItemIndexMapping(lastIndiVarExp).insert(lastClassVarCompItem, lastIndiItemIndexMapping); |
| 5327 |
|
| 5328 |
} |
| 5329 |
buildingVarItem->setInitializedVariableExtensions(true); |
| 5330 |
} |
| 5331 |
|
| 5332 |
if (!buildingVarItem->isIndividualVariableTypeExtensionsProcessed()) { |
| 5333 |
|
| 5334 |
COptimizedComplexVariableCompositionItem* lastIndiVarCompItem = buildingVarItem->getLastIndividualVariableCompositionItem(); |
| 5335 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* lastIndiVarCompItemIndexMapping = buildingVarItem->getLastIndividualVariableCompositionItemIndexMapping(); |
| 5336 |
|
| 5337 |
|
| 5338 |
QSet<CIndividualVariableExpression*>* remVarExpSet = buildingVarItem->getRemainingVariableExpressionSet(); |
| 5339 |
|
| 5340 |
|
| 5341 |
for (CIndividualVariableExpression* varExp : *remVarExpSet) { |
| 5342 |
|
| 5343 |
if (!processing) { |
| 5344 |
QSet<QPair<CIndividualVariableExpression*, CClassVariableExpression*>>* mHandledIndividualVariableTypeExtensionVariablePairSet = buildingVarItem->getIndividualVariableTypeExtensionVariableHandledPairSet(); |
| 5345 |
QList<CClassVariableExpression*> typeExtVarList = buildingVarItem->getIndividualVariableTypeExtensionVariables(varExp); |
| 5346 |
for (CClassVariableExpression* typeExtVar : typeExtVarList) { |
| 5347 |
if (!processing) { |
| 5348 |
if (!mHandledIndividualVariableTypeExtensionVariablePairSet->contains(QPair<CIndividualVariableExpression*, CClassVariableExpression*>(varExp, typeExtVar))) { |
| 5349 |
mHandledIndividualVariableTypeExtensionVariablePairSet->insert(QPair<CIndividualVariableExpression*, CClassVariableExpression*>(varExp, typeExtVar)); |
| 5350 |
processing = createIndividualTypeExtension(buildingVarItem, typeExtVar, lastIndiVarCompItemIndexMapping, varExp, lastIndiVarCompItem, processing, lastIndiVarExp, varExpVarComItemHash); |
| 5351 |
} |
| 5352 |
} |
| 5353 |
} |
| 5354 |
} |
| 5355 |
|
| 5356 |
if (!processing) { |
| 5357 |
QSet<QPair<CIndividualVariableExpression*, CPropertyVariableExpression*>>* mHandledIndividualVariablePropertyExtensionVariablePairSet = buildingVarItem->getIndividualVariablePropertyExtensionVariableHandledPairSet(); |
| 5358 |
QList<CPropertyVariableExpression*> propExtVarList = buildingVarItem->getIndividualVariablePropertyExtensionVariables(varExp); |
| 5359 |
for (CPropertyVariableExpression* propExtVar : propExtVarList) { |
| 5360 |
if (!processing) { |
| 5361 |
if (!mHandledIndividualVariablePropertyExtensionVariablePairSet->contains(QPair<CIndividualVariableExpression*, CPropertyVariableExpression*>(varExp, propExtVar))) { |
| 5362 |
mHandledIndividualVariablePropertyExtensionVariablePairSet->insert(QPair<CIndividualVariableExpression*, CPropertyVariableExpression*>(varExp, propExtVar)); |
| 5363 |
processing = createIndividualPropertyExtension(buildingVarItem, propExtVar, lastIndiVarCompItemIndexMapping, varExp, lastIndiVarCompItem, processing, lastIndiVarExp, varExpVarComItemHash); |
| 5364 |
} |
| 5365 |
} |
| 5366 |
} |
| 5367 |
} |
| 5368 |
|
| 5369 |
} |
| 5370 |
|
| 5371 |
if (!processing) { |
| 5372 |
buildingVarItem->setIndividualVariableTypeExtensionsProcessed(true); |
| 5373 |
} |
| 5374 |
} |
| 5375 |
|
| 5376 |
|
| 5377 |
|
| 5378 |
if (!processing && buildingVarItem->isIndividualVariableTypeExtensionsProcessed()) { |
| 5379 |
COptimizedComplexVariableCompositionItem* varCompItem = nullptr; |
| 5380 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(lastIndiVarExp); |
| 5381 |
QSet<COptimizedComplexVariableCompositionItem*>* joiningVarCompItemSet = buildingVarItem->getJoiningVariableCompositionItemSet(); |
| 5382 |
if (joiningVarCompItemSet->size() > 1) { |
| 5383 |
|
| 5384 |
QSet<COptimizedComplexVariableCompositionItem*>* varConBaseItemSet = varExpVarComItemHash->value(lastIndiVarExp); |
| 5385 |
for (QSet<COptimizedComplexVariableCompositionItem*>::iterator it = varConBaseItemSet->begin(); it != varConBaseItemSet->end(); ) { |
| 5386 |
if (!joiningVarCompItemSet->contains(*it)) { |
| 5387 |
varItemIndexMapping.remove(*it); |
| 5388 |
it = varConBaseItemSet->erase(it); |
| 5389 |
} else { |
| 5390 |
++it; |
| 5391 |
} |
| 5392 |
} |
| 5393 |
|
| 5394 |
bool lastComputation = false; |
| 5395 |
varCompItem = buildJoinedVariableJoiningItems(buildingVarItem, lastIndiVarExp, &processing, lastComputation).first; |
| 5396 |
joiningVarCompItemSet->clear(); |
| 5397 |
joiningVarCompItemSet->insert(varCompItem); |
| 5398 |
} |
| 5399 |
} |
| 5400 |
|
| 5401 |
return processing; |
| 5402 |
} |
| 5403 |
|
| 5404 |
|
| 5405 |
|
| 5406 |
|
| 5407 |
|
| 5408 |
|
| 5409 |
|
| 5410 |
bool COptimizedComplexExpressionAnsweringHandler::createIndividualTypeExtension(COptimizedComplexBuildingIndividualMixedVariableCompositionsItem* buildingVarItem, CClassVariableExpression* typeExtVar, COptimizedComplexVariableCompositionItemVariableIndexMapping* lastIndiVarCompItemIndexMapping, CIndividualVariableExpression* varExp, COptimizedComplexVariableCompositionItem* lastIndiVarCompItem, bool processing, CExpressionVariable* lastIndiVarExp, QHash<CExpressionVariable *, QSet<COptimizedComplexVariableCompositionItem *> *>* varExpVarComItemHash) { |
| 5411 |
COptimizedComplexBuildingClassVariableCompositionsItem* classVarCompBuildingItem = buildingVarItem->getExtensionClassVariableSubQueryBuildingItem(typeExtVar); |
| 5412 |
|
| 5413 |
COptimizedComplexVariableCompositionItem* classVarItem = nullptr; |
| 5414 |
CExpressionVariable* lastClassVarExp = nullptr; |
| 5415 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* classItemIndexMapping = nullptr; |
| 5416 |
if (classVarCompBuildingItem) { |
| 5417 |
classVarItem = classVarCompBuildingItem->getVariableLastCompositionItem(typeExtVar); |
| 5418 |
lastClassVarExp = classVarCompBuildingItem->getLastHandledVariableExpression(); |
| 5419 |
classItemIndexMapping = classVarCompBuildingItem->getVariableItemIndexMapping(lastClassVarExp).value(classVarItem); |
| 5420 |
} |
| 5421 |
|
| 5422 |
cint64 indiVarPos = lastIndiVarCompItemIndexMapping->getSearchedVariablePosition(varExp); |
| 5423 |
cint64 classVarPos = 0; |
| 5424 |
cint64 classVarCount = 1; |
| 5425 |
if (classItemIndexMapping) { |
| 5426 |
classVarPos = classItemIndexMapping->getSearchedVariablePosition(typeExtVar); |
| 5427 |
classVarCount = classItemIndexMapping->count(); |
| 5428 |
} |
| 5429 |
|
| 5430 |
cint64 indiVarCount = lastIndiVarCompItemIndexMapping->count(); |
| 5431 |
|
| 5432 |
cint64 newVarCount = indiVarCount + classVarCount; |
| 5433 |
|
| 5434 |
COptimizedComplexVariableIndividualTypeExtensionItem*& varIndiTypeExtItem = lastIndiVarCompItem->getIndividualTypeExtensionItem(indiVarPos, classVarItem, classVarPos); |
| 5435 |
if (!varIndiTypeExtItem) { |
| 5436 |
varIndiTypeExtItem = new COptimizedComplexVariableIndividualTypeExtensionItem(lastIndiVarCompItem, classVarItem, indiVarPos, classVarPos); |
| 5437 |
varIndiTypeExtItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 5438 |
varIndiTypeExtItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 5439 |
} |
| 5440 |
addUsedVariableCompositionItem(buildingVarItem, varIndiTypeExtItem); |
| 5441 |
|
| 5442 |
if (!varIndiTypeExtItem->isVariableMappingsInitialized()) { |
| 5443 |
varIndiTypeExtItem->setVariableMappingsInitialized(true); |
| 5444 |
|
| 5445 |
COptimizedComplexVariableIndividualMappings* varMapping = new COptimizedComplexVariableIndividualMappingsHash(newVarCount); |
| 5446 |
for (cint64 i = 0; i < indiVarCount; ++i) { |
| 5447 |
varMapping->setBindingMapping(i, lastIndiVarCompItem->getVariableMapping()->getBindingMapping(i)); |
| 5448 |
} |
| 5449 |
if (classVarItem) { |
| 5450 |
for (cint64 i = 0; i < classVarCount; ++i) { |
| 5451 |
varMapping->setBindingMapping(i + indiVarCount, classVarItem->getVariableMapping()->getBindingMapping(i)); |
| 5452 |
} |
| 5453 |
} else { |
| 5454 |
varMapping->setBindingMapping(indiVarCount, COptimizedComplexVariableIndividualMappings::CLASS_VARIABLE); |
| 5455 |
} |
| 5456 |
varIndiTypeExtItem->setVariableMapping(varMapping); |
| 5457 |
|
| 5458 |
queueVariableItemComputation(buildingVarItem, varIndiTypeExtItem); |
| 5459 |
processing = true; |
| 5460 |
} |
| 5461 |
|
| 5462 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 5463 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 5464 |
varItemIndexMapping.insert(varIndiTypeExtItem, itemIndexMapping); |
| 5465 |
|
| 5466 |
for (auto it = lastIndiVarCompItemIndexMapping->constBegin(), itEnd = lastIndiVarCompItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 5467 |
itemIndexMapping->insert(it.key(), it.value()); |
| 5468 |
} |
| 5469 |
if (classItemIndexMapping) { |
| 5470 |
for (auto it = classItemIndexMapping->constBegin(), itEnd = classItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 5471 |
itemIndexMapping->insert(it.key() + indiVarCount, it.value()); |
| 5472 |
} |
| 5473 |
} else { |
| 5474 |
itemIndexMapping->insert(indiVarCount, typeExtVar); |
| 5475 |
} |
| 5476 |
|
| 5477 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 5478 |
QStringList debugIndiVariableNameStringList = debugGetItemVariableNames(buildingVarItem, lastIndiVarExp, lastIndiVarCompItem); |
| 5479 |
QStringList debugClassVariableNameStringList; |
| 5480 |
if (classVarItem) { |
| 5481 |
debugClassVariableNameStringList = debugGetItemVariableNames(buildingVarItem, lastIndiVarExp, classVarItem); |
| 5482 |
} else { |
| 5483 |
debugClassVariableNameStringList.append(typeExtVar->getName()); |
| 5484 |
} |
| 5485 |
QStringList debugVariableNameStringList = debugGetItemVariableNames(buildingVarItem, varExp, varIndiTypeExtItem); |
| 5486 |
varIndiTypeExtItem->debugVariableNameStringList = debugVariableNameStringList; |
| 5487 |
varIndiTypeExtItem->debugCreationString = QString("Computation step %1").arg(varIndiTypeExtItem->getComputationStepId()) + " with [" + debugVariableNameStringList.join(", ") + "] obtained by extending [" + debugIndiVariableNameStringList.join(", ") + "] with types of [" + debugClassVariableNameStringList.join(", ") + "]"; |
| 5488 |
debugCreationStringList += varIndiTypeExtItem->debugCreationString; |
| 5489 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 5490 |
#endif |
| 5491 |
|
| 5492 |
QSet<COptimizedComplexVariableCompositionItem*>* varConBaseItemSet = varExpVarComItemHash->value(lastIndiVarExp); |
| 5493 |
if (!varConBaseItemSet) { |
| 5494 |
varConBaseItemSet = new QSet<COptimizedComplexVariableCompositionItem*>(); |
| 5495 |
varExpVarComItemHash->insert(lastIndiVarExp, varConBaseItemSet); |
| 5496 |
} |
| 5497 |
varConBaseItemSet->insert(varIndiTypeExtItem); |
| 5498 |
|
| 5499 |
|
| 5500 |
buildingVarItem->setLastHandledVariableExpression(lastIndiVarExp); |
| 5501 |
buildingVarItem->updateLastHandledVariableItemAssociation(lastIndiVarExp, varIndiTypeExtItem); |
| 5502 |
|
| 5503 |
buildingVarItem->getJoiningVariableCompositionItemSet()->insert(varIndiTypeExtItem); |
| 5504 |
return processing; |
| 5505 |
} |
| 5506 |
|
| 5507 |
|
| 5508 |
|
| 5509 |
|
| 5510 |
|
| 5511 |
|
| 5512 |
|
| 5513 |
|
| 5514 |
|
| 5515 |
bool COptimizedComplexExpressionAnsweringHandler::createIndividualPropertyExtension(COptimizedComplexBuildingIndividualMixedVariableCompositionsItem* buildingVarItem, CPropertyVariableExpression* typeExtVar, COptimizedComplexVariableCompositionItemVariableIndexMapping* lastIndiVarCompItemIndexMapping, CIndividualVariableExpression* varExp, COptimizedComplexVariableCompositionItem* lastIndiVarCompItem, bool processing, CExpressionVariable* lastIndiVarExp, QHash<CExpressionVariable *, QSet<COptimizedComplexVariableCompositionItem *> *>* varExpVarComItemHash) { |
| 5516 |
COptimizedComplexBuildingPropertyVariableCompositionsItem* propertyVarCompBuildingItem = buildingVarItem->getExtensionPropertyVariableSubQueryBuildingItem(typeExtVar); |
| 5517 |
|
| 5518 |
COptimizedComplexVariableCompositionItem* propVarItem = nullptr; |
| 5519 |
CExpressionVariable* lastClassVarExp = nullptr; |
| 5520 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* propItemIndexMapping = nullptr; |
| 5521 |
if (propertyVarCompBuildingItem) { |
| 5522 |
propVarItem = propertyVarCompBuildingItem->getVariableLastCompositionItem(typeExtVar); |
| 5523 |
lastClassVarExp = propertyVarCompBuildingItem->getLastHandledVariableExpression(); |
| 5524 |
propItemIndexMapping = propertyVarCompBuildingItem->getVariableItemIndexMapping(lastClassVarExp).value(propVarItem); |
| 5525 |
} |
| 5526 |
|
| 5527 |
cint64 indiVarPos = lastIndiVarCompItemIndexMapping->getSearchedVariablePosition(varExp); |
| 5528 |
cint64 propVarPos = 0; |
| 5529 |
cint64 propVarCount = 1; |
| 5530 |
if (propItemIndexMapping) { |
| 5531 |
propVarPos = propItemIndexMapping->getSearchedVariablePosition(typeExtVar); |
| 5532 |
propVarCount = propItemIndexMapping->count(); |
| 5533 |
} |
| 5534 |
|
| 5535 |
cint64 indiVarCount = lastIndiVarCompItemIndexMapping->count(); |
| 5536 |
|
| 5537 |
cint64 newVarCount = indiVarCount + propVarCount; |
| 5538 |
|
| 5539 |
COptimizedComplexVariableIndividualNeighboringPropertyExtensionItem*& varIndiPropExtItem = lastIndiVarCompItem->getIndividualNeighboringPropertyExtensionItem(indiVarPos, propVarItem, propVarPos); |
| 5540 |
if (!varIndiPropExtItem) { |
| 5541 |
varIndiPropExtItem = new COptimizedComplexVariableIndividualNeighboringPropertyExtensionItem(lastIndiVarCompItem, propVarItem, indiVarPos, propVarPos); |
| 5542 |
varIndiPropExtItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 5543 |
varIndiPropExtItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 5544 |
} |
| 5545 |
addUsedVariableCompositionItem(buildingVarItem, varIndiPropExtItem); |
| 5546 |
|
| 5547 |
if (!varIndiPropExtItem->isVariableMappingsInitialized()) { |
| 5548 |
varIndiPropExtItem->setVariableMappingsInitialized(true); |
| 5549 |
|
| 5550 |
COptimizedComplexVariableIndividualMappings* varMapping = new COptimizedComplexVariableIndividualMappingsHash(newVarCount); |
| 5551 |
for (cint64 i = 0; i < indiVarCount; ++i) { |
| 5552 |
varMapping->setBindingMapping(i, lastIndiVarCompItem->getVariableMapping()->getBindingMapping(i)); |
| 5553 |
} |
| 5554 |
if (propVarItem) { |
| 5555 |
for (cint64 i = 0; i < propVarCount; ++i) { |
| 5556 |
varMapping->setBindingMapping(i + indiVarCount, propVarItem->getVariableMapping()->getBindingMapping(i)); |
| 5557 |
} |
| 5558 |
} else { |
| 5559 |
varMapping->setBindingMapping(indiVarCount, COptimizedComplexVariableIndividualMappings::PROPERTY_VARIABLE); |
| 5560 |
} |
| 5561 |
varIndiPropExtItem->setVariableMapping(varMapping); |
| 5562 |
|
| 5563 |
queueVariableItemComputation(buildingVarItem, varIndiPropExtItem); |
| 5564 |
processing = true; |
| 5565 |
} |
| 5566 |
|
| 5567 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 5568 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 5569 |
varItemIndexMapping.insert(varIndiPropExtItem, itemIndexMapping); |
| 5570 |
|
| 5571 |
for (auto it = lastIndiVarCompItemIndexMapping->constBegin(), itEnd = lastIndiVarCompItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 5572 |
itemIndexMapping->insert(it.key(), it.value()); |
| 5573 |
} |
| 5574 |
if (propItemIndexMapping) { |
| 5575 |
for (auto it = propItemIndexMapping->constBegin(), itEnd = propItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 5576 |
itemIndexMapping->insert(it.key() + indiVarCount, it.value()); |
| 5577 |
} |
| 5578 |
} else { |
| 5579 |
itemIndexMapping->insert(indiVarCount, typeExtVar); |
| 5580 |
} |
| 5581 |
|
| 5582 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 5583 |
QStringList debugIndiVariableNameStringList = debugGetItemVariableNames(buildingVarItem, lastIndiVarExp, lastIndiVarCompItem); |
| 5584 |
QStringList debugPropVariableNameStringList; |
| 5585 |
if (propVarItem) { |
| 5586 |
debugPropVariableNameStringList = debugGetItemVariableNames(buildingVarItem, lastIndiVarExp, propVarItem); |
| 5587 |
} else { |
| 5588 |
debugPropVariableNameStringList.append(typeExtVar->getName()); |
| 5589 |
} |
| 5590 |
QStringList debugVariableNameStringList = debugGetItemVariableNames(buildingVarItem, varExp, varIndiPropExtItem); |
| 5591 |
varIndiPropExtItem->debugVariableNameStringList = debugVariableNameStringList; |
| 5592 |
varIndiPropExtItem->debugCreationString = QString("Computation step %1").arg(varIndiPropExtItem->getComputationStepId()) + " with [" + debugVariableNameStringList.join(", ") + "] obtained by extending [" + debugIndiVariableNameStringList.join(", ") + "] with neighboring properties of [" + debugPropVariableNameStringList.join(", ") + "]"; |
| 5593 |
debugCreationStringList += varIndiPropExtItem->debugCreationString; |
| 5594 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 5595 |
#endif |
| 5596 |
|
| 5597 |
QSet<COptimizedComplexVariableCompositionItem*>* varConBaseItemSet = varExpVarComItemHash->value(lastIndiVarExp); |
| 5598 |
if (!varConBaseItemSet) { |
| 5599 |
varConBaseItemSet = new QSet<COptimizedComplexVariableCompositionItem*>(); |
| 5600 |
varExpVarComItemHash->insert(lastIndiVarExp, varConBaseItemSet); |
| 5601 |
} |
| 5602 |
varConBaseItemSet->insert(varIndiPropExtItem); |
| 5603 |
|
| 5604 |
|
| 5605 |
buildingVarItem->setLastHandledVariableExpression(lastIndiVarExp); |
| 5606 |
buildingVarItem->updateLastHandledVariableItemAssociation(lastIndiVarExp, varIndiPropExtItem); |
| 5607 |
|
| 5608 |
buildingVarItem->getJoiningVariableCompositionItemSet()->insert(varIndiPropExtItem); |
| 5609 |
return processing; |
| 5610 |
} |
| 5611 |
|
| 5612 |
|
| 5613 |
|
| 5614 |
|
| 5615 |
|
| 5616 |
|
| 5617 |
|
| 5618 |
|
| 5619 |
|
| 5620 |
|
| 5621 |
bool COptimizedComplexExpressionAnsweringHandler::createPropertyVariableCompositionItemsComputation(COptimizedComplexBuildingPropertyVariableCompositionsItem* buildingVarItem, bool processing, bool& continueProcessingBuildingVarItem, QList<COptimizedComplexVariableCompositionItem *>* compositionVarItemList, CAnswererContext* answererContext) { |
| 5622 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 5623 |
|
| 5624 |
if (!buildingVarItem->isInitializedBaseRoleVariableItems()) { |
| 5625 |
QSet<CPropertyVariableExpression*>* remVarExpSet = buildingVarItem->getRemainingVariableExpressionSet(); |
| 5626 |
|
| 5627 |
for (CPropertyVariableExpression* varExp : *remVarExpSet) { |
| 5628 |
QList<CRole*> superRoleList = buildingVarItem->getVariableSuperRoles(varExp); |
| 5629 |
QList<CRole*> subRoleList = buildingVarItem->getVariableSubRoles(varExp); |
| 5630 |
|
| 5631 |
auto hanlder = [&](CRole* role, bool superProperties) { |
| 5632 |
|
| 5633 |
COptimizedComplexVariableRoleSubSuperItem* varPropBaseItem = mOntoAnsweringItem->getRoleSubSuperItem(role, superProperties); |
| 5634 |
if (!varPropBaseItem) { |
| 5635 |
varPropBaseItem = new COptimizedComplexVariableRoleSubSuperItem(role, superProperties); |
| 5636 |
mOntoAnsweringItem->setRoleSubSuperItem(role, superProperties, varPropBaseItem); |
| 5637 |
varPropBaseItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 5638 |
varPropBaseItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 5639 |
} |
| 5640 |
addUsedVariableCompositionItem(buildingVarItem, varPropBaseItem); |
| 5641 |
if (!varPropBaseItem->isVariableMappingsInitialized()) { |
| 5642 |
varPropBaseItem->setVariableMappingsInitialized(true); |
| 5643 |
|
| 5644 |
COptimizedComplexVariableIndividualMappings* varMapping = new COptimizedComplexVariableIndividualMappingsHash(1); |
| 5645 |
varMapping->setBindingMapping(0, COptimizedComplexVariableIndividualMappings::PROPERTY_VARIABLE); |
| 5646 |
varPropBaseItem->setVariableMapping(varMapping); |
| 5647 |
|
| 5648 |
queueVariableItemComputation(buildingVarItem, varPropBaseItem); |
| 5649 |
processing = true; |
| 5650 |
} |
| 5651 |
|
| 5652 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 5653 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 5654 |
varItemIndexMapping.insert(varPropBaseItem, itemIndexMapping); |
| 5655 |
itemIndexMapping->insert(0, varExp); |
| 5656 |
|
| 5657 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 5658 |
QStringList debugVariableNameStringList = debugGetItemVariableNames(buildingVarItem, varExp, varPropBaseItem); |
| 5659 |
varPropBaseItem->debugVariableNameStringList = debugVariableNameStringList; |
| 5660 |
varPropBaseItem->debugCreationString = QString("Computation step %1").arg(varPropBaseItem->getComputationStepId()) + " with [" + debugVariableNameStringList.join(", ") + "] initialized"; |
| 5661 |
debugCreationStringList += varPropBaseItem->debugCreationString; |
| 5662 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 5663 |
#endif |
| 5664 |
|
| 5665 |
QSet<COptimizedComplexVariableCompositionItem*>* varConBaseItemSet = varExpVarComItemHash->value(varExp); |
| 5666 |
if (!varConBaseItemSet) { |
| 5667 |
varConBaseItemSet = new QSet<COptimizedComplexVariableCompositionItem*>(); |
| 5668 |
varExpVarComItemHash->insert(varExp, varConBaseItemSet); |
| 5669 |
} |
| 5670 |
varConBaseItemSet->insert(varPropBaseItem); |
| 5671 |
|
| 5672 |
|
| 5673 |
buildingVarItem->setLastHandledVariableExpression(varExp); |
| 5674 |
buildingVarItem->updateLastHandledVariableItemAssociation(varExp, varPropBaseItem); |
| 5675 |
}; |
| 5676 |
|
| 5677 |
for (CRole* conItem : superRoleList) { |
| 5678 |
hanlder(conItem, false); |
| 5679 |
} |
| 5680 |
for (CRole* conItem : subRoleList) { |
| 5681 |
hanlder(conItem, true); |
| 5682 |
} |
| 5683 |
|
| 5684 |
} |
| 5685 |
|
| 5686 |
|
| 5687 |
buildingVarItem->setInitializedBaseRoleVariableItems(true); |
| 5688 |
} |
| 5689 |
|
| 5690 |
|
| 5691 |
|
| 5692 |
QList<CPropertyVariableExpression*> remainVarExpList = buildingVarItem->getRemainingVariableExpressionSet()->toList(); |
| 5693 |
|
| 5694 |
while (!processing && !remainVarExpList.isEmpty()) { |
| 5695 |
|
| 5696 |
CPropertyVariableExpression* varExp = remainVarExpList.takeFirst(); |
| 5697 |
COptimizedComplexVariableCompositionItem* varCompItem = nullptr; |
| 5698 |
// join items |
| 5699 |
QSet<COptimizedComplexVariableCompositionItem*>* joiningVarItemSet = varExpVarComItemHash->value(varExp); |
| 5700 |
if (joiningVarItemSet->size() == 1) { |
| 5701 |
varCompItem = *joiningVarItemSet->constBegin(); |
| 5702 |
} else { |
| 5703 |
bool lastComputation = false; |
| 5704 |
varCompItem = buildJoinedVariableJoiningItems(buildingVarItem, varExp, &processing, lastComputation).first; |
| 5705 |
} |
| 5706 |
|
| 5707 |
cint64 propagatedCount = 0; |
| 5708 |
QSet<QPair<CExpressionVariable*, CExpressionVariable*>> remSubSuperPropSet = buildingVarItem->getVariableRemainingSubSuperPropagationSet(varExp); |
| 5709 |
if (!processing) { |
| 5710 |
|
| 5711 |
for (QPair<CExpressionVariable*, CExpressionVariable* > remSubSuperPropPair : remSubSuperPropSet) { |
| 5712 |
CExpressionVariable* subVar = remSubSuperPropPair.first; |
| 5713 |
CExpressionVariable* superVar = remSubSuperPropPair.second; |
| 5714 |
CExpressionVariable* otherVar = superVar; |
| 5715 |
bool superPropagation = true; |
| 5716 |
if (varExp == superVar) { |
| 5717 |
otherVar = subVar; |
| 5718 |
superPropagation = false; |
| 5719 |
} |
| 5720 |
if (remSubSuperPropSet.size() - propagatedCount == 1 || !buildingVarItem->isRemovingPropagationDisconnecting(varExp, subVar, superVar)) { |
| 5721 |
|
| 5722 |
buildVariableSubSuperPropagationItem(buildingVarItem, varExp, varCompItem, nullptr, (CPropertyVariableExpression*)otherVar, superPropagation, &processing, answererContext); |
| 5723 |
propagatedCount++; |
| 5724 |
buildingVarItem->removeVariableSubSuperPropagation(subVar, superVar); |
| 5725 |
buildingVarItem->setVariableExpressionUnhandled((CPropertyVariableExpression*)otherVar); |
| 5726 |
|
| 5727 |
} |
| 5728 |
} |
| 5729 |
|
| 5730 |
if (propagatedCount == remSubSuperPropSet.size()) { |
| 5731 |
buildingVarItem->setVariableExpressionHandled(varExp); |
| 5732 |
buildingVarItem->setLastHandledVariableExpression(varExp); |
| 5733 |
if (!processing) { |
| 5734 |
remainVarExpList = buildingVarItem->getRemainingVariableExpressionSet()->toList(); |
| 5735 |
} |
| 5736 |
} |
| 5737 |
|
| 5738 |
} |
| 5739 |
|
| 5740 |
} |
| 5741 |
|
| 5742 |
|
| 5743 |
return processing; |
| 5744 |
} |
| 5745 |
|
| 5746 |
|
| 5747 |
|
| 5748 |
|
| 5749 |
|
| 5750 |
|
| 5751 |
|
| 5752 |
|
| 5753 |
|
| 5754 |
|
| 5755 |
|
| 5756 |
bool COptimizedComplexExpressionAnsweringHandler::createIndividualVariableCompositionItemsComputation(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, bool processing, bool& continueProcessingBuildingVarItem, QList<COptimizedComplexVariableCompositionItem *>* compositionVarItemList, CAnswererContext* answererContext) { |
| 5757 |
QHash<CExpressionVariable*, COptimizedComplexConceptItem*>* varConItemHash = buildingVarItem->getVariableConceptItemHash(); |
| 5758 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 5759 |
QSet<CIndividualVariableExpression*>* reuseVarExpComputationsCheckSet = buildingVarItem->getReuseVariableExpressionComputationsCheckSet(); |
| 5760 |
|
| 5761 |
if (!buildingVarItem->isInitializedBaseConceptVariableItems()) { |
| 5762 |
|
| 5763 |
for (QHash<CExpressionVariable*, COptimizedComplexConceptItem*>::const_iterator it = varConItemHash->constBegin(), itEnd = varConItemHash->constEnd(); it != itEnd && buildingVarItem->isSatisfiable(); ++it) { |
| 5764 |
CIndividualVariableExpression* varExp = (CIndividualVariableExpression*)it.key(); |
| 5765 |
COptimizedComplexConceptItem* conItem = it.value(); |
| 5766 |
if (!conItem->getKnownInstanceItems() || conItem->getKnownInstanceItems()->isEmpty()) { |
| 5767 |
buildingVarItem->setSatisfiability(false); |
| 5768 |
break; |
| 5769 |
} |
| 5770 |
} |
| 5771 |
|
| 5772 |
if (buildingVarItem->isSatisfiable()) { |
| 5773 |
|
| 5774 |
QSet<CIndividualVariableExpression*> propagatableOverVarSet; |
| 5775 |
bool allPropagatableOverVar = true; |
| 5776 |
for (QHash<CExpressionVariable*, COptimizedComplexConceptItem*>::const_iterator it = varConItemHash->constBegin(), itEnd = varConItemHash->constEnd(); it != itEnd && mConfSkipConceptItemsIntegrationForPropagationOverVariables; ++it) { |
| 5777 |
CIndividualVariableExpression* varExp = (CIndividualVariableExpression*)it.key(); |
| 5778 |
COptimizedComplexConceptItem* conItem = it.value(); |
| 5779 |
|
| 5780 |
QList<CObjectPropertyAssertionExpression*> propAssList = buildingVarItem->getUnhanledPropertyAssertionsExpressions(varExp); |
| 5781 |
QList<CDataPropertyAssertionExpression*> dataPropAssList = buildingVarItem->getUnhanledDataPropertyAssertionsExpressions(varExp); |
| 5782 |
|
| 5783 |
if (dataPropAssList.isEmpty() && propAssList.size() == 2) { |
| 5784 |
|
| 5785 |
bool selfRestriction = false; |
| 5786 |
for (CObjectPropertyAssertionExpression* propAss : propAssList) { |
| 5787 |
if (buildingVarItem->getOtherVariableExpression(varExp, propAss) == varExp) { |
| 5788 |
selfRestriction = true; |
| 5789 |
break; |
| 5790 |
} |
| 5791 |
} |
| 5792 |
|
| 5793 |
if (!selfRestriction) { |
| 5794 |
if (areConceptItemConceptsImpliedByPropertyDomains(varExp, conItem, propAssList, buildingVarItem, answererContext)) { |
| 5795 |
propagatableOverVarSet.insert(varExp); |
| 5796 |
} else { |
| 5797 |
allPropagatableOverVar = false; |
| 5798 |
} |
| 5799 |
} else { |
| 5800 |
allPropagatableOverVar = false; |
| 5801 |
} |
| 5802 |
|
| 5803 |
} else { |
| 5804 |
allPropagatableOverVar = false; |
| 5805 |
} |
| 5806 |
} |
| 5807 |
|
| 5808 |
|
| 5809 |
if (allPropagatableOverVar) { |
| 5810 |
QList<CIndividualVariableExpression*> remainVarExpList = getSortedRemainingVariableExpressionList(buildingVarItem, &propagatableOverVarSet); |
| 5811 |
if (!remainVarExpList.isEmpty()) { |
| 5812 |
propagatableOverVarSet.remove(remainVarExpList.first()); |
| 5813 |
} |
| 5814 |
|
| 5815 |
if (propagatableOverVarSet.size() == varConItemHash->size()) { |
| 5816 |
propagatableOverVarSet.clear(); |
| 5817 |
} |
| 5818 |
} |
| 5819 |
|
| 5820 |
|
| 5821 |
|
| 5822 |
for (QHash<CExpressionVariable*, COptimizedComplexConceptItem*>::const_iterator it = varConItemHash->constBegin(), itEnd = varConItemHash->constEnd(); it != itEnd; ++it) { |
| 5823 |
CIndividualVariableExpression* varExp = (CIndividualVariableExpression*)it.key(); |
| 5824 |
COptimizedComplexConceptItem* conItem = it.value(); |
| 5825 |
|
| 5826 |
|
| 5827 |
//if (!conItem->isLazyRealizationInstancesRetrieved() && mConfMinimalMappingsComputationSize < 0) { |
| 5828 |
// CComplexConceptStepInstanceComputationProcess* instComStep = conItem->getComputationProcess()->getInstancesComputationProcess(true); |
| 5829 |
// instComStep->setAllInstanceComputationRequired(true); |
| 5830 |
// processing |= initializeQueryProcessingStep(instComStep, conItem, nullptr, buildingVarItem); |
| 5831 |
//} |
| 5832 |
if (!propagatableOverVarSet.contains(varExp)) { |
| 5833 |
|
| 5834 |
COptimizedComplexVariableConceptBaseItem* varConBaseItem = conItem->getVariableConceptBaseItem(); |
| 5835 |
if (!varConBaseItem) { |
| 5836 |
varConBaseItem = new COptimizedComplexVariableConceptBaseItem(conItem); |
| 5837 |
conItem->setVariableConceptBaseItem(varConBaseItem); |
| 5838 |
reuseVarExpComputationsCheckSet->remove(varExp); |
| 5839 |
varConBaseItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 5840 |
varConBaseItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 5841 |
} |
| 5842 |
addUsedVariableCompositionItem(buildingVarItem, varConBaseItem); |
| 5843 |
if (!varConBaseItem->isVariableMappingsInitialized()) { |
| 5844 |
varConBaseItem->setVariableMappingsInitialized(true); |
| 5845 |
|
| 5846 |
COptimizedComplexVariableIndividualMappings* varMapping = new COptimizedComplexVariableIndividualMappingsHash(1); |
| 5847 |
varMapping->setBindingMapping(0, COptimizedComplexVariableIndividualMappings::INDIVIDUAL_VARIABLE); |
| 5848 |
varConBaseItem->setVariableMapping(varMapping); |
| 5849 |
|
| 5850 |
queueVariableItemComputation(buildingVarItem, varConBaseItem); |
| 5851 |
processing = true; |
| 5852 |
} |
| 5853 |
|
| 5854 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 5855 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 5856 |
varItemIndexMapping.insert(varConBaseItem, itemIndexMapping); |
| 5857 |
itemIndexMapping->insert(0, varExp); |
| 5858 |
|
| 5859 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 5860 |
QStringList debugVariableNameStringList = debugGetItemVariableNames(buildingVarItem, varExp, varConBaseItem); |
| 5861 |
varConBaseItem->debugVariableNameStringList = debugVariableNameStringList; |
| 5862 |
varConBaseItem->debugCreationString = QString("Computation step %1").arg(varConBaseItem->getComputationStepId()) + " with [" + debugVariableNameStringList.join(", ") + "] initialized"; |
| 5863 |
debugCreationStringList += varConBaseItem->debugCreationString; |
| 5864 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 5865 |
#endif |
| 5866 |
|
| 5867 |
QSet<COptimizedComplexVariableCompositionItem*>* varConBaseItemSet = new QSet<COptimizedComplexVariableCompositionItem*>(); |
| 5868 |
varConBaseItemSet->insert(varConBaseItem); |
| 5869 |
varExpVarComItemHash->insert(varExp, varConBaseItemSet); |
| 5870 |
|
| 5871 |
|
| 5872 |
buildingVarItem->setLastHandledVariableExpression(varExp); |
| 5873 |
buildingVarItem->updateLastHandledVariableItemAssociation(varExp, varConBaseItem); |
| 5874 |
} |
| 5875 |
} |
| 5876 |
|
| 5877 |
|
| 5878 |
|
| 5879 |
|
| 5880 |
|
| 5881 |
|
| 5882 |
|
| 5883 |
|
| 5884 |
|
| 5885 |
|
| 5886 |
while (!reuseVarExpComputationsCheckSet->isEmpty()) { |
| 5887 |
|
| 5888 |
QSet<CIndividualVariableExpression*>::iterator it = reuseVarExpComputationsCheckSet->begin(); |
| 5889 |
CIndividualVariableExpression* varExp = *it; |
| 5890 |
reuseVarExpComputationsCheckSet->erase(it); |
| 5891 |
|
| 5892 |
COptimizedComplexVariableCompositionItem* varCompItem = nullptr; |
| 5893 |
|
| 5894 |
// join items |
| 5895 |
QSet<COptimizedComplexVariableCompositionItem*>* joiningVarItemSet = varExpVarComItemHash->value(varExp); |
| 5896 |
if (joiningVarItemSet) { |
| 5897 |
if (joiningVarItemSet->size() == 1) { |
| 5898 |
varCompItem = *joiningVarItemSet->constBegin(); |
| 5899 |
} else { |
| 5900 |
QList<QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>> joinedVarCompItems = reuseJoinedVariableCompositionItems(buildingVarItem, varExp); |
| 5901 |
if (joinedVarCompItems.size() == 1) { |
| 5902 |
varCompItem = joinedVarCompItems.first().first; |
| 5903 |
} |
| 5904 |
} |
| 5905 |
|
| 5906 |
if (varCompItem) { |
| 5907 |
QList<CObjectPropertyAssertionExpression*> propAssList = buildingVarItem->getUnhanledPropertyAssertionsExpressions(varExp); |
| 5908 |
cint64 reusedCount = 0; |
| 5909 |
for (CObjectPropertyAssertionExpression* propAss : propAssList) { |
| 5910 |
|
| 5911 |
if (tryReuseVariableRolePropagationItem(buildingVarItem, varExp, varCompItem, nullptr, propAss)) { |
| 5912 |
if (propAssList.size() - reusedCount == 1 || !buildingVarItem->isRemovingPropertyAssertionDisconnecting(varExp, propAss)) { |
| 5913 |
reusedCount++; |
| 5914 |
buildingVarItem->setPropertyAssertionHandled(propAss); |
| 5915 |
reuseVarExpComputationsCheckSet->insert(buildingVarItem->getOtherVariableExpression(varExp, propAss)); |
| 5916 |
buildingVarItem->setVariableExpressionUnhandled(buildingVarItem->getOtherVariableExpression(varExp, propAss)); |
| 5917 |
} |
| 5918 |
} |
| 5919 |
} |
| 5920 |
if (reusedCount == propAssList.size()) { |
| 5921 |
buildingVarItem->setVariableExpressionHandled(varExp); |
| 5922 |
buildingVarItem->setLastHandledVariableExpression(varExp); |
| 5923 |
} |
| 5924 |
} |
| 5925 |
} |
| 5926 |
|
| 5927 |
} |
| 5928 |
|
| 5929 |
|
| 5930 |
buildingVarItem->setInitializedBaseConceptVariableItems(true); |
| 5931 |
} |
| 5932 |
} |
| 5933 |
|
| 5934 |
|
| 5935 |
|
| 5936 |
|
| 5937 |
|
| 5938 |
|
| 5939 |
// initialize items extracted from extendible query |
| 5940 |
if (!processing && compositionVarItemList->isEmpty()) { |
| 5941 |
QHash<cint64, CComplexQueryExpressionProcessingData*>* queryExtensionProcessingDataHash = mOntoAnsweringItem->getQueryExtensionProcessingDataHash(); |
| 5942 |
QList<CExpressionVariable*>* extendibleQueryTransferringExtractionVariableList = buildingVarItem->getExtendibleQueryTransferringExtractionVariableList(); |
| 5943 |
while (!extendibleQueryTransferringExtractionVariableList->isEmpty()) { |
| 5944 |
CExpressionVariable* expVar = extendibleQueryTransferringExtractionVariableList->takeFirst(); |
| 5945 |
CComplexQueryExpressionProcessingData* queryProcessingData = buildingVarItem->getQueryProcessingData(); |
| 5946 |
CComplexQueryExtendibleData* queryExtendibleData = queryProcessingData->getQueryExtendibleData(); |
| 5947 |
QList<CQuery*>* dependingQueries = queryExtendibleData->getExtendingQueryList(); |
| 5948 |
for (CQuery* dependingQuery : *dependingQueries) { |
| 5949 |
CComplexAssertionsIndividualVariablesAnsweringExtendibleQuery* depExtCompAssIndVarQuery = dynamic_cast<CComplexAssertionsIndividualVariablesAnsweringExtendibleQuery*>(dependingQuery); |
| 5950 |
if (depExtCompAssIndVarQuery) { |
| 5951 |
CComplexQueryExtendibleData* depQueryExtendibleData = depExtCompAssIndVarQuery->getExtendibleData(); |
| 5952 |
cint64 depExtId = depQueryExtendibleData->getExtendibleId(); |
| 5953 |
CComplexQueryExpressionProcessingData* depQueryProcessingData = queryExtensionProcessingDataHash->value(depExtId); |
| 5954 |
if (depExtId > 0 && depQueryProcessingData) { |
| 5955 |
QList<CExpressionVariable*>* depQueryVarList = depExtCompAssIndVarQuery->getDistinguishedVariableExpressions(); |
| 5956 |
cint64 varInd = 0; |
| 5957 |
CExpressionVariable* depFoundVariable = nullptr; |
| 5958 |
for (CExpressionVariable* depQueryVar : *depQueryVarList) { |
| 5959 |
if (depQueryVar->getName() == expVar->getName() || depQueryVar == expVar) { |
| 5960 |
depFoundVariable = depQueryVar; |
| 5961 |
break; |
| 5962 |
} |
| 5963 |
} |
| 5964 |
if (depFoundVariable) { |
| 5965 |
COptimizedComplexBuildingVariableCompositionsItem* depVarBuildItem = depQueryProcessingData->getVariableBuildingItem(); |
| 5966 |
|
| 5967 |
|
| 5968 |
CExpressionVariable* depLastVarExp = depVarBuildItem->getLastHandledVariableExpression(); |
| 5969 |
if (depLastVarExp) { |
| 5970 |
COptimizedComplexVariableCompositionItem* depLastVarItem = depVarBuildItem->getVariableLastCompositionItem(depLastVarExp); |
| 5971 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* depItemIndexMapping = depVarBuildItem->getVariableItemIndexMapping(depLastVarExp).value(depLastVarItem); |
| 5972 |
|
| 5973 |
|
| 5974 |
//COptimizedComplexVariableCompositionItem* depLastVarItem = depVarBuildItem->getVariableLastCompositionItem(depFoundVariable); |
| 5975 |
//COptimizedComplexVariableCompositionItemVariableIndexMapping* depItemIndexMapping = depVarBuildItem->getVariableItemIndexMapping(depFoundVariable).value(depLastVarItem); |
| 5976 |
|
| 5977 |
//cint64 depVarIdx = -1; |
| 5978 |
//for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = depItemIndexMapping->constBegin(), itEnd = depItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 5979 |
// cint64 varIdx = it.key(); |
| 5980 |
// CExpressionVariable* varExp = it.value(); |
| 5981 |
// if (depFoundVariable == varExp) { |
| 5982 |
// depVarIdx = varIdx; |
| 5983 |
// break; |
| 5984 |
// } |
| 5985 |
//} |
| 5986 |
|
| 5987 |
buildQueryTransferringVariableExtractionItem(depVarBuildItem, depFoundVariable, depLastVarItem, depItemIndexMapping, buildingVarItem, expVar, &processing); |
| 5988 |
break; |
| 5989 |
|
| 5990 |
} |
| 5991 |
} |
| 5992 |
} |
| 5993 |
} |
| 5994 |
} |
| 5995 |
} |
| 5996 |
} |
| 5997 |
|
| 5998 |
|
| 5999 |
|
| 6000 |
|
| 6001 |
// initialize basic data literals items |
| 6002 |
if (!processing && compositionVarItemList->isEmpty()) { |
| 6003 |
|
| 6004 |
|
| 6005 |
QList<CDataPropertyAssertionExpression*>* basicDataPropAssList = buildingVarItem->getBasicDataPropertyAssertionList(); |
| 6006 |
|
| 6007 |
QHash<CDataLiteralVariableExpression*, CIndividualVariableExpression*>* dataVarIndiVarHash = buildingVarItem->getDataLiteralVariableIndidualVariableMappingHash(); |
| 6008 |
QSet<CIndividualVariableExpression*>* remainingDataVarExpSet = buildingVarItem->getRemainingExtendingDataVariableSet(); |
| 6009 |
|
| 6010 |
if (!buildingVarItem->isInitializedBasicDataVariableItems() && buildingVarItem->isSatisfiable()) { |
| 6011 |
|
| 6012 |
for (CDataPropertyAssertionExpression* dataPropAssExp : *basicDataPropAssList) { |
| 6013 |
CDataLiteralVariableExpression* dataVarExp = (CDataLiteralVariableExpression*)dataPropAssExp->getDataLiteralTermExpression(); |
| 6014 |
CIndividualTermExpression* indiTermExp = dataPropAssExp->getIndividualTermExpression(); |
| 6015 |
CDataPropertyTermExpression* dataPropertyExp = dataPropAssExp->getDataPropertyTermExpression(); |
| 6016 |
|
| 6017 |
|
| 6018 |
CRole* dataRole = mOntoAnsweringItem->getOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getDataPropertyTermRoleMappingHash()->value(dataPropertyExp); |
| 6019 |
CIndividual* indi = mOntoAnsweringItem->getOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getIndividulTermIndiMappingHash()->value(indiTermExp); |
| 6020 |
|
| 6021 |
|
| 6022 |
COptimizedComplexVariableDataLiteralBaseItem* dataLiteralBaseItem = new COptimizedComplexVariableDataLiteralBaseItem(indi, dataRole); |
| 6023 |
COptimizedComplexVariableIndividualMappings* varMapping = new COptimizedComplexVariableIndividualMappingsHash(1); |
| 6024 |
varMapping->setBindingMapping(0, COptimizedComplexVariableIndividualMappings::DATA_LITERAL_VARIABLE); |
| 6025 |
dataLiteralBaseItem->setVariableMapping(varMapping); |
| 6026 |
dataLiteralBaseItem->setVariableMappingsComputationRequirement(-1); |
| 6027 |
dataLiteralBaseItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 6028 |
addUsedVariableCompositionItem(buildingVarItem, dataLiteralBaseItem); |
| 6029 |
queueVariableItemComputation(buildingVarItem, dataLiteralBaseItem); |
| 6030 |
processing = true; |
| 6031 |
|
| 6032 |
|
| 6033 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(dataVarExp); |
| 6034 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 6035 |
varItemIndexMapping.insert(dataLiteralBaseItem, itemIndexMapping); |
| 6036 |
itemIndexMapping->insert(0, dataVarExp); |
| 6037 |
|
| 6038 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 6039 |
QStringList debugVariableNameStringList = debugGetItemVariableNames(buildingVarItem, dataVarExp, dataLiteralBaseItem); |
| 6040 |
dataLiteralBaseItem->debugVariableNameStringList = debugVariableNameStringList; |
| 6041 |
dataLiteralBaseItem->debugCreationString = QString("Computation step %1").arg(dataLiteralBaseItem->getComputationStepId()) + " with [" + debugVariableNameStringList.join(", ") + "] initialized"; |
| 6042 |
debugCreationStringList += dataLiteralBaseItem->debugCreationString; |
| 6043 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 6044 |
#endif |
| 6045 |
QSet<COptimizedComplexVariableCompositionItem*>* varConBaseItemSet = new QSet<COptimizedComplexVariableCompositionItem*>(); |
| 6046 |
varConBaseItemSet->insert(dataLiteralBaseItem); |
| 6047 |
varExpVarComItemHash->insert(dataVarExp, varConBaseItemSet); |
| 6048 |
|
| 6049 |
buildingVarItem->setLastHandledVariableExpression(dataVarExp); |
| 6050 |
buildingVarItem->updateLastHandledVariableItemAssociation(dataVarExp, dataLiteralBaseItem); |
| 6051 |
|
| 6052 |
} |
| 6053 |
|
| 6054 |
buildingVarItem->setInitializedBasicDataVariableItems(true); |
| 6055 |
} |
| 6056 |
|
| 6057 |
basicDataPropAssList->clear(); |
| 6058 |
} |
| 6059 |
|
| 6060 |
|
| 6061 |
|
| 6062 |
|
| 6063 |
|
| 6064 |
|
| 6065 |
// data literals extension of variable items |
| 6066 |
if (!processing && compositionVarItemList->isEmpty()) { |
| 6067 |
|
| 6068 |
|
| 6069 |
QHash<CDataLiteralVariableExpression*, CIndividualVariableExpression*>* dataVarIndiVarHash = buildingVarItem->getDataLiteralVariableIndidualVariableMappingHash(); |
| 6070 |
QSet<CIndividualVariableExpression*>* remainingDataVarExpSet = buildingVarItem->getRemainingExtendingDataVariableSet(); |
| 6071 |
|
| 6072 |
if (!buildingVarItem->isInitializedConceptDataVariableExtensionItems() && buildingVarItem->isSatisfiable()) { |
| 6073 |
|
| 6074 |
for (CIndividualVariableExpression* indiVarExp : *remainingDataVarExpSet) { |
| 6075 |
QList<CDataPropertyAssertionExpression*> unDataPropAssList = buildingVarItem->getUnhanledDataPropertyAssertionsExpressions(indiVarExp); |
| 6076 |
|
| 6077 |
|
| 6078 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 6079 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(indiVarExp); |
| 6080 |
COptimizedComplexVariableCompositionItem* varCompItem = *varExpVarComItemHash->value(indiVarExp)->begin(); |
| 6081 |
// TODO: check if correct for multiple item index mappings (as long as data literals are processed with priority, then there is probably no problem) |
| 6082 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = varItemIndexMapping.value(varCompItem); |
| 6083 |
|
| 6084 |
|
| 6085 |
for (CDataPropertyAssertionExpression* dataPropAss : unDataPropAssList) { |
| 6086 |
CDataLiteralVariableExpression* dataVarExp = (CDataLiteralVariableExpression*)dataPropAss->getDataLiteralTermExpression(); |
| 6087 |
CDataPropertyTermExpression* dataPropExp = dataPropAss->getDataPropertyTermExpression(); |
| 6088 |
|
| 6089 |
buildVariableRolePropagationItem(buildingVarItem, indiVarExp, varCompItem, itemIndexMapping, dataVarExp, dataPropExp, &processing, answererContext); |
| 6090 |
|
| 6091 |
if (dataVarIndiVarHash->count(dataVarExp) <= 1) { |
| 6092 |
buildingVarItem->setDataPropertyAssertionHandled(dataPropAss); |
| 6093 |
} |
| 6094 |
} |
| 6095 |
} |
| 6096 |
|
| 6097 |
buildingVarItem->setInitializedConceptDataVariableExtensionItems(true); |
| 6098 |
} |
| 6099 |
|
| 6100 |
|
| 6101 |
|
| 6102 |
} |
| 6103 |
|
| 6104 |
|
| 6105 |
|
| 6106 |
|
| 6107 |
// joining basic data literals items and combining them with data extension items |
| 6108 |
if (!processing && compositionVarItemList->isEmpty()) { |
| 6109 |
|
| 6110 |
|
| 6111 |
QSet<CDataLiteralVariableExpression*>* basicDataVarJoiningSet = buildingVarItem->getBasicDataVariableJoiningSet(); |
| 6112 |
if (!buildingVarItem->isJoinedBasicDataVariableItems() && buildingVarItem->isSatisfiable()) { |
| 6113 |
|
| 6114 |
for (CDataLiteralVariableExpression* dataVarExp : *basicDataVarJoiningSet) { |
| 6115 |
QSet<COptimizedComplexVariableCompositionItem*>* joiningVarItemSet = varExpVarComItemHash->value(dataVarExp); |
| 6116 |
COptimizedComplexVariableCompositionItem* dataVarCompItem = *joiningVarItemSet->constBegin(); |
| 6117 |
if (joiningVarItemSet->size() > 1) { |
| 6118 |
dataVarCompItem = buildJoinedVariableJoiningItems(buildingVarItem, dataVarExp, &processing).first; |
| 6119 |
} |
| 6120 |
|
| 6121 |
QList<CDataPropertyAssertionExpression*> dataPropAssList = buildingVarItem->getUnhanledDataPropertyAssertionsExpressions(dataVarExp); |
| 6122 |
|
| 6123 |
for (QList<CDataPropertyAssertionExpression*>::iterator it = dataPropAssList.begin(), itEnd = dataPropAssList.end(); it != itEnd; ++it) { |
| 6124 |
CDataPropertyAssertionExpression* dataPropAssExp(*it); |
| 6125 |
|
| 6126 |
CIndividualVariableExpression* indiVar = (CIndividualVariableExpression*)dataPropAssExp->getIndividualTermExpression(); |
| 6127 |
COptimizedComplexVariableCompositionItem* indiVarCompItem = *varExpVarComItemHash->value(indiVar)->begin(); |
| 6128 |
buildVariableJoiningItem(buildingVarItem, indiVar, false, indiVar, indiVarCompItem, dataVarExp, dataVarCompItem, nullptr, nullptr, &processing); |
| 6129 |
|
| 6130 |
} |
| 6131 |
} |
| 6132 |
buildingVarItem->setJoinedBasicDataVariableItems(true); |
| 6133 |
} |
| 6134 |
} |
| 6135 |
|
| 6136 |
|
| 6137 |
|
| 6138 |
|
| 6139 |
|
| 6140 |
|
| 6141 |
|
| 6142 |
QSet<CIndividualVariableExpression*>* remainVarExpSet = buildingVarItem->getRemainingVariableExpressionSet(); |
| 6143 |
if (!processing && !remainVarExpSet->isEmpty() && buildingVarItem->isSatisfiable() && (!buildingVarItem->isWaitingComputation() || continueProcessingBuildingVarItem)) { |
| 6144 |
|
| 6145 |
//TODO: sort remainVarExpList by number of instances |
| 6146 |
QList<CIndividualVariableExpression*> remainVarExpList = getSortedRemainingVariableExpressionList(buildingVarItem, remainVarExpSet); |
| 6147 |
|
| 6148 |
while (!remainVarExpList.isEmpty() && !processing) { |
| 6149 |
CIndividualVariableExpression* varExp = remainVarExpList.takeFirst(); |
| 6150 |
|
| 6151 |
|
| 6152 |
QList<CObjectPropertyAssertionExpression*> propAssList = buildingVarItem->getUnhanledPropertyAssertionsExpressions(varExp); |
| 6153 |
QList<CDataPropertyAssertionExpression*> dataPropAssList = buildingVarItem->getUnhanledDataPropertyAssertionsExpressions(varExp); |
| 6154 |
|
| 6155 |
COptimizedComplexVariableCompositionItem* varCompItem = nullptr; |
| 6156 |
// join items |
| 6157 |
QSet<COptimizedComplexVariableCompositionItem*>* joiningVarItemSet = varExpVarComItemHash->value(varExp); |
| 6158 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 6159 |
if (joiningVarItemSet->size() == 1 && varItemIndexMapping.size() == 1) { |
| 6160 |
varCompItem = *joiningVarItemSet->constBegin(); |
| 6161 |
} else { |
| 6162 |
bool lastComputation = remainVarExpList.isEmpty() && propAssList.isEmpty() && dataPropAssList.isEmpty() && (!buildingVarItem->getAbsorbingQueryPartsList() || buildingVarItem->getAbsorbingQueryPartsList()->isEmpty()) && mConfMinimalMappingsComputationSize < 0; |
| 6163 |
if (lastComputation) { |
| 6164 |
lastComputation = false; |
| 6165 |
CComplexQueryExpressionProcessingData* queryProcData = buildingVarItem->getQueryProcessingData(); |
| 6166 |
CComplexAssertionsIndividualVariablesAnsweringQuery* compAssIndVarQuery = (CComplexAssertionsIndividualVariablesAnsweringQuery*)queryProcData->getQuery(); |
| 6167 |
if (compAssIndVarQuery && dynamic_cast<CVariableBindingsAnswersStreamingResult*>(compAssIndVarQuery->getQueryResult()) && !compAssIndVarQuery->getResultOrderingLinker()) { |
| 6168 |
lastComputation = true; |
| 6169 |
} |
| 6170 |
} |
| 6171 |
varCompItem = buildJoinedVariableJoiningItems(buildingVarItem, varExp, &processing, lastComputation).first; |
| 6172 |
} |
| 6173 |
cint64 propagatedCount = 0; |
| 6174 |
if (!processing) { |
| 6175 |
|
| 6176 |
if (!dataPropAssList.isEmpty() && propAssList.isEmpty()) { |
| 6177 |
for (QList<CDataPropertyAssertionExpression*>::iterator it = dataPropAssList.begin(), itEnd = dataPropAssList.end(); it != itEnd; ++it) { |
| 6178 |
CDataPropertyAssertionExpression* dataPropAssExp(*it); |
| 6179 |
QList<CIndividualVariableExpression*> indiBackDataPropAssList = buildingVarItem->getUnhandledDataExtensionIndividualTermExpressions(dataPropAssExp, varExp); |
| 6180 |
if (indiBackDataPropAssList.size() <= 0) { |
| 6181 |
buildingVarItem->setDataPropertyAssertionHandled(dataPropAssExp); |
| 6182 |
} else if (indiBackDataPropAssList.size() == 1 || !buildingVarItem->isRemovingDataPropertyAssertionDisconnecting(varExp, dataPropAssExp)) { |
| 6183 |
|
| 6184 |
CIndividualVariableExpression* connIndiVarExp = *indiBackDataPropAssList.begin(); |
| 6185 |
COptimizedComplexVariableCompositionItem* connVarCompItem = *varExpVarComItemHash->value(connIndiVarExp)->begin(); |
| 6186 |
|
| 6187 |
buildVariableJoiningItem(buildingVarItem, connIndiVarExp, false, varExp, varCompItem, connIndiVarExp, connVarCompItem, nullptr, nullptr, &processing); |
| 6188 |
|
| 6189 |
propagatedCount++; |
| 6190 |
buildingVarItem->setDataPropertyAssertionHandled(dataPropAssExp); |
| 6191 |
buildingVarItem->setVariableExpressionUnhandled(connIndiVarExp); |
| 6192 |
} |
| 6193 |
} |
| 6194 |
|
| 6195 |
} else { |
| 6196 |
|
| 6197 |
QList<CObjectPropertyAssertionExpression*> sortedPropAssList = getVariableRemainingSortedObjectPropertyList(buildingVarItem, varExp, varCompItem, propAssList); |
| 6198 |
|
| 6199 |
for (CObjectPropertyAssertionExpression* propAss : sortedPropAssList) { |
| 6200 |
if (sortedPropAssList.size() - propagatedCount == 1 || !buildingVarItem->isRemovingPropertyAssertionDisconnecting(varExp, propAss)) { |
| 6201 |
|
| 6202 |
QHash<CExpressionVariable*, cint64> reductionVarExpIndHash = getPropagationReducableVariables(buildingVarItem, varExp, varCompItem, nullptr, propAss); |
| 6203 |
varCompItem = buildVariableReductionItem(buildingVarItem, varExp, false, varCompItem, nullptr, reductionVarExpIndHash, &processing).first; |
| 6204 |
|
| 6205 |
buildVariableRolePropagationItem(buildingVarItem, varExp, varCompItem, nullptr, reductionVarExpIndHash, propAss, &processing, answererContext); |
| 6206 |
propagatedCount++; |
| 6207 |
buildingVarItem->setPropertyAssertionHandled(propAss); |
| 6208 |
buildingVarItem->setVariableExpressionUnhandled(buildingVarItem->getOtherVariableExpression(varExp, propAss)); |
| 6209 |
} |
| 6210 |
} |
| 6211 |
} |
| 6212 |
|
| 6213 |
if (propagatedCount == propAssList.size() + dataPropAssList.size()) { |
| 6214 |
buildingVarItem->setVariableExpressionHandled(varExp); |
| 6215 |
buildingVarItem->setLastHandledVariableExpression(varExp); |
| 6216 |
if (!processing) { |
| 6217 |
remainVarExpList = getSortedRemainingVariableExpressionList(buildingVarItem, remainVarExpSet); |
| 6218 |
} |
| 6219 |
} |
| 6220 |
|
| 6221 |
} |
| 6222 |
|
| 6223 |
} |
| 6224 |
} |
| 6225 |
|
| 6226 |
|
| 6227 |
|
| 6228 |
|
| 6229 |
|
| 6230 |
|
| 6231 |
|
| 6232 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*>* absorbingQueryPartsList = buildingVarItem->getAbsorbingQueryPartsList(); |
| 6233 |
if (!processing && absorbingQueryPartsList && !absorbingQueryPartsList->isEmpty() && buildingVarItem->isSatisfiable() && (!buildingVarItem->isWaitingComputation() || continueProcessingBuildingVarItem)) { |
| 6234 |
|
| 6235 |
// - try to use ordinary sparql evaluation with limit 1 if it is an ask query |
| 6236 |
// -- check whether all properties and classes are instantiated by individual nodes |
| 6237 |
// -- build corresponding concept items and add property and class assertion to variable building item |
| 6238 |
// -- reschedule absorption handling part such that absorption-based item is created if no answer is found |
| 6239 |
|
| 6240 |
CComplexQueryExpressionProcessingData* queryProcessingData = buildingVarItem->getQueryProcessingData(); |
| 6241 |
if (mConfBooleanQueryExistentialPartOrdinaryEvaluation && !buildingVarItem->hasAbsorptionBasedQueryPartsOrdinaryEvaluated()) { |
| 6242 |
buildingVarItem->setAbsorptionBasedQueryPartsOrdinaryEvaluated(true); |
| 6243 |
|
| 6244 |
processing = generateOrdinaryVariableBuiltItemEvaluationFromAbsorptionBasedPart(queryProcessingData, answererContext, absorbingQueryPartsList, buildingVarItem, processing); |
| 6245 |
} |
| 6246 |
|
| 6247 |
if (!processing) { |
| 6248 |
|
| 6249 |
bool ordinaryEvaluationSucceeded = false; |
| 6250 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* subItemOrdinaryEval = buildingVarItem->getAbsorptionBasedQueryPartsOrdinaryEvaluationSubVariableBuiltItem(); |
| 6251 |
if (buildingVarItem->hasAbsorptionBasedQueryPartsOrdinaryEvaluated() && subItemOrdinaryEval && subItemOrdinaryEval->isSatisfiable()) { |
| 6252 |
LOG(INFO, getDomain(), logTr("Found answer with ordinary evaluation for %1 existential parts of Boolean query, skipping absorption-based handling.").arg(absorbingQueryPartsList->size()), this); |
| 6253 |
ordinaryEvaluationSucceeded = true; |
| 6254 |
} else if (buildingVarItem->hasAbsorptionBasedQueryPartsOrdinaryEvaluated() && subItemOrdinaryEval) { |
| 6255 |
LOG(INFO, getDomain(), logTr("No answer found with ordinary evaluation for %1 existential parts of Boolean query, continuing with absorption-based handling.").arg(absorbingQueryPartsList->size()), this); |
| 6256 |
} |
| 6257 |
|
| 6258 |
if (!ordinaryEvaluationSucceeded) { |
| 6259 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*> entailmentCheckingAbsorptionBasedHandlingQueryPartDatas; |
| 6260 |
while (!absorbingQueryPartsList->isEmpty()) { |
| 6261 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorpingHanldingQueryPart = absorbingQueryPartsList->takeFirst(); |
| 6262 |
absorbExistentialQueryPart(absorpingHanldingQueryPart, answererContext); |
| 6263 |
|
| 6264 |
if (absorpingHanldingQueryPart->hasPreparationVariables()) { |
| 6265 |
buildingVarItem->addAbsorbedBasedQueryPartItemExtensionHandling(absorpingHanldingQueryPart); |
| 6266 |
} else { |
| 6267 |
buildingVarItem->addAbsorbedBasedQueryPartEntailmentCheckingHandling(absorpingHanldingQueryPart); |
| 6268 |
entailmentCheckingAbsorptionBasedHandlingQueryPartDatas.append(absorpingHanldingQueryPart); |
| 6269 |
} |
| 6270 |
|
| 6271 |
} |
| 6272 |
|
| 6273 |
if (mConfDebugTestingOntologyWriting) { |
| 6274 |
COntologyTextFormater::writeOntologyToFile(mOntoAnsweringItem->getTestingOntology(), "Debugging/Answering/Absorbed-Query-Expressions.txt"); |
| 6275 |
} |
| 6276 |
|
| 6277 |
mTestingOntologyPreprocessor->preprocess(mOntoAnsweringItem->getTestingOntology(), mOntoAnsweringItem->getTestingOntology()->getConfiguration()); |
| 6278 |
|
| 6279 |
if (mConfDebugTestingOntologyWriting) { |
| 6280 |
COntologyTextFormater::writeOntologyToFile(mOntoAnsweringItem->getTestingOntology(), "Debugging/Answering/Absorbed-Preprocessed-Query-Expressions.txt"); |
| 6281 |
} |
| 6282 |
|
| 6283 |
for (COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* data : entailmentCheckingAbsorptionBasedHandlingQueryPartDatas) { |
| 6284 |
createAbsorbedQueryPartEntailmentTest(data, queryProcessingData, answererContext); |
| 6285 |
} |
| 6286 |
} else { |
| 6287 |
absorbingQueryPartsList->clear(); |
| 6288 |
} |
| 6289 |
|
| 6290 |
|
| 6291 |
} |
| 6292 |
|
| 6293 |
} |
| 6294 |
|
| 6295 |
|
| 6296 |
|
| 6297 |
|
| 6298 |
|
| 6299 |
|
| 6300 |
|
| 6301 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem*>* absorptionHanldingQueryExtensionJoiningList = buildingVarItem->getAbsorptionBasedHandlingExtensionItemJoiningList(); |
| 6302 |
if (!processing && absorptionHanldingQueryExtensionJoiningList && !absorptionHanldingQueryExtensionJoiningList->isEmpty() && buildingVarItem->isSatisfiable() && (!buildingVarItem->isWaitingComputation() || continueProcessingBuildingVarItem)) { |
| 6303 |
|
| 6304 |
COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationItem = absorptionHanldingQueryExtensionJoiningList->takeFirst(); |
| 6305 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHandlingData = absorptionPropagationItem->getAbsorptionBasedHandlingData(); |
| 6306 |
CExpressionVariable* initializerVariableExp = absorptionHandlingData->getInitializerVariableExpression(); |
| 6307 |
|
| 6308 |
|
| 6309 |
QList< QPair<COptimizedComplexVariableCompositionItem*, CExpressionVariable*> >* variableExtendingItemList = absorptionPropagationItem->getExtendingCompositionItemAssociatedVariablePairList(); |
| 6310 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 6311 |
|
| 6312 |
// TODO: check, may has to be extended/adapted for cases where same item is used for several variables |
| 6313 |
|
| 6314 |
|
| 6315 |
QSet<CExpressionVariable*>* indiVarSet = absorptionHandlingData->getIndividualVariableSet(); |
| 6316 |
QSet<COptimizedComplexVariableCompositionItem*> integratedItemSet; |
| 6317 |
|
| 6318 |
for (CExpressionVariable* indiVarExp : *indiVarSet) { |
| 6319 |
COptimizedComplexVariableCompositionItem* varCompItem = buildingVarItem->getVariableLastCompositionItem(indiVarExp); |
| 6320 |
CExpressionVariable* associatedVariableExpression = buildingVarItem->getVariableLastCompositionItemAssociatedVariableExpression(indiVarExp); |
| 6321 |
|
| 6322 |
if (!integratedItemSet.contains(varCompItem)) { |
| 6323 |
integratedItemSet.insert(varCompItem); |
| 6324 |
if (varCompItem->getVariableMapping()->getBindingSize() > 1) { |
| 6325 |
variableExtendingItemList->append(QPair<COptimizedComplexVariableCompositionItem*, CExpressionVariable*>(varCompItem, associatedVariableExpression)); |
| 6326 |
} |
| 6327 |
} |
| 6328 |
|
| 6329 |
|
| 6330 |
} |
| 6331 |
|
| 6332 |
|
| 6333 |
|
| 6334 |
COptimizedComplexVariableCompositionItem* lastCompItem = absorptionPropagationItem; |
| 6335 |
CExpressionVariable* lastVariableExp = initializerVariableExp; |
| 6336 |
for (QPair<COptimizedComplexVariableCompositionItem*, CExpressionVariable*> extendingItemAssociatedVariablePair : *variableExtendingItemList) { |
| 6337 |
COptimizedComplexVariableCompositionItem* extendingItem = extendingItemAssociatedVariablePair.first; |
| 6338 |
CExpressionVariable* associatedVariableExpression = extendingItemAssociatedVariablePair.second; |
| 6339 |
lastCompItem = buildVariableJoiningItem(buildingVarItem, initializerVariableExp, false, lastVariableExp, lastCompItem, associatedVariableExpression, extendingItem, nullptr, nullptr, &processing).first; |
| 6340 |
} |
| 6341 |
|
| 6342 |
|
| 6343 |
for (CExpressionVariable* indiVarExp : *indiVarSet) { |
| 6344 |
QSet<COptimizedComplexVariableCompositionItem*>* compItems = varExpVarComItemHash->value(indiVarExp); |
| 6345 |
if (compItems->size() > 0) { |
| 6346 |
compItems->clear(); |
| 6347 |
compItems->insert(absorptionPropagationItem); |
| 6348 |
} |
| 6349 |
} |
| 6350 |
|
| 6351 |
for (CExpressionVariable* indiVarExp : *indiVarSet) { |
| 6352 |
buildingVarItem->updateLastHandledVariableItemAssociation(indiVarExp, lastCompItem); |
| 6353 |
} |
| 6354 |
buildingVarItem->updateLastHandledVariableItemAssociation(initializerVariableExp, lastCompItem); |
| 6355 |
buildingVarItem->setLastHandledVariableExpression(initializerVariableExp); |
| 6356 |
|
| 6357 |
|
| 6358 |
} |
| 6359 |
|
| 6360 |
|
| 6361 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*>* absorbedQueryPartsItemExtensionList = buildingVarItem->getAbsorbedQueryPartItemExtensionHandlingList(); |
| 6362 |
if (!processing && absorbedQueryPartsItemExtensionList && !absorbedQueryPartsItemExtensionList->isEmpty() && buildingVarItem->isSatisfiable() && (!buildingVarItem->isWaitingComputation() || continueProcessingBuildingVarItem)) { |
| 6363 |
|
| 6364 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHanldingQueryPart = absorbedQueryPartsItemExtensionList->takeFirst(); |
| 6365 |
|
| 6366 |
buildAbsorbedPartHandlingItem(buildingVarItem, absorptionHanldingQueryPart, varExpVarComItemHash, &processing); |
| 6367 |
|
| 6368 |
} |
| 6369 |
|
| 6370 |
return processing; |
| 6371 |
} |
| 6372 |
|
| 6373 |
bool COptimizedComplexExpressionAnsweringHandler::generateOrdinaryVariableBuiltItemEvaluationFromAbsorptionBasedPart(CComplexQueryExpressionProcessingData* queryProcessingData, CAnswererContext* answererContext, QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData *>* absorbingQueryPartsList, COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, bool processing) { |
| 6374 |
CComplexAssertionsIndividualVariablesAnsweringQuery* compAssIndVarQuery = dynamic_cast<CComplexAssertionsIndividualVariablesAnsweringQuery*>(queryProcessingData->getQuery()); |
| 6375 |
if (compAssIndVarQuery->isBooleanEntailmentResultRequired()) { |
| 6376 |
|
| 6377 |
bool ordinaryEvaluationUseful = true; |
| 6378 |
|
| 6379 |
cint64 statsTerms = 0; |
| 6380 |
cint64 statsTermsNoDeterministicInstances = 0; |
| 6381 |
cint64 statsTermsNoIndividualInstances = 0; |
| 6382 |
COccurrenceStatisticsCacheReader* occStatsCacheReader = answererContext->getAnsweringCalculationHandler()->getOccurrenceStatisticsCacheReader(); |
| 6383 |
cint64 ontologyId = mOntoAnsweringItem->getOntology()->getOntologyID(); |
| 6384 |
|
| 6385 |
for (COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorpingHanldingQueryPart : *absorbingQueryPartsList) { |
| 6386 |
|
| 6387 |
QSet<CExpressionVariable*>* restExpVarSet = absorpingHanldingQueryPart->getRestrictedAbsorptionVariableSet(); |
| 6388 |
|
| 6389 |
QSet<CObjectPropertyAssertionExpression*>* propAssSet = absorpingHanldingQueryPart->getPropertyAssertionSet(); |
| 6390 |
for (CObjectPropertyAssertionExpression* propAssExp : *propAssSet) { |
| 6391 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 6392 |
if (dynamic_cast<CObjectPropertyExpression*>(propExp)) { |
| 6393 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 6394 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 6395 |
// TODO: correctly resolve inverses |
| 6396 |
|
| 6397 |
if (restExpVarSet->contains(firstVarExp) || restExpVarSet->contains(secondVarExp)) { |
| 6398 |
|
| 6399 |
CRole* role = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value((CObjectPropertyTermExpression*)propExp); |
| 6400 |
CRole* inverseRole = role->getInverseRole(); |
| 6401 |
COccurrenceStatisticsRoleData roleOccStatsData = occStatsCacheReader->getAccummulatedRoleDataOccurrenceStatistics(ontologyId, role->getRoleTag()); |
| 6402 |
++statsTerms; |
| 6403 |
if (roleOccStatsData.getDeterministicInstanceOccurrencesCount() <= 0) { |
| 6404 |
statsTermsNoDeterministicInstances++; |
| 6405 |
} |
| 6406 |
if (roleOccStatsData.getIndividualInstanceOccurrencesCount() <= 0) { |
| 6407 |
statsTermsNoIndividualInstances++; |
| 6408 |
break; |
| 6409 |
} |
| 6410 |
if (inverseRole) { |
| 6411 |
++statsTerms; |
| 6412 |
COccurrenceStatisticsRoleData invRoleOccStatsData = occStatsCacheReader->getAccummulatedRoleDataOccurrenceStatistics(ontologyId, inverseRole->getRoleTag()); |
| 6413 |
if (invRoleOccStatsData.getDeterministicInstanceOccurrencesCount() <= 0) { |
| 6414 |
statsTermsNoDeterministicInstances++; |
| 6415 |
} |
| 6416 |
if (invRoleOccStatsData.getIndividualInstanceOccurrencesCount() <= 0) { |
| 6417 |
statsTermsNoIndividualInstances++; |
| 6418 |
break; |
| 6419 |
} |
| 6420 |
} |
| 6421 |
} |
| 6422 |
} |
| 6423 |
} |
| 6424 |
|
| 6425 |
QHash<CExpressionVariable*, CBuildExpression*>* varBuiltExpHash = absorpingHanldingQueryPart->getVariableBuiltExpressionsHash(); |
| 6426 |
for (QHash<CExpressionVariable*, CBuildExpression*>::const_iterator it = varBuiltExpHash->constBegin(), itEnd = varBuiltExpHash->constEnd(); it != itEnd && statsTermsNoIndividualInstances <= 0; ++it) { |
| 6427 |
|
| 6428 |
CIndividualVariableExpression* varExp = dynamic_cast<CIndividualVariableExpression*>(it.key()); |
| 6429 |
CClassTermExpression* classExp = (CClassTermExpression*)it.value(); |
| 6430 |
|
| 6431 |
if (restExpVarSet->contains(varExp) && dynamic_cast<CClassExpression*>(classExp)) { |
| 6432 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value((CClassTermExpression*)classExp); |
| 6433 |
if (concept->getOperatorCode() == CCEQ) { |
| 6434 |
concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getTBox()->getEquivalentConceptCandidateHash(false)->value(concept); |
| 6435 |
} |
| 6436 |
COccurrenceStatisticsConceptData conceptOccStatsData = occStatsCacheReader->getAccummulatedConceptDataOccurrenceStatistics(ontologyId, concept->getConceptTag()); |
| 6437 |
++statsTerms; |
| 6438 |
if (conceptOccStatsData.getDeterministicInstanceOccurrencesCount() <= 0) { |
| 6439 |
statsTermsNoDeterministicInstances++; |
| 6440 |
} |
| 6441 |
if (conceptOccStatsData.getIndividualInstanceOccurrencesCount() <= 0) { |
| 6442 |
statsTermsNoIndividualInstances++; |
| 6443 |
break; |
| 6444 |
} |
| 6445 |
} |
| 6446 |
|
| 6447 |
|
| 6448 |
} |
| 6449 |
} |
| 6450 |
|
| 6451 |
|
| 6452 |
ordinaryEvaluationUseful = statsTermsNoIndividualInstances <= 0 && (double)statsTermsNoDeterministicInstances / (double)statsTerms < 0.5; |
| 6453 |
|
| 6454 |
|
| 6455 |
|
| 6456 |
if (ordinaryEvaluationUseful) { |
| 6457 |
|
| 6458 |
CConcreteOntology* testingOnto = mOntoAnsweringItem->getTestingOntology(); |
| 6459 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarCompItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 6460 |
|
| 6461 |
|
| 6462 |
cint64 queryyClassTerms = 0; |
| 6463 |
|
| 6464 |
QList<CObjectPropertyAssertionExpression*> bothVarPropAssPropagationList; |
| 6465 |
QSet<CExpressionVariable*> conceptVarExpSet; |
| 6466 |
QHash<CExpressionVariable*, CAxiomExpression*> varExpAxiomExpHash; |
| 6467 |
QHash<CExpressionVariable*, CBuildExpression*> varRolledUpClassExpHash; |
| 6468 |
for (COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorpingHanldingQueryPart : *absorbingQueryPartsList) { |
| 6469 |
|
| 6470 |
QSet<CObjectPropertyAssertionExpression*>* propAssSet = absorpingHanldingQueryPart->getPropertyAssertionSet(); |
| 6471 |
for (CObjectPropertyAssertionExpression* propAssExp : *propAssSet) { |
| 6472 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 6473 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getFirstIndividualTermExpression()); |
| 6474 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(propAssExp->getSecondIndividualTermExpression()); |
| 6475 |
bool restrictedPropAss = false; |
| 6476 |
if (!varExpVarCompItemHash->contains(firstVarExp)) { |
| 6477 |
restrictedPropAss = true; |
| 6478 |
} |
| 6479 |
if (!varExpVarCompItemHash->contains(secondVarExp)) { |
| 6480 |
restrictedPropAss = true; |
| 6481 |
} |
| 6482 |
if (restrictedPropAss) { |
| 6483 |
bothVarPropAssPropagationList.append(propAssExp); |
| 6484 |
if (firstVarExp) { |
| 6485 |
if (!varExpVarCompItemHash->contains(firstVarExp)) { |
| 6486 |
conceptVarExpSet.insert(firstVarExp); |
| 6487 |
} |
| 6488 |
varExpAxiomExpHash.insertMulti(firstVarExp, propAssExp); |
| 6489 |
} |
| 6490 |
if (secondVarExp && secondVarExp != firstVarExp) { |
| 6491 |
if (!varExpVarCompItemHash->contains(secondVarExp)) { |
| 6492 |
conceptVarExpSet.insert(secondVarExp); |
| 6493 |
} |
| 6494 |
varExpAxiomExpHash.insertMulti(secondVarExp, propAssExp); |
| 6495 |
} |
| 6496 |
} |
| 6497 |
} |
| 6498 |
|
| 6499 |
QHash<CExpressionVariable*, CBuildExpression*>* varBuiltExpHash = absorpingHanldingQueryPart->getVariableBuiltExpressionsHash(); |
| 6500 |
for (QHash<CExpressionVariable*, CBuildExpression*>::const_iterator it = varBuiltExpHash->constBegin(), itEnd = varBuiltExpHash->constEnd(); it != itEnd && statsTermsNoIndividualInstances <= 0; ++it) { |
| 6501 |
CIndividualVariableExpression* varExp = dynamic_cast<CIndividualVariableExpression*>(it.key()); |
| 6502 |
CClassTermExpression* classExp = (CClassTermExpression*)it.value(); |
| 6503 |
if (!varExpVarCompItemHash->contains(varExp)) { |
| 6504 |
conceptVarExpSet.insert(varExp); |
| 6505 |
varRolledUpClassExpHash.insert(varExp, classExp); |
| 6506 |
++queryyClassTerms; |
| 6507 |
} |
| 6508 |
} |
| 6509 |
} |
| 6510 |
|
| 6511 |
|
| 6512 |
LOG(INFO, getDomain(), logTr("Trying ordinary evaluation with %2 terms for %1 existential parts of Boolean query.").arg(absorbingQueryPartsList->size()).arg(bothVarPropAssPropagationList.size() + queryyClassTerms), this); |
| 6513 |
|
| 6514 |
mTestingOntologyBuilder->initializeBuilding(); |
| 6515 |
|
| 6516 |
// building complex concept expressions for concept items |
| 6517 |
QSet<CExpressionVariable*> prepareIndiVarSet; |
| 6518 |
QSet<CExpressionVariable*> rolledVarExpSet; |
| 6519 |
QSet<CExpressionVariable*> anonymousIndiVariableSet; |
| 6520 |
QHash<CExpressionVariable*, CBuildExpression*> individualTriggerUpdatableHash; |
| 6521 |
QList<QPair<CIndividualVariableExpression*, CClassTermExpression*>> varClassInstTestExpList; |
| 6522 |
varClassInstTestExpList = generateConceptItemExpressions(conceptVarExpSet, rolledVarExpSet, anonymousIndiVariableSet, varRolledUpClassExpHash, varExpAxiomExpHash, individualTriggerUpdatableHash, prepareIndiVarSet, queryProcessingData); |
| 6523 |
|
| 6524 |
|
| 6525 |
mTestingOntologyBuilder->completeBuilding(); |
| 6526 |
|
| 6527 |
|
| 6528 |
QList<QPair<CIndividualVariableExpression*, TConceptNegPair>> varConNegInstTestExpList; |
| 6529 |
varConNegInstTestExpList = upgradeExistTopToIndividualTriggers(varClassInstTestExpList, individualTriggerUpdatableHash, answererContext); |
| 6530 |
|
| 6531 |
|
| 6532 |
|
| 6533 |
if (mConfDebugTestingOntologyWriting) { |
| 6534 |
COntologyTextFormater::writeOntologyToFile(testingOnto, "Debugging/Answering/Absorbed-Query-Expressions.txt"); |
| 6535 |
} |
| 6536 |
|
| 6537 |
mTestingOntologyPreprocessor->preprocess(testingOnto, testingOnto->getConfiguration()); |
| 6538 |
|
| 6539 |
|
| 6540 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* limitedSubBuildingVarItem = buildingVarItem->createExtendingBuildingVariableCompositionsItem(); |
| 6541 |
|
| 6542 |
|
| 6543 |
bool conceptItemsProcessing = schedulingConceptItemsProcessingForBuildItem(varConNegInstTestExpList, nullptr, limitedSubBuildingVarItem); |
| 6544 |
|
| 6545 |
limitedSubBuildingVarItem->addVariablePropertyAssertions(bothVarPropAssPropagationList); |
| 6546 |
buildingVarItem->setAbsorptionBasedQueryPartsOrdinaryEvaluationSubVariableBuiltItem(limitedSubBuildingVarItem); |
| 6547 |
|
| 6548 |
|
| 6549 |
|
| 6550 |
|
| 6551 |
// todo |
| 6552 |
|
| 6553 |
CComputedItemDataNotificationLinker* notLinker = mOntoAnsweringItem->createComputedItemDataNotificationLinker(); |
| 6554 |
notLinker->setBuildingVariableItemProcessingItem(buildingVarItem); |
| 6555 |
limitedSubBuildingVarItem->addNotificationLinker(notLinker); |
| 6556 |
buildingVarItem->incWaitingSubVariableBuildingItemCount(); |
| 6557 |
|
| 6558 |
queryProcessingData->incBuildingVariableItem(); |
| 6559 |
if (!conceptItemsProcessing) { |
| 6560 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(limitedSubBuildingVarItem); |
| 6561 |
limitedSubBuildingVarItem->setProcessingQueued(true); |
| 6562 |
} |
| 6563 |
processing = true; |
| 6564 |
} |
| 6565 |
} |
| 6566 |
return processing; |
| 6567 |
} |
| 6568 |
|
| 6569 |
|
| 6570 |
|
| 6571 |
|
| 6572 |
static bool itemSortLessVariableMappingsThan(const TRemainingVariableMappingCountSortingItem& item1, const TRemainingVariableMappingCountSortingItem& item2) { |
| 6573 |
if (item1.second < item2.second) { |
| 6574 |
return true; |
| 6575 |
} else if (item1.second == item2.second) { |
| 6576 |
return item1.first->getName() < item2.first->getName(); |
| 6577 |
} else { |
| 6578 |
return false; |
| 6579 |
} |
| 6580 |
} |
| 6581 |
|
| 6582 |
|
| 6583 |
|
| 6584 |
|
| 6585 |
static bool itemSortLessObjectPropertyScoresThan(const TRemainingVariableCompositionItemObjectPropertySortingItem& item1, const TRemainingVariableCompositionItemObjectPropertySortingItem& item2) { |
| 6586 |
if (item1.second < item2.second) { |
| 6587 |
return true; |
| 6588 |
} else if (item1.second == item2.second) { |
| 6589 |
return item1.first->getObjectPropertyTermExpression() < item2.first->getObjectPropertyTermExpression(); |
| 6590 |
} else { |
| 6591 |
return false; |
| 6592 |
} |
| 6593 |
} |
| 6594 |
|
| 6595 |
|
| 6596 |
|
| 6597 |
|
| 6598 |
QList<CObjectPropertyAssertionExpression*> COptimizedComplexExpressionAnsweringHandler::getVariableRemainingSortedObjectPropertyList(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CIndividualVariableExpression* varExp, COptimizedComplexVariableCompositionItem* varCompItem, const QList<CObjectPropertyAssertionExpression*>& propAssList) { |
| 6599 |
QList<CObjectPropertyAssertionExpression*> sortedPropAssList; |
| 6600 |
|
| 6601 |
if (mConfNextVariablePropagationHandlingPropertyPriorization) { |
| 6602 |
double expectedBindingSize = varCompItem->getVariableMappingsExpectedCount(); |
| 6603 |
|
| 6604 |
QList<TRemainingVariableCompositionItemObjectPropertySortingItem> sortingItemList; |
| 6605 |
for (CObjectPropertyAssertionExpression* propAssExp : propAssList) { |
| 6606 |
|
| 6607 |
double propInOutModificationFactor = 1; |
| 6608 |
double propTotalScore = 0; |
| 6609 |
getVariableCompositionItemPropertyAssertionHandlingScores(buildingVarItem, varExp, varCompItem, propAssExp, expectedBindingSize, propTotalScore, propInOutModificationFactor); |
| 6610 |
|
| 6611 |
|
| 6612 |
double propScoredExpectedBindingsSize = (propInOutModificationFactor * mConfNextVariablePropagationHandlingPropertyInOutFactorIntegrationPercent + expectedBindingSize * (100. - mConfNextVariablePropagationHandlingPropertyInOutFactorIntegrationPercent)) / 100.; |
| 6613 |
double propTotalScoredExpectedBindingsSize = propScoredExpectedBindingsSize; |
| 6614 |
if (propTotalScore != 0.) { |
| 6615 |
propTotalScoredExpectedBindingsSize = (propScoredExpectedBindingsSize * (100. - mConfNextVariablePropagationHandlingPropertyTotalScoreIntegrationPercent) + propTotalScore * mConfNextVariablePropagationHandlingPropertyTotalScoreIntegrationPercent) / 100.; |
| 6616 |
} |
| 6617 |
|
| 6618 |
sortingItemList.append(TRemainingVariableCompositionItemObjectPropertySortingItem(propAssExp, propTotalScoredExpectedBindingsSize)); |
| 6619 |
} |
| 6620 |
qSort(sortingItemList.begin(), sortingItemList.end(), itemSortLessObjectPropertyScoresThan); |
| 6621 |
for (TRemainingVariableCompositionItemObjectPropertySortingItem remVarSortItem : sortingItemList) { |
| 6622 |
sortedPropAssList.append(remVarSortItem.first); |
| 6623 |
} |
| 6624 |
} else { |
| 6625 |
sortedPropAssList = propAssList; |
| 6626 |
} |
| 6627 |
return sortedPropAssList; |
| 6628 |
} |
| 6629 |
|
| 6630 |
|
| 6631 |
|
| 6632 |
QList<CIndividualVariableExpression*> COptimizedComplexExpressionAnsweringHandler::getSortedRemainingVariableExpressionList(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, QSet<CIndividualVariableExpression*>* remainVarExpSet) { |
| 6633 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 6634 |
QList<TRemainingVariableMappingCountSortingItem> remainVarExpSortList; |
| 6635 |
|
| 6636 |
|
| 6637 |
auto remainVarOtherVarsAssociatedFunc = [&](CExpressionVariable* remainVarExp, COptimizedComplexVariableCompositionItem* joiningVarItem)->QSet<CExpressionVariable*> { |
| 6638 |
QSet<CExpressionVariable*> varsAssociatedSet; |
| 6639 |
varsAssociatedSet.insert(remainVarExp); |
| 6640 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(remainVarExp); |
| 6641 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemMapping = varItemIndexMapping.value(joiningVarItem); |
| 6642 |
if (itemMapping) { |
| 6643 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemMapping->constBegin(), itEnd = itemMapping->constEnd(); it != itEnd; ++it) { |
| 6644 |
CExpressionVariable* otherAssocExpVar = it.value(); |
| 6645 |
varsAssociatedSet.insert(remainVarExp); |
| 6646 |
} |
| 6647 |
} |
| 6648 |
return varsAssociatedSet; |
| 6649 |
}; |
| 6650 |
|
| 6651 |
|
| 6652 |
auto remainVarOtherVarsAssociatedItemSetFunc = [&](CExpressionVariable* remainVarExp, QSet<COptimizedComplexVariableCompositionItem*>* joiningVarItemSet)->QSet<CExpressionVariable*> { |
| 6653 |
QSet<CExpressionVariable*> remainVarOtherVarsAssociatedSet; |
| 6654 |
remainVarOtherVarsAssociatedSet.insert(remainVarExp); |
| 6655 |
for (COptimizedComplexVariableCompositionItem* joiningVarItem : *joiningVarItemSet) { |
| 6656 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(remainVarExp); |
| 6657 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemMapping = varItemIndexMapping.value(joiningVarItem); |
| 6658 |
if (itemMapping) { |
| 6659 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemMapping->constBegin(), itEnd = itemMapping->constEnd(); it != itEnd; ++it) { |
| 6660 |
CExpressionVariable* otherAssocExpVar = it.value(); |
| 6661 |
remainVarOtherVarsAssociatedSet.insert(remainVarExp); |
| 6662 |
} |
| 6663 |
} |
| 6664 |
} |
| 6665 |
return remainVarOtherVarsAssociatedSet; |
| 6666 |
}; |
| 6667 |
|
| 6668 |
QHash<CExpressionVariable*, cint64> varsAssociatedCountHash; |
| 6669 |
for (CIndividualVariableExpression* remainVarExp : *remainVarExpSet) { |
| 6670 |
QSet<COptimizedComplexVariableCompositionItem*>* joiningVarItemSet = varExpVarComItemHash->value(remainVarExp); |
| 6671 |
|
| 6672 |
if (joiningVarItemSet) { |
| 6673 |
QSet<CExpressionVariable*> remainVarOtherVarsAssociatedSet = remainVarOtherVarsAssociatedItemSetFunc(remainVarExp, joiningVarItemSet); |
| 6674 |
for (CExpressionVariable* assocVar : remainVarOtherVarsAssociatedSet) { |
| 6675 |
varsAssociatedCountHash[assocVar]++; |
| 6676 |
} |
| 6677 |
} |
| 6678 |
} |
| 6679 |
|
| 6680 |
|
| 6681 |
|
| 6682 |
for (CIndividualVariableExpression* remainVarExp : *remainVarExpSet) { |
| 6683 |
QSet<COptimizedComplexVariableCompositionItem*>* joiningVarItemSet = varExpVarComItemHash->value(remainVarExp); |
| 6684 |
|
| 6685 |
if (joiningVarItemSet) { |
| 6686 |
QSet<CExpressionVariable*> remainVarOtherVarsAssociatedSet = remainVarOtherVarsAssociatedItemSetFunc(remainVarExp, joiningVarItemSet); |
| 6687 |
|
| 6688 |
double minExpectedBindingSize = DOUBLE_MAX; |
| 6689 |
COptimizedComplexVariableCompositionItem* minJoiningVarItem = nullptr; |
| 6690 |
for (COptimizedComplexVariableCompositionItem* joiningVarItem : *joiningVarItemSet) { |
| 6691 |
if (joiningVarItem->getVariableMappingsExpectedCount() < minExpectedBindingSize) { |
| 6692 |
minExpectedBindingSize = joiningVarItem->getVariableMappingsExpectedCount(); |
| 6693 |
minJoiningVarItem = joiningVarItem; |
| 6694 |
} |
| 6695 |
} |
| 6696 |
|
| 6697 |
// TODO: maybe integrate other items in the estimation (but on the ohter hand, they are joined anyway first and then the estimation is recomputed) |
| 6698 |
//if (joiningVarItemSet->size() > 1 && minJoiningVarItem) { |
| 6699 |
// QSet<CExpressionVariable*> minVarsAssociatedSet = remainVarOtherVarsAssociatedFunc(remainVarExp, minJoiningVarItem); |
| 6700 |
// for (COptimizedComplexVariableCompositionItem* joiningVarItem : *joiningVarItemSet) { |
| 6701 |
// if (joiningVarItem != minJoiningVarItem) { |
| 6702 |
// cint64 minVarCount = minVarsAssociatedSet.size(); |
| 6703 |
// QSet<CExpressionVariable*> varsAssociatedSet = remainVarOtherVarsAssociatedFunc(remainVarExp, joiningVarItem); |
| 6704 |
// cint64 newVarCount = 0; |
| 6705 |
// cint64 missVarCount = 0; |
| 6706 |
// for (CExpressionVariable* assocVar : varsAssociatedSet) { |
| 6707 |
// if (!minVarsAssociatedSet.contains(assocVar)) { |
| 6708 |
// ++newVarCount; |
| 6709 |
// } |
| 6710 |
// } |
| 6711 |
// for (CExpressionVariable* assocVar : minVarsAssociatedSet) { |
| 6712 |
// if (!varsAssociatedSet.contains(assocVar)) { |
| 6713 |
// ++missVarCount; |
| 6714 |
// } |
| 6715 |
// } |
| 6716 |
// cint64 changeVarCount = newVarCount - missVarCount; |
| 6717 |
// } |
| 6718 |
// } |
| 6719 |
//} |
| 6720 |
|
| 6721 |
|
| 6722 |
|
| 6723 |
double expectedBindingsModificationFactor = 1.; |
| 6724 |
QList<CObjectPropertyAssertionExpression*> propAssList; |
| 6725 |
if (mConfNextVariablePropagationHandlingReducibleFactorIntegration || mConfNextVariablePropagationHandlingPropertyScoresIntegration) { |
| 6726 |
propAssList = buildingVarItem->getUnhanledPropertyAssertionsExpressions(remainVarExp); |
| 6727 |
} |
| 6728 |
|
| 6729 |
if (mConfNextVariablePropagationHandlingReducibleFactorIntegration) { |
| 6730 |
// determine whether only one object property remains |
| 6731 |
if (propAssList.size() == 1) { |
| 6732 |
// determine the reducible variables after the propagation |
| 6733 |
cint64 reducibleVarCount = 0; |
| 6734 |
|
| 6735 |
for (CExpressionVariable* assocVar : remainVarOtherVarsAssociatedSet) { |
| 6736 |
cint64 varOccCount = varsAssociatedCountHash.value(assocVar); |
| 6737 |
if (varOccCount <= 1 && !buildingVarItem->getReductionDeniedVariableSet()->contains(assocVar)) { |
| 6738 |
reducibleVarCount++; |
| 6739 |
} |
| 6740 |
} |
| 6741 |
|
| 6742 |
|
| 6743 |
if (reducibleVarCount >= 1) { |
| 6744 |
expectedBindingsModificationFactor *= pow(mConfNextVariablePropagationHandlingReducibleFactor, (double)reducibleVarCount); |
| 6745 |
} |
| 6746 |
} |
| 6747 |
} |
| 6748 |
|
| 6749 |
|
| 6750 |
double propInOutModificationFactor = 1.; |
| 6751 |
double propTotalScore = 0.; |
| 6752 |
if (mConfNextVariablePropagationHandlingPropertyScoresIntegration) { |
| 6753 |
for (CObjectPropertyAssertionExpression* propAssExp : propAssList) { |
| 6754 |
|
| 6755 |
getVariableCompositionItemPropertyAssertionHandlingScores(buildingVarItem, remainVarExp, minJoiningVarItem, propAssExp, minExpectedBindingSize, propInOutModificationFactor, propTotalScore); |
| 6756 |
|
| 6757 |
} |
| 6758 |
} |
| 6759 |
|
| 6760 |
double propScoredExpectedBindingsSize = (propInOutModificationFactor * mConfNextVariablePropagationHandlingPropertyInOutFactorIntegrationPercent + minExpectedBindingSize * (100. - mConfNextVariablePropagationHandlingPropertyInOutFactorIntegrationPercent)) / 100.; |
| 6761 |
double propTotalScoredExpectedBindingsSize = propScoredExpectedBindingsSize; |
| 6762 |
if (propTotalScore != 0.) { |
| 6763 |
propTotalScoredExpectedBindingsSize = (propScoredExpectedBindingsSize * (100. - mConfNextVariablePropagationHandlingPropertyTotalScoreIntegrationPercent) + propTotalScore * mConfNextVariablePropagationHandlingPropertyTotalScoreIntegrationPercent) / 100.; |
| 6764 |
} |
| 6765 |
double expectedBindingsSize = propTotalScoredExpectedBindingsSize * expectedBindingsModificationFactor; |
| 6766 |
|
| 6767 |
|
| 6768 |
TRemainingVariableMappingCountSortingItem remVarSortItem(remainVarExp, expectedBindingsSize); |
| 6769 |
remainVarExpSortList.append(remVarSortItem); |
| 6770 |
} |
| 6771 |
} |
| 6772 |
|
| 6773 |
|
| 6774 |
|
| 6775 |
|
| 6776 |
|
| 6777 |
qSort(remainVarExpSortList.begin(), remainVarExpSortList.end(), itemSortLessVariableMappingsThan); |
| 6778 |
|
| 6779 |
QStringList remainingVarStringList; |
| 6780 |
|
| 6781 |
QList<CIndividualVariableExpression*> remainVarExpList; |
| 6782 |
for (TRemainingVariableMappingCountSortingItem remVarSortItem : remainVarExpSortList) { |
| 6783 |
remainVarExpList.append(remVarSortItem.first); |
| 6784 |
|
| 6785 |
if (mConfExtendedLogging) { |
| 6786 |
QString expectedCoundString; |
| 6787 |
expectedCoundString.setNum(remVarSortItem.second, 'f', 1); |
| 6788 |
remainingVarStringList.append(QString("%1 with %2 expected mappings").arg(remVarSortItem.first->getName()).arg(expectedCoundString)); |
| 6789 |
} |
| 6790 |
} |
| 6791 |
|
| 6792 |
if (mConfExtendedLogging) { |
| 6793 |
LOG(INFO, getDomain(), logTr("Continue propagation for remaining variables: %1.").arg(remainingVarStringList.join(", ")), this); |
| 6794 |
} |
| 6795 |
|
| 6796 |
return remainVarExpList; |
| 6797 |
} |
| 6798 |
|
| 6799 |
|
| 6800 |
|
| 6801 |
void COptimizedComplexExpressionAnsweringHandler::getVariableCompositionItemPropertyAssertionHandlingScores(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CIndividualVariableExpression* remainVarExp, COptimizedComplexVariableCompositionItem* minJoiningVarItem, CObjectPropertyAssertionExpression* propAssExp, double minExpectedBindingSize, double &propInOutModificationFactor, double &propTotalScore) { |
| 6802 |
|
| 6803 |
COccurrenceStatisticsCacheReader* occStatsCacheReader = mAnswererContext->getAnsweringCalculationHandler()->getOccurrenceStatisticsCacheReader(); |
| 6804 |
CConcreteOntology* ontology = mOntoAnsweringItem->getOntology(); |
| 6805 |
cint64 ontologyId = ontology->getOntologyID(); |
| 6806 |
CRole* role = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value((CObjectPropertyTermExpression*)propAssExp->getObjectPropertyTermExpression()); |
| 6807 |
CRole* outRole = role; |
| 6808 |
CRole* inRole = role->getInverseRole(); |
| 6809 |
CIndividualVariableExpression* otherVarExp = (CIndividualVariableExpression*)propAssExp->getSecondIndividualTermExpression(); |
| 6810 |
if (propAssExp->getFirstIndividualTermExpression() != remainVarExp) { |
| 6811 |
outRole = inRole; |
| 6812 |
inRole = role; |
| 6813 |
otherVarExp = (CIndividualVariableExpression*)propAssExp->getFirstIndividualTermExpression(); |
| 6814 |
} |
| 6815 |
if (role) { |
| 6816 |
//if (CIRIName::getRecentIRIName(role->getPropertyNameLinker()) == "http://semantics.crl.ibm.com/univ-bench-dl.owl#like") { |
| 6817 |
// hasLikeRole = true; |
| 6818 |
//} |
| 6819 |
|
| 6820 |
double complexFactor = 1.; |
| 6821 |
if (role->isComplexRole()) { |
| 6822 |
complexFactor = 2.5; |
| 6823 |
} |
| 6824 |
|
| 6825 |
COccurrenceStatisticsRoleData roleOccStatsData = occStatsCacheReader->getAccummulatedRoleDataOccurrenceStatistics(ontologyId, role->getRoleTag()); |
| 6826 |
double roleOccFactor = complexFactor * (roleOccStatsData.getDeterministicInstanceOccurrencesCount() + roleOccStatsData.getNonDeterministicInstanceOccurrencesCount() * 2 + roleOccStatsData.getExistentialInstanceOccurrencesCount() * 1.5 + roleOccStatsData.getIndividualInstanceOccurrencesCount()); |
| 6827 |
propTotalScore += roleOccFactor; |
| 6828 |
} |
| 6829 |
|
| 6830 |
double inOutRatio = 1; |
| 6831 |
if (outRole && inRole) { |
| 6832 |
COccurrenceStatisticsRoleData outRoleOccStatsData = occStatsCacheReader->getAccummulatedRoleDataOccurrenceStatistics(ontologyId, outRole->getRoleTag()); |
| 6833 |
COccurrenceStatisticsRoleData inRoleOccStatsData = occStatsCacheReader->getAccummulatedRoleDataOccurrenceStatistics(ontologyId, inRole->getRoleTag()); |
| 6834 |
cint64 inRoleInstCount = inRoleOccStatsData.getOutgoingNodeInstanceOccurrencesCount(); |
| 6835 |
cint64 outRoleInstCount = outRoleOccStatsData.getOutgoingNodeInstanceOccurrencesCount(); |
| 6836 |
|
| 6837 |
if (!mConfForceAlwaysVariableCompositionItemRoleSampling && outRoleInstCount != inRoleInstCount && inRoleInstCount != 0) { |
| 6838 |
inOutRatio = (double)inRoleInstCount / (double)outRoleInstCount; |
| 6839 |
} else if (mConfForceAlwaysVariableCompositionItemRoleSampling || mConfVariableCompositionItemRoleSampling) { |
| 6840 |
inOutRatio = getVariableCompositionItemRoleSampledInOutRatio(buildingVarItem, remainVarExp, otherVarExp, minJoiningVarItem, outRole, inRole, mAnswererContext); |
| 6841 |
} |
| 6842 |
|
| 6843 |
propInOutModificationFactor += minExpectedBindingSize * inOutRatio; |
| 6844 |
} |
| 6845 |
} |
| 6846 |
|
| 6847 |
|
| 6848 |
|
| 6849 |
cint64 COptimizedComplexExpressionAnsweringHandler::getVariableCompositionItemVariablePosition(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CExpressionVariable* varExp, COptimizedComplexVariableCompositionItem* varItem) { |
| 6850 |
cint64 propVarPos = -1; |
| 6851 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 6852 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemMapping = varItemIndexMapping.value(varItem); |
| 6853 |
if (itemMapping) { |
| 6854 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemMapping->constBegin(), itEnd = itemMapping->constEnd(); it != itEnd; ++it) { |
| 6855 |
CExpressionVariable* otherAssocExpVar = it.value(); |
| 6856 |
if (otherAssocExpVar == varExp) { |
| 6857 |
propVarPos = it.key(); |
| 6858 |
break; |
| 6859 |
} |
| 6860 |
} |
| 6861 |
} |
| 6862 |
return propVarPos; |
| 6863 |
} |
| 6864 |
|
| 6865 |
|
| 6866 |
|
| 6867 |
double COptimizedComplexExpressionAnsweringHandler::getVariableCompositionItemRoleSampledInOutRatio(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CExpressionVariable* varExp, CExpressionVariable* otherVarExp, COptimizedComplexVariableCompositionItem* varItem, CRole* outRole, CRole* inRole, CAnswererContext* answererContext) { |
| 6868 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 6869 |
QSet<COptimizedComplexVariableCompositionItem*>* otherVarItemSet = varExpVarComItemHash->value(otherVarExp); |
| 6870 |
if (otherVarItemSet) { |
| 6871 |
double minExpectedBindingSize = DOUBLE_MAX; |
| 6872 |
COptimizedComplexVariableCompositionItem* minOtherVarItem = nullptr; |
| 6873 |
for (COptimizedComplexVariableCompositionItem* otherVarItem : *otherVarItemSet) { |
| 6874 |
if (otherVarItem->getVariableMappingsExpectedCount() < minExpectedBindingSize) { |
| 6875 |
minExpectedBindingSize = otherVarItem->getVariableMappingsExpectedCount(); |
| 6876 |
minOtherVarItem = otherVarItem; |
| 6877 |
} |
| 6878 |
} |
| 6879 |
if (minOtherVarItem) { |
| 6880 |
double sampledInCountEstimation = getVariableCompositionItemRoleAverageSampledOutCount(buildingVarItem, varExp, varItem, outRole, answererContext); |
| 6881 |
return sampledInCountEstimation; |
| 6882 |
//double sampledOutCountEstimation = getVariableCompositionItemRoleAverageSampledOutCount(buildingVarItem, otherVarExp, minOtherVarItem, inRole, answererContext); |
| 6883 |
//double inOutRatio = (double)sampledInCountEstimation / (double)sampledOutCountEstimation; |
| 6884 |
//return inOutRatio; |
| 6885 |
} |
| 6886 |
} |
| 6887 |
return 1.; |
| 6888 |
|
| 6889 |
} |
| 6890 |
|
| 6891 |
|
| 6892 |
|
| 6893 |
double COptimizedComplexExpressionAnsweringHandler::getVariableCompositionItemRoleAverageSampledOutCount(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CExpressionVariable* varExp, COptimizedComplexVariableCompositionItem* varItem, CRole* role, CAnswererContext* answererContext) { |
| 6894 |
CRoleRealization* roleRealization = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 6895 |
CRoleInstantiatedItem* roleInstancesItem = roleRealization->getRoleInstantiatedItem(role); |
| 6896 |
|
| 6897 |
|
| 6898 |
cint64 variableCompositionItemRoleSamplingCount = mConfVariableCompositionItemRoleSamplingCount; |
| 6899 |
cint64 expectedCount = varItem->getVariableMappingsExpectedCount(); |
| 6900 |
if (expectedCount > mConfVariableCompositionItemRoleSamplingMappingsIncreaseSize) { |
| 6901 |
variableCompositionItemRoleSamplingCount *= expectedCount / mConfVariableCompositionItemRoleSamplingMappingsIncreaseSize; |
| 6902 |
} |
| 6903 |
COptimizedComplexVariableCompositionItemRoleSamplingData& roleSamplingData = varItem->getRoleSamplingData(role); |
| 6904 |
if (roleSamplingData.getSampleCount() < variableCompositionItemRoleSamplingCount && varItem->getVariableMappingsCurrentCount() > roleSamplingData.getSampleCount()) { |
| 6905 |
|
| 6906 |
cint64 propVarPos = getVariableCompositionItemVariablePosition(buildingVarItem, varExp, varItem); |
| 6907 |
|
| 6908 |
|
| 6909 |
cint64 averageCount = 0; |
| 6910 |
double averageEstimatedCount = 0; |
| 6911 |
|
| 6912 |
auto averageBindingsEstimate = [&](COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindCardLinker) { |
| 6913 |
CRealizationIndividualInstanceItemReference propInstItemRef = bindCardLinker->getBindings()->getBinding(propVarPos).reference; |
| 6914 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = roleRealization->getRoleFillerInstancesIterator(propInstItemRef, roleInstancesItem, false, mRoleFillerRealizationSorting); |
| 6915 |
iterator->begin(); |
| 6916 |
double estimatedCount = iterator->remainingInstancesEstimation().getEstimatedCount(); |
| 6917 |
averageEstimatedCount += estimatedCount; |
| 6918 |
averageCount++; |
| 6919 |
delete iterator; |
| 6920 |
}; |
| 6921 |
|
| 6922 |
COptimizedComplexVariableIndividualBindingsCardinalityBatchLinker* bindCardBatchLinker = varItem->getVariableMapping()->getFirstAddedBindingsCardinalityBatchLinker(); |
| 6923 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindCardLinker = varItem->getVariableMapping()->getLastAddedBindingsCardinalityLinker(); |
| 6924 |
if (bindCardLinker && bindCardBatchLinker) { |
| 6925 |
bindCardLinker = bindCardLinker->getNext(); |
| 6926 |
} |
| 6927 |
while (averageCount < variableCompositionItemRoleSamplingCount && (bindCardLinker || bindCardBatchLinker)) { |
| 6928 |
if (bindCardBatchLinker) { |
| 6929 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* batchBindCardLinker = bindCardBatchLinker->getStartBindingsCardinalityLinker(); |
| 6930 |
if (batchBindCardLinker) { |
| 6931 |
averageBindingsEstimate(batchBindCardLinker); |
| 6932 |
} |
| 6933 |
bindCardBatchLinker = bindCardBatchLinker->getNext(); |
| 6934 |
} else if (bindCardLinker) { |
| 6935 |
averageBindingsEstimate(bindCardLinker); |
| 6936 |
bindCardLinker = bindCardLinker->getNext(); |
| 6937 |
} |
| 6938 |
} |
| 6939 |
if (averageCount != 0) { |
| 6940 |
averageEstimatedCount /= averageCount; |
| 6941 |
} |
| 6942 |
roleSamplingData.updateSamplingData(averageCount, averageEstimatedCount); |
| 6943 |
} |
| 6944 |
return roleSamplingData.getSampleEstimatedRoleSuccessorCount(); |
| 6945 |
} |
| 6946 |
|
| 6947 |
|
| 6948 |
|
| 6949 |
|
| 6950 |
|
| 6951 |
bool COptimizedComplexExpressionAnsweringHandler::processExtractedInstanceCandidatePossiblePropagations(CAnsweringMessageDataInstancePossiblePropagationsData* instanceCandidatePropagationMessage, CAnswererContext* answererContext) { |
| 6952 |
CConcept* concept = instanceCandidatePropagationMessage->getTestingConcept(); |
| 6953 |
bool negation = instanceCandidatePropagationMessage->getTestingConceptNegation(); |
| 6954 |
COptimizedComplexConceptItem* conceptItem = mOntoAnsweringItem->getComplexConceptItem(concept, negation); |
| 6955 |
CCLASSSUBSUMPTIONMESSAGELIST<CIndividualReference>* indiList = instanceCandidatePropagationMessage->getIndividualReferenceList(); |
| 6956 |
|
| 6957 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 6958 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceCandPropItemSet = conceptItem->getPossibleInstanceCandidatePropagationItemSet(); |
| 6959 |
//mTestedPossibleInstancesCount += possibleInstanceItemSet->size(); |
| 6960 |
//delete possibleInstanceItemSet; |
| 6961 |
//conceptItem->setPossibleInstanceItemSet(nullptr); |
| 6962 |
//conceptItem->incPossibleTestedNonInstanceCount(possibleInstanceItemSet->size()); |
| 6963 |
if (indiList && !indiList->isEmpty()) { |
| 6964 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 6965 |
for (CCLASSSUBSUMPTIONMESSAGELIST<CIndividualReference>::const_iterator it = indiList->constBegin(), itEnd = indiList->constEnd(); it != itEnd; ++it) { |
| 6966 |
CRealizationIndividualInstanceItemReference indiItemRef = sameRealization->getSameInstanceItemReference(*it); |
| 6967 |
if (possibleInstanceCandPropItemSet->contains(indiItemRef)) { |
| 6968 |
possibleInstanceItemSet->insert(indiItemRef); |
| 6969 |
} |
| 6970 |
//mTestedPossibleInstancesCount++; |
| 6971 |
} |
| 6972 |
//conceptItem->incPossibleTestedNonInstanceCount(newPossibleInstanceItemSet->size() - possibleInstanceItemSet->size()); |
| 6973 |
} |
| 6974 |
conceptItem->setCandidateReceived(true); |
| 6975 |
return true; |
| 6976 |
} |
| 6977 |
|
| 6978 |
|
| 6979 |
|
| 6980 |
bool COptimizedComplexExpressionAnsweringHandler::processExtractedInstanceCertainPropagations(CAnsweringMessageDataInstanceCertainPropagationsData* instanceCandidatePropagationMessage, CAnswererContext* answererContext) { |
| 6981 |
|
| 6982 |
CConcreteOntology* testingOnto = mOntoAnsweringItem->getTestingOntology(false); |
| 6983 |
CConcept* concept = instanceCandidatePropagationMessage->getTestingConcept(); |
| 6984 |
bool negation = instanceCandidatePropagationMessage->getTestingConceptNegation(); |
| 6985 |
CConcept* propagatedConcept = instanceCandidatePropagationMessage->getPropagatedConcept(); |
| 6986 |
COptimizedComplexConceptItem* conceptItem = mOntoAnsweringItem->getComplexConceptItem(concept, negation); |
| 6987 |
CCLASSSUBSUMPTIONMESSAGELIST<CIndividualReference>* indiList = instanceCandidatePropagationMessage->getIndividualReferenceList(); |
| 6988 |
|
| 6989 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 6990 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceCandPropItemSet = conceptItem->getPossibleInstanceCandidatePropagationItemSet(); |
| 6991 |
COptimizedComplexConceptInstanziatedIndividualItemHash* directInstanceItems = conceptItem->getKnownInstanceItems(); |
| 6992 |
|
| 6993 |
if (indiList && !indiList->isEmpty()) { |
| 6994 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 6995 |
for (CCLASSSUBSUMPTIONMESSAGELIST<CIndividualReference>::const_iterator it = indiList->constBegin(), itEnd = indiList->constEnd(); it != itEnd; ++it) { |
| 6996 |
CRealizationIndividualInstanceItemReference indiItemRef = sameRealization->getSameInstanceItemReference(*it); |
| 6997 |
//mTestedPossibleInstancesCount++; |
| 6998 |
if (possibleInstanceCandPropItemSet->contains(indiItemRef)) { |
| 6999 |
directInstanceItems->addRealizationIndividualInstanceItemReference(indiItemRef); |
| 7000 |
} |
| 7001 |
} |
| 7002 |
} |
| 7003 |
return true; |
| 7004 |
} |
| 7005 |
|
| 7006 |
|
| 7007 |
|
| 7008 |
|
| 7009 |
|
| 7010 |
|
| 7011 |
bool COptimizedComplexExpressionAnsweringHandler::visitAllIndividuals(function<bool(const CIndividualReference& indiRef)> visitFunc) { |
| 7012 |
|
| 7013 |
CConcreteOntology* ontology = mOntoAnsweringItem->getOntology(); |
| 7014 |
|
| 7015 |
CBOXSET<CIndividual*>* activeIndiSet = ontology->getABox()->getActiveIndividualSet(); |
| 7016 |
CIndividualVector* indiVec = ontology->getABox()->getIndividualVector(false); |
| 7017 |
cint64 indiCount = 0; |
| 7018 |
if (indiVec) { |
| 7019 |
indiCount = indiVec->getItemCount(); |
| 7020 |
} |
| 7021 |
|
| 7022 |
bool visited = false; |
| 7023 |
bool continueVisiting = true; |
| 7024 |
cint64 maxTriplesIndexedIndiId = 0; |
| 7025 |
COntologyTriplesAssertionsAccessor* triplesAccessor = ontology->getOntologyTriplesData()->getTripleAssertionAccessor(); |
| 7026 |
if (triplesAccessor) { |
| 7027 |
maxTriplesIndexedIndiId = ontology->getOntologyTriplesData()->getTripleAssertionAccessor()->getMaxIndexedIndividualId(); |
| 7028 |
} |
| 7029 |
if (indiVec) { |
| 7030 |
cint64 indiCount = indiVec->getItemCount(); |
| 7031 |
for (cint64 idx = 0; idx < indiCount && continueVisiting; ++idx) { |
| 7032 |
CIndividual* indi = indiVec->getData(idx); |
| 7033 |
|
| 7034 |
CIndividualReference indiRef; |
| 7035 |
if (indi && activeIndiSet->contains(indi)) { |
| 7036 |
indiRef = CIndividualReference(indi); |
| 7037 |
visited = true; |
| 7038 |
} else if (idx <= maxTriplesIndexedIndiId) { |
| 7039 |
visited = true; |
| 7040 |
indiRef = CIndividualReference(idx); |
| 7041 |
} |
| 7042 |
continueVisiting = visitFunc(indiRef); |
| 7043 |
|
| 7044 |
} |
| 7045 |
} |
| 7046 |
return visited; |
| 7047 |
} |
| 7048 |
|
| 7049 |
|
| 7050 |
|
| 7051 |
|
| 7052 |
|
| 7053 |
bool COptimizedComplexExpressionAnsweringHandler::createAbsorbedQueryPartEntailmentTest(COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHanldingQueryPart, CComplexQueryExpressionProcessingData* procData, CAnswererContext* answererContext) { |
| 7054 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 7055 |
CExpressionVariable* initializerVariable = absorptionHanldingQueryPart->getInitializerVariableExpression(); |
| 7056 |
CVariable* variable = absorptionHanldingQueryPart->getVariableExpressionVariableHash()->value(initializerVariable); |
| 7057 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 7058 |
|
| 7059 |
CConcept* restrictedTopPropConcept = nullptr; |
| 7060 |
bool splitting = false; |
| 7061 |
if (!splitting && mConfQueryEntailmentTestRestrictedTopPropertyPropagationSplitting && mConfMaxVariableBindingPropagationsInitializationIndividualCount > 0 && absorptionHanldingQueryPart->isTopObjectPropertyInitializationPropagation()) { |
| 7062 |
restrictedTopPropConcept = getAbsorbExistentialQueryPartRestrictedTopPropagationConcept(absorptionHanldingQueryPart, answererContext); |
| 7063 |
splitting = true; |
| 7064 |
} |
| 7065 |
|
| 7066 |
if (!splitting) { |
| 7067 |
splitting = !absorptionHanldingQueryPart->isTopObjectPropertyUsed() && mConfMaxVariableBindingPropagationsInitializationIndividualCount > 0; |
| 7068 |
} |
| 7069 |
|
| 7070 |
if (!splitting) { |
| 7071 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, absorptionHanldingQueryPart->isTopObjectPropertyUsed(), answererContext); |
| 7072 |
|
| 7073 |
procData->incEntailmentComputation(); |
| 7074 |
visitAllIndividuals([&](const CIndividualReference& indiRef)->bool { |
| 7075 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(absorptionHanldingQueryPart->getInitializerConcept(), false, indiRef, satCalcJob); |
| 7076 |
return true; |
| 7077 |
}); |
| 7078 |
|
| 7079 |
CAnsweringPropagationSteeringAbsorptionEntailmentController* propagationSteeringController = new CAnsweringPropagationSteeringAbsorptionEntailmentController(restrictedTopPropConcept); |
| 7080 |
CAnsweringMessageDataCalculationCompletedVariableBindingEntailment* completedMessage = new CAnsweringMessageDataCalculationCompletedVariableBindingEntailment(satCalcJob, nullptr, absorptionHanldingQueryPart, procData, nullptr, nullptr); |
| 7081 |
satCalcJob->setSatisfiableAnswererBindingPropagationAdapter(new CSatisfiableTaskAnswererBindingPropagationAdapter(absorptionHanldingQueryPart->getInitializerConcept(), absorptionHanldingQueryPart->getPropagationFinalizationConcept(), this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler(), propagationSteeringController)); |
| 7082 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incExistentialQueryPartEntailmentTestingCount(); |
| 7083 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 7084 |
} else { |
| 7085 |
|
| 7086 |
// TODO: make sure that the absorption does not create a propagation over top object property/role such that all individuals have to be expanded |
| 7087 |
CAnsweringSplitEntailmentTestingCancellationAdapter* cancelAdapter = new CAnsweringSplitEntailmentTestingCancellationAdapter(); |
| 7088 |
cint64 currentCount = 0; |
| 7089 |
cint64 totalCount = 0; |
| 7090 |
visitAllIndividuals([&](const CIndividualReference& indiRef)->bool { |
| 7091 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(absorptionHanldingQueryPart->getInitializerConcept(), false, indiRef, satCalcJob); |
| 7092 |
totalCount++; |
| 7093 |
if (++currentCount >= mConfMaxVariableBindingPropagationsInitializationIndividualCount) { |
| 7094 |
currentCount = 0; |
| 7095 |
procData->incEntailmentComputation(); |
| 7096 |
CAnsweringPropagationSteeringAbsorptionEntailmentController* propagationSteeringController = new CAnsweringPropagationSteeringAbsorptionEntailmentController(restrictedTopPropConcept); |
| 7097 |
CAnsweringMessageDataCalculationCompletedVariableBindingEntailment* completedMessage = new CAnsweringMessageDataCalculationCompletedVariableBindingEntailment(satCalcJob, nullptr, absorptionHanldingQueryPart, procData, nullptr, cancelAdapter); |
| 7098 |
satCalcJob->setSatisfiableAnswererBindingPropagationAdapter(new CSatisfiableTaskAnswererBindingPropagationAdapter(absorptionHanldingQueryPart->getInitializerConcept(), absorptionHanldingQueryPart->getPropagationFinalizationConcept(), this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler(), propagationSteeringController)); |
| 7099 |
satCalcJob->setCancellationAdapter(cancelAdapter->incCurrentEntailmentTestingCount()); |
| 7100 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incExistentialQueryPartEntailmentTestingCount(); |
| 7101 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 7102 |
|
| 7103 |
} |
| 7104 |
return true; |
| 7105 |
}); |
| 7106 |
|
| 7107 |
if (satCalcJob) { |
| 7108 |
procData->incEntailmentComputation(); |
| 7109 |
CAnsweringPropagationSteeringAbsorptionEntailmentController* propagationSteeringController = new CAnsweringPropagationSteeringAbsorptionEntailmentController(restrictedTopPropConcept); |
| 7110 |
CAnsweringMessageDataCalculationCompletedVariableBindingEntailment* completedMessage = new CAnsweringMessageDataCalculationCompletedVariableBindingEntailment(satCalcJob, nullptr, absorptionHanldingQueryPart, procData, nullptr, cancelAdapter); |
| 7111 |
satCalcJob->setCancellationAdapter(cancelAdapter->incCurrentEntailmentTestingCount()); |
| 7112 |
satCalcJob->setSatisfiableAnswererBindingPropagationAdapter(new CSatisfiableTaskAnswererBindingPropagationAdapter(absorptionHanldingQueryPart->getInitializerConcept(), absorptionHanldingQueryPart->getPropagationFinalizationConcept(), this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler(), propagationSteeringController)); |
| 7113 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incExistentialQueryPartEntailmentTestingCount(); |
| 7114 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 7115 |
} |
| 7116 |
|
| 7117 |
if (mConfExtendedLogging) { |
| 7118 |
LOG(INFO, getDomain(), logTr("Scheduled %1 entailment tests for absorbed query part with %2 initialization individuals in average.").arg(cancelAdapter->getCurrentEntailmentTestingCount()).arg(totalCount / cancelAdapter->getCurrentEntailmentTestingCount()), this); |
| 7119 |
} |
| 7120 |
|
| 7121 |
|
| 7122 |
} |
| 7123 |
return true; |
| 7124 |
} |
| 7125 |
|
| 7126 |
|
| 7127 |
|
| 7128 |
|
| 7129 |
|
| 7130 |
|
| 7131 |
|
| 7132 |
bool COptimizedComplexExpressionAnsweringHandler::createVariableBindingConfirmationTest(COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationExtension, COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableIndividualBindingsCardinalityLinker* testingVarIndiBindingCardLinker, CSameRealization* sameRealization, CAnswererContext* answererContext) { |
| 7133 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHanldingQueryPart = absorptionPropagationExtension->getAbsorptionBasedHandlingData(); |
| 7134 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 7135 |
buildingVarItem->incVariableBindingsConfirmationCount(); |
| 7136 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 7137 |
|
| 7138 |
CVariable* initializingVariable = absorptionHanldingQueryPart->getVariableExpressionVariableHash()->value(absorptionHanldingQueryPart->getInitializerVariableExpression()); |
| 7139 |
CRealizationIndividualInstanceItemReference instanceItemRef = testingVarIndiBindingCardLinker->getBindings()->getBinding(absorptionPropagationExtension->getVariableIndexHash()->value(initializingVariable)).reference; |
| 7140 |
QList<CIndividualReference> sameIndiList; |
| 7141 |
CInstanceBindingIndividualCollectionVisitor visitor(&sameIndiList); |
| 7142 |
sameRealization->visitSameIndividuals(instanceItemRef, &visitor); |
| 7143 |
CIndividualReference individualRef = sameIndiList.first(); |
| 7144 |
|
| 7145 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, absorptionHanldingQueryPart->isTopObjectPropertyUsed(), answererContext); |
| 7146 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(absorptionHanldingQueryPart->getInitializerConcept(), false, individualRef, satCalcJob); |
| 7147 |
CAnsweringMessageDataCalculationCompletedVariableBindingConfirmation* completedMessage = new CAnsweringMessageDataCalculationCompletedVariableBindingConfirmation(satCalcJob, absorptionPropagationExtension, buildingVarItem, testingVarIndiBindingCardLinker); |
| 7148 |
CAnsweringPropagationSteeringAbsorptionExtensionItemBindingController* propagationSteeringController = new CAnsweringPropagationSteeringAbsorptionExtensionItemBindingController(absorptionPropagationExtension, *testingVarIndiBindingCardLinker->getBindings(), sameRealization); |
| 7149 |
satCalcJob->setSatisfiableAnswererBindingPropagationAdapter(new CSatisfiableTaskAnswererBindingPropagationAdapter(absorptionHanldingQueryPart->getInitializerConcept(), absorptionHanldingQueryPart->getPropagationFinalizationConcept(), this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler(), propagationSteeringController)); |
| 7150 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incExistentialQueryPartVariableBindingConfirmationCount(); |
| 7151 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 7152 |
return true; |
| 7153 |
} |
| 7154 |
|
| 7155 |
|
| 7156 |
|
| 7157 |
|
| 7158 |
|
| 7159 |
|
| 7160 |
|
| 7161 |
bool COptimizedComplexExpressionAnsweringHandler::continueCalculationJobFromNondeterministicCachedGraph(CSatisfiableCalculationJob* satCalcJob, CAnswererContext* answererContext) { |
| 7162 |
if (mConfNonDeterministicSatisfiableCalculationContinuation) { |
| 7163 |
satCalcJob->setAllowNonDeterministicSatisfiableCalculationContinuation(true); |
| 7164 |
return true; |
| 7165 |
} |
| 7166 |
return false; |
| 7167 |
} |
| 7168 |
|
| 7169 |
|
| 7170 |
|
| 7171 |
bool COptimizedComplexExpressionAnsweringHandler::createAbsorbedQueryPartEntailmentTest(COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationExtension, COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CAnswererContext* answererContext, bool &continueProcessingBuildingVarItem) { |
| 7172 |
|
| 7173 |
CComplexQueryExpressionProcessingData* queryProcData = buildingVarItem->getQueryProcessingData(); |
| 7174 |
if (absorptionPropagationExtension->isEntailmentFound()) { |
| 7175 |
queryProcData->decBuildingVariableItem(); |
| 7176 |
absorptionPropagationExtension->setPropagationInitializationIndividualsSplittedTestsRemaining(false); |
| 7177 |
if (!queryProcData->hasComputation() && !absorptionPropagationExtension->hasRemainingPropagationInitializationIndividualsSplittedTests()) { |
| 7178 |
finishQueryProcessing(queryProcData); |
| 7179 |
} |
| 7180 |
return false; |
| 7181 |
} |
| 7182 |
|
| 7183 |
|
| 7184 |
buildingVarItem->getQueryProcessingData()->incEntailmentComputation(); |
| 7185 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHanldingQueryPart = absorptionPropagationExtension->getAbsorptionBasedHandlingData(); |
| 7186 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 7187 |
|
| 7188 |
|
| 7189 |
|
| 7190 |
buildingVarItem->incVariableBindingsPropagationCount(); |
| 7191 |
CExpressionVariable* initializerVariable = absorptionHanldingQueryPart->getInitializerVariableExpression(); |
| 7192 |
if (!absorptionHanldingQueryPart->getPrepareVariableSet()->contains(initializerVariable)) { |
| 7193 |
initializerVariable = *absorptionHanldingQueryPart->getPrepareVariableSet()->begin(); |
| 7194 |
} |
| 7195 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 7196 |
CVariable* variable = absorptionHanldingQueryPart->getVariableExpressionVariableHash()->value(initializerVariable); |
| 7197 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, absorptionHanldingQueryPart->isTopObjectPropertyUsed(), answererContext); |
| 7198 |
QSet<CIndividualReference>* indiSet = absorptionPropagationExtension->getVariableSteeringIndividualBindingSet(variable); |
| 7199 |
|
| 7200 |
QSet<CIndividualReference>* splitIndiSet = nullptr; |
| 7201 |
if (!absorptionHanldingQueryPart->isTopObjectPropertyUsed() && (absorptionPropagationExtension->isPropagationInitializationIndividualsSplitted() || indiSet->size() > mConfMaxVariableBindingPropagationsInitializationIndividualCount && mConfMaxVariableBindingPropagationsInitializationIndividualCount > 0)) { |
| 7202 |
splitIndiSet = new QSet<CIndividualReference>(); |
| 7203 |
absorptionPropagationExtension->setPropagationInitializationIndividualsSplitted(true); |
| 7204 |
} |
| 7205 |
for (QSet<CIndividualReference>::iterator it = indiSet->begin(); it != indiSet->end() && (mConfMaxVariableBindingPropagationsInitializationIndividualCount < 0 || !splitIndiSet || splitIndiSet->size() < mConfMaxVariableBindingPropagationsInitializationIndividualCount); ) { |
| 7206 |
CIndividualReference individual(*it); |
| 7207 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(absorptionHanldingQueryPart->getInitializerConcept(), false, individual, satCalcJob); |
| 7208 |
if (splitIndiSet) { |
| 7209 |
splitIndiSet->insert(individual); |
| 7210 |
it = indiSet->erase(it); |
| 7211 |
} else { |
| 7212 |
++it; |
| 7213 |
} |
| 7214 |
} |
| 7215 |
if (splitIndiSet) { |
| 7216 |
if (mConfExtendedLogging) { |
| 7217 |
LOG(INFO, getDomain(), logTr("%1. entailment test for absorbed query part based on %2 bindings scheduled.").arg(absorptionPropagationExtension->getNextPropagationInitializationIndividualsSplittedTestId()).arg(splitIndiSet->size()), this); |
| 7218 |
} |
| 7219 |
if (!indiSet->isEmpty()) { |
| 7220 |
// put into queue such that remaining propagation tests are scheduled at some point |
| 7221 |
if (!absorptionPropagationExtension->isSplitPropagationItemProcessingQueued()) { |
| 7222 |
buildingVarItem->addAbsorptionBasedHandlingExtensionPropagationItem(absorptionPropagationExtension); |
| 7223 |
absorptionPropagationExtension->setSplitPropagationItemProcessingQueued(true); |
| 7224 |
} |
| 7225 |
absorptionPropagationExtension->setPropagationInitializationIndividualsSplittedTestsRemaining(true); |
| 7226 |
continueProcessingBuildingVarItem = true; |
| 7227 |
} else { |
| 7228 |
queryProcData->decBuildingVariableItem(); |
| 7229 |
absorptionPropagationExtension->setPropagationInitializationIndividualsSplittedTestsRemaining(false); |
| 7230 |
} |
| 7231 |
} |
| 7232 |
|
| 7233 |
|
| 7234 |
|
| 7235 |
CAnsweringPropagationSteeringAbsorptionExtensionItemController* propagationSteeringController = new CAnsweringPropagationSteeringAbsorptionExtensionItemController(absorptionPropagationExtension, variable, splitIndiSet); |
| 7236 |
CAnsweringSplitEntailmentTestingCancellationAdapter* cancelAdapter = nullptr; |
| 7237 |
if (splitIndiSet) { |
| 7238 |
cancelAdapter = absorptionPropagationExtension->getEntailmentTestingCancellationAdapter(); |
| 7239 |
cancelAdapter->incCurrentEntailmentTestingCount(); |
| 7240 |
satCalcJob->setCancellationAdapter(cancelAdapter); |
| 7241 |
} |
| 7242 |
absorptionPropagationExtension->addPropagationSteeringController(propagationSteeringController); |
| 7243 |
CAnsweringMessageDataCalculationCompletedVariableBindingEntailment* completedMessage = new CAnsweringMessageDataCalculationCompletedVariableBindingEntailment(satCalcJob, propagationSteeringController, absorptionHanldingQueryPart, buildingVarItem->getQueryProcessingData(), absorptionPropagationExtension, cancelAdapter); |
| 7244 |
satCalcJob->setSatisfiableAnswererBindingPropagationAdapter(new CSatisfiableTaskAnswererBindingPropagationAdapter(absorptionHanldingQueryPart->getInitializerConcept(), absorptionHanldingQueryPart->getPropagationFinalizationConcept(), this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler(), propagationSteeringController)); |
| 7245 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incExistentialQueryPartEntailmentTestingCount(); |
| 7246 |
if (!absorptionHanldingQueryPart->hasNonTrivialAbsorptionPropagation()) { |
| 7247 |
continueCalculationJobFromNondeterministicCachedGraph(satCalcJob, answererContext); |
| 7248 |
} |
| 7249 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 7250 |
return true; |
| 7251 |
} |
| 7252 |
|
| 7253 |
|
| 7254 |
|
| 7255 |
|
| 7256 |
bool COptimizedComplexExpressionAnsweringHandler::processVariableBindingsEntailmentCalculationCompleted(CAnsweringMessageDataCalculationCompletedVariableBindingEntailment* message, CAnswererContext* answererContext) { |
| 7257 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorbedQueryPartData = message->getAbsorbedQueryPartData(); |
| 7258 |
CComplexQueryExpressionProcessingData* queryProcData = message->getQueryProcessingData(); |
| 7259 |
COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationExtension = message->getAbsorptionPropagationExtension(); |
| 7260 |
CAnsweringPropagationSteeringAbsorptionExtensionItemController* propagationSteeringController = message->getPropagationSteeringController(); |
| 7261 |
CAnsweringSplitEntailmentTestingCancellationAdapter* cancelAdapter = message->getCancellationAdapter(); |
| 7262 |
|
| 7263 |
if (cancelAdapter) { |
| 7264 |
cancelAdapter->decCurrentEntailmentTestingCount(); |
| 7265 |
} |
| 7266 |
if (cancelAdapter && !message->isSatisfiable()) { |
| 7267 |
cancelAdapter->setEntailmentFound(); |
| 7268 |
} |
| 7269 |
|
| 7270 |
if (!absorptionPropagationExtension && message->isSatisfiable()) { |
| 7271 |
queryProcData->setUnsatisfiable(true); |
| 7272 |
} |
| 7273 |
if (absorptionPropagationExtension && !message->isSatisfiable()) { |
| 7274 |
absorptionPropagationExtension->setEntailmentFound(true); |
| 7275 |
} |
| 7276 |
if (absorptionPropagationExtension) { |
| 7277 |
absorptionPropagationExtension->removePropagationSteeringController(propagationSteeringController); |
| 7278 |
} |
| 7279 |
if (propagationSteeringController) { |
| 7280 |
delete propagationSteeringController; |
| 7281 |
} |
| 7282 |
|
| 7283 |
queryProcData->decEntailmentComputation(); |
| 7284 |
if (!absorptionPropagationExtension && !cancelAdapter || absorptionPropagationExtension && !absorptionPropagationExtension->hasRemainingPropagationInitializationIndividualsSplittedTests() || cancelAdapter->getCurrentEntailmentTestingCount() == 0) { |
| 7285 |
if (!queryProcData->hasComputation()) { |
| 7286 |
if (absorptionPropagationExtension && !absorptionPropagationExtension->isEntailmentFound()) { |
| 7287 |
queryProcData->setUnsatisfiable(true); |
| 7288 |
} |
| 7289 |
if (cancelAdapter && !cancelAdapter->hasEntailmentFound()) { |
| 7290 |
queryProcData->setUnsatisfiable(true); |
| 7291 |
} |
| 7292 |
finishQueryProcessing(queryProcData); |
| 7293 |
} |
| 7294 |
} |
| 7295 |
return true; |
| 7296 |
} |
| 7297 |
|
| 7298 |
|
| 7299 |
|
| 7300 |
|
| 7301 |
|
| 7302 |
|
| 7303 |
|
| 7304 |
|
| 7305 |
|
| 7306 |
|
| 7307 |
bool COptimizedComplexExpressionAnsweringHandler::createVariableBindingPropagationTest(COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationExtension, COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CAnswererContext* answererContext, bool &continueProcessingBuildingVarItem) { |
| 7308 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHanldingQueryPart = absorptionPropagationExtension->getAbsorptionBasedHandlingData(); |
| 7309 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 7310 |
buildingVarItem->incVariableBindingsPropagationCount(); |
| 7311 |
CExpressionVariable* initializerVariable = absorptionHanldingQueryPart->getInitializerVariableExpression(); |
| 7312 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 7313 |
CVariable* variable = absorptionHanldingQueryPart->getVariableExpressionVariableHash()->value(initializerVariable); |
| 7314 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, absorptionHanldingQueryPart->isTopObjectPropertyUsed(), answererContext); |
| 7315 |
|
| 7316 |
|
| 7317 |
QSet<CIndividualReference>* splitIndiSet = nullptr; |
| 7318 |
CAnsweringSplitPropagationTestControllingItem* repSlitTestContItem = nullptr; |
| 7319 |
QList<CAnsweringSplitPropagationTestControllingItem*>* remainingRepeatedSplitTestingItemList = absorptionPropagationExtension->getRemainingRepeatedSplitTestingItemList(); |
| 7320 |
bool remainingTests = false; |
| 7321 |
if (!remainingRepeatedSplitTestingItemList->isEmpty()) { |
| 7322 |
repSlitTestContItem = remainingRepeatedSplitTestingItemList->takeFirst(); |
| 7323 |
repSlitTestContItem->getBaseVariableData()->visitIntegrateableVariableBindings([&](const CIndividualReference& indiRef)->bool { |
| 7324 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(absorptionHanldingQueryPart->getInitializerConcept(), false, indiRef, satCalcJob); |
| 7325 |
return true; |
| 7326 |
}); |
| 7327 |
if (!remainingRepeatedSplitTestingItemList->isEmpty()) { |
| 7328 |
remainingTests = true; |
| 7329 |
} |
| 7330 |
|
| 7331 |
if (absorptionPropagationExtension->hasPreparedSplitPropagationTestControllingItems()) { |
| 7332 |
if (absorptionPropagationExtension->hasRemainingPreparedSplitPropagationTestControllingItems()) { |
| 7333 |
remainingTests = true; |
| 7334 |
} |
| 7335 |
} else { |
| 7336 |
QSet<CIndividualReference>* indiSet = absorptionPropagationExtension->getVariableSteeringIndividualBindingSet(variable); |
| 7337 |
if (!indiSet->isEmpty()) { |
| 7338 |
remainingTests = true; |
| 7339 |
} |
| 7340 |
} |
| 7341 |
} else { |
| 7342 |
bool splitting = false; |
| 7343 |
QSet<CIndividualReference>* indiSet = absorptionPropagationExtension->getVariableSteeringIndividualBindingSet(variable); |
| 7344 |
if (!absorptionHanldingQueryPart->isTopObjectPropertyUsed() && absorptionPropagationExtension->isPropagationInitializationIndividualsSplitted() || indiSet->size() > mConfMaxVariableBindingPropagationsInitializationIndividualCount && mConfMaxVariableBindingPropagationsInitializationIndividualCount > 0) { |
| 7345 |
splitting = true; |
| 7346 |
} |
| 7347 |
|
| 7348 |
if (splitting && absorptionPropagationExtension->hasPreparedSplitPropagationTestControllingItems()) { |
| 7349 |
CAnsweringSplitPropagationTestControllingItem* nextPrepSplitItem = absorptionPropagationExtension->getNextPreparedSplitPropagationTestControllingItem(); |
| 7350 |
|
| 7351 |
if (nextPrepSplitItem) { |
| 7352 |
CVariable* baseVar = nextPrepSplitItem->getBaseVariableData()->getVariable(); |
| 7353 |
cint64 newTotalLimit = nextPrepSplitItem->getIntendedIntegrationLimit(); |
| 7354 |
for (CExpressionVariable* preparedVarExp : *absorptionHanldingQueryPart->getPrepareVariableSet()) { |
| 7355 |
CVariable* prepVar = absorptionHanldingQueryPart->getVariableExpressionVariableHash()->value(preparedVarExp); |
| 7356 |
if (prepVar && prepVar != baseVar) { |
| 7357 |
CAnsweringSplitPropagationTestingVariableData* perpVarData = nextPrepSplitItem->getVariableData(prepVar); |
| 7358 |
if (!perpVarData || perpVarData->getIntegrateableVariableBindingCount() <= 0) { |
| 7359 |
|
| 7360 |
QSet<CIndividualReference>* bindIndiSet = absorptionPropagationExtension->getVariableSteeringIndividualBindingSet(prepVar); |
| 7361 |
if (!perpVarData) { |
| 7362 |
perpVarData = new CAnsweringSplitPropagationTestingVariableData(nextPrepSplitItem->getNextVariableDataId(), prepVar, preparedVarExp, bindIndiSet); |
| 7363 |
nextPrepSplitItem->addVariableData(perpVarData, false); |
| 7364 |
perpVarData->setVariableBindingsIntegrationLimit(mConfSplitVariableMappingPropagationTestInitialVariableIntegrationLimit); |
| 7365 |
} else { |
| 7366 |
perpVarData->addIntegrateableVariableBindings(bindIndiSet); |
| 7367 |
} |
| 7368 |
newTotalLimit += mConfSplitVariableMappingPropagationTestInitialVariableIntegrationLimit; |
| 7369 |
} |
| 7370 |
} |
| 7371 |
} |
| 7372 |
nextPrepSplitItem->setIntegrationLimit(newTotalLimit); |
| 7373 |
|
| 7374 |
splitIndiSet = nextPrepSplitItem->getBaseVariableData()->getVariableBindingIndividualSet(); |
| 7375 |
repSlitTestContItem = nextPrepSplitItem; |
| 7376 |
|
| 7377 |
nextPrepSplitItem->getBaseVariableData()->visitIntegrateableVariableBindings([&](const CIndividualReference& indiRef)->bool { |
| 7378 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(absorptionHanldingQueryPart->getInitializerConcept(), false, indiRef, satCalcJob); |
| 7379 |
return true; |
| 7380 |
}); |
| 7381 |
} |
| 7382 |
|
| 7383 |
if (absorptionPropagationExtension->hasRemainingPreparedSplitPropagationTestControllingItems()) { |
| 7384 |
remainingTests = true; |
| 7385 |
} |
| 7386 |
|
| 7387 |
} else { |
| 7388 |
if (splitting) { |
| 7389 |
splitIndiSet = new QSet<CIndividualReference>(); |
| 7390 |
absorptionPropagationExtension->setPropagationInitializationIndividualsSplitted(true); |
| 7391 |
} |
| 7392 |
for (QSet<CIndividualReference>::iterator it = indiSet->begin(); it != indiSet->end() && (mConfMaxVariableBindingPropagationsInitializationIndividualCount < 0 || !splitIndiSet || splitIndiSet->size() < mConfMaxVariableBindingPropagationsInitializationIndividualCount); ) { |
| 7393 |
CIndividualReference indiRef(*it); |
| 7394 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(absorptionHanldingQueryPart->getInitializerConcept(), false, indiRef, satCalcJob); |
| 7395 |
if (splitIndiSet) { |
| 7396 |
splitIndiSet->insert(indiRef); |
| 7397 |
it = indiSet->erase(it); |
| 7398 |
} else { |
| 7399 |
++it; |
| 7400 |
} |
| 7401 |
} |
| 7402 |
if (splitIndiSet) { |
| 7403 |
if (!indiSet->isEmpty()) { |
| 7404 |
remainingTests = true; |
| 7405 |
} |
| 7406 |
} |
| 7407 |
} |
| 7408 |
} |
| 7409 |
if (remainingTests) { |
| 7410 |
// put into queue such that remaining propagation tests are scheduled at some point |
| 7411 |
if (!absorptionPropagationExtension->isSplitPropagationItemProcessingQueued()) { |
| 7412 |
buildingVarItem->addAbsorptionBasedHandlingExtensionPropagationItem(absorptionPropagationExtension); |
| 7413 |
absorptionPropagationExtension->setSplitPropagationItemProcessingQueued(true); |
| 7414 |
} |
| 7415 |
absorptionPropagationExtension->setPropagationInitializationIndividualsSplittedTestsRemaining(true); |
| 7416 |
continueProcessingBuildingVarItem = true; |
| 7417 |
} else { |
| 7418 |
absorptionPropagationExtension->setPropagationInitializationIndividualsSplittedTestsRemaining(false); |
| 7419 |
} |
| 7420 |
|
| 7421 |
|
| 7422 |
CAnsweringPropagationSteeringController* propagationSteeringController = nullptr; |
| 7423 |
if (splitIndiSet || repSlitTestContItem) { |
| 7424 |
if (repSlitTestContItem) { |
| 7425 |
propagationSteeringController = repSlitTestContItem; |
| 7426 |
} else { |
| 7427 |
repSlitTestContItem = createSplitPropagationTestControllingItem(absorptionPropagationExtension, absorptionHanldingQueryPart, splitIndiSet); |
| 7428 |
propagationSteeringController = repSlitTestContItem; |
| 7429 |
} |
| 7430 |
if (mConfExtendedLogging) { |
| 7431 |
LOG(INFO, getDomain(), logTr("%2. marker propagation test for split %1 of absorbed query part based on %3 bindings scheduled.").arg(repSlitTestContItem->getTestingItemId()).arg(repSlitTestContItem->getNextTestingId() + 1).arg(repSlitTestContItem->getBaseVariableData()->getIntegrateableVariableBindingCount()), this); |
| 7432 |
} |
| 7433 |
} else { |
| 7434 |
propagationSteeringController = new CAnsweringPropagationSteeringAbsorptionExtensionItemController(absorptionPropagationExtension, variable); |
| 7435 |
} |
| 7436 |
absorptionPropagationExtension->addPropagationSteeringController(propagationSteeringController); |
| 7437 |
CAnsweringMessageDataCalculationCompletedVariableBindingPropagations* completedMessage = new CAnsweringMessageDataCalculationCompletedVariableBindingPropagations(satCalcJob, propagationSteeringController, absorptionPropagationExtension, buildingVarItem); |
| 7438 |
satCalcJob->setSatisfiableAnswererBindingPropagationAdapter(new CSatisfiableTaskAnswererBindingPropagationAdapter(absorptionHanldingQueryPart->getInitializerConcept(), absorptionHanldingQueryPart->getPropagationFinalizationConcept(), this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler(), propagationSteeringController)); |
| 7439 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incExistentialQueryPartVariableBindingPropagationCount(); |
| 7440 |
if (!absorptionHanldingQueryPart->hasNonTrivialAbsorptionPropagation()) { |
| 7441 |
continueCalculationJobFromNondeterministicCachedGraph(satCalcJob, answererContext); |
| 7442 |
} |
| 7443 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 7444 |
return true; |
| 7445 |
} |
| 7446 |
|
| 7447 |
|
| 7448 |
|
| 7449 |
|
| 7450 |
|
| 7451 |
|
| 7452 |
|
| 7453 |
|
| 7454 |
|
| 7455 |
CAnsweringSplitPropagationTestControllingItem* COptimizedComplexExpressionAnsweringHandler::createSplitPropagationTestControllingItem(COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationExtension, COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHanldingQueryPart, QSet<CIndividualReference>* splitIndiSet, bool initializeBindingSets) { |
| 7456 |
CAnsweringSplitPropagationTestControllingItem* splitTestingItem = absorptionPropagationExtension->getNextSplitPropagationTestControllingItem(); |
| 7457 |
cint64 varDataId = 0; |
| 7458 |
CExpressionVariable* baseVarExp = absorptionHanldingQueryPart->getInitializerVariableExpression(); |
| 7459 |
CVariable* baseVar = absorptionHanldingQueryPart->getVariableExpressionVariableHash()->value(baseVarExp); |
| 7460 |
CAnsweringSplitPropagationTestingVariableData* baseVarData = new CAnsweringSplitPropagationTestingVariableData(varDataId, baseVar, baseVarExp, splitIndiSet); |
| 7461 |
splitTestingItem->addVariableData(baseVarData, true); |
| 7462 |
cint64 totalLimit = mConfSplitVariableMappingPropagationTestInitialTotalIntegrationLimit; |
| 7463 |
for (CExpressionVariable* preparedVarExp : *absorptionHanldingQueryPart->getPrepareVariableSet()) { |
| 7464 |
CVariable* prepVar = absorptionHanldingQueryPart->getVariableExpressionVariableHash()->value(preparedVarExp); |
| 7465 |
if (prepVar && prepVar != baseVar) { |
| 7466 |
QSet<CIndividualReference>* bindIndiSet = nullptr; |
| 7467 |
if (initializeBindingSets) { |
| 7468 |
bindIndiSet = absorptionPropagationExtension->getVariableSteeringIndividualBindingSet(prepVar); |
| 7469 |
} |
| 7470 |
CAnsweringSplitPropagationTestingVariableData* perpVarData = new CAnsweringSplitPropagationTestingVariableData(varDataId, prepVar, preparedVarExp, bindIndiSet); |
| 7471 |
splitTestingItem->addVariableData(perpVarData, false); |
| 7472 |
perpVarData->setVariableBindingsIntegrationLimit(mConfSplitVariableMappingPropagationTestInitialVariableIntegrationLimit); |
| 7473 |
totalLimit += mConfSplitVariableMappingPropagationTestInitialVariableIntegrationLimit; |
| 7474 |
} |
| 7475 |
} |
| 7476 |
splitTestingItem->setIntegrationLimit(totalLimit); |
| 7477 |
return splitTestingItem; |
| 7478 |
} |
| 7479 |
|
| 7480 |
|
| 7481 |
|
| 7482 |
bool COptimizedComplexExpressionAnsweringHandler::processVariableBindingsPropagationItemCalculationCompleted(CAnsweringMessageDataCalculationCompletedVariableBindingPropagations* message, bool computationError, CAnswererContext* answererContext) { |
| 7483 |
COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationItem = message->getAbsorptionPropagationItem(); |
| 7484 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildVarItem = message->getVariableBuildingItem(); |
| 7485 |
CAnsweringPropagationSteeringController* propagationSteeringController = message->getPropagationSteeringController(); |
| 7486 |
absorptionPropagationItem->removePropagationSteeringController(propagationSteeringController); |
| 7487 |
if (propagationSteeringController) { |
| 7488 |
CAnsweringSplitPropagationTestControllingItem* splitPropTestContItem = dynamic_cast<CAnsweringSplitPropagationTestControllingItem*>(propagationSteeringController); |
| 7489 |
if (splitPropTestContItem) { |
| 7490 |
cint64 intLimit = splitPropTestContItem->getIntendedIntegrationLimit(); |
| 7491 |
cint64 newIntLimit = qMax(intLimit * mConfSplitVariableMappingPropagationTestIntegrationLimitIncreaseFactor, mConfSplitVariableMappingPropagationTestMaxIntegrationLimit); |
| 7492 |
splitPropTestContItem->reconfigureVariableIntegrationLimits(newIntLimit); |
| 7493 |
splitPropTestContItem->disableCheckedVariableIntegrations(); |
| 7494 |
if (!splitPropTestContItem->hasCheckedAllVariableIntegrations()) { |
| 7495 |
absorptionPropagationItem->addRemainingRepeatedSplitTestingItem(splitPropTestContItem); |
| 7496 |
|
| 7497 |
if (!absorptionPropagationItem->isSplitPropagationItemProcessingQueued()) { |
| 7498 |
buildVarItem->addAbsorptionBasedHandlingExtensionPropagationItem(absorptionPropagationItem); |
| 7499 |
absorptionPropagationItem->setSplitPropagationItemProcessingQueued(true); |
| 7500 |
if (!buildVarItem->isProcessingQueued()) { |
| 7501 |
buildVarItem->setProcessingQueued(true); |
| 7502 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(buildVarItem); |
| 7503 |
} |
| 7504 |
} |
| 7505 |
} |
| 7506 |
} else { |
| 7507 |
delete propagationSteeringController; |
| 7508 |
} |
| 7509 |
} |
| 7510 |
|
| 7511 |
if (computationError) { |
| 7512 |
buildVarItem->getQueryProcessingData()->setComputationError(computationError); |
| 7513 |
} |
| 7514 |
|
| 7515 |
buildVarItem->decVariableBindingsPropagationCount(); |
| 7516 |
|
| 7517 |
if (!absorptionPropagationItem->hasRemainingPropagationInitializationIndividualsSplittedTests()) { |
| 7518 |
if (!absorptionPropagationItem->isVariableMappingsComputed()) { |
| 7519 |
// schedule item processing |
| 7520 |
queueVariableItemComputation(buildVarItem, absorptionPropagationItem); |
| 7521 |
} |
| 7522 |
buildVarItem->setProcessingQueued(true); |
| 7523 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(buildVarItem); |
| 7524 |
} |
| 7525 |
|
| 7526 |
return true; |
| 7527 |
} |
| 7528 |
|
| 7529 |
|
| 7530 |
|
| 7531 |
|
| 7532 |
|
| 7533 |
|
| 7534 |
bool COptimizedComplexExpressionAnsweringHandler::processVariableBindingsConfirmationCalculationCompleted(CAnsweringMessageDataCalculationCompletedVariableBindingConfirmation* message, CAnswererContext* answererContext) { |
| 7535 |
COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationItem = message->getAbsorptionPropagationItem(); |
| 7536 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildVarItem = message->getVariableBuildingItem(); |
| 7537 |
|
| 7538 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* variableBindingCardLinker = message->getPropagatedBindingCardinalityLinker(); |
| 7539 |
|
| 7540 |
QHash<COptimizedComplexVariableIndividualBindingsHasher, COptimizedComplexVariableIndividualBindingsCardinalityLinker*>* testingVariableMapping = absorptionPropagationItem->getTestingVariableMapping(); |
| 7541 |
testingVariableMapping->remove(variableBindingCardLinker); |
| 7542 |
|
| 7543 |
bool variableBindingEntailed = !message->isSatisfiable(); |
| 7544 |
if (variableBindingEntailed) { |
| 7545 |
absorptionPropagationItem->getVariableMapping()->addInsertingBindingsCardinalityLinker(variableBindingCardLinker, true); |
| 7546 |
} |
| 7547 |
|
| 7548 |
buildVarItem->decVariableBindingsConfirmationCount(); |
| 7549 |
|
| 7550 |
COptimizedComplexVariableIndividualMappings* possibleVarIndiBindings = absorptionPropagationItem->getPossibleVariableMapping(); |
| 7551 |
if (!buildVarItem->isProcessingQueued() && possibleVarIndiBindings->getBindingCount() <= 0 && !buildVarItem->isWaitingVariableBindingsConfirmation()) { |
| 7552 |
buildVarItem->setProcessingQueued(true); |
| 7553 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(buildVarItem); |
| 7554 |
} |
| 7555 |
|
| 7556 |
return true; |
| 7557 |
} |
| 7558 |
|
| 7559 |
|
| 7560 |
|
| 7561 |
|
| 7562 |
|
| 7563 |
|
| 7564 |
|
| 7565 |
|
| 7566 |
bool COptimizedComplexExpressionAnsweringHandler::processExtractedVariableBindingPropagations(CAnsweringMessageDataVariableBindingPropagations* variableBindingsPropagationMessage, CAnswererContext* answererContext) { |
| 7567 |
|
| 7568 |
|
| 7569 |
CVARIABLEBINDINGMESSAGELIST<CAnsweringMessageDataVariableBindingPropagationsData*>* individualBindingList = variableBindingsPropagationMessage->getIndividualBindingList(); |
| 7570 |
CVARIABLEBINDINGMESSAGELIST<CVariable*>* variablesList = variableBindingsPropagationMessage->getVariablesList(); |
| 7571 |
|
| 7572 |
CConcept* propagationFinalizationConcept = variableBindingsPropagationMessage->getPropagationFinalizationConcept(); |
| 7573 |
QHash<CConcept*, COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*>* propagationFinalizationConceptAbsorptionDataHash = mOntoAnsweringItem->getPropagationFinalizationConceptAbsorptionDataHash(); |
| 7574 |
QHash<CConcept*, COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem*>* propagationFinalizationConceptAbsorptionItemHash = mOntoAnsweringItem->getPropagationFinalizationConceptAbsorptionItemHash(); |
| 7575 |
|
| 7576 |
|
| 7577 |
COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionItem = propagationFinalizationConceptAbsorptionItemHash->value(propagationFinalizationConcept); |
| 7578 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionData = propagationFinalizationConceptAbsorptionDataHash->value(propagationFinalizationConcept); |
| 7579 |
|
| 7580 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 7581 |
QHash<CVariable*, cint64>* variableIndexHash = absorptionItem->getVariableIndexHash(); |
| 7582 |
COptimizedComplexVariableIndividualMappings* variableMapping = absorptionItem->getVariableMapping(); |
| 7583 |
|
| 7584 |
|
| 7585 |
|
| 7586 |
QHash<CExpressionVariable*, cint64> variablePosHash; |
| 7587 |
cint64 varPosCount = 0; |
| 7588 |
QList<QList<cint64>> variableIndexPosList; |
| 7589 |
for (CVariable* variable : *variablesList) { |
| 7590 |
QList<cint64> indexs = variableIndexHash->values(variable); |
| 7591 |
variableIndexPosList.append(indexs); |
| 7592 |
varPosCount += indexs.size(); |
| 7593 |
} |
| 7594 |
|
| 7595 |
COptimizedComplexVariableIndividualMappings* possibleVariableMapping = absorptionItem->getPossibleVariableMapping(); |
| 7596 |
|
| 7597 |
COptimizedComplexVariableIndividualBindings* propagatedBinding = nullptr; |
| 7598 |
COptimizedComplexVariableIndividualBindingsCardinality* propagatedCardinalites = nullptr; |
| 7599 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* propagatedLinker = nullptr; |
| 7600 |
|
| 7601 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem = nullptr; |
| 7602 |
|
| 7603 |
cint64 count = 0; |
| 7604 |
// first verify that variable binding is valid |
| 7605 |
for (CAnsweringMessageDataVariableBindingPropagationsData* individualBindingData : *individualBindingList) { |
| 7606 |
bool possiblePropagation = individualBindingData->isPossibleBinding(); |
| 7607 |
count++; |
| 7608 |
|
| 7609 |
if (!propagatedBinding) { |
| 7610 |
propagatedBinding = createBindingsForVariableCompositionItems(varPosCount, absorptionItem, buildingVarItem); |
| 7611 |
} |
| 7612 |
|
| 7613 |
cint64 pos = 0; |
| 7614 |
for (QList<cint64> variableIndexPositions : variableIndexPosList) { |
| 7615 |
CIndividualReference indiRef = individualBindingData->getBindingIndividualReference(pos++); |
| 7616 |
for (cint64 variableIndexPos : variableIndexPositions) { |
| 7617 |
if (variableIndexPos >= 0) { |
| 7618 |
CRealizationIndividualInstanceItemReference instanceItemRef = sameRealization->getSameInstanceItemReference(indiRef); |
| 7619 |
propagatedBinding->setBinding(variableIndexPos, instanceItemRef); |
| 7620 |
} |
| 7621 |
} |
| 7622 |
} |
| 7623 |
|
| 7624 |
if (!propagatedLinker) { |
| 7625 |
propagatedLinker = createBindingsLinkerForVariableCompositionItems(propagatedBinding, nullptr, absorptionItem, buildingVarItem); |
| 7626 |
} else { |
| 7627 |
propagatedLinker->updateCardinality(propagatedCardinalites); |
| 7628 |
} |
| 7629 |
|
| 7630 |
|
| 7631 |
if (!possiblePropagation) { |
| 7632 |
if (variableMapping->addInsertingBindingsCardinalityLinker(propagatedLinker, true)) { |
| 7633 |
propagatedBinding = nullptr; |
| 7634 |
propagatedLinker = nullptr; |
| 7635 |
propagatedCardinalites = nullptr; |
| 7636 |
} else { |
| 7637 |
propagatedCardinalites = propagatedLinker->getCurrentCardinalities(); |
| 7638 |
} |
| 7639 |
|
| 7640 |
} else { |
| 7641 |
if (!possibleVariableMapping) { |
| 7642 |
possibleVariableMapping = new COptimizedComplexVariableIndividualMappingsHash(variablesList->size()); |
| 7643 |
absorptionItem->setPossibleVariableMapping(possibleVariableMapping); |
| 7644 |
} |
| 7645 |
if (possibleVariableMapping->addInsertingBindingsCardinalityLinker(propagatedLinker, true)) { |
| 7646 |
propagatedBinding = nullptr; |
| 7647 |
propagatedLinker = nullptr; |
| 7648 |
propagatedCardinalites = nullptr; |
| 7649 |
} else { |
| 7650 |
propagatedCardinalites = propagatedLinker->getCurrentCardinalities(); |
| 7651 |
} |
| 7652 |
} |
| 7653 |
} |
| 7654 |
|
| 7655 |
if (mConfExtendedLogging) { |
| 7656 |
cint64 possMappingCount = 0; |
| 7657 |
if (possibleVariableMapping) { |
| 7658 |
possMappingCount = possibleVariableMapping->getBindingCount(); |
| 7659 |
} |
| 7660 |
cint64 certMappingCount = variableMapping->getBindingCount(); |
| 7661 |
LOG(INFO, getDomain(), logTr("Obtained %1 certain and %2 possible mappings from propagated marker for absorbed query part.").arg(certMappingCount).arg(possMappingCount), this); |
| 7662 |
} |
| 7663 |
|
| 7664 |
|
| 7665 |
return true; |
| 7666 |
} |
| 7667 |
|
| 7668 |
|
| 7669 |
|
| 7670 |
|
| 7671 |
|
| 7672 |
|
| 7673 |
|
| 7674 |
bool COptimizedComplexExpressionAnsweringHandler::canRetrieveInstantiatingDataValueIndividuals(CRole* dataRole, CDataLiteral* dataLiteral) { |
| 7675 |
COntologyTriplesAssertionsAccessor* triplesAssertionAccessor = mOntoAnsweringItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor(); |
| 7676 |
if (triplesAssertionAccessor && dataRole->hasPropertyName()) { |
| 7677 |
CDatatype* datatype = dataLiteral->getDatatype(); |
| 7678 |
if (datatype) { |
| 7679 |
if (datatype->getDatatypeType() == CDatatype::DT_STRING) { |
| 7680 |
return true; |
| 7681 |
} |
| 7682 |
} |
| 7683 |
} |
| 7684 |
return false; |
| 7685 |
} |
| 7686 |
|
| 7687 |
|
| 7688 |
QMap<cint64, IndividualIdCandidateData>* COptimizedComplexExpressionAnsweringHandler::getInstantiatingDataValueIndividualIdMap(CRole* dataRole, CDataLiteral* dataLiteral, QMap<cint64, IndividualIdCandidateData>* instantiatingDataValueIndividualIdMap, CAnswererContext* answererContext) { |
| 7689 |
if (!instantiatingDataValueIndividualIdMap) { |
| 7690 |
instantiatingDataValueIndividualIdMap = new QMap<cint64, IndividualIdCandidateData>(); |
| 7691 |
} |
| 7692 |
COntologyTriplesAssertionsAccessor* triplesAssertionAccessor = mOntoAnsweringItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor(); |
| 7693 |
triplesAssertionAccessor->visitDataValueIndividuals(dataRole, dataLiteral, [&](cint64 indiId)->bool { |
| 7694 |
instantiatingDataValueIndividualIdMap->insert(indiId, IndividualIdCandidateData()); |
| 7695 |
return true; |
| 7696 |
}); |
| 7697 |
return instantiatingDataValueIndividualIdMap; |
| 7698 |
} |
| 7699 |
|
| 7700 |
|
| 7701 |
|
| 7702 |
|
| 7703 |
|
| 7704 |
|
| 7705 |
QSet<CDataLiteral*>* COptimizedComplexExpressionAnsweringHandler::getInstantiatedDataLiterals(const CIndividualReference& indiRef, CRole* dataRole, QSet<CDataLiteral*>* dataLiteralSet, CAnswererContext* answererContext) { |
| 7706 |
|
| 7707 |
if (!dataLiteralSet) { |
| 7708 |
dataLiteralSet = new QSet<CDataLiteral*>(); |
| 7709 |
} |
| 7710 |
QHash<QPair<QString, CDatatype*>, CDataLiteral*>* dataValueDatatypeSingleLiteralHash = nullptr; |
| 7711 |
COntologyTriplesAssertionsAccessor* triplesAssertionAccessor = mOntoAnsweringItem->getOntology()->getOntologyTriplesData()->getTripleAssertionAccessor(); |
| 7712 |
if (triplesAssertionAccessor) { |
| 7713 |
dataValueDatatypeSingleLiteralHash = mOntoAnsweringItem->getDataValueDatatypeSingleLiteralHash(); |
| 7714 |
} |
| 7715 |
CDataLiteralNormalizerPreProcess dataLitNormalizer; |
| 7716 |
CPreProcessContextBase preprocessingContext(mOntoAnsweringItem->getTestingOntology(), mOntoAnsweringItem->getTestingOntology()->getConfiguration()); |
| 7717 |
CContext* dataValueMemoryManagementContext = mOntoAnsweringItem->getDataValueMemoryManagementContext(); |
| 7718 |
|
| 7719 |
CIndividualProcessNodeVector* indiProcVector = nullptr; |
| 7720 |
CConsistence* consistence = mOntoAnsweringItem->getOntology()->getConsistence(); |
| 7721 |
if (consistence) { |
| 7722 |
CConsistenceData* consData = consistence->getConsistenceModelData(); |
| 7723 |
if (consData) { |
| 7724 |
CConsistenceTaskData* consTaskData = dynamic_cast<CConsistenceTaskData*>(consData); |
| 7725 |
CSatisfiableCalculationTask* satConsTask = consTaskData->getCompletionGraphCachedSatisfiableTask(); |
| 7726 |
if (!satConsTask) { |
| 7727 |
satConsTask = consTaskData->getDeterministicSatisfiableTask(); |
| 7728 |
} |
| 7729 |
if (satConsTask) { |
| 7730 |
CProcessingDataBox* procDataBox = satConsTask->getProcessingDataBox(); |
| 7731 |
if (procDataBox) { |
| 7732 |
indiProcVector = procDataBox->getIndividualProcessNodeVector(); |
| 7733 |
} |
| 7734 |
} |
| 7735 |
} |
| 7736 |
} |
| 7737 |
|
| 7738 |
|
| 7739 |
if (indiProcVector) { |
| 7740 |
bool nondeterministicNodeFlag = true; |
| 7741 |
CIndividualProcessNode* indiProcNode = getNominalIndividualProcessNode(indiRef, indiProcVector, &nondeterministicNodeFlag, answererContext); |
| 7742 |
if (indiProcNode) { |
| 7743 |
CRoleSuccessorLinkIterator succRoleIt = indiProcNode->getRoleSuccessorLinkIterator(dataRole); |
| 7744 |
while (succRoleIt.hasNext()) { |
| 7745 |
bool nonDeterministicEdgeFlag = true; |
| 7746 |
CIndividualLinkEdge* linkEdge = succRoleIt.next(true); |
| 7747 |
CDependencyTrackPoint* linkEdgeDepPoint = linkEdge->getDependencyTrackPoint(); |
| 7748 |
if (linkEdgeDepPoint) { |
| 7749 |
nonDeterministicEdgeFlag = linkEdgeDepPoint->getBranchingTag() > 0; |
| 7750 |
} |
| 7751 |
cint64 succIndiId = linkEdge->getOppositeIndividualID(indiProcNode); |
| 7752 |
CIndividualProcessNode* succNode = indiProcVector->getData(succIndiId); |
| 7753 |
|
| 7754 |
for (CConceptDescriptor* conDesIt = succNode->getReapplyConceptLabelSet(false)->getAddingSortedConceptDescriptionLinker(); conDesIt; conDesIt = conDesIt->getNextConceptDesciptor()) { |
| 7755 |
CConcept* concept = conDesIt->getConcept(); |
| 7756 |
bool negated = conDesIt->isNegated(); |
| 7757 |
CDependencyTrackPoint* conDepTrackPoint = conDesIt->getDependencyTrackPoint(); |
| 7758 |
bool nondeterministicConcept = true; |
| 7759 |
if (!negated && concept->getOperatorCode() == CCDATALITERAL) { |
| 7760 |
|
| 7761 |
if (conDepTrackPoint) { |
| 7762 |
nondeterministicConcept = conDepTrackPoint->getBranchingTag() > 0; |
| 7763 |
} |
| 7764 |
|
| 7765 |
CDataLiteral* dataLiteral = concept->getDataLiteral(); |
| 7766 |
if (!nondeterministicNodeFlag && !nonDeterministicEdgeFlag && !nondeterministicConcept) { |
| 7767 |
if (dataValueDatatypeSingleLiteralHash) { |
| 7768 |
CDataLiteral*& hashedValue = (*dataValueDatatypeSingleLiteralHash)[QPair<QString, CDatatype*>(dataLiteral->getLexicalDataLiteralValueString(), dataLiteral->getDatatype())]; |
| 7769 |
if (!hashedValue) { |
| 7770 |
hashedValue = dataLiteral; |
| 7771 |
} |
| 7772 |
dataLiteralSet->insert(hashedValue); |
| 7773 |
} else { |
| 7774 |
dataLiteralSet->insert(dataLiteral); |
| 7775 |
} |
| 7776 |
} |
| 7777 |
} |
| 7778 |
} |
| 7779 |
} |
| 7780 |
} |
| 7781 |
} |
| 7782 |
|
| 7783 |
|
| 7784 |
if (triplesAssertionAccessor) { |
| 7785 |
class COntologyTriplesIndividualDataAssertionsVisitor : public COntologyTriplesIndividualAssertionsVisitor { |
| 7786 |
public: |
| 7787 |
function<bool(CDataLiteral* dataLiteral, CRole* dataRole)> mDataLiteralHandleFunc; |
| 7788 |
|
| 7789 |
COntologyTriplesIndividualDataAssertionsVisitor(function<bool(CDataLiteral* dataLiteral, CRole* dataRole)> dataLiteralHandleFunc) { |
| 7790 |
mDataLiteralHandleFunc = dataLiteralHandleFunc; |
| 7791 |
} |
| 7792 |
|
| 7793 |
bool visitIndividualName(const QString& indiName, COntologyTriplesAssertionsAccessor* accessor) { |
| 7794 |
// for debugging, it is visiting the individual name |
| 7795 |
return true; |
| 7796 |
} |
| 7797 |
|
| 7798 |
bool visitRoleAssertion(CRole* role, cint64 otherIndividualId, COntologyTriplesAssertionsAccessor* accessor) { |
| 7799 |
return false; |
| 7800 |
} |
| 7801 |
|
| 7802 |
bool visitReverseRoleAssertion(CRole* role, cint64 otherIndividualId, COntologyTriplesAssertionsAccessor* accessor) { |
| 7803 |
return false; |
| 7804 |
} |
| 7805 |
|
| 7806 |
bool visitDataAssertion(CRole* role, CDataLiteral* dataLiteral, COntologyTriplesAssertionsAccessor* accessor) { |
| 7807 |
return mDataLiteralHandleFunc(dataLiteral, role); |
| 7808 |
} |
| 7809 |
|
| 7810 |
bool visitConceptAssertion(CConcept* concept, COntologyTriplesAssertionsAccessor* accessor) { |
| 7811 |
return false; |
| 7812 |
} |
| 7813 |
} visitor([&](CDataLiteral* dataLiteral, CRole* dataLiteralDataRole)->bool { |
| 7814 |
if (dataRole == dataLiteralDataRole) { |
| 7815 |
|
| 7816 |
if (dataValueDatatypeSingleLiteralHash) { |
| 7817 |
CDataLiteral*& hashedValue = (*dataValueDatatypeSingleLiteralHash)[QPair<QString, CDatatype*>(dataLiteral->getLexicalDataLiteralValueString(), dataLiteral->getDatatype())]; |
| 7818 |
if (!hashedValue) { |
| 7819 |
CDataLiteral* copiedDataLiteral = CObjectParameterizingAllocator<CDataLiteral, CContext*>::allocateAndConstructAndParameterize(nullptr, nullptr); |
| 7820 |
copiedDataLiteral->initDataLiteral(dataLiteral->getLexicalDataLiteralValueString(), dataLiteral->getDatatype()); |
| 7821 |
|
| 7822 |
CDataLiteralValue* dataLiteralValue = copiedDataLiteral->getDataLiteralValue(); |
| 7823 |
if (!dataLiteralValue) { |
| 7824 |
dataLitNormalizer.createPreprocessedDataLiteralValue(copiedDataLiteral, &preprocessingContext, dataValueMemoryManagementContext); |
| 7825 |
} |
| 7826 |
|
| 7827 |
hashedValue = copiedDataLiteral; |
| 7828 |
} |
| 7829 |
dataLiteralSet->insert(hashedValue); |
| 7830 |
} else { |
| 7831 |
CDataLiteral* copiedDataLiteral = CObjectParameterizingAllocator<CDataLiteral, CContext*>::allocateAndConstructAndParameterize(nullptr, nullptr); |
| 7832 |
copiedDataLiteral->initDataLiteral(dataLiteral->getLexicalDataLiteralValueString(), dataLiteral->getDatatype()); |
| 7833 |
|
| 7834 |
CDataLiteralValue* dataLiteralValue = copiedDataLiteral->getDataLiteralValue(); |
| 7835 |
if (!dataLiteralValue) { |
| 7836 |
dataLitNormalizer.createPreprocessedDataLiteralValue(copiedDataLiteral, &preprocessingContext, dataValueMemoryManagementContext); |
| 7837 |
} |
| 7838 |
|
| 7839 |
dataLiteralSet->insert(copiedDataLiteral); |
| 7840 |
} |
| 7841 |
|
| 7842 |
|
| 7843 |
} |
| 7844 |
return true; |
| 7845 |
}); |
| 7846 |
|
| 7847 |
|
| 7848 |
|
| 7849 |
triplesAssertionAccessor->visitIndividualAssertions(indiRef.getIndividualID(), &visitor, false, false, false, true); |
| 7850 |
} else { |
| 7851 |
|
| 7852 |
CIndividual* indi = indiRef.getIndividual(); |
| 7853 |
if (indi) { |
| 7854 |
for (CDataAssertionLinker* dataAssertionLinkerIt = indi->getAssertionDataLinker(); dataAssertionLinkerIt; dataAssertionLinkerIt = dataAssertionLinkerIt->getNext()) { |
| 7855 |
if (dataRole == dataAssertionLinkerIt->getRole()) { |
| 7856 |
|
| 7857 |
CDataLiteral* dataLiteral = dataAssertionLinkerIt->getDataLiteral(); |
| 7858 |
|
| 7859 |
if (dataValueDatatypeSingleLiteralHash) { |
| 7860 |
CDataLiteral*& hashedValue = (*dataValueDatatypeSingleLiteralHash)[QPair<QString, CDatatype*>(dataLiteral->getLexicalDataLiteralValueString(), dataLiteral->getDatatype())]; |
| 7861 |
if (!hashedValue) { |
| 7862 |
hashedValue = dataLiteral; |
| 7863 |
} |
| 7864 |
dataLiteralSet->insert(hashedValue); |
| 7865 |
} else { |
| 7866 |
dataLiteralSet->insert(dataLiteral); |
| 7867 |
} |
| 7868 |
|
| 7869 |
} |
| 7870 |
} |
| 7871 |
} |
| 7872 |
} |
| 7873 |
|
| 7874 |
return dataLiteralSet; |
| 7875 |
} |
| 7876 |
|
| 7877 |
|
| 7878 |
|
| 7879 |
|
| 7880 |
|
| 7881 |
|
| 7882 |
|
| 7883 |
CIndividualProcessNode* COptimizedComplexExpressionAnsweringHandler::getMergeCorrectedIndividualProcessNode(CIndividualProcessNode* indiProcNode, CIndividualProcessNodeVector* indiProcVector, bool* nonDeterministicallyMergedFlag, CAnswererContext* answererContext) { |
| 7884 |
bool nonDeterministicMerged = false; |
| 7885 |
while (indiProcNode && indiProcNode->getMergedIntoIndividualNodeID() != indiProcNode->getIndividualNodeID()) { |
| 7886 |
cint64 mergeID = indiProcNode->getMergedIntoIndividualNodeID(); |
| 7887 |
CDependencyTrackPoint* mergedDepTrackPoint = indiProcNode->getMergedDependencyTrackPoint(); |
| 7888 |
indiProcNode = indiProcVector->getData(mergeID); |
| 7889 |
if (!mergedDepTrackPoint || mergedDepTrackPoint->getBranchingTag() > 0) { |
| 7890 |
nonDeterministicMerged = true; |
| 7891 |
} |
| 7892 |
} |
| 7893 |
if (nonDeterministicallyMergedFlag) { |
| 7894 |
*nonDeterministicallyMergedFlag = nonDeterministicMerged; |
| 7895 |
} |
| 7896 |
return indiProcNode; |
| 7897 |
} |
| 7898 |
|
| 7899 |
|
| 7900 |
|
| 7901 |
|
| 7902 |
CIndividualProcessNode* COptimizedComplexExpressionAnsweringHandler::getNominalIndividualProcessNode(const CIndividualReference& indiRef, CIndividualProcessNodeVector* indiProcVector, bool* nondeterministicNodeFlag, CAnswererContext* answererContext) { |
| 7903 |
|
| 7904 |
cint64 indiID = -indiRef.getIndividualID(); |
| 7905 |
|
| 7906 |
if (indiProcVector) { |
| 7907 |
CIndividualProcessNode* baseIndiProcNode = indiProcVector->getData(indiID); |
| 7908 |
CIndividualProcessNode* indiProcNode = baseIndiProcNode; |
| 7909 |
bool nondeterministicallyMergedFlag = false; |
| 7910 |
if (indiProcNode) { |
| 7911 |
indiProcNode = getMergeCorrectedIndividualProcessNode(indiProcNode, indiProcVector, &nondeterministicallyMergedFlag, answererContext); |
| 7912 |
} |
| 7913 |
if (nondeterministicNodeFlag) { |
| 7914 |
*nondeterministicNodeFlag = nondeterministicallyMergedFlag; |
| 7915 |
} |
| 7916 |
return indiProcNode; |
| 7917 |
} |
| 7918 |
return nullptr; |
| 7919 |
} |
| 7920 |
|
| 7921 |
|
| 7922 |
|
| 7923 |
|
| 7924 |
|
| 7925 |
|
| 7926 |
bool COptimizedComplexExpressionAnsweringHandler::queueVariableItemComputation(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableCompositionItem* varCompItem) { |
| 7927 |
if (!varCompItem->isComputationQueued()) { |
| 7928 |
varCompItem->setComputationQueued(true); |
| 7929 |
buildingVarItem->addComputeVariableMappingItem(varCompItem); |
| 7930 |
return true; |
| 7931 |
} |
| 7932 |
return false; |
| 7933 |
} |
| 7934 |
|
| 7935 |
|
| 7936 |
|
| 7937 |
|
| 7938 |
bool COptimizedComplexExpressionAnsweringHandler::debugCheckVariableMappingContainsSolution(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableCompositionItem* varCompItem) { |
| 7939 |
QHash<CExpressionVariable*, COptimizedComplexConceptItem*>* varConItemHash = buildingVarItem->getVariableConceptItemHash(); |
| 7940 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 7941 |
|
| 7942 |
QHash<CExpressionVariable*, COptimizedComplexVariableCompositionItemVariableExpressionMapping>* varItemIndexMappingHash = buildingVarItem->getVariableItemIndexMappingHash(); |
| 7943 |
|
| 7944 |
bool allContainingSolution = true; |
| 7945 |
for (QHash<CExpressionVariable*, COptimizedComplexVariableCompositionItemVariableExpressionMapping>::const_iterator it = varItemIndexMappingHash->constBegin(), itEnd = varItemIndexMappingHash->constEnd(); it != itEnd; ++it) { |
| 7946 |
CExpressionVariable* varExp = it.key(); |
| 7947 |
const COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = it.value(); |
| 7948 |
if (varItemIndexMapping.contains(varCompItem)) { |
| 7949 |
allContainingSolution &= debugCheckVariableMappingContainsSolution(buildingVarItem, varExp, varCompItem); |
| 7950 |
} |
| 7951 |
} |
| 7952 |
|
| 7953 |
return allContainingSolution; |
| 7954 |
|
| 7955 |
} |
| 7956 |
|
| 7957 |
|
| 7958 |
|
| 7959 |
QString COptimizedComplexExpressionAnsweringHandler::debugGetVariableMappingsHeaderString(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableCompositionItem* varCompItem, cint64** sortArray) { |
| 7960 |
QHash<CExpressionVariable*, COptimizedComplexConceptItem*>* varConItemHash = buildingVarItem->getVariableConceptItemHash(); |
| 7961 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 7962 |
|
| 7963 |
QString varHeaderString; |
| 7964 |
QList<CExpressionVariable*> varList; |
| 7965 |
for (auto it = varExpVarComItemHash->constBegin(), itEnd = varExpVarComItemHash->constEnd(); it != itEnd; ++it) { |
| 7966 |
CExpressionVariable* var = it.key(); |
| 7967 |
QSet<COptimizedComplexVariableCompositionItem*>* compItemSet = it.value(); |
| 7968 |
if (compItemSet && compItemSet->contains(varCompItem)) { |
| 7969 |
varList.append(var); |
| 7970 |
} |
| 7971 |
} |
| 7972 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 7973 |
if (varList.isEmpty() && varCompItem->debugVarItemIndexMapping) { |
| 7974 |
varList.append(nullptr); |
| 7975 |
} |
| 7976 |
#endif |
| 7977 |
|
| 7978 |
for (CExpressionVariable* var : varList) { |
| 7979 |
QStringList varNameStrings = debugGetItemVariableNames(buildingVarItem, var, varCompItem); |
| 7980 |
if (sortArray) { |
| 7981 |
if (!*sortArray) { |
| 7982 |
*sortArray = new cint64[varNameStrings.length()]; |
| 7983 |
} |
| 7984 |
QHash<QString, cint64> varNameIndHash; |
| 7985 |
QStringList sortedVarNameStrings = varNameStrings; |
| 7986 |
qSort(sortedVarNameStrings.begin(), sortedVarNameStrings.end()); |
| 7987 |
cint64 nextVarId = 0; |
| 7988 |
for (const QString& varName : sortedVarNameStrings) { |
| 7989 |
varNameIndHash.insert(varName, nextVarId++); |
| 7990 |
} |
| 7991 |
cint64 varOriginalInd = 0; |
| 7992 |
for (const QString& varName : varNameStrings) { |
| 7993 |
cint64 varNewInd = varNameIndHash.value(varName); |
| 7994 |
(*sortArray)[varOriginalInd++] = varNewInd; |
| 7995 |
} |
| 7996 |
varNameStrings = sortedVarNameStrings; |
| 7997 |
} |
| 7998 |
varHeaderString += varNameStrings.join("\t") + "\r\n"; |
| 7999 |
} |
| 8000 |
|
| 8001 |
return varHeaderString; |
| 8002 |
} |
| 8003 |
|
| 8004 |
|
| 8005 |
|
| 8006 |
QSet<QString> COptimizedComplexExpressionAnsweringHandler::debugGetVariableMappingStringSet(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableCompositionItem* varCompItem, cint64** sortArray) { |
| 8007 |
QSet<QString> bindingStringSet; |
| 8008 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 8009 |
|
| 8010 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 8011 |
|
| 8012 |
for (COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = varMapping->getLastAddedBindingsCardinalityLinker(); linker; linker = linker->getNext()) { |
| 8013 |
COptimizedComplexVariableIndividualBindings* binding = linker->getBindings(); |
| 8014 |
|
| 8015 |
QStringList bindingStringList; |
| 8016 |
|
| 8017 |
for (cint64 i = 0; i < binding->getBindingSize(); ++i) { |
| 8018 |
|
| 8019 |
COptimizedComplexVariableIndividualMappings::VARIABLE_TYPE bindingType = varMapping->getBindingMapping(i); |
| 8020 |
if (bindingType == COptimizedComplexVariableIndividualMappings::INDIVIDUAL_VARIABLE) { |
| 8021 |
|
| 8022 |
CRealizationIndividualInstanceItemReference instItemRef = binding->getBinding(i).reference; |
| 8023 |
COptimizedKPSetIndividualItem* indiItem = (COptimizedKPSetIndividualItem*)instItemRef.getRealizationInstanceItem(); |
| 8024 |
if (indiItem && indiItem->getIndividualId() != instItemRef.getIndividualID()) { |
| 8025 |
bool debug = true; |
| 8026 |
} |
| 8027 |
CIndividual* individual = instItemRef.getIndividual(); |
| 8028 |
QString individualString = QString::number(instItemRef.getIndividualID()); |
| 8029 |
if (individual) { |
| 8030 |
QList<CIndividualReference> sameIndiList; |
| 8031 |
QList<QString> upSameIndiList; |
| 8032 |
CInstanceBindingIndividualCollectionVisitor visitor(&sameIndiList); |
| 8033 |
sameRealization->visitSameIndividuals(instItemRef, &visitor); |
| 8034 |
for (const CIndividualReference& indiRef : sameIndiList) { |
| 8035 |
CIndividual* indi = mOntoAnsweringItem->getOntology()->getABox()->getIndividualVector()->getData(indiRef.getIndividualID()); |
| 8036 |
upSameIndiList.append(CIRIName::getRecentIRIName(indi->getIndividualNameLinker())); |
| 8037 |
} |
| 8038 |
qSort(upSameIndiList.begin(), upSameIndiList.end()); |
| 8039 |
individualString = upSameIndiList.first(); |
| 8040 |
} else { |
| 8041 |
individualString = mOntoAnsweringItem->getOntology()->getIndividualNameResolver()->getIndividualName(instItemRef); |
| 8042 |
} |
| 8043 |
bindingStringList.append(individualString); |
| 8044 |
|
| 8045 |
} |
| 8046 |
} |
| 8047 |
|
| 8048 |
if (sortArray && *sortArray) { |
| 8049 |
QStringList sortedBindingStringList(bindingStringList); |
| 8050 |
cint64 bindingPos = 0; |
| 8051 |
for (const QString& bindingString : bindingStringList) { |
| 8052 |
cint64 newPos = (*sortArray)[bindingPos++]; |
| 8053 |
sortedBindingStringList[newPos] = bindingString; |
| 8054 |
} |
| 8055 |
bindingStringList = sortedBindingStringList; |
| 8056 |
} |
| 8057 |
QString bindingString = bindingStringList.join("\t"); |
| 8058 |
|
| 8059 |
cint64 card = 0; |
| 8060 |
if (linker->getCurrentCardinalities()) { |
| 8061 |
card = linker->getCurrentCardinalities()->getSameIndividualsSeparatlyConsideredCardinality(); |
| 8062 |
} |
| 8063 |
bindingString.append(QString("\t%1").arg(card)); |
| 8064 |
bindingStringSet.insert(bindingString); |
| 8065 |
} |
| 8066 |
return bindingStringSet; |
| 8067 |
} |
| 8068 |
|
| 8069 |
|
| 8070 |
bool COptimizedComplexExpressionAnsweringHandler::debugWriteVariableMappingToFileWithHeader(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableCompositionItem* varCompItem, const QString& suffix) { |
| 8071 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingIndiVarItem = dynamic_cast<COptimizedComplexBuildingIndividualVariableCompositionsItem*>(buildingVarItem); |
| 8072 |
if (buildingIndiVarItem) { |
| 8073 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 8074 |
QString nextFileName = QString("Debugging/Answering/item-bindings-%1-%2.tsv").arg(varCompItem->getComputationStepId()).arg(nextBindingsFileId++); |
| 8075 |
if (!suffix.isEmpty()) { |
| 8076 |
nextFileName = QString("Debugging/Answering/item-bindings-%1.tsv").arg(suffix); |
| 8077 |
} |
| 8078 |
QFile bindingsFile(nextFileName); |
| 8079 |
if (bindingsFile.open(QIODevice::WriteOnly)) { |
| 8080 |
|
| 8081 |
cint64* sortArray = nullptr; |
| 8082 |
|
| 8083 |
QString varHeaderString = debugGetVariableMappingsHeaderString(buildingIndiVarItem, varCompItem, &sortArray); |
| 8084 |
bindingsFile.write(varHeaderString.toLocal8Bit()); |
| 8085 |
|
| 8086 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 8087 |
cint64 debugId = 0; |
| 8088 |
for (auto debugString : debugCreationStringList) { |
| 8089 |
if (debugString == varCompItem->debugCreationString) { |
| 8090 |
bindingsFile.write(QString("#-%1 [current] >> %2\r\n").arg(debugId++).arg(debugString).toLocal8Bit()); |
| 8091 |
} else { |
| 8092 |
bindingsFile.write(QString("#-%1 --------- >> %2\r\n").arg(debugId++).arg(debugString).toLocal8Bit()); |
| 8093 |
} |
| 8094 |
} |
| 8095 |
|
| 8096 |
#endif |
| 8097 |
|
| 8098 |
QSet<QString> bindingsStringSet = debugGetVariableMappingStringSet(buildingIndiVarItem, varCompItem, &sortArray); |
| 8099 |
for (QString bindingString : bindingsStringSet) { |
| 8100 |
bindingsFile.write(bindingString.toLocal8Bit()); |
| 8101 |
bindingsFile.write("\r\n"); |
| 8102 |
} |
| 8103 |
bindingsFile.close(); |
| 8104 |
if (sortArray) { |
| 8105 |
delete[] sortArray; |
| 8106 |
} |
| 8107 |
} |
| 8108 |
return true; |
| 8109 |
} else { |
| 8110 |
return false; |
| 8111 |
} |
| 8112 |
} |
| 8113 |
|
| 8114 |
|
| 8115 |
|
| 8116 |
|
| 8117 |
bool COptimizedComplexExpressionAnsweringHandler::debugWriteVariableMappingToFile(COptimizedComplexBuildingVariableCompositionsItem* buildVarItem, COptimizedComplexVariableCompositionItem* varCompItem) { |
| 8118 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem = dynamic_cast<COptimizedComplexBuildingIndividualVariableCompositionsItem*>(buildVarItem); |
| 8119 |
if (buildingVarItem) { |
| 8120 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 8121 |
cint64 compStep = varCompItem->getComputationStepId(); |
| 8122 |
QFile bindingsFile(QString("Debugging/Answering/item-bindings-step-%1.tsv").arg(compStep)); |
| 8123 |
QString bindingsString; |
| 8124 |
|
| 8125 |
cint64* sortArray = nullptr; |
| 8126 |
QString varHeaderString = debugGetVariableMappingsHeaderString(buildingVarItem, varCompItem, &sortArray); |
| 8127 |
|
| 8128 |
QSet<QString> bindingsStringSet = debugGetVariableMappingStringSet(buildingVarItem, varCompItem, &sortArray); |
| 8129 |
for (QString bindingString : bindingsStringSet) { |
| 8130 |
if (!bindingsString.isEmpty()) { |
| 8131 |
bindingsString.append("\n"); |
| 8132 |
} |
| 8133 |
bindingsString.append(bindingString); |
| 8134 |
} |
| 8135 |
if (bindingsFile.open(QIODevice::WriteOnly)) { |
| 8136 |
bindingsFile.write(bindingsString.toLocal8Bit()); |
| 8137 |
bindingsFile.close(); |
| 8138 |
} |
| 8139 |
|
| 8140 |
if (sortArray) { |
| 8141 |
delete[] sortArray; |
| 8142 |
} |
| 8143 |
} |
| 8144 |
|
| 8145 |
return true; |
| 8146 |
} |
| 8147 |
|
| 8148 |
|
| 8149 |
bool COptimizedComplexExpressionAnsweringHandler::debugCheckVariableMappingFromFile(COptimizedComplexBuildingVariableCompositionsItem* buildVarItem, COptimizedComplexVariableCompositionItem* varCompItem) { |
| 8150 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem = dynamic_cast<COptimizedComplexBuildingIndividualVariableCompositionsItem*>(buildVarItem); |
| 8151 |
if (buildingVarItem) { |
| 8152 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 8153 |
cint64 compStep = varCompItem->getComputationStepId(); |
| 8154 |
QFile bindingsFile(QString("Debugging/Answering/item-bindings-step.tsv")); |
| 8155 |
|
| 8156 |
cint64* sortArray = nullptr; |
| 8157 |
QString varHeaderString = debugGetVariableMappingsHeaderString(buildingVarItem, varCompItem, &sortArray); |
| 8158 |
|
| 8159 |
QSet<QString> itemBindingsStringSet = debugGetVariableMappingStringSet(buildingVarItem, varCompItem, &sortArray); |
| 8160 |
QSet<QString> fileBindingsStringSet; |
| 8161 |
|
| 8162 |
if (bindingsFile.open(QIODevice::ReadOnly)) { |
| 8163 |
while (!bindingsFile.atEnd()) { |
| 8164 |
fileBindingsStringSet.insert(bindingsFile.readLine().trimmed()); |
| 8165 |
} |
| 8166 |
bindingsFile.close(); |
| 8167 |
} |
| 8168 |
|
| 8169 |
QStringList itemAdditionalBindings; |
| 8170 |
for (QString itemBinding : itemBindingsStringSet) { |
| 8171 |
if (!fileBindingsStringSet.contains(itemBinding.trimmed())) { |
| 8172 |
itemAdditionalBindings.append(itemBinding.trimmed()); |
| 8173 |
} |
| 8174 |
} |
| 8175 |
|
| 8176 |
QStringList fileAdditionalBindings; |
| 8177 |
for (QString fileBinding : fileBindingsStringSet) { |
| 8178 |
if (!itemBindingsStringSet.contains(fileBinding.trimmed())) { |
| 8179 |
fileAdditionalBindings.append(fileBinding.trimmed()); |
| 8180 |
} |
| 8181 |
} |
| 8182 |
|
| 8183 |
if (fileAdditionalBindings.size() > 0 || itemAdditionalBindings.size() > 0) { |
| 8184 |
bool debug = true; |
| 8185 |
|
| 8186 |
COptimizedComplexVariableConceptBaseItem* conceptBaseItem = (COptimizedComplexVariableConceptBaseItem*)varCompItem; |
| 8187 |
COptimizedComplexConceptItem* conceptItem = conceptBaseItem->getConceptItem(); |
| 8188 |
|
| 8189 |
QMap<cint64, CIndividual*> missingIndiIdMap; |
| 8190 |
CIndividualVector* indiVec = mOntoAnsweringItem->getOntology()->getABox()->getIndividualVector(); |
| 8191 |
for (cint64 i = 0; i <= indiVec->getItemMaxIndex(); ++i) { |
| 8192 |
CIndividual* indi = indiVec->getData(i); |
| 8193 |
if (indi) { |
| 8194 |
QString indiName = CIRIName::getRecentIRIName(indi->getIndividualNameLinker()); |
| 8195 |
if (fileAdditionalBindings.contains(indiName + "\t0")) { |
| 8196 |
missingIndiIdMap.insert(indi->getIndividualID(), indi); |
| 8197 |
} |
| 8198 |
} |
| 8199 |
} |
| 8200 |
|
| 8201 |
|
| 8202 |
QMap<cint64, CIndividual*> additionalIndiIdMap; |
| 8203 |
for (cint64 i = 0; i <= indiVec->getItemMaxIndex(); ++i) { |
| 8204 |
CIndividual* indi = indiVec->getData(i); |
| 8205 |
if (indi) { |
| 8206 |
QString indiName = CIRIName::getRecentIRIName(indi->getIndividualNameLinker()); |
| 8207 |
if (itemAdditionalBindings.contains(indiName + "\t0")) { |
| 8208 |
additionalIndiIdMap.insert(indi->getIndividualID(), indi); |
| 8209 |
} |
| 8210 |
} |
| 8211 |
} |
| 8212 |
|
| 8213 |
|
| 8214 |
|
| 8215 |
initializeRealizationInstancesIterators(conceptItem, -1, mAnswererContext); |
| 8216 |
|
| 8217 |
|
| 8218 |
CRealizationIndividualInstanceItemReferenceIterator* iterator1 = conceptItem->getRealizationIterator(); |
| 8219 |
if (iterator1) { |
| 8220 |
iterator1->begin(); |
| 8221 |
COptimizedComplexConceptInstanziatedIndividualItemHash* directInstanceItems = new COptimizedComplexConceptInstanziatedIndividualItemHash(); |
| 8222 |
QSet<CRealizationIndividualInstanceItemReference>* possiblenstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 8223 |
cint64 visitedIndis = 0; |
| 8224 |
while (!iterator1->atEnd()) { |
| 8225 |
|
| 8226 |
CRealizationIndividualInstanceItemReference indiItemRef = iterator1->currentIndividualInstanceItemReference(); |
| 8227 |
QString indiName = CIRIName::getRecentIRIName(indiItemRef.getIndividual()->getIndividualNameLinker()); |
| 8228 |
|
| 8229 |
|
| 8230 |
cint64 nextAdditionalIndiId = -1; |
| 8231 |
QMap<cint64, CIndividual*>::iterator it = additionalIndiIdMap.upperBound(indiItemRef.getIndividualID()); |
| 8232 |
if (it != additionalIndiIdMap.end()) { |
| 8233 |
nextAdditionalIndiId = it.key(); |
| 8234 |
} |
| 8235 |
|
| 8236 |
CRealizationIndividualInstanceItemReferenceIterator* iteratorCopy = iterator1->getCopy(); |
| 8237 |
iterator1->moveNext(); |
| 8238 |
if (!iterator1->atEnd()) { |
| 8239 |
CRealizationIndividualInstanceItemReference nextIndiItemRef = iterator1->currentIndividualInstanceItemReference(); |
| 8240 |
bool debug = false; |
| 8241 |
|
| 8242 |
if (nextIndiItemRef.getIndividualID() > nextAdditionalIndiId && nextAdditionalIndiId >= 0) { |
| 8243 |
debug = true; |
| 8244 |
} |
| 8245 |
|
| 8246 |
QString nextIndiName = CIRIName::getRecentIRIName(nextIndiItemRef.getIndividual()->getIndividualNameLinker()); |
| 8247 |
if (fileAdditionalBindings.contains(nextIndiName + "\t0")) { |
| 8248 |
debug = true; |
| 8249 |
} |
| 8250 |
|
| 8251 |
if (!itemBindingsStringSet.contains(nextIndiName + "\t0")) { |
| 8252 |
debug = true; |
| 8253 |
} |
| 8254 |
|
| 8255 |
|
| 8256 |
if (debug) { |
| 8257 |
bool debug = true; |
| 8258 |
initializeRealizationInstancesIterators(conceptItem, -1, mAnswererContext); |
| 8259 |
CRealizationIndividualInstanceItemReferenceIterator* iteratorCopy2 = iteratorCopy->getCopy(); |
| 8260 |
iteratorCopy->moveNext(); |
| 8261 |
iteratorCopy2->moveNext(); |
| 8262 |
} |
| 8263 |
} |
| 8264 |
|
| 8265 |
} |
| 8266 |
} |
| 8267 |
|
| 8268 |
|
| 8269 |
|
| 8270 |
initializeRealizationInstancesIterators(conceptItem, -1, mAnswererContext); |
| 8271 |
|
| 8272 |
|
| 8273 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = conceptItem->getRealizationIterator(); |
| 8274 |
if (iterator) { |
| 8275 |
iterator->begin(); |
| 8276 |
COptimizedComplexConceptInstanziatedIndividualItemHash* directInstanceItems = new COptimizedComplexConceptInstanziatedIndividualItemHash(); |
| 8277 |
QSet<CRealizationIndividualInstanceItemReference>* possiblenstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 8278 |
cint64 visitedIndis = 0; |
| 8279 |
while (!iterator->atEnd()) { |
| 8280 |
|
| 8281 |
CRealizationIndividualInstanceItemReference indiItemRef = iterator->currentIndividualInstanceItemReference(); |
| 8282 |
QString indiName = CIRIName::getRecentIRIName(indiItemRef.getIndividual()->getIndividualNameLinker()); |
| 8283 |
|
| 8284 |
|
| 8285 |
cint64 nextMissingIndiId = -1; |
| 8286 |
QMap<cint64, CIndividual*>::iterator it = missingIndiIdMap.upperBound(indiItemRef.getIndividualID()); |
| 8287 |
if (it != missingIndiIdMap.end()) { |
| 8288 |
nextMissingIndiId = it.key(); |
| 8289 |
} |
| 8290 |
|
| 8291 |
CRealizationIndividualInstanceItemReferenceIterator* iteratorCopy = iterator->getCopy(); |
| 8292 |
iterator->moveNext(); |
| 8293 |
if (!iterator->atEnd()) { |
| 8294 |
CRealizationIndividualInstanceItemReference nextIndiItemRef = iterator->currentIndividualInstanceItemReference(); |
| 8295 |
bool debug = false; |
| 8296 |
if (nextIndiItemRef.getIndividualID() > nextMissingIndiId && nextMissingIndiId >= 0) { |
| 8297 |
debug = true; |
| 8298 |
} |
| 8299 |
|
| 8300 |
QString nextIndiName = CIRIName::getRecentIRIName(nextIndiItemRef.getIndividual()->getIndividualNameLinker()); |
| 8301 |
if (itemAdditionalBindings.contains(nextIndiName + "\t0")) { |
| 8302 |
debug = true; |
| 8303 |
} |
| 8304 |
|
| 8305 |
if (debug) { |
| 8306 |
bool debug = true; |
| 8307 |
initializeRealizationInstancesIterators(conceptItem, -1, mAnswererContext); |
| 8308 |
CRealizationIndividualInstanceItemReferenceIterator* iteratorCopy2 = iteratorCopy->getCopy(); |
| 8309 |
iteratorCopy->moveNext(); |
| 8310 |
iteratorCopy2->moveNext(); |
| 8311 |
} |
| 8312 |
} |
| 8313 |
|
| 8314 |
} |
| 8315 |
} |
| 8316 |
|
| 8317 |
|
| 8318 |
} |
| 8319 |
|
| 8320 |
if (sortArray) { |
| 8321 |
delete[] sortArray; |
| 8322 |
} |
| 8323 |
} |
| 8324 |
|
| 8325 |
return true; |
| 8326 |
} |
| 8327 |
|
| 8328 |
|
| 8329 |
|
| 8330 |
bool COptimizedComplexExpressionAnsweringHandler::debugCheckVariableMappingContainsSolution(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CExpressionVariable* varExp, COptimizedComplexVariableCompositionItem* varCompItem) { |
| 8331 |
QHash<CExpressionVariable*, COptimizedComplexConceptItem*>* varConItemHash = buildingVarItem->getVariableConceptItemHash(); |
| 8332 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 8333 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 8334 |
|
| 8335 |
|
| 8336 |
QHash<QString, QString> varSolutionHash; |
| 8337 |
varSolutionHash.insert("X", "http://www.Department0.University0.edu/GraduateStudent112"); |
| 8338 |
varSolutionHash.insert("Y", "http://www.Department0.University0.edu/AssociateProfessor9"); |
| 8339 |
varSolutionHash.insert("Z", "http://www.Department0.University0.edu/GraduateCourse31"); |
| 8340 |
|
| 8341 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemMapping = varItemIndexMapping.value(varCompItem); |
| 8342 |
QVector<QString> nameStringVec(itemMapping->count()); |
| 8343 |
|
| 8344 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemMapping->constBegin(), itEnd = itemMapping->constEnd(); it != itEnd; ++it) { |
| 8345 |
cint64 idx = it.key(); |
| 8346 |
CExpressionVariable* expression = it.value(); |
| 8347 |
QString varName = expression->getName(); |
| 8348 |
nameStringVec[idx] = varName; |
| 8349 |
} |
| 8350 |
|
| 8351 |
bool contained = false; |
| 8352 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 8353 |
for (COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = varMapping->getLastAddedBindingsCardinalityLinker(); linker; linker = linker->getNext()) { |
| 8354 |
COptimizedComplexVariableIndividualBindings* binding = linker->getBindings(); |
| 8355 |
|
| 8356 |
bool allVariableBindingsMatchSolution = true; |
| 8357 |
for (cint64 i = 0; allVariableBindingsMatchSolution && i < itemMapping->count(); ++i) { |
| 8358 |
|
| 8359 |
|
| 8360 |
|
| 8361 |
QString varString = nameStringVec[i]; |
| 8362 |
if (varSolutionHash.contains(varString)) { |
| 8363 |
QString solution = varSolutionHash[varString]; |
| 8364 |
|
| 8365 |
COptimizedComplexVariableIndividualMappings::VARIABLE_TYPE bindingType = varMapping->getBindingMapping(i); |
| 8366 |
if (bindingType == COptimizedComplexVariableIndividualMappings::INDIVIDUAL_VARIABLE) { |
| 8367 |
|
| 8368 |
CRealizationIndividualInstanceItemReference instItemRef = binding->getBinding(i).reference; |
| 8369 |
COptimizedKPSetIndividualItem* indiItem = (COptimizedKPSetIndividualItem*)instItemRef.getRealizationInstanceItem(); |
| 8370 |
CIndividual* individual = indiItem->getIndividual(); |
| 8371 |
QString individualString = QString::number(indiItem->getIndividualId()); |
| 8372 |
if (individual) { |
| 8373 |
individualString = CIRIName::getRecentIRIName(individual->getIndividualNameLinker()); |
| 8374 |
} else { |
| 8375 |
individualString = mOntoAnsweringItem->getOntology()->getIndividualNameResolver()->getIndividualName(indiItem->getIndividualReference()); |
| 8376 |
} |
| 8377 |
|
| 8378 |
if (individualString != solution) { |
| 8379 |
allVariableBindingsMatchSolution = false; |
| 8380 |
} |
| 8381 |
|
| 8382 |
} else if (bindingType == COptimizedComplexVariableIndividualMappings::DATA_LITERAL_VARIABLE) { |
| 8383 |
|
| 8384 |
CDataLiteral* dataLiteral = (CDataLiteral*)binding->getBinding(i).pointer; |
| 8385 |
QString literalString = "\"" + dataLiteral->getDataLiteralValue()->getValueString() + "\"^^" + dataLiteral->getDatatype()->getDatatypeIRI(); |
| 8386 |
if (literalString != solution) { |
| 8387 |
allVariableBindingsMatchSolution = false; |
| 8388 |
} |
| 8389 |
|
| 8390 |
} |
| 8391 |
|
| 8392 |
|
| 8393 |
} |
| 8394 |
} |
| 8395 |
|
| 8396 |
if (allVariableBindingsMatchSolution) { |
| 8397 |
contained = true; |
| 8398 |
break; |
| 8399 |
} |
| 8400 |
|
| 8401 |
} |
| 8402 |
if (!contained) { |
| 8403 |
bool debug = false; |
| 8404 |
if (debug) { |
| 8405 |
debugCheckVariableMappingContainsSolution(buildingVarItem, varExp, varCompItem); |
| 8406 |
} |
| 8407 |
} |
| 8408 |
return contained; |
| 8409 |
|
| 8410 |
} |
| 8411 |
|
| 8412 |
|
| 8413 |
|
| 8414 |
|
| 8415 |
QStringList COptimizedComplexExpressionAnsweringHandler::debugGetItemVariableNames(COptimizedComplexBuildingVariableCompositionsItem* buildVarItem, CExpressionVariable* varExp, COptimizedComplexVariableCompositionItem* varCompItem) { |
| 8416 |
QStringList varNameList; |
| 8417 |
QHash<CExpressionVariable*, COptimizedComplexConceptItem*>* varConItemHash = buildVarItem->getVariableConceptItemHash(); |
| 8418 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 8419 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemMapping = nullptr; |
| 8420 |
if (varExp && varCompItem) { |
| 8421 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildVarItem->getVariableItemIndexMapping(varExp); |
| 8422 |
itemMapping = varItemIndexMapping.value(varCompItem); |
| 8423 |
} |
| 8424 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 8425 |
else { |
| 8426 |
itemMapping = varCompItem->debugVarItemIndexMapping; |
| 8427 |
} |
| 8428 |
#endif |
| 8429 |
|
| 8430 |
|
| 8431 |
if (itemMapping) { |
| 8432 |
QVector<QString> nameStringVec(itemMapping->count()); |
| 8433 |
|
| 8434 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemMapping->constBegin(), itEnd = itemMapping->constEnd(); it != itEnd; ++it) { |
| 8435 |
cint64 idx = it.key(); |
| 8436 |
CExpressionVariable* expression = it.value(); |
| 8437 |
QString varName = expression->getName(); |
| 8438 |
nameStringVec[idx] = varName; |
| 8439 |
} |
| 8440 |
for (cint64 i = 0; i < itemMapping->count(); ++i) { |
| 8441 |
varNameList.append(nameStringVec[i]); |
| 8442 |
} |
| 8443 |
} else { |
| 8444 |
bool debug = true; |
| 8445 |
} |
| 8446 |
return varNameList; |
| 8447 |
} |
| 8448 |
|
| 8449 |
|
| 8450 |
|
| 8451 |
|
| 8452 |
bool COptimizedComplexExpressionAnsweringHandler::tryReuseVariableRolePropagationItem(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CIndividualVariableExpression* varExp, COptimizedComplexVariableCompositionItem* varCompItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping, CObjectPropertyAssertionExpression* propAss) { |
| 8453 |
|
| 8454 |
QHash<CExpressionVariable*, COptimizedComplexConceptItem*>* varConItemHash = buildingVarItem->getVariableConceptItemHash(); |
| 8455 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 8456 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 8457 |
|
| 8458 |
CRole* role = mOntoAnsweringItem->getOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propAss->getObjectPropertyTermExpression()); |
| 8459 |
bool inversed = false; |
| 8460 |
if (propAss->getFirstIndividualTermExpression() != varExp) { |
| 8461 |
inversed = true; |
| 8462 |
} |
| 8463 |
CIndividualVariableExpression* otherExp = buildingVarItem->getOtherVariableExpression(varExp, propAss); |
| 8464 |
if (!itemIndexMapping) { |
| 8465 |
itemIndexMapping = varItemIndexMapping.value(varCompItem); |
| 8466 |
} |
| 8467 |
bool propVarExpAlreadyPresent = false; |
| 8468 |
cint64 varIdx = 0; |
| 8469 |
cint64 propVarIdx = itemIndexMapping->size(); |
| 8470 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 8471 |
cint64 idx = it.key(); |
| 8472 |
CExpressionVariable* testVarExp = it.value(); |
| 8473 |
if (testVarExp == otherExp) { |
| 8474 |
propVarExpAlreadyPresent = true; |
| 8475 |
propVarIdx = idx; |
| 8476 |
} |
| 8477 |
else if (varExp == testVarExp) { |
| 8478 |
varIdx = idx; |
| 8479 |
} |
| 8480 |
} |
| 8481 |
|
| 8482 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 8483 |
|
| 8484 |
if (varCompItem->hasRoleInversePropagationItem(role, inversed, varIdx)) { |
| 8485 |
COptimizedComplexVariableRolePropagationItem* varRolePropItem = varCompItem->getRoleInversePropagationItem(role, inversed, varIdx); |
| 8486 |
|
| 8487 |
|
| 8488 |
|
| 8489 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& propVarItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(otherExp); |
| 8490 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* propItemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 8491 |
propVarItemIndexMapping.insertMulti(varRolePropItem, propItemIndexMapping); |
| 8492 |
|
| 8493 |
addUsedVariableCompositionItem(buildingVarItem, varRolePropItem); |
| 8494 |
|
| 8495 |
cint64 newIdx = itemIndexMapping->size(); |
| 8496 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 8497 |
cint64 idx = it.key(); |
| 8498 |
CExpressionVariable* propVarExp = it.value(); |
| 8499 |
propItemIndexMapping->insert(idx, propVarExp); |
| 8500 |
} |
| 8501 |
propItemIndexMapping->insert(newIdx, otherExp); |
| 8502 |
|
| 8503 |
varExpVarComItemHash->value(otherExp)->insert(varRolePropItem); |
| 8504 |
buildingVarItem->updateLastHandledVariableItemAssociation(otherExp, varRolePropItem); |
| 8505 |
|
| 8506 |
|
| 8507 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 8508 |
QStringList debugVariableNamePrevItemStringList = debugGetItemVariableNames(buildingVarItem, varExp, varCompItem); |
| 8509 |
QStringList debugVariableNamePropItemStringList = debugGetItemVariableNames(buildingVarItem, otherExp, varRolePropItem); |
| 8510 |
varRolePropItem->debugVariableNameStringList = debugVariableNamePropItemStringList; |
| 8511 |
QString roleName = CIRIName::getRecentIRIName(role->getPropertyNameLinker()); |
| 8512 |
if (inversed) { |
| 8513 |
roleName = CIRIName::getRecentIRIName(role->getInverseRole()->getPropertyNameLinker()) + "^-"; |
| 8514 |
} |
| 8515 |
varRolePropItem->debugCreationString = "Computation step " + QString::number(varRolePropItem->getComputationStepId()) + " with [" + debugVariableNamePropItemStringList.join(", ") + "] obtained by propagating " + varExp->getName() + " from [" + debugVariableNamePrevItemStringList.join(", ") + "] of step " + QString::number(varCompItem->getComputationStepId()) + " over role " + roleName; |
| 8516 |
debugCreationStringList += varRolePropItem->debugCreationString; |
| 8517 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 8518 |
#endif |
| 8519 |
|
| 8520 |
|
| 8521 |
return true; |
| 8522 |
} else { |
| 8523 |
return false; |
| 8524 |
} |
| 8525 |
} |
| 8526 |
|
| 8527 |
|
| 8528 |
|
| 8529 |
|
| 8530 |
|
| 8531 |
|
| 8532 |
|
| 8533 |
|
| 8534 |
|
| 8535 |
|
| 8536 |
|
| 8537 |
|
| 8538 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildVariableSubSuperPropagationItem(COptimizedComplexBuildingPropertyVariableCompositionsItem* buildingVarItem, CPropertyVariableExpression* varExp, COptimizedComplexVariableCompositionItem* varCompItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping, CPropertyVariableExpression* otherVariable, bool superPropagation, bool* processing, CAnswererContext* answererContext) { |
| 8539 |
QHash<CExpressionVariable*, COptimizedComplexConceptItem*>* varConItemHash = buildingVarItem->getVariableConceptItemHash(); |
| 8540 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 8541 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 8542 |
|
| 8543 |
if (!itemIndexMapping) { |
| 8544 |
itemIndexMapping = varItemIndexMapping.value(varCompItem); |
| 8545 |
} |
| 8546 |
bool propVarExpAlreadyPresent = false; |
| 8547 |
cint64 varIdx = 0; |
| 8548 |
cint64 propVarIdx = itemIndexMapping->size(); |
| 8549 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 8550 |
cint64 idx = it.key(); |
| 8551 |
CExpressionVariable* testVarExp = it.value(); |
| 8552 |
if (testVarExp == otherVariable) { |
| 8553 |
propVarExpAlreadyPresent = true; |
| 8554 |
propVarIdx = idx; |
| 8555 |
} else if (varExp == testVarExp) { |
| 8556 |
varIdx = idx; |
| 8557 |
} |
| 8558 |
} |
| 8559 |
|
| 8560 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 8561 |
|
| 8562 |
COptimizedComplexVariableSubSuperPropertiesPropagationItem*& varSubSuperPropertiesPropItem = varCompItem->getSubSuperPropertiesPropagationItem(superPropagation, varIdx); |
| 8563 |
bool created = false; |
| 8564 |
if (!varSubSuperPropertiesPropItem) { |
| 8565 |
varSubSuperPropertiesPropItem = new COptimizedComplexVariableSubSuperPropertiesPropagationItem(varCompItem, superPropagation, varIdx); |
| 8566 |
created = true; |
| 8567 |
varSubSuperPropertiesPropItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 8568 |
varSubSuperPropertiesPropItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 8569 |
} |
| 8570 |
addUsedVariableCompositionItem(buildingVarItem, varSubSuperPropertiesPropItem); |
| 8571 |
if (!varSubSuperPropertiesPropItem->isVariableMappingsInitialized()) { |
| 8572 |
varSubSuperPropertiesPropItem->setVariableMappingsInitialized(true); |
| 8573 |
// schedule item processing |
| 8574 |
queueVariableItemComputation(buildingVarItem, varSubSuperPropertiesPropItem); |
| 8575 |
if (processing) { |
| 8576 |
*processing = true; |
| 8577 |
} |
| 8578 |
|
| 8579 |
} |
| 8580 |
|
| 8581 |
|
| 8582 |
|
| 8583 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& propVarItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(otherVariable); |
| 8584 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* extendItemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 8585 |
propVarItemIndexMapping.insertMulti(varSubSuperPropertiesPropItem, extendItemIndexMapping); |
| 8586 |
|
| 8587 |
cint64 newIdx = itemIndexMapping->size(); |
| 8588 |
COptimizedComplexVariableIndividualMappings* propVarMapping = nullptr; |
| 8589 |
if (created) { |
| 8590 |
propVarMapping = new COptimizedComplexVariableIndividualMappingsHash(newIdx + 1); |
| 8591 |
} |
| 8592 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 8593 |
cint64 idx = it.key(); |
| 8594 |
CExpressionVariable* propVarExp = it.value(); |
| 8595 |
extendItemIndexMapping->insert(idx, propVarExp); |
| 8596 |
if (created) { |
| 8597 |
propVarMapping->setBindingMapping(idx, varMapping->getBindingMapping(idx)); |
| 8598 |
} |
| 8599 |
} |
| 8600 |
extendItemIndexMapping->insert(newIdx, otherVariable); |
| 8601 |
if (created) { |
| 8602 |
propVarMapping->setBindingMapping(newIdx, COptimizedComplexVariableIndividualMappings::PROPERTY_VARIABLE); |
| 8603 |
varSubSuperPropertiesPropItem->setVariableMapping(propVarMapping); |
| 8604 |
} |
| 8605 |
|
| 8606 |
|
| 8607 |
|
| 8608 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 8609 |
QStringList debugVariableNamePrevItemStringList = debugGetItemVariableNames(buildingVarItem, varExp, varCompItem); |
| 8610 |
#endif |
| 8611 |
|
| 8612 |
varExpVarComItemHash->value(otherVariable)->insert(varSubSuperPropertiesPropItem); |
| 8613 |
buildingVarItem->updateLastHandledVariableItemAssociation(otherVariable, varSubSuperPropertiesPropItem); |
| 8614 |
|
| 8615 |
|
| 8616 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 8617 |
QStringList debugVariableNameNewItemStringList = debugGetItemVariableNames(buildingVarItem, varExp, varSubSuperPropertiesPropItem); |
| 8618 |
varSubSuperPropertiesPropItem->debugVariableNameStringList = debugVariableNameNewItemStringList; |
| 8619 |
QString propName = "super"; |
| 8620 |
if (!superPropagation) { |
| 8621 |
propName = "sub"; |
| 8622 |
} |
| 8623 |
varSubSuperPropertiesPropItem->debugCreationString = "Computation step " + QString::number(varSubSuperPropertiesPropItem->getComputationStepId()) + " with [" + debugVariableNameNewItemStringList.join(", ") + "] obtained by propagating " + varExp->getName() + " from [" + debugVariableNamePrevItemStringList.join(", ") + "] of step " + QString::number(varCompItem->getComputationStepId()) + " with " + propName + " properties propagation"; |
| 8624 |
debugCreationStringList += varSubSuperPropertiesPropItem->debugCreationString; |
| 8625 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 8626 |
#endif |
| 8627 |
|
| 8628 |
|
| 8629 |
return QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(varSubSuperPropertiesPropItem, extendItemIndexMapping); |
| 8630 |
} |
| 8631 |
|
| 8632 |
|
| 8633 |
|
| 8634 |
|
| 8635 |
|
| 8636 |
|
| 8637 |
|
| 8638 |
|
| 8639 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildVariableSubSuperPropagationItem(COptimizedComplexBuildingClassVariableCompositionsItem* buildingVarItem, CClassVariableExpression* varExp, COptimizedComplexVariableCompositionItem* varCompItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping, CClassVariableExpression* otherVariable, bool superPropagation, bool* processing, CAnswererContext* answererContext) { |
| 8640 |
QHash<CExpressionVariable*, COptimizedComplexConceptItem*>* varConItemHash = buildingVarItem->getVariableConceptItemHash(); |
| 8641 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 8642 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 8643 |
|
| 8644 |
if (!itemIndexMapping) { |
| 8645 |
itemIndexMapping = varItemIndexMapping.value(varCompItem); |
| 8646 |
} |
| 8647 |
bool propVarExpAlreadyPresent = false; |
| 8648 |
cint64 varIdx = 0; |
| 8649 |
cint64 propVarIdx = itemIndexMapping->size(); |
| 8650 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 8651 |
cint64 idx = it.key(); |
| 8652 |
CExpressionVariable* testVarExp = it.value(); |
| 8653 |
if (testVarExp == otherVariable) { |
| 8654 |
propVarExpAlreadyPresent = true; |
| 8655 |
propVarIdx = idx; |
| 8656 |
} else if (varExp == testVarExp) { |
| 8657 |
varIdx = idx; |
| 8658 |
} |
| 8659 |
} |
| 8660 |
|
| 8661 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 8662 |
|
| 8663 |
COptimizedComplexVariableSubSuperClassesPropagationItem*& varSubSuperClassesPropItem = varCompItem->getSubSuperClassesPropagationItem(superPropagation, varIdx); |
| 8664 |
bool created = false; |
| 8665 |
if (!varSubSuperClassesPropItem) { |
| 8666 |
varSubSuperClassesPropItem = new COptimizedComplexVariableSubSuperClassesPropagationItem(varCompItem, superPropagation, varIdx); |
| 8667 |
created = true; |
| 8668 |
varSubSuperClassesPropItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 8669 |
varSubSuperClassesPropItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 8670 |
} |
| 8671 |
addUsedVariableCompositionItem(buildingVarItem, varSubSuperClassesPropItem); |
| 8672 |
if (!varSubSuperClassesPropItem->isVariableMappingsInitialized()) { |
| 8673 |
varSubSuperClassesPropItem->setVariableMappingsInitialized(true); |
| 8674 |
// schedule item processing |
| 8675 |
queueVariableItemComputation(buildingVarItem, varSubSuperClassesPropItem); |
| 8676 |
if (processing) { |
| 8677 |
*processing = true; |
| 8678 |
} |
| 8679 |
|
| 8680 |
} |
| 8681 |
|
| 8682 |
|
| 8683 |
|
| 8684 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& propVarItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(otherVariable); |
| 8685 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* extendItemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 8686 |
propVarItemIndexMapping.insertMulti(varSubSuperClassesPropItem, extendItemIndexMapping); |
| 8687 |
|
| 8688 |
cint64 newIdx = itemIndexMapping->size(); |
| 8689 |
COptimizedComplexVariableIndividualMappings* propVarMapping = nullptr; |
| 8690 |
if (created) { |
| 8691 |
propVarMapping = new COptimizedComplexVariableIndividualMappingsHash(newIdx + 1); |
| 8692 |
} |
| 8693 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 8694 |
cint64 idx = it.key(); |
| 8695 |
CExpressionVariable* propVarExp = it.value(); |
| 8696 |
extendItemIndexMapping->insert(idx, propVarExp); |
| 8697 |
if (created) { |
| 8698 |
propVarMapping->setBindingMapping(idx, varMapping->getBindingMapping(idx)); |
| 8699 |
} |
| 8700 |
} |
| 8701 |
extendItemIndexMapping->insert(newIdx, otherVariable); |
| 8702 |
if (created) { |
| 8703 |
propVarMapping->setBindingMapping(newIdx, COptimizedComplexVariableIndividualMappings::CLASS_VARIABLE); |
| 8704 |
varSubSuperClassesPropItem->setVariableMapping(propVarMapping); |
| 8705 |
} |
| 8706 |
|
| 8707 |
|
| 8708 |
|
| 8709 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 8710 |
QStringList debugVariableNamePrevItemStringList = debugGetItemVariableNames(buildingVarItem, varExp, varCompItem); |
| 8711 |
#endif |
| 8712 |
|
| 8713 |
varExpVarComItemHash->value(otherVariable)->insert(varSubSuperClassesPropItem); |
| 8714 |
buildingVarItem->updateLastHandledVariableItemAssociation(otherVariable, varSubSuperClassesPropItem); |
| 8715 |
|
| 8716 |
|
| 8717 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 8718 |
QStringList debugVariableNameNewItemStringList = debugGetItemVariableNames(buildingVarItem, varExp, varSubSuperClassesPropItem); |
| 8719 |
varSubSuperClassesPropItem->debugVariableNameStringList = debugVariableNameNewItemStringList; |
| 8720 |
QString propName = "super"; |
| 8721 |
if (!superPropagation) { |
| 8722 |
propName = "sub"; |
| 8723 |
} |
| 8724 |
varSubSuperClassesPropItem->debugCreationString = "Computation step " + QString::number(varSubSuperClassesPropItem->getComputationStepId()) + " with [" + debugVariableNameNewItemStringList.join(", ") + "] obtained by propagating " + varExp->getName() + " from [" + debugVariableNamePrevItemStringList.join(", ") + "] of step " + QString::number(varCompItem->getComputationStepId()) + " to " + propName + " classes propagation"; |
| 8725 |
debugCreationStringList += varSubSuperClassesPropItem->debugCreationString; |
| 8726 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 8727 |
#endif |
| 8728 |
|
| 8729 |
|
| 8730 |
return QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(varSubSuperClassesPropItem, extendItemIndexMapping); |
| 8731 |
} |
| 8732 |
|
| 8733 |
|
| 8734 |
|
| 8735 |
|
| 8736 |
|
| 8737 |
|
| 8738 |
|
| 8739 |
|
| 8740 |
|
| 8741 |
|
| 8742 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildVariableRolePropagationItem(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CIndividualVariableExpression* varExp, COptimizedComplexVariableCompositionItem* varCompItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping, CDataLiteralVariableExpression* dataVariable, CDataPropertyTermExpression* dataPropTerm, bool* processing, CAnswererContext* answererContext) { |
| 8743 |
QHash<CExpressionVariable*, COptimizedComplexConceptItem*>* varConItemHash = buildingVarItem->getVariableConceptItemHash(); |
| 8744 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 8745 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 8746 |
|
| 8747 |
CRole* dataRole = mOntoAnsweringItem->getOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getDataPropertyTermRoleMappingHash()->value(dataPropTerm); |
| 8748 |
if (!itemIndexMapping) { |
| 8749 |
itemIndexMapping = varItemIndexMapping.value(varCompItem); |
| 8750 |
} |
| 8751 |
bool propVarExpAlreadyPresent = false; |
| 8752 |
cint64 varIdx = 0; |
| 8753 |
cint64 propVarIdx = itemIndexMapping->size(); |
| 8754 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 8755 |
cint64 idx = it.key(); |
| 8756 |
CExpressionVariable* testVarExp = it.value(); |
| 8757 |
if (testVarExp == dataVariable) { |
| 8758 |
propVarExpAlreadyPresent = true; |
| 8759 |
propVarIdx = idx; |
| 8760 |
} |
| 8761 |
else if (varExp == testVarExp) { |
| 8762 |
varIdx = idx; |
| 8763 |
} |
| 8764 |
} |
| 8765 |
|
| 8766 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 8767 |
|
| 8768 |
COptimizedComplexVariableDataLiteralExtensionItem*& varDataRoleExtItem = varCompItem->getDataLiteralExtensionItem(dataRole, varIdx); |
| 8769 |
bool created = false; |
| 8770 |
if (!varDataRoleExtItem) { |
| 8771 |
varDataRoleExtItem = new COptimizedComplexVariableDataLiteralExtensionItem(varCompItem, dataRole, varIdx); |
| 8772 |
created = true; |
| 8773 |
varDataRoleExtItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 8774 |
varDataRoleExtItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 8775 |
} |
| 8776 |
addUsedVariableCompositionItem(buildingVarItem, varDataRoleExtItem); |
| 8777 |
if (!varDataRoleExtItem->isVariableMappingsInitialized()) { |
| 8778 |
varDataRoleExtItem->setVariableMappingsInitialized(true); |
| 8779 |
// schedule item processing |
| 8780 |
queueVariableItemComputation(buildingVarItem, varDataRoleExtItem); |
| 8781 |
if (processing) { |
| 8782 |
*processing = true; |
| 8783 |
} |
| 8784 |
|
| 8785 |
} |
| 8786 |
|
| 8787 |
|
| 8788 |
|
| 8789 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* extendItemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 8790 |
|
| 8791 |
cint64 newIdx = itemIndexMapping->size(); |
| 8792 |
COptimizedComplexVariableIndividualMappings* propVarMapping = nullptr; |
| 8793 |
if (created) { |
| 8794 |
propVarMapping = new COptimizedComplexVariableIndividualMappingsHash(newIdx + 1); |
| 8795 |
} |
| 8796 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 8797 |
cint64 idx = it.key(); |
| 8798 |
CExpressionVariable* propVarExp = it.value(); |
| 8799 |
extendItemIndexMapping->insert(idx, propVarExp); |
| 8800 |
if (created) { |
| 8801 |
propVarMapping->setBindingMapping(idx, varMapping->getBindingMapping(idx)); |
| 8802 |
} |
| 8803 |
} |
| 8804 |
extendItemIndexMapping->insert(newIdx, dataVariable); |
| 8805 |
if (created) { |
| 8806 |
propVarMapping->setBindingMapping(newIdx, COptimizedComplexVariableIndividualMappings::DATA_LITERAL_VARIABLE); |
| 8807 |
varDataRoleExtItem->setVariableMapping(propVarMapping); |
| 8808 |
} |
| 8809 |
|
| 8810 |
|
| 8811 |
|
| 8812 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 8813 |
QStringList debugVariableNamePrevItemStringList = debugGetItemVariableNames(buildingVarItem, varExp, varCompItem); |
| 8814 |
#endif |
| 8815 |
|
| 8816 |
varItemIndexMapping.insert(varDataRoleExtItem, extendItemIndexMapping); |
| 8817 |
varExpVarComItemHash->value(varExp)->insert(varDataRoleExtItem); |
| 8818 |
|
| 8819 |
|
| 8820 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 8821 |
QStringList debugVariableNameNewItemStringList = debugGetItemVariableNames(buildingVarItem, varExp, varDataRoleExtItem); |
| 8822 |
varDataRoleExtItem->debugVariableNameStringList = debugVariableNameNewItemStringList; |
| 8823 |
QString roleName = CIRIName::getRecentIRIName(dataRole->getPropertyNameLinker()); |
| 8824 |
varDataRoleExtItem->debugCreationString = "Computation step " + QString::number(varDataRoleExtItem->getComputationStepId()) + " with [" + debugVariableNameNewItemStringList.join(", ") + "] obtained by extending " + varExp->getName() + " from [" + debugVariableNamePrevItemStringList.join(", ") + "] of step " + QString::number(varCompItem->getComputationStepId()) + " with data values for data role " + roleName; |
| 8825 |
debugCreationStringList += varDataRoleExtItem->debugCreationString; |
| 8826 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 8827 |
#endif |
| 8828 |
|
| 8829 |
buildingVarItem->updateLastHandledVariableItemAssociation(varExp, varDataRoleExtItem); |
| 8830 |
|
| 8831 |
return QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(varDataRoleExtItem, extendItemIndexMapping); |
| 8832 |
} |
| 8833 |
|
| 8834 |
|
| 8835 |
|
| 8836 |
|
| 8837 |
|
| 8838 |
|
| 8839 |
|
| 8840 |
|
| 8841 |
|
| 8842 |
QHash<CExpressionVariable*, cint64> COptimizedComplexExpressionAnsweringHandler::getPropagationReducableVariables(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CExpressionVariable* propVarExp, COptimizedComplexVariableCompositionItem* varCompItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping, CObjectPropertyAssertionExpression* propAss) { |
| 8843 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 8844 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(propVarExp); |
| 8845 |
|
| 8846 |
if (!itemIndexMapping) { |
| 8847 |
itemIndexMapping = varItemIndexMapping.value(varCompItem); |
| 8848 |
} |
| 8849 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*>* absorbingQueryPartsList = buildingVarItem->getAbsorbingQueryPartsList(); |
| 8850 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*>* absorbedQueryPartsItemExtensionList = buildingVarItem->getAbsorbedQueryPartItemExtensionHandlingList(); |
| 8851 |
|
| 8852 |
QHash<CExpressionVariable*, cint64> reductionVarIdxSet; |
| 8853 |
if (mConfAllowBindingReduction && buildingVarItem->isBindingsReducible() && varCompItem->getVariableMappingsExpectedCount() > mConfMappingSizeBindingReduction && absorbedQueryPartsItemExtensionList->isEmpty() && absorbingQueryPartsList->isEmpty()) { |
| 8854 |
// test whether there is no absorption propagation |
| 8855 |
// test whether there exists a variable that is not distinguished, has no remaining properties, and is not used by a remaining item for any variable |
| 8856 |
QSet<CExpressionVariable*>* allVarExpSet = buildingVarItem->getAllVariableSet(); |
| 8857 |
QSet<CExpressionVariable*>* reductionDeniedVarExpSet = buildingVarItem->getReductionDeniedVariableSet(); |
| 8858 |
|
| 8859 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 8860 |
cint64 idx = it.key(); |
| 8861 |
CExpressionVariable* varExp = it.value(); |
| 8862 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(varExp); |
| 8863 |
|
| 8864 |
if (!reductionDeniedVarExpSet->contains(varExp) && indiVarExp) { |
| 8865 |
|
| 8866 |
QList<CObjectPropertyAssertionExpression*> propAssList = buildingVarItem->getUnhanledPropertyAssertionsExpressions(indiVarExp); |
| 8867 |
QList<CDataPropertyAssertionExpression*> dataPropAssList = buildingVarItem->getUnhanledDataPropertyAssertionsExpressions(indiVarExp); |
| 8868 |
if (dataPropAssList.isEmpty() && (propVarExp != varExp && propAssList.isEmpty() || propAssList.size() == 1 && propAssList.first() == propAss)) { |
| 8869 |
|
| 8870 |
bool varExpStillRequired = false; |
| 8871 |
for (CExpressionVariable* otherVarExp : *allVarExpSet) { |
| 8872 |
|
| 8873 |
|
| 8874 |
|
| 8875 |
CIndividualVariableExpression* otherIndiVarExp = dynamic_cast<CIndividualVariableExpression*>(otherVarExp); |
| 8876 |
if (otherIndiVarExp) { |
| 8877 |
QList<CObjectPropertyAssertionExpression*> propAssList = buildingVarItem->getUnhanledPropertyAssertionsExpressions(otherIndiVarExp); |
| 8878 |
QList<CDataPropertyAssertionExpression*> dataPropAssList = buildingVarItem->getUnhanledDataPropertyAssertionsExpressions(otherIndiVarExp); |
| 8879 |
QSet<COptimizedComplexVariableCompositionItem*>* remainingItemSet = varExpVarComItemHash->value(otherVarExp); |
| 8880 |
|
| 8881 |
if (remainingItemSet) { |
| 8882 |
bool investigateVarItemMappings = false; |
| 8883 |
if (!dataPropAssList.isEmpty() || !propAssList.isEmpty() || remainingItemSet->size() > 1) { |
| 8884 |
investigateVarItemMappings = true; |
| 8885 |
} |
| 8886 |
if (!investigateVarItemMappings && remainingItemSet->size() == 1) { |
| 8887 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> firstOtherItemIndexMappings = buildingVarItem->getVariableItemIndexMapping(otherVarExp).values(*remainingItemSet->begin()); |
| 8888 |
if (firstOtherItemIndexMappings.size() > 1) { |
| 8889 |
investigateVarItemMappings = true; |
| 8890 |
} |
| 8891 |
} |
| 8892 |
|
| 8893 |
if (investigateVarItemMappings) { |
| 8894 |
for (COptimizedComplexVariableCompositionItem* otherVarCompItem : *remainingItemSet) { |
| 8895 |
if (otherVarCompItem) { |
| 8896 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> otherItemIndexMappings = buildingVarItem->getVariableItemIndexMapping(otherVarExp).values(otherVarCompItem); |
| 8897 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping* otherItemIndexMapping : otherItemIndexMappings) { |
| 8898 |
if (otherItemIndexMapping && (otherVarCompItem != varCompItem || otherItemIndexMapping != itemIndexMapping)) { |
| 8899 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator otherIt = otherItemIndexMapping->constBegin(), otherItEnd = otherItemIndexMapping->constEnd(); otherIt != otherItEnd; ++otherIt) { |
| 8900 |
CExpressionVariable* testVarExp = otherIt.value(); |
| 8901 |
if (testVarExp == varExp) { |
| 8902 |
varExpStillRequired = true; |
| 8903 |
break; |
| 8904 |
} |
| 8905 |
} |
| 8906 |
} |
| 8907 |
if (varExpStillRequired) { |
| 8908 |
break; |
| 8909 |
} |
| 8910 |
} |
| 8911 |
} |
| 8912 |
if (varExpStillRequired) { |
| 8913 |
break; |
| 8914 |
} |
| 8915 |
} |
| 8916 |
} |
| 8917 |
} |
| 8918 |
} |
| 8919 |
if (varExpStillRequired) { |
| 8920 |
break; |
| 8921 |
} |
| 8922 |
|
| 8923 |
//QSet<COptimizedComplexVariableCompositionItem*>* remainingItemSet = varExpVarComItemHash->value(otherVarExp); |
| 8924 |
//for (COptimizedComplexVariableCompositionItem* remainingItem : *remainingItemSet) { |
| 8925 |
//} |
| 8926 |
//CExpressionVariable* associatedVariableExpression = buildingVarItem->getVariableLastCompositionItemAssociatedVariableExpression(otherVarExp); |
| 8927 |
|
| 8928 |
//COptimizedComplexVariableCompositionItem* otherVarCompItem = buildingVarItem->getVariableLastCompositionItem(otherVarExp); |
| 8929 |
//if (otherVarCompItem != varCompItem && otherVarCompItem) { |
| 8930 |
// COptimizedComplexVariableCompositionItemVariableIndexMapping* otherItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(otherVarExp).value(otherVarCompItem); |
| 8931 |
// if (otherItemIndexMapping) { |
| 8932 |
// for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator otherIt = otherItemIndexMapping->constBegin(), otherItEnd = otherItemIndexMapping->constEnd(); otherIt != otherItEnd && !varExpStillRequired; ++otherIt) { |
| 8933 |
// CExpressionVariable* testVarExp = otherIt.value(); |
| 8934 |
// if (testVarExp == varExp) { |
| 8935 |
// varExpStillRequired = true; |
| 8936 |
// } |
| 8937 |
// } |
| 8938 |
// } |
| 8939 |
//} |
| 8940 |
//if (varExpStillRequired) { |
| 8941 |
// break; |
| 8942 |
//} |
| 8943 |
} |
| 8944 |
|
| 8945 |
if (!varExpStillRequired) { |
| 8946 |
reductionVarIdxSet.insertMulti(varExp, idx); |
| 8947 |
} |
| 8948 |
|
| 8949 |
} |
| 8950 |
|
| 8951 |
} |
| 8952 |
} |
| 8953 |
} |
| 8954 |
return reductionVarIdxSet; |
| 8955 |
} |
| 8956 |
|
| 8957 |
|
| 8958 |
|
| 8959 |
|
| 8960 |
QHash<CExpressionVariable*, cint64> COptimizedComplexExpressionAnsweringHandler::getReducableVariables(COptimizedComplexBuildingVariableCompositionsItem* buildVarItem, CExpressionVariable* propVarExp, COptimizedComplexVariableCompositionItem* varCompItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping) { |
| 8961 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 8962 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildVarItem->getVariableItemIndexMapping(propVarExp); |
| 8963 |
|
| 8964 |
QHash<CExpressionVariable*, cint64> reductionVarIdxSet; |
| 8965 |
if (!itemIndexMapping) { |
| 8966 |
itemIndexMapping = varItemIndexMapping.value(varCompItem); |
| 8967 |
} |
| 8968 |
|
| 8969 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingIndiVarItem = dynamic_cast<COptimizedComplexBuildingIndividualVariableCompositionsItem*>(buildVarItem); |
| 8970 |
if (buildingIndiVarItem) { |
| 8971 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*>* absorbedQueryPartsItemExtensionList = buildingIndiVarItem->getAbsorbedQueryPartItemExtensionHandlingList(); |
| 8972 |
|
| 8973 |
|
| 8974 |
|
| 8975 |
if (mConfAllowBindingReduction && buildingIndiVarItem->isBindingsReducible() && varCompItem->getVariableMappingsExpectedCount() >= mConfMappingSizeBindingReduction && absorbedQueryPartsItemExtensionList->isEmpty()) { |
| 8976 |
// test whether there is no absorption propagation |
| 8977 |
// test whether there exists a variable that is not distinguished, has no remaining properties, and is not used by a remaining item for any variable |
| 8978 |
QSet<CExpressionVariable*>* allVarExpSet = buildingIndiVarItem->getAllVariableSet(); |
| 8979 |
QSet<CExpressionVariable*>* reductionDeniedVarExpSet = buildingIndiVarItem->getReductionDeniedVariableSet(); |
| 8980 |
|
| 8981 |
QHash<CExpressionVariable*, cint64> varUseCountHash; |
| 8982 |
|
| 8983 |
for (CExpressionVariable* varExp : *allVarExpSet) { |
| 8984 |
|
| 8985 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(varExp); |
| 8986 |
if (indiVarExp) { |
| 8987 |
QList<CObjectPropertyAssertionExpression*> propAssList = buildingIndiVarItem->getUnhanledPropertyAssertionsExpressions(indiVarExp); |
| 8988 |
QList<CDataPropertyAssertionExpression*> dataPropAssList = buildingIndiVarItem->getUnhanledDataPropertyAssertionsExpressions(indiVarExp); |
| 8989 |
QSet<COptimizedComplexVariableCompositionItem*>* remainingItemSet = varExpVarComItemHash->value(varExp); |
| 8990 |
if (remainingItemSet) { |
| 8991 |
bool investigateVarItemMappings = false; |
| 8992 |
if (!dataPropAssList.isEmpty() || !propAssList.isEmpty()) { |
| 8993 |
varUseCountHash[varExp] += 2; |
| 8994 |
investigateVarItemMappings = true; |
| 8995 |
} |
| 8996 |
if (remainingItemSet->size() > 1) { |
| 8997 |
investigateVarItemMappings = true; |
| 8998 |
} |
| 8999 |
if (!investigateVarItemMappings && remainingItemSet->size() == 1) { |
| 9000 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> firstOtherItemIndexMappings = buildingIndiVarItem->getVariableItemIndexMapping(varExp).values(*remainingItemSet->begin()); |
| 9001 |
if (firstOtherItemIndexMappings.size() > 1) { |
| 9002 |
investigateVarItemMappings = true; |
| 9003 |
} |
| 9004 |
} |
| 9005 |
|
| 9006 |
if (investigateVarItemMappings) { |
| 9007 |
for (COptimizedComplexVariableCompositionItem* remainingItem : *remainingItemSet) { |
| 9008 |
if (remainingItem) { |
| 9009 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> otherItemIndexMappings = buildingIndiVarItem->getVariableItemIndexMapping(varExp).values(remainingItem); |
| 9010 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping* otherItemIndexMapping : otherItemIndexMappings) { |
| 9011 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator otherIt = otherItemIndexMapping->constBegin(), otherItEnd = otherItemIndexMapping->constEnd(); otherIt != otherItEnd; ++otherIt) { |
| 9012 |
CExpressionVariable* otherVarExp = otherIt.value(); |
| 9013 |
varUseCountHash[otherVarExp]++; |
| 9014 |
} |
| 9015 |
} |
| 9016 |
} |
| 9017 |
} |
| 9018 |
} |
| 9019 |
} |
| 9020 |
|
| 9021 |
} |
| 9022 |
} |
| 9023 |
|
| 9024 |
|
| 9025 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 9026 |
cint64 idx = it.key(); |
| 9027 |
CExpressionVariable* varExp = it.value(); |
| 9028 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(varExp); |
| 9029 |
|
| 9030 |
if (!reductionDeniedVarExpSet->contains(varExp) && indiVarExp) { |
| 9031 |
|
| 9032 |
cint64 useCount = varUseCountHash.value(varExp); |
| 9033 |
if (useCount <= 1) { |
| 9034 |
reductionVarIdxSet.insertMulti(varExp, idx); |
| 9035 |
} |
| 9036 |
} |
| 9037 |
} |
| 9038 |
} |
| 9039 |
} |
| 9040 |
|
| 9041 |
COptimizedComplexBuildingClassVariableCompositionsItem* buildingClassVarItem = dynamic_cast<COptimizedComplexBuildingClassVariableCompositionsItem*>(buildVarItem); |
| 9042 |
if (buildingClassVarItem) { |
| 9043 |
|
| 9044 |
if (mConfAllowBindingReduction && varCompItem->getVariableMappingsExpectedCount() >= mConfMappingSizeBindingReduction) { |
| 9045 |
// test whether there is no absorption propagation |
| 9046 |
// test whether there exists a variable that is not distinguished, has no remaining properties, and is not used by a remaining item for any variable |
| 9047 |
QSet<CClassVariableExpression*>* allVarExpSet = buildingClassVarItem->getAllVariableSet(); |
| 9048 |
|
| 9049 |
|
| 9050 |
QHash<CExpressionVariable*, cint64> varUseCountHash; |
| 9051 |
|
| 9052 |
for (CClassVariableExpression* varExp : *allVarExpSet) { |
| 9053 |
|
| 9054 |
QSet<QPair<CExpressionVariable*, CExpressionVariable*>> remSubSuperPropSet = buildingClassVarItem->getVariableRemainingSubSuperPropagationSet(varExp); |
| 9055 |
QSet<COptimizedComplexVariableCompositionItem*>* remainingItemSet = varExpVarComItemHash->value(varExp); |
| 9056 |
|
| 9057 |
if (remainingItemSet) { |
| 9058 |
bool investigateVarItemMappings = false; |
| 9059 |
if (!remSubSuperPropSet.isEmpty()) { |
| 9060 |
varUseCountHash[varExp] += 2; |
| 9061 |
investigateVarItemMappings = true; |
| 9062 |
} |
| 9063 |
if (remainingItemSet->size() > 1) { |
| 9064 |
investigateVarItemMappings = true; |
| 9065 |
} |
| 9066 |
if (!investigateVarItemMappings && remainingItemSet->size() == 1) { |
| 9067 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> firstOtherItemIndexMappings = buildingIndiVarItem->getVariableItemIndexMapping(varExp).values(*remainingItemSet->begin()); |
| 9068 |
if (firstOtherItemIndexMappings.size() > 1) { |
| 9069 |
investigateVarItemMappings = true; |
| 9070 |
} |
| 9071 |
} |
| 9072 |
|
| 9073 |
if (investigateVarItemMappings) { |
| 9074 |
for (COptimizedComplexVariableCompositionItem* remainingItem : *remainingItemSet) { |
| 9075 |
if (remainingItem) { |
| 9076 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> otherItemIndexMappings = buildingIndiVarItem->getVariableItemIndexMapping(varExp).values(remainingItem); |
| 9077 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping* otherItemIndexMapping : otherItemIndexMappings) { |
| 9078 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator otherIt = otherItemIndexMapping->constBegin(), otherItEnd = otherItemIndexMapping->constEnd(); otherIt != otherItEnd; ++otherIt) { |
| 9079 |
CExpressionVariable* otherVarExp = otherIt.value(); |
| 9080 |
varUseCountHash[otherVarExp]++; |
| 9081 |
} |
| 9082 |
} |
| 9083 |
} |
| 9084 |
} |
| 9085 |
} |
| 9086 |
} |
| 9087 |
|
| 9088 |
} |
| 9089 |
|
| 9090 |
|
| 9091 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 9092 |
cint64 idx = it.key(); |
| 9093 |
CExpressionVariable* varExp = it.value(); |
| 9094 |
CClassVariableExpression* classVarExp = dynamic_cast<CClassVariableExpression*>(varExp); |
| 9095 |
if (classVarExp) { |
| 9096 |
cint64 useCount = varUseCountHash.value(varExp); |
| 9097 |
if (useCount <= 1) { |
| 9098 |
reductionVarIdxSet.insertMulti(varExp, idx); |
| 9099 |
} |
| 9100 |
} |
| 9101 |
} |
| 9102 |
} |
| 9103 |
} |
| 9104 |
|
| 9105 |
return reductionVarIdxSet; |
| 9106 |
} |
| 9107 |
|
| 9108 |
|
| 9109 |
CConcept* COptimizedComplexExpressionAnsweringHandler::getAbsorbExistentialQueryPartRestrictedTopPropagationConcept(COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* data, CAnswererContext* answererContext) { |
| 9110 |
CConcept* resTopPropCon = data->getRestrictedTopPropagationConcept(); |
| 9111 |
if (!resTopPropCon && !data->hasRestrictedTopPropagationConceptChecked()) { |
| 9112 |
CConcept* initCon = data->getInitializerConcept(); |
| 9113 |
if (initCon) { |
| 9114 |
CRole* topRole = mOntoAnsweringItem->getOntology()->getDataBoxes()->getRBox()->getTopObjectRole(); |
| 9115 |
QList<TConceptNegPair> invConNegList; |
| 9116 |
invConNegList.append(TConceptNegPair(initCon, false)); |
| 9117 |
while (!invConNegList.isEmpty() && !resTopPropCon) { |
| 9118 |
TConceptNegPair conNegPair = invConNegList.takeFirst(); |
| 9119 |
CConcept* concept = conNegPair.first; |
| 9120 |
bool conNeg = conNegPair.second; |
| 9121 |
CConceptOperator* conOp = concept->getConceptOperator(); |
| 9122 |
cint64 opCode = concept->getOperatorCode(); |
| 9123 |
if (!conNeg && conOp->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_ALL_AQALL_TYPE)) { |
| 9124 |
CRole* role = concept->getRole(); |
| 9125 |
if (role == topRole) { |
| 9126 |
resTopPropCon = concept; |
| 9127 |
} |
| 9128 |
} else if (!conNeg && conOp->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_TRIG_AND_AQAND_TYPE)) { |
| 9129 |
for (CSortedNegLinker<CConcept*>* opConLinkerIt = concept->getOperandList(); opConLinkerIt; opConLinkerIt = opConLinkerIt->getNext()) { |
| 9130 |
CConcept* opCon = opConLinkerIt->getData(); |
| 9131 |
bool opConNeg = opConLinkerIt->isNegated(); |
| 9132 |
invConNegList.append(TConceptNegPair(opCon, opConNeg)); |
| 9133 |
} |
| 9134 |
} |
| 9135 |
|
| 9136 |
} |
| 9137 |
} |
| 9138 |
data->setRestrictedTopPropagationConcept(resTopPropCon); |
| 9139 |
data->setRestrictedTopPropagationConceptChecked(true); |
| 9140 |
} |
| 9141 |
return resTopPropCon; |
| 9142 |
} |
| 9143 |
|
| 9144 |
|
| 9145 |
|
| 9146 |
|
| 9147 |
|
| 9148 |
void COptimizedComplexExpressionAnsweringHandler::absorbExistentialQueryPart(COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* data, CAnswererContext* answererContext) { |
| 9149 |
QHash<CConcept*, COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*>* propagationFinalizationConceptAbsorptionDataHash = mOntoAnsweringItem->getPropagationFinalizationConceptAbsorptionDataHash(); |
| 9150 |
QStringList varList; |
| 9151 |
if (mConfExtendedLogging) { |
| 9152 |
for (CExpressionVariable* var : *data->getAbsorptionVariableSet()) { |
| 9153 |
varList.append(var->getName()); |
| 9154 |
} |
| 9155 |
} |
| 9156 |
COccurrenceStatisticsCacheReader* occStatsCacheReader = answererContext->getAnsweringCalculationHandler()->getOccurrenceStatisticsCacheReader(); |
| 9157 |
if (mConfVariablePreAbsorption) { |
| 9158 |
COptimizedComplexVariablePreAbsorptionBasedQueryPartHandler preAbsorptionHandler(data, mOntoAnsweringItem, occStatsCacheReader); |
| 9159 |
preAbsorptionHandler.readConfig(mOntoAnsweringItem->getCalculationConfiguration()); |
| 9160 |
cint64 prevConCount = mOntoAnsweringItem->getTestingOntology()->getTBox()->getNextConceptID(); |
| 9161 |
preAbsorptionHandler.absorbQueryPart(); |
| 9162 |
cint64 newConCount = mOntoAnsweringItem->getTestingOntology()->getTBox()->getNextConceptID(); |
| 9163 |
if (mConfExtendedLogging) { |
| 9164 |
LOG(INFO, getDomain(), logTr("Preabsorbed existential query part consiting of variables %1 with %2 concepts.").arg(varList.join(", ")).arg(newConCount - prevConCount), this); |
| 9165 |
} |
| 9166 |
|
| 9167 |
} |
| 9168 |
|
| 9169 |
COptimizedComplexVariableBindingAbsorptionBasedQueryPartHandler absorptionHandler(data, mOntoAnsweringItem, occStatsCacheReader); |
| 9170 |
absorptionHandler.readConfig(mOntoAnsweringItem->getCalculationConfiguration()); |
| 9171 |
cint64 prevConCount = mOntoAnsweringItem->getTestingOntology()->getTBox()->getNextConceptID(); |
| 9172 |
absorptionHandler.absorbQueryPart(); |
| 9173 |
cint64 newConCount = mOntoAnsweringItem->getTestingOntology()->getTBox()->getNextConceptID(); |
| 9174 |
if (mConfExtendedLogging) { |
| 9175 |
LOG(INFO, getDomain(), logTr("Absorbed existential query part consisting of variables %1 with %2 concepts (%3 is initialization and %4 is first binding variable).").arg(varList.join(", ")).arg(newConCount - prevConCount).arg(data->getInitializerVariableExpression()->getName()).arg(data->getBindingPropagationStartVariableExpression()->getName()), this); |
| 9176 |
} |
| 9177 |
|
| 9178 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incExistentialQueryPartAbsorptionCount(); |
| 9179 |
|
| 9180 |
|
| 9181 |
CConcept* propFinalConcept = data->getPropagationFinalizationConcept(); |
| 9182 |
propagationFinalizationConceptAbsorptionDataHash->insert(propFinalConcept, data); |
| 9183 |
} |
| 9184 |
|
| 9185 |
|
| 9186 |
|
| 9187 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildAbsorbedPartHandlingItem(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHanldingQueryPart, QHash<CExpressionVariable *, QSet<COptimizedComplexVariableCompositionItem *> *>* varExpVarComItemHash, bool* processing) { |
| 9188 |
COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absorptionPropagationItem = new COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem(absorptionHanldingQueryPart); |
| 9189 |
absorptionPropagationItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 9190 |
QList<COptimizedComplexVariableCompositionItem*> computationDependentItemList; |
| 9191 |
|
| 9192 |
|
| 9193 |
QSet<CExpressionVariable*>* preparationVarSet = absorptionHanldingQueryPart->getPrepareVariableSet(); |
| 9194 |
QSet<CExpressionVariable*>* indiVarSet = absorptionHanldingQueryPart->getIndividualBindingsVariableSet(); |
| 9195 |
|
| 9196 |
QSet<CExpressionVariable*> useVarSet(*preparationVarSet); |
| 9197 |
useVarSet = useVarSet.unite(*indiVarSet); |
| 9198 |
|
| 9199 |
QList<CExpressionVariable*> indiIntVarList = indiVarSet->toList(); |
| 9200 |
CExpressionVariable* initializationVar = absorptionHanldingQueryPart->getInitializerVariableExpression(); |
| 9201 |
if (!useVarSet.contains(initializationVar)) { |
| 9202 |
indiIntVarList.append(initializationVar); |
| 9203 |
} |
| 9204 |
|
| 9205 |
QHash<CExpressionVariable*, CVariable*>* variableExpressionVariableHash = absorptionHanldingQueryPart->getVariableExpressionVariableHash(); |
| 9206 |
|
| 9207 |
|
| 9208 |
|
| 9209 |
|
| 9210 |
QHash<CConcept*, COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem*>* propagationFinalizationConceptAbsorptionItemHash = mOntoAnsweringItem->getPropagationFinalizationConceptAbsorptionItemHash(); |
| 9211 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* extendItemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 9212 |
cint64 nextVariableIdx = 0; |
| 9213 |
COptimizedComplexVariableIndividualMappings* newPropVarMapping = new COptimizedComplexVariableIndividualMappingsHash(indiVarSet->size()); |
| 9214 |
|
| 9215 |
QHash<CVariable*, cint64>* variableIndexHash = absorptionPropagationItem->getVariableIndexHash(); |
| 9216 |
|
| 9217 |
QSet<COptimizedComplexVariableCompositionItem*>* integratedItemSet = absorptionPropagationItem->getIntegratedVariableCompositionItemSet(); |
| 9218 |
|
| 9219 |
CExpressionVariable* initializingVarExp = absorptionHanldingQueryPart->getInitializerVariableExpression(); |
| 9220 |
|
| 9221 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9222 |
QStringList prevItemsStringList; |
| 9223 |
#endif |
| 9224 |
|
| 9225 |
cint64 omputationItemDepth = 0; |
| 9226 |
|
| 9227 |
for (CExpressionVariable* indiVarExp : useVarSet) { |
| 9228 |
COptimizedComplexVariableCompositionItem* varCompItem = buildingVarItem->getVariableLastCompositionItem(indiVarExp); |
| 9229 |
computationDependentItemList.append(varCompItem); |
| 9230 |
varCompItem->addComputationSuccessorItem(absorptionPropagationItem); |
| 9231 |
omputationItemDepth = qMax(omputationItemDepth, varCompItem->getComputationItemDepth() + 1); |
| 9232 |
|
| 9233 |
CExpressionVariable* associatedVariableExpression = buildingVarItem->getVariableLastCompositionItemAssociatedVariableExpression(indiVarExp); |
| 9234 |
|
| 9235 |
if (!integratedItemSet->contains(varCompItem) && indiVarSet->contains(indiVarExp)) { |
| 9236 |
integratedItemSet->insert(varCompItem); |
| 9237 |
} |
| 9238 |
|
| 9239 |
CVariable* variable = variableExpressionVariableHash->value(indiVarExp); |
| 9240 |
absorptionPropagationItem->setVariableCompositionItem(variable, varCompItem); |
| 9241 |
absorptionPropagationItem->setVariableExpressionCompositionItem(indiVarExp, varCompItem); |
| 9242 |
|
| 9243 |
propagationFinalizationConceptAbsorptionItemHash->insert(absorptionHanldingQueryPart->getPropagationFinalizationConcept(), absorptionPropagationItem); |
| 9244 |
|
| 9245 |
// in principle there can be several item index mappings, but at this stage they should already be joined, hence only one remaining for that item |
| 9246 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* varIndexMapping = buildingVarItem->getVariableItemIndexMapping(associatedVariableExpression).value(varCompItem); |
| 9247 |
|
| 9248 |
cint64 varPos = -1; |
| 9249 |
if (varIndexMapping) { |
| 9250 |
varPos = varIndexMapping->getSearchedVariablePosition(indiVarExp); |
| 9251 |
} |
| 9252 |
|
| 9253 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 9254 |
if (varMapping->getBindingCount() > 0) { |
| 9255 |
if (indiVarSet->contains(indiVarExp)) { |
| 9256 |
variableIndexHash->insertMulti(variable, nextVariableIdx); |
| 9257 |
newPropVarMapping->setBindingMapping(nextVariableIdx, varMapping->getBindingMapping(varPos)); |
| 9258 |
extendItemIndexMapping->insert(nextVariableIdx++, indiVarExp); |
| 9259 |
} |
| 9260 |
} else { |
| 9261 |
buildingVarItem->setSatisfiability(false); |
| 9262 |
} |
| 9263 |
|
| 9264 |
|
| 9265 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9266 |
QStringList debugVariableNamePrevItemStringList = debugGetItemVariableNames(buildingVarItem, associatedVariableExpression, varCompItem); |
| 9267 |
prevItemsStringList += "[" + debugVariableNamePrevItemStringList.join(", ") + "] of step " + QString::number(varCompItem->getComputationStepId()); |
| 9268 |
#endif |
| 9269 |
|
| 9270 |
} |
| 9271 |
absorptionPropagationItem->setVariableMapping(newPropVarMapping); |
| 9272 |
absorptionPropagationItem->setComputationDependentItemList(computationDependentItemList); |
| 9273 |
absorptionPropagationItem->setComputationItemDepth(omputationItemDepth); |
| 9274 |
addUsedVariableCompositionItem(buildingVarItem, absorptionPropagationItem); |
| 9275 |
|
| 9276 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(initializingVarExp); |
| 9277 |
varItemIndexMapping.insert(absorptionPropagationItem, extendItemIndexMapping); |
| 9278 |
varExpVarComItemHash->value(initializingVarExp)->insert(absorptionPropagationItem); |
| 9279 |
|
| 9280 |
|
| 9281 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9282 |
QStringList debugVariableNameNewItemStringList = debugGetItemVariableNames(buildingVarItem, initializingVarExp, absorptionPropagationItem); |
| 9283 |
absorptionPropagationItem->debugVariableNameStringList = debugVariableNameNewItemStringList; |
| 9284 |
absorptionPropagationItem->debugCreationString = QString("Computation step %1").arg(absorptionPropagationItem->getComputationStepId()) + " with [" + debugVariableNameNewItemStringList.join(", ") + "] absorption propagation based on { " + prevItemsStringList.join(" }, { ") + " } "; |
| 9285 |
debugCreationStringList += absorptionPropagationItem->debugCreationString; |
| 9286 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 9287 |
#endif |
| 9288 |
|
| 9289 |
|
| 9290 |
|
| 9291 |
if (buildingVarItem->isSatisfiable()) { |
| 9292 |
|
| 9293 |
if (!absorptionPropagationItem->isVariableMappingsInitialized()) { |
| 9294 |
absorptionPropagationItem->setVariableMappingsInitialized(true); |
| 9295 |
// schedule item processing |
| 9296 |
queueVariableItemComputation(buildingVarItem, absorptionPropagationItem); |
| 9297 |
|
| 9298 |
if (processing) { |
| 9299 |
*processing = true; |
| 9300 |
} |
| 9301 |
} |
| 9302 |
} |
| 9303 |
return QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(absorptionPropagationItem, extendItemIndexMapping); |
| 9304 |
} |
| 9305 |
|
| 9306 |
|
| 9307 |
|
| 9308 |
|
| 9309 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildQueryTransferringVariableExtractionItem(COptimizedComplexBuildingVariableCompositionsItem* extractionBuildingVarItem, CExpressionVariable* extractionVarExp, COptimizedComplexVariableCompositionItem* extractionVarCompItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* extractionItemIndexMapping, COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CExpressionVariable* varExp, bool* processing) { |
| 9310 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& extractionVarItemIndexMapping = extractionBuildingVarItem->getVariableItemIndexMapping(extractionVarExp); |
| 9311 |
|
| 9312 |
if (!extractionItemIndexMapping) { |
| 9313 |
extractionItemIndexMapping = extractionVarItemIndexMapping.value(extractionVarCompItem); |
| 9314 |
} |
| 9315 |
|
| 9316 |
cint64 extractionVarId = 0; |
| 9317 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = extractionItemIndexMapping->constBegin(), itEnd = extractionItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 9318 |
cint64 varInd = it.key(); |
| 9319 |
CExpressionVariable* varExp = it.value(); |
| 9320 |
if (varExp == extractionVarExp) { |
| 9321 |
extractionVarId = varInd; |
| 9322 |
break; |
| 9323 |
} |
| 9324 |
} |
| 9325 |
|
| 9326 |
|
| 9327 |
COptimizedComplexVariableExtractionItem*& varRedItem = extractionVarCompItem->getExtractionItem(extractionVarId); |
| 9328 |
bool created = false; |
| 9329 |
if (!varRedItem) { |
| 9330 |
varRedItem = new COptimizedComplexVariableExtractionItem(extractionVarCompItem, extractionVarId); |
| 9331 |
created = true; |
| 9332 |
varRedItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 9333 |
varRedItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 9334 |
} |
| 9335 |
addUsedVariableCompositionItem(buildingVarItem, varRedItem); |
| 9336 |
|
| 9337 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* redItemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 9338 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 9339 |
redItemIndexMapping->insert(0, varExp); |
| 9340 |
varItemIndexMapping.insertMulti(varRedItem, redItemIndexMapping); |
| 9341 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9342 |
varRedItem->debugVarItemIndexMapping = redItemIndexMapping; |
| 9343 |
#endif |
| 9344 |
|
| 9345 |
COptimizedComplexVariableIndividualMappings* redVarMapping = nullptr; |
| 9346 |
if (created) { |
| 9347 |
redVarMapping = new COptimizedComplexVariableIndividualMappingsHash(1); |
| 9348 |
COptimizedComplexVariableIndividualMappings* varMapping = extractionVarCompItem->getVariableMapping(); |
| 9349 |
redVarMapping->setBindingMapping(0, varMapping->getBindingMapping(extractionVarId)); |
| 9350 |
} |
| 9351 |
|
| 9352 |
|
| 9353 |
|
| 9354 |
if (!varRedItem->isVariableMappingsInitialized()) { |
| 9355 |
varRedItem->setVariableMappingsInitialized(true); |
| 9356 |
// schedule item processing |
| 9357 |
queueVariableItemComputation(buildingVarItem, varRedItem); |
| 9358 |
if (processing) { |
| 9359 |
*processing = true; |
| 9360 |
} |
| 9361 |
} |
| 9362 |
|
| 9363 |
if (created) { |
| 9364 |
varRedItem->setVariableMapping(redVarMapping); |
| 9365 |
} |
| 9366 |
|
| 9367 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 9368 |
varExpVarComItemHash->value(varExp)->insert(varRedItem); |
| 9369 |
|
| 9370 |
|
| 9371 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9372 |
QStringList debugVariableNamePrevItemStringList = debugGetItemVariableNames(extractionBuildingVarItem, extractionVarExp, extractionVarCompItem); |
| 9373 |
QStringList debugVariableNameRedItemStringList = debugGetItemVariableNames(buildingVarItem, varExp, varRedItem); |
| 9374 |
varRedItem->debugVariableNameStringList = debugVariableNameRedItemStringList; |
| 9375 |
varRedItem->debugCreationString = "Computation step " + QString::number(varRedItem->getComputationStepId()) + " with [" + debugVariableNameRedItemStringList.join(", ") + "] obtained by extracting " + extractionVarExp->getName() + " from [" + debugVariableNamePrevItemStringList.join(", ") + "] of step " + QString::number(extractionVarCompItem->getComputationStepId()); |
| 9376 |
debugCreationStringList += varRedItem->debugCreationString; |
| 9377 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 9378 |
#endif |
| 9379 |
|
| 9380 |
|
| 9381 |
buildingVarItem->updateLastHandledVariableItemAssociation(varExp, varRedItem); |
| 9382 |
|
| 9383 |
return QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(varRedItem, redItemIndexMapping); |
| 9384 |
} |
| 9385 |
|
| 9386 |
|
| 9387 |
|
| 9388 |
|
| 9389 |
|
| 9390 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildVariableReductionItem(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CExpressionVariable* propVarExp, bool allopReductionForVar, COptimizedComplexVariableCompositionItem* varCompItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping, QHash<CExpressionVariable*, cint64>& reductionVarExpIndHash, bool* processing) { |
| 9391 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 9392 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(propVarExp); |
| 9393 |
|
| 9394 |
if (!itemIndexMapping) { |
| 9395 |
itemIndexMapping = varItemIndexMapping.value(varCompItem); |
| 9396 |
} |
| 9397 |
|
| 9398 |
if (!reductionVarExpIndHash.isEmpty()) { |
| 9399 |
|
| 9400 |
QMap<cint64,cint64> reductionVarIdxMap; |
| 9401 |
cint64 nextRedNumber = 0; |
| 9402 |
CExpressionVariable* redExpVar = nullptr; |
| 9403 |
for (QHash<CExpressionVariable*, cint64>::iterator it = reductionVarExpIndHash.begin(); it != reductionVarExpIndHash.end(); ) { |
| 9404 |
CExpressionVariable* expVar = it.key(); |
| 9405 |
cint64 varIdx = it.value(); |
| 9406 |
if (allopReductionForVar || expVar != propVarExp) { |
| 9407 |
reductionVarIdxMap.insert(varIdx, nextRedNumber++); |
| 9408 |
it = reductionVarExpIndHash.erase(it); |
| 9409 |
redExpVar = expVar; |
| 9410 |
} else { |
| 9411 |
++it; |
| 9412 |
} |
| 9413 |
} |
| 9414 |
|
| 9415 |
|
| 9416 |
|
| 9417 |
cint64 redNumber = 0; |
| 9418 |
while (!reductionVarIdxMap.isEmpty()) { |
| 9419 |
|
| 9420 |
|
| 9421 |
QMap<cint64, cint64>::iterator redIt = reductionVarIdxMap.begin(); |
| 9422 |
cint64 nextRedIdx = redIt.key(); |
| 9423 |
cint64 correctedRedIdx = nextRedIdx - redNumber++; |
| 9424 |
redIt = reductionVarIdxMap.erase(redIt); |
| 9425 |
|
| 9426 |
|
| 9427 |
COptimizedComplexVariableReductionItem*& varRedItem = varCompItem->getReductionItem(correctedRedIdx); |
| 9428 |
bool created = false; |
| 9429 |
if (!varRedItem) { |
| 9430 |
varRedItem = new COptimizedComplexVariableReductionItem(varCompItem, correctedRedIdx); |
| 9431 |
created = true; |
| 9432 |
varRedItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 9433 |
varRedItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 9434 |
} |
| 9435 |
addUsedVariableCompositionItem(buildingVarItem, varRedItem); |
| 9436 |
|
| 9437 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* redItemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 9438 |
varItemIndexMapping.insertMulti(varRedItem, redItemIndexMapping); |
| 9439 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9440 |
varRedItem->debugVarItemIndexMapping = redItemIndexMapping; |
| 9441 |
#endif |
| 9442 |
|
| 9443 |
cint64 newIdx = itemIndexMapping->size(); |
| 9444 |
CExpressionVariable* redVarExp = nullptr; |
| 9445 |
COptimizedComplexVariableIndividualMappings* redVarMapping = nullptr; |
| 9446 |
if (created) { |
| 9447 |
redVarMapping = new COptimizedComplexVariableIndividualMappingsHash(newIdx - 1); |
| 9448 |
} |
| 9449 |
|
| 9450 |
cint64 nextIdx = 0; |
| 9451 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 9452 |
for (cint64 i = 0; i < itemIndexMapping->size(); ++i) { |
| 9453 |
CExpressionVariable* indVarExp = itemIndexMapping->value(i); |
| 9454 |
if (i != correctedRedIdx) { |
| 9455 |
redItemIndexMapping->insert(nextIdx, indVarExp); |
| 9456 |
if (created) { |
| 9457 |
redVarMapping->setBindingMapping(nextIdx++, varMapping->getBindingMapping(i)); |
| 9458 |
} else { |
| 9459 |
nextIdx++; |
| 9460 |
} |
| 9461 |
} else { |
| 9462 |
redVarExp = indVarExp; |
| 9463 |
} |
| 9464 |
} |
| 9465 |
|
| 9466 |
if (!varRedItem->isVariableMappingsInitialized()) { |
| 9467 |
varRedItem->setVariableMappingsInitialized(true); |
| 9468 |
// schedule item processing |
| 9469 |
queueVariableItemComputation(buildingVarItem, varRedItem); |
| 9470 |
if (processing) { |
| 9471 |
*processing = true; |
| 9472 |
} |
| 9473 |
} |
| 9474 |
|
| 9475 |
if (created) { |
| 9476 |
varRedItem->setVariableMapping(redVarMapping); |
| 9477 |
} |
| 9478 |
|
| 9479 |
varExpVarComItemHash->value(propVarExp)->remove(varCompItem); |
| 9480 |
varExpVarComItemHash->value(propVarExp)->insert(varRedItem); |
| 9481 |
|
| 9482 |
|
| 9483 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9484 |
QStringList debugVariableNamePrevItemStringList = debugGetItemVariableNames(buildingVarItem, propVarExp, varCompItem); |
| 9485 |
QStringList debugVariableNameRedItemStringList = debugGetItemVariableNames(buildingVarItem, propVarExp, varRedItem); |
| 9486 |
varRedItem->debugVariableNameStringList = debugVariableNameRedItemStringList; |
| 9487 |
varRedItem->debugCreationString = "Computation step " + QString::number(varRedItem->getComputationStepId()) + " with [" + debugVariableNameRedItemStringList.join(", ") + "] obtained by reducing " + redVarExp->getName() + " from [" + debugVariableNamePrevItemStringList.join(", ") + "] of step " + QString::number(varCompItem->getComputationStepId()); |
| 9488 |
debugCreationStringList += varRedItem->debugCreationString; |
| 9489 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 9490 |
#endif |
| 9491 |
|
| 9492 |
|
| 9493 |
buildingVarItem->updateLastHandledVariableItemAssociation(propVarExp, varRedItem); |
| 9494 |
if (!allopReductionForVar) { |
| 9495 |
buildingVarItem->clearLastHandledVariableItemAssociation(redExpVar); |
| 9496 |
} |
| 9497 |
|
| 9498 |
varItemIndexMapping.removeItemVariableExpressionMapping(varCompItem, itemIndexMapping); |
| 9499 |
|
| 9500 |
varCompItem = varRedItem; |
| 9501 |
itemIndexMapping = redItemIndexMapping; |
| 9502 |
|
| 9503 |
} |
| 9504 |
} |
| 9505 |
|
| 9506 |
return QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(varCompItem, itemIndexMapping); |
| 9507 |
} |
| 9508 |
|
| 9509 |
|
| 9510 |
|
| 9511 |
|
| 9512 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildVariableRolePropagationItem(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CIndividualVariableExpression* varExp, COptimizedComplexVariableCompositionItem* varCompItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping, QHash<CExpressionVariable*, cint64>& reductionVarExpIndHash, CObjectPropertyAssertionExpression* propAss, bool* processing, CAnswererContext* answererContext) { |
| 9513 |
|
| 9514 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 9515 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 9516 |
|
| 9517 |
CRole* role = mOntoAnsweringItem->getOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propAss->getObjectPropertyTermExpression()); |
| 9518 |
bool inversed = false; |
| 9519 |
if (propAss->getFirstIndividualTermExpression() != varExp) { |
| 9520 |
inversed = true; |
| 9521 |
} |
| 9522 |
|
| 9523 |
|
| 9524 |
if (mConfExtendedLogging) { |
| 9525 |
QString roleName = "?"; |
| 9526 |
if (role->getPropertyNameLinker()) { |
| 9527 |
roleName = CIRIName::getRecentIRIName(role->getPropertyNameLinker()); |
| 9528 |
if (inversed) { |
| 9529 |
roleName = roleName + " inversed"; |
| 9530 |
} |
| 9531 |
} else if (role->getInverseRole() && role->getInverseRole()->getPropertyNameLinker()) { |
| 9532 |
roleName = CIRIName::getRecentIRIName(role->getInverseRole()->getPropertyNameLinker()); |
| 9533 |
if (!inversed) { |
| 9534 |
roleName = roleName + " inversed"; |
| 9535 |
} |
| 9536 |
} |
| 9537 |
LOG(INFO, getDomain(), logTr("Scheduling propagation of mappings associated with %1 over role %2.").arg(varExp->getName()).arg(roleName), this); |
| 9538 |
} |
| 9539 |
|
| 9540 |
|
| 9541 |
CIndividualVariableExpression* otherExp = buildingVarItem->getOtherVariableExpression(varExp, propAss); |
| 9542 |
if (!itemIndexMapping) { |
| 9543 |
itemIndexMapping = varItemIndexMapping.value(varCompItem); |
| 9544 |
} |
| 9545 |
bool propToVarExpAlreadyPresent = false; |
| 9546 |
cint64 varIdx = 0; |
| 9547 |
cint64 propToVarIdx = itemIndexMapping->size(); |
| 9548 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 9549 |
cint64 idx = it.key(); |
| 9550 |
CExpressionVariable* testVarExp = it.value(); |
| 9551 |
if (testVarExp == otherExp) { |
| 9552 |
propToVarExpAlreadyPresent = true; |
| 9553 |
propToVarIdx = idx; |
| 9554 |
} |
| 9555 |
if (varExp == testVarExp) { |
| 9556 |
varIdx = idx; |
| 9557 |
} |
| 9558 |
} |
| 9559 |
|
| 9560 |
bool replacement = false; |
| 9561 |
if (!propToVarExpAlreadyPresent && mConfPropagationReplacement && reductionVarExpIndHash.value(varExp, -1) == varIdx) { |
| 9562 |
replacement = true; |
| 9563 |
} |
| 9564 |
if (propToVarExpAlreadyPresent && !mConfPropagationJoining) { |
| 9565 |
propToVarExpAlreadyPresent = false; |
| 9566 |
} |
| 9567 |
|
| 9568 |
cint64 newVarIdx = varIdx; |
| 9569 |
cint64 newVarCount = itemIndexMapping->size(); |
| 9570 |
|
| 9571 |
COptimizedComplexVariableIndividualMappings* varMapping = varCompItem->getVariableMapping(); |
| 9572 |
|
| 9573 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9574 |
QString withJoinReplacing; |
| 9575 |
#endif |
| 9576 |
|
| 9577 |
|
| 9578 |
bool created = false; |
| 9579 |
COptimizedComplexVariableRolePropagationAbstractItem* varRolePropItem = nullptr; |
| 9580 |
if (!propToVarExpAlreadyPresent) { |
| 9581 |
if (replacement) { |
| 9582 |
COptimizedComplexVariableRolePropagationReplacementItem*& replacementVarRolePropItem = varCompItem->getRoleInversePropagationReplacementItem(role, inversed, varIdx, varIdx); |
| 9583 |
if (!replacementVarRolePropItem) { |
| 9584 |
replacementVarRolePropItem = new COptimizedComplexVariableRolePropagationReplacementItem(varCompItem, role, inversed, varIdx, varIdx); |
| 9585 |
created = true; |
| 9586 |
} |
| 9587 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9588 |
withJoinReplacing = " with replacement "; |
| 9589 |
#endif |
| 9590 |
|
| 9591 |
varRolePropItem = replacementVarRolePropItem; |
| 9592 |
} else { |
| 9593 |
newVarIdx = itemIndexMapping->size(); |
| 9594 |
newVarCount = itemIndexMapping->size() + 1; |
| 9595 |
COptimizedComplexVariableRolePropagationItem*& newVarRolePropItem = varCompItem->getRoleInversePropagationItem(role, inversed, varIdx); |
| 9596 |
if (!newVarRolePropItem) { |
| 9597 |
newVarRolePropItem = new COptimizedComplexVariableRolePropagationItem(varCompItem, role, inversed, varIdx); |
| 9598 |
created = true; |
| 9599 |
} |
| 9600 |
varRolePropItem = newVarRolePropItem; |
| 9601 |
} |
| 9602 |
} else { |
| 9603 |
COptimizedComplexVariableRolePropagationJoiningItem*& joinVarRolePropItem = varCompItem->getRoleInversePropagationJoiningItem(role, inversed, varIdx, propToVarIdx); |
| 9604 |
newVarIdx = propToVarIdx; |
| 9605 |
if (!joinVarRolePropItem) { |
| 9606 |
joinVarRolePropItem = new COptimizedComplexVariableRolePropagationJoiningItem(varCompItem, role, inversed, varIdx, propToVarIdx); |
| 9607 |
created = true; |
| 9608 |
} |
| 9609 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9610 |
withJoinReplacing = " with joining "; |
| 9611 |
#endif |
| 9612 |
varRolePropItem = joinVarRolePropItem; |
| 9613 |
} |
| 9614 |
addUsedVariableCompositionItem(buildingVarItem, varRolePropItem); |
| 9615 |
if (created) { |
| 9616 |
varRolePropItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 9617 |
varRolePropItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 9618 |
} |
| 9619 |
if (!varRolePropItem->isVariableMappingsInitialized()) { |
| 9620 |
varRolePropItem->setVariableMappingsInitialized(true); |
| 9621 |
// schedule item processing |
| 9622 |
queueVariableItemComputation(buildingVarItem, varRolePropItem); |
| 9623 |
if (processing) { |
| 9624 |
*processing = true; |
| 9625 |
} |
| 9626 |
|
| 9627 |
//// schedule realization requirement processing |
| 9628 |
//CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 9629 |
//QSet<CIndividualReference> individualSet; |
| 9630 |
//class CRoleTargetsRealizationRequirementInstanceItemVisitor : public CSameRealizationIndividualVisitor { |
| 9631 |
//public: |
| 9632 |
// QSet<CIndividualReference>* mInstanceItemSet; |
| 9633 |
|
| 9634 |
// CRoleTargetsRealizationRequirementInstanceItemVisitor(QSet<CIndividualReference>* instanceItemSet) { |
| 9635 |
// mInstanceItemSet = instanceItemSet; |
| 9636 |
// } |
| 9637 |
|
| 9638 |
// bool visitIndividual(const CIndividualReference& indiRef, CSameRealization* sameRealization) { |
| 9639 |
// mInstanceItemSet->insert(indiRef); |
| 9640 |
// return false; |
| 9641 |
// } |
| 9642 |
//} visitor(&individualSet); |
| 9643 |
//for (COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = varMapping->getLastAddedBindingsCardinalityLinker(); linker; linker = linker->getNext()) { |
| 9644 |
// COptimizedComplexVariableIndividualBindings* binding = linker->getBindings(); |
| 9645 |
// CRealizationIndividualInstanceItemReference instItemRef = bindings->getBinding(varIdx).reference; |
| 9646 |
// sameRealization->visitSameIndividuals(instItemRef, &visitor); |
| 9647 |
//} |
| 9648 |
//if (!individualSet.isEmpty()) { |
| 9649 |
// ensureRoleTargetsRealization(role, inversed, individualSet, buildingVarItem, answererContext); |
| 9650 |
//} |
| 9651 |
} |
| 9652 |
|
| 9653 |
|
| 9654 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& propVarItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(otherExp); |
| 9655 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* propItemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 9656 |
propVarItemIndexMapping.insertMulti(varRolePropItem, propItemIndexMapping); |
| 9657 |
|
| 9658 |
COptimizedComplexVariableIndividualMappings* propVarMapping = nullptr; |
| 9659 |
if (created) { |
| 9660 |
if (mConfConcurrentPropagation) { |
| 9661 |
propVarMapping = new COptimizedComplexVariableIndividualMappingsMultiHash(newVarCount, mConcurrentPropagationComputationTaskCount); |
| 9662 |
} else { |
| 9663 |
propVarMapping = new COptimizedComplexVariableIndividualMappingsHash(newVarCount); |
| 9664 |
} |
| 9665 |
} |
| 9666 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = itemIndexMapping->constBegin(), itEnd = itemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 9667 |
cint64 idx = it.key(); |
| 9668 |
CExpressionVariable* propVarExp = it.value(); |
| 9669 |
propItemIndexMapping->insert(idx, propVarExp); |
| 9670 |
if (created) { |
| 9671 |
propVarMapping->setBindingMapping(idx, varMapping->getBindingMapping(idx)); |
| 9672 |
} |
| 9673 |
} |
| 9674 |
propItemIndexMapping->insert(newVarIdx, otherExp); |
| 9675 |
if (created) { |
| 9676 |
propVarMapping->setBindingMapping(newVarIdx, COptimizedComplexVariableIndividualMappings::INDIVIDUAL_VARIABLE); |
| 9677 |
varRolePropItem->setVariableMapping(propVarMapping); |
| 9678 |
} |
| 9679 |
|
| 9680 |
QSet<COptimizedComplexVariableCompositionItem*>*& otherVarCompItemSet = (*varExpVarComItemHash)[otherExp]; |
| 9681 |
if (!otherVarCompItemSet) { |
| 9682 |
otherVarCompItemSet = new QSet<COptimizedComplexVariableCompositionItem*>(); |
| 9683 |
} |
| 9684 |
otherVarCompItemSet->insert(varRolePropItem); |
| 9685 |
|
| 9686 |
|
| 9687 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9688 |
QStringList debugVariableNamePrevItemStringList = debugGetItemVariableNames(buildingVarItem, varExp, varCompItem); |
| 9689 |
QStringList debugVariableNamePropItemStringList = debugGetItemVariableNames(buildingVarItem, otherExp, varRolePropItem); |
| 9690 |
varRolePropItem->debugVariableNameStringList = debugVariableNamePropItemStringList; |
| 9691 |
QString roleName = CIRIName::getRecentIRIName(role->getPropertyNameLinker()); |
| 9692 |
if (inversed) { |
| 9693 |
if (role->getInverseRole()->getPropertyNameLinker()) { |
| 9694 |
roleName = CIRIName::getRecentIRIName(role->getInverseRole()->getPropertyNameLinker()); |
| 9695 |
} else { |
| 9696 |
roleName += "^-"; |
| 9697 |
} |
| 9698 |
} |
| 9699 |
varRolePropItem->debugCreationString = "Computation step " + QString::number(varRolePropItem->getComputationStepId()) + " with [" + debugVariableNamePropItemStringList.join(", ") + "] obtained by propagating " + varExp->getName() + withJoinReplacing + " from ["+debugVariableNamePrevItemStringList.join(", ")+"] of step " + QString::number(varCompItem->getComputationStepId()) + " over role "+ roleName; |
| 9700 |
debugCreationStringList += varRolePropItem->debugCreationString; |
| 9701 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 9702 |
#endif |
| 9703 |
|
| 9704 |
buildingVarItem->updateLastHandledVariableItemAssociation(otherExp, varRolePropItem); |
| 9705 |
|
| 9706 |
return QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(varRolePropItem, propItemIndexMapping); |
| 9707 |
|
| 9708 |
} |
| 9709 |
|
| 9710 |
|
| 9711 |
|
| 9712 |
|
| 9713 |
|
| 9714 |
bool itemMappingSortLessBindingsThan(QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> compItemMapping1Pair, QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> compItemMapping2Pair) { |
| 9715 |
return compItemMapping1Pair.first->getVariableMappingsExpectedCount() < compItemMapping2Pair.first->getVariableMappingsExpectedCount(); |
| 9716 |
} |
| 9717 |
|
| 9718 |
|
| 9719 |
|
| 9720 |
|
| 9721 |
QList<QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>> COptimizedComplexExpressionAnsweringHandler::reuseJoinedVariableCompositionItems(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CExpressionVariable* varExp) { |
| 9722 |
|
| 9723 |
|
| 9724 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 9725 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(varExp); |
| 9726 |
|
| 9727 |
|
| 9728 |
QList<QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>> compItemMappingPairList; |
| 9729 |
for (COptimizedComplexVariableCompositionItemVariableExpressionMapping::const_iterator it = varItemIndexMapping.constBegin(), itEnd = varItemIndexMapping.constEnd(); it != itEnd; ++it) { |
| 9730 |
COptimizedComplexVariableCompositionItem* joiningItem = it.key(); |
| 9731 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = it.value(); |
| 9732 |
compItemMappingPairList.append(QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(joiningItem, itemIndexMapping)); |
| 9733 |
} |
| 9734 |
|
| 9735 |
|
| 9736 |
// sort list |
| 9737 |
qSort(compItemMappingPairList.begin(), compItemMappingPairList.end(), itemMappingSortLessBindingsThan); |
| 9738 |
|
| 9739 |
QList<QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>> compItemMappingPairPreJoinedList; |
| 9740 |
while (!compItemMappingPairList.isEmpty()) { |
| 9741 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> compItemMappingPair = compItemMappingPairList.takeFirst(); |
| 9742 |
COptimizedComplexVariableCompositionItem* joiningItem1 = compItemMappingPair.first; |
| 9743 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping1 = compItemMappingPair.second; |
| 9744 |
|
| 9745 |
bool joined = false; |
| 9746 |
|
| 9747 |
QList<QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>>::iterator it = compItemMappingPairPreJoinedList.begin(); |
| 9748 |
while (it != compItemMappingPairPreJoinedList.end() && !joined) { |
| 9749 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> testedCompItemMappingPair(*it); |
| 9750 |
COptimizedComplexVariableCompositionItem* joiningItem2 = testedCompItemMappingPair.first; |
| 9751 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping2 = testedCompItemMappingPair.second; |
| 9752 |
|
| 9753 |
if (hasVariableJoiningItem(buildingVarItem, varExp, false, joiningItem1, joiningItem2, itemIndexMapping1, itemIndexMapping2)) { |
| 9754 |
joined = true; |
| 9755 |
|
| 9756 |
|
| 9757 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> joinedItemMappingPair = buildVariableJoiningItem(buildingVarItem, varExp, false, joiningItem1, joiningItem2, itemIndexMapping1, itemIndexMapping2, nullptr); |
| 9758 |
compItemMappingPairList.prepend(joinedItemMappingPair); |
| 9759 |
compItemMappingPairPreJoinedList.erase(it); |
| 9760 |
|
| 9761 |
} else { |
| 9762 |
++it; |
| 9763 |
} |
| 9764 |
} |
| 9765 |
if (!joined) { |
| 9766 |
compItemMappingPairPreJoinedList.append(compItemMappingPair); |
| 9767 |
} |
| 9768 |
} |
| 9769 |
|
| 9770 |
qSort(compItemMappingPairPreJoinedList.begin(), compItemMappingPairPreJoinedList.end(), itemMappingSortLessBindingsThan); |
| 9771 |
return compItemMappingPairPreJoinedList; |
| 9772 |
|
| 9773 |
} |
| 9774 |
|
| 9775 |
|
| 9776 |
|
| 9777 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildJoinedVariableJoiningItems(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CExpressionVariable* varExp, bool* processing, bool lastComputationItem) { |
| 9778 |
|
| 9779 |
cint64 joinCount = 0; |
| 9780 |
cint64 reductionCount = 0; |
| 9781 |
|
| 9782 |
QList<QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>> compItemMappingPairPreJoinedList = reuseJoinedVariableCompositionItems(buildingVarItem, varExp); |
| 9783 |
|
| 9784 |
|
| 9785 |
for (cint64 i = 0; i < compItemMappingPairPreJoinedList.size(); ) { |
| 9786 |
|
| 9787 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> compItemMappingPair = compItemMappingPairPreJoinedList.at(i); |
| 9788 |
COptimizedComplexVariableCompositionItem* joiningItem = compItemMappingPair.first; |
| 9789 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = compItemMappingPair.second; |
| 9790 |
QSet<CExpressionVariable*> varExpSet; |
| 9791 |
bool sameVarExpJoiningRequired = false; |
| 9792 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator itMap = itemIndexMapping->constBegin(), itMapEnd = itemIndexMapping->constEnd(); !sameVarExpJoiningRequired && itMap != itMapEnd; ++itMap) { |
| 9793 |
CExpressionVariable* usedVarExp(itMap.value()); |
| 9794 |
if (varExpSet.contains(usedVarExp)) { |
| 9795 |
sameVarExpJoiningRequired = true; |
| 9796 |
} else { |
| 9797 |
varExpSet.insert(usedVarExp); |
| 9798 |
} |
| 9799 |
} |
| 9800 |
if (sameVarExpJoiningRequired) { |
| 9801 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> joinedItemMappingPair = buildVariableJoiningItem(buildingVarItem, varExp, true, joiningItem, joiningItem, itemIndexMapping, itemIndexMapping, processing); |
| 9802 |
compItemMappingPairPreJoinedList.replace(i, joinedItemMappingPair); |
| 9803 |
joinCount++; |
| 9804 |
} else { |
| 9805 |
++i; |
| 9806 |
} |
| 9807 |
} |
| 9808 |
|
| 9809 |
QList<QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>> reducedCompItemMappingPairPreJoinedList; |
| 9810 |
while (!compItemMappingPairPreJoinedList.isEmpty()) { |
| 9811 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> compItemMappingPair = compItemMappingPairPreJoinedList.takeFirst(); |
| 9812 |
COptimizedComplexVariableCompositionItem* joiningItem = compItemMappingPair.first; |
| 9813 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping = compItemMappingPair.second; |
| 9814 |
|
| 9815 |
QHash<CExpressionVariable*, cint64> reductionVarExpIndHash; |
| 9816 |
if (!mConfAllowJoiningBindingReduction) { |
| 9817 |
reductionVarExpIndHash = getReducableVariables(buildingVarItem, varExp, joiningItem, itemIndexMapping); |
| 9818 |
} |
| 9819 |
compItemMappingPair = buildVariableReductionItem(buildingVarItem, varExp, false, joiningItem, itemIndexMapping, reductionVarExpIndHash, processing); |
| 9820 |
|
| 9821 |
if (joiningItem != compItemMappingPair.first) { |
| 9822 |
++reductionCount; |
| 9823 |
} |
| 9824 |
|
| 9825 |
reducedCompItemMappingPairPreJoinedList.append(compItemMappingPair); |
| 9826 |
} |
| 9827 |
|
| 9828 |
|
| 9829 |
|
| 9830 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> compItemMapping1Pair = reducedCompItemMappingPairPreJoinedList.takeFirst(); |
| 9831 |
COptimizedComplexVariableCompositionItem* joiningItem1 = compItemMapping1Pair.first; |
| 9832 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping1 = compItemMapping1Pair.second; |
| 9833 |
|
| 9834 |
while (!reducedCompItemMappingPairPreJoinedList.isEmpty()) { |
| 9835 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> compItemMapping2Pair = reducedCompItemMappingPairPreJoinedList.takeFirst(); |
| 9836 |
COptimizedComplexVariableCompositionItem* joiningItem2 = compItemMapping2Pair.first; |
| 9837 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping2 = compItemMapping2Pair.second; |
| 9838 |
|
| 9839 |
bool lastJoinComputation = lastComputationItem && mConfAllowJoiningBindingReduction && reducedCompItemMappingPairPreJoinedList.isEmpty(); |
| 9840 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> joinedItemMappingPair = buildVariableJoiningItem(buildingVarItem, varExp, false, joiningItem1, joiningItem2, itemIndexMapping1, itemIndexMapping2, processing, lastJoinComputation); |
| 9841 |
|
| 9842 |
QHash<CExpressionVariable*, cint64> reductionVarExpIndHash; |
| 9843 |
if (!mConfAllowJoiningBindingReduction) { |
| 9844 |
reductionVarExpIndHash = getReducableVariables(buildingVarItem, varExp, joinedItemMappingPair.first, joinedItemMappingPair.second); |
| 9845 |
} |
| 9846 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> reducedJoinedItemMappingPair = buildVariableReductionItem(buildingVarItem, varExp, false, joinedItemMappingPair.first, joinedItemMappingPair.second, reductionVarExpIndHash, processing); |
| 9847 |
|
| 9848 |
if (joinedItemMappingPair.first != reducedJoinedItemMappingPair.first) { |
| 9849 |
++reductionCount; |
| 9850 |
} |
| 9851 |
|
| 9852 |
joiningItem1 = reducedJoinedItemMappingPair.first; |
| 9853 |
itemIndexMapping1 = reducedJoinedItemMappingPair.second; |
| 9854 |
joinCount++; |
| 9855 |
} |
| 9856 |
|
| 9857 |
if (mConfExtendedLogging) { |
| 9858 |
LOG(INFO, getDomain(), logTr("Scheduling %2 joins with %3 reductions for items associated with variable %1.").arg(varExp->getName()).arg(joinCount).arg(reductionCount), this); |
| 9859 |
} |
| 9860 |
|
| 9861 |
return QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(joiningItem1, itemIndexMapping1); |
| 9862 |
} |
| 9863 |
|
| 9864 |
|
| 9865 |
|
| 9866 |
|
| 9867 |
|
| 9868 |
|
| 9869 |
|
| 9870 |
|
| 9871 |
|
| 9872 |
|
| 9873 |
|
| 9874 |
bool COptimizedComplexExpressionAnsweringHandler::hasVariableJoiningItem(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CExpressionVariable* varExp, bool itemSameVarReduction, COptimizedComplexVariableCompositionItem* joiningItem1, COptimizedComplexVariableCompositionItem* joiningItem2, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping1, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping2) { |
| 9875 |
|
| 9876 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 9877 |
|
| 9878 |
|
| 9879 |
|
| 9880 |
COptimizedComplexVariableCompositionItem* minLeftItem = qMin(joiningItem1, joiningItem2); |
| 9881 |
COptimizedComplexVariableCompositionItem* maxRightItem = qMax(joiningItem1, joiningItem2); |
| 9882 |
|
| 9883 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* minLeftItemIndexMapping = itemIndexMapping1; |
| 9884 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* maxRightItemIndexMapping = itemIndexMapping2; |
| 9885 |
|
| 9886 |
if (minLeftItem == joiningItem2) { |
| 9887 |
minLeftItemIndexMapping = itemIndexMapping2; |
| 9888 |
maxRightItemIndexMapping = itemIndexMapping1; |
| 9889 |
} |
| 9890 |
|
| 9891 |
COptimizedComplexVariableJoiningBindingPositionMapping joiningBindingPositionMapping(maxRightItem, minLeftItemIndexMapping->size(), maxRightItemIndexMapping->size()); |
| 9892 |
|
| 9893 |
QSet<CExpressionVariable*> reductionVarExpSet = getJoinReducableVariables(buildingVarItem, varExp, minLeftItem, minLeftItemIndexMapping, maxRightItem, maxRightItemIndexMapping, itemSameVarReduction); |
| 9894 |
cint64 nextVarIdx = fillJoiningBindingPositionMapping(minLeftItemIndexMapping, joiningBindingPositionMapping, maxRightItemIndexMapping, itemSameVarReduction, reductionVarExpSet); |
| 9895 |
|
| 9896 |
|
| 9897 |
return minLeftItem->hasJoiningItem(joiningBindingPositionMapping); |
| 9898 |
} |
| 9899 |
|
| 9900 |
|
| 9901 |
|
| 9902 |
|
| 9903 |
|
| 9904 |
|
| 9905 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildVariableJoiningItem(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CExpressionVariable* varExp, bool itemSameVarReduction, COptimizedComplexVariableCompositionItem* joiningItem1, COptimizedComplexVariableCompositionItem* joiningItem2, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping1, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping2, bool* processing, bool lastComputationItem) { |
| 9906 |
return buildVariableJoiningItem(buildingVarItem, varExp, itemSameVarReduction, varExp, joiningItem1, varExp, joiningItem2, itemIndexMapping1, itemIndexMapping2, processing, lastComputationItem); |
| 9907 |
} |
| 9908 |
|
| 9909 |
|
| 9910 |
|
| 9911 |
QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*> COptimizedComplexExpressionAnsweringHandler::buildVariableJoiningItem(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CExpressionVariable* destVarExp, bool itemSameVarReduction, CExpressionVariable* varExp1, COptimizedComplexVariableCompositionItem* joiningItem1, CExpressionVariable* varExp2, COptimizedComplexVariableCompositionItem* joiningItem2, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping1, COptimizedComplexVariableCompositionItemVariableIndexMapping* itemIndexMapping2, bool* processing, bool lastComputationItem) { |
| 9912 |
|
| 9913 |
|
| 9914 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildingVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 9915 |
|
| 9916 |
|
| 9917 |
|
| 9918 |
COptimizedComplexVariableCompositionItem* minLeftItem = joiningItem1; |
| 9919 |
COptimizedComplexVariableCompositionItem* maxRightItem = joiningItem2; |
| 9920 |
|
| 9921 |
CExpressionVariable* minLeftVarExp = varExp1; |
| 9922 |
CExpressionVariable* maxRightVarExp = varExp2; |
| 9923 |
|
| 9924 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* minLeftItemIndexMapping = itemIndexMapping1; |
| 9925 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* maxRightItemIndexMapping = itemIndexMapping2; |
| 9926 |
|
| 9927 |
|
| 9928 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& destVarItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(destVarExp); |
| 9929 |
|
| 9930 |
if (joiningItem2 < joiningItem1) { |
| 9931 |
minLeftItem = joiningItem2; |
| 9932 |
maxRightItem = joiningItem1; |
| 9933 |
|
| 9934 |
minLeftVarExp = varExp2; |
| 9935 |
maxRightVarExp = varExp1; |
| 9936 |
|
| 9937 |
minLeftItemIndexMapping = itemIndexMapping2; |
| 9938 |
maxRightItemIndexMapping = itemIndexMapping1; |
| 9939 |
|
| 9940 |
} |
| 9941 |
|
| 9942 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& minLeftVarItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(minLeftVarExp); |
| 9943 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& maxRightVarItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(maxRightVarExp); |
| 9944 |
|
| 9945 |
|
| 9946 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> minLeftItemIndexMappingList = minLeftVarItemIndexMapping.values(minLeftItem); |
| 9947 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> maxRightItemIndexMappingList = maxRightVarItemIndexMapping.values(maxRightItem); |
| 9948 |
|
| 9949 |
|
| 9950 |
|
| 9951 |
if (!minLeftItemIndexMapping) { |
| 9952 |
minLeftItemIndexMapping = minLeftItemIndexMappingList.first(); |
| 9953 |
} |
| 9954 |
if (!maxRightItemIndexMapping) { |
| 9955 |
maxRightItemIndexMapping = maxRightItemIndexMappingList.first(); |
| 9956 |
} |
| 9957 |
|
| 9958 |
COptimizedComplexVariableJoiningBindingPositionMapping joiningBindingPositionMapping(maxRightItem, minLeftItemIndexMapping->size(), maxRightItemIndexMapping->size()); |
| 9959 |
|
| 9960 |
|
| 9961 |
QSet<CExpressionVariable*> reductionVarExpSet = getJoinReducableVariables(buildingVarItem, destVarExp, minLeftItem, minLeftItemIndexMapping, maxRightItem, maxRightItemIndexMapping, itemSameVarReduction); |
| 9962 |
cint64 nextVarIdx = fillJoiningBindingPositionMapping(minLeftItemIndexMapping, joiningBindingPositionMapping, maxRightItemIndexMapping, itemSameVarReduction, reductionVarExpSet); |
| 9963 |
|
| 9964 |
|
| 9965 |
COptimizedComplexVariableJoiningItem*& joinedItem = minLeftItem->getJoiningItem(joiningBindingPositionMapping); |
| 9966 |
|
| 9967 |
bool createdJoinedItem = false; |
| 9968 |
if (!joinedItem) { |
| 9969 |
createdJoinedItem = true; |
| 9970 |
joinedItem = new COptimizedComplexVariableJoiningItem(minLeftItem, maxRightItem, joiningBindingPositionMapping); |
| 9971 |
joinedItem->setComputationStepId(mOntoAnsweringItem->getNextComputationStepId()); |
| 9972 |
if (lastComputationItem && mConfAllowLastStepSplitComputation) { |
| 9973 |
joinedItem->setVariableMappingsComputationRequirement(mConfLastStepSplitComputationMappingsRequirement); |
| 9974 |
joinedItem->setLastComputation(true); |
| 9975 |
} else { |
| 9976 |
joinedItem->setVariableMappingsComputationRequirement(mConfMinimalMappingsComputationSize); |
| 9977 |
} |
| 9978 |
} |
| 9979 |
addUsedVariableCompositionItem(buildingVarItem, joinedItem); |
| 9980 |
|
| 9981 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* joinedItemIndexMapping = new COptimizedComplexVariableCompositionItemVariableIndexMapping(); |
| 9982 |
COptimizedComplexVariableIndividualMappings* joinedVarMapping = nullptr; |
| 9983 |
if (createdJoinedItem) { |
| 9984 |
if (mConfConcurrentJoining) { |
| 9985 |
joinedVarMapping = new COptimizedComplexVariableIndividualMappingsMultiHash(nextVarIdx, mConcurrentJoinComputationTaskCount); |
| 9986 |
} else { |
| 9987 |
joinedVarMapping = new COptimizedComplexVariableIndividualMappingsHash(nextVarIdx); |
| 9988 |
} |
| 9989 |
} |
| 9990 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 9991 |
joinedItem->debugVarItemIndexMapping = joinedItemIndexMapping; |
| 9992 |
#endif |
| 9993 |
|
| 9994 |
COptimizedComplexVariableIndividualMappings* minLeftVarMapping = minLeftItem->getVariableMapping(); |
| 9995 |
COptimizedComplexVariableIndividualMappings* maxRightVarMapping = maxRightItem->getVariableMapping(); |
| 9996 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = minLeftItemIndexMapping->constBegin(), itEnd = minLeftItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 9997 |
cint64 idx = it.key(); |
| 9998 |
cint64 mappedVarIdx = joiningBindingPositionMapping.getMappedBindingPosition(true, idx); |
| 9999 |
if (mappedVarIdx >= 0) { |
| 10000 |
CExpressionVariable* joinVarExp = it.value(); |
| 10001 |
joinedItemIndexMapping->insert(mappedVarIdx, joinVarExp); |
| 10002 |
if (createdJoinedItem) { |
| 10003 |
joinedVarMapping->setBindingMapping(mappedVarIdx, minLeftVarMapping->getBindingMapping(idx)); |
| 10004 |
} |
| 10005 |
} |
| 10006 |
} |
| 10007 |
if (!itemSameVarReduction) { |
| 10008 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = maxRightItemIndexMapping->constBegin(), itEnd = maxRightItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 10009 |
cint64 idx = it.key(); |
| 10010 |
cint64 mappedVarIdx = joiningBindingPositionMapping.getMappedBindingPosition(false, idx); |
| 10011 |
if (mappedVarIdx >= 0) { |
| 10012 |
CExpressionVariable* joinVarExp = it.value(); |
| 10013 |
joinedItemIndexMapping->insert(mappedVarIdx, joinVarExp); |
| 10014 |
if (createdJoinedItem) { |
| 10015 |
joinedVarMapping->setBindingMapping(mappedVarIdx, maxRightVarMapping->getBindingMapping(idx)); |
| 10016 |
} |
| 10017 |
} |
| 10018 |
} |
| 10019 |
} |
| 10020 |
// insert new mapping |
| 10021 |
if (createdJoinedItem) { |
| 10022 |
joinedItem->setVariableMapping(joinedVarMapping); |
| 10023 |
} |
| 10024 |
destVarItemIndexMapping.insertMulti(joinedItem, joinedItemIndexMapping); |
| 10025 |
|
| 10026 |
|
| 10027 |
varExpVarComItemHash->value(destVarExp)->insert(joinedItem); |
| 10028 |
|
| 10029 |
if (!joinedItem->isVariableMappingsInitialized()) { |
| 10030 |
joinedItem->setVariableMappingsInitialized(true); |
| 10031 |
|
| 10032 |
if (processing) { |
| 10033 |
*processing = true; |
| 10034 |
} |
| 10035 |
// schedule item processing |
| 10036 |
queueVariableItemComputation(buildingVarItem, joinedItem); |
| 10037 |
} |
| 10038 |
|
| 10039 |
#ifdef OPTIMIZED_ANSWERER_DEBUG_STRINGS |
| 10040 |
QStringList debugVariableNameLeftItemStringList = debugGetItemVariableNames(buildingVarItem, minLeftVarExp, minLeftItem); |
| 10041 |
QStringList debugVariableNameRightItemStringList = debugGetItemVariableNames(buildingVarItem, maxRightVarExp, maxRightItem); |
| 10042 |
|
| 10043 |
QStringList debugVariableNameJoinedItemStringList = debugGetItemVariableNames(buildingVarItem, destVarExp, joinedItem); |
| 10044 |
joinedItem->debugVariableNameStringList = debugVariableNameJoinedItemStringList; |
| 10045 |
QString reductionString; |
| 10046 |
QStringList reductionVarStringList; |
| 10047 |
for (CExpressionVariable* varExp : reductionVarExpSet) { |
| 10048 |
reductionVarStringList.append(varExp->getName()); |
| 10049 |
} |
| 10050 |
if (!reductionVarStringList.isEmpty()) { |
| 10051 |
reductionString = QString(" with implicit reduction of variables <%1> ").arg(reductionVarStringList.join(", ")); |
| 10052 |
} |
| 10053 |
joinedItem->debugCreationString = "Computation step " + QString::number(joinedItem->getComputationStepId()) + " with [" + debugVariableNameJoinedItemStringList.join(", ") + "] obtained by joining at " + destVarExp->getName() + reductionString + " from [" + debugVariableNameLeftItemStringList.join(", ") + "] of step " + QString::number(minLeftItem->getComputationStepId()) + " and [" + debugVariableNameRightItemStringList.join(", ") + "] of step " + QString::number(maxRightItem->getComputationStepId()); |
| 10054 |
debugCreationStringList += joinedItem->debugCreationString; |
| 10055 |
debugCreationString = debugCreationStringList.join("\r\n"); |
| 10056 |
#endif |
| 10057 |
|
| 10058 |
|
| 10059 |
// re-add remaining mappings |
| 10060 |
if (minLeftVarExp == destVarExp) { |
| 10061 |
minLeftVarItemIndexMapping.remove(minLeftItem); |
| 10062 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping* mapping : minLeftItemIndexMappingList) { |
| 10063 |
minLeftVarItemIndexMapping.insertMulti(minLeftItem, mapping); |
| 10064 |
} |
| 10065 |
varExpVarComItemHash->value(minLeftVarExp)->remove(minLeftItem); |
| 10066 |
} |
| 10067 |
if (maxRightVarExp == destVarExp) { |
| 10068 |
maxRightVarItemIndexMapping.remove(maxRightItem); |
| 10069 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping* mapping : maxRightItemIndexMappingList) { |
| 10070 |
maxRightVarItemIndexMapping.insertMulti(maxRightItem, mapping); |
| 10071 |
} |
| 10072 |
varExpVarComItemHash->value(maxRightVarExp)->remove(maxRightItem); |
| 10073 |
} |
| 10074 |
buildingVarItem->updateLastHandledVariableItemAssociation(destVarExp, joinedItem); |
| 10075 |
|
| 10076 |
|
| 10077 |
destVarItemIndexMapping.removeItemVariableExpressionMapping(minLeftItem, minLeftItemIndexMapping); |
| 10078 |
destVarItemIndexMapping.removeItemVariableExpressionMapping(maxRightItem, maxRightItemIndexMapping); |
| 10079 |
|
| 10080 |
|
| 10081 |
return QPair<COptimizedComplexVariableCompositionItem*, COptimizedComplexVariableCompositionItemVariableIndexMapping*>(joinedItem, joinedItemIndexMapping); |
| 10082 |
|
| 10083 |
} |
| 10084 |
|
| 10085 |
|
| 10086 |
|
| 10087 |
|
| 10088 |
|
| 10089 |
|
| 10090 |
QSet<CExpressionVariable*> COptimizedComplexExpressionAnsweringHandler::getJoinReducableVariables(COptimizedComplexBuildingVariableCompositionsItem* buildVarItem, CExpressionVariable* destVarExp, COptimizedComplexVariableCompositionItem* minLeftItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* minLeftItemIndexMapping, COptimizedComplexVariableCompositionItem* maxRightItem, COptimizedComplexVariableCompositionItemVariableIndexMapping* maxRightItemIndexMapping, bool itemSameVarReduction) { |
| 10091 |
|
| 10092 |
QHash<CExpressionVariable*, QSet<COptimizedComplexVariableCompositionItem*>*>* varExpVarComItemHash = buildVarItem->getVariableExpressionVariableCompositionItemHash(); |
| 10093 |
|
| 10094 |
QSet<CExpressionVariable*> reductionVarIdxSet; |
| 10095 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem = dynamic_cast<COptimizedComplexBuildingIndividualVariableCompositionsItem*>(buildVarItem); |
| 10096 |
if (buildingVarItem) { |
| 10097 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData*>* absorbedQueryPartsItemExtensionList = buildingVarItem->getAbsorbedQueryPartItemExtensionHandlingList(); |
| 10098 |
if (mConfAllowBindingReduction && mConfAllowJoiningBindingReduction && buildingVarItem->isBindingsReducible() && absorbedQueryPartsItemExtensionList->isEmpty()) { |
| 10099 |
// test whether there is no absorption propagation |
| 10100 |
// test whether there exists a variable that is not distinguished, has no remaining properties, and is not used by a remaining item for any variable |
| 10101 |
QSet<CExpressionVariable*>* allVarExpSet = buildingVarItem->getAllVariableSet(); |
| 10102 |
QSet<CExpressionVariable*>* reductionDeniedVarExpSet = buildingVarItem->getReductionDeniedVariableSet(); |
| 10103 |
|
| 10104 |
QHash<CExpressionVariable*, cint64> varUseCountHash; |
| 10105 |
|
| 10106 |
for (CExpressionVariable* varExp : *allVarExpSet) { |
| 10107 |
|
| 10108 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(varExp); |
| 10109 |
if (indiVarExp) { |
| 10110 |
QList<CObjectPropertyAssertionExpression*> propAssList = buildingVarItem->getUnhanledPropertyAssertionsExpressions(indiVarExp); |
| 10111 |
QList<CDataPropertyAssertionExpression*> dataPropAssList = buildingVarItem->getUnhanledDataPropertyAssertionsExpressions(indiVarExp); |
| 10112 |
QSet<COptimizedComplexVariableCompositionItem*>* remainingItemSet = varExpVarComItemHash->value(varExp); |
| 10113 |
if (remainingItemSet) { |
| 10114 |
bool investigateVarItemMappings = false; |
| 10115 |
if (!dataPropAssList.isEmpty() || !propAssList.isEmpty()) { |
| 10116 |
varUseCountHash[varExp] += 2; |
| 10117 |
investigateVarItemMappings = true; |
| 10118 |
} |
| 10119 |
if (remainingItemSet->size() > 1) { |
| 10120 |
investigateVarItemMappings = true; |
| 10121 |
} |
| 10122 |
if (!investigateVarItemMappings && remainingItemSet->size() == 1) { |
| 10123 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> firstOtherItemIndexMappings = buildingVarItem->getVariableItemIndexMapping(varExp).values(*remainingItemSet->begin()); |
| 10124 |
if (firstOtherItemIndexMappings.size() > 1) { |
| 10125 |
investigateVarItemMappings = true; |
| 10126 |
} |
| 10127 |
} |
| 10128 |
|
| 10129 |
if (investigateVarItemMappings) { |
| 10130 |
for (COptimizedComplexVariableCompositionItem* remainingItem : *remainingItemSet) { |
| 10131 |
if (remainingItem) { |
| 10132 |
QList<COptimizedComplexVariableCompositionItemVariableIndexMapping*> otherItemIndexMappings = buildingVarItem->getVariableItemIndexMapping(varExp).values(remainingItem); |
| 10133 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping* otherItemIndexMapping : otherItemIndexMappings) { |
| 10134 |
if ((remainingItem != minLeftItem || otherItemIndexMapping != minLeftItemIndexMapping) && (remainingItem != maxRightItem || otherItemIndexMapping != maxRightItemIndexMapping)) { |
| 10135 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator otherIt = otherItemIndexMapping->constBegin(), otherItEnd = otherItemIndexMapping->constEnd(); otherIt != otherItEnd; ++otherIt) { |
| 10136 |
CExpressionVariable* otherVarExp = otherIt.value(); |
| 10137 |
varUseCountHash[otherVarExp]++; |
| 10138 |
} |
| 10139 |
} |
| 10140 |
} |
| 10141 |
} |
| 10142 |
} |
| 10143 |
} |
| 10144 |
} |
| 10145 |
|
| 10146 |
} |
| 10147 |
} |
| 10148 |
|
| 10149 |
|
| 10150 |
if (!itemSameVarReduction) { |
| 10151 |
QSet<CExpressionVariable*> leftVarSingleCheckSet; |
| 10152 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = minLeftItemIndexMapping->constBegin(), itEnd = minLeftItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 10153 |
CExpressionVariable* varExp = it.value(); |
| 10154 |
leftVarSingleCheckSet.insert(varExp); |
| 10155 |
varUseCountHash[varExp]++; |
| 10156 |
} |
| 10157 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = maxRightItemIndexMapping->constBegin(), itEnd = maxRightItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 10158 |
CExpressionVariable* varExp = it.value(); |
| 10159 |
if (leftVarSingleCheckSet.contains(varExp)) { |
| 10160 |
leftVarSingleCheckSet.remove(varExp); |
| 10161 |
} else { |
| 10162 |
varUseCountHash[varExp]++; |
| 10163 |
} |
| 10164 |
} |
| 10165 |
|
| 10166 |
COptimizedComplexVariableCompositionItemVariableExpressionMapping& varItemIndexMapping = buildingVarItem->getVariableItemIndexMapping(destVarExp); |
| 10167 |
if (varItemIndexMapping.size() > 1) { |
| 10168 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping* otherItemIndexMapping : varItemIndexMapping) { |
| 10169 |
if (otherItemIndexMapping != maxRightItemIndexMapping && otherItemIndexMapping != minLeftItemIndexMapping) { |
| 10170 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator otherIt = otherItemIndexMapping->constBegin(), otherItEnd = otherItemIndexMapping->constEnd(); otherIt != otherItEnd; ++otherIt) { |
| 10171 |
CExpressionVariable* otherVarExp = otherIt.value(); |
| 10172 |
varUseCountHash[otherVarExp]++; |
| 10173 |
} |
| 10174 |
} |
| 10175 |
} |
| 10176 |
} |
| 10177 |
|
| 10178 |
} else { |
| 10179 |
QSet<CExpressionVariable*> leftVarSingleCheckSet; |
| 10180 |
QSet<CExpressionVariable*> leftVarSingleCheckSet2; |
| 10181 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = minLeftItemIndexMapping->constBegin(), itEnd = minLeftItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 10182 |
CExpressionVariable* varExp = it.value(); |
| 10183 |
if (!leftVarSingleCheckSet.contains(varExp)) { |
| 10184 |
leftVarSingleCheckSet.insert(varExp); |
| 10185 |
varUseCountHash[varExp]++; |
| 10186 |
} else { |
| 10187 |
if (!leftVarSingleCheckSet2.contains(varExp)) { |
| 10188 |
leftVarSingleCheckSet2.insert(varExp); |
| 10189 |
} else { |
| 10190 |
varUseCountHash[varExp]++; |
| 10191 |
} |
| 10192 |
} |
| 10193 |
} |
| 10194 |
} |
| 10195 |
|
| 10196 |
|
| 10197 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = minLeftItemIndexMapping->constBegin(), itEnd = minLeftItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 10198 |
cint64 idx = it.key(); |
| 10199 |
CExpressionVariable* varExp = it.value(); |
| 10200 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(varExp); |
| 10201 |
if (!reductionDeniedVarExpSet->contains(varExp) && indiVarExp) { |
| 10202 |
cint64 useCount = varUseCountHash.value(varExp); |
| 10203 |
if (useCount <= 1) { |
| 10204 |
reductionVarIdxSet.insert(varExp); |
| 10205 |
} |
| 10206 |
} |
| 10207 |
} |
| 10208 |
if (!itemSameVarReduction) { |
| 10209 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = maxRightItemIndexMapping->constBegin(), itEnd = maxRightItemIndexMapping->constEnd(); it != itEnd; ++it) { |
| 10210 |
cint64 idx = it.key(); |
| 10211 |
CExpressionVariable* varExp = it.value(); |
| 10212 |
CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(varExp); |
| 10213 |
if (!reductionDeniedVarExpSet->contains(varExp) && indiVarExp) { |
| 10214 |
cint64 useCount = varUseCountHash.value(varExp); |
| 10215 |
if (useCount <= 1) { |
| 10216 |
reductionVarIdxSet.insert(varExp); |
| 10217 |
} |
| 10218 |
} |
| 10219 |
} |
| 10220 |
} |
| 10221 |
|
| 10222 |
} |
| 10223 |
} |
| 10224 |
return reductionVarIdxSet; |
| 10225 |
} |
| 10226 |
|
| 10227 |
|
| 10228 |
|
| 10229 |
|
| 10230 |
|
| 10231 |
cint64 COptimizedComplexExpressionAnsweringHandler::fillJoiningBindingPositionMapping(COptimizedComplexVariableCompositionItemVariableIndexMapping* minLeftItemIndexMapping, COptimizedComplexVariableJoiningBindingPositionMapping &joiningBindingPositionMapping, COptimizedComplexVariableCompositionItemVariableIndexMapping* maxRightItemIndexMapping, bool itemSameVarReduction, QSet<CExpressionVariable *> &reductionVarExpSet) { |
| 10232 |
cint64 nextVarIdx = 0; |
| 10233 |
QHash<cint64, cint64> minLeftVarIdsCorrectionHash; |
| 10234 |
QSet<CExpressionVariable*> sameItemVarExpMergedSet; |
| 10235 |
QHash<CExpressionVariable*, cint64> minLeftItemVarExpIdxHash; |
| 10236 |
QHash<CExpressionVariable*, cint64> maxRightItemVarExpIdxHash; |
| 10237 |
QSet<CExpressionVariable*> commonVarExpSet; |
| 10238 |
cint64 minLeftEliminationCount = 0; |
| 10239 |
|
| 10240 |
for (cint64 idx = 0; idx < minLeftItemIndexMapping->size(); ++idx) { |
| 10241 |
joiningBindingPositionMapping.addBindingPositionMapping(true, idx, -1); |
| 10242 |
} |
| 10243 |
for (cint64 idx = 0; idx < maxRightItemIndexMapping->size(); ++idx) { |
| 10244 |
joiningBindingPositionMapping.addBindingPositionMapping(false, idx, -1); |
| 10245 |
} |
| 10246 |
|
| 10247 |
|
| 10248 |
if (!itemSameVarReduction) { |
| 10249 |
// determine the variables that occur in both items and use their positions for the hashing key linker |
| 10250 |
for (cint64 idx = 0; idx < minLeftItemIndexMapping->size(); ++idx) { |
| 10251 |
CExpressionVariable* refVarExp = minLeftItemIndexMapping->value(idx); |
| 10252 |
if (!minLeftItemVarExpIdxHash.contains(refVarExp)) { |
| 10253 |
minLeftItemVarExpIdxHash.insert(refVarExp, idx); |
| 10254 |
} |
| 10255 |
} |
| 10256 |
for (cint64 idx = 0; idx < maxRightItemIndexMapping->size(); ++idx) { |
| 10257 |
CExpressionVariable* refVarExp = maxRightItemIndexMapping->value(idx); |
| 10258 |
if (minLeftItemVarExpIdxHash.contains(refVarExp)) { |
| 10259 |
commonVarExpSet.insert(refVarExp); |
| 10260 |
} |
| 10261 |
if (!maxRightItemVarExpIdxHash.contains(refVarExp)) { |
| 10262 |
maxRightItemVarExpIdxHash.insert(refVarExp, idx); |
| 10263 |
} |
| 10264 |
} |
| 10265 |
|
| 10266 |
|
| 10267 |
CXLinker<cint64>* leftKeyBindingLinker = nullptr; |
| 10268 |
CXLinker<cint64>* rightKeyBindingLinker = nullptr; |
| 10269 |
|
| 10270 |
CXLinker<cint64>* lastLeftKeyBindingLinker = nullptr; |
| 10271 |
CXLinker<cint64>* lastRightKeyBindingLinker = nullptr; |
| 10272 |
|
| 10273 |
|
| 10274 |
CXLinker<cint64>* leftRemainingBindingLinker = nullptr; |
| 10275 |
CXLinker<cint64>* rightRemainingBindingLinker = nullptr; |
| 10276 |
|
| 10277 |
CXLinker<cint64>* lastLeftRemainingBindingLinker = nullptr; |
| 10278 |
CXLinker<cint64>* lastRightRemainingBindingLinker = nullptr; |
| 10279 |
|
| 10280 |
|
| 10281 |
|
| 10282 |
|
| 10283 |
for (QSet<CExpressionVariable*>::const_iterator it = commonVarExpSet.constBegin(), itEnd = commonVarExpSet.constEnd(); it != itEnd; ++it) { |
| 10284 |
CExpressionVariable* commVarExp = *it; |
| 10285 |
|
| 10286 |
cint64 leftVarIdx = minLeftItemVarExpIdxHash.value(commVarExp); |
| 10287 |
CXLinker<cint64>* newLeftKeyBindingLinker = new CXLinker<cint64>(); |
| 10288 |
newLeftKeyBindingLinker->initLinker(leftVarIdx); |
| 10289 |
if (lastLeftKeyBindingLinker) { |
| 10290 |
lastLeftKeyBindingLinker->append(newLeftKeyBindingLinker); |
| 10291 |
lastLeftKeyBindingLinker = newLeftKeyBindingLinker; |
| 10292 |
} else { |
| 10293 |
lastLeftKeyBindingLinker = newLeftKeyBindingLinker; |
| 10294 |
leftKeyBindingLinker = newLeftKeyBindingLinker; |
| 10295 |
} |
| 10296 |
|
| 10297 |
cint64 rightVarIdx = maxRightItemVarExpIdxHash.value(commVarExp); |
| 10298 |
CXLinker<cint64>* newRightKeyBindingLinker = new CXLinker<cint64>(); |
| 10299 |
newRightKeyBindingLinker->initLinker(rightVarIdx); |
| 10300 |
if (lastRightKeyBindingLinker) { |
| 10301 |
lastRightKeyBindingLinker->append(newRightKeyBindingLinker); |
| 10302 |
lastRightKeyBindingLinker = newRightKeyBindingLinker; |
| 10303 |
} else { |
| 10304 |
lastRightKeyBindingLinker = newRightKeyBindingLinker; |
| 10305 |
rightKeyBindingLinker = newRightKeyBindingLinker; |
| 10306 |
} |
| 10307 |
} |
| 10308 |
joiningBindingPositionMapping.setLeftKeyBindingLinker(leftKeyBindingLinker); |
| 10309 |
joiningBindingPositionMapping.setRightKeyBindingLinker(rightKeyBindingLinker); |
| 10310 |
|
| 10311 |
|
| 10312 |
for (cint64 idx = 0; idx < minLeftItemIndexMapping->size(); ++idx) { |
| 10313 |
CExpressionVariable* refVarExp = minLeftItemIndexMapping->value(idx); |
| 10314 |
if (!reductionVarExpSet.contains(refVarExp)) { |
| 10315 |
cint64 corrIdx = nextVarIdx++; |
| 10316 |
joiningBindingPositionMapping.addBindingPositionMapping(true, idx, corrIdx); |
| 10317 |
minLeftVarIdsCorrectionHash.insert(idx, corrIdx); |
| 10318 |
|
| 10319 |
CXLinker<cint64>* newLeftRemainingBindingLinker = new CXLinker<cint64>(); |
| 10320 |
newLeftRemainingBindingLinker->initLinker(idx); |
| 10321 |
if (lastLeftRemainingBindingLinker) { |
| 10322 |
lastLeftRemainingBindingLinker->append(newLeftRemainingBindingLinker); |
| 10323 |
lastLeftRemainingBindingLinker = newLeftRemainingBindingLinker; |
| 10324 |
} else { |
| 10325 |
lastLeftRemainingBindingLinker = newLeftRemainingBindingLinker; |
| 10326 |
leftRemainingBindingLinker = newLeftRemainingBindingLinker; |
| 10327 |
} |
| 10328 |
|
| 10329 |
} |
| 10330 |
} |
| 10331 |
for (cint64 idx = 0; idx < maxRightItemIndexMapping->size(); ++idx) { |
| 10332 |
CExpressionVariable* refVarExp = maxRightItemIndexMapping->value(idx); |
| 10333 |
if (!reductionVarExpSet.contains(refVarExp)) { |
| 10334 |
if (!commonVarExpSet.contains(refVarExp) || maxRightItemVarExpIdxHash.value(refVarExp) != idx) { |
| 10335 |
joiningBindingPositionMapping.addBindingPositionMapping(false, idx, nextVarIdx++); |
| 10336 |
} |
| 10337 |
|
| 10338 |
CXLinker<cint64>* newRightRemainingBindingLinker = new CXLinker<cint64>(); |
| 10339 |
newRightRemainingBindingLinker->initLinker(idx); |
| 10340 |
if (lastRightRemainingBindingLinker) { |
| 10341 |
lastRightRemainingBindingLinker->append(newRightRemainingBindingLinker); |
| 10342 |
lastRightRemainingBindingLinker = newRightRemainingBindingLinker; |
| 10343 |
} else { |
| 10344 |
lastRightRemainingBindingLinker = newRightRemainingBindingLinker; |
| 10345 |
rightRemainingBindingLinker = newRightRemainingBindingLinker; |
| 10346 |
} |
| 10347 |
|
| 10348 |
|
| 10349 |
} |
| 10350 |
} |
| 10351 |
joiningBindingPositionMapping.setLeftRemainingBindingLinker(leftRemainingBindingLinker); |
| 10352 |
joiningBindingPositionMapping.setRightRemainingBindingLinker(rightRemainingBindingLinker); |
| 10353 |
|
| 10354 |
|
| 10355 |
for (CExpressionVariable* redVarExp : reductionVarExpSet) { |
| 10356 |
if (minLeftItemVarExpIdxHash.contains(redVarExp)) { |
| 10357 |
cint64 idx = minLeftItemVarExpIdxHash.value(redVarExp); |
| 10358 |
joiningBindingPositionMapping.addBindingPositionMapping(true, idx, -2); |
| 10359 |
joiningBindingPositionMapping.setVariableReduction(true); |
| 10360 |
} else if (maxRightItemVarExpIdxHash.contains(redVarExp)) { |
| 10361 |
cint64 idx = maxRightItemVarExpIdxHash.value(redVarExp); |
| 10362 |
joiningBindingPositionMapping.addBindingPositionMapping(false, idx, -2); |
| 10363 |
joiningBindingPositionMapping.setVariableReduction(true); |
| 10364 |
} |
| 10365 |
} |
| 10366 |
|
| 10367 |
|
| 10368 |
} else { |
| 10369 |
// determine the variables that occur twice and use their positions (together with the remaining variables' positions) for the hashing key linker |
| 10370 |
|
| 10371 |
for (cint64 idx = 0; idx < minLeftItemIndexMapping->size(); ++idx) { |
| 10372 |
CExpressionVariable* refVarExp = minLeftItemIndexMapping->value(idx); |
| 10373 |
if (!minLeftItemVarExpIdxHash.contains(refVarExp)) { |
| 10374 |
minLeftItemVarExpIdxHash.insert(refVarExp, idx); |
| 10375 |
} else { |
| 10376 |
commonVarExpSet.insert(refVarExp); |
| 10377 |
if (!maxRightItemVarExpIdxHash.contains(refVarExp)) { |
| 10378 |
maxRightItemVarExpIdxHash.insert(refVarExp, idx); |
| 10379 |
} |
| 10380 |
} |
| 10381 |
} |
| 10382 |
|
| 10383 |
|
| 10384 |
CXLinker<cint64>* leftKeyBindingLinker = nullptr; |
| 10385 |
CXLinker<cint64>* rightKeyBindingLinker = nullptr; |
| 10386 |
|
| 10387 |
CXLinker<cint64>* lastLeftKeyBindingLinker = nullptr; |
| 10388 |
CXLinker<cint64>* lastRightKeyBindingLinker = nullptr; |
| 10389 |
|
| 10390 |
|
| 10391 |
|
| 10392 |
|
| 10393 |
for (cint64 idx = 0; idx < minLeftItemIndexMapping->size(); ++idx) { |
| 10394 |
CExpressionVariable* refVarExp = minLeftItemIndexMapping->value(idx); |
| 10395 |
|
| 10396 |
cint64 leftVarIdx = idx; |
| 10397 |
CXLinker<cint64>* newLeftKeyBindingLinker = new CXLinker<cint64>(); |
| 10398 |
newLeftKeyBindingLinker->initLinker(leftVarIdx); |
| 10399 |
if (lastLeftKeyBindingLinker) { |
| 10400 |
lastLeftKeyBindingLinker->append(newLeftKeyBindingLinker); |
| 10401 |
lastLeftKeyBindingLinker = newLeftKeyBindingLinker; |
| 10402 |
} else { |
| 10403 |
lastLeftKeyBindingLinker = newLeftKeyBindingLinker; |
| 10404 |
leftKeyBindingLinker = newLeftKeyBindingLinker; |
| 10405 |
} |
| 10406 |
|
| 10407 |
cint64 rightVarIdx = idx; |
| 10408 |
if (commonVarExpSet.contains(refVarExp)) { |
| 10409 |
if (!sameItemVarExpMergedSet.contains(refVarExp)) { |
| 10410 |
sameItemVarExpMergedSet.insert(refVarExp); |
| 10411 |
rightVarIdx = maxRightItemVarExpIdxHash.value(refVarExp); |
| 10412 |
} |
| 10413 |
} |
| 10414 |
CXLinker<cint64>* newRightKeyBindingLinker = new CXLinker<cint64>(); |
| 10415 |
newRightKeyBindingLinker->initLinker(rightVarIdx); |
| 10416 |
if (lastRightKeyBindingLinker) { |
| 10417 |
lastRightKeyBindingLinker->append(newRightKeyBindingLinker); |
| 10418 |
lastRightKeyBindingLinker = newRightKeyBindingLinker; |
| 10419 |
} else { |
| 10420 |
lastRightKeyBindingLinker = newRightKeyBindingLinker; |
| 10421 |
rightKeyBindingLinker = newRightKeyBindingLinker; |
| 10422 |
} |
| 10423 |
} |
| 10424 |
joiningBindingPositionMapping.setLeftKeyBindingLinker(leftKeyBindingLinker); |
| 10425 |
joiningBindingPositionMapping.setRightKeyBindingLinker(rightKeyBindingLinker); |
| 10426 |
|
| 10427 |
|
| 10428 |
for (cint64 idx = 0; idx < minLeftItemIndexMapping->size(); ++idx) { |
| 10429 |
CExpressionVariable* refVarExp = minLeftItemIndexMapping->value(idx); |
| 10430 |
if (!reductionVarExpSet.contains(refVarExp)) { |
| 10431 |
|
| 10432 |
bool addVarIdx = false; |
| 10433 |
if (!commonVarExpSet.contains(refVarExp)) { |
| 10434 |
addVarIdx = true; |
| 10435 |
} else { |
| 10436 |
if (sameItemVarExpMergedSet.contains(refVarExp)) { |
| 10437 |
sameItemVarExpMergedSet.remove(refVarExp); |
| 10438 |
addVarIdx = false; |
| 10439 |
} else { |
| 10440 |
addVarIdx = true; |
| 10441 |
} |
| 10442 |
} |
| 10443 |
|
| 10444 |
if (addVarIdx) { |
| 10445 |
cint64 corrIdx = nextVarIdx++; |
| 10446 |
joiningBindingPositionMapping.addBindingPositionMapping(true, idx, corrIdx); |
| 10447 |
minLeftVarIdsCorrectionHash.insert(idx, corrIdx); |
| 10448 |
} |
| 10449 |
} |
| 10450 |
} |
| 10451 |
|
| 10452 |
for (CExpressionVariable* redVarExp : reductionVarExpSet) { |
| 10453 |
cint64 idx = minLeftItemVarExpIdxHash.value(redVarExp); |
| 10454 |
joiningBindingPositionMapping.addBindingPositionMapping(true, idx, -2); |
| 10455 |
joiningBindingPositionMapping.setVariableReduction(true); |
| 10456 |
} |
| 10457 |
|
| 10458 |
} |
| 10459 |
joiningBindingPositionMapping.setSelfSameVariableReduction(itemSameVarReduction); |
| 10460 |
return nextVarIdx; |
| 10461 |
} |
| 10462 |
|
| 10463 |
bool COptimizedComplexExpressionAnsweringHandler::finishSubClassCalculationStepProcessing(COptimizedComplexConceptItem* conceptItem, CComplexConceptStepComputationProcess* compStep, CAnswererContext* answererContext) { |
| 10464 |
delete conceptItem->getPossibleSubClassNodeTestingList(); |
| 10465 |
conceptItem->setPossibleSubClassNodeTestingList(nullptr); |
| 10466 |
delete conceptItem->getPossibleSubClassTestingNodeSet(); |
| 10467 |
conceptItem->setPossibleSubClassTestingNodeSet(nullptr); |
| 10468 |
delete conceptItem->getMaximumSubClassNodeSet(); |
| 10469 |
conceptItem->setMaximumSubClassNodeSet(nullptr); |
| 10470 |
return finishCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 10471 |
} |
| 10472 |
|
| 10473 |
|
| 10474 |
|
| 10475 |
|
| 10476 |
|
| 10477 |
bool COptimizedComplexExpressionAnsweringHandler::initializeRealization(COptimizedComplexConceptItem* conceptItem, CAnswererContext* answererContext) { |
| 10478 |
CConceptRealization* conceptRealization = mOntoAnsweringItem->getOntology()->getRealization()->getConceptRealization(); |
| 10479 |
CRoleRealization* roleRealization = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 10480 |
if (!conceptRealization || !roleRealization) { |
| 10481 |
QList<COntologyProcessingRequirement*> reqList; |
| 10482 |
COntologyProcessingInitializedRealizationRequirement* initRealReq = new COntologyProcessingInitializedRealizationRequirement(); |
| 10483 |
reqList.append(initRealReq); |
| 10484 |
CAnsweringMessageDataRequirementCompletedRealization* reqCompMess = new CAnsweringMessageDataRequirementCompletedRealization(conceptItem); |
| 10485 |
processRequirements(answererContext, mOntoAnsweringItem->getOntology(), reqList, reqCompMess); |
| 10486 |
conceptItem->incLazyRealizationProcessingCount(); |
| 10487 |
return true; |
| 10488 |
} |
| 10489 |
return false; |
| 10490 |
} |
| 10491 |
|
| 10492 |
|
| 10493 |
|
| 10494 |
bool COptimizedComplexExpressionAnsweringHandler::initializeRealizationInstancesIterators(COptimizedComplexConceptItem* conceptItem, cint64 requiredInstancesCount, CAnswererContext* answererContext) { |
| 10495 |
QSet<CHierarchyNode*>* superHierNodeSet = conceptItem->getDirectSuperClassNodeSet(); |
| 10496 |
QSet<CHierarchyNode*>* subHierNodeSet = conceptItem->getDirectSubClassNodeSet(); |
| 10497 |
CHierarchyNode* topHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getTopHierarchyNode(); |
| 10498 |
CHierarchyNode* bottomHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getBottomHierarchyNode(); |
| 10499 |
|
| 10500 |
CConceptRealization* conceptRealization = mOntoAnsweringItem->getOntology()->getRealization()->getConceptRealization(); |
| 10501 |
CRoleRealization* roleRealization = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 10502 |
|
| 10503 |
QList<CRealizationIndividualInstanceItemReferenceIterator*> realizationIteratorList; |
| 10504 |
bool unsatisfiable = false; |
| 10505 |
|
| 10506 |
QList<COntologyProcessingRequirement*> reqList; |
| 10507 |
bool subInsteadOfTopHierNodeRealization = false; |
| 10508 |
if (superHierNodeSet) { |
| 10509 |
for (CHierarchyNode* node : *superHierNodeSet) { |
| 10510 |
if (node != topHierNode) { |
| 10511 |
if (mConfDirectPossibleRealizationRequesting) { |
| 10512 |
COntologyProcessingConceptRealizationRequirement* conRealReq = new COntologyProcessingConceptRealizationRequirement(CIndividualReference(), node->getOneEquivalentConcept()); |
| 10513 |
reqList.append(conRealReq); |
| 10514 |
} |
| 10515 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = conceptRealization->getConceptInstancesIterator(node->getOneEquivalentConcept(), false, mDefaultRealizationSorting); |
| 10516 |
realizationIteratorList.append(iterator); |
| 10517 |
if (iterator->atEnd() && !iterator->requiresInitialization()) { |
| 10518 |
unsatisfiable = true; |
| 10519 |
break; |
| 10520 |
} |
| 10521 |
} else { |
| 10522 |
subInsteadOfTopHierNodeRealization = true; |
| 10523 |
} |
| 10524 |
} |
| 10525 |
} else { |
| 10526 |
for (TConceptNegPair conNegPair : *conceptItem->getAtomicConcpetSet()) { |
| 10527 |
CConcept* concept = conNegPair.first; |
| 10528 |
bool negation = conNegPair.second; |
| 10529 |
if (!negation && (concept->getOperatorCode() == CCATOM || concept->getOperatorCode() == CCSUB || concept->getOperatorCode() == CCEQ)) { |
| 10530 |
if (mConfDirectPossibleRealizationRequesting) { |
| 10531 |
COntologyProcessingConceptRealizationRequirement* conRealReq = new COntologyProcessingConceptRealizationRequirement(CIndividualReference(), concept); |
| 10532 |
reqList.append(conRealReq); |
| 10533 |
} |
| 10534 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = conceptRealization->getConceptInstancesIterator(concept, false, mDefaultRealizationSorting); |
| 10535 |
realizationIteratorList.append(iterator); |
| 10536 |
if (iterator->atEnd() && !iterator->requiresInitialization()) { |
| 10537 |
unsatisfiable = true; |
| 10538 |
break; |
| 10539 |
} |
| 10540 |
|
| 10541 |
} |
| 10542 |
} |
| 10543 |
} |
| 10544 |
if (subInsteadOfTopHierNodeRealization && subHierNodeSet && !unsatisfiable) { |
| 10545 |
for (CHierarchyNode* node : *subHierNodeSet) { |
| 10546 |
if (node != bottomHierNode) { |
| 10547 |
if (mConfDirectPossibleRealizationRequesting) { |
| 10548 |
COntologyProcessingConceptRealizationRequirement* conRealReq = new COntologyProcessingConceptRealizationRequirement(CIndividualReference(), node->getOneEquivalentConcept()); |
| 10549 |
reqList.append(conRealReq); |
| 10550 |
} |
| 10551 |
} |
| 10552 |
} |
| 10553 |
} |
| 10554 |
|
| 10555 |
typedef QPair<CRole*, CDataLiteral*> TRoleDataLiteralPair; |
| 10556 |
|
| 10557 |
CConcept* indiTriggerConcept = mOntoAnsweringItem->getOntology()->getTBox()->getIndividualTriggerConcept(); |
| 10558 |
CConcept* topDataRangeConcept = mOntoAnsweringItem->getOntology()->getTBox()->getTopDataRangeConcept(); |
| 10559 |
|
| 10560 |
QSet<CRole*> roleRequiredNeighboursSet; |
| 10561 |
QSet<CRole*> roleRequiredExistentialSet; |
| 10562 |
QSet<TRoleIndividualPair> roleRequiredSuccIndiSet; |
| 10563 |
QSet<TRoleDataLiteralPair> roleDataLiteralRequiredInstantiatingSet; |
| 10564 |
QSet<CRole*> roleRequiredDataSet; |
| 10565 |
|
| 10566 |
if (!unsatisfiable) { |
| 10567 |
for (TConceptNegPair conNegPair : *conceptItem->getAtomicConcpetSet()) { |
| 10568 |
CConcept* concept = conNegPair.first; |
| 10569 |
bool negation = conNegPair.second; |
| 10570 |
if (!negation && concept->getOperatorCode() == CCVALUE) { |
| 10571 |
CIndividual* nomIndividual = concept->getNominalIndividual(); |
| 10572 |
CRole* role = concept->getRole(); |
| 10573 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndividual)); |
| 10574 |
|
| 10575 |
} else if (!negation && concept->getOperatorCode() == CCSOME) { |
| 10576 |
CRole* role = concept->getRole(); |
| 10577 |
if (!role->isDataRole() && concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 10578 |
if (concept->getOperandList()->getData() == indiTriggerConcept && !concept->getOperandList()->isNegated()) { |
| 10579 |
roleRequiredNeighboursSet.insert(role); |
| 10580 |
} else if (concept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && !concept->getOperandList()->isNegated()) { |
| 10581 |
CIndividual* nomIndi = concept->getOperandList()->getData()->getNominalIndividual(); |
| 10582 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndi)); |
| 10583 |
} else { |
| 10584 |
roleRequiredExistentialSet.insert(role); |
| 10585 |
} |
| 10586 |
} |
| 10587 |
|
| 10588 |
if (role->isDataRole() && concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 10589 |
CConcept* opConcept = concept->getOperandList()->getData(); |
| 10590 |
bool opConNegation = concept->getOperandList()->isNegated(); |
| 10591 |
|
| 10592 |
if (opConcept == topDataRangeConcept && !opConNegation) { |
| 10593 |
roleRequiredDataSet.insert(role); |
| 10594 |
} else if (opConcept->getOperatorCode() == CCDATALITERAL && !opConNegation) { |
| 10595 |
if (canRetrieveInstantiatingDataValueIndividuals(role, opConcept->getDataLiteral())) { |
| 10596 |
roleDataLiteralRequiredInstantiatingSet.insert(TRoleDataLiteralPair(role, opConcept->getDataLiteral())); |
| 10597 |
} else { |
| 10598 |
roleRequiredDataSet.insert(role); |
| 10599 |
} |
| 10600 |
} |
| 10601 |
} |
| 10602 |
|
| 10603 |
} else if (negation && concept->getOperatorCode() == CCALL) { |
| 10604 |
CRole* role = concept->getRole(); |
| 10605 |
if (!role->isDataRole() && concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 10606 |
if (concept->getOperandList()->getData() == indiTriggerConcept && concept->getOperandList()->isNegated()) { |
| 10607 |
roleRequiredNeighboursSet.insert(role); |
| 10608 |
} else if (concept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && concept->getOperandList()->isNegated()) { |
| 10609 |
CIndividual* nomIndi = concept->getOperandList()->getData()->getNominalIndividual(); |
| 10610 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndi)); |
| 10611 |
} else { |
| 10612 |
roleRequiredExistentialSet.insert(role); |
| 10613 |
} |
| 10614 |
} |
| 10615 |
|
| 10616 |
|
| 10617 |
if (role->isDataRole() && concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 10618 |
CConcept* opConcept = concept->getOperandList()->getData(); |
| 10619 |
bool opConNegation = concept->getOperandList()->isNegated(); |
| 10620 |
|
| 10621 |
if (opConcept == topDataRangeConcept && opConNegation) { |
| 10622 |
roleRequiredDataSet.insert(role); |
| 10623 |
} else if (opConcept->getOperatorCode() == CCDATALITERAL && opConNegation) { |
| 10624 |
if (canRetrieveInstantiatingDataValueIndividuals(role, opConcept->getDataLiteral())) { |
| 10625 |
roleDataLiteralRequiredInstantiatingSet.insert(TRoleDataLiteralPair(role, opConcept->getDataLiteral())); |
| 10626 |
} else { |
| 10627 |
roleRequiredDataSet.insert(role); |
| 10628 |
} |
| 10629 |
} |
| 10630 |
} |
| 10631 |
|
| 10632 |
} else if (!negation && concept->getOperatorCode() == CCAQCHOOCE) { |
| 10633 |
CRole* role = nullptr; |
| 10634 |
if (concept->getOperandCount() >= 1) { |
| 10635 |
CConcept* aqChOpConcept = concept->getOperandList()->getData(); |
| 10636 |
if (aqChOpConcept && aqChOpConcept->getOperatorCode() == CCAQSOME && !concept->getOperandList()->isNegated()) { |
| 10637 |
role = aqChOpConcept->getRole(); |
| 10638 |
|
| 10639 |
if (aqChOpConcept->getOperandCount() == 1 && aqChOpConcept->getOperandList()->getData()) { |
| 10640 |
if (aqChOpConcept->getOperandList()->getData() == indiTriggerConcept && !aqChOpConcept->getOperandList()->isNegated()) { |
| 10641 |
roleRequiredNeighboursSet.insert(role); |
| 10642 |
} else if (aqChOpConcept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && !aqChOpConcept->getOperandList()->isNegated()) { |
| 10643 |
CIndividual* nomIndi = aqChOpConcept->getOperandList()->getData()->getNominalIndividual(); |
| 10644 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndi)); |
| 10645 |
} else { |
| 10646 |
roleRequiredExistentialSet.insert(role); |
| 10647 |
} |
| 10648 |
} |
| 10649 |
|
| 10650 |
} |
| 10651 |
} |
| 10652 |
} |
| 10653 |
} |
| 10654 |
} |
| 10655 |
if (!roleDataLiteralRequiredInstantiatingSet.isEmpty() && !unsatisfiable) { |
| 10656 |
for (const TRoleDataLiteralPair& roleDataLiteralPair : roleDataLiteralRequiredInstantiatingSet) { |
| 10657 |
CRole* role = roleDataLiteralPair.first; |
| 10658 |
CDataLiteral* dataLiteral = roleDataLiteralPair.second; |
| 10659 |
QMap<cint64, IndividualIdCandidateData>* instantiatingDataValueIndividualIdMap = getInstantiatingDataValueIndividualIdMap(role, dataLiteral, nullptr, answererContext); |
| 10660 |
if (!instantiatingDataValueIndividualIdMap->isEmpty()) { |
| 10661 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = conceptRealization->getIterationCandidateIndividualIdIterator(*instantiatingDataValueIndividualIdMap, mDefaultRealizationSorting); |
| 10662 |
realizationIteratorList.append(iterator); |
| 10663 |
if (iterator->atEnd() && !iterator->requiresInitialization()) { |
| 10664 |
unsatisfiable = true; |
| 10665 |
break; |
| 10666 |
} |
| 10667 |
} else { |
| 10668 |
unsatisfiable = true; |
| 10669 |
break; |
| 10670 |
} |
| 10671 |
delete instantiatingDataValueIndividualIdMap; |
| 10672 |
} |
| 10673 |
} |
| 10674 |
if (!roleRequiredDataSet.isEmpty() && !unsatisfiable) { |
| 10675 |
for (CRole* role : roleRequiredDataSet) { |
| 10676 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = roleRealization->getRoleDataInstancesIterator(role, mDefaultRealizationSorting); |
| 10677 |
realizationIteratorList.append(iterator); |
| 10678 |
if (iterator->atEnd() && !iterator->requiresInitialization()) { |
| 10679 |
unsatisfiable = true; |
| 10680 |
} |
| 10681 |
} |
| 10682 |
} |
| 10683 |
if (!roleRequiredNeighboursSet.isEmpty() || !roleRequiredSuccIndiSet.isEmpty() || !roleRequiredExistentialSet.isEmpty()) { |
| 10684 |
if (!unsatisfiable) { |
| 10685 |
for (CRole* role : roleRequiredNeighboursSet) { |
| 10686 |
if (mConfDirectPossibleRealizationRequesting) { |
| 10687 |
COntologyProcessingRoleRealizationRequirement* roleRealReq = new COntologyProcessingRoleRealizationRequirement(role, false); |
| 10688 |
reqList.append(roleRealReq); |
| 10689 |
} |
| 10690 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = roleRealization->getRoleNeighbouringInstancesIterator(role, false, mDefaultRealizationSorting); |
| 10691 |
realizationIteratorList.append(iterator); |
| 10692 |
if (iterator->atEnd() && !iterator->requiresInitialization()) { |
| 10693 |
unsatisfiable = true; |
| 10694 |
break; |
| 10695 |
} |
| 10696 |
} |
| 10697 |
} |
| 10698 |
if (!unsatisfiable) { |
| 10699 |
for (const TRoleIndividualPair& roleIndiPair : roleRequiredSuccIndiSet) { |
| 10700 |
CRole* role = roleIndiPair.first; |
| 10701 |
CIndividual* nomIndividual = roleIndiPair.second; |
| 10702 |
if (mConfDirectPossibleRealizationRequesting) { |
| 10703 |
COntologyProcessingRoleRealizationRequirement* roleRealReq = new COntologyProcessingRoleRealizationRequirement(role, true, nomIndividual); |
| 10704 |
reqList.append(roleRealReq); |
| 10705 |
} |
| 10706 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = roleRealization->getRoleFillerInstancesIterator(roleRealization->getRoleInstanceItemReference(nomIndividual), role, true, mDefaultRealizationSorting); |
| 10707 |
realizationIteratorList.append(iterator); |
| 10708 |
if (iterator->atEnd() && !iterator->requiresInitialization()) { |
| 10709 |
unsatisfiable = true; |
| 10710 |
break; |
| 10711 |
} |
| 10712 |
} |
| 10713 |
} |
| 10714 |
if (!unsatisfiable && !roleRequiredExistentialSet.isEmpty()) { |
| 10715 |
for (CRole* role : roleRequiredExistentialSet) { |
| 10716 |
if (!roleRequiredNeighboursSet.contains(role)) { |
| 10717 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = roleRealization->getRoleExistentialInstancesIterator(role, false, mDefaultRealizationSorting); |
| 10718 |
realizationIteratorList.append(iterator); |
| 10719 |
if (iterator->atEnd() && !iterator->requiresInitialization()) { |
| 10720 |
unsatisfiable = true; |
| 10721 |
break; |
| 10722 |
} |
| 10723 |
} |
| 10724 |
} |
| 10725 |
} |
| 10726 |
} |
| 10727 |
|
| 10728 |
|
| 10729 |
if (!unsatisfiable && realizationIteratorList.isEmpty()) { |
| 10730 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = conceptRealization->getConceptInstancesIterator(topHierNode->getOneEquivalentConcept(), false, mDefaultRealizationSorting); |
| 10731 |
realizationIteratorList.append(iterator); |
| 10732 |
if (iterator->atEnd() && !iterator->requiresInitialization()) { |
| 10733 |
unsatisfiable = true; |
| 10734 |
} |
| 10735 |
} |
| 10736 |
|
| 10737 |
|
| 10738 |
if (!realizationIteratorList.isEmpty()) { |
| 10739 |
if (!unsatisfiable) { |
| 10740 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = conceptRealization->getIterationIntersectionIterator(realizationIteratorList); |
| 10741 |
if (iterator->requiresInitialization()) { |
| 10742 |
COntologyProcessingIteratorRealizationRequirement* roleRealReq = new COntologyProcessingIteratorRealizationRequirement(iterator, requiredInstancesCount); |
| 10743 |
reqList.append(roleRealReq); |
| 10744 |
} |
| 10745 |
conceptItem->setRealizationIterator(iterator); |
| 10746 |
} else { |
| 10747 |
qDeleteAll(realizationIteratorList); |
| 10748 |
} |
| 10749 |
} |
| 10750 |
|
| 10751 |
|
| 10752 |
if (!reqList.isEmpty()) { |
| 10753 |
if (!unsatisfiable) { |
| 10754 |
CAnsweringMessageDataRequirementCompletedRealization* reqCompMess = new CAnsweringMessageDataRequirementCompletedRealization(conceptItem); |
| 10755 |
processRequirements(answererContext, mOntoAnsweringItem->getOntology(), reqList, reqCompMess); |
| 10756 |
conceptItem->incLazyRealizationProcessingCount(); |
| 10757 |
return true; |
| 10758 |
} else { |
| 10759 |
qDeleteAll(reqList); |
| 10760 |
} |
| 10761 |
} |
| 10762 |
return false; |
| 10763 |
} |
| 10764 |
|
| 10765 |
|
| 10766 |
|
| 10767 |
bool COptimizedComplexExpressionAnsweringHandler::initializeKnownPossibleInstances(COptimizedComplexConceptItem* conceptItem, cint64 requiredInstancesCount, CAnswererContext* answererContext) { |
| 10768 |
|
| 10769 |
COptimizedComplexConceptInstanziatedIndividualItemHash* directInstanceItems = conceptItem->getKnownInstanceItems(); |
| 10770 |
if (!directInstanceItems) { |
| 10771 |
directInstanceItems = new COptimizedComplexConceptInstanziatedIndividualItemHash(); |
| 10772 |
conceptItem->setKnownInstanceItems(directInstanceItems); |
| 10773 |
} |
| 10774 |
|
| 10775 |
|
| 10776 |
bool completelyHandled = conceptItem->getAllAtomicConceptsCompletelyHandled(); |
| 10777 |
cint64 certainInstances = directInstanceItems->size(); |
| 10778 |
|
| 10779 |
|
| 10780 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = conceptItem->getRealizationIterator(); |
| 10781 |
|
| 10782 |
//CRealizationIndividualInstanceItemReferenceIterator* iteratorCopy = iterator->getCopy(); |
| 10783 |
|
| 10784 |
if (iterator) { |
| 10785 |
iterator->begin(); |
| 10786 |
|
| 10787 |
QSet<CRealizationIndividualInstanceItemReference>* possiblenstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 10788 |
if (!possiblenstanceItemSet) { |
| 10789 |
possiblenstanceItemSet = new QSet<CRealizationIndividualInstanceItemReference>(); |
| 10790 |
conceptItem->setPossibleInstanceItemSet(possiblenstanceItemSet); |
| 10791 |
} |
| 10792 |
cint64 visitedIndis = 0; |
| 10793 |
while (!iterator->atEnd() && !iterator->requiresInitialization() && (requiredInstancesCount < 0 || visitedIndis < requiredInstancesCount)) { |
| 10794 |
CRealizationIndividualInstanceItemReference indiItemRef = iterator->currentIndividualInstanceItemReference(); |
| 10795 |
if (completelyHandled && iterator->isCurrentInstanceCertain()) { |
| 10796 |
directInstanceItems->addRealizationIndividualInstanceItemReference(indiItemRef); |
| 10797 |
} else { |
| 10798 |
possiblenstanceItemSet->insert(indiItemRef); |
| 10799 |
} |
| 10800 |
iterator->moveNext(); |
| 10801 |
conceptItem->inRealizationRetrievedInstanceCandidateCount(); |
| 10802 |
++visitedIndis; |
| 10803 |
} |
| 10804 |
|
| 10805 |
//if (visitedIndis <= 0 && conceptItem->debugVariableNameUseList.contains("v0__HClFC__n550")) { |
| 10806 |
// iteratorCopy->begin(); |
| 10807 |
// while (!iteratorCopy->atEnd()) { |
| 10808 |
// iteratorCopy->moveNext(); |
| 10809 |
// } |
| 10810 |
// initializeRealizationInstancesIterators(conceptItem, 1, answererContext); |
| 10811 |
// CRealizationIndividualInstanceItemReferenceIterator* iterator = conceptItem->getRealizationIterator(); |
| 10812 |
// iterator->begin(); |
| 10813 |
//} |
| 10814 |
|
| 10815 |
|
| 10816 |
cint64 newCertainInstances = directInstanceItems->size() - certainInstances; |
| 10817 |
conceptItem->setLastRetrievedCertainInstanceItemCount(newCertainInstances); |
| 10818 |
|
| 10819 |
cint64 estimatedInstances = iterator->remainingInstancesEstimation().getEstimatedCount(); |
| 10820 |
conceptItem->setRealizationRetrievingExpectedInstanceCandidateCount(conceptItem->getRealizationRetrievedInstanceCandidateCount() + estimatedInstances); |
| 10821 |
|
| 10822 |
|
| 10823 |
if (iterator->requiresInitialization()) { |
| 10824 |
QList<COntologyProcessingRequirement*> reqList; |
| 10825 |
COntologyProcessingIteratorRealizationRequirement* roleRealReq = new COntologyProcessingIteratorRealizationRequirement(iterator, requiredInstancesCount); |
| 10826 |
reqList.append(roleRealReq); |
| 10827 |
|
| 10828 |
CAnsweringMessageDataRequirementCompletedRealization* reqCompMess = new CAnsweringMessageDataRequirementCompletedRealization(conceptItem); |
| 10829 |
processRequirements(answererContext, mOntoAnsweringItem->getOntology(), reqList, reqCompMess); |
| 10830 |
conceptItem->incLazyRealizationProcessingCount(); |
| 10831 |
return true; |
| 10832 |
} else if (conceptItem->getRealizationIterator()->atEnd()) { |
| 10833 |
conceptItem->setLazyRealizationInstancesRetrieved(true); |
| 10834 |
} |
| 10835 |
} else { |
| 10836 |
conceptItem->setLazyRealizationInstancesRetrieved(true); |
| 10837 |
} |
| 10838 |
|
| 10839 |
return false; |
| 10840 |
} |
| 10841 |
|
| 10842 |
|
| 10843 |
|
| 10844 |
|
| 10845 |
|
| 10846 |
|
| 10847 |
bool COptimizedComplexExpressionAnsweringHandler::schedulePossibleInstancesNeighourRealization(COptimizedComplexConceptItem* conceptItem, CAnswererContext* answererContext) { |
| 10848 |
QSet<CRealizationIndividualInstanceItemReference>* possibleDirectInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 10849 |
CConcept* indiTriggerConcept = mOntoAnsweringItem->getOntology()->getTBox()->getIndividualTriggerConcept(); |
| 10850 |
|
| 10851 |
QSet<CRole*> roleRequiredNeighboursSet; |
| 10852 |
QSet<TRoleIndividualPair> roleRequiredSuccIndiSet; |
| 10853 |
for (TConceptNegPair conNegPair : *conceptItem->getAtomicConcpetSet()) { |
| 10854 |
CConcept* concept = conNegPair.first; |
| 10855 |
bool negation = conNegPair.second; |
| 10856 |
if (!negation && concept->getOperatorCode() == CCSOME) { |
| 10857 |
CRole* role = concept->getRole(); |
| 10858 |
if (concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 10859 |
if (concept->getOperandList()->getData() == indiTriggerConcept && !concept->getOperandList()->isNegated()) { |
| 10860 |
roleRequiredNeighboursSet.insert(role); |
| 10861 |
} else if (concept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && !concept->getOperandList()->isNegated()) { |
| 10862 |
CIndividual* nomIndi = concept->getOperandList()->getData()->getNominalIndividual(); |
| 10863 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndi)); |
| 10864 |
} |
| 10865 |
} |
| 10866 |
|
| 10867 |
} else if (negation && concept->getOperatorCode() == CCALL) { |
| 10868 |
CRole* role = concept->getRole(); |
| 10869 |
if (concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 10870 |
if (concept->getOperandList()->getData() == indiTriggerConcept && concept->getOperandList()->isNegated()) { |
| 10871 |
roleRequiredNeighboursSet.insert(role); |
| 10872 |
} else if (concept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && concept->getOperandList()->isNegated()) { |
| 10873 |
CIndividual* nomIndi = concept->getOperandList()->getData()->getNominalIndividual(); |
| 10874 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndi)); |
| 10875 |
} |
| 10876 |
} |
| 10877 |
|
| 10878 |
} else if (!negation && concept->getOperatorCode() == CCAQCHOOCE) { |
| 10879 |
CRole* role = nullptr; |
| 10880 |
if (concept->getOperandCount() >= 1) { |
| 10881 |
CConcept* aqChOpConcept = concept->getOperandList()->getData(); |
| 10882 |
if (aqChOpConcept && aqChOpConcept->getOperatorCode() == CCAQSOME && !concept->getOperandList()->isNegated()) { |
| 10883 |
role = aqChOpConcept->getRole(); |
| 10884 |
|
| 10885 |
if (aqChOpConcept->getOperandCount() == 1 && aqChOpConcept->getOperandList()->getData()) { |
| 10886 |
if (aqChOpConcept->getOperandList()->getData() == indiTriggerConcept && !concept->getOperandList()->isNegated()) { |
| 10887 |
roleRequiredNeighboursSet.insert(role); |
| 10888 |
} else if (aqChOpConcept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && !aqChOpConcept->getOperandList()->isNegated()) { |
| 10889 |
CIndividual* nomIndi = aqChOpConcept->getOperandList()->getData()->getNominalIndividual(); |
| 10890 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndi)); |
| 10891 |
} |
| 10892 |
} |
| 10893 |
|
| 10894 |
} |
| 10895 |
} |
| 10896 |
|
| 10897 |
} |
| 10898 |
|
| 10899 |
} |
| 10900 |
if (!roleRequiredNeighboursSet.isEmpty() || !roleRequiredSuccIndiSet.isEmpty()) { |
| 10901 |
conceptItem->setLazyNeighbourRealizationPruningRequired(true); |
| 10902 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 10903 |
|
| 10904 |
class CIndividualTestingVisitor : public CSameRealizationIndividualVisitor { |
| 10905 |
public: |
| 10906 |
CIndividualReference testingIndiRef; |
| 10907 |
|
| 10908 |
bool visitIndividual(const CIndividualReference& indiRef, CSameRealization* sameRealization) { |
| 10909 |
testingIndiRef = indiRef; |
| 10910 |
return false; |
| 10911 |
} |
| 10912 |
} visitor; |
| 10913 |
|
| 10914 |
QList<COntologyProcessingRequirement*> reqList; |
| 10915 |
for (CRole* role : roleRequiredNeighboursSet) { |
| 10916 |
for (CRealizationIndividualInstanceItemReference possInstItem : *possibleDirectInstanceItemSet) { |
| 10917 |
sameRealization->visitSameIndividuals(possInstItem, &visitor); |
| 10918 |
COntologyProcessingRoleRealizationRequirement* roleRealReq = new COntologyProcessingRoleRealizationRequirement(role, false, visitor.testingIndiRef); |
| 10919 |
reqList.append(roleRealReq); |
| 10920 |
} |
| 10921 |
} |
| 10922 |
for (const TRoleIndividualPair& roleIndiPair : roleRequiredSuccIndiSet) { |
| 10923 |
CRole* role = roleIndiPair.first; |
| 10924 |
CIndividual* succIndi = roleIndiPair.second; |
| 10925 |
for (CRealizationIndividualInstanceItemReference possInstItem : *possibleDirectInstanceItemSet) { |
| 10926 |
sameRealization->visitSameIndividuals(possInstItem, &visitor); |
| 10927 |
COntologyProcessingRoleRealizationRequirement* roleRealReq = new COntologyProcessingRoleRealizationRequirement(role, false, visitor.testingIndiRef, succIndi); |
| 10928 |
reqList.append(roleRealReq); |
| 10929 |
} |
| 10930 |
} |
| 10931 |
CAnsweringMessageDataRequirementCompletedRealization* reqCompMess = new CAnsweringMessageDataRequirementCompletedRealization(conceptItem); |
| 10932 |
processRequirements(answererContext, mOntoAnsweringItem->getOntology(), reqList, reqCompMess); |
| 10933 |
conceptItem->incLazyRealizationProcessingCount(); |
| 10934 |
return true; |
| 10935 |
} |
| 10936 |
return false; |
| 10937 |
} |
| 10938 |
|
| 10939 |
|
| 10940 |
|
| 10941 |
|
| 10942 |
|
| 10943 |
|
| 10944 |
|
| 10945 |
|
| 10946 |
|
| 10947 |
bool COptimizedComplexExpressionAnsweringHandler::checkConceptInstancesCompletelyResolveable(COptimizedComplexConceptItem* conceptItem, QSet<TConceptNegPair>* remainingConNegPair) { |
| 10948 |
|
| 10949 |
|
| 10950 |
CRoleRealization* roleRealization = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 10951 |
|
| 10952 |
CConcept* indiTriggerConcept = mOntoAnsweringItem->getOntology()->getTBox()->getIndividualTriggerConcept(); |
| 10953 |
CConcept* topDataRangeConcept = mOntoAnsweringItem->getOntology()->getTBox()->getTopDataRangeConcept(); |
| 10954 |
CConcept* topConcept = mOntoAnsweringItem->getOntology()->getTBox()->getTopConcept(); |
| 10955 |
|
| 10956 |
bool allConceptCompletelyHandled = true; |
| 10957 |
|
| 10958 |
|
| 10959 |
for (TConceptNegPair conNegPair : *conceptItem->getAtomicConcpetSet()) { |
| 10960 |
|
| 10961 |
bool conceptCompletelyHandled = false; |
| 10962 |
|
| 10963 |
CConcept* concept = conNegPair.first; |
| 10964 |
bool negation = conNegPair.second; |
| 10965 |
if (!negation && concept->getOperatorCode() == CCSOME) { |
| 10966 |
// TODO: we should check for the special concept O here instead of top |
| 10967 |
CRole* role = concept->getRole(); |
| 10968 |
if (!role->isDataRole() && concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 10969 |
if (concept->getOperandList()->getData() == indiTriggerConcept && !concept->getOperandList()->isNegated()) { |
| 10970 |
conceptCompletelyHandled = true; |
| 10971 |
} else if (concept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && !concept->getOperandList()->isNegated()) { |
| 10972 |
conceptCompletelyHandled = true; |
| 10973 |
} else if (concept->getOperandList()->getData() == topConcept && !concept->getOperandList()->isNegated()) { |
| 10974 |
conceptCompletelyHandled = true; |
| 10975 |
} |
| 10976 |
} |
| 10977 |
|
| 10978 |
if (role->isDataRole() && !conceptCompletelyHandled && concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 10979 |
|
| 10980 |
CConcept* opConcept = concept->getOperandList()->getData(); |
| 10981 |
bool opConNegation = concept->getOperandList()->isNegated(); |
| 10982 |
|
| 10983 |
if (opConcept == topDataRangeConcept && !opConNegation) { |
| 10984 |
conceptCompletelyHandled = true; |
| 10985 |
} else if (opConcept->getOperatorCode() == CCDATALITERAL && !opConNegation) { |
| 10986 |
if (canRetrieveInstantiatingDataValueIndividuals(role, opConcept->getDataLiteral())) { |
| 10987 |
conceptCompletelyHandled = true; |
| 10988 |
} |
| 10989 |
} |
| 10990 |
} |
| 10991 |
|
| 10992 |
} else if (negation && concept->getOperatorCode() == CCALL) { |
| 10993 |
// TODO: we should check for the special concept O here instead of top |
| 10994 |
CRole* role = concept->getRole(); |
| 10995 |
if (!role->isDataRole() && concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 10996 |
if (concept->getOperandList()->getData() == indiTriggerConcept && concept->getOperandList()->isNegated()) { |
| 10997 |
conceptCompletelyHandled = true; |
| 10998 |
} else if (concept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && concept->getOperandList()->isNegated()) { |
| 10999 |
conceptCompletelyHandled = true; |
| 11000 |
} else if (concept->getOperandList()->getData() == topConcept && concept->getOperandList()->isNegated()) { |
| 11001 |
conceptCompletelyHandled = true; |
| 11002 |
} |
| 11003 |
} |
| 11004 |
|
| 11005 |
if (role->isDataRole() && !conceptCompletelyHandled && concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 11006 |
|
| 11007 |
CConcept* opConcept = concept->getOperandList()->getData(); |
| 11008 |
bool opConNegation = concept->getOperandList()->isNegated(); |
| 11009 |
|
| 11010 |
if (opConcept == topDataRangeConcept && opConNegation) { |
| 11011 |
conceptCompletelyHandled = true; |
| 11012 |
} else if (opConcept->getOperatorCode() == CCDATALITERAL && opConNegation) { |
| 11013 |
if (canRetrieveInstantiatingDataValueIndividuals(role, opConcept->getDataLiteral())) { |
| 11014 |
conceptCompletelyHandled = true; |
| 11015 |
} |
| 11016 |
} |
| 11017 |
} |
| 11018 |
} else if (!negation && concept->getOperatorCode() == CCVALUE) { |
| 11019 |
conceptCompletelyHandled = true; |
| 11020 |
} else if (!negation && concept->hasClassName()) { |
| 11021 |
conceptCompletelyHandled = true; |
| 11022 |
} else if (!negation && concept->getOperatorCode() == CCAQCHOOCE) { |
| 11023 |
bool indiTriggerConceptRestriction = false; |
| 11024 |
if (concept->getOperandCount() >= 1) { |
| 11025 |
CConcept* aqChOpConcept = concept->getOperandList()->getData(); |
| 11026 |
if (aqChOpConcept && aqChOpConcept->getOperatorCode() == CCAQSOME && !concept->getOperandList()->isNegated()) { |
| 11027 |
|
| 11028 |
if (aqChOpConcept->getOperandCount() == 1) { |
| 11029 |
if (aqChOpConcept->getOperandList()->getData() == indiTriggerConcept && !aqChOpConcept->getOperandList()->isNegated()) { |
| 11030 |
indiTriggerConceptRestriction = true; |
| 11031 |
} else if (aqChOpConcept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && !aqChOpConcept->getOperandList()->isNegated()) { |
| 11032 |
indiTriggerConceptRestriction = true; |
| 11033 |
} else if (aqChOpConcept->getOperandList()->getData() == topConcept && !aqChOpConcept->getOperandList()->isNegated()) { |
| 11034 |
conceptCompletelyHandled = true; |
| 11035 |
} |
| 11036 |
} |
| 11037 |
|
| 11038 |
} |
| 11039 |
} |
| 11040 |
if (indiTriggerConceptRestriction) { |
| 11041 |
conceptCompletelyHandled = true; |
| 11042 |
} |
| 11043 |
} |
| 11044 |
|
| 11045 |
if (!conceptCompletelyHandled) { |
| 11046 |
allConceptCompletelyHandled = false; |
| 11047 |
if (remainingConNegPair) { |
| 11048 |
remainingConNegPair->insert(conNegPair); |
| 11049 |
} |
| 11050 |
} |
| 11051 |
} |
| 11052 |
|
| 11053 |
return allConceptCompletelyHandled; |
| 11054 |
} |
| 11055 |
|
| 11056 |
|
| 11057 |
|
| 11058 |
|
| 11059 |
bool COptimizedComplexExpressionAnsweringHandler::checkPossibleInstancesCompletelyHandled(COptimizedComplexConceptItem* conceptItem, CAnswererContext* answererContext) { |
| 11060 |
|
| 11061 |
if (!conceptItem->getCompletelyHandledReducedInstanceTestingConcept()) { |
| 11062 |
|
| 11063 |
QSet<TConceptNegPair> remainingConNegPair; |
| 11064 |
bool allConceptCompletelyHandled = checkConceptInstancesCompletelyResolveable(conceptItem, &remainingConNegPair); |
| 11065 |
conceptItem->setCompletelyHandledReducedInstanceTestingConcept(conceptItem->getConcept()); |
| 11066 |
conceptItem->setCompletelyHandledReducedInstanceTestingConceptNegation(conceptItem->getConceptNegation()); |
| 11067 |
|
| 11068 |
conceptItem->setAllAtomicConceptsCompletelyHandled(allConceptCompletelyHandled); |
| 11069 |
if (allConceptCompletelyHandled) { |
| 11070 |
QSet<CRealizationIndividualInstanceItemReference>* possibleDirectInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 11071 |
COptimizedComplexConceptInstanziatedIndividualItemHash* knownDirectInstanceItems = conceptItem->getKnownInstanceItems(); |
| 11072 |
|
| 11073 |
if (possibleDirectInstanceItemSet) { |
| 11074 |
mTestedPossibleInstancesCount += possibleDirectInstanceItemSet->size(); |
| 11075 |
for (const CRealizationIndividualInstanceItemReference& item : *possibleDirectInstanceItemSet) { |
| 11076 |
knownDirectInstanceItems->addRealizationIndividualInstanceItemReference(item); |
| 11077 |
} |
| 11078 |
possibleDirectInstanceItemSet->clear(); |
| 11079 |
} |
| 11080 |
return true; |
| 11081 |
} else { |
| 11082 |
// create reduced testing concept |
| 11083 |
CMemoryAllocationManager* memMan = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getBoxContext()->getMemoryAllocationManager(); |
| 11084 |
CTBox* tBox = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getTBox(); |
| 11085 |
CConceptVector* conceptVec = tBox->getConceptVector(); |
| 11086 |
|
| 11087 |
CConcept* reducedConcept = CObjectAllocator< CConcept >::allocateAndConstruct(memMan); |
| 11088 |
reducedConcept->initConcept(); |
| 11089 |
cint64 nextConTag = tBox->getNextConceptID(); |
| 11090 |
reducedConcept->initTag(nextConTag); |
| 11091 |
reducedConcept->setOperatorCode(CCAND); |
| 11092 |
conceptVec->setLocalData(nextConTag, reducedConcept); |
| 11093 |
|
| 11094 |
for (TConceptNegPair conNegPar : remainingConNegPair) { |
| 11095 |
CConcept* opConcept = conNegPar.first; |
| 11096 |
bool opConceptNegation = conNegPar.second; |
| 11097 |
|
| 11098 |
CSortedNegLinker<CConcept*>* newIndiTrigOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(memMan); |
| 11099 |
newIndiTrigOpCon->init(opConcept, opConceptNegation, reducedConcept->getOperandList()); |
| 11100 |
reducedConcept->setOperandList(newIndiTrigOpCon); |
| 11101 |
reducedConcept->incOperandCount(); |
| 11102 |
} |
| 11103 |
conceptItem->setCompletelyHandledReducedInstanceTestingConcept(reducedConcept); |
| 11104 |
conceptItem->setCompletelyHandledReducedInstanceTestingConceptNegation(false); |
| 11105 |
|
| 11106 |
} |
| 11107 |
} else if (conceptItem->getAllAtomicConceptsCompletelyHandled()) { |
| 11108 |
QSet<CRealizationIndividualInstanceItemReference>* possibleDirectInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 11109 |
COptimizedComplexConceptInstanziatedIndividualItemHash* knownDirectInstanceItems = conceptItem->getKnownInstanceItems(); |
| 11110 |
if (possibleDirectInstanceItemSet) { |
| 11111 |
mTestedPossibleInstancesCount += possibleDirectInstanceItemSet->size(); |
| 11112 |
for (const CRealizationIndividualInstanceItemReference& item : *possibleDirectInstanceItemSet) { |
| 11113 |
knownDirectInstanceItems->addRealizationIndividualInstanceItemReference(item); |
| 11114 |
} |
| 11115 |
possibleDirectInstanceItemSet->clear(); |
| 11116 |
} |
| 11117 |
return true; |
| 11118 |
} |
| 11119 |
return false; |
| 11120 |
} |
| 11121 |
|
| 11122 |
|
| 11123 |
|
| 11124 |
|
| 11125 |
|
| 11126 |
|
| 11127 |
|
| 11128 |
bool COptimizedComplexExpressionAnsweringHandler::neighboursPrunePossibleInstances(COptimizedComplexConceptItem* conceptItem, CAnswererContext* answererContext) { |
| 11129 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 11130 |
CRoleRealization* roleRealization = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 11131 |
QSet<CRealizationIndividualInstanceItemReference>* possibleDirectInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 11132 |
CConcept* indiTriggerConcept = mOntoAnsweringItem->getOntology()->getTBox()->getIndividualTriggerConcept(); |
| 11133 |
|
| 11134 |
QSet<CRole*> roleRequiredNeighboursSet; |
| 11135 |
QSet<TRoleIndividualPair> roleRequiredSuccIndiSet; |
| 11136 |
for (TConceptNegPair conNegPair : *conceptItem->getAtomicConcpetSet()) { |
| 11137 |
CConcept* concept = conNegPair.first; |
| 11138 |
bool negation = conNegPair.second; |
| 11139 |
if (!negation && concept->getOperatorCode() == CCSOME) { |
| 11140 |
CRole* role = concept->getRole(); |
| 11141 |
if (concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 11142 |
if (concept->getOperandList()->getData() == indiTriggerConcept && !concept->getOperandList()->isNegated()) { |
| 11143 |
roleRequiredNeighboursSet.insert(role); |
| 11144 |
} else if (concept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && !concept->getOperandList()->isNegated()) { |
| 11145 |
CIndividual* nomIndi = concept->getOperandList()->getData()->getNominalIndividual(); |
| 11146 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndi)); |
| 11147 |
} |
| 11148 |
} |
| 11149 |
} else if (negation && concept->getOperatorCode() == CCALL) { |
| 11150 |
CRole* role = concept->getRole(); |
| 11151 |
if (concept->getOperandCount() == 1 && concept->getOperandList()->getData()) { |
| 11152 |
if (concept->getOperandList()->getData() == indiTriggerConcept && concept->getOperandList()->isNegated()) { |
| 11153 |
roleRequiredNeighboursSet.insert(role); |
| 11154 |
} else if (concept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && concept->getOperandList()->isNegated()) { |
| 11155 |
CIndividual* nomIndi = concept->getOperandList()->getData()->getNominalIndividual(); |
| 11156 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndi)); |
| 11157 |
} |
| 11158 |
} |
| 11159 |
} else if (!negation && concept->getOperatorCode() == CCAQCHOOCE) { |
| 11160 |
CRole* role = nullptr; |
| 11161 |
if (concept->getOperandCount() >= 1) { |
| 11162 |
CConcept* aqChOpConcept = concept->getOperandList()->getData(); |
| 11163 |
if (aqChOpConcept && aqChOpConcept->getOperatorCode() == CCAQSOME && !concept->getOperandList()->isNegated()) { |
| 11164 |
role = aqChOpConcept->getRole(); |
| 11165 |
|
| 11166 |
if (aqChOpConcept->getOperandCount() == 1 && aqChOpConcept->getOperandList()->getData()) { |
| 11167 |
if (aqChOpConcept->getOperandList()->getData() == indiTriggerConcept && !aqChOpConcept->getOperandList()->isNegated()) { |
| 11168 |
roleRequiredNeighboursSet.insert(role); |
| 11169 |
} else if (aqChOpConcept->getOperandList()->getData()->getOperatorCode() == CCNOMINAL && !aqChOpConcept->getOperandList()->isNegated()) { |
| 11170 |
CIndividual* nomIndi = aqChOpConcept->getOperandList()->getData()->getNominalIndividual(); |
| 11171 |
roleRequiredSuccIndiSet.insert(TRoleIndividualPair(role, nomIndi)); |
| 11172 |
} |
| 11173 |
} |
| 11174 |
|
| 11175 |
} |
| 11176 |
} |
| 11177 |
} |
| 11178 |
} |
| 11179 |
|
| 11180 |
|
| 11181 |
if (roleRealization && sameRealization) { |
| 11182 |
class CPossibleInstancesRoleNeighbourPruningVisitor : public CRoleRealizationInstanceVisitor { |
| 11183 |
public: |
| 11184 |
bool mHasRoleNeighbourFlag = false; |
| 11185 |
|
| 11186 |
bool visitRoleInstance(const CRealizationIndividualInstanceItemReference& indiRealItemRef, CRoleRealization* roleRealization) { |
| 11187 |
mHasRoleNeighbourFlag = true; |
| 11188 |
return false; |
| 11189 |
} |
| 11190 |
}; |
| 11191 |
|
| 11192 |
class CIndividualTestingVisitor : public CSameRealizationIndividualVisitor { |
| 11193 |
public: |
| 11194 |
CIndividualReference testingIndiRef; |
| 11195 |
|
| 11196 |
bool visitIndividual(const CIndividualReference& indiRef, CSameRealization* sameRealization) { |
| 11197 |
testingIndiRef = indiRef; |
| 11198 |
return false; |
| 11199 |
} |
| 11200 |
} sameInstanceVisitor; |
| 11201 |
|
| 11202 |
CPossibleInstancesRoleNeighbourPruningVisitor roleInstanceVisitor; |
| 11203 |
for (QSet<CRealizationIndividualInstanceItemReference>::iterator it = possibleDirectInstanceItemSet->begin(); it != possibleDirectInstanceItemSet->end(); ) { |
| 11204 |
CRealizationIndividualInstanceItemReference possInstItem(*it); |
| 11205 |
bool hasRoleNeighbour = true; |
| 11206 |
|
| 11207 |
for (QSet<TRoleIndividualPair>::const_iterator itRoleSucc = roleRequiredSuccIndiSet.constBegin(), itRoleSuccEnd = roleRequiredSuccIndiSet.constEnd(); hasRoleNeighbour && itRoleSucc != itRoleSuccEnd; ++itRoleSucc) { |
| 11208 |
CRole* role = itRoleSucc->first; |
| 11209 |
CIndividual* succIndi = itRoleSucc->second; |
| 11210 |
roleInstanceVisitor.mHasRoleNeighbourFlag = false; |
| 11211 |
sameRealization->visitSameIndividuals(possInstItem, &sameInstanceVisitor); |
| 11212 |
hasRoleNeighbour = roleRealization->isRoleInstance(role, sameInstanceVisitor.testingIndiRef, succIndi); |
| 11213 |
} |
| 11214 |
|
| 11215 |
for (QSet<CRole*>::const_iterator itRole = roleRequiredNeighboursSet.constBegin(), itRoleEnd = roleRequiredNeighboursSet.constEnd(); hasRoleNeighbour && itRole != itRoleEnd; ++itRole) { |
| 11216 |
CRole* role(*itRole); |
| 11217 |
roleInstanceVisitor.mHasRoleNeighbourFlag = false; |
| 11218 |
roleRealization->visitTargetIndividuals(roleRealization->getRoleInstanceItemReference(possInstItem), roleRealization->getRoleInstantiatedItem(role), &roleInstanceVisitor); |
| 11219 |
hasRoleNeighbour = roleInstanceVisitor.mHasRoleNeighbourFlag; |
| 11220 |
} |
| 11221 |
|
| 11222 |
if (!hasRoleNeighbour) { |
| 11223 |
mTestedPossibleInstancesCount++; |
| 11224 |
it = possibleDirectInstanceItemSet->erase(it); |
| 11225 |
} else { |
| 11226 |
++it; |
| 11227 |
} |
| 11228 |
} |
| 11229 |
} |
| 11230 |
return true; |
| 11231 |
} |
| 11232 |
|
| 11233 |
|
| 11234 |
bool COptimizedComplexExpressionAnsweringHandler::searchKnownPossibleInstances(COptimizedComplexConceptItem* conceptItem, CAnswererContext* answererContext) { |
| 11235 |
CConceptRealization* conceptRealization = mOntoAnsweringItem->getOntology()->getRealization()->getConceptRealization(); |
| 11236 |
CRoleRealization* roleRealization = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 11237 |
QSet<CRealizationIndividualInstanceItemReference>* possibleDirectInstanceItemSet = new QSet<CRealizationIndividualInstanceItemReference>(); |
| 11238 |
COptimizedComplexConceptInstanziatedIndividualItemHash* knownDirectInstanceItems = new COptimizedComplexConceptInstanziatedIndividualItemHash(); |
| 11239 |
bool possibleInstancesInitialized = false; |
| 11240 |
|
| 11241 |
class CPossibleInstancesOptimizedComplexConceptItemVisitor : public CConceptRealizationInstanceVisitor { |
| 11242 |
public: |
| 11243 |
QSet<CRealizationIndividualInstanceItemReference>* mInstanceItemSet; |
| 11244 |
|
| 11245 |
CPossibleInstancesOptimizedComplexConceptItemVisitor(QSet<CRealizationIndividualInstanceItemReference>* instanceItemSet) { |
| 11246 |
mInstanceItemSet = instanceItemSet; |
| 11247 |
} |
| 11248 |
|
| 11249 |
bool visitInstance(const CRealizationIndividualInstanceItemReference& indiRealItemRef, CConceptRealization* conRealization) { |
| 11250 |
mInstanceItemSet->insert(indiRealItemRef); |
| 11251 |
return true; |
| 11252 |
} |
| 11253 |
}; |
| 11254 |
|
| 11255 |
if (conceptRealization) { |
| 11256 |
CHierarchyNode* topHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getTopHierarchyNode(); |
| 11257 |
CHierarchyNode* bottomHierNode = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getBottomHierarchyNode(); |
| 11258 |
|
| 11259 |
QSet<CHierarchyNode*>* superClassNodeSet = conceptItem->getDirectSuperClassNodeSet(); |
| 11260 |
QSet<CHierarchyNode*>* subClassNodeSet = conceptItem->getDirectSubClassNodeSet(); |
| 11261 |
QSet<CHierarchyNode*> searchingInstanceNodeSet; |
| 11262 |
QList<CHierarchyNode*> searchingInstanceNodeList; |
| 11263 |
for (auto node : *superClassNodeSet) { |
| 11264 |
searchingInstanceNodeSet.insert(node); |
| 11265 |
if (!subClassNodeSet->contains(node)) { |
| 11266 |
searchingInstanceNodeList.append(node); |
| 11267 |
} |
| 11268 |
QSet<CRealizationIndividualInstanceItemReference> tmpDirectInstanceItemSet; |
| 11269 |
QSet<CRealizationIndividualInstanceItemReference>* fillDirectInstanceItemSet = possibleDirectInstanceItemSet; |
| 11270 |
if (possibleInstancesInitialized) { |
| 11271 |
fillDirectInstanceItemSet = &tmpDirectInstanceItemSet; |
| 11272 |
} |
| 11273 |
while (!searchingInstanceNodeList.isEmpty()) { |
| 11274 |
auto node = searchingInstanceNodeList.takeFirst(); |
| 11275 |
|
| 11276 |
if (node == topHierNode) { |
| 11277 |
|
| 11278 |
QSet<CRealizationIndividualInstanceItemReference> excludeDirectInstanceItemSet; |
| 11279 |
for (auto subNode : *subClassNodeSet) { |
| 11280 |
if (subNode != bottomHierNode) { |
| 11281 |
CPossibleInstancesOptimizedComplexConceptItemVisitor possibleRealizationVisitor(&excludeDirectInstanceItemSet); |
| 11282 |
conceptRealization->visitDirectInstances(subNode->getOneEquivalentConcept(), &possibleRealizationVisitor); |
| 11283 |
} |
| 11284 |
} |
| 11285 |
|
| 11286 |
|
| 11287 |
|
| 11288 |
visitAllIndividuals([&](const CIndividualReference& indiRef)->bool { |
| 11289 |
CRealizationIndividualInstanceItemReference indiItemRef = conceptRealization->getInstanceItemReference(indiRef); |
| 11290 |
if (!excludeDirectInstanceItemSet.contains(indiItemRef)) { |
| 11291 |
fillDirectInstanceItemSet->insert(indiItemRef); |
| 11292 |
} |
| 11293 |
return true; |
| 11294 |
}); |
| 11295 |
|
| 11296 |
|
| 11297 |
} else { |
| 11298 |
|
| 11299 |
CPossibleInstancesOptimizedComplexConceptItemVisitor possibleRealizationVisitor(fillDirectInstanceItemSet); |
| 11300 |
conceptRealization->visitDirectInstances(node->getOneEquivalentConcept(), &possibleRealizationVisitor); |
| 11301 |
|
| 11302 |
for (auto childNode : *node->getChildNodeSet()) { |
| 11303 |
if (!subClassNodeSet->contains(childNode)) { |
| 11304 |
searchingInstanceNodeList.append(childNode); |
| 11305 |
searchingInstanceNodeSet.insert(childNode); |
| 11306 |
} |
| 11307 |
} |
| 11308 |
} |
| 11309 |
} |
| 11310 |
if (!possibleInstancesInitialized) { |
| 11311 |
possibleInstancesInitialized = true; |
| 11312 |
} else { |
| 11313 |
possibleDirectInstanceItemSet->intersect(tmpDirectInstanceItemSet); |
| 11314 |
} |
| 11315 |
|
| 11316 |
} |
| 11317 |
|
| 11318 |
} |
| 11319 |
|
| 11320 |
|
| 11321 |
|
| 11322 |
if (roleRealization) { |
| 11323 |
class CPossibleInstancesOptimizedComplexRoleItemVisitor : public CRoleRealizationInstanceVisitor { |
| 11324 |
public: |
| 11325 |
QSet<CRealizationIndividualInstanceItemReference>* mInstanceItemSet; |
| 11326 |
|
| 11327 |
CPossibleInstancesOptimizedComplexRoleItemVisitor(QSet<CRealizationIndividualInstanceItemReference>* instanceItemSet) { |
| 11328 |
mInstanceItemSet = instanceItemSet; |
| 11329 |
} |
| 11330 |
|
| 11331 |
bool visitRoleInstance(const CRealizationIndividualInstanceItemReference& indiRealItemRef, CRoleRealization* roleRealization) { |
| 11332 |
mInstanceItemSet->insert(indiRealItemRef); |
| 11333 |
return true; |
| 11334 |
} |
| 11335 |
}; |
| 11336 |
|
| 11337 |
for (TConceptNegPair conNegPair : *conceptItem->getAtomicConcpetSet()) { |
| 11338 |
CConcept* concept = conNegPair.first; |
| 11339 |
bool negation = conNegPair.second; |
| 11340 |
if (!negation && concept->getOperatorCode() == CCVALUE) { |
| 11341 |
|
| 11342 |
CIndividual* nomIndividual = concept->getNominalIndividual(); |
| 11343 |
CRole* role = concept->getRole(); |
| 11344 |
|
| 11345 |
if (!possibleInstancesInitialized) { |
| 11346 |
possibleInstancesInitialized = true; |
| 11347 |
CPossibleInstancesOptimizedComplexRoleItemVisitor possibleRealizationVisitor(possibleDirectInstanceItemSet); |
| 11348 |
roleRealization->visitSourceIndividuals(nomIndividual, role, &possibleRealizationVisitor); |
| 11349 |
} else { |
| 11350 |
QSet<CRealizationIndividualInstanceItemReference> tmpDirectInstanceItemSet; |
| 11351 |
CPossibleInstancesOptimizedComplexRoleItemVisitor possibleRealizationVisitor(&tmpDirectInstanceItemSet); |
| 11352 |
roleRealization->visitSourceIndividuals(nomIndividual, role, &possibleRealizationVisitor); |
| 11353 |
possibleDirectInstanceItemSet->intersect(tmpDirectInstanceItemSet); |
| 11354 |
} |
| 11355 |
} |
| 11356 |
} |
| 11357 |
|
| 11358 |
|
| 11359 |
} |
| 11360 |
|
| 11361 |
class CSuperInstancesOptimizedComplexConceptItemVisitor : public COptimizedComplexConceptItemVisitor { |
| 11362 |
public: |
| 11363 |
QSet<CRealizationIndividualInstanceItemReference>* mPossibleDirectInstanceItemSet; |
| 11364 |
CConceptRealization* mConceptRealization; |
| 11365 |
|
| 11366 |
CSuperInstancesOptimizedComplexConceptItemVisitor(QSet<CRealizationIndividualInstanceItemReference>* possibleDirectInstanceItemSet, CConceptRealization* conceptRealization) { |
| 11367 |
mPossibleDirectInstanceItemSet = possibleDirectInstanceItemSet; |
| 11368 |
mConceptRealization = conceptRealization; |
| 11369 |
} |
| 11370 |
|
| 11371 |
cint64 mSuperItemVisitingLimit = 50; |
| 11372 |
cint64 mSuperItemResultVisitingLimit = 5; |
| 11373 |
|
| 11374 |
|
| 11375 |
bool visitComplexSuperConceptItem(COptimizedComplexConceptItem* item, bool& continueVisitingSuperItems) { |
| 11376 |
CComplexConceptStepComputationProcess* compStep = item->getComputationProcess()->getInstancesComputationProcess(false); |
| 11377 |
if (compStep && compStep->isComputationProcessFinished()) { |
| 11378 |
COptimizedComplexConceptInstanziatedIndividualItemHash* superInstanceItems = item->getKnownInstanceItems(); |
| 11379 |
if (superInstanceItems) { |
| 11380 |
QSet<CRealizationIndividualInstanceItemReference> superIndirectAllInstanceItemSet; |
| 11381 |
for (auto itemLinker = superInstanceItems->getAddedRealizationIndividualInstanceItemReferenceLinker(); itemLinker; itemLinker = itemLinker->getNext()) { |
| 11382 |
superIndirectAllInstanceItemSet.insert(itemLinker->getRealizationIndividualInstanceItemReference()); |
| 11383 |
} |
| 11384 |
// may be a little bit inefficient |
| 11385 |
CPossibleInstancesOptimizedComplexConceptItemVisitor possibleRealizationVisitor(&superIndirectAllInstanceItemSet); |
| 11386 |
for (auto node : *item->getDirectSubClassNodeSet()) { |
| 11387 |
mConceptRealization->visitInstances(node->getOneEquivalentConcept(), false, &possibleRealizationVisitor); |
| 11388 |
} |
| 11389 |
mPossibleDirectInstanceItemSet->intersect(superIndirectAllInstanceItemSet); |
| 11390 |
continueVisitingSuperItems = false; |
| 11391 |
if (--mSuperItemResultVisitingLimit < 0) { |
| 11392 |
return false; |
| 11393 |
} |
| 11394 |
} |
| 11395 |
} |
| 11396 |
if (--mSuperItemVisitingLimit < 0) { |
| 11397 |
return false; |
| 11398 |
} |
| 11399 |
return true; |
| 11400 |
} |
| 11401 |
} superItemVisitor(possibleDirectInstanceItemSet, conceptRealization); |
| 11402 |
visitSuperSubConceptItems(conceptItem, false, true, &superItemVisitor); |
| 11403 |
|
| 11404 |
|
| 11405 |
|
| 11406 |
|
| 11407 |
class CSubInstancesOptimizedComplexConceptItemVisitor : public COptimizedComplexConceptItemVisitor { |
| 11408 |
public: |
| 11409 |
QSet<CRealizationIndividualInstanceItemReference>* mPossibleDirectInstanceItemSet; |
| 11410 |
COptimizedComplexConceptInstanziatedIndividualItemHash* mKnownDirectInstanceItems; |
| 11411 |
|
| 11412 |
CSubInstancesOptimizedComplexConceptItemVisitor(QSet<CRealizationIndividualInstanceItemReference>* possibleDirectInstanceItemSet, COptimizedComplexConceptInstanziatedIndividualItemHash* knownDirectInstanceItems) { |
| 11413 |
mPossibleDirectInstanceItemSet = possibleDirectInstanceItemSet; |
| 11414 |
mKnownDirectInstanceItems = knownDirectInstanceItems; |
| 11415 |
} |
| 11416 |
|
| 11417 |
cint64 mSubItemVisitingLimit = 50; |
| 11418 |
cint64 mSubItemResultVisitingLimit = 5; |
| 11419 |
|
| 11420 |
bool visitComplexSuperConceptItem(COptimizedComplexConceptItem* item, bool& continueVisitingSuperItems) { |
| 11421 |
CComplexConceptStepComputationProcess* compStep = item->getComputationProcess()->getInstancesComputationProcess(false); |
| 11422 |
if (compStep && compStep->isComputationProcessFinished()) { |
| 11423 |
COptimizedComplexConceptInstanziatedIndividualItemHash* subInstanceItems = item->getKnownInstanceItems(); |
| 11424 |
if (subInstanceItems) { |
| 11425 |
for (auto itemLinker = subInstanceItems->getAddedRealizationIndividualInstanceItemReferenceLinker(); itemLinker; itemLinker = itemLinker->getNext()) { |
| 11426 |
auto item = itemLinker->getRealizationIndividualInstanceItemReference(); |
| 11427 |
if (mPossibleDirectInstanceItemSet->contains(item)) { |
| 11428 |
mKnownDirectInstanceItems->addRealizationIndividualInstanceItemReference(item); |
| 11429 |
mPossibleDirectInstanceItemSet->remove(item); |
| 11430 |
} |
| 11431 |
} |
| 11432 |
continueVisitingSuperItems = false; |
| 11433 |
if (--mSubItemResultVisitingLimit < 0) { |
| 11434 |
return false; |
| 11435 |
} |
| 11436 |
} |
| 11437 |
} |
| 11438 |
if (--mSubItemVisitingLimit < 0) { |
| 11439 |
return false; |
| 11440 |
} |
| 11441 |
return true; |
| 11442 |
} |
| 11443 |
} subItemVisitor(possibleDirectInstanceItemSet, knownDirectInstanceItems); |
| 11444 |
visitSuperSubConceptItems(conceptItem, true, false, &subItemVisitor); |
| 11445 |
|
| 11446 |
|
| 11447 |
|
| 11448 |
conceptItem->setKnownInstanceItems(knownDirectInstanceItems); |
| 11449 |
conceptItem->setPossibleInstanceItemSet(possibleDirectInstanceItemSet); |
| 11450 |
|
| 11451 |
mTotalPossibleInstancesCount += possibleDirectInstanceItemSet->size(); |
| 11452 |
|
| 11453 |
return true; |
| 11454 |
} |
| 11455 |
|
| 11456 |
|
| 11457 |
|
| 11458 |
|
| 11459 |
bool COptimizedComplexExpressionAnsweringHandler::createSuperClassSubsumptionTest(COptimizedComplexConceptItem* conceptItem, CHierarchyNode* testingNode, CAnswererContext* answererContext) { |
| 11460 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 11461 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 11462 |
CConcept* superClassConcept = testingNode->getOneEquivalentConcept(); |
| 11463 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, conceptItem->isTopObjectPropertyUsed(), answererContext); |
| 11464 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(conceptItem->getConcept(), conceptItem->getConceptNegation(), superClassConcept, true, nullptr, satCalcJob); |
| 11465 |
CAnsweringMessageDataCalculationCompletedSubsumptionSuperClass* completedMessage = new CAnsweringMessageDataCalculationCompletedSubsumptionSuperClass(satCalcJob, conceptItem, testingNode); |
| 11466 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incComplexConceptItemsSuperClassSubsumptionTestingCount(); |
| 11467 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 11468 |
return true; |
| 11469 |
} |
| 11470 |
|
| 11471 |
|
| 11472 |
|
| 11473 |
bool COptimizedComplexExpressionAnsweringHandler::createSubClassSubsumptionTest(COptimizedComplexConceptItem* conceptItem, CHierarchyNode* testingNode, CAnswererContext* answererContext) { |
| 11474 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 11475 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 11476 |
CConcept* subClassConcept = testingNode->getOneEquivalentConcept(); |
| 11477 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, conceptItem->isTopObjectPropertyUsed(), answererContext); |
| 11478 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(subClassConcept, false, conceptItem->getConcept(), !conceptItem->getConceptNegation(), nullptr, satCalcJob); |
| 11479 |
CAnsweringMessageDataCalculationCompletedSubsumptionSubClass* completedMessage = new CAnsweringMessageDataCalculationCompletedSubsumptionSubClass(satCalcJob, conceptItem, testingNode); |
| 11480 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incComplexConceptItemsSubClassSubsumptionTestingCount(); |
| 11481 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 11482 |
return true; |
| 11483 |
} |
| 11484 |
|
| 11485 |
|
| 11486 |
|
| 11487 |
bool COptimizedComplexExpressionAnsweringHandler::createInvidiualInstanceTest(COptimizedComplexConceptItem* conceptItem, const CIndividualReference& testingIndiRef, CAnswererContext* answererContext) { |
| 11488 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 11489 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 11490 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, conceptItem->isTopObjectPropertyUsed(), answererContext); |
| 11491 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(conceptItem->getConcept(), !conceptItem->getConceptNegation(), testingIndiRef, satCalcJob); |
| 11492 |
CAnsweringMessageDataCalculationCompletedInstanceIndividual* completedMessage = new CAnsweringMessageDataCalculationCompletedInstanceIndividual(satCalcJob, conceptItem, testingIndiRef); |
| 11493 |
|
| 11494 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incComplexConceptItemsPossibleInstanceVerificationCount(); |
| 11495 |
|
| 11496 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 11497 |
return true; |
| 11498 |
} |
| 11499 |
|
| 11500 |
|
| 11501 |
|
| 11502 |
|
| 11503 |
|
| 11504 |
|
| 11505 |
|
| 11506 |
|
| 11507 |
|
| 11508 |
|
| 11509 |
CConcreteOntology* COptimizedComplexExpressionAnsweringHandler::createQueryMaterializationData(QSet<CExpressionVariable *> varExpSet, QSet<CExpressionVariable *> rolledVarExpSet, QSet<CExpressionVariable *> anonymousIndiVariableSet, QHash<CExpressionVariable *, CBuildExpression *> rebuiltVarClassTermExp, QHash<CExpressionVariable *, CAxiomExpression *> varExpAxiomExpHash, |
| 11510 |
bool allAnonymousVariables, QSet<CExpressionVariable *> initialAnonymousIndiVariableSet, QList<CDataPropertyAssertionExpression *> bothVarDataPropAssPropagationList, QList<CObjectPropertyAssertionExpression *> bothVarPropAssPropagationList, QList<CDataPropertyAssertionExpression *> onlyDataVarDataPropAssList, COptimizedComplexBuildingIndividualVariableCompositionsItem* varBuildItem, CAnswererContext* answererContext) { |
| 11511 |
|
| 11512 |
|
| 11513 |
CComplexQueryFinishingBuildingVariableCompositionsItemData* buildFinishingData = varBuildItem->getBuildingFinishingData(); |
| 11514 |
if (!buildFinishingData) { |
| 11515 |
buildFinishingData = new CComplexQueryFinishingBuildingVariableCompositionsItemData(); |
| 11516 |
buildFinishingData->varExpSet = varExpSet; |
| 11517 |
buildFinishingData->rolledVarExpSet = rolledVarExpSet; |
| 11518 |
buildFinishingData->anonymousIndiVariableSet = anonymousIndiVariableSet; |
| 11519 |
buildFinishingData->rebuiltVarClassTermExp = rebuiltVarClassTermExp; |
| 11520 |
buildFinishingData->varExpAxiomExpHash = varExpAxiomExpHash; |
| 11521 |
buildFinishingData->allAnonymousVariables = allAnonymousVariables; |
| 11522 |
buildFinishingData->initialAnonymousIndiVariableSet = initialAnonymousIndiVariableSet; |
| 11523 |
buildFinishingData->bothVarDataPropAssPropagationList = bothVarDataPropAssPropagationList; |
| 11524 |
buildFinishingData->bothVarPropAssPropagationList = bothVarPropAssPropagationList; |
| 11525 |
buildFinishingData->onlyDataVarDataPropAssList = onlyDataVarDataPropAssList; |
| 11526 |
varBuildItem->setBuildingFinishingData(buildFinishingData); |
| 11527 |
} |
| 11528 |
|
| 11529 |
CConcreteOntology* ontology = mOntoAnsweringItem->getTestingOntology(); |
| 11530 |
CComplexQueryMaterializationData* matData = varBuildItem->getMaterializationData(); |
| 11531 |
if (!matData) { |
| 11532 |
matData = new CComplexQueryMaterializationData(); |
| 11533 |
varBuildItem->setMaterializationData(matData); |
| 11534 |
} |
| 11535 |
CConcreteOntology* tmpMatOntology = matData->getTemporaryMaterializationOntology(); |
| 11536 |
if (!tmpMatOntology) { |
| 11537 |
tmpMatOntology = new CConcreteOntology(ontology, ontology->getConfiguration()); |
| 11538 |
tmpMatOntology->setOntologyID(ontology->getOntologyID()); |
| 11539 |
tmpMatOntology->setConsistence(ontology->getConsistence()); |
| 11540 |
tmpMatOntology->getTBox()->setMinimalNextConceptID(ontology->getTBox()->getMinimalNextConceptID()); |
| 11541 |
matData->setTemporaryMaterializationOntology(tmpMatOntology); |
| 11542 |
|
| 11543 |
CABox* tempRoleRealAbox = tmpMatOntology->getABox(); |
| 11544 |
CIndividualVector* indiVec = tempRoleRealAbox->getIndividualVector(true); |
| 11545 |
|
| 11546 |
CClassTermExpression* topClassTermExp = tmpMatOntology->getBuildData()->getTopClassExpression(); |
| 11547 |
CObjectPropertyTermExpression* topObjPropExp = tmpMatOntology->getBuildData()->getTopObjectPropertyExpression(); |
| 11548 |
|
| 11549 |
for (CExpressionVariable* varExp : varExpSet) { |
| 11550 |
|
| 11551 |
if (!rolledVarExpSet.contains(varExp)) { |
| 11552 |
CIndividual* varIndi = matData->getVariableIndividual(varExp); |
| 11553 |
|
| 11554 |
|
| 11555 |
QList<CBuildExpression*> varExpList = rebuiltVarClassTermExp.values(varExp); |
| 11556 |
|
| 11557 |
QList<CConcept*> conceptList; |
| 11558 |
|
| 11559 |
for (CBuildExpression* varClassTermExp : varExpList) { |
| 11560 |
CClassTermExpression* classTermExp = dynamic_cast<CClassTermExpression*>(varClassTermExp); |
| 11561 |
|
| 11562 |
CConcept* concept = tmpMatOntology->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value((CClassTermExpression*)classTermExp); |
| 11563 |
if (concept) { |
| 11564 |
conceptList.append(concept); |
| 11565 |
} |
| 11566 |
|
| 11567 |
} |
| 11568 |
|
| 11569 |
|
| 11570 |
|
| 11571 |
for (CConcept* concept : conceptList) { |
| 11572 |
CConceptAssertionLinker* nextConceptAssertionLinker = new CConceptAssertionLinker(); |
| 11573 |
nextConceptAssertionLinker->initNegLinker(concept, concept->hasMappingNegation()); |
| 11574 |
|
| 11575 |
varIndi->addAssertionConceptLinker(nextConceptAssertionLinker); |
| 11576 |
} |
| 11577 |
|
| 11578 |
|
| 11579 |
|
| 11580 |
|
| 11581 |
QList<CAxiomExpression*> assExplist = varExpAxiomExpHash.values(varExp); |
| 11582 |
for (CAxiomExpression* assExp : assExplist) { |
| 11583 |
CObjectPropertyAssertionExpression* propAssExp = dynamic_cast<CObjectPropertyAssertionExpression*>(assExp); |
| 11584 |
if (propAssExp) { |
| 11585 |
CObjectPropertyTermExpression* propExp = propAssExp->getObjectPropertyTermExpression(); |
| 11586 |
if (propExp != topObjPropExp) { |
| 11587 |
CRole* role = tmpMatOntology->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash()->value(propExp); |
| 11588 |
CIndividualTermExpression* firstIndiExp = propAssExp->getFirstIndividualTermExpression(); |
| 11589 |
CIndividualTermExpression* secondIndiExp = propAssExp->getSecondIndividualTermExpression(); |
| 11590 |
CIndividualVariableExpression* firstVarExp = dynamic_cast<CIndividualVariableExpression*>(firstIndiExp); |
| 11591 |
CIndividualVariableExpression* secondVarExp = dynamic_cast<CIndividualVariableExpression*>(secondIndiExp); |
| 11592 |
if ((!firstVarExp || !rolledVarExpSet.contains(firstVarExp)) && (!secondVarExp || !rolledVarExpSet.contains(secondVarExp))) { |
| 11593 |
CIndividual* firstIndi = nullptr; |
| 11594 |
CIndividual* secondIndi = nullptr; |
| 11595 |
if (firstVarExp) { |
| 11596 |
firstIndi = matData->getVariableIndividual(firstVarExp); |
| 11597 |
} else { |
| 11598 |
firstIndi = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getIndividulTermIndiMappingHash()->value(firstIndiExp); |
| 11599 |
if (!firstIndi) { |
| 11600 |
CNamedIndividualExpression* namedFirstIndiExp = dynamic_cast<CNamedIndividualExpression*>(firstIndiExp); |
| 11601 |
if (namedFirstIndiExp) { |
| 11602 |
firstIndi = mOntoAnsweringItem->getTestingOntology()->getStringMapping()->getIndividualFromName(namedFirstIndiExp->getName()); |
| 11603 |
} |
| 11604 |
} |
| 11605 |
if (firstIndi) { |
| 11606 |
firstIndi = CConceptRoleIndividualLocator::getLocatedIndividual(firstIndi, tmpMatOntology); |
| 11607 |
} |
| 11608 |
} |
| 11609 |
if (secondVarExp) { |
| 11610 |
secondIndi = matData->getVariableIndividual(secondVarExp); |
| 11611 |
} else { |
| 11612 |
secondIndi = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getIndividulTermIndiMappingHash()->value(secondIndiExp); |
| 11613 |
if (!secondIndi) { |
| 11614 |
CNamedIndividualExpression* namedSecondIndiExp = dynamic_cast<CNamedIndividualExpression*>(secondIndiExp); |
| 11615 |
if (namedSecondIndiExp) { |
| 11616 |
secondIndi = mOntoAnsweringItem->getTestingOntology()->getStringMapping()->getIndividualFromName(namedSecondIndiExp->getName()); |
| 11617 |
} |
| 11618 |
} |
| 11619 |
if (secondIndi) { |
| 11620 |
secondIndi = CConceptRoleIndividualLocator::getLocatedIndividual(secondIndi, tmpMatOntology); |
| 11621 |
} |
| 11622 |
} |
| 11623 |
|
| 11624 |
if (firstIndi && secondIndi) { |
| 11625 |
CRoleAssertionLinker* nextRoleAssertionLinker = new CRoleAssertionLinker(); |
| 11626 |
nextRoleAssertionLinker->initRoleAssertionLinker(role, secondIndi); |
| 11627 |
firstIndi->addAssertionRoleLinker(nextRoleAssertionLinker); |
| 11628 |
|
| 11629 |
CReverseRoleAssertionLinker* nextReverseRoleAssertionLinker = new CReverseRoleAssertionLinker(); |
| 11630 |
nextReverseRoleAssertionLinker->initReverseRoleAssertionLinker(nextRoleAssertionLinker, firstIndi); |
| 11631 |
secondIndi->addReverseAssertionRoleLinker(nextReverseRoleAssertionLinker); |
| 11632 |
} |
| 11633 |
|
| 11634 |
} |
| 11635 |
} |
| 11636 |
} |
| 11637 |
|
| 11638 |
//CDataPropertyAssertionExpression* dataPropAssExp = dynamic_cast<CDataPropertyAssertionExpression*>(assExp); |
| 11639 |
//if (dataPropAssExp) { |
| 11640 |
// CDataPropertyTermExpression* dataPropTermExp = dataPropAssExp->getDataPropertyTermExpression(); |
| 11641 |
// CIndividualVariableExpression* indiVarExp = dynamic_cast<CIndividualVariableExpression*>(dataPropAssExp->getIndividualTermExpression()); |
| 11642 |
// CDataLiteralVariableExpression* dataVarExp = dynamic_cast<CDataLiteralVariableExpression*>(dataPropAssExp->getDataLiteralTermExpression()); |
| 11643 |
// if (indiVarExp && !dataVarExp) { |
| 11644 |
// CRole* role = tmpMatOntology->getDataBoxes()->getExpressionDataBoxMapping()->getDataPropertyTermRoleMappingHash()->value(dataPropTermExp); |
| 11645 |
// CDataLiteralExpression* dataLiteralExp = (CDataLiteralExpression*)dataPropAssExp->getDataLiteralTermExpression(); |
| 11646 |
|
| 11647 |
|
| 11648 |
// CDataLiteral* dataLiteral = CObjectParameterizingAllocator<CDataLiteral, CContext*>::allocateAndConstructAndParameterize(mMemMan, updateConcreteOntology->getDataBoxes()->getBoxContext()); |
| 11649 |
// dataLiteral->initDataLiteral(QString::fromUtf8(literalValue), datatype); |
| 11650 |
|
| 11651 |
// createDataLiteralValue(dataLiteral, updateConcreteOntology); |
| 11652 |
|
| 11653 |
// CDataAssertionLinker* dataAssertionLinker = new CDataAssertionLinker(); |
| 11654 |
// dataAssertionLinker->initDataAssertionLinker(role, ) |
| 11655 |
// |
| 11656 |
|
| 11657 |
// dataLiteralExp = (CDataLiteralExpression*)mTestingOntologyBuilder->rebuildExpression(dataLiteralExp); |
| 11658 |
// instTestingExpList.append(mTestingOntologyBuilder->getDataHasValue(dataPropTermExp, dataLiteralExp)); |
| 11659 |
// } |
| 11660 |
|
| 11661 |
//} |
| 11662 |
} |
| 11663 |
} |
| 11664 |
|
| 11665 |
|
| 11666 |
} |
| 11667 |
|
| 11668 |
|
| 11669 |
|
| 11670 |
} |
| 11671 |
return tmpMatOntology; |
| 11672 |
} |
| 11673 |
|
| 11674 |
|
| 11675 |
|
| 11676 |
bool COptimizedComplexExpressionAnsweringHandler::createQueryMaterializationTest(COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CAnswererContext* answererContext) { |
| 11677 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 11678 |
|
| 11679 |
CComplexQueryMaterializationData* matData = buildingVarItem->getMaterializationData(); |
| 11680 |
|
| 11681 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 11682 |
|
| 11683 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(matData->getVariableIndividualList()); |
| 11684 |
|
| 11685 |
|
| 11686 |
|
| 11687 |
CAnsweringMessageDataCalculationCompletedQueryMaterialization* completedMessage = new CAnsweringMessageDataCalculationCompletedQueryMaterialization(satCalcJob, buildingVarItem, matData); |
| 11688 |
satCalcJob->setSatisfiableAnswererMaterializationAdapter(new CSatisfiableTaskAnswererQueryingMaterializationAdapter(matData->getVariableIndividualList(), (cint64)matData, this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler())); |
| 11689 |
|
| 11690 |
|
| 11691 |
//mOntoAnsweringItem->getAnsweringHandlingStatistics()->getComplexConceptItemsPossibleInstanceVerificationCount(); |
| 11692 |
|
| 11693 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 11694 |
return true; |
| 11695 |
} |
| 11696 |
|
| 11697 |
|
| 11698 |
|
| 11699 |
static bool tuplesSortMoreHierachyDepthThan(const TDepthHierarchyNodeConceptClassTermExpressionTuple& item1, const TDepthHierarchyNodeConceptClassTermExpressionTuple& item2) { |
| 11700 |
return item1.first.first == -1 || item1.first.first > item2.first.first; |
| 11701 |
} |
| 11702 |
|
| 11703 |
|
| 11704 |
bool COptimizedComplexExpressionAnsweringHandler::processQueryMaterializationCalculationCompleted(CAnsweringMessageDataCalculationCompletedQueryMaterialization* message, CAnswererContext* answererContext) { |
| 11705 |
|
| 11706 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem = message->getBuildingVariableCompositionItem(); |
| 11707 |
CComplexQueryMaterializationData* matData = message->getMaterializationData(); |
| 11708 |
CComplexQueryExpressionProcessingData* queryProcessingData = buildingVarItem->getQueryProcessingData(); |
| 11709 |
|
| 11710 |
if (!message->isSatisfiable()) { |
| 11711 |
buildingVarItem->setSatisfiability(false); |
| 11712 |
|
| 11713 |
LOG(INFO, getDomain(), logTr("Query materialization revealed unsatisfiability."), this); |
| 11714 |
finishQueryProcessingAsUnsatisfaible(queryProcessingData); |
| 11715 |
|
| 11716 |
} else { |
| 11717 |
|
| 11718 |
// sort concepts with classified class hierarchy and use only minimized/necessary concepts |
| 11719 |
CTaxonomy* classHierarchy = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy(); |
| 11720 |
|
| 11721 |
QList<CIndividual*> indiList = matData->getVariableIndividualList(); |
| 11722 |
QHash<CExpressionVariable*, CConcept*>* variableMaterializedConceptsHash = matData->getVariableMaterializedConceptsHash(); |
| 11723 |
QHash<CExpressionVariable*, CBuildExpression*>* variableClassTermExpHash = buildingVarItem->getVariableClassTermExpressionHash(); |
| 11724 |
|
| 11725 |
QHash<CExpressionVariable*, CBuildExpression*> newVariableClassTermExpHash; |
| 11726 |
for (CIndividual* indi : indiList) { |
| 11727 |
CExpressionVariable* expVar = matData->getVariable(indi); |
| 11728 |
QList<CConcept*> conceptList = variableMaterializedConceptsHash->values(expVar); |
| 11729 |
|
| 11730 |
QList< QPair<CConcept*, CClassTermExpression*> > conceptClassTermExpList; |
| 11731 |
for (CConcept* concept : conceptList) { |
| 11732 |
CClassTermExpression* classExp = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getConceptClassTermMappingHash()->value(concept); |
| 11733 |
conceptClassTermExpList.append(QPair<CConcept*, CClassTermExpression*>(concept, classExp)); |
| 11734 |
} |
| 11735 |
|
| 11736 |
for (CBuildExpression* buildExp : variableClassTermExpHash->values(expVar)) { |
| 11737 |
CClassTermExpression* classExp = (CClassTermExpression*)buildExp; |
| 11738 |
CConcept* concept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(classExp); |
| 11739 |
conceptClassTermExpList.append(QPair<CConcept*, CClassTermExpression*>(concept, classExp)); |
| 11740 |
} |
| 11741 |
|
| 11742 |
CHierarchyNode* topHierNode = classHierarchy->getTopHierarchyNode(); |
| 11743 |
|
| 11744 |
QList<TDepthHierarchyNodeConceptClassTermExpressionTuple> depthConceptHierTupleList; |
| 11745 |
for (QPair<CConcept*, CClassTermExpression*> conceptClassTermExpPair : conceptClassTermExpList) { |
| 11746 |
CConcept* concept = conceptClassTermExpPair.first; |
| 11747 |
CClassTermExpression* classTermExp = conceptClassTermExpPair.second; |
| 11748 |
|
| 11749 |
CHierarchyNode* hierNode = classHierarchy->getHierarchyNode(concept, false); |
| 11750 |
if (hierNode != topHierNode) { |
| 11751 |
if (hierNode) { |
| 11752 |
depthConceptHierTupleList.append(TDepthHierarchyNodeConceptClassTermExpressionTuple(QPair<cint64, CHierarchyNode*>(hierNode->getPredecessorNodeCount(), hierNode), QPair<CConcept*, CClassTermExpression*>(concept, classTermExp))); |
| 11753 |
} else { |
| 11754 |
depthConceptHierTupleList.append(TDepthHierarchyNodeConceptClassTermExpressionTuple(QPair<cint64, CHierarchyNode*>(-1, nullptr), QPair<CConcept*, CClassTermExpression*>(concept, classTermExp))); |
| 11755 |
} |
| 11756 |
} |
| 11757 |
|
| 11758 |
} |
| 11759 |
qSort(depthConceptHierTupleList.begin(), depthConceptHierTupleList.end(), tuplesSortMoreHierachyDepthThan); |
| 11760 |
|
| 11761 |
|
| 11762 |
QList< CClassTermExpression* > newClassTermExpList; |
| 11763 |
QSet<CHierarchyNode*> includedPredecessorNodeSet; |
| 11764 |
for (const TDepthHierarchyNodeConceptClassTermExpressionTuple& tuple : depthConceptHierTupleList) { |
| 11765 |
CHierarchyNode* hierNode = tuple.first.second; |
| 11766 |
bool include = false; |
| 11767 |
if (hierNode) { |
| 11768 |
if (!includedPredecessorNodeSet.contains(hierNode)) { |
| 11769 |
include = true; |
| 11770 |
} |
| 11771 |
} else { |
| 11772 |
include = true; |
| 11773 |
} |
| 11774 |
|
| 11775 |
if (include) { |
| 11776 |
newClassTermExpList.append(tuple.second.second); |
| 11777 |
if (hierNode) { |
| 11778 |
includedPredecessorNodeSet.insert(hierNode); |
| 11779 |
for (CHierarchyNode* predHierNode : *hierNode->getPredecessorNodeSet()) { |
| 11780 |
includedPredecessorNodeSet.insert(predHierNode); |
| 11781 |
} |
| 11782 |
} |
| 11783 |
} |
| 11784 |
} |
| 11785 |
|
| 11786 |
for (CClassTermExpression* classTermExp : newClassTermExpList) { |
| 11787 |
if (classTermExp) { |
| 11788 |
newVariableClassTermExpHash.insertMulti(expVar, classTermExp); |
| 11789 |
} |
| 11790 |
} |
| 11791 |
|
| 11792 |
} |
| 11793 |
buildingVarItem->setVariableClassTermExpressionHash(newVariableClassTermExpHash); |
| 11794 |
|
| 11795 |
|
| 11796 |
CComplexQueryFinishingBuildingVariableCompositionsItemData* buildFinishingData = buildingVarItem->getBuildingFinishingData(); |
| 11797 |
if (buildFinishingData) { |
| 11798 |
|
| 11799 |
mTestingOntologyBuilder->initializeBuilding(); |
| 11800 |
|
| 11801 |
finishConceptAndAbsorptionItemsGeneration(buildFinishingData->varExpSet, buildFinishingData->rolledVarExpSet, buildFinishingData->anonymousIndiVariableSet, *buildingVarItem->getVariableClassTermExpressionHash(), buildFinishingData->varExpAxiomExpHash, buildFinishingData->allAnonymousVariables, buildFinishingData->initialAnonymousIndiVariableSet, |
| 11802 |
buildFinishingData->bothVarDataPropAssPropagationList, buildFinishingData->bothVarPropAssPropagationList, buildFinishingData->onlyDataVarDataPropAssList, buildingVarItem, answererContext); |
| 11803 |
|
| 11804 |
} |
| 11805 |
} |
| 11806 |
|
| 11807 |
|
| 11808 |
|
| 11809 |
return true; |
| 11810 |
} |
| 11811 |
|
| 11812 |
|
| 11813 |
|
| 11814 |
bool COptimizedComplexExpressionAnsweringHandler::processExtractedMaterializationConcept(CAnsweringMessageDataCalculationMaterializedConcepts* matConceptsMessage, CAnswererContext* answererContext) { |
| 11815 |
CComplexQueryMaterializationData* matData = (CComplexQueryMaterializationData*)matConceptsMessage->getMaterializationDataIdentifier(); |
| 11816 |
CIndividual* varIndi = matConceptsMessage->getVariableIndividual(); |
| 11817 |
|
| 11818 |
QHash<CExpressionVariable*, CConcept*>* variableMaterializedConceptsHash = matData->getVariableMaterializedConceptsHash(); |
| 11819 |
CExpressionVariable* var = matData->getVariable(varIndi); |
| 11820 |
|
| 11821 |
CCLASSSUBSUMPTIONMESSAGELIST<CConcept*>* subsumerList = matConceptsMessage->getClassSubsumerList(); |
| 11822 |
if (subsumerList) { |
| 11823 |
for (CConcept* subsumerCon : *subsumerList) { |
| 11824 |
variableMaterializedConceptsHash->insertMulti(var, subsumerCon); |
| 11825 |
} |
| 11826 |
} |
| 11827 |
|
| 11828 |
return true; |
| 11829 |
} |
| 11830 |
|
| 11831 |
|
| 11832 |
|
| 11833 |
|
| 11834 |
bool COptimizedComplexExpressionAnsweringHandler::canSplitActivationIndividualPropagation(COptimizedComplexConceptItem* conceptItem, CConceptOfInterestActivationTriggeringData activationTriggeringData, CAnswererContext* answererContext) { |
| 11835 |
CConceptOfInterestActivationLinker* activationLinker = activationTriggeringData.getActivationLinker(); |
| 11836 |
if (activationLinker && !activationLinker->hasNext() && activationLinker->getActivationIndividual()) { |
| 11837 |
CConcept* actCon = activationLinker->getActivationConcept(); |
| 11838 |
|
| 11839 |
CConceptOperator* conceptOperator = actCon->getConceptOperator(); |
| 11840 |
if (conceptOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_ALL_AQALL_TYPE)) { |
| 11841 |
CRole* role = actCon->getRole(); |
| 11842 |
if (!role->isComplexRole()) { |
| 11843 |
return true; |
| 11844 |
} |
| 11845 |
} |
| 11846 |
|
| 11847 |
} |
| 11848 |
return false; |
| 11849 |
} |
| 11850 |
|
| 11851 |
|
| 11852 |
|
| 11853 |
|
| 11854 |
|
| 11855 |
double COptimizedComplexExpressionAnsweringHandler::getNextRoleActivationPropagationMultiplicationEstimation(double currentExpectedCount, const QSet<CRealizationIndividualInstanceItemReference>& currentSample, CConcept* currentPropConcept, QSet<CRealizationIndividualInstanceItemReference>& nextSample, CConcept*& nextPropagationConcept, CAnswererContext* answererContext) { |
| 11856 |
CRoleRealization* roleRealization = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 11857 |
|
| 11858 |
nextPropagationConcept = nullptr; |
| 11859 |
|
| 11860 |
QList<TConceptNegPair> testingPropConList; |
| 11861 |
testingPropConList.append(TConceptNegPair(currentPropConcept, false)); |
| 11862 |
while (!testingPropConList.isEmpty()) { |
| 11863 |
TConceptNegPair conNegPair = testingPropConList.takeFirst(); |
| 11864 |
CConcept* concept = conNegPair.first; |
| 11865 |
bool conNeg = conNegPair.second; |
| 11866 |
|
| 11867 |
CConceptOperator* conceptOperator = concept->getConceptOperator(); |
| 11868 |
if (!conNeg && conceptOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_ALL_AQALL_TYPE)) { |
| 11869 |
if (concept->getRole() && !concept->getRole()->isComplexRole()) { |
| 11870 |
nextPropagationConcept = concept; |
| 11871 |
break; |
| 11872 |
} |
| 11873 |
} |
| 11874 |
|
| 11875 |
if (!conNeg && conceptOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_TRIG_AND_AQAND_TYPE)) { |
| 11876 |
for (CSortedNegLinker<CConcept*>* opConLinkerIt = concept->getOperandList(); opConLinkerIt; opConLinkerIt = opConLinkerIt->getNext()) { |
| 11877 |
testingPropConList.append(TConceptNegPair(opConLinkerIt->getData(), opConLinkerIt->isNegated())); |
| 11878 |
} |
| 11879 |
} else if (!conNeg && conceptOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_IMPL_TYPE) && concept->getOperandList()) { |
| 11880 |
testingPropConList.prepend(TConceptNegPair(concept->getOperandList()->getData(), concept->getOperandList()->isNegated())); |
| 11881 |
} |
| 11882 |
|
| 11883 |
} |
| 11884 |
|
| 11885 |
|
| 11886 |
CRole* role = nullptr; |
| 11887 |
if (nextPropagationConcept) { |
| 11888 |
role = nextPropagationConcept->getRole(); |
| 11889 |
|
| 11890 |
CRoleInstantiatedItem* roleInstancesItem = roleRealization->getRoleInstantiatedItem(role); |
| 11891 |
|
| 11892 |
|
| 11893 |
cint64 requiredSamplingCount = 15; |
| 11894 |
if (requiredSamplingCount > currentSample.size()) { |
| 11895 |
requiredSamplingCount = currentSample.size(); |
| 11896 |
} |
| 11897 |
cint64 currentSampleCount = 0; |
| 11898 |
if (currentSampleCount < requiredSamplingCount) { |
| 11899 |
|
| 11900 |
cint64 averageCount = 0; |
| 11901 |
double averageEstimatedCount = 0; |
| 11902 |
cint64 nextSampleAddingCount = 3; |
| 11903 |
|
| 11904 |
auto averageBindingsEstimate = [&](const CRealizationIndividualInstanceItemReference& propInstItemRef) { |
| 11905 |
CRealizationIndividualInstanceItemReferenceIterator* iterator = roleRealization->getRoleFillerInstancesIterator(propInstItemRef, roleInstancesItem, false, mRoleFillerRealizationSorting); |
| 11906 |
iterator->begin(); |
| 11907 |
|
| 11908 |
double estimatedCount = iterator->remainingInstancesEstimation().getEstimatedCount(); |
| 11909 |
while (!iterator->atEnd() && nextSampleAddingCount-- > 0) { |
| 11910 |
nextSample.insert(iterator->currentIndividualInstanceItemReference()); |
| 11911 |
iterator->moveNext(); |
| 11912 |
} |
| 11913 |
|
| 11914 |
averageEstimatedCount += estimatedCount; |
| 11915 |
averageCount++; |
| 11916 |
delete iterator; |
| 11917 |
}; |
| 11918 |
|
| 11919 |
QSet<CRealizationIndividualInstanceItemReference>::const_iterator sampleIt = currentSample.constBegin(); |
| 11920 |
while (currentSampleCount++ < requiredSamplingCount && sampleIt != currentSample.constEnd()) { |
| 11921 |
CRealizationIndividualInstanceItemReference sampleInstItemRef = *sampleIt; |
| 11922 |
averageBindingsEstimate(sampleInstItemRef); |
| 11923 |
} |
| 11924 |
if (averageCount != 0) { |
| 11925 |
averageEstimatedCount = averageEstimatedCount / averageCount * currentExpectedCount; |
| 11926 |
} |
| 11927 |
|
| 11928 |
return averageEstimatedCount; |
| 11929 |
} |
| 11930 |
} |
| 11931 |
return 0; |
| 11932 |
} |
| 11933 |
|
| 11934 |
|
| 11935 |
|
| 11936 |
|
| 11937 |
|
| 11938 |
|
| 11939 |
|
| 11940 |
CConcept* COptimizedComplexExpressionAnsweringHandler::getSplitActivationIndividualPropagationConcept(COptimizedComplexConceptItem* conceptItem, CConceptOfInterestActivationTriggeringData activationTriggeringData, CVariable*& propVar, double& splitCompSize, CAnswererContext* answererContext) { |
| 11941 |
CConceptOfInterestActivationLinker* activationLinker = activationTriggeringData.getActivationLinker(); |
| 11942 |
CConcept* actCon = activationLinker->getActivationConcept(); |
| 11943 |
|
| 11944 |
CConcept* splitPropConcept = actCon; |
| 11945 |
|
| 11946 |
bool splitEstimationReached = false; |
| 11947 |
double splitEstimationSize = mConfAbsorbedIndividualActivationInstanceCandidatePropagationDirectSplittingSize; |
| 11948 |
double firstEstimationSize = -1; |
| 11949 |
|
| 11950 |
|
| 11951 |
double maxEstimationSize = 0; |
| 11952 |
CConcept* maxPropConcept = actCon; |
| 11953 |
|
| 11954 |
|
| 11955 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 11956 |
QSet<CRealizationIndividualInstanceItemReference> currentIndiSampleSet; |
| 11957 |
double currentEstimationCount = 1; |
| 11958 |
CConcept* currentPropConcept = actCon; |
| 11959 |
currentIndiSampleSet.insert(sameRealization->getSameInstanceItemReference(activationTriggeringData.getActivationLinker()->getActivationIndividual())); |
| 11960 |
|
| 11961 |
|
| 11962 |
while (currentEstimationCount < splitEstimationSize && currentPropConcept) { |
| 11963 |
|
| 11964 |
QSet<CRealizationIndividualInstanceItemReference> nextIndiSampleSet; |
| 11965 |
CConcept* nextPropConcept = nullptr; |
| 11966 |
double nextPropEstimationCount = getNextRoleActivationPropagationMultiplicationEstimation(currentEstimationCount, currentIndiSampleSet, currentPropConcept, nextIndiSampleSet, nextPropConcept, answererContext); |
| 11967 |
|
| 11968 |
if (nextPropEstimationCount > maxEstimationSize) { |
| 11969 |
maxPropConcept = nextPropConcept; |
| 11970 |
} |
| 11971 |
if (firstEstimationSize < 0) { |
| 11972 |
firstEstimationSize = nextPropEstimationCount; |
| 11973 |
} |
| 11974 |
|
| 11975 |
if (nextPropConcept && nextPropEstimationCount >= splitEstimationSize) { |
| 11976 |
currentEstimationCount = nextPropEstimationCount; |
| 11977 |
splitPropConcept = nextPropConcept; |
| 11978 |
splitEstimationReached = true; |
| 11979 |
break; |
| 11980 |
} else if (nextPropConcept) { |
| 11981 |
currentPropConcept = nextPropConcept->getOperandList()->getData(); |
| 11982 |
currentEstimationCount = nextPropEstimationCount; |
| 11983 |
currentIndiSampleSet = nextIndiSampleSet; |
| 11984 |
} else { |
| 11985 |
break; |
| 11986 |
} |
| 11987 |
} |
| 11988 |
|
| 11989 |
if (!splitEstimationReached && maxPropConcept && maxEstimationSize > mConfAbsorbedIndividualActivationInstanceCandidatePropagationMinimumSplittingSize) { |
| 11990 |
splitEstimationReached = maxPropConcept; |
| 11991 |
currentEstimationCount = maxEstimationSize; |
| 11992 |
} |
| 11993 |
|
| 11994 |
if (splitEstimationReached) { |
| 11995 |
splitCompSize = currentEstimationCount; |
| 11996 |
propVar = splitPropConcept->getVariable(); |
| 11997 |
if (!propVar) { |
| 11998 |
CMemoryAllocationManager* memMan = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getBoxContext()->getMemoryAllocationManager(); |
| 11999 |
propVar = CObjectAllocator< CVariable >::allocateAndConstruct(memMan); |
| 12000 |
CSortedLinker<CVariable*>* propVarLinker = CObjectAllocator< CSortedLinker<CVariable*> >::allocateAndConstruct(memMan); |
| 12001 |
propVarLinker->setData(propVar); |
| 12002 |
propVar->initVariable(nullptr, 0); |
| 12003 |
splitPropConcept->setVariableLinker(propVarLinker); |
| 12004 |
} |
| 12005 |
return actCon; |
| 12006 |
} |
| 12007 |
|
| 12008 |
|
| 12009 |
|
| 12010 |
QHash<CConcept*, CConcept*>* activationPropagationSplitConceptHash = mOntoAnsweringItem->getActivationPropagationSplitConceptHash(); |
| 12011 |
CConcept*& concept = (*activationPropagationSplitConceptHash)[actCon]; |
| 12012 |
|
| 12013 |
splitCompSize = firstEstimationSize; |
| 12014 |
|
| 12015 |
if (!concept) { |
| 12016 |
CMemoryAllocationManager* memMan = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getBoxContext()->getMemoryAllocationManager(); |
| 12017 |
CTBox* tBox = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getTBox(); |
| 12018 |
CConceptVector* conceptVec = tBox->getConceptVector(); |
| 12019 |
|
| 12020 |
CConcept* propConcept = CObjectAllocator< CConcept >::allocateAndConstruct(memMan); |
| 12021 |
cint64 nextConTag = tBox->getNextConceptID(); |
| 12022 |
propConcept->initConceptCopy(actCon); |
| 12023 |
propConcept->setOperandList(actCon->getOperandList()); |
| 12024 |
propConcept->setTag(nextConTag); |
| 12025 |
conceptVec->setLocalData(nextConTag, propConcept); |
| 12026 |
|
| 12027 |
propVar = CObjectAllocator< CVariable >::allocateAndConstruct(memMan); |
| 12028 |
CSortedLinker<CVariable*>* propVarLinker = CObjectAllocator< CSortedLinker<CVariable*> >::allocateAndConstruct(memMan); |
| 12029 |
propVarLinker->setData(propVar); |
| 12030 |
propVar->initVariable(nullptr, 0); |
| 12031 |
propConcept->setVariableLinker(propVarLinker); |
| 12032 |
concept = propConcept; |
| 12033 |
} |
| 12034 |
if (concept) { |
| 12035 |
propVar = concept->getVariable(); |
| 12036 |
} |
| 12037 |
|
| 12038 |
return concept; |
| 12039 |
} |
| 12040 |
|
| 12041 |
|
| 12042 |
bool COptimizedComplexExpressionAnsweringHandler::createCandidatePropagationInstanceTest(COptimizedComplexConceptItem* conceptItem, CConceptOfInterestActivationTriggeringData activationTriggeringData, CAnswererContext* answererContext) { |
| 12043 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 12044 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 12045 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 12046 |
QSet<CRealizationIndividualInstanceItemReference> testingSet; |
| 12047 |
CComplexConceptStepInstanceComputationProcess* compStep = conceptItem->getComputationProcess()->getInstancesComputationProcess(true); |
| 12048 |
|
| 12049 |
if (mConfAbsorbedIndividualActivationInstanceCandidatePropagationSplitting && canSplitActivationIndividualPropagation(conceptItem, activationTriggeringData, answererContext)) { |
| 12050 |
CVariable* propVar = nullptr; |
| 12051 |
double splitCompSize = 0; |
| 12052 |
CConcept* splitableIndActCon = getSplitActivationIndividualPropagationConcept(conceptItem, activationTriggeringData, propVar, splitCompSize, answererContext); |
| 12053 |
testingSet = *possibleInstanceItemSet; |
| 12054 |
|
| 12055 |
cint64 moduloCount = 1; |
| 12056 |
if (propVar && splitCompSize > mConfAbsorbedIndividualActivationInstanceCandidatePropagationMinimumSplittingSize) { |
| 12057 |
double splitFac = 40 * log(splitCompSize) / log(10); |
| 12058 |
moduloCount = qMin((cint64)(splitCompSize / splitFac), mConfAbsorbedIndividualActivationInstanceCandidatePropagationMaximumSplittingCount); |
| 12059 |
} |
| 12060 |
for (cint64 indiModulo = 0; indiModulo < moduloCount; ++indiModulo) { |
| 12061 |
satCalcJob = nullptr; |
| 12062 |
|
| 12063 |
CAnsweringPropagationSteeringAbsorptionPropagationController* propCon = nullptr; |
| 12064 |
if (moduloCount > 1) { |
| 12065 |
propCon = new CAnsweringPropagationSteeringAbsorptionPropagationController(propVar, moduloCount, indiModulo); |
| 12066 |
} |
| 12067 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, conceptItem->isTopObjectPropertyUsed(), answererContext); |
| 12068 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(splitableIndActCon, false, activationTriggeringData.getActivationLinker()->getActivationIndividual(), satCalcJob); |
| 12069 |
|
| 12070 |
CAnsweringMessageDataCalculationCompletedInstanceCandidatePropagationItem* completedMessage = new CAnsweringMessageDataCalculationCompletedInstanceCandidatePropagationItem(satCalcJob, conceptItem, testingSet); |
| 12071 |
satCalcJob->setSatisfiableAnswererInstancePropagationMessageAdapter(new CSatisfiableTaskAnswererInstancePropagationMessageAdapter(conceptItem->getConcept(), conceptItem->getConceptNegation(), activationTriggeringData.getTriggeringConcept() == nullptr, this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler(), propCon)); |
| 12072 |
|
| 12073 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incComplexConceptItemsCandidatePropagationCount(); |
| 12074 |
|
| 12075 |
continueCalculationJobFromNondeterministicCachedGraph(satCalcJob, answererContext); |
| 12076 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 12077 |
|
| 12078 |
if (indiModulo != 0) { |
| 12079 |
compStep->setComputationProcessProcessing(true); |
| 12080 |
compStep->incCurrentlyRunningComputationCount(); |
| 12081 |
conceptItem->incCandidatePropagationProcessingCount(); |
| 12082 |
} |
| 12083 |
} |
| 12084 |
conceptItem->setPossibleInstanceItemSetCandidatePropagationIterator(possibleInstanceItemSet->constEnd()); |
| 12085 |
conceptItem->setPossibleInstanceItemSetCandidatePropagationIteratorInitialized(true); |
| 12086 |
conceptItem->setPossibleInstanceCandidatePropagationItemSet(possibleInstanceItemSet); |
| 12087 |
conceptItem->setPossibleInstanceItemSet(new QSet<CRealizationIndividualInstanceItemReference>()); |
| 12088 |
conceptItem->setPossibleInstanceCandidatePropagationBeginningKnownInstancesCount(conceptItem->getKnownInstanceItems()->size()); |
| 12089 |
|
| 12090 |
|
| 12091 |
} else { |
| 12092 |
|
| 12093 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, conceptItem->isTopObjectPropertyUsed(), answererContext); |
| 12094 |
bool allOnceProp = false; |
| 12095 |
for (CConceptOfInterestActivationLinker* activationLinkerIt = activationTriggeringData.getActivationLinker(); activationLinkerIt; activationLinkerIt = activationLinkerIt->getNext()) { |
| 12096 |
if (activationLinkerIt->getActivationIndividual()) { |
| 12097 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(activationLinkerIt->getActivationConcept(), false, activationLinkerIt->getActivationIndividual(), satCalcJob); |
| 12098 |
allOnceProp = true; |
| 12099 |
testingSet = *possibleInstanceItemSet; |
| 12100 |
conceptItem->setPossibleInstanceItemSetCandidatePropagationIteratorInitialized(true); |
| 12101 |
conceptItem->setPossibleInstanceCandidatePropagationItemSet(possibleInstanceItemSet); |
| 12102 |
conceptItem->setPossibleInstanceItemSetCandidatePropagationIterator(possibleInstanceItemSet->constBegin()); |
| 12103 |
conceptItem->setPossibleInstanceItemSet(new QSet<CRealizationIndividualInstanceItemReference>()); |
| 12104 |
conceptItem->setPossibleInstanceCandidatePropagationBeginningKnownInstancesCount(conceptItem->getKnownInstanceItems()->size()); |
| 12105 |
} |
| 12106 |
} |
| 12107 |
for (CConceptOfInterestActivationLinker* activationLinkerIt = activationTriggeringData.getActivationLinker(); activationLinkerIt; activationLinkerIt = activationLinkerIt->getNext()) { |
| 12108 |
if (!activationLinkerIt->getActivationIndividual()) { |
| 12109 |
|
| 12110 |
if (!conceptItem->hasPossibleInstanceItemSetCandidatePropagationIteratorInitialized()) { |
| 12111 |
conceptItem->setPossibleInstanceItemSetCandidatePropagationIteratorInitialized(true); |
| 12112 |
conceptItem->setPossibleInstanceCandidatePropagationItemSet(possibleInstanceItemSet); |
| 12113 |
conceptItem->setPossibleInstanceItemSet(new QSet<CRealizationIndividualInstanceItemReference>()); |
| 12114 |
conceptItem->setPossibleInstanceItemSetCandidatePropagationIterator(possibleInstanceItemSet->constBegin()); |
| 12115 |
conceptItem->setPossibleInstanceCandidatePropagationBeginningKnownInstancesCount(conceptItem->getKnownInstanceItems()->size()); |
| 12116 |
} |
| 12117 |
|
| 12118 |
cint64 count = 0; |
| 12119 |
QSet<CRealizationIndividualInstanceItemReference>::const_iterator candIt = conceptItem->getPossibleInstanceItemSetCandidatePropagationIterator(); |
| 12120 |
for (QSet<CRealizationIndividualInstanceItemReference>::const_iterator candItEnd = conceptItem->getPossibleInstanceCandidatePropagationItemSet()->constEnd(); candIt != candItEnd && (count++ <= mConfMaxCandidateInstancePropagationsInitializationIndividualCount || allOnceProp); ++candIt) { |
| 12121 |
CRealizationIndividualInstanceItemReference possibleInstanceItem(*candIt); |
| 12122 |
testingSet.insert(possibleInstanceItem); |
| 12123 |
|
| 12124 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(activationLinkerIt->getActivationConcept(), false, possibleInstanceItem.getIndividualIdentifier(), satCalcJob); |
| 12125 |
} |
| 12126 |
conceptItem->setPossibleInstanceItemSetCandidatePropagationIterator(candIt); |
| 12127 |
} |
| 12128 |
} |
| 12129 |
if (allOnceProp) { |
| 12130 |
conceptItem->setPossibleInstanceItemSetCandidatePropagationIterator(possibleInstanceItemSet->constEnd()); |
| 12131 |
} |
| 12132 |
|
| 12133 |
|
| 12134 |
CAnsweringMessageDataCalculationCompletedInstanceCandidatePropagationItem* completedMessage = new CAnsweringMessageDataCalculationCompletedInstanceCandidatePropagationItem(satCalcJob, conceptItem, testingSet); |
| 12135 |
satCalcJob->setSatisfiableAnswererInstancePropagationMessageAdapter(new CSatisfiableTaskAnswererInstancePropagationMessageAdapter(conceptItem->getConcept(), conceptItem->getConceptNegation(), activationTriggeringData.getTriggeringConcept() == nullptr, this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler())); |
| 12136 |
|
| 12137 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incComplexConceptItemsCandidatePropagationCount(); |
| 12138 |
|
| 12139 |
continueCalculationJobFromNondeterministicCachedGraph(satCalcJob, answererContext); |
| 12140 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 12141 |
|
| 12142 |
} |
| 12143 |
return true; |
| 12144 |
} |
| 12145 |
|
| 12146 |
|
| 12147 |
|
| 12148 |
|
| 12149 |
bool COptimizedComplexExpressionAnsweringHandler::createInvidiualItemInstanceTest(COptimizedComplexConceptItem* conceptItem, const CRealizationIndividualInstanceItemReference& testingItemRef, CAnswererContext* answererContext) { |
| 12150 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 12151 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 12152 |
|
| 12153 |
//if (visitor.testingIndi) { |
| 12154 |
// if (CIRIName::getRecentIRIName(visitor.testingIndi->getIndividualNameLinker()) == "http://www.Department1.University0.edu/UndergraduateStudent79") { |
| 12155 |
// bool debug = true; |
| 12156 |
// } |
| 12157 |
//} |
| 12158 |
//if (visitor.testingIndi) { |
| 12159 |
// for (auto it = visitor.testingIndi->getAssertionRoleLinker(); it; it = it->getNext()) { |
| 12160 |
// CIndividual* othIndi = it->getIndividual(); |
| 12161 |
// if (CIRIName::getRecentIRIName(othIndi->getIndividualNameLinker()) == "http://www.Department0.University0.edu/GraduateCourse0" && CIRIName::getRecentIRIName(it->getRole()->getPropertyNameLinker()) == "http://swat.cse.lehigh.edu/onto/University1-fully.owl#takesCourse") { |
| 12162 |
// bool debug = true; |
| 12163 |
// } |
| 12164 |
// } |
| 12165 |
//} |
| 12166 |
|
| 12167 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incComplexConceptItemsPossibleInstanceVerificationCount(); |
| 12168 |
|
| 12169 |
CConcept* reducedConcept = conceptItem->getCompletelyHandledReducedInstanceTestingConcept(); |
| 12170 |
bool reducedNegation = conceptItem->getCompletelyHandledReducedInstanceTestingConceptNegation(); |
| 12171 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, conceptItem->isTopObjectPropertyUsed(), answererContext); |
| 12172 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(reducedConcept, !reducedNegation, testingItemRef, satCalcJob); |
| 12173 |
|
| 12174 |
CAnsweringMessageDataCalculationCompletedInstanceItem* completedMessage = new CAnsweringMessageDataCalculationCompletedInstanceItem(satCalcJob, conceptItem, testingItemRef); |
| 12175 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 12176 |
return true; |
| 12177 |
} |
| 12178 |
|
| 12179 |
|
| 12180 |
bool COptimizedComplexExpressionAnsweringHandler::createSatisfiabilityTest(COptimizedComplexConceptItem* conceptItem, CAnswererContext* answererContext) { |
| 12181 |
CSatisfiableCalculationJob* satCalcJob = nullptr; |
| 12182 |
CSatisfiableCalculationJobGenerator satCalcJobGen(mOntoAnsweringItem->getTestingOntology()); |
| 12183 |
satCalcJob = extendProcessingByTopPropagation(satCalcJobGen, satCalcJob, conceptItem->isTopObjectPropertyUsed(), answererContext); |
| 12184 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(conceptItem->getConcept(), conceptItem->getConceptNegation(), nullptr, satCalcJob); |
| 12185 |
CAnsweringMessageDataCalculationCompletedSatisfiable* completedMessage = new CAnsweringMessageDataCalculationCompletedSatisfiable(satCalcJob, conceptItem); |
| 12186 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incComplexConceptItemsSatisfiabilityTestingCount(); |
| 12187 |
satCalcJob->setSatisfiableAnswererSubsumptionMessageAdapter(new CSatisfiableTaskAnswererSubsumptionMessageAdapter(conceptItem->getConcept(), conceptItem->getConceptNegation(), this, mOntoAnsweringItem->getTestingOntology(false), answererContext->getAnsweringCalculationHandler())); |
| 12188 |
processCalculationJob(answererContext, satCalcJob, completedMessage); |
| 12189 |
return true; |
| 12190 |
} |
| 12191 |
|
| 12192 |
|
| 12193 |
CSatisfiableCalculationJob* COptimizedComplexExpressionAnsweringHandler::extendProcessingByTopPropagation(CSatisfiableCalculationJobGenerator& satCalcJobGen, CSatisfiableCalculationJob* satCalcJob, bool hasTopObjectPropertyPropagation, CAnswererContext* answererContext) { |
| 12194 |
if (hasTopObjectPropertyPropagation) { |
| 12195 |
CConcept* topRolePropagationExistingIndividualCreationConcept = mOntoAnsweringItem->getTopRolePropagationExistingIndividualCreationConcept(); |
| 12196 |
if (!topRolePropagationExistingIndividualCreationConcept) { |
| 12197 |
CMemoryAllocationManager* memMan = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getBoxContext()->getMemoryAllocationManager(); |
| 12198 |
CTBox* tBox = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getTBox(); |
| 12199 |
CConceptVector* conceptVec = tBox->getConceptVector(); |
| 12200 |
|
| 12201 |
topRolePropagationExistingIndividualCreationConcept = CObjectAllocator<CConcept>::allocateAndConstruct(memMan); |
| 12202 |
|
| 12203 |
CIndividualVector* indiVec = mOntoAnsweringItem->getTestingOntology(false)->getABox()->getIndividualVector(); |
| 12204 |
cint64 univConnIndiID = mOntoAnsweringItem->getTestingOntology(false)->getABox()->getNextIndividualId(true); |
| 12205 |
CIndividual* universalConnIndi = CObjectAllocator< CIndividual >::allocateAndConstruct(memMan); |
| 12206 |
universalConnIndi->initIndividual(univConnIndiID); |
| 12207 |
indiVec->setData(univConnIndiID, universalConnIndi); |
| 12208 |
|
| 12209 |
topRolePropagationExistingIndividualCreationConcept->initConcept(); |
| 12210 |
cint64 nextConTag = tBox->getNextConceptID(); |
| 12211 |
topRolePropagationExistingIndividualCreationConcept->initTag(nextConTag); |
| 12212 |
topRolePropagationExistingIndividualCreationConcept->setOperatorCode(CCVALUE); |
| 12213 |
topRolePropagationExistingIndividualCreationConcept->setRole(mOntoAnsweringItem->getTestingOntology(false)->getRBox()->getTopObjectRole()); |
| 12214 |
topRolePropagationExistingIndividualCreationConcept->incOperandCount(); |
| 12215 |
topRolePropagationExistingIndividualCreationConcept->setNominalIndividual(universalConnIndi); |
| 12216 |
conceptVec->setLocalData(nextConTag, topRolePropagationExistingIndividualCreationConcept); |
| 12217 |
|
| 12218 |
mOntoAnsweringItem->setTopRolePropagationExistingIndividual(universalConnIndi); |
| 12219 |
mOntoAnsweringItem->setTopRolePropagationExistingIndividualCreationConcept(topRolePropagationExistingIndividualCreationConcept); |
| 12220 |
} |
| 12221 |
|
| 12222 |
|
| 12223 |
|
| 12224 |
visitAllIndividuals([&](const CIndividualReference& indiRef)->bool { |
| 12225 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(topRolePropagationExistingIndividualCreationConcept, false, indiRef, satCalcJob); |
| 12226 |
return true; |
| 12227 |
}); |
| 12228 |
|
| 12229 |
satCalcJob = satCalcJobGen.getSatisfiableCalculationJob(topRolePropagationExistingIndividualCreationConcept, false, mOntoAnsweringItem->getTopRolePropagationExistingIndividual(), satCalcJob); |
| 12230 |
|
| 12231 |
} |
| 12232 |
return satCalcJob; |
| 12233 |
} |
| 12234 |
|
| 12235 |
|
| 12236 |
|
| 12237 |
|
| 12238 |
bool COptimizedComplexExpressionAnsweringHandler::processRequirements(CAnswererContext* answererContext, CConcreteOntology* ontology, const QList<COntologyProcessingRequirement*>& reqList, CAnsweringMessageDataRequirementCompleted* completedMessage) { |
| 12239 |
if (!mOntoAnsweringItem->hasRequirementProcessingSchedulingReported()) { |
| 12240 |
LOG(INFO, getDomain(), logTr("Scheduling processing of (realization) requirements."), this); |
| 12241 |
mOntoAnsweringItem->setRequirementProcessingSchedulingReported(true); |
| 12242 |
} |
| 12243 |
if (mConfExtendedLogging) { |
| 12244 |
LOG(INFO, getDomain(), logTr("Scheduling processing of %1 requirements.").arg(reqList.size()), this); |
| 12245 |
} |
| 12246 |
mOntoAnsweringItem->getAnsweringHandlingStatistics()->incRequestedRealizationRequirementCount(reqList.size()); |
| 12247 |
answererContext->getAnsweringCalculationHandler()->ensureRequirements(this, ontology, reqList, completedMessage); |
| 12248 |
return true; |
| 12249 |
} |
| 12250 |
|
| 12251 |
|
| 12252 |
bool COptimizedComplexExpressionAnsweringHandler::processCalculationJob(CAnswererContext* answererContext, CSatisfiableCalculationJob* satCalcJob, CAnsweringMessageDataCalculationCompleted* completedMessage) { |
| 12253 |
satCalcJob->setCalculationConfiguration(mOntoAnsweringItem->getCalculationConfiguration()); |
| 12254 |
|
| 12255 |
CAnsweringCalculationStatisticsCollection* statColl = nullptr; |
| 12256 |
if (mOntoAnsweringItem->isProcessStatisticsCollectionConfigured()) { |
| 12257 |
statColl = mOntoAnsweringItem->getCalculationStatisticsCollection(); |
| 12258 |
completedMessage->setStatisticsCollection(statColl); |
| 12259 |
} |
| 12260 |
satCalcJob->setCalclulationStatisticsCollector(statColl); |
| 12261 |
|
| 12262 |
answererContext->getAnsweringCalculationHandler()->postCalculation(this, satCalcJob, completedMessage, completedMessage); |
| 12263 |
return true; |
| 12264 |
} |
| 12265 |
|
| 12266 |
|
| 12267 |
|
| 12268 |
|
| 12269 |
|
| 12270 |
|
| 12271 |
|
| 12272 |
|
| 12273 |
bool COptimizedComplexExpressionAnsweringHandler::processCalculationMessage(CAnsweringMessageData* message, CAnswererContext* answererContext) { |
| 12274 |
while (message) { |
| 12275 |
CAnsweringMessageData::ANSWERINGMESSAGEDATA messageType = message->getAnsweringMessageDataType(); |
| 12276 |
if (messageType == CAnsweringMessageData::CALCULATIONCOMPLETED) { |
| 12277 |
CAnsweringMessageDataCalculationCompleted* calcCompMessage = (CAnsweringMessageDataCalculationCompleted*)message; |
| 12278 |
|
| 12279 |
bool errorOcurred = false; |
| 12280 |
if (calcCompMessage->hasCalculationError()) { |
| 12281 |
LOG(ERROR, getDomain(), logTr("Error in computation, answer computation for ontology '%1' failed.").arg(mOntoAnsweringItem->getOntology()->getTerminologyName()), this); |
| 12282 |
errorOcurred = true; |
| 12283 |
} |
| 12284 |
|
| 12285 |
CAnsweringMessageDataCalculationCompleted::CALCULATIONTYPE calcType = calcCompMessage->getCalculationType(); |
| 12286 |
if (calcType == CAnsweringMessageDataCalculationCompleted::SATISFIABLECALCULATION) { |
| 12287 |
CAnsweringMessageDataCalculationCompletedSatisfiable* satCalcCompMessage = (CAnsweringMessageDataCalculationCompletedSatisfiable*)calcCompMessage; |
| 12288 |
processSatisfiableCalculationCompleted(satCalcCompMessage, answererContext); |
| 12289 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::SUPERCLASSSUBSUMPTIONCALCULATION) { |
| 12290 |
CAnsweringMessageDataCalculationCompletedSubsumptionSuperClass* subCalcCompMessage = (CAnsweringMessageDataCalculationCompletedSubsumptionSuperClass*)calcCompMessage; |
| 12291 |
processSuperClassSubsumptionCalculationCompleted(subCalcCompMessage, answererContext); |
| 12292 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::SUBCLASSSUBSUMPTIONCALCULATION) { |
| 12293 |
CAnsweringMessageDataCalculationCompletedSubsumptionSubClass* subCalcCompMessage = (CAnsweringMessageDataCalculationCompletedSubsumptionSubClass*)calcCompMessage; |
| 12294 |
processSubClassSubsumptionCalculationCompleted(subCalcCompMessage, answererContext); |
| 12295 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::INDIVIDUALINSTANCECALCULATION) { |
| 12296 |
CAnsweringMessageDataCalculationCompletedInstanceIndividual* instCalcCompMessage = (CAnsweringMessageDataCalculationCompletedInstanceIndividual*)calcCompMessage; |
| 12297 |
processIndividualInstanceCalculationCompleted(instCalcCompMessage, answererContext); |
| 12298 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::INSTANCEENTAILMENTCALCULATION) { |
| 12299 |
CAnsweringMessageDataCalculationCompletedInstanceEntailment* instCalcCompMessage = (CAnsweringMessageDataCalculationCompletedInstanceEntailment*)calcCompMessage; |
| 12300 |
processInstanceEntailmentCalculationCompleted(instCalcCompMessage, answererContext); |
| 12301 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::CLASSSUBSUMPTIONCALCULATION) { |
| 12302 |
CAnsweringMessageDataCalculationCompletedClassSubsumption* subsumCalcCompMessage = (CAnsweringMessageDataCalculationCompletedClassSubsumption*)calcCompMessage; |
| 12303 |
processClassSumsumptionEntailmentCalculationCompleted(subsumCalcCompMessage, answererContext); |
| 12304 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::ITEMINSTANCECALCULATION) { |
| 12305 |
CAnsweringMessageDataCalculationCompletedInstanceItem* instCalcCompMessage = (CAnsweringMessageDataCalculationCompletedInstanceItem*)calcCompMessage; |
| 12306 |
processIndividualItemCalculationCompleted(instCalcCompMessage, answererContext); |
| 12307 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::VARIABLEBINDINGPPROPAGATIONCALCULATION) { |
| 12308 |
CAnsweringMessageDataCalculationCompletedVariableBindingPropagations* varBindPropCompMessage = (CAnsweringMessageDataCalculationCompletedVariableBindingPropagations*)calcCompMessage; |
| 12309 |
processVariableBindingsPropagationItemCalculationCompleted(varBindPropCompMessage, errorOcurred, answererContext); |
| 12310 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::VARIABLEBINDINGCONFIRMATIONCALCULATION) { |
| 12311 |
CAnsweringMessageDataCalculationCompletedVariableBindingConfirmation* varBindConfCompMessage = (CAnsweringMessageDataCalculationCompletedVariableBindingConfirmation*)calcCompMessage; |
| 12312 |
processVariableBindingsConfirmationCalculationCompleted(varBindConfCompMessage, answererContext); |
| 12313 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::VARIABLEBINDINGENTAILMENTCALCULATION) { |
| 12314 |
CAnsweringMessageDataCalculationCompletedVariableBindingEntailment* varBindEntCompMessage = (CAnsweringMessageDataCalculationCompletedVariableBindingEntailment*)calcCompMessage; |
| 12315 |
processVariableBindingsEntailmentCalculationCompleted(varBindEntCompMessage, answererContext); |
| 12316 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::ITEMINSTANCECANDIDATEPROPAGATIONCALCULATION) { |
| 12317 |
CAnsweringMessageDataCalculationCompletedInstanceCandidatePropagationItem* instCandPropMessage = (CAnsweringMessageDataCalculationCompletedInstanceCandidatePropagationItem*)calcCompMessage; |
| 12318 |
processIndividualCandidatePropagationCalculationCompleted(instCandPropMessage, answererContext); |
| 12319 |
} else if (calcType == CAnsweringMessageDataCalculationCompleted::QUERYMATERIALIZATIONCALCULATION) { |
| 12320 |
CAnsweringMessageDataCalculationCompletedQueryMaterialization* matConCompMessage = (CAnsweringMessageDataCalculationCompletedQueryMaterialization*)calcCompMessage; |
| 12321 |
processQueryMaterializationCalculationCompleted(matConCompMessage, answererContext); |
| 12322 |
} |
| 12323 |
|
| 12324 |
CAnsweringCalculationStatisticsCollection* statColl = calcCompMessage->getStatisticsCollection(); |
| 12325 |
if (statColl) { |
| 12326 |
mOntoAnsweringItem->reuseCalculationStatisticsCollection(statColl); |
| 12327 |
} |
| 12328 |
|
| 12329 |
} else if (messageType == CAnsweringMessageData::CALCULATIONADAPTER) { |
| 12330 |
CAnsweringMessageDataCalculationAdapter* calcAdapMessage = (CAnsweringMessageDataCalculationAdapter*)message; |
| 12331 |
CAnsweringMessageDataCalculationAdapter::CALCULATIONADAPTERTYPE calcType = calcAdapMessage->getCalculationAdapterType(); |
| 12332 |
if (calcType == CAnsweringMessageDataCalculationAdapter::CLASSSUBSUMERS) { |
| 12333 |
CAnsweringMessageDataCalculationClassSubsumers* classSubsumersMessage = (CAnsweringMessageDataCalculationClassSubsumers*)calcAdapMessage; |
| 12334 |
processExtractedClassSubsumers(classSubsumersMessage, answererContext); |
| 12335 |
} else if (calcType == CAnsweringMessageDataCalculationAdapter::POSSIBLECLASSSUBSUMERS) { |
| 12336 |
CAnsweringMessageDataCalculationPossibleClassSubsumers* possibleClassSubsumersMessage = (CAnsweringMessageDataCalculationPossibleClassSubsumers*)calcAdapMessage; |
| 12337 |
processExtractedPossibleClassSubsumers(possibleClassSubsumersMessage, answererContext); |
| 12338 |
} else if (calcType == CAnsweringMessageDataCalculationAdapter::PROPAGATION_BINDINGS) { |
| 12339 |
CAnsweringMessageDataVariableBindingPropagations* variableBindingsPropagationMessage = (CAnsweringMessageDataVariableBindingPropagations*)calcAdapMessage; |
| 12340 |
processExtractedVariableBindingPropagations(variableBindingsPropagationMessage, answererContext); |
| 12341 |
} else if (calcType == CAnsweringMessageDataCalculationAdapter::INSTANCE_CERTAIN_PROPAGATIONS) { |
| 12342 |
CAnsweringMessageDataInstanceCertainPropagationsData* instanceCandidatePropagationMessage = (CAnsweringMessageDataInstanceCertainPropagationsData*)calcAdapMessage; |
| 12343 |
processExtractedInstanceCertainPropagations(instanceCandidatePropagationMessage, answererContext); |
| 12344 |
} else if (calcType == CAnsweringMessageDataCalculationAdapter::INSTANCE_POSSIBLE_PROPAGATIONS) { |
| 12345 |
CAnsweringMessageDataInstancePossiblePropagationsData* instanceCandidatePossiblePropagationMessage = (CAnsweringMessageDataInstancePossiblePropagationsData*)calcAdapMessage; |
| 12346 |
processExtractedInstanceCandidatePossiblePropagations(instanceCandidatePossiblePropagationMessage, answererContext); |
| 12347 |
} else if (calcType == CAnsweringMessageDataCalculationAdapter::MATERIALIZED_CONCEPTS) { |
| 12348 |
CAnsweringMessageDataCalculationMaterializedConcepts* matConceptsMessage = (CAnsweringMessageDataCalculationMaterializedConcepts*)calcAdapMessage; |
| 12349 |
processExtractedMaterializationConcept(matConceptsMessage, answererContext); |
| 12350 |
} |
| 12351 |
} |
| 12352 |
message = message->getNext(); |
| 12353 |
} |
| 12354 |
return false; |
| 12355 |
} |
| 12356 |
|
| 12357 |
|
| 12358 |
|
| 12359 |
bool COptimizedComplexExpressionAnsweringHandler::processRequirementMessage(CAnsweringMessageData* message, CAnswererContext* answererContext) { |
| 12360 |
while (message) { |
| 12361 |
CAnsweringMessageData::ANSWERINGMESSAGEDATA messageType = message->getAnsweringMessageDataType(); |
| 12362 |
if (messageType == CAnsweringMessageData::REQUIREMENTCOMPLETED) { |
| 12363 |
if (mConfExtendedLogging) { |
| 12364 |
LOG(INFO, getDomain(), logTr("Finished processing requirements, continuing query answering."), this); |
| 12365 |
} |
| 12366 |
|
| 12367 |
CAnsweringMessageDataRequirementCompleted* reqCompMessage = (CAnsweringMessageDataRequirementCompleted*)message; |
| 12368 |
CAnsweringMessageDataRequirementCompleted::REQUIREMENTTYPE reqType = reqCompMessage->getRequirementType(); |
| 12369 |
if (reqType == CAnsweringMessageDataRequirementCompleted::REALIZATIONREQUIREMENT) { |
| 12370 |
CAnsweringMessageDataRequirementCompletedRealization* compRealReqMess = (CAnsweringMessageDataRequirementCompletedRealization*)reqCompMessage; |
| 12371 |
COptimizedComplexConceptItem* conItem = compRealReqMess->getConceptItem(); |
| 12372 |
if (conItem) { |
| 12373 |
conItem->decLazyRealizationProcessingCount(); |
| 12374 |
if (conItem->getLazyRealizationProcessingCount() <= 0) { |
| 12375 |
CComplexConceptStepComputationProcess* compStep = conItem->getComputationProcess()->getInstancesComputationProcess(false); |
| 12376 |
conItem->setQueuedProcessStep(compStep); |
| 12377 |
compStep->setComputationProcessQueued(true); |
| 12378 |
COptimizedComplexConceptStepAnsweringItem* processingStep = mOntoAnsweringItem->getConceptProcessingStepItem(compStep->getComputationType()); |
| 12379 |
processingStep->addQueuedConceptItem(conItem); |
| 12380 |
} |
| 12381 |
} |
| 12382 |
COptimizedComplexVariableCompositionItem* variableCompositionItem = compRealReqMess->getVariableCompositionItem(); |
| 12383 |
COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem = compRealReqMess->getBuildingVariableCompositionItem(); |
| 12384 |
if (buildingVarItem && variableCompositionItem) { |
| 12385 |
buildingVarItem->decVariableCompositionItemWaitingCount(); |
| 12386 |
buildingVarItem->addComputeVariableMappingItem(variableCompositionItem); |
| 12387 |
if (buildingVarItem->getVariableCompositionItemWaitingCount() <= 0) { |
| 12388 |
buildingVarItem->setProcessingQueued(true); |
| 12389 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(buildingVarItem); |
| 12390 |
} |
| 12391 |
} |
| 12392 |
} else if (reqType == CAnsweringMessageDataRequirementCompleted::SUBCLASSREALIZATIONREQUIREMENT) { |
| 12393 |
CAnsweringMessageDataRequirementCompletedSubClassRealization* subClassRealReqMess = (CAnsweringMessageDataRequirementCompletedSubClassRealization*)reqCompMessage; |
| 12394 |
COptimizedComplexConceptItem* conItem = subClassRealReqMess->getConceptItem(); |
| 12395 |
CComplexConceptStepComputationProcess* compStep = conItem->getComputationProcess()->getSubClassRealizationProcess(false); |
| 12396 |
finishCalculationStepProcessing(conItem, compStep, answererContext); |
| 12397 |
|
| 12398 |
} else if (reqType == CAnsweringMessageDataRequirementCompleted::CONCEPTASSERTIONENTAILMENTREQUIREMENT) { |
| 12399 |
CAnsweringMessageDataRequirementCompletedConceptAssertionEntailment* entReqMes = (CAnsweringMessageDataRequirementCompletedConceptAssertionEntailment*)reqCompMessage; |
| 12400 |
CEntailmentQueryProcessingData* procData = entReqMes->getEntailmentProcessingData(); |
| 12401 |
procData->mHasResult = true; |
| 12402 |
CConcept* concept = entReqMes->getConcept(); |
| 12403 |
CIndividual* individual = entReqMes->getIndividual(); |
| 12404 |
CConceptRealization* conReal = mOntoAnsweringItem->getOntology()->getRealization()->getConceptRealization(); |
| 12405 |
procData->mEntailed = conReal->isConceptInstance(individual,concept); |
| 12406 |
for (CXLinker<CComplexQueryExpressionProcessingData*>* procDataLinkerIt = procData->mProcDataLinker; procDataLinkerIt; procDataLinkerIt = procDataLinkerIt->getNext()) { |
| 12407 |
CComplexQueryExpressionProcessingData* queryProcData = procDataLinkerIt->getData(); |
| 12408 |
queryProcData->decEntailmentComputation(); |
| 12409 |
if (!queryProcData->hasComputation()) { |
| 12410 |
finishQueryProcessing(queryProcData); |
| 12411 |
} |
| 12412 |
} |
| 12413 |
mOntoAnsweringItem->releaseQueryProcessingLinker(procData->mProcDataLinker); |
| 12414 |
procData->mProcDataLinker = nullptr; |
| 12415 |
|
| 12416 |
} else if (reqType == CAnsweringMessageDataRequirementCompleted::ROLEASSERTIONENTAILMENTREQUIREMENT) { |
| 12417 |
CAnsweringMessageDataRequirementCompletedRoleAssertionEntailment* entReqMes = (CAnsweringMessageDataRequirementCompletedRoleAssertionEntailment*)reqCompMessage; |
| 12418 |
CEntailmentQueryProcessingData* procData = entReqMes->getEntailmentProcessingData(); |
| 12419 |
procData->mHasResult = true; |
| 12420 |
CRole* role = entReqMes->getRole(); |
| 12421 |
CIndividual* individualSource = entReqMes->getIndividualSource(); |
| 12422 |
CIndividual* individualDest = entReqMes->getIndividualDestination(); |
| 12423 |
CRoleRealization* roleReal = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 12424 |
procData->mEntailed = roleReal->isRoleInstance(role,individualSource,individualDest); |
| 12425 |
for (CXLinker<CComplexQueryExpressionProcessingData*>* procDataLinkerIt = procData->mProcDataLinker; procDataLinkerIt; procDataLinkerIt = procDataLinkerIt->getNext()) { |
| 12426 |
CComplexQueryExpressionProcessingData* queryProcData = procDataLinkerIt->getData(); |
| 12427 |
queryProcData->decEntailmentComputation(); |
| 12428 |
if (!queryProcData->hasComputation()) { |
| 12429 |
finishQueryProcessing(queryProcData); |
| 12430 |
} |
| 12431 |
} |
| 12432 |
mOntoAnsweringItem->releaseQueryProcessingLinker(procData->mProcDataLinker); |
| 12433 |
procData->mProcDataLinker = nullptr; |
| 12434 |
|
| 12435 |
} else if (reqType == CAnsweringMessageDataRequirementCompletedRoleTargetsRealization::ROLETARGETSREALIZATIONREQUIREMENT) { |
| 12436 |
CAnsweringMessageDataRequirementCompletedRoleTargetsRealization* roleTarRealMes = (CAnsweringMessageDataRequirementCompletedRoleTargetsRealization*)reqCompMessage; |
| 12437 |
CRole* role = roleTarRealMes->getRole(); |
| 12438 |
bool inversed = roleTarRealMes->getInversed(); |
| 12439 |
QList<CIndividualReference>* individualSourceList = roleTarRealMes->getIndividualSourceList(); |
| 12440 |
|
| 12441 |
for (CIndividualReference individualSource : *individualSourceList) { |
| 12442 |
|
| 12443 |
CRoleTargetsRealizationHasher enHasher(role, individualSource, inversed); |
| 12444 |
CEntailmentVariableBuildingItemData* varBuildData = mRoleTargetsProcDataHash[enHasher]; |
| 12445 |
|
| 12446 |
for (CXLinker<COptimizedComplexBuildingIndividualVariableCompositionsItem*>* procDataLinkerIt = varBuildData->mProcDataLinker; procDataLinkerIt; procDataLinkerIt = procDataLinkerIt->getNext()) { |
| 12447 |
COptimizedComplexBuildingIndividualVariableCompositionsItem* varBuildItem = procDataLinkerIt->getData(); |
| 12448 |
varBuildItem->decWaitingRoleTargetsRealizationCount(); |
| 12449 |
if (!varBuildItem->isWaitingRoleTargetsRealization()) { |
| 12450 |
varBuildItem->setProcessingQueued(true); |
| 12451 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(varBuildItem); |
| 12452 |
} |
| 12453 |
} |
| 12454 |
mOntoAnsweringItem->releaseBuildingVariableItemProcessingLinker(varBuildData->mProcDataLinker); |
| 12455 |
varBuildData->mProcDataLinker = nullptr; |
| 12456 |
} |
| 12457 |
|
| 12458 |
} |
| 12459 |
} |
| 12460 |
message = message->getNext(); |
| 12461 |
} |
| 12462 |
return false; |
| 12463 |
} |
| 12464 |
|
| 12465 |
|
| 12466 |
|
| 12467 |
|
| 12468 |
|
| 12469 |
|
| 12470 |
QSet<CHierarchyNode*>* COptimizedComplexExpressionAnsweringHandler::getDirectReducedSuperNodeSet(const QSet<CHierarchyNode*>& superClassesSet) { |
| 12471 |
QSet<CHierarchyNode*>* directSuperClassesSet = new QSet<CHierarchyNode*>(); |
| 12472 |
QList<CHierarchyNode*> predCountSortedSuperClassNodeList; |
| 12473 |
for (QSet<CHierarchyNode*>::const_iterator it = superClassesSet.constBegin(), itEnd = superClassesSet.constEnd(); it != itEnd; ++it) { |
| 12474 |
CHierarchyNode* superClassNode(*it); |
| 12475 |
if (superClassNode) { |
| 12476 |
predCountSortedSuperClassNodeList.append(superClassNode); |
| 12477 |
} |
| 12478 |
} |
| 12479 |
qSort(predCountSortedSuperClassNodeList.begin(), predCountSortedSuperClassNodeList.end(), nodeSortMorePredecessorsThan); |
| 12480 |
for (QList<CHierarchyNode*>::const_iterator it = predCountSortedSuperClassNodeList.constBegin(), itEnd = predCountSortedSuperClassNodeList.constEnd(); it != itEnd; ++it) { |
| 12481 |
CHierarchyNode* superClassNode(*it); |
| 12482 |
bool alreadyContained = false; |
| 12483 |
for (QSet<CHierarchyNode*>::const_iterator itDirect = directSuperClassesSet->constBegin(), itDirectEnd = directSuperClassesSet->constEnd(); !alreadyContained && itDirect != itDirectEnd; ++itDirect) { |
| 12484 |
CHierarchyNode* directSuperNode(*itDirect); |
| 12485 |
if (directSuperNode->hasPredecessorNode(superClassNode)) { |
| 12486 |
alreadyContained = true; |
| 12487 |
} |
| 12488 |
} |
| 12489 |
if (!alreadyContained) { |
| 12490 |
directSuperClassesSet->insert(superClassNode); |
| 12491 |
if (directSuperClassesSet->count() == 1 && superClassNode->getPredecessorNodeCount()+1 == predCountSortedSuperClassNodeList.count()) { |
| 12492 |
break; |
| 12493 |
} |
| 12494 |
} |
| 12495 |
} |
| 12496 |
return directSuperClassesSet; |
| 12497 |
} |
| 12498 |
|
| 12499 |
|
| 12500 |
|
| 12501 |
|
| 12502 |
|
| 12503 |
bool COptimizedComplexExpressionAnsweringHandler::processExtractedClassSubsumers(CAnsweringMessageDataCalculationClassSubsumers* message, CAnswererContext* answererContext) { |
| 12504 |
CConcept* concept = message->getSubsumedConcept(); |
| 12505 |
bool negation = message->getSubsumedConceptNegation(); |
| 12506 |
COptimizedComplexConceptItem* conceptItem = mOntoAnsweringItem->getComplexConceptItem(concept,negation); |
| 12507 |
CClassConceptClassification* classClassification = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification(); |
| 12508 |
CCLASSSUBSUMPTIONMESSAGELIST<CConcept*>* superClassesList = message->getClassSubsumerList(); |
| 12509 |
if (classClassification) { |
| 12510 |
QSet<CHierarchyNode*>* superClassesSet = new QSet<CHierarchyNode*>(); |
| 12511 |
CTaxonomy* taxonomy = classClassification->getClassConceptTaxonomy(); |
| 12512 |
for (CCLASSSUBSUMPTIONMESSAGELIST<CConcept*>::const_iterator it = superClassesList->constBegin(), itEnd = superClassesList->constEnd(); it != itEnd; ++it) { |
| 12513 |
CConcept* superClass(*it); |
| 12514 |
CHierarchyNode* hierNode = taxonomy->getHierarchyNode(superClass, false); |
| 12515 |
if (hierNode) { |
| 12516 |
superClassesSet->insert(hierNode); |
| 12517 |
} |
| 12518 |
} |
| 12519 |
conceptItem->setKnownSuperClassNodeSet(superClassesSet); |
| 12520 |
} else { |
| 12521 |
QSet<CConcept*>* knownSuperConceptSet = new QSet<CConcept*>(); |
| 12522 |
for (CCLASSSUBSUMPTIONMESSAGELIST<CConcept*>::const_iterator it = superClassesList->constBegin(), itEnd = superClassesList->constEnd(); it != itEnd; ++it) { |
| 12523 |
CConcept* superClass(*it); |
| 12524 |
knownSuperConceptSet->insert(superClass); |
| 12525 |
} |
| 12526 |
conceptItem->setKnownSuperConceptSet(knownSuperConceptSet); |
| 12527 |
} |
| 12528 |
return true; |
| 12529 |
} |
| 12530 |
|
| 12531 |
|
| 12532 |
|
| 12533 |
|
| 12534 |
bool COptimizedComplexExpressionAnsweringHandler::processExtractedPossibleClassSubsumers(CAnsweringMessageDataCalculationPossibleClassSubsumers* message, CAnswererContext* answererContext) { |
| 12535 |
CConcept* concept = message->getSubsumedConcept(); |
| 12536 |
bool negation = message->getSubsumedConceptNegation(); |
| 12537 |
COptimizedComplexConceptItem* conceptItem = mOntoAnsweringItem->getComplexConceptItem(concept, negation); |
| 12538 |
CClassConceptClassification* classClassification = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification(); |
| 12539 |
if (classClassification) { |
| 12540 |
QSet<CHierarchyNode*>* possSuperClassesSet = new QSet<CHierarchyNode*>(); |
| 12541 |
QSet<CHierarchyNode*>* knownSuperClassesSet = conceptItem->getKnownSuperClassNodeSet(); |
| 12542 |
QSet<CConcept*>* knowSuperConceptSet = conceptItem->getKnownSuperConceptSet(); |
| 12543 |
CTaxonomy* taxonomy = classClassification->getClassConceptTaxonomy(); |
| 12544 |
CCLASSSUBSUMPTIONMESSAGELIST<CAnsweringMessageDataCalculationPossibleClassSubsumersData*>* possSuperClassesList = message->getPossibleClassSubsumerList(); |
| 12545 |
for (CCLASSSUBSUMPTIONMESSAGELIST<CAnsweringMessageDataCalculationPossibleClassSubsumersData*>::const_iterator it = possSuperClassesList->constBegin(), itEnd = possSuperClassesList->constEnd(); it != itEnd; ++it) { |
| 12546 |
CAnsweringMessageDataCalculationPossibleClassSubsumersData* possSuperClassData(*it); |
| 12547 |
if (possSuperClassData->isPossibleSubsumerValid()) { |
| 12548 |
CConcept* possSuperClass = possSuperClassData->getPossibleSubsumerConcept(); |
| 12549 |
CHierarchyNode* hierNode = taxonomy->getHierarchyNode(possSuperClass, false); |
| 12550 |
if (hierNode) { |
| 12551 |
if (knownSuperClassesSet && !knownSuperClassesSet->contains(hierNode) || knowSuperConceptSet && !knowSuperConceptSet->contains(possSuperClass)) { |
| 12552 |
possSuperClassesSet->insert(hierNode); |
| 12553 |
} |
| 12554 |
} |
| 12555 |
} |
| 12556 |
} |
| 12557 |
conceptItem->setPossibleSuperClassNodeSet(possSuperClassesSet); |
| 12558 |
} else { |
| 12559 |
QSet<CConcept*>* knowSuperConceptSet = conceptItem->getKnownSuperConceptSet(); |
| 12560 |
QSet<CConcept*>* possibleSuperConceptSet = new QSet<CConcept*>(); |
| 12561 |
CCLASSSUBSUMPTIONMESSAGELIST<CAnsweringMessageDataCalculationPossibleClassSubsumersData*>* possSuperClassesList = message->getPossibleClassSubsumerList(); |
| 12562 |
for (CCLASSSUBSUMPTIONMESSAGELIST<CAnsweringMessageDataCalculationPossibleClassSubsumersData*>::const_iterator it = possSuperClassesList->constBegin(), itEnd = possSuperClassesList->constEnd(); it != itEnd; ++it) { |
| 12563 |
CAnsweringMessageDataCalculationPossibleClassSubsumersData* possSuperClassData(*it); |
| 12564 |
if (possSuperClassData->isPossibleSubsumerValid()) { |
| 12565 |
CConcept* possSuperClass = possSuperClassData->getPossibleSubsumerConcept(); |
| 12566 |
if (knowSuperConceptSet && !knowSuperConceptSet->contains(possSuperClass)) { |
| 12567 |
possibleSuperConceptSet->insert(possSuperClass); |
| 12568 |
} |
| 12569 |
} |
| 12570 |
} |
| 12571 |
conceptItem->setPossibleSuperConceptSet(possibleSuperConceptSet); |
| 12572 |
} |
| 12573 |
return true; |
| 12574 |
} |
| 12575 |
|
| 12576 |
|
| 12577 |
|
| 12578 |
bool COptimizedComplexExpressionAnsweringHandler::processSatisfiableCalculationCompleted(CAnsweringMessageDataCalculationCompletedSatisfiable* message, CAnswererContext* answererContext) { |
| 12579 |
COptimizedComplexConceptItem* conceptItem = message->getConceptItem(); |
| 12580 |
if (conceptItem->isSuperClassComputationInitializing()) { |
| 12581 |
conceptItem->setSuperClassComputationInitializing(false); |
| 12582 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getSuperClassNodesComputationProcess(true); |
| 12583 |
compStep->setComputationProcessProcessing(false); |
| 12584 |
compStep->decCurrentlyRunningComputationCount(); |
| 12585 |
COptimizedComplexConceptStepAnsweringItem* processingStep = mOntoAnsweringItem->getConceptProcessingStepItem(compStep->getComputationType()); |
| 12586 |
processingStep->addQueuedConceptItem(conceptItem); |
| 12587 |
} else { |
| 12588 |
bool satisfiable = message->getCalculationCallbackContextData()->isSatisfiable(); |
| 12589 |
conceptItem->setSatisfiability(satisfiable); |
| 12590 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getSatisfiableClassNodesComputationProcess(true); |
| 12591 |
compStep->setComputationProcessProcessing(false); |
| 12592 |
compStep->decCurrentlyRunningComputationCount(); |
| 12593 |
compStep->incFinishedComputationCount(); |
| 12594 |
finishCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 12595 |
} |
| 12596 |
return true; |
| 12597 |
} |
| 12598 |
|
| 12599 |
|
| 12600 |
bool COptimizedComplexExpressionAnsweringHandler::processSuperClassSubsumptionCalculationCompleted(CAnsweringMessageDataCalculationCompletedSubsumptionSuperClass* message, CAnswererContext* answererContext) { |
| 12601 |
COptimizedComplexConceptItem* conceptItem = message->getConceptItem(); |
| 12602 |
bool satisfiable = message->getCalculationCallbackContextData()->isSatisfiable(); |
| 12603 |
CHierarchyNode* superClassNode = message->getSuperClassNode(); |
| 12604 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getSuperClassNodesComputationProcess(true); |
| 12605 |
if (!satisfiable) { |
| 12606 |
conceptItem->getKnownSuperClassNodeSet()->insert(superClassNode); |
| 12607 |
} |
| 12608 |
compStep->decCurrentlyRunningComputationCount(); |
| 12609 |
compStep->incFinishedComputationCount(); |
| 12610 |
if (compStep->getCurrentlyRunningComputationCount() == 0) { |
| 12611 |
compStep->setComputationProcessProcessing(false); |
| 12612 |
if (!conceptItem->getPossibleSuperClassNodeTestingList() || conceptItem->getPossibleSuperClassNodeTestingList()->isEmpty()) { |
| 12613 |
delete conceptItem->getPossibleSuperClassNodeTestingList(); |
| 12614 |
conceptItem->setPossibleSuperClassNodeTestingList(nullptr); |
| 12615 |
QSet<CHierarchyNode*>* knownSuperClassSet = conceptItem->getKnownSuperClassNodeSet(); |
| 12616 |
if (knownSuperClassSet) { |
| 12617 |
QSet<CHierarchyNode*>* directSuperClassSet = getDirectReducedSuperNodeSet(*knownSuperClassSet); |
| 12618 |
conceptItem->setKnownSuperClassNodeSet(nullptr); |
| 12619 |
delete knownSuperClassSet; |
| 12620 |
conceptItem->setDirectSuperClassNodeSet(directSuperClassSet); |
| 12621 |
} |
| 12622 |
finishCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 12623 |
} |
| 12624 |
} |
| 12625 |
return true; |
| 12626 |
} |
| 12627 |
|
| 12628 |
|
| 12629 |
bool COptimizedComplexExpressionAnsweringHandler::processSubClassSubsumptionCalculationCompleted(CAnsweringMessageDataCalculationCompletedSubsumptionSubClass* message, CAnswererContext* answererContext) { |
| 12630 |
COptimizedComplexConceptItem* conceptItem = message->getConceptItem(); |
| 12631 |
bool satisfiable = message->getCalculationCallbackContextData()->isSatisfiable(); |
| 12632 |
CHierarchyNode* subClassNode = message->getSubClassNode(); |
| 12633 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getSubClassNodesComputationProcess(true); |
| 12634 |
if (!satisfiable) { |
| 12635 |
conceptItem->getDirectSubClassNodeSet()->insert(subClassNode); |
| 12636 |
} else { |
| 12637 |
for (QSet<CHierarchyNode*>::const_iterator it = subClassNode->getChildNodeSet()->constBegin(), itEnd = subClassNode->getChildNodeSet()->constEnd(); it != itEnd; ++it) { |
| 12638 |
CHierarchyNode* childNode(*it); |
| 12639 |
if (!conceptItem->getPossibleSubClassTestingNodeSet()->contains(childNode)) { |
| 12640 |
conceptItem->getPossibleSubClassTestingNodeSet()->insert(childNode); |
| 12641 |
conceptItem->getPossibleSubClassNodeTestingList()->append(childNode); |
| 12642 |
if (conceptItem->getPossibleSubClassNodeTestingList()->size() == 1) { |
| 12643 |
if (!compStep->isComputationProcessQueued()) { |
| 12644 |
compStep->setComputationProcessQueued(true); |
| 12645 |
COptimizedComplexConceptStepAnsweringItem* processingStep = mOntoAnsweringItem->getConceptProcessingStepItem(compStep->getComputationType()); |
| 12646 |
processingStep->addQueuedConceptItem(conceptItem); |
| 12647 |
} |
| 12648 |
} |
| 12649 |
} |
| 12650 |
} |
| 12651 |
} |
| 12652 |
compStep->incFinishedComputationCount(); |
| 12653 |
compStep->decCurrentlyRunningComputationCount(); |
| 12654 |
if (compStep->getCurrentlyRunningComputationCount() == 0) { |
| 12655 |
compStep->setComputationProcessProcessing(false); |
| 12656 |
if (!conceptItem->getPossibleSubClassNodeTestingList() || conceptItem->getPossibleSubClassNodeTestingList()->isEmpty()) { |
| 12657 |
finishSubClassCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 12658 |
} |
| 12659 |
} |
| 12660 |
return true; |
| 12661 |
} |
| 12662 |
|
| 12663 |
|
| 12664 |
|
| 12665 |
|
| 12666 |
|
| 12667 |
|
| 12668 |
bool COptimizedComplexExpressionAnsweringHandler::processIndividualCandidatePropagationCalculationCompleted(CAnsweringMessageDataCalculationCompletedInstanceCandidatePropagationItem* message, CAnswererContext* answererContext) { |
| 12669 |
COptimizedComplexConceptItem* conceptItem = message->getConceptItem(); |
| 12670 |
conceptItem->decCandidatePropagationProcessingCount(); |
| 12671 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getInstancesComputationProcess(true); |
| 12672 |
|
| 12673 |
|
| 12674 |
QSet<CRealizationIndividualInstanceItemReference>* testingSet = message->getTestingSet(); |
| 12675 |
|
| 12676 |
compStep->decCurrentlyRunningComputationCount(); |
| 12677 |
compStep->incFinishedComputationCount(); |
| 12678 |
if (compStep->getCurrentlyRunningComputationCount() == 0) { |
| 12679 |
compStep->setComputationProcessProcessing(false); |
| 12680 |
} |
| 12681 |
|
| 12682 |
|
| 12683 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceCandPropItemSet = conceptItem->getPossibleInstanceCandidatePropagationItemSet(); |
| 12684 |
QSet<CRealizationIndividualInstanceItemReference>* possibleInstanceItemSet = conceptItem->getPossibleInstanceItemSet(); |
| 12685 |
if (conceptItem->getCandidatePropagationProcessingCount() <= 0 && conceptItem->isCandidatePropagated()) { |
| 12686 |
cint64 testedCount = possibleInstanceCandPropItemSet->size() - possibleInstanceItemSet->size(); |
| 12687 |
cint64 knownInstancesCount = conceptItem->getKnownInstanceItems()->size(); |
| 12688 |
cint64 newKnownInstancesCount = knownInstancesCount - conceptItem->getPossibleInstanceCandidatePropagationBeginningKnownInstancesCount(); |
| 12689 |
conceptItem->incPossibleTestedNonInstanceCount(possibleInstanceCandPropItemSet->size() - possibleInstanceItemSet->size() - newKnownInstancesCount); |
| 12690 |
mTestedPossibleInstancesCount += testedCount; |
| 12691 |
delete possibleInstanceCandPropItemSet; |
| 12692 |
conceptItem->setPossibleInstanceCandidatePropagationItemSet(nullptr); |
| 12693 |
if (possibleInstanceItemSet->isEmpty()) { |
| 12694 |
delete possibleInstanceItemSet; |
| 12695 |
conceptItem->setPossibleInstanceItemSet(nullptr); |
| 12696 |
} |
| 12697 |
COptimizedComplexConceptStepAnsweringItem* processingStep = mOntoAnsweringItem->getConceptProcessingStepItem(compStep->getComputationType()); |
| 12698 |
processingStep->addQueuedConceptItem(conceptItem); |
| 12699 |
|
| 12700 |
} |
| 12701 |
|
| 12702 |
return true; |
| 12703 |
} |
| 12704 |
|
| 12705 |
|
| 12706 |
|
| 12707 |
bool COptimizedComplexExpressionAnsweringHandler::processIndividualItemCalculationCompleted(CAnsweringMessageDataCalculationCompletedInstanceItem* message, CAnswererContext* answererContext) { |
| 12708 |
COptimizedComplexConceptItem* conceptItem = message->getConceptItem(); |
| 12709 |
bool satisfiable = message->getCalculationCallbackContextData()->isSatisfiable(); |
| 12710 |
CRealizationIndividualInstanceItemReference testingItemRef = message->getInstanceItemReference(); |
| 12711 |
CComplexConceptStepComputationProcess* compStep = conceptItem->getComputationProcess()->getInstancesComputationProcess(true); |
| 12712 |
if (!satisfiable) { |
| 12713 |
conceptItem->getKnownInstanceItems()->addRealizationIndividualInstanceItemReference(testingItemRef); |
| 12714 |
} else { |
| 12715 |
conceptItem->incPossibleTestedNonInstanceCount(1); |
| 12716 |
} |
| 12717 |
compStep->decCurrentlyRunningComputationCount(); |
| 12718 |
compStep->incFinishedComputationCount(); |
| 12719 |
mTestedPossibleInstancesCount++; |
| 12720 |
if (compStep->getCurrentlyRunningComputationCount() == 0) { |
| 12721 |
compStep->setComputationProcessProcessing(false); |
| 12722 |
} |
| 12723 |
|
| 12724 |
COptimizedComplexConceptStepAnsweringItem* processingStep = mOntoAnsweringItem->getConceptProcessingStepItem(compStep->getComputationType()); |
| 12725 |
processingStep->addQueuedConceptItem(conceptItem); |
| 12726 |
return true; |
| 12727 |
} |
| 12728 |
|
| 12729 |
|
| 12730 |
|
| 12731 |
|
| 12732 |
bool COptimizedComplexExpressionAnsweringHandler::processIndividualInstanceCalculationCompleted(CAnsweringMessageDataCalculationCompletedInstanceIndividual* message, CAnswererContext* answererContext) { |
| 12733 |
bool satisfiable = message->getCalculationCallbackContextData()->isSatisfiable(); |
| 12734 |
CIndividualReference testingIndiRef = message->getIndividualReference(); |
| 12735 |
COptimizedComplexConceptItem* conceptItem = message->getConceptItem(); |
| 12736 |
if (conceptItem) { |
| 12737 |
CComplexConceptStepInstanceComputationProcess* compStep = conceptItem->getComputationProcess()->getInstancesComputationProcess(true); |
| 12738 |
if (!satisfiable) { |
| 12739 |
conceptItem->getKnownInstanceIndividualSet()->insert(testingIndiRef); |
| 12740 |
} else { |
| 12741 |
conceptItem->incPossibleTestedNonInstanceCount(); |
| 12742 |
} |
| 12743 |
compStep->decCurrentlyRunningComputationCount(); |
| 12744 |
compStep->incFinishedComputationCount(); |
| 12745 |
if (compStep->getCurrentlyRunningComputationCount() == 0) { |
| 12746 |
compStep->setComputationProcessProcessing(false); |
| 12747 |
|
| 12748 |
if (!conceptItem->getPossibleInstanceIndividualSet() || conceptItem->getPossibleInstanceIndividualSet()->isEmpty()) { |
| 12749 |
updateComputedInstancesCount(conceptItem, compStep, answererContext); |
| 12750 |
|
| 12751 |
if (conceptItem->isLazyRealizationInstancesRetrieved()) { |
| 12752 |
delete conceptItem->getPossibleInstanceIndividualSet(); |
| 12753 |
finishCalculationStepProcessing(conceptItem, compStep, answererContext); |
| 12754 |
} |
| 12755 |
} |
| 12756 |
} |
| 12757 |
} |
| 12758 |
return true; |
| 12759 |
} |
| 12760 |
|
| 12761 |
|
| 12762 |
|
| 12763 |
bool COptimizedComplexExpressionAnsweringHandler::processInstanceEntailmentCalculationCompleted(CAnsweringMessageDataCalculationCompletedInstanceEntailment* message, CAnswererContext* answererContext) { |
| 12764 |
bool satisfiable = message->getCalculationCallbackContextData()->isSatisfiable(); |
| 12765 |
CIndividualReference testingIndiRef = message->getIndividualReference(); |
| 12766 |
CConcept* concept = message->getConcept(); |
| 12767 |
bool negation = message->getNegation(); |
| 12768 |
CEntailmentQueryProcessingData* entailmentData = message->getEntailmentData(); |
| 12769 |
entailmentData->mEntailed = !satisfiable; |
| 12770 |
entailmentData->mHasResult = true; |
| 12771 |
for (CXLinker<CComplexQueryExpressionProcessingData*>* procDataLinkerIt = entailmentData->mProcDataLinker; procDataLinkerIt; procDataLinkerIt = procDataLinkerIt->getNext()) { |
| 12772 |
CComplexQueryExpressionProcessingData* queryProcData = procDataLinkerIt->getData(); |
| 12773 |
queryProcData->decEntailmentComputation(); |
| 12774 |
if (!queryProcData->hasComputation()) { |
| 12775 |
finishQueryProcessing(queryProcData); |
| 12776 |
} |
| 12777 |
} |
| 12778 |
mOntoAnsweringItem->releaseQueryProcessingLinker(entailmentData->mProcDataLinker); |
| 12779 |
entailmentData->mProcDataLinker = nullptr; |
| 12780 |
return true; |
| 12781 |
} |
| 12782 |
|
| 12783 |
|
| 12784 |
|
| 12785 |
|
| 12786 |
bool COptimizedComplexExpressionAnsweringHandler::processClassSumsumptionEntailmentCalculationCompleted(CAnsweringMessageDataCalculationCompletedClassSubsumption* message, CAnswererContext* answererContext) { |
| 12787 |
bool satisfiable = message->getCalculationCallbackContextData()->isSatisfiable(); |
| 12788 |
CConcept* subConcept = message->getSubConcept(); |
| 12789 |
bool subConNegation = message->getSubConceptNegation(); |
| 12790 |
CEntailmentQueryProcessingData* entailmentData = message->getEntailmentData(); |
| 12791 |
entailmentData->mEntailed = !satisfiable; |
| 12792 |
entailmentData->mHasResult = true; |
| 12793 |
for (CXLinker<CComplexQueryExpressionProcessingData*>* procDataLinkerIt = entailmentData->mProcDataLinker; procDataLinkerIt; procDataLinkerIt = procDataLinkerIt->getNext()) { |
| 12794 |
CComplexQueryExpressionProcessingData* queryProcData = procDataLinkerIt->getData(); |
| 12795 |
queryProcData->decEntailmentComputation(); |
| 12796 |
if (!queryProcData->hasComputation()) { |
| 12797 |
finishQueryProcessing(queryProcData); |
| 12798 |
} |
| 12799 |
} |
| 12800 |
mOntoAnsweringItem->releaseQueryProcessingLinker(entailmentData->mProcDataLinker); |
| 12801 |
entailmentData->mProcDataLinker = nullptr; |
| 12802 |
return true; |
| 12803 |
} |
| 12804 |
|
| 12805 |
|
| 12806 |
|
| 12807 |
bool COptimizedComplexExpressionAnsweringHandler::notifyWaitingItemData(CComputedItemDataNotificationLinker* notLinker, CComplexConceptStepComputationProcess* compStep, CAnswererContext* answererContext) { |
| 12808 |
if (notLinker) { |
| 12809 |
for (CComputedItemDataNotificationLinker* notLinkerIt = notLinker; notLinkerIt; notLinkerIt = notLinkerIt->getNext()) { |
| 12810 |
COptimizedComplexVariableCompositionItem* varCompItem = notLinkerIt->getVariableCompositionItem(); |
| 12811 |
COptimizedComplexBuildingVariableCompositionsItem* buildVarItem = notLinkerIt->getBuildingVariableItemProcessingItem(); |
| 12812 |
if (buildVarItem) { |
| 12813 |
if (varCompItem) { |
| 12814 |
queueVariableItemComputation(buildVarItem, varCompItem); |
| 12815 |
} |
| 12816 |
buildVarItem->setComputationStepFinished(compStep); |
| 12817 |
if (!buildVarItem->isWaitingComputationStep() && !buildVarItem->isProcessingQueued()) { |
| 12818 |
buildVarItem->setProcessingQueued(true); |
| 12819 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(buildVarItem); |
| 12820 |
} |
| 12821 |
} |
| 12822 |
CComplexQueryExpressionProcessingData* queryProcData = notLinkerIt->getQueryProcessingData(); |
| 12823 |
if (queryProcData) { |
| 12824 |
queryProcData->setComputationStepFinished(compStep); |
| 12825 |
if (!queryProcData->hasComputation()) { |
| 12826 |
finishQueryProcessing(queryProcData); |
| 12827 |
} |
| 12828 |
} |
| 12829 |
} |
| 12830 |
mOntoAnsweringItem->releaseComputedItemDataNotificationLinker(notLinker); |
| 12831 |
return true; |
| 12832 |
} |
| 12833 |
return false; |
| 12834 |
} |
| 12835 |
|
| 12836 |
|
| 12837 |
|
| 12838 |
bool COptimizedComplexExpressionAnsweringHandler::finishCalculationStepProcessing(COptimizedComplexConceptItem* conceptItem, CComplexConceptStepComputationProcess* compStep, CAnswererContext* answererContext) { |
| 12839 |
compStep->setComputationProcessFinished(true); |
| 12840 |
|
| 12841 |
notifyWaitingItemData(compStep->takeNotificationLinker(), compStep, answererContext); |
| 12842 |
|
| 12843 |
requeueConceptItemNextProcessing(conceptItem, compStep); |
| 12844 |
return true; |
| 12845 |
} |
| 12846 |
|
| 12847 |
|
| 12848 |
|
| 12849 |
|
| 12850 |
bool COptimizedComplexExpressionAnsweringHandler::updateComputedInstancesCount(COptimizedComplexConceptItem* conceptItem, CComplexConceptStepInstanceComputationProcess* compStep, CAnswererContext* answererContext) { |
| 12851 |
compStep->updateComputedInstancesCount(conceptItem->getKnownInstanceItems()->size(), [&](CComputedItemDataNotificationLinker* notLinker) { |
| 12852 |
notifyWaitingItemData(notLinker, compStep, answererContext); |
| 12853 |
}); |
| 12854 |
if (conceptItem->isLazyRealizationInstancesRetrieved()) { |
| 12855 |
compStep->setExpectedInstancesCount(conceptItem->getKnownInstanceItems()->size()); |
| 12856 |
compStep->updateAllInstancesComputed([&](CComputedItemDataNotificationLinker* notLinker) { |
| 12857 |
notifyWaitingItemData(notLinker, compStep, answererContext); |
| 12858 |
}); |
| 12859 |
} else { |
| 12860 |
cint64 currentKnownInstances = conceptItem->getKnownInstanceItems()->size(); |
| 12861 |
cint64 currentRetrievedInstances = conceptItem->getRealizationRetrievedInstanceCandidateCount(); |
| 12862 |
cint64 exprectedRetrievedInstances = conceptItem->getRealizationRetrievingExpectedInstanceCandidateCount(); |
| 12863 |
double correctionFactor = (double)currentKnownInstances / (double)currentRetrievedInstances; |
| 12864 |
double exprectedKnownInstances = (double)currentKnownInstances / (double)currentRetrievedInstances * (double)exprectedRetrievedInstances; |
| 12865 |
|
| 12866 |
|
| 12867 |
CRealizationIndividualInstanceItemReferenceIterator* realizationIterator = conceptItem->getRealizationIterator(); |
| 12868 |
COptimizedRepresentativeKPSetIntersectionCombinationIterator* intRealizationIterator = dynamic_cast<COptimizedRepresentativeKPSetIntersectionCombinationIterator*>(conceptItem->getRealizationIterator()); |
| 12869 |
if (intRealizationIterator && (currentRetrievedInstances < mConfConceptItemExpectedCountSamplingRetrievedPercentageLimit * exprectedRetrievedInstances || conceptItem->getRealizationIteratorSamplingExpectedCount() >= 0)) { |
| 12870 |
cint64 currentIndiId = realizationIterator->currentIndividualInstanceItemReference().getIndividualID(); |
| 12871 |
cint64 nextIndiId = mOntoAnsweringItem->getOntology()->getABox()->getNextIndividualId(false); |
| 12872 |
if (currentRetrievedInstances < mConfConceptItemExpectedCountSamplingRetrievedPercentageLimit * exprectedRetrievedInstances && conceptItem->getRealizationIteratorSamplingExpectedCount() < 0) { |
| 12873 |
|
| 12874 |
//QStringList sampleStringList; |
| 12875 |
//QString sampleString; |
| 12876 |
|
| 12877 |
CRealizationIndividualInstanceItemReferenceIterator* samplingIterator = realizationIterator->getCopy(); |
| 12878 |
cint64 samplingCount = 0; |
| 12879 |
cint64 availableSampleCount = 0; |
| 12880 |
double availableSampleIndiDiff = 0; |
| 12881 |
double nonAvailableSampleIndiDiff = 0; |
| 12882 |
cint64 availableSampleRequiredInitializationCount = 0; |
| 12883 |
double samplingRange = 0; |
| 12884 |
double samplingRangeExpectedCount = 0; |
| 12885 |
for (cint64 samplingNr = currentKnownInstances + 1; samplingNr < mConfConceptItemExpectedCountSamplingSize; ++samplingNr) { |
| 12886 |
double samplingIndiId = (double)nextIndiId / (double)mConfConceptItemExpectedCountSamplingSize * (double)samplingNr; |
| 12887 |
double nextSamplingIndiId = (double)nextIndiId / (double)mConfConceptItemExpectedCountSamplingSize * (double)(samplingNr + 1); |
| 12888 |
if (samplingIndiId > currentIndiId) { |
| 12889 |
++samplingCount; |
| 12890 |
samplingRange += nextSamplingIndiId - samplingIndiId; |
| 12891 |
|
| 12892 |
if (!samplingIterator->atEnd()) { |
| 12893 |
cint64 sampleIndiId = samplingIterator->currentIndividualInstanceItemReference().getIndividualID(); |
| 12894 |
if (sampleIndiId < samplingIndiId) { |
| 12895 |
samplingIterator->moveTo(CRealizationIndividualInstanceItemReference(samplingIndiId + 1., nullptr), false); |
| 12896 |
if (!samplingIterator->atEnd()) { |
| 12897 |
sampleIndiId = samplingIterator->currentIndividualInstanceItemReference().getIndividualID(); |
| 12898 |
} else { |
| 12899 |
sampleIndiId = -1; |
| 12900 |
} |
| 12901 |
} |
| 12902 |
if (sampleIndiId >= samplingIndiId && sampleIndiId < nextSamplingIndiId) { |
| 12903 |
availableSampleCount++; |
| 12904 |
|
| 12905 |
cint64 nextSampleIndiId = -1; |
| 12906 |
bool requiresInitialization = samplingIterator->requiresInitialization(); |
| 12907 |
samplingIterator->moveNext(); |
| 12908 |
if (!samplingIterator->atEnd()) { |
| 12909 |
nextSampleIndiId = samplingIterator->currentIndividualInstanceItemReference().getIndividualID(); |
| 12910 |
} |
| 12911 |
if (nextSampleIndiId == -1 || nextSampleIndiId > nextSamplingIndiId) { |
| 12912 |
// only one individual in sampling range |
| 12913 |
double newExpectedCount = 1.; |
| 12914 |
if (requiresInitialization) { |
| 12915 |
availableSampleRequiredInitializationCount++; |
| 12916 |
newExpectedCount = 0.5; |
| 12917 |
} |
| 12918 |
availableSampleIndiDiff += (nextSamplingIndiId - samplingIndiId); |
| 12919 |
samplingRangeExpectedCount += newExpectedCount; |
| 12920 |
//sampleStringList.append(QString("Sample \t%1 between \t%2 and \t%3 is \t%4 with nothing else, adding \t%6 to expected \t(now %7)").arg(samplingNr).arg(samplingIndiId).arg(nextSamplingIndiId).arg(sampleIndiId).arg(newExpectedCount).arg(samplingRangeExpectedCount)); |
| 12921 |
//sampleString = sampleStringList.join("\r\n"); |
| 12922 |
} else { |
| 12923 |
double indiSampleDiff = nextSampleIndiId - sampleIndiId; |
| 12924 |
double indiStartDiff = qMax(sampleIndiId - samplingIndiId, 1.); |
| 12925 |
double indiDiff = indiSampleDiff / 5. * 4 + indiStartDiff / 5; |
| 12926 |
|
| 12927 |
availableSampleIndiDiff += indiDiff; |
| 12928 |
if (requiresInitialization) { |
| 12929 |
availableSampleRequiredInitializationCount++; |
| 12930 |
double newExpectedCount = ((nextSamplingIndiId - samplingIndiId) / indiDiff) * 0.5; |
| 12931 |
samplingRangeExpectedCount += newExpectedCount; |
| 12932 |
} else { |
| 12933 |
double newExpectedCount = ((nextSamplingIndiId - samplingIndiId) / indiDiff); |
| 12934 |
samplingRangeExpectedCount += newExpectedCount; |
| 12935 |
//sampleStringList.append(QString("Sample \t%1 between \t%2 and \t%3 is \t%4 and %8 with diff \t%5, adding \t%6 to expected \t(now %7)").arg(samplingNr).arg(samplingIndiId).arg(nextSamplingIndiId).arg(sampleIndiId).arg(indiDiff).arg(newExpectedCount).arg(samplingRangeExpectedCount).arg(nextSampleIndiId)); |
| 12936 |
//sampleString = sampleStringList.join("\r\n"); |
| 12937 |
} |
| 12938 |
|
| 12939 |
} |
| 12940 |
|
| 12941 |
|
| 12942 |
} else { |
| 12943 |
availableSampleIndiDiff += nextSamplingIndiId - samplingIndiId; |
| 12944 |
nonAvailableSampleIndiDiff += nextSamplingIndiId - samplingIndiId; |
| 12945 |
//sampleStringList.append(QString("Sample \t%1 between \t%2 and \t%3 does not exist, interpreting it as diff \t%4").arg(samplingNr).arg(samplingIndiId).arg(nextSamplingIndiId).arg(nextSamplingIndiId - samplingIndiId)); |
| 12946 |
//sampleString = sampleStringList.join("\r\n"); |
| 12947 |
} |
| 12948 |
} else { |
| 12949 |
availableSampleIndiDiff += nextSamplingIndiId - samplingIndiId; |
| 12950 |
nonAvailableSampleIndiDiff += nextSamplingIndiId - samplingIndiId; |
| 12951 |
//sampleStringList.append(QString("Sample \t%1 between \t%2 and \t%3 does not exist, interpreting it as diff \t%4").arg(samplingNr).arg(samplingIndiId).arg(nextSamplingIndiId).arg(nextSamplingIndiId - samplingIndiId)); |
| 12952 |
//sampleString = sampleStringList.join("\r\n"); |
| 12953 |
} |
| 12954 |
|
| 12955 |
|
| 12956 |
} |
| 12957 |
} |
| 12958 |
delete samplingIterator; |
| 12959 |
|
| 12960 |
if (samplingCount > 0) { |
| 12961 |
double diffBasedSamplingRangeExpectedCount = nextIndiId / availableSampleIndiDiff * availableSampleCount; |
| 12962 |
double samplesExpectedIndiCount = diffBasedSamplingRangeExpectedCount; |
| 12963 |
if (availableSampleIndiDiff <= 0) { |
| 12964 |
samplesExpectedIndiCount = 0; |
| 12965 |
} |
| 12966 |
conceptItem->setRealizationIteratorSamplingExpectedCount(samplesExpectedIndiCount); |
| 12967 |
|
| 12968 |
if (mConfExtendedLogging) { |
| 12969 |
LOG(INFO, getDomain(), logTr("Took %2 samples to correct expected instance count from %3 to %4 for complex concept item %1.").arg(conceptItem->getConceptItemId()).arg(samplingCount).arg(exprectedKnownInstances).arg(samplesExpectedIndiCount), this); |
| 12970 |
} |
| 12971 |
|
| 12972 |
} |
| 12973 |
} |
| 12974 |
|
| 12975 |
|
| 12976 |
double sampleWeightFactor = (double)(nextIndiId - currentIndiId) / (double)nextIndiId; |
| 12977 |
double iteratorWeightFactor = (double)(currentIndiId) / (double)nextIndiId; |
| 12978 |
double samplesExpectedIndiCount = conceptItem->getRealizationIteratorSamplingExpectedCount(); |
| 12979 |
double samplingCorrectedExpectedCount = exprectedKnownInstances * iteratorWeightFactor + samplesExpectedIndiCount * sampleWeightFactor; |
| 12980 |
exprectedKnownInstances = samplingCorrectedExpectedCount * correctionFactor; |
| 12981 |
} |
| 12982 |
|
| 12983 |
|
| 12984 |
compStep->setExpectedInstancesCount(exprectedKnownInstances); |
| 12985 |
|
| 12986 |
|
| 12987 |
|
| 12988 |
} |
| 12989 |
return true; |
| 12990 |
} |
| 12991 |
|
| 12992 |
QSet<COptimizedComplexConceptItem*>* COptimizedComplexExpressionAnsweringHandler::collectComplexConceptItemPredecessors(COptimizedComplexConceptItem* conceptItem, QSet<COptimizedComplexConceptItem*>* predItemSet) { |
| 12993 |
if (!predItemSet) { |
| 12994 |
predItemSet = new QSet<COptimizedComplexConceptItem *>(); |
| 12995 |
} |
| 12996 |
QList<COptimizedComplexConceptItem*> addingList; |
| 12997 |
addingList.append(conceptItem); |
| 12998 |
while (!addingList.isEmpty()) { |
| 12999 |
COptimizedComplexConceptItem* testingItem = addingList.takeFirst(); |
| 13000 |
if (!predItemSet->contains(testingItem)) { |
| 13001 |
predItemSet->insert(testingItem); |
| 13002 |
for (auto superItem : *testingItem->getSuperComplexConceptItemSet()) { |
| 13003 |
addingList.append(superItem); |
| 13004 |
} |
| 13005 |
} |
| 13006 |
} |
| 13007 |
return predItemSet; |
| 13008 |
} |
| 13009 |
|
| 13010 |
|
| 13011 |
|
| 13012 |
QSet<COptimizedComplexConceptItem*>* COptimizedComplexExpressionAnsweringHandler::collectComplexConceptItemSucessors(COptimizedComplexConceptItem* conceptItem, QSet<COptimizedComplexConceptItem*>* succItemSet) { |
| 13013 |
if (!succItemSet) { |
| 13014 |
succItemSet = new QSet<COptimizedComplexConceptItem *>(); |
| 13015 |
} |
| 13016 |
QList<COptimizedComplexConceptItem*> addingList; |
| 13017 |
addingList.append(conceptItem); |
| 13018 |
while (!addingList.isEmpty()) { |
| 13019 |
COptimizedComplexConceptItem* testingItem = addingList.takeFirst(); |
| 13020 |
if (!succItemSet->contains(testingItem)) { |
| 13021 |
succItemSet->insert(testingItem); |
| 13022 |
for (auto superItem : *testingItem->getSubComplexConceptItemSet()) { |
| 13023 |
addingList.append(superItem); |
| 13024 |
} |
| 13025 |
} |
| 13026 |
} |
| 13027 |
return succItemSet; |
| 13028 |
} |
| 13029 |
|
| 13030 |
|
| 13031 |
|
| 13032 |
bool COptimizedComplexExpressionAnsweringHandler::reorderConceptItemParentAddition(COptimizedComplexConceptItem* conceptItem, COptimizedComplexConceptItem* newParentConceptItem) { |
| 13033 |
QSet<COptimizedComplexConceptItem*>* newParentPredItemSet = collectComplexConceptItemPredecessors(newParentConceptItem); |
| 13034 |
QSet<COptimizedComplexConceptItem*>* conceptItemSuccItemSet = collectComplexConceptItemSucessors(conceptItem); |
| 13035 |
QList<COptimizedComplexConceptItem*> removeParentItemList; |
| 13036 |
|
| 13037 |
for (QSet<COptimizedComplexConceptItem*>::iterator it = conceptItem->getSuperComplexConceptItemSet()->begin(); it != conceptItem->getSuperComplexConceptItemSet()->end();) { |
| 13038 |
COptimizedComplexConceptItem* parentItem(*it); |
| 13039 |
if (newParentPredItemSet->contains(parentItem)) { |
| 13040 |
parentItem->getSubComplexConceptItemSet()->remove(conceptItem); |
| 13041 |
it = conceptItem->getSuperComplexConceptItemSet()->erase(it); |
| 13042 |
} else { |
| 13043 |
++it; |
| 13044 |
} |
| 13045 |
} |
| 13046 |
for (QSet<COptimizedComplexConceptItem*>::iterator it = newParentConceptItem->getSubComplexConceptItemSet()->begin(); it != newParentConceptItem->getSubComplexConceptItemSet()->end();) { |
| 13047 |
COptimizedComplexConceptItem* childItem(*it); |
| 13048 |
if (conceptItemSuccItemSet->contains(childItem)) { |
| 13049 |
it = newParentConceptItem->getSubComplexConceptItemSet()->erase(it); |
| 13050 |
childItem->getSuperComplexConceptItemSet()->remove(newParentConceptItem); |
| 13051 |
} else { |
| 13052 |
++it; |
| 13053 |
} |
| 13054 |
} |
| 13055 |
delete conceptItemSuccItemSet; |
| 13056 |
delete newParentPredItemSet; |
| 13057 |
|
| 13058 |
conceptItem->getSuperComplexConceptItemSet()->insert(newParentConceptItem); |
| 13059 |
newParentConceptItem->getSubComplexConceptItemSet()->insert(conceptItem); |
| 13060 |
|
| 13061 |
return true; |
| 13062 |
} |
| 13063 |
|
| 13064 |
|
| 13065 |
bool COptimizedComplexExpressionAnsweringHandler::reorderConceptClassItems() { |
| 13066 |
QList<COptimizedComplexConceptItem*>* classItemReorderingList = mOntoAnsweringItem->getConceptClassItemReorderingList(); |
| 13067 |
CClassConceptClassification* classClassification = mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification(); |
| 13068 |
if (classClassification) { |
| 13069 |
CTaxonomy* taxonomy = classClassification->getClassConceptTaxonomy(); |
| 13070 |
while (!classItemReorderingList->isEmpty()) { |
| 13071 |
COptimizedComplexConceptItem* classItem = classItemReorderingList->takeFirst(); |
| 13072 |
CConcept* classConcept = classItem->getConcept(); |
| 13073 |
CHierarchyNode* classHierNode = taxonomy->getHierarchyNode(classConcept, false); |
| 13074 |
if (classHierNode) { |
| 13075 |
QList<CHierarchyNode*> predTestingList; |
| 13076 |
for (auto parentHierNode : *classHierNode->getParentNodeSet()) { |
| 13077 |
predTestingList.append(parentHierNode); |
| 13078 |
} |
| 13079 |
while (!predTestingList.isEmpty()) { |
| 13080 |
auto parentHierNode = predTestingList.takeFirst(); |
| 13081 |
bool foundParent = false; |
| 13082 |
for (auto parentConcept : *parentHierNode->getEquivalentConceptList()) { |
| 13083 |
COptimizedComplexConceptItem* parentClassItem = mOntoAnsweringItem->getComplexConceptItem(parentConcept, false, false); |
| 13084 |
if (parentClassItem) { |
| 13085 |
foundParent = true; |
| 13086 |
if (!classItem->hasSuperComplexConceptItem(parentClassItem)) { |
| 13087 |
reorderConceptItemParentAddition(classItem, parentClassItem); |
| 13088 |
} |
| 13089 |
} |
| 13090 |
} |
| 13091 |
if (!foundParent) { |
| 13092 |
for (auto nextParentHierNode : *parentHierNode->getParentNodeSet()) { |
| 13093 |
predTestingList.append(nextParentHierNode); |
| 13094 |
} |
| 13095 |
} |
| 13096 |
} |
| 13097 |
} |
| 13098 |
} |
| 13099 |
} |
| 13100 |
return true; |
| 13101 |
} |
| 13102 |
|
| 13103 |
|
| 13104 |
|
| 13105 |
bool COptimizedComplexExpressionAnsweringHandler::extractAtomicSubsumerExpressions(COptimizedComplexConceptItem* conceptItem) { |
| 13106 |
CConcept* concept = conceptItem->getConcept(); |
| 13107 |
bool conceptNegation = conceptItem->getConceptNegation(); |
| 13108 |
QList<TConceptNegPair> testingList; |
| 13109 |
testingList.append(TConceptNegPair(concept,conceptNegation)); |
| 13110 |
QSet<TConceptNegPair>* atomicConceptSet = conceptItem->getAtomicConcpetSet(); |
| 13111 |
while (!testingList.isEmpty()) { |
| 13112 |
TConceptNegPair testingConNegPair = testingList.takeFirst(); |
| 13113 |
CConcept* testingConcept = testingConNegPair.first; |
| 13114 |
bool testingNegation = testingConNegPair.second; |
| 13115 |
cint64 opCode = testingConcept->getOperatorCode(); |
| 13116 |
if (!testingNegation && opCode == CCAND || testingNegation && opCode == CCOR) { |
| 13117 |
for (CSortedNegLinker<CConcept*>* opLinkerIt = testingConcept->getOperandList(); opLinkerIt; opLinkerIt = opLinkerIt->getNext()) { |
| 13118 |
CConcept* opConcept = opLinkerIt->getData(); |
| 13119 |
bool opNegation = opLinkerIt->isNegated() ^ testingNegation; |
| 13120 |
testingList.append(TConceptNegPair(opConcept, opNegation)); |
| 13121 |
} |
| 13122 |
} else { |
| 13123 |
atomicConceptSet->insert(testingConNegPair); |
| 13124 |
} |
| 13125 |
} |
| 13126 |
return !atomicConceptSet->isEmpty(); |
| 13127 |
} |
| 13128 |
|
| 13129 |
|
| 13130 |
bool COptimizedComplexExpressionAnsweringHandler::isTriviallySubsumedConceptItem(COptimizedComplexConceptItem* subsumedConceptItem, COptimizedComplexConceptItem* subsumerConceptItem) { |
| 13131 |
if (subsumedConceptItem->getAtomicConcpetSet()->contains(subsumerConceptItem->getConceptNegationPair())) { |
| 13132 |
return true; |
| 13133 |
} |
| 13134 |
if (subsumedConceptItem->getAtomicConcpetSet()->contains(*subsumerConceptItem->getAtomicConcpetSet())) { |
| 13135 |
return true; |
| 13136 |
} |
| 13137 |
return false; |
| 13138 |
} |
| 13139 |
|
| 13140 |
|
| 13141 |
|
| 13142 |
|
| 13143 |
|
| 13144 |
bool COptimizedComplexExpressionAnsweringHandler::searchSuperSubSuperClassesResult(COptimizedComplexConceptItem* startConceptItem, CAnswererContext* answererContext) { |
| 13145 |
|
| 13146 |
if (!startConceptItem->isSatisfiable()) { |
| 13147 |
QSet<CHierarchyNode*> bottomClassNodeSet; |
| 13148 |
bottomClassNodeSet.insert(mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getBottomHierarchyNode()); |
| 13149 |
startConceptItem->setKnownSuperClassNodeSet(new QSet<CHierarchyNode*>(bottomClassNodeSet)); |
| 13150 |
return true; |
| 13151 |
} |
| 13152 |
if (startConceptItem->getConcept()->hasClassName()) { |
| 13153 |
QSet<CHierarchyNode*> chilsClassNodeSet; |
| 13154 |
chilsClassNodeSet.insert(mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getHierarchyNode(startConceptItem->getConcept())); |
| 13155 |
startConceptItem->setKnownSuperClassNodeSet(new QSet<CHierarchyNode*>(chilsClassNodeSet)); |
| 13156 |
return true; |
| 13157 |
} |
| 13158 |
|
| 13159 |
|
| 13160 |
class CSuperSubsumptionOptimizedComplexConceptItemVisitor : public COptimizedComplexConceptItemVisitor { |
| 13161 |
public: |
| 13162 |
QSet<CHierarchyNode*>* mFoundKnwonSuperClassNodeSet = nullptr; |
| 13163 |
QSet<CHierarchyNode*>* mFoundPossibleSuperClassNodeSet = nullptr; |
| 13164 |
|
| 13165 |
cint64 mSuperItemVisitingLimit = 50; |
| 13166 |
cint64 mSuperItemResultVisitingLimit = 10; |
| 13167 |
|
| 13168 |
cint64 mSubItemVisitingLimit = 50; |
| 13169 |
cint64 mSubItemResultVisitingLimit = 10; |
| 13170 |
|
| 13171 |
bool visitComplexSuperConceptItem(COptimizedComplexConceptItem* item, bool& continueVisitingSuperItems) { |
| 13172 |
CComplexConceptStepComputationProcess* compStep = item->getComputationProcess()->getSuperClassNodesComputationProcess(false); |
| 13173 |
if (compStep && compStep->isComputationProcessFinished()) { |
| 13174 |
QSet<CHierarchyNode*>* superClassNodeSet = item->getDirectSuperClassNodeSet(); |
| 13175 |
if (!mFoundKnwonSuperClassNodeSet) { |
| 13176 |
mFoundKnwonSuperClassNodeSet = new QSet<CHierarchyNode*>(); |
| 13177 |
} |
| 13178 |
mFoundKnwonSuperClassNodeSet->operator+=(*superClassNodeSet); |
| 13179 |
continueVisitingSuperItems = false; |
| 13180 |
if (--mSuperItemResultVisitingLimit < 0) { |
| 13181 |
return false; |
| 13182 |
} |
| 13183 |
} |
| 13184 |
if (--mSuperItemVisitingLimit < 0) { |
| 13185 |
return false; |
| 13186 |
} |
| 13187 |
return true; |
| 13188 |
} |
| 13189 |
|
| 13190 |
bool visitComplexSubConceptItem(COptimizedComplexConceptItem* item, bool& continueVisitingSubItems) { |
| 13191 |
CComplexConceptStepComputationProcess* compStep = item->getComputationProcess()->getSuperClassNodesComputationProcess(false); |
| 13192 |
if (compStep && compStep->isComputationProcessFinished()) { |
| 13193 |
QSet<CHierarchyNode*>* superClassNodeSet = item->getDirectSuperClassNodeSet(); |
| 13194 |
if (!mFoundPossibleSuperClassNodeSet) { |
| 13195 |
mFoundPossibleSuperClassNodeSet = new QSet<CHierarchyNode*>(); |
| 13196 |
if (mFoundKnwonSuperClassNodeSet && !mFoundKnwonSuperClassNodeSet->isEmpty()) { |
| 13197 |
for (auto node : *superClassNodeSet) { |
| 13198 |
if (!mFoundKnwonSuperClassNodeSet->contains(node)) { |
| 13199 |
mFoundPossibleSuperClassNodeSet->insert(node); |
| 13200 |
} |
| 13201 |
} |
| 13202 |
} else { |
| 13203 |
*mFoundPossibleSuperClassNodeSet = *superClassNodeSet; |
| 13204 |
} |
| 13205 |
} else { |
| 13206 |
mFoundPossibleSuperClassNodeSet->intersect(*superClassNodeSet); |
| 13207 |
} |
| 13208 |
if (mFoundPossibleSuperClassNodeSet->isEmpty()) { |
| 13209 |
return false; |
| 13210 |
} |
| 13211 |
continueVisitingSubItems = false; |
| 13212 |
if (--mSubItemResultVisitingLimit < 0) { |
| 13213 |
return false; |
| 13214 |
} |
| 13215 |
} |
| 13216 |
if (--mSubItemVisitingLimit < 0) { |
| 13217 |
return false; |
| 13218 |
} |
| 13219 |
return true; |
| 13220 |
} |
| 13221 |
|
| 13222 |
} visitor; |
| 13223 |
visitSuperSubConceptItems(startConceptItem, false, true, &visitor); |
| 13224 |
if (visitor.mFoundKnwonSuperClassNodeSet) { |
| 13225 |
startConceptItem->setKnownSuperClassNodeSet(visitor.mFoundKnwonSuperClassNodeSet); |
| 13226 |
visitSuperSubConceptItems(startConceptItem, true, false, &visitor); |
| 13227 |
if (visitor.mFoundPossibleSuperClassNodeSet) { |
| 13228 |
startConceptItem->setPossibleSuperClassNodeSet(visitor.mFoundPossibleSuperClassNodeSet); |
| 13229 |
return true; |
| 13230 |
} |
| 13231 |
} |
| 13232 |
return false; |
| 13233 |
} |
| 13234 |
|
| 13235 |
|
| 13236 |
|
| 13237 |
|
| 13238 |
|
| 13239 |
|
| 13240 |
|
| 13241 |
|
| 13242 |
|
| 13243 |
|
| 13244 |
|
| 13245 |
|
| 13246 |
|
| 13247 |
|
| 13248 |
|
| 13249 |
|
| 13250 |
|
| 13251 |
|
| 13252 |
bool COptimizedComplexExpressionAnsweringHandler::searchSuperSubSubClassesResult(COptimizedComplexConceptItem* startConceptItem, CAnswererContext* answererContext) { |
| 13253 |
|
| 13254 |
if (!startConceptItem->isSatisfiable()) { |
| 13255 |
QSet<CHierarchyNode*> bottomClassNodeSet; |
| 13256 |
bottomClassNodeSet.insert(mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getBottomHierarchyNode()); |
| 13257 |
startConceptItem->setDirectSubClassNodeSet(new QSet<CHierarchyNode*>(bottomClassNodeSet)); |
| 13258 |
return true; |
| 13259 |
} |
| 13260 |
if (startConceptItem->getConcept()->hasClassName()) { |
| 13261 |
QSet<CHierarchyNode*> chilsClassNodeSet; |
| 13262 |
chilsClassNodeSet.insert(mOntoAnsweringItem->getOntology()->getClassification()->getClassConceptClassification()->getClassConceptTaxonomy()->getHierarchyNode(startConceptItem->getConcept())); |
| 13263 |
startConceptItem->setDirectSubClassNodeSet(new QSet<CHierarchyNode*>(chilsClassNodeSet)); |
| 13264 |
return true; |
| 13265 |
} |
| 13266 |
|
| 13267 |
|
| 13268 |
class CSuperSubsumptionOptimizedComplexConceptItemVisitor : public COptimizedComplexConceptItemVisitor { |
| 13269 |
public: |
| 13270 |
QSet<CHierarchyNode*>* mFoundMinimumSubClassNodeSet = nullptr; |
| 13271 |
QSet<CHierarchyNode*>* mFoundMaximumSubClassNodeSet = nullptr; |
| 13272 |
|
| 13273 |
cint64 mSuperItemVisitingLimit = 50; |
| 13274 |
cint64 mSuperItemResultVisitingLimit = 10; |
| 13275 |
|
| 13276 |
cint64 mSubItemVisitingLimit = 50; |
| 13277 |
cint64 mSubItemResultVisitingLimit = 10; |
| 13278 |
|
| 13279 |
bool visitComplexSuperConceptItem(COptimizedComplexConceptItem* item, bool& continueVisitingSuperItems) { |
| 13280 |
CComplexConceptStepComputationProcess* compStep = item->getComputationProcess()->getSubClassNodesComputationProcess(false); |
| 13281 |
if (compStep && compStep->isComputationProcessFinished()) { |
| 13282 |
QSet<CHierarchyNode*>* superClassNodeSet = item->getDirectSubClassNodeSet(); |
| 13283 |
if (!mFoundMinimumSubClassNodeSet) { |
| 13284 |
mFoundMinimumSubClassNodeSet = new QSet<CHierarchyNode*>(); |
| 13285 |
} |
| 13286 |
mFoundMinimumSubClassNodeSet->operator+=(*superClassNodeSet); |
| 13287 |
continueVisitingSuperItems = false; |
| 13288 |
if (--mSuperItemResultVisitingLimit < 0) { |
| 13289 |
return false; |
| 13290 |
} |
| 13291 |
} |
| 13292 |
if (--mSuperItemVisitingLimit < 0) { |
| 13293 |
return false; |
| 13294 |
} |
| 13295 |
return true; |
| 13296 |
} |
| 13297 |
|
| 13298 |
bool visitComplexSubConceptItem(COptimizedComplexConceptItem* item, bool& continueVisitingSubItems) { |
| 13299 |
CComplexConceptStepComputationProcess* compStep = item->getComputationProcess()->getSubClassNodesComputationProcess(false); |
| 13300 |
if (compStep && compStep->isComputationProcessFinished()) { |
| 13301 |
QSet<CHierarchyNode*>* superClassNodeSet = item->getDirectSubClassNodeSet(); |
| 13302 |
if (!mFoundMaximumSubClassNodeSet) { |
| 13303 |
mFoundMaximumSubClassNodeSet = new QSet<CHierarchyNode*>(); |
| 13304 |
} |
| 13305 |
mFoundMaximumSubClassNodeSet->operator+=(*superClassNodeSet); |
| 13306 |
continueVisitingSubItems = false; |
| 13307 |
if (--mSuperItemResultVisitingLimit < 0) { |
| 13308 |
return false; |
| 13309 |
} |
| 13310 |
continueVisitingSubItems = false; |
| 13311 |
if (--mSubItemResultVisitingLimit < 0) { |
| 13312 |
return false; |
| 13313 |
} |
| 13314 |
} |
| 13315 |
if (--mSubItemVisitingLimit < 0) { |
| 13316 |
return false; |
| 13317 |
} |
| 13318 |
return true; |
| 13319 |
} |
| 13320 |
|
| 13321 |
} visitor; |
| 13322 |
visitSuperSubConceptItems(startConceptItem, false, true, &visitor); |
| 13323 |
|
| 13324 |
|
| 13325 |
|
| 13326 |
QSet<CHierarchyNode*> testingSubClassCandidateSet; |
| 13327 |
if (visitor.mFoundMinimumSubClassNodeSet) { |
| 13328 |
visitor.mFoundMinimumSubClassNodeSet; |
| 13329 |
for (auto node : *visitor.mFoundMinimumSubClassNodeSet) { |
| 13330 |
testingSubClassCandidateSet.insert(node); |
| 13331 |
} |
| 13332 |
} |
| 13333 |
QSet<CHierarchyNode*>* directSuperClassNodeSet = startConceptItem->getDirectSuperClassNodeSet(); |
| 13334 |
if (directSuperClassNodeSet) { |
| 13335 |
for (QSet<CHierarchyNode*>::const_iterator it = directSuperClassNodeSet->constBegin(), itEnd = directSuperClassNodeSet->constEnd(); it != itEnd; ++it) { |
| 13336 |
CHierarchyNode* hierNode(*it); |
| 13337 |
testingSubClassCandidateSet.insert(hierNode); |
| 13338 |
} |
| 13339 |
} |
| 13340 |
QSet<CHierarchyNode*>* possibleClassNodeTestingSet = getDirectReducedSuperNodeSet(testingSubClassCandidateSet); |
| 13341 |
startConceptItem->setPossibleSubClassTestingNodeSet(possibleClassNodeTestingSet); |
| 13342 |
QList<CHierarchyNode*>* possibleClassNodeTestingList = new QList<CHierarchyNode *>(); |
| 13343 |
startConceptItem->setPossibleSubClassNodeTestingList(possibleClassNodeTestingList); |
| 13344 |
|
| 13345 |
|
| 13346 |
for (auto node : *possibleClassNodeTestingSet) { |
| 13347 |
possibleClassNodeTestingList->append(node); |
| 13348 |
} |
| 13349 |
|
| 13350 |
QSet<CHierarchyNode*>* directSubClassNodeSet = new QSet<CHierarchyNode*>(); |
| 13351 |
startConceptItem->setDirectSubClassNodeSet(directSubClassNodeSet); |
| 13352 |
|
| 13353 |
|
| 13354 |
visitSuperSubConceptItems(startConceptItem, true, false, &visitor); |
| 13355 |
if (visitor.mFoundMaximumSubClassNodeSet) { |
| 13356 |
startConceptItem->setMaximumSubClassNodeSet(visitor.mFoundMaximumSubClassNodeSet); |
| 13357 |
return true; |
| 13358 |
} |
| 13359 |
return false; |
| 13360 |
} |
| 13361 |
|
| 13362 |
|
| 13363 |
|
| 13364 |
|
| 13365 |
|
| 13366 |
|
| 13367 |
|
| 13368 |
|
| 13369 |
|
| 13370 |
|
| 13371 |
|
| 13372 |
|
| 13373 |
|
| 13374 |
|
| 13375 |
|
| 13376 |
bool COptimizedComplexExpressionAnsweringHandler::searchSuperSubSatisfiabilityResult(COptimizedComplexConceptItem* startConceptItem, CAnswererContext* answererContext) { |
| 13377 |
class CSatisfiabilityOptimizedComplexConceptItemVisitor : public COptimizedComplexConceptItemVisitor { |
| 13378 |
public: |
| 13379 |
bool mSatisfiabilityResult = false; |
| 13380 |
bool mFoundSatisfiability = false; |
| 13381 |
bool visitComplexConceptItem(COptimizedComplexConceptItem* item, bool superItem, bool subItem) { |
| 13382 |
CComplexConceptStepComputationProcess* compStep = item->getComputationProcess()->getSatisfiableClassNodesComputationProcess(false); |
| 13383 |
if (compStep && compStep->isComputationProcessFinished()) { |
| 13384 |
if (superItem) { |
| 13385 |
if (!item->isSatisfiable()) { |
| 13386 |
mSatisfiabilityResult = false; |
| 13387 |
mFoundSatisfiability = true; |
| 13388 |
return false; |
| 13389 |
} |
| 13390 |
} |
| 13391 |
if (subItem) { |
| 13392 |
if (item->isSatisfiable()) { |
| 13393 |
mSatisfiabilityResult = true; |
| 13394 |
mFoundSatisfiability = true; |
| 13395 |
return false; |
| 13396 |
} |
| 13397 |
} |
| 13398 |
} |
| 13399 |
return true; |
| 13400 |
} |
| 13401 |
|
| 13402 |
} visitor; |
| 13403 |
visitSuperSubConceptItems(startConceptItem, true, true, &visitor); |
| 13404 |
if (visitor.mFoundSatisfiability) { |
| 13405 |
startConceptItem->setSatisfiability(visitor.mSatisfiabilityResult); |
| 13406 |
startConceptItem->getComputationProcess()->getSatisfiableClassNodesComputationProcess(true)->incDerivedComputationCount()->setComputationProcessFinished(true); |
| 13407 |
return true; |
| 13408 |
} |
| 13409 |
return false; |
| 13410 |
} |
| 13411 |
|
| 13412 |
|
| 13413 |
|
| 13414 |
bool COptimizedComplexExpressionAnsweringHandler::visitSuperSubConceptItems(COptimizedComplexConceptItem* startConceptItem, bool visitSubItems, bool visitSuperItems, COptimizedComplexConceptItemVisitor* visitor) { |
| 13415 |
reorderConceptClassItems(); |
| 13416 |
if (visitSuperItems) { |
| 13417 |
QList<COptimizedComplexConceptItem*> superVisitingList; |
| 13418 |
QSet<COptimizedComplexConceptItem*> superVisitingSet; |
| 13419 |
superVisitingList.append(startConceptItem); |
| 13420 |
while (!superVisitingList.isEmpty()) { |
| 13421 |
COptimizedComplexConceptItem* visitingItem = superVisitingList.takeFirst(); |
| 13422 |
bool continueVisiting = true; |
| 13423 |
if (!visitor->visitComplexSuperConceptItem(visitingItem, continueVisiting)) { |
| 13424 |
return false; |
| 13425 |
} |
| 13426 |
if (continueVisiting) { |
| 13427 |
for (COptimizedComplexConceptItem* superItem : *visitingItem->getSuperComplexConceptItemSet()) { |
| 13428 |
if (!superVisitingSet.contains(superItem)) { |
| 13429 |
superVisitingSet.insert(superItem); |
| 13430 |
superVisitingList.append(superItem); |
| 13431 |
} |
| 13432 |
} |
| 13433 |
} |
| 13434 |
} |
| 13435 |
} |
| 13436 |
if (visitSubItems) { |
| 13437 |
QList<COptimizedComplexConceptItem*> subVisitingList; |
| 13438 |
QSet<COptimizedComplexConceptItem*> subVisitingSet; |
| 13439 |
subVisitingList.append(startConceptItem); |
| 13440 |
while (!subVisitingList.isEmpty()) { |
| 13441 |
COptimizedComplexConceptItem* visitingItem = subVisitingList.takeFirst(); |
| 13442 |
bool continueVisiting = true; |
| 13443 |
if (!visitor->visitComplexSubConceptItem(visitingItem, continueVisiting)) { |
| 13444 |
return false; |
| 13445 |
} |
| 13446 |
if (continueVisiting) { |
| 13447 |
for (COptimizedComplexConceptItem* subItem : *visitingItem->getSubComplexConceptItemSet()) { |
| 13448 |
if (!subVisitingSet.contains(subItem)) { |
| 13449 |
subVisitingSet.insert(subItem); |
| 13450 |
subVisitingList.append(subItem); |
| 13451 |
} |
| 13452 |
} |
| 13453 |
} |
| 13454 |
} |
| 13455 |
} |
| 13456 |
return true; |
| 13457 |
} |
| 13458 |
|
| 13459 |
|
| 13460 |
bool itemSortMorePredecessorsThan(const TConceptItemPredecessorSet& item1, const TConceptItemPredecessorSet& item2) { |
| 13461 |
return item1.second->count() > item1.second->count(); |
| 13462 |
} |
| 13463 |
|
| 13464 |
|
| 13465 |
bool COptimizedComplexExpressionAnsweringHandler::searchTrivialSuperSubConceptItems(COptimizedComplexConceptItem* conceptItem) { |
| 13466 |
QSet<TConceptNegPair>* atomicConceptSet = conceptItem->getAtomicConcpetSet(); |
| 13467 |
COptimizedComplexConceptItem* topConceptItem = mOntoAnsweringItem->getTopConceptItem(); |
| 13468 |
QList<COptimizedComplexConceptItem*> testingConceptItemList; |
| 13469 |
for (TConceptNegPair atomicConNegPair : *atomicConceptSet) { |
| 13470 |
bool atomicConceptClass = false; |
| 13471 |
if (atomicConNegPair.first->hasClassName() && !atomicConNegPair.second) { |
| 13472 |
atomicConceptClass = true; |
| 13473 |
} |
| 13474 |
bool created = false; |
| 13475 |
COptimizedComplexConceptItem* atomicConceptItem = mOntoAnsweringItem->getComplexConceptItem(atomicConNegPair.first, atomicConNegPair.second, atomicConceptClass, &created); |
| 13476 |
if (created) { |
| 13477 |
if (atomicConceptItem != topConceptItem) { |
| 13478 |
topConceptItem->getSubComplexConceptItemSet()->insert(atomicConceptItem); |
| 13479 |
atomicConceptItem->getSuperComplexConceptItemSet()->insert(topConceptItem); |
| 13480 |
} |
| 13481 |
} |
| 13482 |
if (atomicConceptItem && atomicConceptItem != conceptItem) { |
| 13483 |
testingConceptItemList.append(atomicConceptItem); |
| 13484 |
} |
| 13485 |
} |
| 13486 |
reorderConceptClassItems(); |
| 13487 |
|
| 13488 |
//TODO: sorting super concept list??, remove indirect super concepts |
| 13489 |
QSet<COptimizedComplexConceptItem*>* superConceptItemSet = conceptItem->getSuperComplexConceptItemSet(); |
| 13490 |
QSet<COptimizedComplexConceptItem*>* subConceptItemSet = conceptItem->getSubComplexConceptItemSet(); |
| 13491 |
|
| 13492 |
if (testingConceptItemList.isEmpty()) { |
| 13493 |
testingConceptItemList.append(mOntoAnsweringItem->getTopConceptItem()); |
| 13494 |
} |
| 13495 |
|
| 13496 |
QList<TConceptItemPredecessorSet> testingConceptItemPredSetList; |
| 13497 |
while (!testingConceptItemList.isEmpty()) { |
| 13498 |
COptimizedComplexConceptItem* superConceptItem = testingConceptItemList.takeFirst(); |
| 13499 |
testingConceptItemPredSetList.append(TConceptItemPredecessorSet(superConceptItem, collectComplexConceptItemPredecessors(superConceptItem))); |
| 13500 |
} |
| 13501 |
qSort(testingConceptItemPredSetList.begin(), testingConceptItemPredSetList.end(), itemSortMorePredecessorsThan); |
| 13502 |
|
| 13503 |
QSet<COptimizedComplexConceptItem*>* commonPredItemSet = nullptr; |
| 13504 |
while (!testingConceptItemPredSetList.isEmpty()) { |
| 13505 |
TConceptItemPredecessorSet conceptItemPredecessorSet = testingConceptItemPredSetList.takeFirst(); |
| 13506 |
if (!commonPredItemSet) { |
| 13507 |
testingConceptItemList.append(conceptItemPredecessorSet.first); |
| 13508 |
commonPredItemSet = conceptItemPredecessorSet.second; |
| 13509 |
} else { |
| 13510 |
if (!commonPredItemSet->contains(conceptItemPredecessorSet.first)) { |
| 13511 |
testingConceptItemList.append(conceptItemPredecessorSet.first); |
| 13512 |
collectComplexConceptItemPredecessors(conceptItemPredecessorSet.first, commonPredItemSet); |
| 13513 |
delete conceptItemPredecessorSet.second; |
| 13514 |
} |
| 13515 |
} |
| 13516 |
} |
| 13517 |
delete commonPredItemSet; |
| 13518 |
|
| 13519 |
while (!testingConceptItemList.isEmpty()) { |
| 13520 |
COptimizedComplexConceptItem* superConceptItem = testingConceptItemList.takeFirst(); |
| 13521 |
bool foundSubsumption = false; |
| 13522 |
if (topConceptItem != superConceptItem) { |
| 13523 |
for (COptimizedComplexConceptItem* testingConceptItem : *superConceptItem->getSubComplexConceptItemSet()) { |
| 13524 |
if (isTriviallySubsumedConceptItem(conceptItem, testingConceptItem)) { |
| 13525 |
testingConceptItemList.append(testingConceptItem); |
| 13526 |
foundSubsumption = true; |
| 13527 |
} |
| 13528 |
} |
| 13529 |
if (!foundSubsumption) { |
| 13530 |
superConceptItemSet->insert(superConceptItem); |
| 13531 |
} |
| 13532 |
} |
| 13533 |
} |
| 13534 |
|
| 13535 |
for (auto superConceptItem : *superConceptItemSet) { |
| 13536 |
//TODO: handle equivalence, merge with other items |
| 13537 |
for (auto childSuperConceptItem : *superConceptItem->getSubComplexConceptItemSet()) { |
| 13538 |
if (isTriviallySubsumedConceptItem(childSuperConceptItem, conceptItem)) { |
| 13539 |
testingConceptItemList.append(superConceptItem); |
| 13540 |
} |
| 13541 |
} |
| 13542 |
} |
| 13543 |
|
| 13544 |
while (!testingConceptItemList.isEmpty()) { |
| 13545 |
COptimizedComplexConceptItem* subConceptItem = testingConceptItemList.takeFirst(); |
| 13546 |
bool foundSubsumption = false; |
| 13547 |
for (COptimizedComplexConceptItem* testingConceptItem : *subConceptItem->getSubComplexConceptItemSet()) { |
| 13548 |
if (isTriviallySubsumedConceptItem(testingConceptItem, conceptItem)) { |
| 13549 |
testingConceptItemList.append(testingConceptItem); |
| 13550 |
foundSubsumption = true; |
| 13551 |
} |
| 13552 |
} |
| 13553 |
if (!foundSubsumption) { |
| 13554 |
if (subConceptItem != conceptItem) { |
| 13555 |
subConceptItemSet->insert(subConceptItem); |
| 13556 |
} |
| 13557 |
} |
| 13558 |
} |
| 13559 |
|
| 13560 |
for (COptimizedComplexConceptItem* subConceptItem : *conceptItem->getSubComplexConceptItemSet()) { |
| 13561 |
if (subConceptItem != conceptItem) { |
| 13562 |
subConceptItem->getSuperComplexConceptItemSet()->insert(conceptItem); |
| 13563 |
for (COptimizedComplexConceptItem* superConceptItem : *conceptItem->getSuperComplexConceptItemSet()) { |
| 13564 |
if (subConceptItem->hasSuperComplexConceptItem(superConceptItem)) { |
| 13565 |
subConceptItem->getSuperComplexConceptItemSet()->remove(superConceptItem); |
| 13566 |
superConceptItem->getSuperComplexConceptItemSet()->remove(subConceptItem); |
| 13567 |
} |
| 13568 |
} |
| 13569 |
} |
| 13570 |
} |
| 13571 |
for (COptimizedComplexConceptItem* superConceptItem : *conceptItem->getSuperComplexConceptItemSet()) { |
| 13572 |
superConceptItem->getSubComplexConceptItemSet()->insert(conceptItem); |
| 13573 |
} |
| 13574 |
|
| 13575 |
return true; |
| 13576 |
} |
| 13577 |
|
| 13578 |
|
| 13579 |
|
| 13580 |
bool COptimizedComplexExpressionAnsweringHandler::isAnsweringFinished(CAnswererContext* answererContext) { |
| 13581 |
return !mOntoAnsweringItem->hasCurrentlyAnsweringQueries(); |
| 13582 |
} |
| 13583 |
|
| 13584 |
|
| 13585 |
|
| 13586 |
|
| 13587 |
|
| 13588 |
CAnsweringProgress* COptimizedComplexExpressionAnsweringHandler::getAnsweringProgress() { |
| 13589 |
|
| 13590 |
|
| 13591 |
if (mTotalPossibleInstancesCount != mTestedPossibleInstancesCount) { |
| 13592 |
cint64 tested = mTestedPossibleInstancesCount; |
| 13593 |
cint64 total = mTotalPossibleInstancesCount; |
| 13594 |
cint64 elapsedTime = mAnsweringStartTime.elapsed(); |
| 13595 |
double remainingMilliSeconds = 0.; |
| 13596 |
double progessPercent = 0.; |
| 13597 |
if (elapsedTime <= 0 && total > 0) { |
| 13598 |
remainingMilliSeconds = 0.; |
| 13599 |
} else { |
| 13600 |
remainingMilliSeconds = ((double)elapsedTime / (double)tested) * (total - tested); |
| 13601 |
} |
| 13602 |
if (total <= 0) { |
| 13603 |
progessPercent = 0.; |
| 13604 |
} else { |
| 13605 |
progessPercent = ((double)tested / (double)total) * 100.; |
| 13606 |
} |
| 13607 |
mAnsweringProgress.setProgessPercent(progessPercent); |
| 13608 |
mAnsweringProgress.setRemainingMilliSeconds(remainingMilliSeconds); |
| 13609 |
mAnsweringProgress.setTestedInstances(tested); |
| 13610 |
mAnsweringProgress.setTotalInstances(total); |
| 13611 |
} else { |
| 13612 |
mAnsweringProgress.setProgessPercent(0.); |
| 13613 |
mAnsweringProgress.setRemainingMilliSeconds(0.); |
| 13614 |
mAnsweringProgress.setTestedInstances(mTestedPossibleInstancesCount); |
| 13615 |
mAnsweringProgress.setTotalInstances(mTotalPossibleInstancesCount); |
| 13616 |
} |
| 13617 |
return &mAnsweringProgress; |
| 13618 |
} |
| 13619 |
|
| 13620 |
|
| 13621 |
|
| 13622 |
CAnsweringHandler* COptimizedComplexExpressionAnsweringHandler::storeAnsweringStatistics() { |
| 13623 |
CAnsweringStatisticsCollectionStrings* stats = new CAnsweringStatisticsCollectionStrings(); |
| 13624 |
addAnsweringStatistics(stats, false); |
| 13625 |
mOntoAnsweringItem->setDifferenceStoredAnsweringStatisticsCollectionStrings(stats); |
| 13626 |
return this; |
| 13627 |
} |
| 13628 |
|
| 13629 |
|
| 13630 |
CAnsweringHandler* COptimizedComplexExpressionAnsweringHandler::addAnsweringStatistics(CAnsweringStatistics* stats, bool lastStoredDiff) { |
| 13631 |
CAnsweringCalculationStatisticsCollectionStrings* calcStatsColl = mOntoAnsweringItem->getAnsweringStatisticsCollectionStrings(); |
| 13632 |
CAnsweringStatisticsCollectionStrings* diffStats = mOntoAnsweringItem->getDifferenceStoredAnsweringStatisticsCollectionStrings(); |
| 13633 |
if (calcStatsColl) { |
| 13634 |
for (const QString& statName : calcStatsColl->getStatisticsNameStringList()) { |
| 13635 |
cint64 value = calcStatsColl->getStatisticIntegerValue(statName); |
| 13636 |
if (lastStoredDiff && diffStats) { |
| 13637 |
value = value - diffStats->getStatisticIntegerValue(statName); |
| 13638 |
} |
| 13639 |
stats->addProcessingStatistics(statName, value); |
| 13640 |
} |
| 13641 |
} |
| 13642 |
|
| 13643 |
CAnsweringStatistics* tmpStats = stats; |
| 13644 |
if (lastStoredDiff && diffStats) { |
| 13645 |
tmpStats = new CAnsweringStatisticsCollectionStrings(); |
| 13646 |
} |
| 13647 |
CAnsweringHandlingStatistics* handlingStats = mOntoAnsweringItem->getAnsweringHandlingStatistics(); |
| 13648 |
if (handlingStats) { |
| 13649 |
stats->addProcessingStatistics("answering-processed-query-count", handlingStats->getTotalAnsweredQueriesCount()); |
| 13650 |
stats->addProcessingStatistics("answering-existential-query-part-absorption-count", handlingStats->getExistentialQueryPartAbsorptionCount()); |
| 13651 |
stats->addProcessingStatistics("answering-complex-concept-item-creation-count", handlingStats->getCreatedComplexConceptItemsCount()); |
| 13652 |
stats->addProcessingStatistics("answering-requested-realization-requirements-count", handlingStats->getRequestedRealizationRequirementCount()); |
| 13653 |
stats->addProcessingStatistics("answering-complex-concept-item-candidate-propagation-count", handlingStats->getComplexConceptItemsCandidatePropagationCount()); |
| 13654 |
stats->addProcessingStatistics("answering-complex-concept-item-sub-class-subsumption-count", handlingStats->getComplexConceptItemsSubClassSubsumptionTestingCount()); |
| 13655 |
stats->addProcessingStatistics("answering-complex-concept-item-super-class-subsumption-count", handlingStats->getComplexConceptItemsSuperClassSubsumptionTestingCount()); |
| 13656 |
stats->addProcessingStatistics("answering-existential-query-part-entailment-testing-count", handlingStats->getExistentialQueryPartEntailmentTestingCount()); |
| 13657 |
stats->addProcessingStatistics("answering-existential-query-part-variable-binding-propagation-count", handlingStats->getExistentialQueryPartVariableBindingPropagationCount()); |
| 13658 |
stats->addProcessingStatistics("answering-existential-query-part-variable-binding-confirmation-count", handlingStats->getExistentialQueryPartVariableBindingConfirmationCount()); |
| 13659 |
stats->addProcessingStatistics("answering-complex-concept-assertion-entailment-testing-count", handlingStats->getComplexConceptAssertionEntailmentTestingCount()); |
| 13660 |
} |
| 13661 |
if (lastStoredDiff && diffStats) { |
| 13662 |
for (const QString& statName : tmpStats->getStatisticsNameStringList()) { |
| 13663 |
cint64 value = tmpStats->getStatisticIntegerValue(statName); |
| 13664 |
value = value - diffStats->getStatisticIntegerValue(statName); |
| 13665 |
stats->addProcessingStatistics(statName, value); |
| 13666 |
} |
| 13667 |
} |
| 13668 |
|
| 13669 |
return this; |
| 13670 |
} |
| 13671 |
|
| 13672 |
|
| 13673 |
|
| 13674 |
|
| 13675 |
|
| 13676 |
|
| 13677 |
|
| 13678 |
|
| 13679 |
|
| 13680 |
|
| 13681 |
|
| 13682 |
|
| 13683 |
|
| 13684 |
|
| 13685 |
|
| 13686 |
|
| 13687 |
|
| 13688 |
|
| 13689 |
|
| 13690 |
|
| 13691 |
|
| 13692 |
|
| 13693 |
|
| 13694 |
|
| 13695 |
|
| 13696 |
|
| 13697 |
|
| 13698 |
bool COptimizedComplexExpressionAnsweringHandler::finishVariableCompositionItemComputation(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableCompositionItem* varCompItem, bool allMappingsComputed) { |
| 13699 |
if (allMappingsComputed) { |
| 13700 |
varCompItem->setVariableMappingsComputed(true); |
| 13701 |
} |
| 13702 |
if (varCompItem->getVariableMapping()->getBindingCount() <= 0) { |
| 13703 |
buildingVarItem->setSatisfiability(false); |
| 13704 |
} |
| 13705 |
if (mConfDebugWriteVariableCompositionItems) { |
| 13706 |
debugWriteVariableMappingToFileWithHeader(buildingVarItem, varCompItem); |
| 13707 |
|
| 13708 |
//if (varCompItem->getComputationStepId() >= 5) { |
| 13709 |
// debugCheckVariableMappingFromFile(buildingVarItem, varCompItem); |
| 13710 |
//} |
| 13711 |
//debugWriteVariableMappingToFile(buildingVarItem, varCompItem); |
| 13712 |
} |
| 13713 |
QList<COptimizedComplexVariableCompositionItemUpdateData>* updateList = varCompItem->getComputationUpdateItemList(); |
| 13714 |
for (COptimizedComplexVariableCompositionItemUpdateData updateData : *updateList) { |
| 13715 |
COptimizedComplexVariableCompositionItem* updateItem = updateData.getVariableCompositionItem(); |
| 13716 |
COptimizedComplexBuildingVariableCompositionsItem* rescheduleBuildingVarItem = updateData.getVariableBuildingItem(); |
| 13717 |
if (!rescheduleBuildingVarItem) { |
| 13718 |
rescheduleBuildingVarItem = buildingVarItem; |
| 13719 |
} |
| 13720 |
updateItem->decDependencyUpdatingCount(); |
| 13721 |
if (updateItem->getDependencyUpdatingCount() == 0) { |
| 13722 |
queueVariableItemComputation(rescheduleBuildingVarItem, updateItem); |
| 13723 |
if (updateData.getVariableBuildingItem()) { |
| 13724 |
rescheduleBuildingVarItem->decWaitingSubVariableBuildingItemCount(); |
| 13725 |
if (rescheduleBuildingVarItem->getWaitingSubVariableBuildingItemCount() == 0) { |
| 13726 |
if (!rescheduleBuildingVarItem->isProcessingQueued()) { |
| 13727 |
rescheduleBuildingVarItem->setProcessingQueued(true); |
| 13728 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(rescheduleBuildingVarItem); |
| 13729 |
} |
| 13730 |
} |
| 13731 |
} |
| 13732 |
} |
| 13733 |
} |
| 13734 |
updateList->clear(); |
| 13735 |
return true; |
| 13736 |
} |
| 13737 |
|
| 13738 |
|
| 13739 |
|
| 13740 |
|
| 13741 |
|
| 13742 |
|
| 13743 |
bool COptimizedComplexExpressionAnsweringHandler::rescheduleVariableCompositionItemComputation(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableCompositionItem* varCompItem, COptimizedComplexVariableCompositionItem* depSchedulingCompItem, cint64 additionalRequiredMappingCount, COptimizedComplexBuildingVariableCompositionsItem* rescheduleBuildingVarItem) { |
| 13744 |
if (!depSchedulingCompItem->isVariableMappingsComputed()) { |
| 13745 |
if (additionalRequiredMappingCount != -1) { |
| 13746 |
depSchedulingCompItem->setVariableMappingsComputationRequirement(qMax(depSchedulingCompItem->getVariableMappingsComputationRequirement(), additionalRequiredMappingCount)); |
| 13747 |
} else { |
| 13748 |
depSchedulingCompItem->setVariableMappingsComputationRequirement(-1); |
| 13749 |
} |
| 13750 |
depSchedulingCompItem->addComputationUpdateItem(varCompItem, rescheduleBuildingVarItem); |
| 13751 |
if (rescheduleBuildingVarItem && rescheduleBuildingVarItem != buildingVarItem) { |
| 13752 |
if (!buildingVarItem->isProcessingQueued()) { |
| 13753 |
buildingVarItem->setProcessingQueued(true); |
| 13754 |
mOntoAnsweringItem->addProcessingVariableBuildingItem(buildingVarItem); |
| 13755 |
if (buildingVarItem->getQueryProcessingData()) { |
| 13756 |
buildingVarItem->getQueryProcessingData()->incBuildingVariableItem(); |
| 13757 |
} |
| 13758 |
} |
| 13759 |
rescheduleBuildingVarItem->incWaitingSubVariableBuildingItemCount(); |
| 13760 |
} |
| 13761 |
varCompItem->incDependencyUpdatingCount(); |
| 13762 |
queueVariableItemComputation(buildingVarItem, depSchedulingCompItem); |
| 13763 |
return true; |
| 13764 |
} |
| 13765 |
return false; |
| 13766 |
} |
| 13767 |
|
| 13768 |
|
| 13769 |
bool COptimizedComplexExpressionAnsweringHandler::expectedUpdatedReschedulingDependentItemComputation(COptimizedComplexVariableCompositionItemDependence* baseItemDep, COptimizedComplexVariableIndividualMappings* reducedVarMapping, COptimizedComplexVariableCompositionItem* reductionItem, COptimizedComplexVariableCompositionItem* baseItem, COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, COptimizedComplexBuildingVariableCompositionsItem* rescheduleBuildingVarItem) { |
| 13770 |
bool dependentItemRescheduled = false; |
| 13771 |
cint64 totalProcessedMappingsCount = baseItemDep->getTotalProcessedBindingsCardinalityLinkerCount(); |
| 13772 |
cint64 resultingMappingsCount = reducedVarMapping->getBindingCount(); |
| 13773 |
cint64 requiredMappingCount = reductionItem->getVariableMappingsComputationRequirement(); |
| 13774 |
cint64 remaingRequiredMappingCount = requiredMappingCount; |
| 13775 |
double depItemToThisMappingChangeFactor = (double)resultingMappingsCount / (double)totalProcessedMappingsCount; |
| 13776 |
double depAdditionalRequiredMappingCount = depItemToThisMappingChangeFactor * (double)remaingRequiredMappingCount; |
| 13777 |
|
| 13778 |
// determine expected count |
| 13779 |
double expectedCount = depItemToThisMappingChangeFactor * baseItem->getVariableMappingsExpectedCount(); |
| 13780 |
compVarItem->setVariableMappingsExpectedCount(expectedCount); |
| 13781 |
|
| 13782 |
if (reductionItem->requiresMoreVariableMappingsComputation()) { |
| 13783 |
depAdditionalRequiredMappingCount = qMax(depAdditionalRequiredMappingCount + 1., totalProcessedMappingsCount + 1.); |
| 13784 |
|
| 13785 |
depAdditionalRequiredMappingCount = depAdditionalRequiredMappingCount * compVarItem->repeatedRequirementInsufficientDependencyComputationIncreaseFactor(); |
| 13786 |
|
| 13787 |
if (requiredMappingCount == -1 || mConfMappingsComputationUnlimitedInterpretationSize >= 0 && depAdditionalRequiredMappingCount >= mConfMappingsComputationUnlimitedInterpretationSize) { |
| 13788 |
depAdditionalRequiredMappingCount = -1; |
| 13789 |
} |
| 13790 |
|
| 13791 |
if (!baseItemDep->hasMappingsCountComputationRequested(depAdditionalRequiredMappingCount)) { |
| 13792 |
baseItemDep->setLastRequestedMappingsComputationCount(depAdditionalRequiredMappingCount); |
| 13793 |
dependentItemRescheduled = rescheduleVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItem, depAdditionalRequiredMappingCount, rescheduleBuildingVarItem); |
| 13794 |
if (dependentItemRescheduled && mConfExtendedLogging) { |
| 13795 |
LOG(INFO, getDomain(), logTr("Computation step %1 (attempt %2): Requesting %3 mappings from step %4.").arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt(false)).arg(depAdditionalRequiredMappingCount).arg(baseItem->getComputationStepId()), this); |
| 13796 |
} |
| 13797 |
} |
| 13798 |
} |
| 13799 |
return dependentItemRescheduled; |
| 13800 |
} |
| 13801 |
|
| 13802 |
|
| 13803 |
|
| 13804 |
|
| 13805 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemFromRoleSubSuperProperties(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 13806 |
COptimizedComplexVariableRoleSubSuperItem* roleSubSuperItem = (COptimizedComplexVariableRoleSubSuperItem*)compVarItem; |
| 13807 |
CRole* role = roleSubSuperItem->getRole(); |
| 13808 |
bool superProperties = roleSubSuperItem->isRoleSuperProperties(); |
| 13809 |
COptimizedComplexVariableIndividualMappings* variableMapping = roleSubSuperItem->getVariableMapping(); |
| 13810 |
|
| 13811 |
CRolePropertiesHierarchy* roleHierarchy = nullptr; |
| 13812 |
if (!role->isDataRole()) { |
| 13813 |
roleHierarchy = mOntoAnsweringItem->getOntology()->getClassification()->getPropertyRoleClassification()->getRolePropertiesHierarchy(); |
| 13814 |
} else { |
| 13815 |
roleHierarchy = mOntoAnsweringItem->getOntology()->getClassification()->getDataPropertyRoleClassification()->getRolePropertiesHierarchy(); |
| 13816 |
} |
| 13817 |
|
| 13818 |
QSet<CRolePropertiesHierarchyNode*> processedNodeSet; |
| 13819 |
QList<CRolePropertiesHierarchyNode*> processingNodeList; |
| 13820 |
CRolePropertiesHierarchyNode* hierNode = roleHierarchy->getHierarchyNode(role); |
| 13821 |
if (hierNode) { |
| 13822 |
processingNodeList.append(hierNode); |
| 13823 |
processedNodeSet.insert(hierNode); |
| 13824 |
} |
| 13825 |
|
| 13826 |
bool mappingProcessed = true; |
| 13827 |
COptimizedComplexVariableIndividualBindings* binding = nullptr; |
| 13828 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 13829 |
|
| 13830 |
|
| 13831 |
while (!processingNodeList.isEmpty()) { |
| 13832 |
CRolePropertiesHierarchyNode* hierNode = processingNodeList.takeFirst(); |
| 13833 |
|
| 13834 |
if (!binding) { |
| 13835 |
binding = createBindingsForVariableCompositionItems(1, compVarItem, buildingVarItem); |
| 13836 |
} |
| 13837 |
binding->setBinding(0, hierNode); |
| 13838 |
if (!linker) { |
| 13839 |
linker = createBindingsLinkerForVariableCompositionItems(binding, nullptr, compVarItem, buildingVarItem); |
| 13840 |
} |
| 13841 |
if (variableMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 13842 |
binding = nullptr; |
| 13843 |
linker = nullptr; |
| 13844 |
} |
| 13845 |
|
| 13846 |
QSet<CRolePropertiesHierarchyNode*>* nextNodeSet = nullptr; |
| 13847 |
if (superProperties) { |
| 13848 |
nextNodeSet = hierNode->getParentNodeSet(); |
| 13849 |
} else { |
| 13850 |
nextNodeSet = hierNode->getChildNodeSet(); |
| 13851 |
} |
| 13852 |
for (CRolePropertiesHierarchyNode* nextHierNode : *nextNodeSet) { |
| 13853 |
if (!processedNodeSet.contains(nextHierNode)) { |
| 13854 |
processingNodeList.append(nextHierNode); |
| 13855 |
processedNodeSet.insert(nextHierNode); |
| 13856 |
} |
| 13857 |
} |
| 13858 |
|
| 13859 |
} |
| 13860 |
|
| 13861 |
|
| 13862 |
variableMapping->incCurrentUpdateId(); |
| 13863 |
roleSubSuperItem->setVariableMappingsExpectedCount(roleSubSuperItem->getVariableMappingsCurrentCount()); |
| 13864 |
|
| 13865 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, true); |
| 13866 |
} |
| 13867 |
|
| 13868 |
|
| 13869 |
|
| 13870 |
|
| 13871 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemFromConceptItemSubSuperCLasses(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 13872 |
COptimizedComplexVariableConceptSubSuperItem* conceptSubSuperItem = (COptimizedComplexVariableConceptSubSuperItem*)compVarItem; |
| 13873 |
COptimizedComplexConceptItem* conItem = conceptSubSuperItem->getConceptItem(); |
| 13874 |
bool superClasses = conceptSubSuperItem->isConceptItemSuperClasses(); |
| 13875 |
COptimizedComplexVariableIndividualMappings* variableMapping = conceptSubSuperItem->getVariableMapping(); |
| 13876 |
|
| 13877 |
bool mappingProcessed = true; |
| 13878 |
COptimizedComplexVariableIndividualBindings* binding = nullptr; |
| 13879 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 13880 |
|
| 13881 |
|
| 13882 |
QSet<CHierarchyNode*>* hierNodeSet = nullptr; |
| 13883 |
if (superClasses) { |
| 13884 |
hierNodeSet = conItem->getDirectSuperClassNodeSet(); |
| 13885 |
} else { |
| 13886 |
hierNodeSet = conItem->getDirectSubClassNodeSet(); |
| 13887 |
} |
| 13888 |
|
| 13889 |
QSet<CHierarchyNode*> processedNodeSet; |
| 13890 |
QList<CHierarchyNode*> processingNodeList; |
| 13891 |
for (CHierarchyNode* hierNode : *hierNodeSet) { |
| 13892 |
processingNodeList.append(hierNode); |
| 13893 |
processedNodeSet.insert(hierNode); |
| 13894 |
} |
| 13895 |
|
| 13896 |
while (!processingNodeList.isEmpty()) { |
| 13897 |
CHierarchyNode* hierNode = processingNodeList.takeFirst(); |
| 13898 |
|
| 13899 |
if (!binding) { |
| 13900 |
binding = createBindingsForVariableCompositionItems(1, compVarItem, buildingVarItem); |
| 13901 |
} |
| 13902 |
binding->setBinding(0, hierNode); |
| 13903 |
if (!linker) { |
| 13904 |
linker = createBindingsLinkerForVariableCompositionItems(binding, nullptr, compVarItem, buildingVarItem); |
| 13905 |
} |
| 13906 |
if (variableMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 13907 |
binding = nullptr; |
| 13908 |
linker = nullptr; |
| 13909 |
} |
| 13910 |
|
| 13911 |
QSet<CHierarchyNode*>* nextNodeSet = nullptr; |
| 13912 |
if (superClasses) { |
| 13913 |
nextNodeSet = hierNode->getParentNodeSet(); |
| 13914 |
} else { |
| 13915 |
nextNodeSet = hierNode->getChildNodeSet(); |
| 13916 |
} |
| 13917 |
for (CHierarchyNode* nextHierNode : *nextNodeSet) { |
| 13918 |
if (!processedNodeSet.contains(nextHierNode)) { |
| 13919 |
processingNodeList.append(nextHierNode); |
| 13920 |
processedNodeSet.insert(nextHierNode); |
| 13921 |
} |
| 13922 |
} |
| 13923 |
|
| 13924 |
} |
| 13925 |
|
| 13926 |
|
| 13927 |
variableMapping->incCurrentUpdateId(); |
| 13928 |
conceptSubSuperItem->setVariableMappingsExpectedCount(conceptSubSuperItem->getVariableMappingsCurrentCount()); |
| 13929 |
|
| 13930 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, true); |
| 13931 |
} |
| 13932 |
|
| 13933 |
|
| 13934 |
|
| 13935 |
|
| 13936 |
|
| 13937 |
|
| 13938 |
|
| 13939 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemSubSuperClassesPropagation(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 13940 |
COptimizedComplexVariableSubSuperClassesPropagationItem* conceptSubSuperClassesPropItem = (COptimizedComplexVariableSubSuperClassesPropagationItem*)compVarItem; |
| 13941 |
bool superClasses = conceptSubSuperClassesPropItem->isSuperClassesPropagation(); |
| 13942 |
COptimizedComplexVariableIndividualMappings* variableMapping = conceptSubSuperClassesPropItem->getVariableMapping(); |
| 13943 |
|
| 13944 |
|
| 13945 |
COptimizedComplexVariableCompositionItem* baseItem = conceptSubSuperClassesPropItem->getBaseItem(); |
| 13946 |
COptimizedComplexVariableCompositionItemDependence* baseItemDep = conceptSubSuperClassesPropItem->getBaseItemDependence(); |
| 13947 |
COptimizedComplexVariableIndividualMappings* baseVarMapping = baseItem->getVariableMapping(); |
| 13948 |
COptimizedComplexVariableIndividualMappings* propVarMapping = conceptSubSuperClassesPropItem->getVariableMapping(); |
| 13949 |
|
| 13950 |
cint64 baseSize = baseVarMapping->getBindingSize(); |
| 13951 |
cint64 propSize = baseSize + 1; |
| 13952 |
cint64 newVarIdx = baseSize; |
| 13953 |
cint64 propVarIdx = conceptSubSuperClassesPropItem->getVariableIndex(); |
| 13954 |
|
| 13955 |
COptimizedComplexVariableIndividualBindings* propagatedBindings = nullptr; |
| 13956 |
COptimizedComplexVariableIndividualBindingsCardinality* propagatedCardinalites = nullptr; |
| 13957 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 13958 |
|
| 13959 |
|
| 13960 |
if (baseVarMapping->getBindingCount() <= 0) { |
| 13961 |
if (rescheduleVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItem, 1)) { |
| 13962 |
return; |
| 13963 |
} |
| 13964 |
} |
| 13965 |
|
| 13966 |
COptimizedComplexVariableIndividualMappings::VARIABLE_TYPE redVarMapType = baseVarMapping->getBindingMapping(propVarIdx); |
| 13967 |
|
| 13968 |
function<void(COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites)> propHandlingFunc = [&](COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites) { |
| 13969 |
TIndividualInstanceItemDataBinding& propBinding = bindings->getBinding(propVarIdx); |
| 13970 |
CHierarchyNode* baseHierNode = propBinding.classHierNode; |
| 13971 |
|
| 13972 |
QSet<CHierarchyNode*>* hierNodeSet = nullptr; |
| 13973 |
if (superClasses) { |
| 13974 |
hierNodeSet = baseHierNode->getParentNodeSet(); |
| 13975 |
} else { |
| 13976 |
hierNodeSet = baseHierNode->getChildNodeSet(); |
| 13977 |
} |
| 13978 |
|
| 13979 |
QSet<CHierarchyNode*> processedNodeSet; |
| 13980 |
QList<CHierarchyNode*> processingNodeList; |
| 13981 |
for (CHierarchyNode* hierNode : *hierNodeSet) { |
| 13982 |
processingNodeList.append(hierNode); |
| 13983 |
processedNodeSet.insert(hierNode); |
| 13984 |
} |
| 13985 |
processingNodeList.append(baseHierNode); |
| 13986 |
processedNodeSet.insert(baseHierNode); |
| 13987 |
|
| 13988 |
while (!processingNodeList.isEmpty()) { |
| 13989 |
CHierarchyNode* hierNode = processingNodeList.takeFirst(); |
| 13990 |
|
| 13991 |
if (!propagatedBindings) { |
| 13992 |
propagatedBindings = createBindingsForVariableCompositionItems(propSize, compVarItem, buildingVarItem); |
| 13993 |
} |
| 13994 |
if (!propagatedCardinalites) { |
| 13995 |
propagatedCardinalites = createBindingsCardinalitesForVariableCompositionItems(compVarItem, buildingVarItem); |
| 13996 |
} |
| 13997 |
if (propagatedCardinalites) { |
| 13998 |
if (cardinalites) { |
| 13999 |
*propagatedCardinalites = *cardinalites; |
| 14000 |
} else { |
| 14001 |
propagatedCardinalites->initCardinalities(1, 1); |
| 14002 |
} |
| 14003 |
propagatedCardinalites->setCardinalityUpdateId(-1); |
| 14004 |
} |
| 14005 |
|
| 14006 |
cint64 nextIdx = 0; |
| 14007 |
for (cint64 i = 0; i < baseSize; ++i) { |
| 14008 |
propagatedBindings->setBinding(nextIdx++, bindings->getBinding(i)); |
| 14009 |
} |
| 14010 |
propagatedBindings->setBinding(newVarIdx, hierNode); |
| 14011 |
|
| 14012 |
if (!linker) { |
| 14013 |
linker = createBindingsLinkerForVariableCompositionItems(propagatedBindings, nullptr, compVarItem, buildingVarItem); |
| 14014 |
} else { |
| 14015 |
linker->setInitialCardinality(propagatedCardinalites); |
| 14016 |
} |
| 14017 |
if (variableMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 14018 |
propagatedBindings = nullptr; |
| 14019 |
propagatedCardinalites = nullptr; |
| 14020 |
linker = nullptr; |
| 14021 |
} else { |
| 14022 |
propagatedCardinalites = linker->getCurrentCardinalities(); |
| 14023 |
} |
| 14024 |
|
| 14025 |
QSet<CHierarchyNode*>* nextNodeSet = nullptr; |
| 14026 |
if (superClasses) { |
| 14027 |
nextNodeSet = hierNode->getParentNodeSet(); |
| 14028 |
} else { |
| 14029 |
nextNodeSet = hierNode->getChildNodeSet(); |
| 14030 |
} |
| 14031 |
for (CHierarchyNode* nextHierNode : *nextNodeSet) { |
| 14032 |
if (!processedNodeSet.contains(nextHierNode)) { |
| 14033 |
processingNodeList.append(nextHierNode); |
| 14034 |
processedNodeSet.insert(nextHierNode); |
| 14035 |
} |
| 14036 |
} |
| 14037 |
|
| 14038 |
} |
| 14039 |
|
| 14040 |
}; |
| 14041 |
|
| 14042 |
|
| 14043 |
|
| 14044 |
bool mappingProcessed = false; |
| 14045 |
while (conceptSubSuperClassesPropItem->requiresMoreVariableMappingsComputation() && (!baseItemDep->isBatchProcessed() || baseItemDep->loadNextBatch())) { |
| 14046 |
|
| 14047 |
while (conceptSubSuperClassesPropItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentBindingsCardinalityLinker(false)) { |
| 14048 |
mappingProcessed = true; |
| 14049 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = baseItemDep->getBatchCurrentBindingsCardinalityLinker(true); |
| 14050 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14051 |
COptimizedComplexVariableIndividualBindingsCardinality* cardinalites = bindingLinker->getInitialCardinalities(); |
| 14052 |
|
| 14053 |
propHandlingFunc(bindings, cardinalites); |
| 14054 |
} |
| 14055 |
|
| 14056 |
|
| 14057 |
while (conceptSubSuperClassesPropItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentUpdatedCardinalityLinker(false)) { |
| 14058 |
mappingProcessed = true; |
| 14059 |
COptimizedComplexVariableIndividualUpdateCardinalityLinker* updatedCardinalityLinker = baseItemDep->getBatchCurrentUpdatedCardinalityLinker(true); |
| 14060 |
COptimizedComplexVariableIndividualBindingsCardinality* prevCardinalites = updatedCardinalityLinker->getPreviousCardinality(); |
| 14061 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = updatedCardinalityLinker->getUpdatedBindingsCardinalityLinker(); |
| 14062 |
COptimizedComplexVariableIndividualBindingsCardinality* newCardinalites = updatedCardinalityLinker->getNewCardinality(); |
| 14063 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14064 |
|
| 14065 |
COptimizedComplexVariableIndividualBindingsCardinality tmpDiffCardinalites = *newCardinalites; |
| 14066 |
tmpDiffCardinalites.substractCardinalities(prevCardinalites); |
| 14067 |
|
| 14068 |
propHandlingFunc(bindings, &tmpDiffCardinalites); |
| 14069 |
} |
| 14070 |
|
| 14071 |
} |
| 14072 |
|
| 14073 |
propVarMapping->incCurrentUpdateId(); |
| 14074 |
|
| 14075 |
bool dependentItemRescheduled = false; |
| 14076 |
dependentItemRescheduled = expectedUpdatedReschedulingDependentItemComputation(baseItemDep, propVarMapping, conceptSubSuperClassesPropItem, baseItem, compVarItem, buildingVarItem); |
| 14077 |
|
| 14078 |
if (!dependentItemRescheduled && compVarItem->getDependencyUpdatingCount() <= 0) { |
| 14079 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItemDep->isProcessingFinished()); |
| 14080 |
if (mConfExtendedLogging) { |
| 14081 |
LOG(INFO, getDomain(), logTr("Computation step %3 (attempt %4): Sub/Super classes propagation computation from %1 mappings of step %5 resulted in %2 mappings.").arg(baseVarMapping->getBindingCount()).arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()).arg(baseItem->getComputationStepId()), this); |
| 14082 |
} |
| 14083 |
} |
| 14084 |
|
| 14085 |
configureDependentComputationIncreaseFactor(dependentItemRescheduled, mappingProcessed, compVarItem); |
| 14086 |
|
| 14087 |
} |
| 14088 |
|
| 14089 |
|
| 14090 |
|
| 14091 |
|
| 14092 |
|
| 14093 |
|
| 14094 |
|
| 14095 |
|
| 14096 |
|
| 14097 |
|
| 14098 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemSubSuperPropertiesPropagation(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 14099 |
COptimizedComplexVariableSubSuperPropertiesPropagationItem* conceptSubSuperPropertiesPropItem = (COptimizedComplexVariableSubSuperPropertiesPropagationItem*)compVarItem; |
| 14100 |
bool superProperties = conceptSubSuperPropertiesPropItem->isSuperPropertiesPropagation(); |
| 14101 |
COptimizedComplexVariableIndividualMappings* variableMapping = conceptSubSuperPropertiesPropItem->getVariableMapping(); |
| 14102 |
|
| 14103 |
|
| 14104 |
COptimizedComplexVariableCompositionItem* baseItem = conceptSubSuperPropertiesPropItem->getBaseItem(); |
| 14105 |
COptimizedComplexVariableCompositionItemDependence* baseItemDep = conceptSubSuperPropertiesPropItem->getBaseItemDependence(); |
| 14106 |
COptimizedComplexVariableIndividualMappings* baseVarMapping = baseItem->getVariableMapping(); |
| 14107 |
COptimizedComplexVariableIndividualMappings* propVarMapping = conceptSubSuperPropertiesPropItem->getVariableMapping(); |
| 14108 |
|
| 14109 |
cint64 baseSize = baseVarMapping->getBindingSize(); |
| 14110 |
cint64 propSize = baseSize + 1; |
| 14111 |
cint64 newVarIdx = baseSize; |
| 14112 |
cint64 propVarIdx = conceptSubSuperPropertiesPropItem->getVariableIndex(); |
| 14113 |
|
| 14114 |
COptimizedComplexVariableIndividualBindings* propagatedBindings = nullptr; |
| 14115 |
COptimizedComplexVariableIndividualBindingsCardinality* propagatedCardinalites = nullptr; |
| 14116 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 14117 |
|
| 14118 |
|
| 14119 |
if (baseVarMapping->getBindingCount() <= 0) { |
| 14120 |
if (rescheduleVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItem, 1)) { |
| 14121 |
return; |
| 14122 |
} |
| 14123 |
} |
| 14124 |
|
| 14125 |
COptimizedComplexVariableIndividualMappings::VARIABLE_TYPE redVarMapType = baseVarMapping->getBindingMapping(propVarIdx); |
| 14126 |
|
| 14127 |
function<void(COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites)> propHandlingFunc = [&](COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites) { |
| 14128 |
TIndividualInstanceItemDataBinding& propBinding = bindings->getBinding(propVarIdx); |
| 14129 |
CRolePropertiesHierarchyNode* baseHierNode = propBinding.propertyHierNode; |
| 14130 |
|
| 14131 |
QSet<CRolePropertiesHierarchyNode*>* hierNodeSet = nullptr; |
| 14132 |
if (superProperties) { |
| 14133 |
hierNodeSet = baseHierNode->getParentNodeSet(); |
| 14134 |
} else { |
| 14135 |
hierNodeSet = baseHierNode->getChildNodeSet(); |
| 14136 |
} |
| 14137 |
|
| 14138 |
QSet<CRolePropertiesHierarchyNode*> processedNodeSet; |
| 14139 |
QList<CRolePropertiesHierarchyNode*> processingNodeList; |
| 14140 |
for (CRolePropertiesHierarchyNode* hierNode : *hierNodeSet) { |
| 14141 |
processingNodeList.append(hierNode); |
| 14142 |
processedNodeSet.insert(hierNode); |
| 14143 |
} |
| 14144 |
processingNodeList.append(baseHierNode); |
| 14145 |
processedNodeSet.insert(baseHierNode); |
| 14146 |
|
| 14147 |
while (!processingNodeList.isEmpty()) { |
| 14148 |
CRolePropertiesHierarchyNode* hierNode = processingNodeList.takeFirst(); |
| 14149 |
|
| 14150 |
if (!propagatedBindings) { |
| 14151 |
propagatedBindings = createBindingsForVariableCompositionItems(propSize, compVarItem, buildingVarItem); |
| 14152 |
} |
| 14153 |
if (!propagatedCardinalites) { |
| 14154 |
propagatedCardinalites = createBindingsCardinalitesForVariableCompositionItems(compVarItem, buildingVarItem); |
| 14155 |
} |
| 14156 |
if (propagatedCardinalites) { |
| 14157 |
if (cardinalites) { |
| 14158 |
*propagatedCardinalites = *cardinalites; |
| 14159 |
} else { |
| 14160 |
propagatedCardinalites->initCardinalities(1, 1); |
| 14161 |
} |
| 14162 |
propagatedCardinalites->setCardinalityUpdateId(-1); |
| 14163 |
} |
| 14164 |
|
| 14165 |
cint64 nextIdx = 0; |
| 14166 |
for (cint64 i = 0; i < baseSize; ++i) { |
| 14167 |
propagatedBindings->setBinding(nextIdx++, bindings->getBinding(i)); |
| 14168 |
} |
| 14169 |
propagatedBindings->setBinding(newVarIdx, hierNode); |
| 14170 |
|
| 14171 |
if (!linker) { |
| 14172 |
linker = createBindingsLinkerForVariableCompositionItems(propagatedBindings, nullptr, compVarItem, buildingVarItem); |
| 14173 |
} else { |
| 14174 |
linker->setInitialCardinality(propagatedCardinalites); |
| 14175 |
} |
| 14176 |
if (variableMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 14177 |
propagatedBindings = nullptr; |
| 14178 |
propagatedCardinalites = nullptr; |
| 14179 |
linker = nullptr; |
| 14180 |
} else { |
| 14181 |
propagatedCardinalites = linker->getCurrentCardinalities(); |
| 14182 |
} |
| 14183 |
|
| 14184 |
QSet<CRolePropertiesHierarchyNode*>* nextNodeSet = nullptr; |
| 14185 |
if (superProperties) { |
| 14186 |
nextNodeSet = hierNode->getParentNodeSet(); |
| 14187 |
} else { |
| 14188 |
nextNodeSet = hierNode->getChildNodeSet(); |
| 14189 |
} |
| 14190 |
for (CRolePropertiesHierarchyNode* nextHierNode : *nextNodeSet) { |
| 14191 |
if (!processedNodeSet.contains(nextHierNode)) { |
| 14192 |
processingNodeList.append(nextHierNode); |
| 14193 |
processedNodeSet.insert(nextHierNode); |
| 14194 |
} |
| 14195 |
} |
| 14196 |
|
| 14197 |
} |
| 14198 |
|
| 14199 |
}; |
| 14200 |
|
| 14201 |
|
| 14202 |
|
| 14203 |
bool mappingProcessed = false; |
| 14204 |
while (conceptSubSuperPropertiesPropItem->requiresMoreVariableMappingsComputation() && (!baseItemDep->isBatchProcessed() || baseItemDep->loadNextBatch())) { |
| 14205 |
|
| 14206 |
while (conceptSubSuperPropertiesPropItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentBindingsCardinalityLinker(false)) { |
| 14207 |
mappingProcessed = true; |
| 14208 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = baseItemDep->getBatchCurrentBindingsCardinalityLinker(true); |
| 14209 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14210 |
COptimizedComplexVariableIndividualBindingsCardinality* cardinalites = bindingLinker->getInitialCardinalities(); |
| 14211 |
|
| 14212 |
propHandlingFunc(bindings, cardinalites); |
| 14213 |
} |
| 14214 |
|
| 14215 |
|
| 14216 |
while (conceptSubSuperPropertiesPropItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentUpdatedCardinalityLinker(false)) { |
| 14217 |
mappingProcessed = true; |
| 14218 |
COptimizedComplexVariableIndividualUpdateCardinalityLinker* updatedCardinalityLinker = baseItemDep->getBatchCurrentUpdatedCardinalityLinker(true); |
| 14219 |
COptimizedComplexVariableIndividualBindingsCardinality* prevCardinalites = updatedCardinalityLinker->getPreviousCardinality(); |
| 14220 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = updatedCardinalityLinker->getUpdatedBindingsCardinalityLinker(); |
| 14221 |
COptimizedComplexVariableIndividualBindingsCardinality* newCardinalites = updatedCardinalityLinker->getNewCardinality(); |
| 14222 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14223 |
|
| 14224 |
COptimizedComplexVariableIndividualBindingsCardinality tmpDiffCardinalites = *newCardinalites; |
| 14225 |
tmpDiffCardinalites.substractCardinalities(prevCardinalites); |
| 14226 |
|
| 14227 |
propHandlingFunc(bindings, &tmpDiffCardinalites); |
| 14228 |
} |
| 14229 |
|
| 14230 |
} |
| 14231 |
|
| 14232 |
propVarMapping->incCurrentUpdateId(); |
| 14233 |
|
| 14234 |
bool dependentItemRescheduled = false; |
| 14235 |
dependentItemRescheduled = expectedUpdatedReschedulingDependentItemComputation(baseItemDep, propVarMapping, conceptSubSuperPropertiesPropItem, baseItem, compVarItem, buildingVarItem); |
| 14236 |
|
| 14237 |
if (!dependentItemRescheduled && compVarItem->getDependencyUpdatingCount() <= 0) { |
| 14238 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItemDep->isProcessingFinished()); |
| 14239 |
if (mConfExtendedLogging) { |
| 14240 |
LOG(INFO, getDomain(), logTr("Computation step %3 (attempt %4): Sub/Super properties propagation computation from %1 mappings of step %5 resulted in %2 mappings.").arg(baseVarMapping->getBindingCount()).arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()).arg(baseItem->getComputationStepId()), this); |
| 14241 |
} |
| 14242 |
} |
| 14243 |
|
| 14244 |
configureDependentComputationIncreaseFactor(dependentItemRescheduled, mappingProcessed, compVarItem); |
| 14245 |
|
| 14246 |
} |
| 14247 |
|
| 14248 |
|
| 14249 |
|
| 14250 |
|
| 14251 |
|
| 14252 |
|
| 14253 |
|
| 14254 |
|
| 14255 |
|
| 14256 |
|
| 14257 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemIndividualTypeExtension(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingIndividualMixedVariableCompositionsItem* buildingVarItem, bool& processing, bool& subBuildItemProcessing) { |
| 14258 |
COptimizedComplexVariableIndividualTypeExtensionItem* indiTypeExtItem = (COptimizedComplexVariableIndividualTypeExtensionItem*)compVarItem; |
| 14259 |
COptimizedComplexVariableIndividualMappings* variableMapping = indiTypeExtItem->getVariableMapping(); |
| 14260 |
|
| 14261 |
|
| 14262 |
CConceptRealization* conReal = mOntoAnsweringItem->getOntology()->getRealization()->getConceptRealization(); |
| 14263 |
|
| 14264 |
COptimizedComplexVariableCompositionItem* baseItem = indiTypeExtItem->getBaseItem(); |
| 14265 |
COptimizedComplexVariableCompositionItemDependence* baseItemDep = indiTypeExtItem->getBaseItemDependence(); |
| 14266 |
COptimizedComplexVariableIndividualMappings* baseVarMapping = baseItem->getVariableMapping(); |
| 14267 |
COptimizedComplexVariableIndividualMappings* extVarMapping = indiTypeExtItem->getVariableMapping(); |
| 14268 |
|
| 14269 |
COptimizedComplexVariableCompositionItem* classTypeExtItem = indiTypeExtItem->getClassVariableItem(); |
| 14270 |
|
| 14271 |
cint64 indiVarPos = indiTypeExtItem->getExtensionIndividualVariableId(); |
| 14272 |
cint64 classVarPos = indiTypeExtItem->getExtensionClassVariableId(); |
| 14273 |
|
| 14274 |
cint64 baseSize = baseVarMapping->getBindingSize(); |
| 14275 |
cint64 extSize = 0; |
| 14276 |
|
| 14277 |
COptimizedComplexVariableIndividualMappings* classTypeExtVarMapping = nullptr; |
| 14278 |
if (classTypeExtItem) { |
| 14279 |
classTypeExtVarMapping = classTypeExtItem->getVariableMapping(); |
| 14280 |
extSize = classTypeExtVarMapping->getBindingSize(); |
| 14281 |
} else { |
| 14282 |
extSize = 1; |
| 14283 |
} |
| 14284 |
cint64 newSize = baseSize + extSize; |
| 14285 |
|
| 14286 |
|
| 14287 |
COptimizedComplexVariableIndividualBindings* extendedBindings = nullptr; |
| 14288 |
COptimizedComplexVariableIndividualBindingsCardinality* extendedCardinalites = nullptr; |
| 14289 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 14290 |
|
| 14291 |
|
| 14292 |
if (classTypeExtItem && rescheduleVariableCompositionItemComputation(buildingVarItem, compVarItem, classTypeExtItem, -1)) { |
| 14293 |
return; |
| 14294 |
} |
| 14295 |
|
| 14296 |
if (baseVarMapping->getBindingCount() <= 0) { |
| 14297 |
if (rescheduleVariableCompositionItemComputation(buildingVarItem->getIndividualVariableSubQueryBuildingItem(), compVarItem, baseItem, 1, buildingVarItem)) { |
| 14298 |
subBuildItemProcessing = true; |
| 14299 |
return; |
| 14300 |
} |
| 14301 |
} |
| 14302 |
|
| 14303 |
|
| 14304 |
QList<COptimizedComplexVariableIndividualTypeExtensionProcessingRealizationData>* waitingProcessedRealizationBindingsCardinalityDataList = indiTypeExtItem->getWaitingProcessedRealizationBindingsCardinalityDataList(); |
| 14305 |
|
| 14306 |
QList<COntologyProcessingRequirement*> reqList; |
| 14307 |
|
| 14308 |
|
| 14309 |
function<void(COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites, bool realized)> extHandlingFunc = [&](COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites, bool realized) { |
| 14310 |
TIndividualInstanceItemDataBinding& propBinding = bindings->getBinding(indiVarPos); |
| 14311 |
|
| 14312 |
CRealizationIndividualInstanceItemReference indInstItem = propBinding.reference; |
| 14313 |
|
| 14314 |
auto bindingCreationFunc = [&](CHierarchyNode* node, COptimizedComplexVariableIndividualBindings* classExtBindings) { |
| 14315 |
if (!extendedBindings) { |
| 14316 |
extendedBindings = createBindingsForVariableCompositionItems(newSize, compVarItem, buildingVarItem); |
| 14317 |
} |
| 14318 |
if (!extendedCardinalites) { |
| 14319 |
extendedCardinalites = createBindingsCardinalitesForVariableCompositionItems(compVarItem, buildingVarItem); |
| 14320 |
} |
| 14321 |
if (extendedCardinalites) { |
| 14322 |
if (cardinalites) { |
| 14323 |
*extendedCardinalites = *cardinalites; |
| 14324 |
} else { |
| 14325 |
extendedCardinalites->initCardinalities(1, 1); |
| 14326 |
} |
| 14327 |
extendedCardinalites->setCardinalityUpdateId(-1); |
| 14328 |
} |
| 14329 |
|
| 14330 |
cint64 nextIdx = 0; |
| 14331 |
for (cint64 i = 0; i < baseSize; ++i) { |
| 14332 |
extendedBindings->setBinding(nextIdx++, bindings->getBinding(i)); |
| 14333 |
} |
| 14334 |
if (classExtBindings) { |
| 14335 |
for (cint64 i = 0; i < extSize; ++i) { |
| 14336 |
extendedBindings->setBinding(nextIdx++, classExtBindings->getBinding(i)); |
| 14337 |
} |
| 14338 |
} else { |
| 14339 |
extendedBindings->setBinding(nextIdx++, node); |
| 14340 |
} |
| 14341 |
|
| 14342 |
if (!linker) { |
| 14343 |
linker = createBindingsLinkerForVariableCompositionItems(extendedBindings, nullptr, compVarItem, buildingVarItem); |
| 14344 |
} else { |
| 14345 |
linker->setInitialCardinality(extendedCardinalites); |
| 14346 |
} |
| 14347 |
if (variableMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 14348 |
extendedBindings = nullptr; |
| 14349 |
extendedCardinalites = nullptr; |
| 14350 |
linker = nullptr; |
| 14351 |
} else { |
| 14352 |
extendedCardinalites = linker->getCurrentCardinalities(); |
| 14353 |
} |
| 14354 |
|
| 14355 |
}; |
| 14356 |
|
| 14357 |
bool realizationRequired = false; |
| 14358 |
if (classTypeExtItem) { |
| 14359 |
COptimizedComplexVariableCompositionItemDependence classItemDep(classTypeExtItem); |
| 14360 |
while (!realized && (!classItemDep.isBatchProcessed() || classItemDep.loadNextBatch())) { |
| 14361 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindCardLinker = classItemDep.getBatchCurrentBindingsCardinalityLinker(true); |
| 14362 |
COptimizedComplexVariableIndividualBindings* classExtBindings = bindCardLinker->getBindings(); |
| 14363 |
TIndividualInstanceItemDataBinding& classExtBinding = classExtBindings->getBinding(classVarPos); |
| 14364 |
CHierarchyNode* classHierNode = classExtBinding.classHierNode; |
| 14365 |
CConcept* classCon = classHierNode->getOneEquivalentConcept(); |
| 14366 |
CConceptInstantiatedItem* conceptItem = conReal->getInstantiatedItem(classCon); |
| 14367 |
|
| 14368 |
if (conReal->requiresConceptInstanceRealization(indInstItem, conceptItem)) { |
| 14369 |
COntologyProcessingConceptRealizationRequirement* roleRealReq = new COntologyProcessingConceptRealizationRequirement(indInstItem, classCon); |
| 14370 |
reqList.append(roleRealReq); |
| 14371 |
} |
| 14372 |
} |
| 14373 |
|
| 14374 |
if (realizationRequired) { |
| 14375 |
waitingProcessedRealizationBindingsCardinalityDataList->append(COptimizedComplexVariableIndividualTypeExtensionProcessingRealizationData(bindings, cardinalites)); |
| 14376 |
} else { |
| 14377 |
|
| 14378 |
classItemDep.reset(); |
| 14379 |
while (!classItemDep.isBatchProcessed() || classItemDep.loadNextBatch()) { |
| 14380 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindCardLinker = classItemDep.getBatchCurrentBindingsCardinalityLinker(true); |
| 14381 |
COptimizedComplexVariableIndividualBindings* classExtBindings = bindCardLinker->getBindings(); |
| 14382 |
TIndividualInstanceItemDataBinding& classExtBinding = classExtBindings->getBinding(classVarPos); |
| 14383 |
CHierarchyNode* classHierNode = classExtBinding.classHierNode; |
| 14384 |
CConcept* classCon = classHierNode->getOneEquivalentConcept(); |
| 14385 |
CConceptInstantiatedItem* conceptItem = conReal->getInstantiatedItem(classCon); |
| 14386 |
|
| 14387 |
if (conReal->isConceptInstance(indInstItem, conceptItem)) { |
| 14388 |
|
| 14389 |
bindingCreationFunc(nullptr, classExtBindings); |
| 14390 |
|
| 14391 |
} |
| 14392 |
} |
| 14393 |
|
| 14394 |
} |
| 14395 |
} else { |
| 14396 |
if (!realized && conReal->requiresConceptInstanceRealization(indInstItem)) { |
| 14397 |
COntologyProcessingConceptRealizationRequirement* roleRealReq = new COntologyProcessingConceptRealizationRequirement(indInstItem); |
| 14398 |
reqList.append(roleRealReq); |
| 14399 |
} |
| 14400 |
|
| 14401 |
|
| 14402 |
|
| 14403 |
class CConceptRealizationHierarchyNodeBindingsConverterVisitor : public CConceptRealizationInstantiatedToHierarchyNodeVisitor { |
| 14404 |
public: |
| 14405 |
function<void(CHierarchyNode*)> mFunc; |
| 14406 |
CConceptRealizationHierarchyNodeBindingsConverterVisitor(function<void(CHierarchyNode*)> func) { |
| 14407 |
mFunc = func; |
| 14408 |
} |
| 14409 |
|
| 14410 |
virtual bool visitHierarchyNode(CHierarchyNode* hierNode, CConceptRealization* conRealization) { |
| 14411 |
mFunc(hierNode); |
| 14412 |
return true; |
| 14413 |
} |
| 14414 |
|
| 14415 |
} visitor([&](CHierarchyNode* node) { |
| 14416 |
bindingCreationFunc(node, nullptr); |
| 14417 |
}); |
| 14418 |
|
| 14419 |
if (realizationRequired) { |
| 14420 |
waitingProcessedRealizationBindingsCardinalityDataList->append(COptimizedComplexVariableIndividualTypeExtensionProcessingRealizationData(bindings, cardinalites)); |
| 14421 |
} else { |
| 14422 |
conReal->visitAllTypes(indInstItem, &visitor); |
| 14423 |
} |
| 14424 |
} |
| 14425 |
|
| 14426 |
}; |
| 14427 |
|
| 14428 |
|
| 14429 |
|
| 14430 |
while (!waitingProcessedRealizationBindingsCardinalityDataList->isEmpty()) { |
| 14431 |
COptimizedComplexVariableIndividualTypeExtensionProcessingRealizationData data = waitingProcessedRealizationBindingsCardinalityDataList->takeFirst(); |
| 14432 |
extHandlingFunc(data.getBindings(), data.getCardinalites(), true); |
| 14433 |
} |
| 14434 |
|
| 14435 |
|
| 14436 |
bool mappingProcessed = false; |
| 14437 |
while (indiTypeExtItem->requiresMoreVariableMappingsComputation() && (!baseItemDep->isBatchProcessed() || baseItemDep->loadNextBatch())) { |
| 14438 |
|
| 14439 |
while (indiTypeExtItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentBindingsCardinalityLinker(false)) { |
| 14440 |
mappingProcessed = true; |
| 14441 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = baseItemDep->getBatchCurrentBindingsCardinalityLinker(true); |
| 14442 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14443 |
COptimizedComplexVariableIndividualBindingsCardinality* cardinalites = bindingLinker->getInitialCardinalities(); |
| 14444 |
|
| 14445 |
extHandlingFunc(bindings, cardinalites, false); |
| 14446 |
} |
| 14447 |
|
| 14448 |
|
| 14449 |
while (indiTypeExtItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentUpdatedCardinalityLinker(false)) { |
| 14450 |
mappingProcessed = true; |
| 14451 |
COptimizedComplexVariableIndividualUpdateCardinalityLinker* updatedCardinalityLinker = baseItemDep->getBatchCurrentUpdatedCardinalityLinker(true); |
| 14452 |
COptimizedComplexVariableIndividualBindingsCardinality* prevCardinalites = updatedCardinalityLinker->getPreviousCardinality(); |
| 14453 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = updatedCardinalityLinker->getUpdatedBindingsCardinalityLinker(); |
| 14454 |
COptimizedComplexVariableIndividualBindingsCardinality* newCardinalites = updatedCardinalityLinker->getNewCardinality(); |
| 14455 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14456 |
|
| 14457 |
COptimizedComplexVariableIndividualBindingsCardinality tmpDiffCardinalites = *newCardinalites; |
| 14458 |
tmpDiffCardinalites.substractCardinalities(prevCardinalites); |
| 14459 |
|
| 14460 |
extHandlingFunc(bindings, &tmpDiffCardinalites, false); |
| 14461 |
} |
| 14462 |
|
| 14463 |
} |
| 14464 |
|
| 14465 |
|
| 14466 |
bool realizationScheduled = indiTypeExtItem->getScheduledRealizationCount() > 0; |
| 14467 |
if (!reqList.isEmpty()) { |
| 14468 |
realizationScheduled = true; |
| 14469 |
indiTypeExtItem->incScheduledRealizationCount(reqList.size()); |
| 14470 |
processCompositionItemRequirements(reqList, compVarItem, buildingVarItem, mAnswererContext); |
| 14471 |
processing = true; |
| 14472 |
} |
| 14473 |
|
| 14474 |
|
| 14475 |
extVarMapping->incCurrentUpdateId(); |
| 14476 |
|
| 14477 |
bool dependentItemRescheduled = false; |
| 14478 |
dependentItemRescheduled = expectedUpdatedReschedulingDependentItemComputation(baseItemDep, extVarMapping, indiTypeExtItem, baseItem, compVarItem, buildingVarItem->getIndividualVariableSubQueryBuildingItem(), buildingVarItem); |
| 14479 |
if (dependentItemRescheduled) { |
| 14480 |
subBuildItemProcessing = true; |
| 14481 |
} |
| 14482 |
|
| 14483 |
if (!realizationScheduled && !dependentItemRescheduled && compVarItem->getDependencyUpdatingCount() <= 0) { |
| 14484 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItemDep->isProcessingFinished()); |
| 14485 |
if (mConfExtendedLogging) { |
| 14486 |
if (classTypeExtItem) { |
| 14487 |
LOG(INFO, getDomain(), logTr("Computation step %3 (attempt %4): Individual type extension computation from %1 mappings of step %5 and %7 mappings of step %6 resulted in %2 mappings.") |
| 14488 |
.arg(baseVarMapping->getBindingCount()).arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()).arg(baseItem->getComputationStepId()).arg(classTypeExtItem->getComputationStepId()).arg(classTypeExtVarMapping->getBindingCount()), this); |
| 14489 |
} else { |
| 14490 |
LOG(INFO, getDomain(), logTr("Computation step %3 (attempt %4): Individual type extension computation from %1 mappings of step %5 resulted in %2 mappings.") |
| 14491 |
.arg(baseVarMapping->getBindingCount()).arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()).arg(baseItem->getComputationStepId()), this); |
| 14492 |
} |
| 14493 |
} |
| 14494 |
} |
| 14495 |
|
| 14496 |
configureDependentComputationIncreaseFactor(dependentItemRescheduled, mappingProcessed, compVarItem); |
| 14497 |
|
| 14498 |
} |
| 14499 |
|
| 14500 |
|
| 14501 |
|
| 14502 |
|
| 14503 |
|
| 14504 |
|
| 14505 |
|
| 14506 |
|
| 14507 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemIndividualPropertyExtension(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingIndividualMixedVariableCompositionsItem* buildingVarItem, bool& processing, bool& subBuildItemProcessing) { |
| 14508 |
COptimizedComplexVariableIndividualNeighboringPropertyExtensionItem* indiPropExtItem = (COptimizedComplexVariableIndividualNeighboringPropertyExtensionItem*)compVarItem; |
| 14509 |
COptimizedComplexVariableIndividualMappings* variableMapping = indiPropExtItem->getVariableMapping(); |
| 14510 |
|
| 14511 |
|
| 14512 |
CRoleRealization* roleReal = mOntoAnsweringItem->getOntology()->getRealization()->getRoleRealization(); |
| 14513 |
|
| 14514 |
COptimizedComplexVariableCompositionItem* baseItem = indiPropExtItem->getBaseItem(); |
| 14515 |
COptimizedComplexVariableCompositionItemDependence* baseItemDep = indiPropExtItem->getBaseItemDependence(); |
| 14516 |
COptimizedComplexVariableIndividualMappings* baseVarMapping = baseItem->getVariableMapping(); |
| 14517 |
COptimizedComplexVariableIndividualMappings* extVarMapping = indiPropExtItem->getVariableMapping(); |
| 14518 |
|
| 14519 |
COptimizedComplexVariableCompositionItem* propTypeExtItem = indiPropExtItem->getPropertyVariableItem(); |
| 14520 |
|
| 14521 |
cint64 indiVarPos = indiPropExtItem->getExtensionIndividualVariableId(); |
| 14522 |
cint64 propVarPos = indiPropExtItem->getExtensionPropertyVariableId(); |
| 14523 |
|
| 14524 |
cint64 baseSize = baseVarMapping->getBindingSize(); |
| 14525 |
cint64 extSize = 0; |
| 14526 |
|
| 14527 |
COptimizedComplexVariableIndividualMappings* propTypeExtVarMapping = nullptr; |
| 14528 |
if (propTypeExtItem) { |
| 14529 |
propTypeExtVarMapping = propTypeExtItem->getVariableMapping(); |
| 14530 |
extSize = propTypeExtVarMapping->getBindingSize(); |
| 14531 |
} else { |
| 14532 |
extSize = 1; |
| 14533 |
} |
| 14534 |
cint64 newSize = baseSize + extSize; |
| 14535 |
|
| 14536 |
|
| 14537 |
COptimizedComplexVariableIndividualBindings* extendedBindings = nullptr; |
| 14538 |
COptimizedComplexVariableIndividualBindingsCardinality* extendedCardinalites = nullptr; |
| 14539 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 14540 |
|
| 14541 |
|
| 14542 |
if (propTypeExtItem && rescheduleVariableCompositionItemComputation(buildingVarItem, compVarItem, propTypeExtItem, -1)) { |
| 14543 |
return; |
| 14544 |
} |
| 14545 |
|
| 14546 |
if (baseVarMapping->getBindingCount() <= 0) { |
| 14547 |
if (rescheduleVariableCompositionItemComputation(buildingVarItem->getIndividualVariableSubQueryBuildingItem(), compVarItem, baseItem, 1, buildingVarItem)) { |
| 14548 |
subBuildItemProcessing = true; |
| 14549 |
return; |
| 14550 |
} |
| 14551 |
} |
| 14552 |
|
| 14553 |
|
| 14554 |
QList<COptimizedComplexVariableIndividualPropertyExtensionProcessingRealizationData>* waitingProcessedRealizationBindingsCardinalityDataList = indiPropExtItem->getWaitingProcessedRealizationBindingsCardinalityDataList(); |
| 14555 |
|
| 14556 |
QList<COntologyProcessingRequirement*> reqList; |
| 14557 |
|
| 14558 |
|
| 14559 |
function<void(COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites, bool realized)> extHandlingFunc = [&](COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites, bool realized) { |
| 14560 |
TIndividualInstanceItemDataBinding& propBinding = bindings->getBinding(indiVarPos); |
| 14561 |
|
| 14562 |
CRealizationIndividualInstanceItemReference indInstItem = propBinding.reference; |
| 14563 |
|
| 14564 |
auto bindingCreationFunc = [&](CRolePropertiesHierarchyNode* node, COptimizedComplexVariableIndividualBindings* propExtBindings) { |
| 14565 |
if (!extendedBindings) { |
| 14566 |
extendedBindings = createBindingsForVariableCompositionItems(newSize, compVarItem, buildingVarItem); |
| 14567 |
} |
| 14568 |
if (!extendedCardinalites) { |
| 14569 |
extendedCardinalites = createBindingsCardinalitesForVariableCompositionItems(compVarItem, buildingVarItem); |
| 14570 |
} |
| 14571 |
if (extendedCardinalites) { |
| 14572 |
if (cardinalites) { |
| 14573 |
*extendedCardinalites = *cardinalites; |
| 14574 |
} else { |
| 14575 |
extendedCardinalites->initCardinalities(1, 1); |
| 14576 |
} |
| 14577 |
extendedCardinalites->setCardinalityUpdateId(-1); |
| 14578 |
} |
| 14579 |
|
| 14580 |
cint64 nextIdx = 0; |
| 14581 |
for (cint64 i = 0; i < baseSize; ++i) { |
| 14582 |
extendedBindings->setBinding(nextIdx++, bindings->getBinding(i)); |
| 14583 |
} |
| 14584 |
if (propExtBindings) { |
| 14585 |
for (cint64 i = 0; i < extSize; ++i) { |
| 14586 |
extendedBindings->setBinding(nextIdx++, propExtBindings->getBinding(i)); |
| 14587 |
} |
| 14588 |
} else { |
| 14589 |
extendedBindings->setBinding(nextIdx++, node); |
| 14590 |
} |
| 14591 |
|
| 14592 |
if (!linker) { |
| 14593 |
linker = createBindingsLinkerForVariableCompositionItems(extendedBindings, nullptr, compVarItem, buildingVarItem); |
| 14594 |
} else { |
| 14595 |
linker->setInitialCardinality(extendedCardinalites); |
| 14596 |
} |
| 14597 |
if (variableMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 14598 |
extendedBindings = nullptr; |
| 14599 |
extendedCardinalites = nullptr; |
| 14600 |
linker = nullptr; |
| 14601 |
} else { |
| 14602 |
extendedCardinalites = linker->getCurrentCardinalities(); |
| 14603 |
} |
| 14604 |
|
| 14605 |
}; |
| 14606 |
|
| 14607 |
bool realizationRequired = false; |
| 14608 |
if (propTypeExtItem) { |
| 14609 |
COptimizedComplexVariableCompositionItemDependence classItemDep(propTypeExtItem); |
| 14610 |
while (!realized && (!classItemDep.isBatchProcessed() || classItemDep.loadNextBatch())) { |
| 14611 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindCardLinker = classItemDep.getBatchCurrentBindingsCardinalityLinker(true); |
| 14612 |
COptimizedComplexVariableIndividualBindings* propExtBindings = bindCardLinker->getBindings(); |
| 14613 |
TIndividualInstanceItemDataBinding& propExtBinding = propExtBindings->getBinding(propVarPos); |
| 14614 |
CRolePropertiesHierarchyNode* propHierNode = propExtBinding.propertyHierNode; |
| 14615 |
CRole* propRole = propHierNode->getOneEquivalentElement(); |
| 14616 |
CRoleInstantiatedItem* roleItem = roleReal->getRoleInstantiatedItem(propRole); |
| 14617 |
|
| 14618 |
if (roleReal->requiresSourceIndividualRolesRealization(indInstItem, roleItem)) { |
| 14619 |
COntologyProcessingRoleRealizationRequirement* roleRealReq = new COntologyProcessingRoleRealizationRequirement(propRole, false, indInstItem); |
| 14620 |
reqList.append(roleRealReq); |
| 14621 |
} |
| 14622 |
} |
| 14623 |
|
| 14624 |
if (realizationRequired) { |
| 14625 |
waitingProcessedRealizationBindingsCardinalityDataList->append(COptimizedComplexVariableIndividualPropertyExtensionProcessingRealizationData(bindings, cardinalites)); |
| 14626 |
} else { |
| 14627 |
|
| 14628 |
classItemDep.reset(); |
| 14629 |
while (!classItemDep.isBatchProcessed() || classItemDep.loadNextBatch()) { |
| 14630 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindCardLinker = classItemDep.getBatchCurrentBindingsCardinalityLinker(true); |
| 14631 |
COptimizedComplexVariableIndividualBindings* propExtBindings = bindCardLinker->getBindings(); |
| 14632 |
TIndividualInstanceItemDataBinding& propExtBinding = propExtBindings->getBinding(propVarPos); |
| 14633 |
CRolePropertiesHierarchyNode* propHierNode = propExtBinding.propertyHierNode; |
| 14634 |
CRole* propRole = propHierNode->getOneEquivalentElement(); |
| 14635 |
CRoleInstantiatedItem* roleItem = roleReal->getRoleInstantiatedItem(propRole); |
| 14636 |
|
| 14637 |
if (roleReal->isSourceIndividualRole(indInstItem, roleItem)) { |
| 14638 |
|
| 14639 |
bindingCreationFunc(nullptr, propExtBindings); |
| 14640 |
|
| 14641 |
} |
| 14642 |
} |
| 14643 |
|
| 14644 |
} |
| 14645 |
} else { |
| 14646 |
if (!realized && roleReal->requiresSourceIndividualRolesRealization(indInstItem)) { |
| 14647 |
COntologyProcessingRoleRealizationRequirement* roleRealReq = new COntologyProcessingRoleRealizationRequirement(nullptr, false, indInstItem); |
| 14648 |
reqList.append(roleRealReq); |
| 14649 |
} |
| 14650 |
|
| 14651 |
|
| 14652 |
|
| 14653 |
class CConceptRealizationHierarchyNodeBindingsConverterVisitor : public CRoleRealizationInstantiatedToHierarchyNodeVisitor { |
| 14654 |
public: |
| 14655 |
function<void(CRolePropertiesHierarchyNode*)> mFunc; |
| 14656 |
CConceptRealizationHierarchyNodeBindingsConverterVisitor(function<void(CRolePropertiesHierarchyNode*)> func) { |
| 14657 |
mFunc = func; |
| 14658 |
} |
| 14659 |
|
| 14660 |
virtual bool visitHierarchyNode(CRolePropertiesHierarchyNode* roleHierNode, CRoleRealization* roleRealization) { |
| 14661 |
mFunc(roleHierNode); |
| 14662 |
return true; |
| 14663 |
} |
| 14664 |
|
| 14665 |
} visitor([&](CRolePropertiesHierarchyNode* node) { |
| 14666 |
bindingCreationFunc(node, nullptr); |
| 14667 |
}); |
| 14668 |
|
| 14669 |
if (realizationRequired) { |
| 14670 |
waitingProcessedRealizationBindingsCardinalityDataList->append(COptimizedComplexVariableIndividualPropertyExtensionProcessingRealizationData(bindings, cardinalites)); |
| 14671 |
} else { |
| 14672 |
roleReal->visitSourceIndividualRoles(indInstItem, &visitor); |
| 14673 |
} |
| 14674 |
} |
| 14675 |
|
| 14676 |
}; |
| 14677 |
|
| 14678 |
|
| 14679 |
|
| 14680 |
while (!waitingProcessedRealizationBindingsCardinalityDataList->isEmpty()) { |
| 14681 |
COptimizedComplexVariableIndividualPropertyExtensionProcessingRealizationData data = waitingProcessedRealizationBindingsCardinalityDataList->takeFirst(); |
| 14682 |
extHandlingFunc(data.getBindings(), data.getCardinalites(), true); |
| 14683 |
} |
| 14684 |
|
| 14685 |
|
| 14686 |
bool mappingProcessed = false; |
| 14687 |
while (indiPropExtItem->requiresMoreVariableMappingsComputation() && (!baseItemDep->isBatchProcessed() || baseItemDep->loadNextBatch())) { |
| 14688 |
|
| 14689 |
while (indiPropExtItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentBindingsCardinalityLinker(false)) { |
| 14690 |
mappingProcessed = true; |
| 14691 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = baseItemDep->getBatchCurrentBindingsCardinalityLinker(true); |
| 14692 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14693 |
COptimizedComplexVariableIndividualBindingsCardinality* cardinalites = bindingLinker->getInitialCardinalities(); |
| 14694 |
|
| 14695 |
extHandlingFunc(bindings, cardinalites, false); |
| 14696 |
} |
| 14697 |
|
| 14698 |
|
| 14699 |
while (indiPropExtItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentUpdatedCardinalityLinker(false)) { |
| 14700 |
mappingProcessed = true; |
| 14701 |
COptimizedComplexVariableIndividualUpdateCardinalityLinker* updatedCardinalityLinker = baseItemDep->getBatchCurrentUpdatedCardinalityLinker(true); |
| 14702 |
COptimizedComplexVariableIndividualBindingsCardinality* prevCardinalites = updatedCardinalityLinker->getPreviousCardinality(); |
| 14703 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = updatedCardinalityLinker->getUpdatedBindingsCardinalityLinker(); |
| 14704 |
COptimizedComplexVariableIndividualBindingsCardinality* newCardinalites = updatedCardinalityLinker->getNewCardinality(); |
| 14705 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14706 |
|
| 14707 |
COptimizedComplexVariableIndividualBindingsCardinality tmpDiffCardinalites = *newCardinalites; |
| 14708 |
tmpDiffCardinalites.substractCardinalities(prevCardinalites); |
| 14709 |
|
| 14710 |
extHandlingFunc(bindings, &tmpDiffCardinalites, false); |
| 14711 |
} |
| 14712 |
|
| 14713 |
} |
| 14714 |
|
| 14715 |
|
| 14716 |
bool realizationScheduled = indiPropExtItem->getScheduledRealizationCount() > 0; |
| 14717 |
if (!reqList.isEmpty()) { |
| 14718 |
realizationScheduled = true; |
| 14719 |
indiPropExtItem->incScheduledRealizationCount(reqList.size()); |
| 14720 |
processCompositionItemRequirements(reqList, compVarItem, buildingVarItem, mAnswererContext); |
| 14721 |
processing = true; |
| 14722 |
} |
| 14723 |
|
| 14724 |
|
| 14725 |
extVarMapping->incCurrentUpdateId(); |
| 14726 |
|
| 14727 |
bool dependentItemRescheduled = false; |
| 14728 |
dependentItemRescheduled = expectedUpdatedReschedulingDependentItemComputation(baseItemDep, extVarMapping, indiPropExtItem, baseItem, compVarItem, buildingVarItem->getIndividualVariableSubQueryBuildingItem(), buildingVarItem); |
| 14729 |
if (dependentItemRescheduled) { |
| 14730 |
subBuildItemProcessing = true; |
| 14731 |
} |
| 14732 |
|
| 14733 |
if (!realizationScheduled && !dependentItemRescheduled && compVarItem->getDependencyUpdatingCount() <= 0) { |
| 14734 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItemDep->isProcessingFinished()); |
| 14735 |
if (mConfExtendedLogging) { |
| 14736 |
if (propTypeExtItem) { |
| 14737 |
LOG(INFO, getDomain(), logTr("Computation step %3 (attempt %4): Individual neighboring extension computation from %1 mappings of step %5 and %7 mappings of step %6 resulted in %2 mappings.") |
| 14738 |
.arg(baseVarMapping->getBindingCount()).arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()).arg(baseItem->getComputationStepId()).arg(propTypeExtItem->getComputationStepId()).arg(propTypeExtVarMapping->getBindingCount()), this); |
| 14739 |
} else { |
| 14740 |
LOG(INFO, getDomain(), logTr("Computation step %3 (attempt %4): Individual neighboring extension computation from %1 mappings of step %5 resulted in %2 mappings.") |
| 14741 |
.arg(baseVarMapping->getBindingCount()).arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()).arg(baseItem->getComputationStepId()), this); |
| 14742 |
} |
| 14743 |
} |
| 14744 |
} |
| 14745 |
|
| 14746 |
configureDependentComputationIncreaseFactor(dependentItemRescheduled, mappingProcessed, compVarItem); |
| 14747 |
} |
| 14748 |
|
| 14749 |
|
| 14750 |
|
| 14751 |
|
| 14752 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemFromConceptItemBase(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, bool& processing) { |
| 14753 |
COptimizedComplexVariableConceptBaseItem* conceptBaseItem = (COptimizedComplexVariableConceptBaseItem*)compVarItem; |
| 14754 |
COptimizedComplexConceptItem* conItem = conceptBaseItem->getConceptItem(); |
| 14755 |
COptimizedComplexVariableIndividualMappings* variableMapping = conceptBaseItem->getVariableMapping(); |
| 14756 |
|
| 14757 |
CConceptRealization* conceptRealization = mOntoAnsweringItem->getOntology()->getRealization()->getConceptRealization(); |
| 14758 |
COptimizedComplexConceptInstanziatedIndividualItemHash* instanceItems = conItem->getKnownInstanceItems(); |
| 14759 |
|
| 14760 |
COptimizedComplexConceptInstanziatedIndividualItemLinker* instanceItemProcessingLinker = conceptBaseItem->getInstanceItemProcessingLinker(); |
| 14761 |
COptimizedComplexConceptInstanziatedIndividualItemLinker* instanceItemProcessedLinker = conceptBaseItem->getInstanceItemProcessedLinker(); |
| 14762 |
COptimizedComplexConceptInstanziatedIndividualItemLinker* instanceItemRetrievedLinker = conceptBaseItem->getInstanceItemRetrievedLinker(); |
| 14763 |
|
| 14764 |
|
| 14765 |
bool mappingProcessed = false; |
| 14766 |
if (instanceItems) { |
| 14767 |
COptimizedComplexVariableIndividualBindings* binding = nullptr; |
| 14768 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 14769 |
|
| 14770 |
while (compVarItem->requiresMoreVariableMappingsComputation() && (instanceItemProcessingLinker != instanceItemProcessedLinker || instanceItemRetrievedLinker != instanceItems->getAddedRealizationIndividualInstanceItemReferenceLinker())) { |
| 14771 |
|
| 14772 |
while (compVarItem->requiresMoreVariableMappingsComputation() && instanceItemProcessingLinker != instanceItemProcessedLinker) { |
| 14773 |
mappingProcessed = true; |
| 14774 |
auto item = instanceItemProcessingLinker->getRealizationIndividualInstanceItemReference(); |
| 14775 |
instanceItemProcessingLinker = instanceItemProcessingLinker->getNext(); |
| 14776 |
if (!binding) { |
| 14777 |
binding = createBindingsForVariableCompositionItems(1, compVarItem, buildingVarItem); |
| 14778 |
} |
| 14779 |
binding->setBinding(0, item); |
| 14780 |
if (!linker) { |
| 14781 |
linker = createBindingsLinkerForVariableCompositionItems(binding, nullptr, compVarItem, buildingVarItem); |
| 14782 |
} |
| 14783 |
if (variableMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 14784 |
binding = nullptr; |
| 14785 |
linker = nullptr; |
| 14786 |
} |
| 14787 |
} |
| 14788 |
|
| 14789 |
if (instanceItemProcessingLinker == instanceItemProcessedLinker && instanceItemRetrievedLinker != instanceItems->getAddedRealizationIndividualInstanceItemReferenceLinker()) { |
| 14790 |
instanceItemProcessedLinker = instanceItemRetrievedLinker; |
| 14791 |
instanceItemProcessingLinker = instanceItemRetrievedLinker = instanceItems->getAddedRealizationIndividualInstanceItemReferenceLinker(); |
| 14792 |
} |
| 14793 |
|
| 14794 |
} |
| 14795 |
|
| 14796 |
conceptBaseItem->setInstanceItemProcessingLinker(instanceItemProcessingLinker); |
| 14797 |
conceptBaseItem->setInstanceItemProcessedLinker(instanceItemProcessedLinker); |
| 14798 |
conceptBaseItem->setInstanceItemRetrievedLinker(instanceItemRetrievedLinker); |
| 14799 |
|
| 14800 |
} |
| 14801 |
variableMapping->incCurrentUpdateId(); |
| 14802 |
|
| 14803 |
|
| 14804 |
|
| 14805 |
bool moreInstanceComputationScheduled = false; |
| 14806 |
CComplexConceptStepInstanceComputationProcess* instanceCompStep = conItem->getComputationProcess()->getInstancesComputationProcess(true); |
| 14807 |
conceptBaseItem->setVariableMappingsExpectedCount(instanceCompStep->getExpectedInstancesCount()); |
| 14808 |
|
| 14809 |
if (!instanceCompStep->hasAllInstancesComputed() && (instanceCompStep->getComputedInstancesCount() < compVarItem->getVariableMappingsComputationRequirement() || compVarItem->getVariableMappingsComputationRequirement() == -1)) { |
| 14810 |
|
| 14811 |
moreInstanceComputationScheduled = true; |
| 14812 |
CComputedItemDataNotificationLinker* notLinker = mOntoAnsweringItem->createComputedItemDataNotificationLinker(); |
| 14813 |
notLinker->setVariableCompositionItem(compVarItem); |
| 14814 |
notLinker->setBuildingVariableItemProcessingItem(buildingVarItem); |
| 14815 |
|
| 14816 |
double mappingRequirementCount = conceptBaseItem->getVariableMappingsComputationRequirement(); |
| 14817 |
|
| 14818 |
mappingRequirementCount = mappingRequirementCount * conceptBaseItem->repeatedRequirementInsufficientDependencyComputationIncreaseFactor(); |
| 14819 |
|
| 14820 |
if (mappingRequirementCount == -1 || mConfMappingsComputationUnlimitedInterpretationSize >= 0 && mappingRequirementCount >= mConfMappingsComputationUnlimitedInterpretationSize) { |
| 14821 |
mappingRequirementCount = -1; |
| 14822 |
} |
| 14823 |
|
| 14824 |
if (mappingRequirementCount >= 0) { |
| 14825 |
instanceCompStep->addComputedInstancesCountRequirement(mappingRequirementCount, notLinker); |
| 14826 |
} else { |
| 14827 |
instanceCompStep->setAllInstanceComputationRequired(true); |
| 14828 |
instanceCompStep->addNotificationLinker(notLinker); |
| 14829 |
} |
| 14830 |
buildingVarItem->setComputationStepWaiting(instanceCompStep); |
| 14831 |
queueConceptItemProcessing(conItem, instanceCompStep); |
| 14832 |
processing = true; |
| 14833 |
|
| 14834 |
if (mConfExtendedLogging) { |
| 14835 |
LOG(INFO, getDomain(), logTr("Computation step %1 (attempt %2): Requesting %3 mappings from concept item %4.").arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt(false)).arg(mappingRequirementCount).arg(conItem->getConceptItemId()), this); |
| 14836 |
} |
| 14837 |
|
| 14838 |
} |
| 14839 |
|
| 14840 |
|
| 14841 |
//if (instanceCompStep->hasAllInstancesComputed() && compVarItem->debugVariableNameStringList.contains("v0__genid634__n274")) { |
| 14842 |
// if (instanceCompStep->hasAllInstancesComputed() && instanceItemProcessingLinker == instanceItemProcessedLinker && instanceItemRetrievedLinker == instanceItems->getAddedRealizationIndividualInstanceItemReferenceLinker()) { |
| 14843 |
// debugCheckVariableMappingFromFile(buildingVarItem, compVarItem); |
| 14844 |
|
| 14845 |
// //debugWriteVariableMappingToFile(buildingVarItem, compVarItem); |
| 14846 |
// } |
| 14847 |
//} |
| 14848 |
|
| 14849 |
|
| 14850 |
if (!moreInstanceComputationScheduled) { |
| 14851 |
bool completed = instanceCompStep->hasAllInstancesComputed() && instanceItemProcessingLinker == instanceItemProcessedLinker && (!instanceItems || instanceItemRetrievedLinker == instanceItems->getAddedRealizationIndividualInstanceItemReferenceLinker()); |
| 14852 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, completed); |
| 14853 |
} |
| 14854 |
|
| 14855 |
configureDependentComputationIncreaseFactor(moreInstanceComputationScheduled, mappingProcessed, compVarItem); |
| 14856 |
|
| 14857 |
|
| 14858 |
|
| 14859 |
//debugCheckVariableMappingContainsSolution(buildingVarItem, compVarItem); |
| 14860 |
} |
| 14861 |
|
| 14862 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemReduction(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 14863 |
COptimizedComplexVariableReductionItem* reductionItem = (COptimizedComplexVariableReductionItem*)compVarItem; |
| 14864 |
cint64 redIdx = reductionItem->getReductionVariableIndex(); |
| 14865 |
COptimizedComplexVariableIndividualMappings* reducedVarMapping = reductionItem->getVariableMapping(); |
| 14866 |
|
| 14867 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 14868 |
|
| 14869 |
// determine how many mappings must be calculated |
| 14870 |
// process currently processing mappings linker of dependent item |
| 14871 |
// count processed mappings |
| 14872 |
// process currently processing cardinality update linker of dependent item |
| 14873 |
// update linkers to last one from dependent item and repeat processing |
| 14874 |
// calculate estimation of how many mappings of dependent item are required to fulfill the requirements for the processing item |
| 14875 |
// reschedule computation of dependent item |
| 14876 |
// or trigger computation for dependent items |
| 14877 |
|
| 14878 |
|
| 14879 |
COptimizedComplexVariableCompositionItem* baseItem = reductionItem->getBaseItem(); |
| 14880 |
COptimizedComplexVariableCompositionItemDependence* baseItemDep = reductionItem->getBaseItemDependence(); |
| 14881 |
COptimizedComplexVariableIndividualMappings* baseVarMapping = baseItem->getVariableMapping(); |
| 14882 |
cint64 baseSize = baseVarMapping->getBindingSize(); |
| 14883 |
cint64 reducedSize = baseSize - 1; |
| 14884 |
COptimizedComplexVariableIndividualBindings* reducedBindings = nullptr; |
| 14885 |
COptimizedComplexVariableIndividualBindingsCardinality* reducedCardinalites = nullptr; |
| 14886 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 14887 |
|
| 14888 |
|
| 14889 |
if (baseVarMapping->getBindingCount() <= 0) { |
| 14890 |
if (rescheduleVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItem, 1)) { |
| 14891 |
return; |
| 14892 |
} |
| 14893 |
} |
| 14894 |
|
| 14895 |
COptimizedComplexVariableIndividualMappings::VARIABLE_TYPE redVarMapType = baseVarMapping->getBindingMapping(redIdx); |
| 14896 |
|
| 14897 |
function<void(COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites)> redHandlingFunc = [&](COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites) { |
| 14898 |
if (!reducedBindings) { |
| 14899 |
reducedBindings = createBindingsForVariableCompositionItems(reducedSize, compVarItem, buildingVarItem); |
| 14900 |
} |
| 14901 |
if (!reducedCardinalites) { |
| 14902 |
reducedCardinalites = createBindingsCardinalitesForVariableCompositionItems(compVarItem, buildingVarItem); |
| 14903 |
} |
| 14904 |
if (reducedCardinalites) { |
| 14905 |
if (cardinalites) { |
| 14906 |
*reducedCardinalites = *cardinalites; |
| 14907 |
} else { |
| 14908 |
reducedCardinalites->initCardinalities(1, 1); |
| 14909 |
} |
| 14910 |
reducedCardinalites->setCardinalityUpdateId(-1); |
| 14911 |
} |
| 14912 |
|
| 14913 |
if (redVarMapType == COptimizedComplexVariableIndividualMappings::INDIVIDUAL_VARIABLE) { |
| 14914 |
TIndividualInstanceItemDataBinding& reducedBinding = bindings->getBinding(redIdx); |
| 14915 |
CInstanceBindingIndividualCountingVisitor visitor; |
| 14916 |
sameRealization->visitSameIndividuals(reducedBinding.reference, &visitor); |
| 14917 |
if (visitor.individualCount > 1) { |
| 14918 |
reducedCardinalites->setSameIndividualsSeparatlyConsideredCardinality(visitor.individualCount * reducedCardinalites->getSameIndividualsSeparatlyConsideredCardinality()); |
| 14919 |
} |
| 14920 |
} else if (redVarMapType == COptimizedComplexVariableIndividualMappings::CLASS_VARIABLE) { |
| 14921 |
TIndividualInstanceItemDataBinding& reducedBinding = bindings->getBinding(redIdx); |
| 14922 |
CHierarchyNode* hierNode = reducedBinding.classHierNode; |
| 14923 |
reducedCardinalites->setSameIndividualsSeparatlyConsideredCardinality(hierNode->getEquivalentConceptCount() * reducedCardinalites->getSameIndividualsSeparatlyConsideredCardinality()); |
| 14924 |
} else if (redVarMapType == COptimizedComplexVariableIndividualMappings::PROPERTY_VARIABLE) { |
| 14925 |
TIndividualInstanceItemDataBinding& reducedBinding = bindings->getBinding(redIdx); |
| 14926 |
CRolePropertiesHierarchyNode* hierNode = reducedBinding.propertyHierNode; |
| 14927 |
reducedCardinalites->setSameIndividualsSeparatlyConsideredCardinality(hierNode->getEquivalentElementCount() * reducedCardinalites->getSameIndividualsSeparatlyConsideredCardinality()); |
| 14928 |
} |
| 14929 |
|
| 14930 |
cint64 nextIdx = 0; |
| 14931 |
for (cint64 i = 0; i < baseSize; ++i) { |
| 14932 |
if (i != redIdx) { |
| 14933 |
reducedBindings->setBinding(nextIdx++, bindings->getBinding(i)); |
| 14934 |
} |
| 14935 |
} |
| 14936 |
if (!linker) { |
| 14937 |
linker = createBindingsLinkerForVariableCompositionItems(reducedBindings, reducedCardinalites, compVarItem, buildingVarItem); |
| 14938 |
} else { |
| 14939 |
linker->setInitialCardinality(reducedCardinalites); |
| 14940 |
} |
| 14941 |
if (reducedVarMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 14942 |
reducedBindings = nullptr; |
| 14943 |
reducedCardinalites = nullptr; |
| 14944 |
linker = nullptr; |
| 14945 |
} else { |
| 14946 |
reducedCardinalites = linker->getCurrentCardinalities(); |
| 14947 |
} |
| 14948 |
}; |
| 14949 |
|
| 14950 |
bool mappingProcessed = false; |
| 14951 |
while (reductionItem->requiresMoreVariableMappingsComputation() && (!baseItemDep->isBatchProcessed() || baseItemDep->loadNextBatch())) { |
| 14952 |
|
| 14953 |
while (reductionItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentBindingsCardinalityLinker(false)) { |
| 14954 |
mappingProcessed = true; |
| 14955 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = baseItemDep->getBatchCurrentBindingsCardinalityLinker(true); |
| 14956 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14957 |
COptimizedComplexVariableIndividualBindingsCardinality* cardinalites = bindingLinker->getInitialCardinalities(); |
| 14958 |
|
| 14959 |
redHandlingFunc(bindings, cardinalites); |
| 14960 |
} |
| 14961 |
|
| 14962 |
|
| 14963 |
while (reductionItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentUpdatedCardinalityLinker(false)) { |
| 14964 |
mappingProcessed = true; |
| 14965 |
COptimizedComplexVariableIndividualUpdateCardinalityLinker* updatedCardinalityLinker = baseItemDep->getBatchCurrentUpdatedCardinalityLinker(true); |
| 14966 |
COptimizedComplexVariableIndividualBindingsCardinality* prevCardinalites = updatedCardinalityLinker->getPreviousCardinality(); |
| 14967 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = updatedCardinalityLinker->getUpdatedBindingsCardinalityLinker(); |
| 14968 |
COptimizedComplexVariableIndividualBindingsCardinality* newCardinalites = updatedCardinalityLinker->getNewCardinality(); |
| 14969 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 14970 |
|
| 14971 |
COptimizedComplexVariableIndividualBindingsCardinality tmpDiffCardinalites = *newCardinalites; |
| 14972 |
tmpDiffCardinalites.substractCardinalities(prevCardinalites); |
| 14973 |
|
| 14974 |
redHandlingFunc(bindings, &tmpDiffCardinalites); |
| 14975 |
} |
| 14976 |
|
| 14977 |
} |
| 14978 |
|
| 14979 |
reducedVarMapping->incCurrentUpdateId(); |
| 14980 |
|
| 14981 |
bool dependentItemRescheduled = false; |
| 14982 |
dependentItemRescheduled = expectedUpdatedReschedulingDependentItemComputation(baseItemDep, reducedVarMapping, reductionItem, baseItem, compVarItem, buildingVarItem); |
| 14983 |
|
| 14984 |
if (!dependentItemRescheduled && compVarItem->getDependencyUpdatingCount() <= 0) { |
| 14985 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItemDep->isProcessingFinished()); |
| 14986 |
if (mConfExtendedLogging) { |
| 14987 |
LOG(INFO, getDomain(), logTr("Computation step %3 (attempt %4): Reduce computation from %1 mappings of step %5 resulted in %2 mappings.").arg(baseVarMapping->getBindingCount()).arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()).arg(baseItem->getComputationStepId()), this); |
| 14988 |
} |
| 14989 |
} |
| 14990 |
|
| 14991 |
configureDependentComputationIncreaseFactor(dependentItemRescheduled, mappingProcessed, compVarItem); |
| 14992 |
|
| 14993 |
|
| 14994 |
|
| 14995 |
} |
| 14996 |
|
| 14997 |
|
| 14998 |
|
| 14999 |
|
| 15000 |
|
| 15001 |
|
| 15002 |
|
| 15003 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemExtraction(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 15004 |
COptimizedComplexVariableExtractionItem* extractionItem = (COptimizedComplexVariableExtractionItem*)compVarItem; |
| 15005 |
cint64 extIdx = extractionItem->getExtractionVariableIndex(); |
| 15006 |
COptimizedComplexVariableIndividualMappings* reducedVarMapping = extractionItem->getVariableMapping(); |
| 15007 |
|
| 15008 |
|
| 15009 |
// determine how many mappings must be calculated |
| 15010 |
// process currently processing mappings linker of dependent item |
| 15011 |
// count processed mappings |
| 15012 |
// process currently processing cardinality update linker of dependent item |
| 15013 |
// update linkers to last one from dependent item and repeat processing |
| 15014 |
// calculate estimation of how many mappings of dependent item are required to fulfill the requirements for the processing item |
| 15015 |
// reschedule computation of dependent item |
| 15016 |
// or trigger computation for dependent items |
| 15017 |
|
| 15018 |
|
| 15019 |
COptimizedComplexVariableCompositionItem* baseItem = extractionItem->getBaseItem(); |
| 15020 |
COptimizedComplexVariableCompositionItemDependence* baseItemDep = extractionItem->getBaseItemDependence(); |
| 15021 |
COptimizedComplexVariableIndividualMappings* baseVarMapping = baseItem->getVariableMapping(); |
| 15022 |
COptimizedComplexVariableIndividualBindings* extractedBindings = nullptr; |
| 15023 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 15024 |
|
| 15025 |
|
| 15026 |
if (baseVarMapping->getBindingCount() <= 0) { |
| 15027 |
if (rescheduleVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItem, 1)) { |
| 15028 |
return; |
| 15029 |
} |
| 15030 |
} |
| 15031 |
|
| 15032 |
|
| 15033 |
function<void(COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites)> redHandlingFunc = [&](COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinalites) { |
| 15034 |
if (!extractedBindings) { |
| 15035 |
extractedBindings = createBindingsForVariableCompositionItems(1, compVarItem, buildingVarItem); |
| 15036 |
} |
| 15037 |
|
| 15038 |
TIndividualInstanceItemDataBinding& reducedBinding = bindings->getBinding(extIdx); |
| 15039 |
extractedBindings->setBinding(0, reducedBinding); |
| 15040 |
|
| 15041 |
if (!linker) { |
| 15042 |
linker = createBindingsLinkerForVariableCompositionItems(extractedBindings, nullptr, compVarItem, buildingVarItem); |
| 15043 |
} else { |
| 15044 |
linker->setInitialCardinality(nullptr); |
| 15045 |
} |
| 15046 |
if (reducedVarMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 15047 |
extractedBindings = nullptr; |
| 15048 |
linker = nullptr; |
| 15049 |
} |
| 15050 |
}; |
| 15051 |
|
| 15052 |
bool mappingProcessed = false; |
| 15053 |
while (extractionItem->requiresMoreVariableMappingsComputation() && (!baseItemDep->isBatchProcessed() || baseItemDep->loadNextBatch())) { |
| 15054 |
|
| 15055 |
while (extractionItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentBindingsCardinalityLinker(false)) { |
| 15056 |
mappingProcessed = true; |
| 15057 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = baseItemDep->getBatchCurrentBindingsCardinalityLinker(true); |
| 15058 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 15059 |
COptimizedComplexVariableIndividualBindingsCardinality* cardinalites = bindingLinker->getInitialCardinalities(); |
| 15060 |
|
| 15061 |
redHandlingFunc(bindings, cardinalites); |
| 15062 |
} |
| 15063 |
|
| 15064 |
|
| 15065 |
while (extractionItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentUpdatedCardinalityLinker(false)) { |
| 15066 |
mappingProcessed = true; |
| 15067 |
baseItemDep->getBatchCurrentUpdatedCardinalityLinker(true); |
| 15068 |
} |
| 15069 |
|
| 15070 |
} |
| 15071 |
|
| 15072 |
reducedVarMapping->incCurrentUpdateId(); |
| 15073 |
|
| 15074 |
bool dependentItemRescheduled = false; |
| 15075 |
dependentItemRescheduled = expectedUpdatedReschedulingDependentItemComputation(baseItemDep, reducedVarMapping, extractionItem, baseItem, compVarItem, buildingVarItem); |
| 15076 |
|
| 15077 |
if (!dependentItemRescheduled && compVarItem->getDependencyUpdatingCount() <= 0) { |
| 15078 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItemDep->isProcessingFinished()); |
| 15079 |
if (mConfExtendedLogging) { |
| 15080 |
LOG(INFO, getDomain(), logTr("Computation step %3 (attempt %4): Extraction computation from %1 mappings of step %5 resulted in %2 mappings.").arg(baseVarMapping->getBindingCount()).arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()).arg(baseItem->getComputationStepId()), this); |
| 15081 |
} |
| 15082 |
} |
| 15083 |
|
| 15084 |
configureDependentComputationIncreaseFactor(dependentItemRescheduled, mappingProcessed, compVarItem); |
| 15085 |
|
| 15086 |
|
| 15087 |
|
| 15088 |
} |
| 15089 |
|
| 15090 |
|
| 15091 |
|
| 15092 |
|
| 15093 |
|
| 15094 |
COptimizedComplexExpressionAnsweringHandler* COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemJoin(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, bool& processing) { |
| 15095 |
COptimizedComplexVariableJoiningItem* joiningItem = (COptimizedComplexVariableJoiningItem*)compVarItem; |
| 15096 |
|
| 15097 |
mJoinComputer->computeVariableMappingsComposition(joiningItem, buildingVarItem, mAnswererContext, processing); |
| 15098 |
|
| 15099 |
if (mConfDebugWriteVariableCompositionItems) { |
| 15100 |
debugWriteVariableMappingToFileWithHeader(buildingVarItem, compVarItem); |
| 15101 |
} |
| 15102 |
|
| 15103 |
//debugWriteVariableMappingToFileWithHeader(buildingVarItem, joiningItem); |
| 15104 |
//if (joiningItem->getComputationStepId() >= 5) { |
| 15105 |
// debugCheckVariableMappingFromFile(buildingVarItem, joiningItem); |
| 15106 |
//} |
| 15107 |
//debugWriteVariableMappingToFile(buildingVarItem, joiningItem); |
| 15108 |
|
| 15109 |
return this; |
| 15110 |
} |
| 15111 |
|
| 15112 |
|
| 15113 |
|
| 15114 |
|
| 15115 |
|
| 15116 |
COptimizedComplexExpressionAnsweringHandler* COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemPropagation(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CAnswererContext* answererContext, bool& processing) { |
| 15117 |
COptimizedComplexVariableRolePropagationAbstractItem* rolePropItem = (COptimizedComplexVariableRolePropagationAbstractItem*)compVarItem; |
| 15118 |
|
| 15119 |
mPropagationComputer->computeVariableMappingsComposition(compVarItem, buildingVarItem, answererContext, processing); |
| 15120 |
|
| 15121 |
if (mConfDebugWriteVariableCompositionItems) { |
| 15122 |
debugWriteVariableMappingToFileWithHeader(buildingVarItem, compVarItem); |
| 15123 |
} |
| 15124 |
|
| 15125 |
//debugWriteVariableMappingToFileWithHeader(buildingVarItem, compVarItem); |
| 15126 |
//if (compVarItem->getComputationStepId() >= 5) { |
| 15127 |
// debugCheckVariableMappingFromFile(buildingVarItem, compVarItem); |
| 15128 |
//} |
| 15129 |
//debugWriteVariableMappingToFile(buildingVarItem, compVarItem); |
| 15130 |
|
| 15131 |
return this; |
| 15132 |
} |
| 15133 |
|
| 15134 |
|
| 15135 |
|
| 15136 |
|
| 15137 |
|
| 15138 |
|
| 15139 |
|
| 15140 |
bool COptimizedComplexExpressionAnsweringHandler::processCompositionItemRequirements(const QList<COntologyProcessingRequirement*>& reqList, COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, CAnswererContext* answererContext) { |
| 15141 |
|
| 15142 |
CAnsweringMessageDataRequirementCompletedRealization* reqCompMess = new CAnsweringMessageDataRequirementCompletedRealization(compVarItem, buildingVarItem); |
| 15143 |
buildingVarItem->incVariableCompositionItemWaitingCount(); |
| 15144 |
processRequirements(answererContext, mOntoAnsweringItem->getOntology(), reqList, reqCompMess); |
| 15145 |
return true; |
| 15146 |
} |
| 15147 |
|
| 15148 |
|
| 15149 |
|
| 15150 |
|
| 15151 |
|
| 15152 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemFromDataLiteralBase(COptimizedComplexVariableCompositionItem* compVarItem, CAnswererContext* answererContext, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 15153 |
COptimizedComplexVariableDataLiteralBaseItem* dataBaseItem = (COptimizedComplexVariableDataLiteralBaseItem*)compVarItem; |
| 15154 |
CRole* dataRole = dataBaseItem->getDataRole(); |
| 15155 |
CIndividualReference indiRef = dataBaseItem->getIndividualReference(); |
| 15156 |
COptimizedComplexVariableIndividualMappings* variableMapping = dataBaseItem->getVariableMapping(); |
| 15157 |
|
| 15158 |
cint64 varIdx = 0; |
| 15159 |
|
| 15160 |
QSet<CDataLiteral*> dataLiteralSet; |
| 15161 |
getInstantiatedDataLiterals(indiRef, dataRole, &dataLiteralSet, answererContext); |
| 15162 |
|
| 15163 |
COptimizedComplexVariableIndividualBindings* binding = nullptr; |
| 15164 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = nullptr; |
| 15165 |
|
| 15166 |
for (CDataLiteral* dataLiteral : dataLiteralSet) { |
| 15167 |
if (!binding) { |
| 15168 |
binding = createBindingsForVariableCompositionItems(1, compVarItem, buildingVarItem); |
| 15169 |
} |
| 15170 |
|
| 15171 |
binding->setBinding(varIdx, dataLiteral); |
| 15172 |
|
| 15173 |
if (!linker) { |
| 15174 |
linker = createBindingsLinkerForVariableCompositionItems(binding, nullptr, compVarItem, buildingVarItem); |
| 15175 |
} |
| 15176 |
if (variableMapping->addInsertingBindingsCardinalityLinker(linker, true)) { |
| 15177 |
binding = nullptr; |
| 15178 |
linker = nullptr; |
| 15179 |
} |
| 15180 |
} |
| 15181 |
|
| 15182 |
variableMapping->incCurrentUpdateId(); |
| 15183 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, true); |
| 15184 |
|
| 15185 |
if (mConfExtendedLogging) { |
| 15186 |
QString roleName = CIRIName::getRecentIRIName(dataRole->getPropertyNameLinker()); |
| 15187 |
LOG(INFO, getDomain(), logTr("Computation step %3 (attempt %4): Initialized %1 mappings for data role %2.").arg(variableMapping->getBindingCount()).arg(roleName).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()), this); |
| 15188 |
} |
| 15189 |
} |
| 15190 |
|
| 15191 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemAbsorptionBasedExtension(COptimizedComplexVariableCompositionItem* compVarItem, bool &processing, COptimizedComplexBuildingIndividualVariableCompositionsItem* buildingVarItem, CAnswererContext* answererContext, bool &continueProcessingBuildingVarItem) { |
| 15192 |
COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem* absBasedItem = (COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem*)compVarItem; |
| 15193 |
bool oneDependentItemRescheduled = false; |
| 15194 |
|
| 15195 |
|
| 15196 |
if (!absBasedItem->isDependentMappingsComputationSchedluled()) { |
| 15197 |
QSet<COptimizedComplexVariableCompositionItem*> scheduledItems; |
| 15198 |
QHash<CExpressionVariable*, COptimizedComplexVariableCompositionItem*>* varCompItemHash = absBasedItem->getVariableExpressionCompositionItemHash(); |
| 15199 |
for (QHash<CExpressionVariable*, COptimizedComplexVariableCompositionItem*>::const_iterator itVarItem = varCompItemHash->constBegin(), itVarItemEnd = varCompItemHash->constEnd(); itVarItem != itVarItemEnd; ++itVarItem) { |
| 15200 |
CExpressionVariable* indiVarExp = itVarItem.key(); |
| 15201 |
COptimizedComplexVariableCompositionItem* varCompItem = itVarItem.value(); |
| 15202 |
if (!varCompItem->isVariableMappingsComputed() && !scheduledItems.contains(varCompItem)) { |
| 15203 |
|
| 15204 |
scheduledItems.insert(varCompItem); |
| 15205 |
bool dependentItemRescheduled = rescheduleVariableCompositionItemComputation(buildingVarItem, compVarItem, varCompItem, -1); |
| 15206 |
|
| 15207 |
if (dependentItemRescheduled && mConfExtendedLogging) { |
| 15208 |
LOG(INFO, getDomain(), logTr("Computation step %1 (attempt %2): Requesting all mappings from step %3.").arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt(false)).arg(varCompItem->getComputationStepId()), this); |
| 15209 |
} |
| 15210 |
oneDependentItemRescheduled |= dependentItemRescheduled; |
| 15211 |
|
| 15212 |
|
| 15213 |
} |
| 15214 |
} |
| 15215 |
absBasedItem->setDependentMappingsComputationSchedluled(true); |
| 15216 |
} |
| 15217 |
|
| 15218 |
|
| 15219 |
if (!oneDependentItemRescheduled) { |
| 15220 |
if (!absBasedItem->isPropatationTestCreated()) { |
| 15221 |
QHash<CExpressionVariable*, COptimizedComplexVariableCompositionItem*>* varCompItemHash = absBasedItem->getVariableExpressionCompositionItemHash(); |
| 15222 |
absBasedItem->setPropatationTestCreated(true); |
| 15223 |
QHash<CConcept*, COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem*>* propagationFinalizationConceptAbsorptionItemHash = mOntoAnsweringItem->getPropagationFinalizationConceptAbsorptionItemHash(); |
| 15224 |
COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* absorptionHanldingQueryPart = absBasedItem->getAbsorptionBasedHandlingData(); |
| 15225 |
QHash<CExpressionVariable*, CVariable*>* variableExpressionVariableHash = absorptionHanldingQueryPart->getVariableExpressionVariableHash(); |
| 15226 |
cint64 steeringVariableBindingsCount = 0; |
| 15227 |
CExpressionVariable* initVarExp = absorptionHanldingQueryPart->getInitializerVariableExpression(); |
| 15228 |
bool supportSplitting = false; |
| 15229 |
cint64 estimatedOverallBindings = 0; |
| 15230 |
for (QHash<CExpressionVariable*, COptimizedComplexVariableCompositionItem*>::const_iterator itVarItem = varCompItemHash->constBegin(), itVarItemEnd = varCompItemHash->constEnd(); itVarItem != itVarItemEnd; ++itVarItem) { |
| 15231 |
CExpressionVariable* indiVarExp = itVarItem.key(); |
| 15232 |
COptimizedComplexVariableCompositionItem* varCompItem = itVarItem.value(); |
| 15233 |
estimatedOverallBindings += varCompItem->getVariableMapping()->getBindingCount(); |
| 15234 |
} |
| 15235 |
double initBindingBucketSize = (double)estimatedOverallBindings / (double)mConfMaxVariableBindingPropagationsInitializationIndividualCount; |
| 15236 |
initBindingBucketSize = qMax(initBindingBucketSize, 10.); |
| 15237 |
initBindingBucketSize = qMin(initBindingBucketSize, 100.); |
| 15238 |
cint64 initBindingBucketCount = initBindingBucketSize; |
| 15239 |
bool splittingInitialized = false; |
| 15240 |
if (estimatedOverallBindings > 100 && absorptionHanldingQueryPart->hasIndividualVariables()) { |
| 15241 |
supportSplitting = true; |
| 15242 |
} |
| 15243 |
|
| 15244 |
|
| 15245 |
|
| 15246 |
for (QHash<CExpressionVariable*, COptimizedComplexVariableCompositionItem*>::const_iterator itVarItem = varCompItemHash->constBegin(), itVarItemEnd = varCompItemHash->constEnd(); itVarItem != itVarItemEnd; ++itVarItem) { |
| 15247 |
CExpressionVariable* indiVarExp = itVarItem.key(); |
| 15248 |
COptimizedComplexVariableCompositionItem* varCompItem = itVarItem.value(); |
| 15249 |
|
| 15250 |
CVariable* variable = variableExpressionVariableHash->value(indiVarExp); |
| 15251 |
QSet<CIndividualReference>*& variableSteeringIndividualBinding = absBasedItem->getVariableSteeringIndividualBindingSet(variable); |
| 15252 |
if (!variableSteeringIndividualBinding) { |
| 15253 |
variableSteeringIndividualBinding = new QSet<CIndividualReference>(); |
| 15254 |
} |
| 15255 |
|
| 15256 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 15257 |
QList<CIndividualReference> indiList; |
| 15258 |
|
| 15259 |
CExpressionVariable* associatedVariableExpression = buildingVarItem->getVariableLastCompositionItemAssociatedVariableExpression(indiVarExp); |
| 15260 |
|
| 15261 |
// TODO: use latest item for variable to identify allowed bindings |
| 15262 |
COptimizedComplexVariableCompositionItemVariableIndexMapping* varIndexMapping = buildingVarItem->getVariableItemIndexMapping(associatedVariableExpression).value(varCompItem); |
| 15263 |
cint64 varPos = -1; |
| 15264 |
cint64 initVarPos = -1; |
| 15265 |
if (varIndexMapping) { |
| 15266 |
for (COptimizedComplexVariableCompositionItemVariableIndexMapping::const_iterator it = varIndexMapping->constBegin(), itEnd = varIndexMapping->constEnd(); it != itEnd; ++it) { |
| 15267 |
if (it.value() == indiVarExp) { |
| 15268 |
varPos = it.key(); |
| 15269 |
} |
| 15270 |
if (it.value() == initVarExp && initVarExp != indiVarExp) { |
| 15271 |
initVarPos = it.key(); |
| 15272 |
} |
| 15273 |
} |
| 15274 |
} |
| 15275 |
if (varPos >= 0) { |
| 15276 |
for (COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinkerIt = varCompItem->getVariableMapping()->getLastAddedBindingsCardinalityLinker(); bindingLinkerIt; bindingLinkerIt = bindingLinkerIt->getNext()) { |
| 15277 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinkerIt->getBindings(); |
| 15278 |
TIndividualInstanceItemDataBinding& instItem = bindings->getBinding(varPos); |
| 15279 |
|
| 15280 |
variableSteeringIndividualBinding->insert(instItem.reference.getIndividualIdentifier()); |
| 15281 |
|
| 15282 |
//indiList.clear(); |
| 15283 |
//CInstanceBindingIndividualCollectionVisitor visitor(&indiList); |
| 15284 |
//sameRealization->visitSameIndividuals(instItem.reference, &visitor); |
| 15285 |
|
| 15286 |
//for (CIndividualReference indiRef : indiList) { |
| 15287 |
// variableSteeringIndividualBinding->insert(indiRef); |
| 15288 |
//} |
| 15289 |
|
| 15290 |
if (supportSplitting && initVarPos >= 0) { |
| 15291 |
if (!splittingInitialized) { |
| 15292 |
absBasedItem->initPreparedSplitPropagationTestControllingItemSize(initBindingBucketCount); |
| 15293 |
} |
| 15294 |
|
| 15295 |
TIndividualInstanceItemDataBinding& initVarInstItem = bindings->getBinding(initVarPos); |
| 15296 |
cint64 initVarInstItemIndiId = initVarInstItem.reference.getIndividualID(); |
| 15297 |
|
| 15298 |
cint64 initVarInstItemIndiHash = 0; |
| 15299 |
if (sizeof(quint64) > sizeof(uint)) { |
| 15300 |
initVarInstItemIndiHash = uint((initVarInstItemIndiId >> (8 * sizeof(uint) - 1)) ^ initVarInstItemIndiId); |
| 15301 |
} else { |
| 15302 |
initVarInstItemIndiHash = uint(initVarInstItemIndiId); |
| 15303 |
} |
| 15304 |
|
| 15305 |
|
| 15306 |
cint64 testingBucketId = initVarInstItemIndiHash % initBindingBucketCount; |
| 15307 |
|
| 15308 |
CAnsweringSplitPropagationTestControllingItem*& splitTestingItem = absBasedItem->getPreparedSplitPropagationTestControllingItem(testingBucketId); |
| 15309 |
if (!splitTestingItem) { |
| 15310 |
splitTestingItem = createSplitPropagationTestControllingItem(absBasedItem, absorptionHanldingQueryPart, nullptr, false); |
| 15311 |
absBasedItem->addReaminingPreparedSplitPropagationTestControllingItem(splitTestingItem); |
| 15312 |
} |
| 15313 |
splitTestingItem->getBaseVariableData()->addIntegrateableVariableBinding(initVarInstItem.reference); |
| 15314 |
splitTestingItem->getVariableData(variable)->addIntegrateableVariableBinding(instItem.reference); |
| 15315 |
} |
| 15316 |
|
| 15317 |
|
| 15318 |
} |
| 15319 |
|
| 15320 |
steeringVariableBindingsCount += variableSteeringIndividualBinding->count(); |
| 15321 |
} |
| 15322 |
|
| 15323 |
|
| 15324 |
} |
| 15325 |
|
| 15326 |
|
| 15327 |
|
| 15328 |
if (absorptionHanldingQueryPart->hasIndividualVariables()) { |
| 15329 |
if (mConfExtendedLogging) { |
| 15330 |
LOG(INFO, getDomain(), logTr("Scheduling marker propagation for absorbed query part based on %1 bindings.").arg(steeringVariableBindingsCount), this); |
| 15331 |
} |
| 15332 |
processing = createVariableBindingPropagationTest(absBasedItem, buildingVarItem, answererContext, continueProcessingBuildingVarItem); |
| 15333 |
} else { |
| 15334 |
if (mConfExtendedLogging) { |
| 15335 |
LOG(INFO, getDomain(), logTr("Testing entailment with prepared upper bounds for absorbed query part."), this); |
| 15336 |
} |
| 15337 |
processing = createAbsorbedQueryPartEntailmentTest(absBasedItem, buildingVarItem, answererContext, continueProcessingBuildingVarItem); |
| 15338 |
} |
| 15339 |
|
| 15340 |
|
| 15341 |
} else { |
| 15342 |
|
| 15343 |
COptimizedComplexVariableIndividualMappings* possibleVarIndiBindings = absBasedItem->getPossibleVariableMapping(); |
| 15344 |
if (possibleVarIndiBindings && possibleVarIndiBindings->getBindingCount() > 0) { |
| 15345 |
QHash<COptimizedComplexVariableIndividualBindingsHasher, COptimizedComplexVariableIndividualBindingsCardinalityLinker*>* testingVarIndiBindings = absBasedItem->getTestingVariableMapping(); |
| 15346 |
if (!testingVarIndiBindings) { |
| 15347 |
testingVarIndiBindings = new QHash<COptimizedComplexVariableIndividualBindingsHasher, COptimizedComplexVariableIndividualBindingsCardinalityLinker*>(); |
| 15348 |
absBasedItem->setTestingVariableMapping(testingVarIndiBindings); |
| 15349 |
} |
| 15350 |
|
| 15351 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* testingVarIndiBindingCardLinker = possibleVarIndiBindings->takeBindingsCardinalityLinker(); |
| 15352 |
testingVarIndiBindings->insert(testingVarIndiBindingCardLinker, testingVarIndiBindingCardLinker); |
| 15353 |
|
| 15354 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 15355 |
processing = createVariableBindingConfirmationTest(absBasedItem, buildingVarItem, testingVarIndiBindingCardLinker, sameRealization, answererContext); |
| 15356 |
buildingVarItem->addComputeVariableMappingItem(absBasedItem); |
| 15357 |
if (possibleVarIndiBindings->getBindingCount() > 0) { |
| 15358 |
continueProcessingBuildingVarItem = true; |
| 15359 |
} |
| 15360 |
|
| 15361 |
} else if (!buildingVarItem->isWaitingVariableBindingsConfirmation()) { |
| 15362 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, true); |
| 15363 |
if (compVarItem->getVariableMapping()->getBindingCount() > 0) { |
| 15364 |
QList<COptimizedComplexVariableAbsorptionBasedHandlingExtensionItem*>* absorptionHanldingQueryExtensionJoiningList = buildingVarItem->getAbsorptionBasedHandlingExtensionItemJoiningList(); |
| 15365 |
absorptionHanldingQueryExtensionJoiningList->append(absBasedItem); |
| 15366 |
} |
| 15367 |
|
| 15368 |
if (mConfExtendedLogging) { |
| 15369 |
LOG(INFO, getDomain(), logTr("Computation step %2 (attempt %3): Obtained %1 mappings via absorbed query entailment tests.").arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()), this); |
| 15370 |
} |
| 15371 |
|
| 15372 |
} |
| 15373 |
|
| 15374 |
} |
| 15375 |
} |
| 15376 |
} |
| 15377 |
|
| 15378 |
void COptimizedComplexExpressionAnsweringHandler::computeVariableCompositionItemDataLiteralExtension(COptimizedComplexVariableCompositionItem* compVarItem, CAnswererContext* answererContext, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 15379 |
COptimizedComplexVariableDataLiteralExtensionItem* dataExtItem = (COptimizedComplexVariableDataLiteralExtensionItem*)compVarItem; |
| 15380 |
COptimizedComplexVariableCompositionItem* baseVarItem = dataExtItem->getBaseItem(); |
| 15381 |
COptimizedComplexVariableCompositionItemDependence* baseItemDep = dataExtItem->getBaseItemDependence(); |
| 15382 |
|
| 15383 |
CRole* dataRole = dataExtItem->getRole(); |
| 15384 |
COptimizedComplexVariableIndividualMappings* baseVariableMapping = baseVarItem->getVariableMapping(); |
| 15385 |
COptimizedComplexVariableIndividualMappings* variableMapping = dataExtItem->getVariableMapping(); |
| 15386 |
|
| 15387 |
CSameRealization* sameRealization = mOntoAnsweringItem->getOntology()->getRealization()->getSameRealization(); |
| 15388 |
|
| 15389 |
// get variable index |
| 15390 |
cint64 varIdx = dataExtItem->getVariableIndex(); |
| 15391 |
cint64 baseBindingSize = baseVariableMapping->getBindingSize(); |
| 15392 |
cint64 newBindingSize = baseVariableMapping->getBindingSize() + 1; |
| 15393 |
|
| 15394 |
cint64* baseBindingMapping = new cint64[newBindingSize]; |
| 15395 |
for (cint64 i = 0; i < baseBindingSize; ++i) { |
| 15396 |
baseBindingMapping[i] = i; |
| 15397 |
} |
| 15398 |
cint64 newVarIdx = baseBindingSize; |
| 15399 |
|
| 15400 |
COptimizedComplexVariableIndividualBindings* extBindings = nullptr; |
| 15401 |
COptimizedComplexVariableIndividualBindingsCardinality* extCardinalites = nullptr; |
| 15402 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* extLinker = nullptr; |
| 15403 |
|
| 15404 |
|
| 15405 |
function<void(COptimizedComplexVariableIndividualBindings* varBinding, COptimizedComplexVariableIndividualBindingsCardinality* varCardinalities)> dataExtHandlingFunc = [&](COptimizedComplexVariableIndividualBindings* varBinding, COptimizedComplexVariableIndividualBindingsCardinality* varCardinalities) { |
| 15406 |
|
| 15407 |
CRealizationIndividualInstanceItemReference instItem = varBinding->getBinding(varIdx).reference; |
| 15408 |
|
| 15409 |
QList<CIndividualReference> indiList; |
| 15410 |
CInstanceBindingIndividualCollectionVisitor visitor(&indiList); |
| 15411 |
sameRealization->visitSameIndividuals(instItem, &visitor); |
| 15412 |
|
| 15413 |
QSet<CDataLiteral*> dataLiteralSet; |
| 15414 |
for (CIndividualReference indi : indiList) { |
| 15415 |
getInstantiatedDataLiterals(indi, dataRole, &dataLiteralSet, answererContext); |
| 15416 |
} |
| 15417 |
|
| 15418 |
for (CDataLiteral* dataLiteral : dataLiteralSet) { |
| 15419 |
|
| 15420 |
if (!extBindings) { |
| 15421 |
extBindings = createBindingsForVariableCompositionItems(newBindingSize, compVarItem, buildingVarItem); |
| 15422 |
} |
| 15423 |
if (!extCardinalites && varCardinalities) { |
| 15424 |
extCardinalites = createBindingsCardinalitesForVariableCompositionItems(compVarItem, buildingVarItem); |
| 15425 |
} |
| 15426 |
if (varCardinalities) { |
| 15427 |
*extCardinalites = *varCardinalities; |
| 15428 |
} |
| 15429 |
if (extCardinalites) { |
| 15430 |
extCardinalites->setCardinalityUpdateId(-1); |
| 15431 |
} |
| 15432 |
|
| 15433 |
for (cint64 i = 0; i < baseBindingSize; ++i) { |
| 15434 |
extBindings->setBinding(baseBindingMapping[i], varBinding->getBinding(i)); |
| 15435 |
} |
| 15436 |
extBindings->setBinding(newVarIdx, dataLiteral); |
| 15437 |
|
| 15438 |
if (!extLinker) { |
| 15439 |
extLinker = createBindingsLinkerForVariableCompositionItems(extBindings, extCardinalites, compVarItem, buildingVarItem); |
| 15440 |
} else { |
| 15441 |
extLinker->setInitialCardinality(extCardinalites); |
| 15442 |
} |
| 15443 |
if (variableMapping->addInsertingBindingsCardinalityLinker(extLinker, true)) { |
| 15444 |
extBindings = nullptr; |
| 15445 |
extCardinalites = nullptr; |
| 15446 |
extLinker = nullptr; |
| 15447 |
} else { |
| 15448 |
extCardinalites = extLinker->getCurrentCardinalities(); |
| 15449 |
} |
| 15450 |
|
| 15451 |
} |
| 15452 |
}; |
| 15453 |
|
| 15454 |
|
| 15455 |
bool mappingProcessed = false; |
| 15456 |
while (dataExtItem->requiresMoreVariableMappingsComputation() && (!baseItemDep->isBatchProcessed() || baseItemDep->loadNextBatch())) { |
| 15457 |
|
| 15458 |
while (dataExtItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentBindingsCardinalityLinker(false)) { |
| 15459 |
mappingProcessed = true; |
| 15460 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = baseItemDep->getBatchCurrentBindingsCardinalityLinker(true); |
| 15461 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 15462 |
COptimizedComplexVariableIndividualBindingsCardinality* cardinalites = bindingLinker->getInitialCardinalities(); |
| 15463 |
|
| 15464 |
dataExtHandlingFunc(bindings, cardinalites); |
| 15465 |
} |
| 15466 |
|
| 15467 |
|
| 15468 |
while (dataExtItem->requiresMoreVariableMappingsComputation() && baseItemDep->getBatchCurrentUpdatedCardinalityLinker(false)) { |
| 15469 |
mappingProcessed = true; |
| 15470 |
COptimizedComplexVariableIndividualUpdateCardinalityLinker* updatedCardinalityLinker = baseItemDep->getBatchCurrentUpdatedCardinalityLinker(true); |
| 15471 |
COptimizedComplexVariableIndividualBindingsCardinality* prevCardinalites = updatedCardinalityLinker->getPreviousCardinality(); |
| 15472 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* bindingLinker = updatedCardinalityLinker->getUpdatedBindingsCardinalityLinker(); |
| 15473 |
COptimizedComplexVariableIndividualBindingsCardinality* newCardinalites = updatedCardinalityLinker->getNewCardinality(); |
| 15474 |
COptimizedComplexVariableIndividualBindings* bindings = bindingLinker->getBindings(); |
| 15475 |
|
| 15476 |
COptimizedComplexVariableIndividualBindingsCardinality tmpDiffCardinalites = *newCardinalites; |
| 15477 |
tmpDiffCardinalites.substractCardinalities(prevCardinalites); |
| 15478 |
|
| 15479 |
dataExtHandlingFunc(bindings, &tmpDiffCardinalites); |
| 15480 |
} |
| 15481 |
|
| 15482 |
} |
| 15483 |
variableMapping->incCurrentUpdateId(); |
| 15484 |
|
| 15485 |
|
| 15486 |
bool dependentItemRescheduled = false; |
| 15487 |
dependentItemRescheduled = expectedUpdatedReschedulingDependentItemComputation(baseItemDep, variableMapping, dataExtItem, baseVarItem, compVarItem, buildingVarItem); |
| 15488 |
|
| 15489 |
if (!dependentItemRescheduled && compVarItem->getDependencyUpdatingCount() <= 0) { |
| 15490 |
|
| 15491 |
finishVariableCompositionItemComputation(buildingVarItem, compVarItem, baseItemDep->isProcessingFinished()); |
| 15492 |
|
| 15493 |
if (mConfExtendedLogging) { |
| 15494 |
QString roleName = CIRIName::getRecentIRIName(dataRole->getPropertyNameLinker()); |
| 15495 |
LOG(INFO, getDomain(), logTr("Computation step %4 (attempt %5): Extending %1 mappings via data role %2 resulted in %3 mappings.").arg(variableMapping->getBindingCount()).arg(roleName).arg(compVarItem->getVariableMapping()->getBindingCount()).arg(compVarItem->getComputationStepId()).arg(compVarItem->getComputationAttempt()), this); |
| 15496 |
} |
| 15497 |
} |
| 15498 |
|
| 15499 |
configureDependentComputationIncreaseFactor(dependentItemRescheduled, mappingProcessed, dataExtItem); |
| 15500 |
|
| 15501 |
//if (variableMapping->count() == 0) { |
| 15502 |
// bool debug = true; |
| 15503 |
//} |
| 15504 |
//debugCheckVariableMappingContainsSolution(buildingVarItem, compVarItem); |
| 15505 |
} |
| 15506 |
|
| 15507 |
void COptimizedComplexExpressionAnsweringHandler::configureDependentComputationIncreaseFactor(bool dependentItemRescheduled, bool mappingProcessed, COptimizedComplexVariableCompositionItem* compVarItem) { |
| 15508 |
if (dependentItemRescheduled && mappingProcessed && compVarItem->requiresMoreVariableMappingsComputation() && !compVarItem->isVariableMappingsComputed()) { |
| 15509 |
compVarItem->increaseRepeatedRequirementInsufficientDependencyComputationIncreaseFactor(mConfMappingsRepeatedlyInsufficientDependencyComputationIncreasingFactor); |
| 15510 |
} else if (!compVarItem->requiresMoreVariableMappingsComputation()) { |
| 15511 |
compVarItem->setRepeatedRequirementInsufficientDependencyComputationIncreaseFactor(1.); |
| 15512 |
} |
| 15513 |
} |
| 15514 |
|
| 15515 |
|
| 15516 |
|
| 15517 |
|
| 15518 |
|
| 15519 |
|
| 15520 |
|
| 15521 |
|
| 15522 |
COptimizedComplexVariableIndividualBindings* COptimizedComplexExpressionAnsweringHandler::createBindingsForVariableCompositionItems(cint64 bindingSize, COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 15523 |
COptimizedComplexVariableIndividualMappings* variableMapping = compVarItem->getVariableMapping(); |
| 15524 |
CMemoryAllocationManager* memMan = variableMapping->getBindingsMemoryAllocationManager(); |
| 15525 |
|
| 15526 |
TIndividualInstanceItemDataBinding* bindingArray = CObjectAllocator<TIndividualInstanceItemDataBinding>::allocateAndConstructArray(memMan, bindingSize); |
| 15527 |
COptimizedComplexVariableIndividualBindings* bindings = CObjectAllocator<COptimizedComplexVariableIndividualBindings>::allocateAndConstruct(memMan); |
| 15528 |
bindings->initIndividualBindings(bindingSize, bindingArray); |
| 15529 |
return bindings; |
| 15530 |
} |
| 15531 |
|
| 15532 |
|
| 15533 |
|
| 15534 |
COptimizedComplexVariableIndividualBindingsCardinality* COptimizedComplexExpressionAnsweringHandler::createBindingsCardinalitesForVariableCompositionItems(COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 15535 |
COptimizedComplexVariableIndividualMappings* variableMapping = compVarItem->getVariableMapping(); |
| 15536 |
CMemoryAllocationManager* memMan = variableMapping->getBindingsMemoryAllocationManager(); |
| 15537 |
COptimizedComplexVariableIndividualBindingsCardinality* bindingsCard = CObjectAllocator<COptimizedComplexVariableIndividualBindingsCardinality>::allocateAndConstruct(memMan); |
| 15538 |
return bindingsCard; |
| 15539 |
} |
| 15540 |
|
| 15541 |
|
| 15542 |
|
| 15543 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* COptimizedComplexExpressionAnsweringHandler::createBindingsLinkerForVariableCompositionItems(COptimizedComplexVariableIndividualBindings* bindings, COptimizedComplexVariableIndividualBindingsCardinality* cardinality, COptimizedComplexVariableCompositionItem* compVarItem, COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem) { |
| 15544 |
COptimizedComplexVariableIndividualMappings* variableMapping = compVarItem->getVariableMapping(); |
| 15545 |
CMemoryAllocationManager* memMan = variableMapping->getBindingsMemoryAllocationManager(); |
| 15546 |
COptimizedComplexVariableIndividualBindingsCardinalityLinker* linker = CObjectAllocator<COptimizedComplexVariableIndividualBindingsCardinalityLinker>::allocateAndConstruct(memMan); |
| 15547 |
linker->initBindingsCardinalityLinker(bindings, cardinality); |
| 15548 |
return linker; |
| 15549 |
} |
| 15550 |
|
| 15551 |
|
| 15552 |
|
| 15553 |
|
| 15554 |
|
| 15555 |
|
| 15556 |
bool COptimizedComplexExpressionAnsweringHandler::queueComputedInstancesCacheMemoryConsumptionUpdate(COptimizedComplexConceptItem* conceptItem) { |
| 15557 |
|
| 15558 |
bool updated = updateAnswersCacheConsumptionForItem(conceptItem); |
| 15559 |
|
| 15560 |
if (!conceptItem->isCacheUpdateQueued()) { |
| 15561 |
conceptItem->setCacheUpdateQueued(true); |
| 15562 |
QList<COptimizedComplexConceptItem*>* updateList = mOntoAnsweringItem->getCacheAnswersComplexConceptItemUpdateList(); |
| 15563 |
updateList->append(conceptItem); |
| 15564 |
updated = true; |
| 15565 |
} |
| 15566 |
return updated; |
| 15567 |
} |
| 15568 |
|
| 15569 |
|
| 15570 |
|
| 15571 |
bool COptimizedComplexExpressionAnsweringHandler::queueAnswersCacheItemUpdate(COptimizedComplexVariableCompositionItem* varCompItem) { |
| 15572 |
|
| 15573 |
bool updated = updateAnswersCacheConsumptionForItem(varCompItem); |
| 15574 |
|
| 15575 |
|
| 15576 |
if (!varCompItem->isCacheUpdateQueued()) { |
| 15577 |
varCompItem->setCacheUpdateQueued(true); |
| 15578 |
QMap<cint64, QList<COptimizedComplexVariableCompositionItem*>* >* cacheAnswersUpdateDepthVariableCompositionItemsMap = mOntoAnsweringItem->getCacheAnswersUpdateDepthVariableCompositionItemsMap(); |
| 15579 |
QList<COptimizedComplexVariableCompositionItem*>* queuedItemList = cacheAnswersUpdateDepthVariableCompositionItemsMap->value(-varCompItem->getComputationItemDepth()); |
| 15580 |
if (!queuedItemList) { |
| 15581 |
queuedItemList = new QList<COptimizedComplexVariableCompositionItem *>(); |
| 15582 |
cacheAnswersUpdateDepthVariableCompositionItemsMap->insert(-varCompItem->getComputationItemDepth(), queuedItemList); |
| 15583 |
} |
| 15584 |
queuedItemList->append(varCompItem); |
| 15585 |
if (varCompItem->getCompositionType() == COptimizedComplexVariableCompositionItem::CONCEPT_BASE) { |
| 15586 |
COptimizedComplexVariableConceptBaseItem* conBaseVarCompItem = (COptimizedComplexVariableConceptBaseItem*)varCompItem; |
| 15587 |
if (conBaseVarCompItem) { |
| 15588 |
queueComputedInstancesCacheMemoryConsumptionUpdate(conBaseVarCompItem->getConceptItem()); |
| 15589 |
} |
| 15590 |
} |
| 15591 |
|
| 15592 |
|
| 15593 |
QList<COptimizedComplexVariableCompositionItem*> dependentUpdateItemList; |
| 15594 |
QList<COptimizedComplexVariableCompositionItem*>* dependentItemList = varCompItem->getComputationDependentItemList(); |
| 15595 |
dependentUpdateItemList.append(*dependentItemList); |
| 15596 |
|
| 15597 |
while (!dependentUpdateItemList.isEmpty()) { |
| 15598 |
COptimizedComplexVariableCompositionItem* updateItem = dependentUpdateItemList.takeFirst(); |
| 15599 |
if (!updateItem->isCacheUpdateQueued() && updateItem->isVariableMappingsComputationStarted()) { |
| 15600 |
updateItem->setCacheUpdateQueued(true); |
| 15601 |
QList<COptimizedComplexVariableCompositionItem*>* queuedItemList = cacheAnswersUpdateDepthVariableCompositionItemsMap->value(-updateItem->getComputationItemDepth()); |
| 15602 |
if (!queuedItemList) { |
| 15603 |
queuedItemList = new QList<COptimizedComplexVariableCompositionItem *>(); |
| 15604 |
cacheAnswersUpdateDepthVariableCompositionItemsMap->insert(-updateItem->getComputationItemDepth(), queuedItemList); |
| 15605 |
} |
| 15606 |
queuedItemList->append(updateItem); |
| 15607 |
|
| 15608 |
if (updateItem->getCompositionType() == COptimizedComplexVariableCompositionItem::CONCEPT_BASE) { |
| 15609 |
COptimizedComplexVariableConceptBaseItem* conBaseVarCompItem = (COptimizedComplexVariableConceptBaseItem*)updateItem; |
| 15610 |
if (conBaseVarCompItem) { |
| 15611 |
queueComputedInstancesCacheMemoryConsumptionUpdate(conBaseVarCompItem->getConceptItem()); |
| 15612 |
} |
| 15613 |
} |
| 15614 |
|
| 15615 |
if (!updateItem->isVariableMappingsComputed()) { |
| 15616 |
dependentUpdateItemList.append(*updateItem->getComputationDependentItemList()); |
| 15617 |
} |
| 15618 |
} |
| 15619 |
} |
| 15620 |
|
| 15621 |
updated = true; |
| 15622 |
|
| 15623 |
} |
| 15624 |
return updated; |
| 15625 |
} |
| 15626 |
|
| 15627 |
|
| 15628 |
|
| 15629 |
bool COptimizedComplexExpressionAnsweringHandler::updateQueuedAnswersCacheItems() { |
| 15630 |
QMap<cint64, QList<COptimizedComplexVariableCompositionItem*>* >* cacheAnswersUpdateDepthVariableCompositionItemsMap = mOntoAnsweringItem->getCacheAnswersUpdateDepthVariableCompositionItemsMap(); |
| 15631 |
QMap<double, CCacheAnswersWeightedUsageCostItemData>* cacheAnswersWeightedUsageCostItemSetDataMap = mOntoAnsweringItem->getCacheAnswersWeightedUsageCostItemSetDataMap(); |
| 15632 |
while (!cacheAnswersUpdateDepthVariableCompositionItemsMap->isEmpty()) { |
| 15633 |
QMap<cint64, QList<COptimizedComplexVariableCompositionItem*>* >::iterator it = cacheAnswersUpdateDepthVariableCompositionItemsMap->begin(); |
| 15634 |
QList<COptimizedComplexVariableCompositionItem*>* updateItemList = it.value(); |
| 15635 |
|
| 15636 |
for (COptimizedComplexVariableCompositionItem* updateItem : *updateItemList) { |
| 15637 |
updateItem->setCacheUpdateQueued(false); |
| 15638 |
|
| 15639 |
// collect costs of all incomplete computed successors |
| 15640 |
double sumCost = 0; |
| 15641 |
for (COptimizedComplexVariableCompositionItem* succItem : *updateItem->getComputationSuccessorItemSet()) { |
| 15642 |
if (!succItem->isVariableMappingsComputed()) { |
| 15643 |
double cost = succItem->getCacheDescendantsIncompleteComputationCostSum() + succItem->getComputationCost(); |
| 15644 |
sumCost += cost; |
| 15645 |
} |
| 15646 |
} |
| 15647 |
updateItem->setCacheDescendantsIncompleteComputationCostSum(sumCost); |
| 15648 |
|
| 15649 |
|
| 15650 |
double totalCost = updateItem->getComputationCost() + sumCost; |
| 15651 |
double usageWeightFactor = updateItem->getCacheWeightedUsageFactor(); |
| 15652 |
|
| 15653 |
double newCacheInstalledCostWeightedUsage = (mConfAnswersCacheCostBaseValue + totalCost) * usageWeightFactor; |
| 15654 |
|
| 15655 |
double lastCacheInstalledCostWeightedUsage = updateItem->getLastCacheInstalledCostWeightedUsage(); |
| 15656 |
if (newCacheInstalledCostWeightedUsage != lastCacheInstalledCostWeightedUsage) { |
| 15657 |
if (lastCacheInstalledCostWeightedUsage != -1) { |
| 15658 |
CCacheAnswersWeightedUsageCostItemData& itemSetData = cacheAnswersWeightedUsageCostItemSetDataMap->operator[](lastCacheInstalledCostWeightedUsage); |
| 15659 |
QSet<COptimizedComplexVariableCompositionItem*>* cacheAnswersCountVarCompItemSet = itemSetData.getComplexVariableItemSet(false); |
| 15660 |
if (cacheAnswersCountVarCompItemSet) { |
| 15661 |
cacheAnswersCountVarCompItemSet->remove(updateItem); |
| 15662 |
if (itemSetData.isEmpty()) { |
| 15663 |
cacheAnswersWeightedUsageCostItemSetDataMap->remove(lastCacheInstalledCostWeightedUsage); |
| 15664 |
} |
| 15665 |
} |
| 15666 |
} |
| 15667 |
CCacheAnswersWeightedUsageCostItemData& itemSetData = cacheAnswersWeightedUsageCostItemSetDataMap->operator[](newCacheInstalledCostWeightedUsage); |
| 15668 |
itemSetData.addItem(updateItem); |
| 15669 |
updateItem->setLastCacheInstalledCostWeightedUsage(newCacheInstalledCostWeightedUsage); |
| 15670 |
} |
| 15671 |
|
| 15672 |
} |
| 15673 |
delete updateItemList; |
| 15674 |
cacheAnswersUpdateDepthVariableCompositionItemsMap->erase(it); |
| 15675 |
} |
| 15676 |
|
| 15677 |
|
| 15678 |
|
| 15679 |
QList<COptimizedComplexConceptItem*>* updateList = mOntoAnsweringItem->getCacheAnswersComplexConceptItemUpdateList(); |
| 15680 |
while (!updateList->isEmpty()) { |
| 15681 |
COptimizedComplexConceptItem* compConItem = updateList->takeFirst(); |
| 15682 |
compConItem->setCacheUpdateQueued(false); |
| 15683 |
|
| 15684 |
double computationCost = compConItem->getComputationCost(); |
| 15685 |
COptimizedComplexVariableConceptBaseItem* varConBaseItem = compConItem->getVariableConceptBaseItem(); |
| 15686 |
if (varConBaseItem && !varConBaseItem->isVariableMappingsComputed()) { |
| 15687 |
double descendantsCosts = varConBaseItem->getCacheDescendantsIncompleteComputationCostSum(); |
| 15688 |
descendantsCosts += varConBaseItem->getComputationCost(); |
| 15689 |
computationCost += descendantsCosts; |
| 15690 |
} |
| 15691 |
|
| 15692 |
double usageWeightFactor = compConItem->getCacheWeightedUsageFactor(); |
| 15693 |
double newCacheInstalledCostWeightedUsage = (mConfAnswersCacheCostBaseValue + computationCost) * usageWeightFactor; |
| 15694 |
|
| 15695 |
double lastCacheInstalledCostWeightedUsage = compConItem->getLastCacheInstalledCostWeightedUsage(); |
| 15696 |
if (newCacheInstalledCostWeightedUsage != lastCacheInstalledCostWeightedUsage) { |
| 15697 |
if (lastCacheInstalledCostWeightedUsage != -1) { |
| 15698 |
CCacheAnswersWeightedUsageCostItemData& itemSetData = cacheAnswersWeightedUsageCostItemSetDataMap->operator[](lastCacheInstalledCostWeightedUsage); |
| 15699 |
QSet<COptimizedComplexConceptItem*>* cacheAnswersCountCompConCompItemSet = itemSetData.getComplexConceptItemSet(false); |
| 15700 |
if (cacheAnswersCountCompConCompItemSet) { |
| 15701 |
cacheAnswersCountCompConCompItemSet->remove(compConItem); |
| 15702 |
if (itemSetData.isEmpty()) { |
| 15703 |
cacheAnswersWeightedUsageCostItemSetDataMap->remove(lastCacheInstalledCostWeightedUsage); |
| 15704 |
} |
| 15705 |
} |
| 15706 |
} |
| 15707 |
CCacheAnswersWeightedUsageCostItemData& itemSetData = cacheAnswersWeightedUsageCostItemSetDataMap->operator[](newCacheInstalledCostWeightedUsage); |
| 15708 |
itemSetData.addItem(compConItem); |
| 15709 |
compConItem->setLastCacheInstalledCostWeightedUsage(newCacheInstalledCostWeightedUsage); |
| 15710 |
} |
| 15711 |
|
| 15712 |
} |
| 15713 |
|
| 15714 |
|
| 15715 |
return true; |
| 15716 |
} |
| 15717 |
|
| 15718 |
|
| 15719 |
|
| 15720 |
|
| 15721 |
bool COptimizedComplexExpressionAnsweringHandler::updateAnswersCacheConsumptionForItem(COptimizedComplexConceptItem* compConItem) { |
| 15722 |
bool updated = false; |
| 15723 |
COptimizedComplexConceptInstanziatedIndividualItemHash* knownInstItemsHash = compConItem->getKnownInstanceItems(); |
| 15724 |
cint64 currentInstanceCount = 0; |
| 15725 |
if (knownInstItemsHash) { |
| 15726 |
currentInstanceCount = knownInstItemsHash->size(); |
| 15727 |
} |
| 15728 |
cint64 lastInstanceCacheReportedCount = compConItem->getLastConceptInstancesCacheReportedCount(); |
| 15729 |
|
| 15730 |
if (lastInstanceCacheReportedCount != currentInstanceCount) { |
| 15731 |
cint64 currentVariableMappingCacheReportedCount = mOntoAnsweringItem->getCacheAnswersCount(); |
| 15732 |
if (lastInstanceCacheReportedCount != -1) { |
| 15733 |
currentVariableMappingCacheReportedCount -= lastInstanceCacheReportedCount; |
| 15734 |
} |
| 15735 |
currentVariableMappingCacheReportedCount += currentInstanceCount; |
| 15736 |
mOntoAnsweringItem->setCacheAnswersCount(currentVariableMappingCacheReportedCount); |
| 15737 |
compConItem->setLastConceptInstancesCacheReportedCount(currentInstanceCount); |
| 15738 |
updated = true; |
| 15739 |
} |
| 15740 |
|
| 15741 |
|
| 15742 |
cint64 currentInstanceMemorySize = compConItem->getMemoryConsumption(); |
| 15743 |
cint64 lastInstanceCacheReportedSize = compConItem->getLastConceptInstancesCacheReportedSize(); |
| 15744 |
if (lastInstanceCacheReportedSize != currentInstanceMemorySize) { |
| 15745 |
cint64 currentVariableMappingCacheReportedSize = mOntoAnsweringItem->getCacheAnswersSizeBytes(); |
| 15746 |
if (lastInstanceCacheReportedSize != -1) { |
| 15747 |
currentVariableMappingCacheReportedSize -= lastInstanceCacheReportedSize; |
| 15748 |
} |
| 15749 |
currentVariableMappingCacheReportedSize += currentInstanceMemorySize; |
| 15750 |
mOntoAnsweringItem->setCacheAnswersSizeBytes(currentVariableMappingCacheReportedSize); |
| 15751 |
compConItem->setLastConceptInstancesCacheReportedSize(currentInstanceMemorySize); |
| 15752 |
updated = true; |
| 15753 |
} |
| 15754 |
|
| 15755 |
return updated; |
| 15756 |
} |
| 15757 |
|
| 15758 |
bool COptimizedComplexExpressionAnsweringHandler::updateAnswersCacheConsumptionForItem(COptimizedComplexVariableCompositionItem* varCompItem) { |
| 15759 |
bool updated = false; |
| 15760 |
COptimizedComplexVariableIndividualMappings* variableMapping = varCompItem->getVariableMapping(); |
| 15761 |
variableMapping->updateBindingsMemoryConsumption(); |
| 15762 |
cint64 currentBindingCount = variableMapping->getBindingCount(); |
| 15763 |
cint64 currentBindingMemorySize = variableMapping->getBindingsMemoryUsage(); |
| 15764 |
cint64 lastVariableMappingCacheReportedCount = varCompItem->getLastVariableMappingCacheReportedCount(); |
| 15765 |
cint64 lastVariableMappingCacheReportedSize = varCompItem->getLastVariableMappingCacheReportedSize(); |
| 15766 |
|
| 15767 |
if (lastVariableMappingCacheReportedCount != currentBindingCount) { |
| 15768 |
cint64 currentVariableMappingCacheReportedCount = mOntoAnsweringItem->getCacheAnswersCount(); |
| 15769 |
if (lastVariableMappingCacheReportedCount != -1) { |
| 15770 |
currentVariableMappingCacheReportedCount -= lastVariableMappingCacheReportedCount; |
| 15771 |
} |
| 15772 |
currentVariableMappingCacheReportedCount += currentBindingCount; |
| 15773 |
mOntoAnsweringItem->setCacheAnswersCount(currentVariableMappingCacheReportedCount); |
| 15774 |
varCompItem->setLastVariableMappingCacheReportedCount(currentBindingCount); |
| 15775 |
updated = true; |
| 15776 |
} |
| 15777 |
|
| 15778 |
if (lastVariableMappingCacheReportedSize != currentBindingMemorySize) { |
| 15779 |
cint64 currentVariableMappingCacheReportedSize = mOntoAnsweringItem->getCacheAnswersSizeBytes(); |
| 15780 |
if (lastVariableMappingCacheReportedSize != -1) { |
| 15781 |
currentVariableMappingCacheReportedSize -= lastVariableMappingCacheReportedSize; |
| 15782 |
} |
| 15783 |
currentVariableMappingCacheReportedSize += currentBindingMemorySize; |
| 15784 |
mOntoAnsweringItem->setCacheAnswersSizeBytes(currentVariableMappingCacheReportedSize); |
| 15785 |
varCompItem->setLastVariableMappingCacheReportedSize(currentBindingMemorySize); |
| 15786 |
updated = true; |
| 15787 |
} |
| 15788 |
|
| 15789 |
return updated; |
| 15790 |
} |
| 15791 |
|
| 15792 |
bool COptimizedComplexExpressionAnsweringHandler::increaseUsageWeight() { |
| 15793 |
QMap<double, CCacheAnswersWeightedUsageCostItemData>* cacheAnswersWeightedUsageCostItemSetDataMap = mOntoAnsweringItem->getCacheAnswersWeightedUsageCostItemSetDataMap(); |
| 15794 |
double weight = mOntoAnsweringItem->getNextUsageWeight(); |
| 15795 |
weight = weight * mConfAnswersCacheUsageWeightIncrease; |
| 15796 |
if (weight > 1000000) { |
| 15797 |
double redFactor = weight; |
| 15798 |
weight = 1; |
| 15799 |
QSet<COptimizedComplexVariableCompositionItem*>* container = mOntoAnsweringItem->getVariableCompositionItemContainer(); |
| 15800 |
for (COptimizedComplexVariableCompositionItem* item : *container) { |
| 15801 |
double itemWeightUsage = item->getCacheWeightedUsageFactor(); |
| 15802 |
itemWeightUsage = itemWeightUsage / redFactor; |
| 15803 |
item->setCacheWeightedUsageFactor(itemWeightUsage); |
| 15804 |
double lastCacheInstalledCostWeightedUsage = item->getLastCacheInstalledCostWeightedUsage(); |
| 15805 |
if (lastCacheInstalledCostWeightedUsage != -1) { |
| 15806 |
double totalCost = item->getComputationCost() + item->getCacheDescendantsIncompleteComputationCostSum(); |
| 15807 |
double newCacheInstalledCostWeightedUsage = (mConfAnswersCacheCostBaseValue + totalCost) * itemWeightUsage; |
| 15808 |
|
| 15809 |
CCacheAnswersWeightedUsageCostItemData& lastItemSetData = cacheAnswersWeightedUsageCostItemSetDataMap->operator[](lastCacheInstalledCostWeightedUsage); |
| 15810 |
QSet<COptimizedComplexVariableCompositionItem*>* cacheAnswersCountVarCompItemSet = lastItemSetData.getComplexVariableItemSet(false); |
| 15811 |
if (cacheAnswersCountVarCompItemSet) { |
| 15812 |
cacheAnswersCountVarCompItemSet->remove(item); |
| 15813 |
if (lastItemSetData.isEmpty()) { |
| 15814 |
cacheAnswersWeightedUsageCostItemSetDataMap->remove(lastCacheInstalledCostWeightedUsage); |
| 15815 |
} |
| 15816 |
} |
| 15817 |
|
| 15818 |
CCacheAnswersWeightedUsageCostItemData& newItemSetData = cacheAnswersWeightedUsageCostItemSetDataMap->operator[](newCacheInstalledCostWeightedUsage); |
| 15819 |
newItemSetData.addItem(item); |
| 15820 |
|
| 15821 |
} |
| 15822 |
} |
| 15823 |
|
| 15824 |
|
| 15825 |
QSet<COptimizedComplexConceptItem*>* conItemContainer = mOntoAnsweringItem->getComplexConceptItemContainer(); |
| 15826 |
for (COptimizedComplexConceptItem* item : *conItemContainer) { |
| 15827 |
double itemWeightUsage = item->getCacheWeightedUsageFactor(); |
| 15828 |
itemWeightUsage = itemWeightUsage / redFactor; |
| 15829 |
item->setCacheWeightedUsageFactor(itemWeightUsage); |
| 15830 |
double lastCacheInstalledCostWeightedUsage = item->getLastCacheInstalledCostWeightedUsage(); |
| 15831 |
if (lastCacheInstalledCostWeightedUsage != -1) { |
| 15832 |
|
| 15833 |
double computationCost = item->getComputationCost(); |
| 15834 |
COptimizedComplexVariableConceptBaseItem* varConBaseItem = item->getVariableConceptBaseItem(); |
| 15835 |
if (varConBaseItem) { |
| 15836 |
double descendantsCosts = varConBaseItem->getCacheDescendantsIncompleteComputationCostSum(); |
| 15837 |
descendantsCosts += varConBaseItem->getComputationCost(); |
| 15838 |
computationCost += descendantsCosts; |
| 15839 |
} |
| 15840 |
|
| 15841 |
double newCacheInstalledCostWeightedUsage = (mConfAnswersCacheCostBaseValue + computationCost) * itemWeightUsage; |
| 15842 |
|
| 15843 |
CCacheAnswersWeightedUsageCostItemData& lastItemSetData = cacheAnswersWeightedUsageCostItemSetDataMap->operator[](lastCacheInstalledCostWeightedUsage); |
| 15844 |
QSet<COptimizedComplexConceptItem*>* cacheAnswersCountVarCompItemSet = lastItemSetData.getComplexConceptItemSet(false); |
| 15845 |
if (cacheAnswersCountVarCompItemSet) { |
| 15846 |
cacheAnswersCountVarCompItemSet->remove(item); |
| 15847 |
if (lastItemSetData.isEmpty()) { |
| 15848 |
cacheAnswersWeightedUsageCostItemSetDataMap->remove(lastCacheInstalledCostWeightedUsage); |
| 15849 |
} |
| 15850 |
} |
| 15851 |
|
| 15852 |
CCacheAnswersWeightedUsageCostItemData& newItemSetData = cacheAnswersWeightedUsageCostItemSetDataMap->operator[](newCacheInstalledCostWeightedUsage); |
| 15853 |
newItemSetData.addItem(item); |
| 15854 |
|
| 15855 |
} |
| 15856 |
} |
| 15857 |
} |
| 15858 |
mOntoAnsweringItem->setNextUsageWeight(weight); |
| 15859 |
return true; |
| 15860 |
} |
| 15861 |
|
| 15862 |
bool COptimizedComplexExpressionAnsweringHandler::cleanUpAnswersCache(bool queryProcessingFinished) { |
| 15863 |
bool cleaned = false; |
| 15864 |
cint64 clearedVarCompItemCount = 0; |
| 15865 |
cint64 prevCacheSize = mOntoAnsweringItem->getCacheAnswersSizeBytes(); |
| 15866 |
if (queryProcessingFinished) { |
| 15867 |
mOntoAnsweringItem->setDeleteMoreCacheEntriesWhileQueryProcessing(true); |
| 15868 |
} |
| 15869 |
if ((queryProcessingFinished || mOntoAnsweringItem->canDeleteMoreCacheEntriesWhileQueryProcessing()) && (mConfAnswersCacheMaximumSizeBytes != -1 && mOntoAnsweringItem->getCacheAnswersSizeBytes() > mConfAnswersCacheMaximumSizeBytes || |
| 15870 |
mConfAnswersCacheMaximumCount != -1 && mOntoAnsweringItem->getCacheAnswersCount() > mConfAnswersCacheMaximumCount)) { |
| 15871 |
|
| 15872 |
updateQueuedAnswersCacheItems(); |
| 15873 |
QMap<double, CCacheAnswersWeightedUsageCostItemData>* cacheAnswersWeightedUsageCostItemSetDataMap = mOntoAnsweringItem->getCacheAnswersWeightedUsageCostItemSetDataMap(); |
| 15874 |
QMap<double, CCacheAnswersWeightedUsageCostItemData>::iterator it = cacheAnswersWeightedUsageCostItemSetDataMap->begin(); |
| 15875 |
while ((mConfAnswersCacheMaximumSizeBytes != -1 && mOntoAnsweringItem->getCacheAnswersSizeBytes() > mConfAnswersCacheMaximumSizeBytes || |
| 15876 |
mConfAnswersCacheMaximumCount != -1 && mOntoAnsweringItem->getCacheAnswersCount() > mConfAnswersCacheMaximumCount) && |
| 15877 |
!cacheAnswersWeightedUsageCostItemSetDataMap->isEmpty() && it != cacheAnswersWeightedUsageCostItemSetDataMap->end()) { |
| 15878 |
|
| 15879 |
CCacheAnswersWeightedUsageCostItemData& itemData = it.value(); |
| 15880 |
QSet<COptimizedComplexVariableCompositionItem*>* cacheAnswersWeightedUsageCostVariableCompositionItemSet = itemData.getComplexVariableItemSet(false); |
| 15881 |
QSet<COptimizedComplexConceptItem*>* cacheAnswersWeightedUsageCostComplexConceptItemSet = itemData.getComplexConceptItemSet(false); |
| 15882 |
|
| 15883 |
|
| 15884 |
|
| 15885 |
if (cacheAnswersWeightedUsageCostComplexConceptItemSet) { |
| 15886 |
QSet<COptimizedComplexConceptItem*>::iterator itItem = cacheAnswersWeightedUsageCostComplexConceptItemSet->begin(); |
| 15887 |
while ((mConfAnswersCacheMaximumSizeBytes != -1 && mOntoAnsweringItem->getCacheAnswersSizeBytes() > mConfAnswersCacheMaximumSizeBytes || |
| 15888 |
mConfAnswersCacheMaximumCount != -1 && mOntoAnsweringItem->getCacheAnswersCount() > mConfAnswersCacheMaximumCount) && |
| 15889 |
!cacheAnswersWeightedUsageCostComplexConceptItemSet->isEmpty() && itItem != cacheAnswersWeightedUsageCostComplexConceptItemSet->end()) { |
| 15890 |
|
| 15891 |
COptimizedComplexConceptItem* resetComputationItem = *itItem; |
| 15892 |
if (resetComputationItem->getQueryUsageCount() <= 0) { |
| 15893 |
itItem = cacheAnswersWeightedUsageCostComplexConceptItemSet->erase(itItem); |
| 15894 |
resetComputationItem->setLastCacheInstalledCostWeightedUsage(-1); |
| 15895 |
|
| 15896 |
cleaned = true; |
| 15897 |
|
| 15898 |
// reset computation for the item |
| 15899 |
cleanUpAnswersCacheItem(resetComputationItem, clearedVarCompItemCount); |
| 15900 |
} else { |
| 15901 |
++itItem; |
| 15902 |
} |
| 15903 |
|
| 15904 |
} |
| 15905 |
} |
| 15906 |
|
| 15907 |
|
| 15908 |
if (cacheAnswersWeightedUsageCostVariableCompositionItemSet) { |
| 15909 |
QSet<COptimizedComplexVariableCompositionItem*>::iterator itItem = cacheAnswersWeightedUsageCostVariableCompositionItemSet->begin(); |
| 15910 |
while ((mConfAnswersCacheMaximumSizeBytes != -1 && mOntoAnsweringItem->getCacheAnswersSizeBytes() > mConfAnswersCacheMaximumSizeBytes || |
| 15911 |
mConfAnswersCacheMaximumCount != -1 && mOntoAnsweringItem->getCacheAnswersCount() > mConfAnswersCacheMaximumCount) && |
| 15912 |
!cacheAnswersWeightedUsageCostVariableCompositionItemSet->isEmpty() && itItem != cacheAnswersWeightedUsageCostVariableCompositionItemSet->end()) { |
| 15913 |
|
| 15914 |
COptimizedComplexVariableCompositionItem* resetComputationItem = *itItem; |
| 15915 |
if (resetComputationItem->getQueryUsageCount() <= 0) { |
| 15916 |
itItem = cacheAnswersWeightedUsageCostVariableCompositionItemSet->erase(itItem); |
| 15917 |
resetComputationItem->setLastCacheInstalledCostWeightedUsage(-1); |
| 15918 |
|
| 15919 |
cleaned = true; |
| 15920 |
|
| 15921 |
// reset computation for the item and all incompletely computed successors |
| 15922 |
cleanUpAnswersCacheItem(resetComputationItem, clearedVarCompItemCount); |
| 15923 |
} else { |
| 15924 |
++itItem; |
| 15925 |
} |
| 15926 |
|
| 15927 |
} |
| 15928 |
} |
| 15929 |
|
| 15930 |
|
| 15931 |
if (!cacheAnswersWeightedUsageCostVariableCompositionItemSet || cacheAnswersWeightedUsageCostVariableCompositionItemSet->isEmpty()) { |
| 15932 |
it = cacheAnswersWeightedUsageCostItemSetDataMap->erase(it); |
| 15933 |
} else { |
| 15934 |
++it; |
| 15935 |
} |
| 15936 |
} |
| 15937 |
|
| 15938 |
if (clearedVarCompItemCount < 0) { |
| 15939 |
mOntoAnsweringItem->setDeleteMoreCacheEntriesWhileQueryProcessing(false); |
| 15940 |
} |
| 15941 |
} |
| 15942 |
if (cleaned && mConfExtendedLogging) { |
| 15943 |
cint64 cacheSize = mOntoAnsweringItem->getCacheAnswersSizeBytes(); |
| 15944 |
LOG(INFO, getDomain(), logTr("Deleted (intermediate) results for %1 compuation steps requiring %4, %3 answers in cache remain with %2.").arg(clearedVarCompItemCount).arg(getCacheSizeString(cacheSize)).arg(mOntoAnsweringItem->getCacheAnswersCount()).arg(getCacheSizeString(prevCacheSize - cacheSize)), this); |
| 15945 |
} |
| 15946 |
return cleaned; |
| 15947 |
} |
| 15948 |
|
| 15949 |
QString COptimizedComplexExpressionAnsweringHandler::getCacheSizeString(cint64 cacheSize) { |
| 15950 |
QString cacheSizeUnit = "B"; |
| 15951 |
if (cacheSize > 10 * 1024) { |
| 15952 |
cacheSize /= 1024; |
| 15953 |
cacheSizeUnit = "KB"; |
| 15954 |
} |
| 15955 |
if (cacheSize > 10 * 1024) { |
| 15956 |
cacheSize /= 1024; |
| 15957 |
cacheSizeUnit = "MB"; |
| 15958 |
} |
| 15959 |
if (cacheSize > 10 * 1024) { |
| 15960 |
cacheSize /= 1024; |
| 15961 |
cacheSizeUnit = "GB"; |
| 15962 |
} |
| 15963 |
return QString("%1 %2").arg(cacheSize).arg(cacheSizeUnit); |
| 15964 |
} |
| 15965 |
|
| 15966 |
|
| 15967 |
|
| 15968 |
bool COptimizedComplexExpressionAnsweringHandler::cleanUpAnswersCacheItem(COptimizedComplexConceptItem* comConItem, cint64& clearedVarCompItemCount) { |
| 15969 |
comConItem->clearComputation(); |
| 15970 |
++clearedVarCompItemCount; |
| 15971 |
|
| 15972 |
queueComputedInstancesCacheMemoryConsumptionUpdate(comConItem); |
| 15973 |
|
| 15974 |
if (comConItem->getVariableConceptBaseItem() && !comConItem->getVariableConceptBaseItem()->isVariableMappingsComputed()) { |
| 15975 |
cleanUpAnswersCacheItem(comConItem->getVariableConceptBaseItem(), clearedVarCompItemCount); |
| 15976 |
} |
| 15977 |
return true; |
| 15978 |
} |
| 15979 |
|
| 15980 |
|
| 15981 |
bool COptimizedComplexExpressionAnsweringHandler::cleanUpAnswersCacheItem(COptimizedComplexVariableCompositionItem* varCompItem, cint64& clearedVarCompItemCount) { |
| 15982 |
QList<COptimizedComplexVariableCompositionItem*> clearComputationItemList; |
| 15983 |
clearComputationItemList.append(varCompItem); |
| 15984 |
|
| 15985 |
|
| 15986 |
while (!clearComputationItemList.isEmpty()) { |
| 15987 |
COptimizedComplexVariableCompositionItem* clearCompItem = clearComputationItemList.takeFirst(); |
| 15988 |
|
| 15989 |
clearCompItem->clearComputation(); |
| 15990 |
|
| 15991 |
if (clearCompItem->isVariableMappingsComputationStarted()) { |
| 15992 |
queueAnswersCacheItemUpdate(clearCompItem); |
| 15993 |
} |
| 15994 |
++clearedVarCompItemCount; |
| 15995 |
|
| 15996 |
QSet<COptimizedComplexVariableCompositionItem*>* succComputationItemSet = clearCompItem->getComputationSuccessorItemSet(); |
| 15997 |
for (COptimizedComplexVariableCompositionItem* succComputationItem : *succComputationItemSet) { |
| 15998 |
if (!succComputationItem->isVariableMappingsComputed() && succComputationItem->isVariableMappingsComputationStarted()) { |
| 15999 |
clearComputationItemList.append(succComputationItem); |
| 16000 |
} |
| 16001 |
} |
| 16002 |
} |
| 16003 |
return true; |
| 16004 |
} |
| 16005 |
|
| 16006 |
|
| 16007 |
|
| 16008 |
bool COptimizedComplexExpressionAnsweringHandler::addUsedVariableCompositionItem(COptimizedComplexBuildingVariableCompositionsItem* buildingVarItem, COptimizedComplexVariableCompositionItem* varCompItem) { |
| 16009 |
QSet<COptimizedComplexVariableCompositionItem*>* container = mOntoAnsweringItem->getVariableCompositionItemContainer(); |
| 16010 |
container->insert(varCompItem); |
| 16011 |
|
| 16012 |
if (buildingVarItem->addUsedComplexVariableCompositionItem(varCompItem)) { |
| 16013 |
varCompItem->incCacheWeightedUsageFactor(mOntoAnsweringItem->getNextUsageWeight()); |
| 16014 |
return true; |
| 16015 |
} |
| 16016 |
return false; |
| 16017 |
} |
| 16018 |
|
| 16019 |
|
| 16020 |
bool COptimizedComplexExpressionAnsweringHandler::startMeasuringVariableCompositionItemComputationCost(COptimizedComplexVariableCompositionItem* varCompItem) { |
| 16021 |
varCompItem->startComputationCostMearsuring(); |
| 16022 |
return true; |
| 16023 |
} |
| 16024 |
|
| 16025 |
bool COptimizedComplexExpressionAnsweringHandler::endMeasuringVariableCompositionItemComputationCost(COptimizedComplexVariableCompositionItem* varCompItem) { |
| 16026 |
varCompItem->stopComputationCostMearsuring(); |
| 16027 |
queueAnswersCacheItemUpdate(varCompItem); |
| 16028 |
cleanUpAnswersCache(false); |
| 16029 |
return true; |
| 16030 |
} |
| 16031 |
|
| 16032 |
|
| 16033 |
bool COptimizedComplexExpressionAnsweringHandler::startMeasuringComplexConceptItemComputationCost(COptimizedComplexConceptItem* compConItem) { |
| 16034 |
compConItem->startComputationCostMearsuring(); |
| 16035 |
return true; |
| 16036 |
} |
| 16037 |
|
| 16038 |
bool COptimizedComplexExpressionAnsweringHandler::endMeasuringComplexConceptItemComputationCost(COptimizedComplexConceptItem* compConItem) { |
| 16039 |
compConItem->stopComputationCostMearsuring(); |
| 16040 |
queueComputedInstancesCacheMemoryConsumptionUpdate(compConItem); |
| 16041 |
cleanUpAnswersCache(false); |
| 16042 |
return true; |
| 16043 |
} |
| 16044 |
|
| 16045 |
|
| 16046 |
}; // end namespace Answerer |
| 16047 |
|
| 16048 |
}; // end namespace Reasoner |
| 16049 |
|
| 16050 |
}; // end namespace Konclude |