Debian Codegraph @

Source/Reasoner/Kernel/Algorithm/CSatisfiableTaskPossibleAssertionCollectingAnalyser.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CSatisfiableTaskPossibleAssertionCollectingAnalyser.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Algorithm {
31
32
33 CSatisfiableTaskPossibleAssertionCollectingAnalyser::CSatisfiableTaskPossibleAssertionCollectingAnalyser() {
34 }
35
36
37
38 bool CSatisfiableTaskPossibleAssertionCollectingAnalyser::readCalculationConfig(CCalculationConfigurationExtension *config) {
39 if (config) {
40 return true;
41 }
42 return false;
43 }
44
45
46 CIndividualProcessNode* CSatisfiableTaskPossibleAssertionCollectingAnalyser::getCorrectedIndividualNode(cint64 baseIndiID, CIndividualProcessNodeVector* indiNodeVec) {
47 CIndividualProcessNode* indi = indiNodeVec->getData(baseIndiID);
48 while (indi->hasMergedIntoIndividualNodeID()) {
49 indi = indiNodeVec->getData(indi->getMergedIntoIndividualNodeID());
50 }
51 return indi;
52 }
53
54
55 bool CSatisfiableTaskPossibleAssertionCollectingAnalyser::analyseSatisfiableTask(CSatisfiableCalculationTask* statCalcTask, CCalculationAlgorithmContext* calcAlgContext) {
56 CSatisfiableTaskRealizationPossibleAssertionCollectingAdapter* possAssCollAdapter = statCalcTask->getPossibleAssertionCollectionAdapter();
57 if (possAssCollAdapter) {
58 CPossibleAssertionsCollectionSet* possAssCollSet = possAssCollAdapter->getPossibleAssertionsCollectionSet();
59 CConcreteOntology* ontology = possAssCollAdapter->getTestingOntology();
60
61 if (possAssCollSet) {
62
63 CSatisfiableCalculationTask* cachedDetTask = getCachedDeterministicCompletionGraphTask(calcAlgContext);
64 CIndividualProcessNodeVector* detCachedIndiNodeVec = nullptr;
65 if (cachedDetTask) {
66 detCachedIndiNodeVec = cachedDetTask->getProcessingDataBox()->getIndividualProcessNodeVector();
67 }
68
69 CBOXSET<CConcept*>* eqNonCanSet = ontology->getTBox()->getEquivalentConceptNonCandidateSet(false);
70
71 QSet< QPair<CIndividual*,CConcept*> > possConAssSet;
72 cint64 maxDetBranchTag = statCalcTask->getProcessingDataBox()->getMaximumDeterministicBranchTag();
73
74 CProcessingDataBox* procDataBox = calcAlgContext->getProcessingDataBox();
75 CIndividualProcessNodeVector* indiNodeVec = procDataBox->getIndividualProcessNodeVector();
76 CIndividualVector* indiVec = procDataBox->getOntology()->getABox()->getIndividualVector();
77 cint64 indiMinIdx = indiNodeVec->getItemMinIndex();
78 for (cint64 i = indiMinIdx; i <= 0; ++i) {
79 CIndividualProcessNode* indiNode = indiNodeVec->getData(i);
80 CIndividualProcessNode* cachedDetIndiNode = nullptr;
81 if (detCachedIndiNodeVec) {
82 cachedDetIndiNode = detCachedIndiNodeVec->getData(i);
83 }
84 if (indiNode && indiNode != cachedDetIndiNode && indiNode->getNominalIndividual()) {
85 if (!cachedDetIndiNode || !indiNode->hasPartialProcessingRestrictionFlags(CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHED) || indiNode->hasPartialProcessingRestrictionFlags(CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHINGINVALID | CIndividualProcessNode::PRFCOMPLETIONGRAPHCACHINGINVALIDATED)) {
86 CReapplyConceptLabelSet* conLabelSet = indiNode->getReapplyConceptLabelSet(false);
87 if (conLabelSet) {
88
89 CIndividual* individual = indiNode->getNominalIndividual();
90 for (CConceptDescriptor* conDesIt = conLabelSet->getAddingSortedConceptDescriptionLinker(); conDesIt; conDesIt = conDesIt->getNext()) {
91 CDependencyTrackPoint* depTrackPoint = conDesIt->getDependencyTrackPoint();
92 CConcept* concept = conDesIt->getConcept();
93 bool conNegation = conDesIt->isNegated();
94 if (!depTrackPoint || depTrackPoint->getBranchingTag() > maxDetBranchTag) {
95 if (!conNegation && concept && concept->hasClassName()) {
96 possConAssSet.insert( QPair<CIndividual*,CConcept*>(individual,concept) );
97 }
98 }
99 if (concept->getOperatorCode() == CCEQCAND) {
100 CConcept* eqConcept = concept->getOperandList()->getData();
101 bool negation = false;
102 if (!conLabelSet->containsConcept(eqConcept,negation)) {
103 possConAssSet.insert( QPair<CIndividual*,CConcept*>(individual,eqConcept) );
104 }
105 }
106 }
107
108 if (eqNonCanSet) {
109 for (CBOXSET<CConcept*>::const_iterator it = eqNonCanSet->constBegin(), itEnd = eqNonCanSet->constEnd(); it != itEnd; ++it) {
110 CConcept* eqConcept(*it);
111 bool negation = false;
112 if (!conLabelSet->containsConcept(eqConcept,negation)) {
113 possConAssSet.insert( QPair<CIndividual*,CConcept*>(individual,eqConcept) );
114 }
115 }
116 }
117
118 CIndividualMergingHash* indiMergingHash = indiNode->getIndividualMergingHash(false);
119 if (indiMergingHash) {
120
121 for (CIndividualMergingHash::const_iterator indiIt = indiMergingHash->constBegin(), indiItEnd = indiMergingHash->constEnd(); indiIt != indiItEnd; ++indiIt) {
122
123 if (indiIt.value().isMergedWithIndividual()) {
124 cint64 indiIDIt = indiIt.key();
125 CIndividual* mergedIndividual = indiVec->getData(indiIDIt);
126 CDependencyTrackPoint* mergeDepTrackPoint = indiIt.value().getDependencyTrackPoint();
127 bool nonDetMerged = true;
128 if (mergeDepTrackPoint && mergeDepTrackPoint->getBranchingTag() <= maxDetBranchTag) {
129 nonDetMerged = false;
130 }
131 for (CConceptDescriptor* conDesIt = conLabelSet->getAddingSortedConceptDescriptionLinker(); conDesIt; conDesIt = conDesIt->getNext()) {
132 CDependencyTrackPoint* depTrackPoint = conDesIt->getDependencyTrackPoint();
133 CConcept* concept = conDesIt->getConcept();
134 bool conNegation = conDesIt->isNegated();
135 if (nonDetMerged || !depTrackPoint || depTrackPoint->getBranchingTag() > maxDetBranchTag) {
136 if (!conNegation && concept && concept->hasClassName()) {
137 possConAssSet.insert(QPair<CIndividual*, CConcept*>(mergedIndividual, concept));
138 }
139 }
140 if (concept->getOperatorCode() == CCEQCAND) {
141 CConcept* eqConcept = concept->getOperandList()->getData();
142 bool negation = false;
143 if (!conLabelSet->containsConcept(eqConcept, negation)) {
144 possConAssSet.insert(QPair<CIndividual*, CConcept*>(mergedIndividual, eqConcept));
145 }
146 }
147 }
148
149 if (eqNonCanSet) {
150 for (CBOXSET<CConcept*>::const_iterator it = eqNonCanSet->constBegin(), itEnd = eqNonCanSet->constEnd(); it != itEnd; ++it) {
151 CConcept* eqConcept(*it);
152 bool negation = false;
153 if (!conLabelSet->containsConcept(eqConcept, negation)) {
154 possConAssSet.insert(QPair<CIndividual*, CConcept*>(mergedIndividual, eqConcept));
155 }
156 }
157 }
158 }
159
160 }
161 }
162
163 }
164 }
165 }
166 }
167
168 if (!possConAssSet.isEmpty()) {
169 possAssCollSet->acquireSynchronisationLock();
170 for (QSet< QPair<CIndividual*,CConcept*> >::const_iterator it = possConAssSet.constBegin(), itEnd = possConAssSet.constEnd(); it != itEnd; ++it) {
171 const QPair<CIndividual*,CConcept*>& indiConPair(*it);
172 possAssCollSet->addPossibleAssertion(indiConPair.first,indiConPair.second);
173 }
174 possAssCollSet->releaseSynchronisationLock();
175 }
176 }
177 }
178 return false;
179 }
180
181
182
183 CSatisfiableCalculationTask* CSatisfiableTaskPossibleAssertionCollectingAnalyser::getCachedDeterministicCompletionGraphTask(CCalculationAlgorithmContext* calcAlgContext) {
184 CConcreteOntology* consOntology = calcAlgContext->getProcessingDataBox()->getOntology();
185 if (consOntology) {
186 CConsistence* consistence = consOntology->getConsistence();
187 if (consistence) {
188 CConsistenceData* consData = consistence->getConsistenceModelData();
189 if (consData) {
190 CConsistenceTaskData* consTaskData = dynamic_cast<CConsistenceTaskData*>(consData);
191 if (consTaskData) {
192 CSatisfiableCalculationTask* compGraphCalcTask = consTaskData->getDeterministicSatisfiableTask();
193 return compGraphCalcTask;
194 }
195 }
196 }
197 }
198 return nullptr;
199 }
200
201
202
203 }; // end namespace Algorithm
204
205 }; // end namespace Kernel
206
207 }; // end namespace Reasoner
208
209 }; // end namespace Konclude