Debian Codegraph @

Source/Reasoner/Preprocess/CDataExtenderPreProcess.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 "CDataExtenderPreProcess.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Preprocess {
29
30
31 CDataExtenderPreProcess::CDataExtenderPreProcess() {
32 mOntology = nullptr;
33 mLastConceptId = 0;
34 }
35
36
37 CDataExtenderPreProcess::~CDataExtenderPreProcess() {
38 }
39
40
41 CConcreteOntology *CDataExtenderPreProcess::preprocess(CConcreteOntology *ontology, CPreProcessContext* context) {
42 mOntology = ontology;
43
44 bool skipForELOntologies = CConfigDataReader::readConfigBoolean(context->getConfiguration(),"Konclude.Calculation.Preprocessing.ProcessingDataExtender.SkipForELFragment",true);
45 bool nonELConstructsUsed = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getBuildConstructFlags()->isNonELConstructUsed();
46
47 CMBox *mBox = ontology->getDataBoxes()->getMBox();
48 CTBox *tBox = ontology->getDataBoxes()->getTBox();
49 CRBox *rBox = ontology->getDataBoxes()->getRBox();
50 CABox *aBox = ontology->getDataBoxes()->getABox();
51
52 CConceptVector* conceptVector = tBox->getConceptVector();
53 CRoleVector* roleVector = rBox->getRoleVector();
54 CIndividualVector* indiVector = aBox->getIndividualVector();
55 CBranchingTriggerVector* branchTriggVec = mBox->getBranchingTriggerVector();
56 CImplicationReplacementVector* impRepVec = mBox->getImplicationReplacementVector();
57
58 CRoleVector *roles = rBox->getRoleVector();
59
60 CConcept *topConcept = conceptVector->getLocalData(1);
61
62 mMemMan = ontology->getDataBoxes()->getBoxContext()->getMemoryAllocationManager();
63
64
65 mStatConceptDataExtended = 0;
66 mStatRoleDataExtended = 0;
67 mStatIndiDataExtended = 0;
68
69
70 cint64 roleCount = rBox->getRoleCount();
71 for (cint64 roleIdx = 0; roleIdx < roleCount; ++roleIdx) {
72 CRole* role = roleVector->getLocalData(roleIdx);
73 if (role) {
74 if (!role->hasRoleData()) {
75 CRoleProcessData* roleData = CObjectAllocator< CRoleProcessData >::allocateAndConstruct(mMemMan);
76 roleData->initRoleProcessExtensionData();
77 role->setRoleData(roleData);
78 ++mStatRoleDataExtended;
79 }
80 }
81 }
82
83 cint64 indiCount = aBox->getIndividualCount();
84 for (cint64 indiIdx = 0; indiIdx < indiCount; ++indiIdx) {
85 CIndividual* indi = indiVector->getLocalData(indiIdx);
86 if (indi) {
87 if (!indi->hasIndividualData()) {
88 CIndividualProcessData* indiData = CObjectAllocator< CIndividualProcessData >::allocateAndConstruct(mMemMan);
89 indiData->initIndividualProcessExtensionData();
90 indi->setIndividualData(indiData);
91 ++mStatIndiDataExtended;
92 }
93 }
94 }
95
96
97 cint64 conCount = tBox->getConceptCount();
98 for (cint64 conIdx = mLastConceptId; conIdx < conCount; ++conIdx) {
99 CConcept* concept = conceptVector->getLocalData(conIdx);
100 if (concept) {
101 if (!concept->hasConceptData()) {
102 CConceptProcessData* conceptData = CObjectAllocator< CConceptProcessData >::allocateAndConstruct(mMemMan);
103 if (nonELConstructsUsed || !skipForELOntologies) {
104 conceptData->initConceptProcessExtensionData(branchTriggVec->getData(conIdx),impRepVec->getData(conIdx));
105 } else {
106 conceptData->initConceptProcessExtensionData(nullptr,nullptr);
107 }
108 concept->setConceptData(conceptData);
109 ++mStatConceptDataExtended;
110 }
111 }
112 }
113 mLastConceptId = conCount;
114
115 LOG(INFO,"::Konclude::Reasoner::Preprocess::ProcessDataExtender",logTr("Extended %1 concepts and %2 roles for processing.").arg(mStatConceptDataExtended).arg(mStatRoleDataExtended),this);
116 return ontology;
117 }
118
119
120 CConcreteOntology* CDataExtenderPreProcess::continuePreprocessing() {
121 if (mOntology) {
122 CMBox *mBox = mOntology->getDataBoxes()->getMBox();
123 CTBox *tBox = mOntology->getDataBoxes()->getTBox();
124
125 CBranchingTriggerVector* branchTriggVec = mBox->getBranchingTriggerVector();
126 CImplicationReplacementVector* impRepVec = mBox->getImplicationReplacementVector();
127
128 CConceptVector* conceptVector = tBox->getConceptVector();
129 cint64 conCount = tBox->getConceptCount();
130 for (cint64 conIdx = mLastConceptId; conIdx < conCount; ++conIdx) {
131 CConcept* concept = conceptVector->getLocalData(conIdx);
132 if (concept) {
133 if (!concept->hasConceptData()) {
134 CConceptProcessData* conceptData = CObjectAllocator< CConceptProcessData >::allocateAndConstruct(mMemMan);
135 conceptData->initConceptProcessExtensionData(branchTriggVec->getData(conIdx), impRepVec->getData(conIdx));
136 concept->setConceptData(conceptData);
137 ++mStatConceptDataExtended;
138 }
139 }
140 }
141 mLastConceptId = conCount;
142
143 }
144 return mOntology;
145 }
146
147
148
149
150 }; // end namespace Preprocess
151
152 }; // end namespace Reasoner
153
154 }; // end namespace Konclude