| 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 "CExpressionSplitter.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Generator { |
| 29 |
|
| 30 |
CExpressionSplitter::CExpressionSplitter(const CEXPRESSIONLIST<CBuildExpression*>& expressions) { |
| 31 |
splitExpressions(expressions); |
| 32 |
} |
| 33 |
|
| 34 |
CExpressionSplitter::CExpressionSplitter(CBuildExpression* expression1, CBuildExpression* expression2, CBuildExpression* expression3) { |
| 35 |
if (expression1) { |
| 36 |
addSplittedExpression(expression1); |
| 37 |
} |
| 38 |
if (expression2) { |
| 39 |
addSplittedExpression(expression2); |
| 40 |
} |
| 41 |
if (expression3) { |
| 42 |
addSplittedExpression(expression3); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
bool CExpressionSplitter::splitExpressions(const CEXPRESSIONLIST<CBuildExpression*>& expressions) { |
| 48 |
bool allSplitted = true; |
| 49 |
for (CEXPRESSIONLIST<CBuildExpression*>::const_iterator it = expressions.constBegin(), itEnd = expressions.constEnd(); it != itEnd; ++it) { |
| 50 |
CBuildExpression* expression(*it); |
| 51 |
allSplitted &= addSplittedExpression(expression); |
| 52 |
} |
| 53 |
return allSplitted; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
bool CExpressionSplitter::addSplittedExpression(CBuildExpression* expression) { |
| 59 |
CClassTermExpression* classExpression = dynamic_cast<CClassTermExpression*>(expression); |
| 60 |
if (classExpression) { |
| 61 |
mClassList.append(classExpression); |
| 62 |
return true; |
| 63 |
} else { |
| 64 |
CObjectPropertyTermExpression* objectPropertyExpression = dynamic_cast<CObjectPropertyTermExpression*>(expression); |
| 65 |
if (objectPropertyExpression) { |
| 66 |
mObjectPropertyList.append(objectPropertyExpression); |
| 67 |
return true; |
| 68 |
} else { |
| 69 |
CIndividualTermExpression* individualExpression = dynamic_cast<CIndividualTermExpression*>(expression); |
| 70 |
if (individualExpression) { |
| 71 |
mIndiList.append(individualExpression); |
| 72 |
return true; |
| 73 |
} else { |
| 74 |
CDataPropertyTermExpression* dataPropertyExpression = dynamic_cast<CDataPropertyTermExpression*>(expression); |
| 75 |
if (dataPropertyExpression) { |
| 76 |
mDataPropertyList.append(dataPropertyExpression); |
| 77 |
return true; |
| 78 |
} else { |
| 79 |
CDataRangeTermExpression* dataRangeExpression = dynamic_cast<CDataRangeTermExpression*>(expression); |
| 80 |
if (dataRangeExpression) { |
| 81 |
mDataRangeList.append(dataRangeExpression); |
| 82 |
CDataLiteralTermExpression* dataLiteralTermExpression = dynamic_cast<CDataLiteralTermExpression*>(expression); |
| 83 |
if (dataLiteralTermExpression) { |
| 84 |
mDataLiteralTermList.append(dataLiteralTermExpression); |
| 85 |
} else { |
| 86 |
CDatatypeExpression* datatypeExpression = dynamic_cast<CDatatypeExpression*>(expression); |
| 87 |
if (datatypeExpression) { |
| 88 |
mDatatypeList.append(datatypeExpression); |
| 89 |
} |
| 90 |
} |
| 91 |
return true; |
| 92 |
} else { |
| 93 |
CDataFacetRestrictionExpression* dataFacetRestExpression = dynamic_cast<CDataFacetRestrictionExpression*>(expression); |
| 94 |
if (dataFacetRestExpression) { |
| 95 |
mDataFacetRestrictionList.append(dataFacetRestExpression); |
| 96 |
return true; |
| 97 |
} else { |
| 98 |
CDataFacetExpression* dataFacetExpression = dynamic_cast<CDataFacetExpression*>(expression); |
| 99 |
if (dataFacetExpression) { |
| 100 |
mDataFacetList.append(dataFacetExpression); |
| 101 |
return true; |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
return false; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
bool CExpressionSplitter::testForClassExpressions(cint64 requiredClassExpressions) { |
| 115 |
if (mClassList.count() < requiredClassExpressions) { |
| 116 |
return false; |
| 117 |
} |
| 118 |
return true; |
| 119 |
} |
| 120 |
|
| 121 |
bool CExpressionSplitter::testForObjectPropertyExpressions(cint64 requiredObjectPropertyExpressions) { |
| 122 |
if (mObjectPropertyList.count() < requiredObjectPropertyExpressions) { |
| 123 |
return false; |
| 124 |
} |
| 125 |
return true; |
| 126 |
} |
| 127 |
|
| 128 |
bool CExpressionSplitter::testForIndividualExpressions(cint64 requiredIndividualExpressions) { |
| 129 |
if (mIndiList.count() < requiredIndividualExpressions) { |
| 130 |
return false; |
| 131 |
} |
| 132 |
return true; |
| 133 |
} |
| 134 |
|
| 135 |
bool CExpressionSplitter::testForDataPropertyExpressions(cint64 dataPropertyExpressions) { |
| 136 |
if (mDataPropertyList.count() < dataPropertyExpressions) { |
| 137 |
return false; |
| 138 |
} |
| 139 |
return true; |
| 140 |
} |
| 141 |
|
| 142 |
bool CExpressionSplitter::testForDataRangeExpressions(cint64 dataRangeExpressions) { |
| 143 |
if (mDataRangeList.count() < dataRangeExpressions) { |
| 144 |
return false; |
| 145 |
} |
| 146 |
return true; |
| 147 |
} |
| 148 |
|
| 149 |
bool CExpressionSplitter::testForDataLiteralTermExpressions(cint64 literalExpressions) { |
| 150 |
if (mDataLiteralTermList.count() < literalExpressions) { |
| 151 |
return false; |
| 152 |
} |
| 153 |
return true; |
| 154 |
} |
| 155 |
|
| 156 |
bool CExpressionSplitter::testForDataFacetRestrictionExpressions(cint64 dataFacetRestrictionExpressions) { |
| 157 |
if (mDataFacetRestrictionList.count() < dataFacetRestrictionExpressions) { |
| 158 |
return false; |
| 159 |
} |
| 160 |
return true; |
| 161 |
} |
| 162 |
|
| 163 |
bool CExpressionSplitter::testForDataFacetExpressions(cint64 dataFacetExpressions) { |
| 164 |
if (mDataFacetList.count() < dataFacetExpressions) { |
| 165 |
return false; |
| 166 |
} |
| 167 |
return true; |
| 168 |
} |
| 169 |
|
| 170 |
bool CExpressionSplitter::testForExpressionComposition(cint64 requiredClassExpressions, cint64 requiredObjectPropertyExpressions, cint64 requiredIndividualExpressions, cint64 dataRangeExpressions, cint64 dataPropertyExpressions, cint64 dataLiteralExpressions, cint64 datatypeExpressions, cint64 dataFacetRestrictionExpressions, cint64 dataFacetExpressions) { |
| 171 |
if (mClassList.count() < requiredClassExpressions) { |
| 172 |
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); |
| 173 |
return false; |
| 174 |
} |
| 175 |
if (mObjectPropertyList.count() < requiredObjectPropertyExpressions) { |
| 176 |
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); |
| 177 |
return false; |
| 178 |
} |
| 179 |
if (mIndiList.count() < requiredIndividualExpressions) { |
| 180 |
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); |
| 181 |
return false; |
| 182 |
} |
| 183 |
if (mDataRangeList.count() < dataRangeExpressions) { |
| 184 |
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); |
| 185 |
return false; |
| 186 |
} |
| 187 |
if (mDataPropertyList.count() < dataPropertyExpressions) { |
| 188 |
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); |
| 189 |
return false; |
| 190 |
} |
| 191 |
if (mDataLiteralTermList.count() < dataLiteralExpressions) { |
| 192 |
LOG(ERROR,"::Konclude::Reasoner::Generator::ExpressionSplitter",logTr("Couldn't extract minimal required %1 DataLiteral-Expressions, extracted DataLiteral-Expressions %2.").arg(dataLiteralExpressions).arg(mDataLiteralTermList.count()),this); |
| 193 |
return false; |
| 194 |
} |
| 195 |
if (mDatatypeList.count() < datatypeExpressions) { |
| 196 |
LOG(ERROR,"::Konclude::Reasoner::Generator::ExpressionSplitter",logTr("Couldn't extract minimal required %1 Datatype-Expressions, extracted Datatype-Expressions %2.").arg(datatypeExpressions).arg(mDatatypeList.count()),this); |
| 197 |
return false; |
| 198 |
} |
| 199 |
if (mDataFacetRestrictionList.count() < dataFacetRestrictionExpressions) { |
| 200 |
LOG(ERROR,"::Konclude::Reasoner::Generator::ExpressionSplitter",logTr("Couldn't extract minimal required %1 DataFacetRestriction-Expressions, extracted DataFacetRestriction-Expressions %2.").arg(dataFacetRestrictionExpressions).arg(mDataFacetRestrictionList.count()),this); |
| 201 |
return false; |
| 202 |
} |
| 203 |
if (mDataFacetList.count() < dataFacetExpressions) { |
| 204 |
LOG(ERROR,"::Konclude::Reasoner::Generator::ExpressionSplitter",logTr("Couldn't extract minimal required %1 DataFacet-Expressions, extracted DataFacet-Expressions %2.").arg(dataFacetExpressions).arg(mDataFacetList.count()),this); |
| 205 |
return false; |
| 206 |
} |
| 207 |
return true; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
CEXPRESSIONLIST<CClassTermExpression*>* CExpressionSplitter::getClassTermExpressionList() { |
| 213 |
return &mClassList; |
| 214 |
} |
| 215 |
|
| 216 |
CEXPRESSIONLIST<CObjectPropertyTermExpression*>* CExpressionSplitter::getObjectPropertyTermExpressionList() { |
| 217 |
return &mObjectPropertyList; |
| 218 |
} |
| 219 |
|
| 220 |
CEXPRESSIONLIST<CIndividualTermExpression*>* CExpressionSplitter::getIndividualTermExpressionList() { |
| 221 |
return &mIndiList; |
| 222 |
} |
| 223 |
|
| 224 |
CEXPRESSIONLIST<CDataRangeTermExpression*>* CExpressionSplitter::getDataRangeTermExpressionList() { |
| 225 |
return &mDataRangeList; |
| 226 |
} |
| 227 |
|
| 228 |
CEXPRESSIONLIST<CDataLiteralTermExpression*>* CExpressionSplitter::getDataLiteralTermExpressionList() { |
| 229 |
return &mDataLiteralTermList; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
CEXPRESSIONLIST<CDatatypeExpression*>* CExpressionSplitter::getDatatypeExpressionList() { |
| 234 |
return &mDatatypeList; |
| 235 |
} |
| 236 |
|
| 237 |
CEXPRESSIONLIST<CDataPropertyTermExpression*>* CExpressionSplitter::getDataPropertyTermExpressionList() { |
| 238 |
return &mDataPropertyList; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
CEXPRESSIONLIST<CDataFacetRestrictionExpression*>* CExpressionSplitter::getDataFacetRestrictionList() { |
| 243 |
return &mDataFacetRestrictionList; |
| 244 |
} |
| 245 |
|
| 246 |
CEXPRESSIONLIST<CDataFacetExpression*>* CExpressionSplitter::getDataFacetList() { |
| 247 |
return &mDataFacetList; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
CClassTermExpression* CExpressionSplitter::getFirstClassTermExpression() { |
| 252 |
return mClassList.first(); |
| 253 |
} |
| 254 |
|
| 255 |
CClassTermExpression* CExpressionSplitter::getFirstOptionalClassTermExpression() { |
| 256 |
if (mClassList.isEmpty()) { |
| 257 |
return nullptr; |
| 258 |
} |
| 259 |
return mClassList.first(); |
| 260 |
} |
| 261 |
|
| 262 |
CDataRangeTermExpression* CExpressionSplitter::getFirstOptionalDataRangeTermExpression() { |
| 263 |
if (mDataRangeList.isEmpty()) { |
| 264 |
return nullptr; |
| 265 |
} |
| 266 |
return mDataRangeList.first(); |
| 267 |
} |
| 268 |
|
| 269 |
CClassTermExpression* CExpressionSplitter::getSecondClassTermExpression() { |
| 270 |
return mClassList.at(1); |
| 271 |
} |
| 272 |
|
| 273 |
CObjectPropertyTermExpression* CExpressionSplitter::getFirstObjectPropertyTermExpression() { |
| 274 |
return mObjectPropertyList.first(); |
| 275 |
} |
| 276 |
|
| 277 |
CObjectPropertyTermExpression* CExpressionSplitter::getSecondObjectPropertyTermExpression() { |
| 278 |
return mObjectPropertyList.at(1); |
| 279 |
} |
| 280 |
|
| 281 |
CIndividualTermExpression* CExpressionSplitter::getFirstIndividualTermExpression() { |
| 282 |
return mIndiList.first(); |
| 283 |
} |
| 284 |
|
| 285 |
CIndividualTermExpression* CExpressionSplitter::getSecondIndividualTermExpression() { |
| 286 |
return mIndiList.at(1); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
CDataPropertyTermExpression* CExpressionSplitter::getFirstDataPropertyTermExpression() { |
| 291 |
return mDataPropertyList.first(); |
| 292 |
} |
| 293 |
|
| 294 |
CDataPropertyTermExpression* CExpressionSplitter::getSecondDataPropertyTermExpression() { |
| 295 |
return mDataPropertyList.at(1); |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
CDataRangeTermExpression* CExpressionSplitter::getFirstDataRangeTermExpression() { |
| 300 |
return mDataRangeList.first(); |
| 301 |
} |
| 302 |
|
| 303 |
CDataRangeTermExpression* CExpressionSplitter::getSecondDataRangeTermExpression() { |
| 304 |
return mDataRangeList.at(1); |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
CDataLiteralTermExpression* CExpressionSplitter::getFirstDataLiteralTermExpression() { |
| 309 |
return mDataLiteralTermList.first(); |
| 310 |
} |
| 311 |
|
| 312 |
CDataLiteralTermExpression* CExpressionSplitter::getSecondDataLiteralTermExpression() { |
| 313 |
return mDataLiteralTermList.at(1); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
CDatatypeExpression* CExpressionSplitter::getFirstDatatypeExpression() { |
| 318 |
return mDatatypeList.first(); |
| 319 |
} |
| 320 |
|
| 321 |
CDatatypeExpression* CExpressionSplitter::getSecondDatatypeExpression() { |
| 322 |
return mDatatypeList.at(1); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
CDataFacetRestrictionExpression* CExpressionSplitter::getFirstDataFacetRestrictionExpression() { |
| 327 |
return mDataFacetRestrictionList.first(); |
| 328 |
} |
| 329 |
|
| 330 |
CDataFacetRestrictionExpression* CExpressionSplitter::getSecondDataFacetRestrictionExpression() { |
| 331 |
return mDataFacetRestrictionList.at(1); |
| 332 |
} |
| 333 |
|
| 334 |
CDataFacetExpression* CExpressionSplitter::getFirstDataFacetExpression() { |
| 335 |
return mDataFacetList.first(); |
| 336 |
} |
| 337 |
|
| 338 |
CDataFacetExpression* CExpressionSplitter::getSecondDataFacetExpression() { |
| 339 |
return mDataFacetList.at(1); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
}; // end namespace Generator |
| 344 |
|
| 345 |
}; // end namespace Reasoner |
| 346 |
|
| 347 |
}; // end namespace Konclude |