Debian Codegraph @

Source/Reasoner/Preprocess/CExtractPropagationIntoCreationDirectionPreProcess.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 "CExtractPropagationIntoCreationDirectionPreProcess.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Preprocess {
29
30
31 CExtractPropagationIntoCreationDirectionPreProcess::CExtractPropagationIntoCreationDirectionPreProcess() {
32 }
33
34
35 CExtractPropagationIntoCreationDirectionPreProcess::~CExtractPropagationIntoCreationDirectionPreProcess() {
36 }
37
38
39 CConcreteOntology* CExtractPropagationIntoCreationDirectionPreProcess::preprocess(CConcreteOntology* ontology, CPreProcessContext* context) {
40 bool skipForELOntologies = CConfigDataReader::readConfigBoolean(context->getConfiguration(),"Konclude.Calculation.Preprocessing.ExtractPropagationIntoCreationDirection.SkipForELFragment",true);
41 bool nonELConstructsUsed = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getBuildConstructFlags()->isNonELConstructUsed();
42
43 if (nonELConstructsUsed || !skipForELOntologies) {
44 CMBox* mBox = ontology->getDataBoxes()->getMBox();
45 CTBox* tBox = ontology->getDataBoxes()->getTBox();
46 CRBox* rBox = ontology->getDataBoxes()->getRBox();
47 CABox* aBox = ontology->getDataBoxes()->getABox();
48
49 CConceptVector* conceptVec = tBox->getConceptVector();
50 cint64 conceptCount = tBox->getConceptCount();
51 CRoleVector* roleVec = rBox->getRoleVector();
52
53 cint64 markedPropagationIntoCreationDirectionConceptCount = 0;
54
55 QHash<CRole*,bool> creationRoleHash;
56 for (cint64 conIdx = 0; conIdx < conceptCount; ++conIdx) {
57 CConcept* concept = conceptVec->getData(conIdx);
58 if (concept) {
59 CConceptOperator* conOperator = concept->getConceptOperator();
60 if (conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_POSSIBLE_ROLE_CREATION_TYPE)) {
61 CRole* role = concept->getRole();
62 if (!creationRoleHash.contains(role)) {
63 for (CSortedNegLinker<CRole*>* superRoleIt = role->getIndirectSuperRoleList(); superRoleIt; superRoleIt = superRoleIt->getNext()) {
64 bool superRoleNegation = superRoleIt->isNegated();
65 CRole* superRole = superRoleIt->getData();
66 if (!superRoleNegation) {
67 bool& roleInserted = creationRoleHash[superRole];
68 if (!roleInserted) {
69 roleInserted = true;
70 }
71 }
72 }
73 }
74 }
75 }
76 }
77
78
79 for (cint64 conIdx = 0; conIdx < conceptCount; ++conIdx) {
80 CConcept* concept = conceptVec->getData(conIdx);
81 if (concept) {
82 CConceptOperator* conOperator = concept->getConceptOperator();
83 if (conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_ALL_AQALL_TYPE | CConceptOperator::CCFS_POSSIBLE_ROLE_CREATION_TYPE)) {
84 CRole* role = concept->getRole();
85 if (creationRoleHash.contains(role)) {
86 CConceptProcessData* conProData = (CConceptProcessData*)concept->getConceptData();
87 if (conProData) {
88 ++markedPropagationIntoCreationDirectionConceptCount;
89 conProData->setPropagationIntoCreationDirection(true);
90 }
91 CRoleProcessData* roleProData = (CRoleProcessData*)role->getRoleData();
92 if (roleProData && !roleProData->hasPropagationAndCreationConceptsFlag()) {
93 roleProData->setPropagationAndCreationConceptsFlag(true);
94 }
95 }
96 }
97 }
98 }
99
100
101 LOG(INFO,"::Konclude::Reasoner::Preprocess::PropagationIntoCreationDirectionExtractor",logTr("Marked %1 concepts with possible propagation into creation direction.").arg(markedPropagationIntoCreationDirectionConceptCount),this);
102 }
103 return ontology;
104 }
105
106
107
108 }; // end namespace Preprocess
109
110 }; // end namespace Reasoner
111
112 }; // end namespace Konclude