Debian Codegraph @

Source/Reasoner/Answerer/COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler.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 "COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Answerer {
29
30
31 COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler::COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler(COptimizedComplexVariableAbsorptionBasedHandlingQueryPartData* queryPart, COptimizedComplexExpressionOntologyAnsweringItem* ontoAnsweringItem) {
32 mQueryPart = queryPart;
33 mOntoAnsweringItem = ontoAnsweringItem;
34
35 mMemMan = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getBoxContext()->getMemoryAllocationManager();
36 mTBox = mOntoAnsweringItem->getTestingOntology(false)->getDataBoxes()->getTBox();
37 mConceptVec = mTBox->getConceptVector();
38 }
39
40
41
42 COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler* COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler::readConfig(CCalculationConfigurationExtension* config) {
43 return this;
44 }
45
46
47
48
49 bool COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler::checkHasTopObjectPropertyPropagation() {
50 CObjectPropertyTermExpression* topObjPropExp = mOntoAnsweringItem->getTestingOntology()->getBuildData()->getTopObjectPropertyExpression();
51 QSet<CExpressionVariable*>* absorbtionVariableSet = mQueryPart->getAbsorptionVariableSet();
52 for (CExpressionVariable* var : absorbtionVariableSet->toList()) {
53 QList<CObjectPropertyAssertionExpression*> neighPropAssList = mQueryPart->getNeighbouringPropertyAssertions(var);
54 QList<CObjectPropertyAssertionExpression*> selfPropAssList = mQueryPart->getSelfPropertyAssertions(var);
55 for (CObjectPropertyAssertionExpression* propAss : neighPropAssList) {
56 if (propAss->getObjectPropertyTermExpression() == topObjPropExp) {
57 return true;
58 }
59 }
60 for (CObjectPropertyAssertionExpression* propAss : selfPropAssList) {
61 if (propAss->getObjectPropertyTermExpression() == topObjPropExp) {
62 return true;
63 }
64 }
65 QList<CBuildExpression*> classExpressions = mQueryPart->getVariableClassExpressions(var);
66 if (classExpressions.size() > 0) {
67 for (CBuildExpression* buildExpression : classExpressions) {
68 CClassTermExpression* classExpression = (CClassTermExpression*)buildExpression;
69 CConcept* testingConcept = mOntoAnsweringItem->getTestingOntology()->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash()->value(classExpression);
70 bool testingNegation = testingConcept->hasMappingNegation();
71 if (checkHasNewTopRolePropagation(testingConcept, testingNegation)) {
72 return true;
73 }
74 }
75
76 }
77
78 }
79 return false;
80 }
81
82
83 bool COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler::checkHasNewTopRolePropagation(CConcept* concept, bool conceptNegation) {
84 CRole* topRole = mOntoAnsweringItem->getTestingOntology()->getRBox()->getTopObjectRole();
85 QList<CConcept*> testingList;
86 QSet<CConcept*> testedSet;
87 testingList.append(concept);
88 testedSet.insert(concept);
89 while (!testingList.isEmpty()) {
90 CConcept* testingConcept = testingList.takeFirst();
91 cint64 opCode = testingConcept->getOperatorCode();
92
93 CConceptOperator* conceptOperator = testingConcept->getConceptOperator();
94 if (conceptOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_ALL_TYPE | CConceptOperator::CCFS_SOME_TYPE)) {
95 CRole* role = testingConcept->getRole();
96 if (role == topRole) {
97 return true;
98 }
99 }
100
101 if (opCode != CCEQ && opCode != CCSUB) {
102 for (CSortedNegLinker<CConcept*>* opConLinkerIt = testingConcept->getOperandList(); opConLinkerIt; opConLinkerIt = opConLinkerIt->getNext()) {
103 CConcept* opConcept = opConLinkerIt->getData();
104 if (!testedSet.contains(opConcept)) {
105 testedSet.insert(opConcept);
106 testingList.append(opConcept);
107 }
108 }
109 }
110
111 }
112 return false;
113 }
114
115
116
117
118
119
120
121
122
123 CRole* COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler::getInverseRole(CRole* role) {
124 return role->getInverseRole();
125 }
126
127
128 void COptimizedComplexVariableAbstractAbsorptionBasedQueryPartHandler::addConceptOperand(CConcept* concept, CConcept* operandConcept, bool operandNegation) {
129 CSortedNegLinker<CConcept*>* newBaseOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(mMemMan);
130 newBaseOpCon->init(operandConcept, operandNegation, concept->getOperandList());
131 concept->setOperandList(newBaseOpCon);
132 concept->incOperandCount();
133 }
134
135
136
137
138 }; // end namespace Answerer
139
140 }; // end namespace Reasoner
141
142 }; // end namespace Konclude