| 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 "COntologyBuildExpressionCounter.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Ontology { |
| 29 |
|
| 30 |
|
| 31 |
COntologyBuildExpressionCounter::COntologyBuildExpressionCounter(COntologyContext* ontoContext) { |
| 32 |
mOntoContext = ontoContext; |
| 33 |
|
| 34 |
mConsistencyProblematicExpressionsChecked = false; |
| 35 |
mConsistencyProblematicExpressions = true; |
| 36 |
|
| 37 |
mExpCountVec = CObjectAllocator< cint64 >::allocateAndConstructArray(mOntoContext->getMemoryAllocationManager(),mExpTypeCount); |
| 38 |
|
| 39 |
resetBuildExpressionCount(); |
| 40 |
} |
| 41 |
|
| 42 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::referenceBuildExpressionCounter(COntologyBuildExpressionCounter* buildExpCounter) { |
| 43 |
mConsistencyProblematicExpressions = true; |
| 44 |
mConsistencyProblematicExpressionsChecked = false; |
| 45 |
if (buildExpCounter) { |
| 46 |
for (cint64 i = 0; i < mExpTypeCount; ++i) { |
| 47 |
mExpCountVec[i] = buildExpCounter->mExpCountVec[i]; |
| 48 |
} |
| 49 |
} else { |
| 50 |
resetBuildExpressionCount(); |
| 51 |
} |
| 52 |
return this; |
| 53 |
} |
| 54 |
|
| 55 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::resetBuildExpressionCount() { |
| 56 |
for (cint64 i = 0; i < mExpTypeCount; ++i) { |
| 57 |
mExpCountVec[i] = 0; |
| 58 |
} |
| 59 |
|
| 60 |
mMinimumMaxObjectCardinality = 0; |
| 61 |
mMaximumMaxObjectCardinality = 0; |
| 62 |
mMinimumMinObjectCardinality = 0; |
| 63 |
mMaximumMinObjectCardinality = 0; |
| 64 |
|
| 65 |
mMinimumMinDataCardinality = 0; |
| 66 |
mMaximumMinDataCardinality = 0; |
| 67 |
mMinimumMaxDataCardinality = 0; |
| 68 |
mMaximumMaxDataCardinality = 0; |
| 69 |
|
| 70 |
mRefferedBottomClassCount = 0; |
| 71 |
mRefferedBottomObjectPropertyCount = 0; |
| 72 |
mRefferedBottomDataPropertyCount = 0; |
| 73 |
|
| 74 |
return this; |
| 75 |
} |
| 76 |
|
| 77 |
cint64& COntologyBuildExpressionCounter::getBuildExpressionCount(CBuildExpression::ExpressionType expType) { |
| 78 |
return mExpCountVec[(cint64)expType]; |
| 79 |
} |
| 80 |
|
| 81 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::incBuildExpressionCount(CBuildExpression::ExpressionType expType, cint64 incCount) { |
| 82 |
mExpCountVec[(cint64)expType] += incCount; |
| 83 |
return this; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
bool COntologyBuildExpressionCounter::hasBuildExpressions(CBuildExpression::ExpressionType expType){ |
| 88 |
return mExpCountVec[(cint64)expType] > 0; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
cint64 COntologyBuildExpressionCounter::getMinimumMaxObjectCardinality() { |
| 94 |
return mMinimumMaxObjectCardinality; |
| 95 |
} |
| 96 |
|
| 97 |
cint64 COntologyBuildExpressionCounter::getMaximumMaxObjectCardinality() { |
| 98 |
return mMaximumMaxObjectCardinality; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
cint64 COntologyBuildExpressionCounter::getMinimumMinObjectCardinality() { |
| 103 |
return mMinimumMinObjectCardinality; |
| 104 |
} |
| 105 |
|
| 106 |
cint64 COntologyBuildExpressionCounter::getMaximumMinObjectCardinality() { |
| 107 |
return mMaximumMinObjectCardinality; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::setMinObjectCardinalityMinimumMaximumCandidate(cint64 cardinality) { |
| 112 |
mMaximumMinObjectCardinality = qMax(cardinality,mMaximumMinObjectCardinality); |
| 113 |
mMinimumMinObjectCardinality = qMin(cardinality,mMinimumMinObjectCardinality); |
| 114 |
return this; |
| 115 |
} |
| 116 |
|
| 117 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::setMaxObjectCardinalityMinimumMaximumCandidate(cint64 cardinality) { |
| 118 |
mMaximumMaxObjectCardinality = qMax(cardinality,mMaximumMaxObjectCardinality); |
| 119 |
mMinimumMaxObjectCardinality = qMin(cardinality,mMinimumMaxObjectCardinality); |
| 120 |
return this; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
cint64 COntologyBuildExpressionCounter::getMinimumMaxDataCardinality() { |
| 126 |
return mMinimumMaxDataCardinality; |
| 127 |
} |
| 128 |
|
| 129 |
cint64 COntologyBuildExpressionCounter::getMaximumMaxDataCardinality() { |
| 130 |
return mMaximumMaxDataCardinality; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
cint64 COntologyBuildExpressionCounter::getMinimumMinDataCardinality() { |
| 135 |
return mMinimumMinDataCardinality; |
| 136 |
} |
| 137 |
|
| 138 |
cint64 COntologyBuildExpressionCounter::getMaximumMinDataCardinality() { |
| 139 |
return mMaximumMinDataCardinality; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::setMinDataCardinalityMinimumMaximumCandidate(cint64 cardinality) { |
| 145 |
mMaximumMinDataCardinality = qMax(cardinality,mMaximumMinDataCardinality); |
| 146 |
mMinimumMinDataCardinality = qMin(cardinality,mMinimumMinDataCardinality); |
| 147 |
return this; |
| 148 |
} |
| 149 |
|
| 150 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::setMaxDataCardinalityMinimumMaximumCandidate(cint64 cardinality) { |
| 151 |
mMaximumMaxDataCardinality = qMax(cardinality,mMaximumMaxDataCardinality); |
| 152 |
mMinimumMaxDataCardinality = qMin(cardinality,mMinimumMaxDataCardinality); |
| 153 |
return this; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::incRefferedBottomClassCount(cint64 incCount) { |
| 158 |
mRefferedBottomClassCount += incCount; |
| 159 |
return this; |
| 160 |
} |
| 161 |
|
| 162 |
cint64 COntologyBuildExpressionCounter::getRefferedBottomClassCount() { |
| 163 |
return mRefferedBottomClassCount; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::incRefferedBottomObjectPropertyCount(cint64 incCount) { |
| 168 |
mRefferedBottomObjectPropertyCount += incCount; |
| 169 |
return this; |
| 170 |
} |
| 171 |
|
| 172 |
cint64 COntologyBuildExpressionCounter::getRefferedBottomObjectPropertyCount() { |
| 173 |
return mRefferedBottomObjectPropertyCount; |
| 174 |
} |
| 175 |
|
| 176 |
COntologyBuildExpressionCounter* COntologyBuildExpressionCounter::incRefferedBottomDataPropertyCount(cint64 incCount) { |
| 177 |
mRefferedBottomDataPropertyCount += incCount; |
| 178 |
return this; |
| 179 |
} |
| 180 |
|
| 181 |
cint64 COntologyBuildExpressionCounter::getRefferedBottomDataPropertyCount() { |
| 182 |
return mRefferedBottomDataPropertyCount; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
bool COntologyBuildExpressionCounter::hasConsistencyProblematicExpressions() { |
| 187 |
if (!mConsistencyProblematicExpressionsChecked) { |
| 188 |
|
| 189 |
mConsistencyProblematicExpressions = false; |
| 190 |
if (hasBuildExpressions(CBuildExpression::BETDISJOINTCLASSES)) { |
| 191 |
mConsistencyProblematicExpressions = true; |
| 192 |
} |
| 193 |
if (hasBuildExpressions(CBuildExpression::BETDISJOINTUNION)) { |
| 194 |
mConsistencyProblematicExpressions = true; |
| 195 |
} |
| 196 |
if (hasBuildExpressions(CBuildExpression::BETOBJECTCOMPLEMENTOF)) { |
| 197 |
mConsistencyProblematicExpressions = true; |
| 198 |
} |
| 199 |
|
| 200 |
if (hasBuildExpressions(CBuildExpression::BETDISJOINTOBJECTPROPERTIES)) { |
| 201 |
mConsistencyProblematicExpressions = true; |
| 202 |
} |
| 203 |
if (hasBuildExpressions(CBuildExpression::BETIRREFLEXIVEPROPERTY)) { |
| 204 |
mConsistencyProblematicExpressions = true; |
| 205 |
} |
| 206 |
if (hasBuildExpressions(CBuildExpression::BETASYMMETRICPROPERTY)) { |
| 207 |
mConsistencyProblematicExpressions = true; |
| 208 |
} |
| 209 |
|
| 210 |
if (hasBuildExpressions(CBuildExpression::BETDIFFERENTINDIVIDUAL)) { |
| 211 |
mConsistencyProblematicExpressions = true; |
| 212 |
} |
| 213 |
if (hasBuildExpressions(CBuildExpression::BETNEGATIVEOBJECTPROPERTYASSERTION)) { |
| 214 |
mConsistencyProblematicExpressions = true; |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
if (hasBuildExpressions(CBuildExpression::BETDISJOINTDATAPROPERTIES)) { |
| 219 |
mConsistencyProblematicExpressions = true; |
| 220 |
} |
| 221 |
if (hasBuildExpressions(CBuildExpression::BETDATASOMEVALUEFROM)) { |
| 222 |
mConsistencyProblematicExpressions = true; |
| 223 |
} |
| 224 |
if (hasBuildExpressions(CBuildExpression::BETDATAHASVALUE)) { |
| 225 |
mConsistencyProblematicExpressions = true; |
| 226 |
} |
| 227 |
if (hasBuildExpressions(CBuildExpression::BETDATAMINCARDINALITY)) { |
| 228 |
mConsistencyProblematicExpressions = true; |
| 229 |
} |
| 230 |
if (hasBuildExpressions(CBuildExpression::BETDATAEXACTCARDINALITY)) { |
| 231 |
mConsistencyProblematicExpressions = true; |
| 232 |
} |
| 233 |
if (hasBuildExpressions(CBuildExpression::BETDATASOMEVALUEFROM)) { |
| 234 |
mConsistencyProblematicExpressions = true; |
| 235 |
} |
| 236 |
if (hasBuildExpressions(CBuildExpression::BETNEGATIVEDATAPROPERTYASSERTION)) { |
| 237 |
mConsistencyProblematicExpressions = true; |
| 238 |
} |
| 239 |
if (hasBuildExpressions(CBuildExpression::BETDATAPROPERTYASSERTION)) { |
| 240 |
mConsistencyProblematicExpressions = true; |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
if (hasBuildExpressions(CBuildExpression::BETNOMINALINDIVIDUALVARIABLE)) { |
| 245 |
mConsistencyProblematicExpressions = true; |
| 246 |
} |
| 247 |
if (hasBuildExpressions(CBuildExpression::BETRULECLASSATOM)) { |
| 248 |
mConsistencyProblematicExpressions = true; |
| 249 |
} |
| 250 |
if (hasBuildExpressions(CBuildExpression::BETRULEPROPERTYATOM)) { |
| 251 |
mConsistencyProblematicExpressions = true; |
| 252 |
} |
| 253 |
if (hasBuildExpressions(CBuildExpression::BETRULEDIFFERENTINDIVIDUALSATOM)) { |
| 254 |
mConsistencyProblematicExpressions = true; |
| 255 |
} |
| 256 |
if (hasBuildExpressions(CBuildExpression::BETRULEATOMBODYLIST)) { |
| 257 |
mConsistencyProblematicExpressions = true; |
| 258 |
} |
| 259 |
if (hasBuildExpressions(CBuildExpression::BETRULEATOMHEADLIST)) { |
| 260 |
mConsistencyProblematicExpressions = true; |
| 261 |
} |
| 262 |
|
| 263 |
if (hasBuildExpressions(CBuildExpression::BETOBJECTEXACTLYCARDINALITY) || hasBuildExpressions(CBuildExpression::BETOBJECTMAXCARDINALITY)) { |
| 264 |
if (getMinimumMaxObjectCardinality() <= 0) { |
| 265 |
mConsistencyProblematicExpressions = true; |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
if (hasBuildExpressions(CBuildExpression::BETOBJECTMINCARDINALITY) || hasBuildExpressions(CBuildExpression::BETOBJECTEXACTLYCARDINALITY)) { |
| 270 |
if (getMaximumMinObjectCardinality() < 0) { |
| 271 |
mConsistencyProblematicExpressions = true; |
| 272 |
} |
| 273 |
if (getMaximumMinObjectCardinality() > 1) { |
| 274 |
if (hasBuildExpressions(CBuildExpression::BETFUNCTIONALPROPERTYOF)) { |
| 275 |
mConsistencyProblematicExpressions = true; |
| 276 |
} |
| 277 |
if (hasBuildExpressions(CBuildExpression::BETFUNCTIONALPROPERTYOF)) { |
| 278 |
mConsistencyProblematicExpressions = true; |
| 279 |
} |
| 280 |
} |
| 281 |
if (hasBuildExpressions(CBuildExpression::BETOBJECTEXACTLYCARDINALITY) || hasBuildExpressions(CBuildExpression::BETOBJECTMAXCARDINALITY)) { |
| 282 |
if (getMaximumMinObjectCardinality() > getMinimumMaxObjectCardinality()) { |
| 283 |
mConsistencyProblematicExpressions = true; |
| 284 |
} |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
if (getRefferedBottomClassCount() > 0) { |
| 289 |
mConsistencyProblematicExpressions = true; |
| 290 |
} |
| 291 |
if (getRefferedBottomClassCount() > 0) { |
| 292 |
mRefferedBottomObjectPropertyCount = true; |
| 293 |
} |
| 294 |
if (getRefferedBottomClassCount() > 0) { |
| 295 |
mRefferedBottomDataPropertyCount = true; |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
mConsistencyProblematicExpressionsChecked = true; |
| 300 |
} |
| 301 |
return mConsistencyProblematicExpressions; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
}; // end namespace Ontology |
| 306 |
|
| 307 |
}; // end namespace Reasoner |
| 308 |
|
| 309 |
}; // end namespace Konclude |