| 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 "CParsingExpressionSplitter.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Parser { |
| 27 |
|
| 28 |
CParsingExpressionSplitter::CParsingExpressionSplitter(const CEXPRESSIONLIST<CBuildExpression*>& expressions) : mExpressionList(expressions) { |
| 29 |
splitExpressions(); |
| 30 |
} |
| 31 |
|
| 32 |
CParsingExpressionSplitter::CParsingExpressionSplitter(CEXPRESSIONLIST<CBuildExpression*>* expressions) : mExpressionList(*expressions) { |
| 33 |
splitExpressions(); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
CParsingExpressionSplitter::CParsingExpressionSplitter(CBuildExpression* expression1, CBuildExpression* expression2, CBuildExpression* expression3) { |
| 38 |
if (expression1) { |
| 39 |
mExpressionList.append(expression1); |
| 40 |
} |
| 41 |
if (expression2) { |
| 42 |
mExpressionList.append(expression2); |
| 43 |
} |
| 44 |
if (expression3) { |
| 45 |
mExpressionList.append(expression3); |
| 46 |
} |
| 47 |
splitExpressions(); |
| 48 |
} |
| 49 |
|
| 50 |
CParsingExpressionSplitter::~CParsingExpressionSplitter() { |
| 51 |
} |
| 52 |
|
| 53 |
bool CParsingExpressionSplitter::splitExpressions() { |
| 54 |
FOREACHIT (CBuildExpression* expression, mExpressionList) { |
| 55 |
CClassTermExpression* classExpression = dynamic_cast<CClassTermExpression*>(expression); |
| 56 |
if (classExpression) { |
| 57 |
mClassList.append(classExpression); |
| 58 |
CObjectIndividualVariableExpression* varExpression = dynamic_cast<CObjectIndividualVariableExpression*>(classExpression); |
| 59 |
if (varExpression) { |
| 60 |
mObjIndiVarList.append(varExpression); |
| 61 |
} else { |
| 62 |
mNotObjIndiVarList.append(varExpression); |
| 63 |
} |
| 64 |
} |
| 65 |
CObjectPropertyTermExpression* objectPropertyExpression = dynamic_cast<CObjectPropertyTermExpression*>(expression); |
| 66 |
if (objectPropertyExpression) { |
| 67 |
mObjectPropertyList.append(objectPropertyExpression); |
| 68 |
} |
| 69 |
CIndividualTermExpression* individualExpression = dynamic_cast<CIndividualTermExpression*>(expression); |
| 70 |
if (individualExpression) { |
| 71 |
mIndiList.append(individualExpression); |
| 72 |
} |
| 73 |
CDataPropertyTermExpression* dataPropertyExpression = dynamic_cast<CDataPropertyTermExpression*>(expression); |
| 74 |
if (dataPropertyExpression) { |
| 75 |
mDataPropertyList.append(dataPropertyExpression); |
| 76 |
} |
| 77 |
CDataRangeTermExpression* dataRangeExpression = dynamic_cast<CDataRangeTermExpression*>(expression); |
| 78 |
if (dataRangeExpression) { |
| 79 |
mDataRangeList.append(dataRangeExpression); |
| 80 |
} |
| 81 |
CDataLiteralTermExpression* dataLitExpression = dynamic_cast<CDataLiteralTermExpression*>(expression); |
| 82 |
if (dataRangeExpression) { |
| 83 |
mDataLitList.append(dataLitExpression); |
| 84 |
} |
| 85 |
} |
| 86 |
return true; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
bool CParsingExpressionSplitter::proofExpressionComposition(cint64 requiredClassExpressions, cint64 requiredObjectPropertyExpressions, cint64 requiredIndividualExpressions, cint64 requiredVariableExpressions, cint64 requiredNotVariableExpressions, cint64 dataRangeExpressions, cint64 dataPropertyExpressions) { |
| 91 |
if (mClassList.count() < requiredClassExpressions) { |
| 92 |
LOG(ERROR,"::Konclude::Reasoner::Generator::ExpressionSplitter",logTr("Couldn't extract minimal required %1 Class-Expressions, extracted Class-Expressions %2.").arg(requiredClassExpressions).arg(mClassList.count()),this); |
| 93 |
return false; |
| 94 |
} |
| 95 |
if (mObjectPropertyList.count() < requiredObjectPropertyExpressions) { |
| 96 |
LOG(ERROR,"::Konclude::Reasoner::Generator::ExpressionSplitter",logTr("Couldn't extract minimal required %1 ObjectProperty-Expressions, extracted ObjectProperty-Expressions %2.").arg(requiredObjectPropertyExpressions).arg(mObjectPropertyList.count()),this); |
| 97 |
return false; |
| 98 |
} |
| 99 |
if (mIndiList.count() < requiredIndividualExpressions) { |
| 100 |
LOG(ERROR,"::Konclude::Reasoner::Generator::ExpressionSplitter",logTr("Couldn't extract minimal required %1 Individual-Expressions, extracted Individual-Expressions %2.").arg(requiredIndividualExpressions).arg(mIndiList.count()),this); |
| 101 |
return false; |
| 102 |
} |
| 103 |
if (mObjIndiVarList.count() < requiredVariableExpressions) { |
| 104 |
LOG(ERROR,"::Konclude::Reasoner::Generator::ExpressionSplitter",logTr("Couldn't extract minimal required %1 Variable-Expressions, extracted Variable-Expressions %2.").arg(requiredVariableExpressions).arg(mObjIndiVarList.count()),this); |
| 105 |
return false; |
| 106 |
} |
| 107 |
if (mNotObjIndiVarList.count() < requiredNotVariableExpressions) { |
| 108 |
LOG(ERROR,"::Konclude::Reasoner::Generator::ExpressionSplitter",logTr("Couldn't extract minimal required %1 Non-Variable-Expressions, extracted Non-Variable-Expressions %2.").arg(requiredNotVariableExpressions).arg(mNotObjIndiVarList.count()),this); |
| 109 |
return false; |
| 110 |
} |
| 111 |
if (mDataRangeList.count() < dataRangeExpressions) { |
| 112 |
LOG(ERROR, "::Konclude::Reasoner::Generator::ExpressionSplitter", logTr("Couldn't extract minimal required %1 DataRange-Expressions, extracted DataRange-Expressions %2.").arg(dataRangeExpressions).arg(mDataRangeList.count()), this); |
| 113 |
return false; |
| 114 |
} |
| 115 |
if (mDataPropertyList.count() < dataPropertyExpressions) { |
| 116 |
LOG(ERROR, "::Konclude::Reasoner::Generator::ExpressionSplitter", logTr("Couldn't extract minimal required %1 DataProperty-Expressions, extracted DataProperty-Expressions %2.").arg(dataPropertyExpressions).arg(mDataPropertyList.count()), this); |
| 117 |
return false; |
| 118 |
} |
| 119 |
return true; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
CEXPRESSIONLIST<CDataRangeTermExpression*>* CParsingExpressionSplitter::getDataRangeTermExpressionList() { |
| 124 |
return &mDataRangeList; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
CEXPRESSIONLIST<CDataLiteralTermExpression*>* CParsingExpressionSplitter::getDataLiteralTermExpressionList() { |
| 129 |
return &mDataLitList; |
| 130 |
} |
| 131 |
|
| 132 |
CEXPRESSIONLIST<CDataPropertyTermExpression*>* CParsingExpressionSplitter::getDataPropertyTermExpressionList() { |
| 133 |
return &mDataPropertyList; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
CEXPRESSIONLIST<CClassTermExpression*>* CParsingExpressionSplitter::getClassTermExpressionList() { |
| 138 |
return &mClassList; |
| 139 |
} |
| 140 |
|
| 141 |
CEXPRESSIONLIST<CObjectPropertyTermExpression*>* CParsingExpressionSplitter::getObjectPropertyTermExpressionList() { |
| 142 |
return &mObjectPropertyList; |
| 143 |
} |
| 144 |
|
| 145 |
CEXPRESSIONLIST<CIndividualTermExpression*>* CParsingExpressionSplitter::getIndividualTermExpressionList() { |
| 146 |
return &mIndiList; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
CEXPRESSIONLIST<CObjectIndividualVariableExpression*>* CParsingExpressionSplitter::getClassVariableTermExpressionList() { |
| 151 |
return &mObjIndiVarList; |
| 152 |
} |
| 153 |
|
| 154 |
CEXPRESSIONLIST<CClassTermExpression*>* CParsingExpressionSplitter::getClassNotVariableTermExpressionList() { |
| 155 |
return &mNotObjIndiVarList; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
CObjectIndividualVariableExpression* CParsingExpressionSplitter::getFirstClassVariableTermExpression() { |
| 160 |
return mObjIndiVarList.first(); |
| 161 |
} |
| 162 |
|
| 163 |
CObjectIndividualVariableExpression* CParsingExpressionSplitter::getSecondClassVariableTermExpression() { |
| 164 |
return mObjIndiVarList.at(1); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
CClassTermExpression* CParsingExpressionSplitter::getFirstClassTermExpression() { |
| 169 |
return mClassList.first(); |
| 170 |
} |
| 171 |
|
| 172 |
CClassTermExpression* CParsingExpressionSplitter::getFirstOptionalClassTermExpression() { |
| 173 |
if (mClassList.isEmpty()) { |
| 174 |
return nullptr; |
| 175 |
} |
| 176 |
return mClassList.first(); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
CClassTermExpression* CParsingExpressionSplitter::getSecondClassTermExpression() { |
| 181 |
return mClassList.at(1); |
| 182 |
} |
| 183 |
|
| 184 |
CObjectPropertyTermExpression* CParsingExpressionSplitter::getFirstObjectPropertyTermExpression() { |
| 185 |
return mObjectPropertyList.first(); |
| 186 |
} |
| 187 |
|
| 188 |
CObjectPropertyTermExpression* CParsingExpressionSplitter::getSecondObjectPropertyTermExpression() { |
| 189 |
return mObjectPropertyList.at(1); |
| 190 |
} |
| 191 |
|
| 192 |
CIndividualTermExpression* CParsingExpressionSplitter::getFirstIndividualTermExpression() { |
| 193 |
return mIndiList.first(); |
| 194 |
} |
| 195 |
|
| 196 |
CIndividualTermExpression* CParsingExpressionSplitter::getSecondIndividualTermExpression() { |
| 197 |
return mIndiList.at(1); |
| 198 |
} |
| 199 |
|
| 200 |
CDataPropertyTermExpression* CParsingExpressionSplitter::getFirstDataPropertyTermExpression() { |
| 201 |
return mDataPropertyList.first(); |
| 202 |
} |
| 203 |
|
| 204 |
CDataPropertyTermExpression* CParsingExpressionSplitter::getSecondDataPropertyTermExpression() { |
| 205 |
return mDataPropertyList.at(1); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
CDataRangeTermExpression* CParsingExpressionSplitter::getFirstDataRangeTermExpression() { |
| 210 |
return mDataRangeList.first(); |
| 211 |
} |
| 212 |
|
| 213 |
CDataRangeTermExpression* CParsingExpressionSplitter::getSecondDataRangeTermExpression() { |
| 214 |
return mDataRangeList.at(1); |
| 215 |
} |
| 216 |
|
| 217 |
CDataLiteralTermExpression* CParsingExpressionSplitter::getFirstDataLiteralTermExpression() { |
| 218 |
return mDataLitList.first(); |
| 219 |
} |
| 220 |
|
| 221 |
CDataLiteralTermExpression* CParsingExpressionSplitter::getSecondDataLiteralTermExpression() { |
| 222 |
return mDataLitList.at(1); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
}; // end namespace Parser |
| 227 |
|
| 228 |
}; // end namespace Konclude |