Debian Codegraph @

Source/Reasoner/Consistiser/CSaturationCommonDisjunctConceptsExtractor.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 "CSaturationCommonDisjunctConceptsExtractor.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Consistiser {
29
30
31 CSaturationCommonDisjunctConceptsExtractor::CSaturationCommonDisjunctConceptsExtractor() {
32 }
33
34 bool CSaturationCommonDisjunctConceptsExtractor::extractCommonDisjunctConcepts(CConcreteOntology* ontology, CSaturationData* saturationData, QSet<CConcept*>* disjunctionConceptSet) {
35 CSaturationTaskData* satTaskData = (CSaturationTaskData*)saturationData;
36 if (satTaskData) {
37 CSatisfiableCalculationTask* satCalcTask = satTaskData->getSaturationTask();
38 if (satCalcTask) {
39
40 CMemoryAllocationManager* mMemMan = ontology->getDataBoxes()->getBoxContext()->getMemoryAllocationManager();
41 CImplicationReplacementVector* repVector = ontology->getDataBoxes()->getMBox()->getImplicationReplacementVector(true);
42
43 for (QSet<CConcept*>::const_iterator it = disjunctionConceptSet->constBegin(), itEnd = disjunctionConceptSet->constEnd(); it != itEnd; ++it) {
44 CConcept* disjunctionConcept(*it);
45 bool disjunctionNegation = false;
46 cint64 disjunctionOpCode = disjunctionConcept->getOperatorCode();
47 if (disjunctionOpCode == CCAND || disjunctionOpCode == CCEQ) {
48 disjunctionNegation = true;
49 }
50 CConceptProcessData* disjConProData = (CConceptProcessData*)disjunctionConcept->getConceptData();
51 if (disjConProData) {
52 CReplacementData* disjReplData = disjConProData->getReplacementData();
53 bool replacementDataInitialized = false;
54 QSet< QPair<CConcept*,bool> > commonConceptNegationPairSet;
55
56 CConceptSaturationReferenceLinkingData* confSatRefLinkingData = (CConceptSaturationReferenceLinkingData*)disjConProData->getConceptReferenceLinking();
57 if (confSatRefLinkingData) {
58 CSaturationConceptReferenceLinking* disjunctConceptRefLinkData = confSatRefLinkingData->getConceptSaturationReferenceLinkingData(disjunctionNegation);
59 if (disjunctConceptRefLinkData) {
60 CIndividualSaturationProcessNode* satIndiNode = (CIndividualSaturationProcessNode*)disjunctConceptRefLinkData->getIndividualProcessNodeForConcept();
61 if (satIndiNode && satIndiNode->isCompleted()) {
62 CReapplyConceptSaturationLabelSet* conSet = satIndiNode->getReapplyConceptSaturationLabelSet(false);
63 if (conSet) {
64 for (CConceptSaturationDescriptor* conDesIt = conSet->getConceptSaturationDescriptionLinker(); conDesIt; conDesIt = conDesIt->getNext()) {
65 CConcept* concept = conDesIt->getConcept();
66 bool negation = conDesIt->isNegated();
67
68 if (concept != disjunctionConcept && concept->getOperatorCode() != CCTOP) {
69 if (!disjReplData) {
70 disjReplData = CObjectAllocator<CReplacementData>::allocateAndConstruct(mMemMan);
71 disjReplData->initReplacementData(nullptr);
72 disjConProData->setReplacementData(disjReplData);
73 repVector->setData(concept->getConceptTag(),disjReplData);
74 replacementDataInitialized = true;
75 }
76
77 if (!replacementDataInitialized) {
78 for (CXNegLinker<CConcept*>* commonConLinkIt = disjReplData->getCommonDisjunctConceptLinker(); commonConLinkIt; commonConLinkIt = commonConLinkIt->getNext()) {
79 CConcept* commonConcept = commonConLinkIt->getData();
80 bool commonConceptNeg = commonConLinkIt->isNegated();
81 commonConceptNegationPairSet.insert( QPair<CConcept*,bool>(commonConcept,commonConceptNeg) );
82 }
83 }
84
85 if (!commonConceptNegationPairSet.contains(QPair<CConcept*,bool>(concept,negation))) {
86 commonConceptNegationPairSet.insert(QPair<CConcept*,bool>(concept,negation));
87 CXNegLinker<CConcept*>* commNegConLinker = CObjectAllocator< CXNegLinker<CConcept*> >::allocateAndConstruct(mMemMan);
88 commNegConLinker->initNegLinker(concept,negation);
89 disjReplData->addCommonDisjunctConceptLinker(commNegConLinker);
90 }
91 }
92
93 }
94 }
95 }
96 }
97 }
98 }
99 }
100 }
101 }
102 return false;
103 }
104
105 }; // end namespace Consistiser
106
107 }; // end namespace Reasoner
108
109 }; // end namespace Konclude