Debian Codegraph @

Source/Reasoner/Kernel/Algorithm/CSatisfiableTaskPropertyClassificationMessageAnalyser.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 "CSatisfiableTaskPropertyClassificationMessageAnalyser.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Algorithm {
31
32
33 CSatisfiableTaskPropertyClassificationMessageAnalyser::CSatisfiableTaskPropertyClassificationMessageAnalyser() {
34 }
35
36
37
38 bool CSatisfiableTaskPropertyClassificationMessageAnalyser::readCalculationConfig(CCalculationConfigurationExtension *config) {
39 if (config) {
40 return true;
41 }
42 return false;
43 }
44
45
46 CIndividualProcessNode* CSatisfiableTaskPropertyClassificationMessageAnalyser::getCorrectedIndividualID(CIndividualProcessNode* baseIndiNode, CIndividualProcessNodeVector* indiNodeVec, bool* nondetMergedFlag) {
47 CIndividualProcessNode* indi = indiNodeVec->getData(baseIndiNode->getIndividualNodeID());
48 while (indi->hasMergedIntoIndividualNodeID()) {
49 if (nondetMergedFlag && *nondetMergedFlag == false) {
50 if (!indi->getMergedDependencyTrackPoint() || indi->getMergedDependencyTrackPoint()->getBranchingTag() > 0) {
51 *nondetMergedFlag = true;
52 }
53 }
54 indi = indiNodeVec->getData(indi->getMergedIntoIndividualNodeID());
55 }
56 return indi;
57 }
58
59
60
61 CClassificationMessageData* CSatisfiableTaskPropertyClassificationMessageAnalyser::extractPossibleSubsumptionInformation(CRole* testingRole, CIndividualProcessNode* indiNode, CReapplyConceptLabelSet* conSet, CCalculationAlgorithmContext* calcAlgContext) {
62 STATINC(ANALYSEPOSSIBLESUBSUMPTIONSCOUNT,calcAlgContext);
63
64 CClassificationMessageData* messageDataLinker = nullptr;
65
66
67 // initialize possible subsumption list
68 CPROPERTYPOSSIBLESUBSUMPTIONMESSAGELIST<CClassificationInitializePossiblePropertySubsumptionData*>* possSubsumerList = nullptr;
69
70
71 CReapplyConceptLabelSetIterator conSetIt = conSet->getConceptLabelSetIterator(true,true,false);
72
73 // create new initialization list for possible subsumers
74 while (conSetIt.hasNext()) {
75 CConceptDescriptor* conDes = conSetIt.getConceptDescriptor();
76 CConcept* concept = conDes->getConcept();
77 bool negated = conDes->getNegation();
78
79
80 CRole* markerRole = concept->getRole();
81 if (!negated && concept->getOperatorCode() == CCMARKER && markerRole && markerRole != testingRole) {
82 if (!possSubsumerList) {
83 possSubsumerList = CObjectParameterizingAllocator< CPROPERTYPOSSIBLESUBSUMPTIONMESSAGELIST<CClassificationInitializePossiblePropertySubsumptionData*>,CContext* >::allocateAndConstructAndParameterize(mTempMemAllocMan,mTmpContext);
84 }
85 CClassificationInitializePossiblePropertySubsumptionData* possSubsumData = CObjectAllocator< CClassificationInitializePossiblePropertySubsumptionData >::allocateAndConstruct(mTempMemAllocMan);
86 possSubsumData->initClassificationPossibleSubsumptionData(markerRole);
87 possSubsumerList->append(possSubsumData);
88 }
89 conSetIt.moveNext();
90 }
91
92
93
94 CClassificationInitializePossiblePropertySubsumptionMessageData* possSubsumMessageData = CObjectAllocator<CClassificationInitializePossiblePropertySubsumptionMessageData>::allocateAndConstruct(mTempMemAllocMan);
95 possSubsumMessageData->initClassificationPossibleSubsumptionMessageData(testingRole,possSubsumerList);
96 messageDataLinker = possSubsumMessageData->append(messageDataLinker);
97 return messageDataLinker;
98 }
99
100
101
102
103 bool CSatisfiableTaskPropertyClassificationMessageAnalyser::analyseSatisfiableTask(CSatisfiableCalculationTask* statCalcTask, CCalculationAlgorithmContext* calcAlgContext) {
104 mStatCalcTask = statCalcTask;
105 CSatisfiableTaskClassificationRoleMarkedMessageAdapter* classMessRoleMarkedAdapter = statCalcTask->getSatisfiableClassificationRoleMarkedMessageAdapter();
106 if (classMessRoleMarkedAdapter) {
107 CClassificationMessageDataObserver* roleMessClassObserver = classMessRoleMarkedAdapter->getRoleClassificationMessageDataObserver();
108 CClassificationMessageData* subsumMessageDataLinker = nullptr;
109 CClassificationMessageData* possSubsumMessageDataLinker = nullptr;
110 CClassificationMessageData* pmMessageDataLinker = nullptr;
111
112
113 CTaskProcessorContext* taskProcessorContext = calcAlgContext->getUsedTaskProcessorContext();
114 CTaskHandleMemoryAllocationManager* taskMemMan = calcAlgContext->getTemporaryMemoryAllocationManager();
115 CRole* testingRole = classMessRoleMarkedAdapter->getTestingRole();
116 CIndividual* markerIndi = classMessRoleMarkedAdapter->getMarkerIndividual();
117
118 //QString iriClassNameString = CIRIName::getRecentIRIName(testingConcept->getClassNameLinker());
119 //if (iriClassNameString == "http://www.owllink.org/testsuite/galen#LowerLobeOfLeftLung") {
120 // bool bug = true;
121 //}
122 //}
123 //considerOtherNode = false;
124
125 CConcreteOntology* testOntology = classMessRoleMarkedAdapter->getTestingOntology();
126 CProcessingDataBox* processingDataBox = statCalcTask->getProcessingDataBox();
127 CIndividualProcessNodeVector* indiNodeVec = processingDataBox->getIndividualProcessNodeVector();
128
129 cint64 maxDetBranchTag = processingDataBox->getMaximumDeterministicBranchTag();
130
131
132
133
134 if (testOntology && testingRole && markerIndi) {
135 cint64 markerIndiID = markerIndi->getIndividualID();
136 CIndividualProcessNode* markerIndiNode = indiNodeVec->getData(-markerIndiID);
137 bool nondetMerged = false;
138 markerIndiNode = getCorrectedIndividualID(markerIndiNode,indiNodeVec,&nondetMerged);
139 if (nondetMerged) {
140 maxDetBranchTag = 0;
141 }
142
143
144 CMemoryPoolContainer memPoolCon;
145 CTaskMemoryPoolAllocationManager classMessMemManCreaterMemMan(&memPoolCon,calcAlgContext->getTemporaryMemoryAllocationManager());
146 mTempMemAllocMan = CObjectAllocator<CTaskMemoryPoolAllocationManager>::allocateAndConstruct(&classMessMemManCreaterMemMan);
147 mTempMemAllocMan->initTaskMemoryPoolAllocationManager(&memPoolCon,calcAlgContext->getTemporaryMemoryAllocationManager());
148 mTmpContext = CObjectParameterizingAllocator< CContextBase,CMemoryAllocationManager* >::allocateAndConstructAndParameterize(mTempMemAllocMan,mTempMemAllocMan);
149
150 CPROPERTYSUBSUMPTIONMESSAGELIST<CRole*>* subsumerList = nullptr;
151
152 CReapplyConceptLabelSet* conSet = markerIndiNode->getReapplyConceptLabelSet(false);
153 if (conSet) {
154 CReapplyConceptLabelSetIterator conSetIt = conSet->getConceptLabelSetIterator(true,true,true);
155 while (conSetIt.hasNext()) {
156 CConceptDescriptor* conDes = conSetIt.getConceptDescriptor();
157 if (conDes) {
158 CConcept* concept = conDes->getConcept();
159 bool negated = conDes->getNegation();
160 CRole* markerRole = concept->getRole();
161
162 if (!negated && concept->getOperatorCode() == CCMARKER && markerRole) {
163 CDependencyTrackPoint* depTrackPoint = conSetIt.getDependencyTrackPoint();
164 bool deterministic = false;
165 if (depTrackPoint) {
166 if (depTrackPoint->getBranchingTag() <= maxDetBranchTag) {
167 deterministic = true;
168 }
169 }
170
171 if (deterministic && markerRole != testingRole) {
172 if (!subsumerList) {
173 subsumerList = CObjectParameterizingAllocator< CPROPERTYSUBSUMPTIONMESSAGELIST<CRole*>,CContext* >::allocateAndConstructAndParameterize(mTempMemAllocMan,mTmpContext);
174 }
175 subsumerList->append(markerRole);
176 }
177 }
178 }
179 conSetIt.moveNext();
180 }
181
182 CClassificationMessageData* messageData = extractPossibleSubsumptionInformation(testingRole,markerIndiNode,conSet,calcAlgContext);
183 if (messageData) {
184 possSubsumMessageDataLinker = messageData->append(possSubsumMessageDataLinker);
185 }
186
187 }
188
189 CClassificationPropertySubsumptionMessageData* subsumMessageData = CObjectAllocator<CClassificationPropertySubsumptionMessageData>::allocateAndConstruct(mTempMemAllocMan);
190 subsumMessageData->initClassificationSubsumptionMessageData(testingRole,subsumerList);
191 subsumMessageDataLinker = subsumMessageData->append(subsumMessageDataLinker);
192 subsumerList = nullptr;
193
194
195
196
197
198 CClassificationMessageData* messageDataLinker = subsumMessageDataLinker;
199 if (pmMessageDataLinker) {
200 messageDataLinker = pmMessageDataLinker->append(messageDataLinker);
201 }
202 if (possSubsumMessageDataLinker) {
203 messageDataLinker = possSubsumMessageDataLinker->append(messageDataLinker);
204 }
205
206 if (messageDataLinker) {
207 roleMessClassObserver->tellClassificationMessage(testOntology,messageDataLinker,memPoolCon.takeMemoryPools());
208 } else {
209 taskMemMan->releaseTemporaryMemoryPools(memPoolCon.takeMemoryPools());
210 }
211
212
213
214 return true;
215
216 }
217 }
218 return false;
219 }
220
221
222
223
224 }; // end namespace Algorithm
225
226 }; // end namespace Kernel
227
228 }; // end namespace Reasoner
229
230 }; // end namespace Konclude