| 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 "CReapplyConceptSaturationLabelSet.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Process { |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
CReapplyConceptSaturationLabelSet::CReapplyConceptSaturationLabelSet(CProcessContext* processContext) : mProcessContext(processContext) { |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
CReapplyConceptSaturationLabelSet* CReapplyConceptSaturationLabelSet::initReapplyConceptSaturationLabelSet() { |
| 39 |
mConceptDesDepHash = nullptr; |
| 40 |
mAdditionalConceptDesDepHash = nullptr; |
| 41 |
mConceptSatDesLinker = nullptr; |
| 42 |
mConceptDesDepHash = CObjectParameterizingAllocator< CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>,CContext* >::allocateAndConstructAndParameterize(mProcessContext->getUsedMemoryAllocationManager(),mProcessContext); |
| 43 |
mConceptCount = 0; |
| 44 |
mTotelCount = 0; |
| 45 |
mModifiedUpdateLinker = nullptr; |
| 46 |
mLastNominalIndepConSatDes = nullptr; |
| 47 |
mConceptFlags.reset(); |
| 48 |
return this; |
| 49 |
} |
| 50 |
|
| 51 |
CReapplyConceptSaturationLabelSet* CReapplyConceptSaturationLabelSet::copyReapplyConceptSaturationLabelSet(CReapplyConceptSaturationLabelSet* copyConceptSaturationLabelSet, bool tryFlatLabelCopy) { |
| 52 |
mConceptCount = copyConceptSaturationLabelSet->mConceptCount; |
| 53 |
mTotelCount = copyConceptSaturationLabelSet->mTotelCount; |
| 54 |
mConceptDesDepHash = CObjectParameterizingAllocator< CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>,CContext* >::allocateAndConstructAndParameterize(mProcessContext->getUsedMemoryAllocationManager(),mProcessContext); |
| 55 |
mConceptFlags = copyConceptSaturationLabelSet->mConceptFlags; |
| 56 |
if (copyConceptSaturationLabelSet->mConceptDesDepHash->count() >= ADDITIONALCOPYSIZE || tryFlatLabelCopy && copyConceptSaturationLabelSet->mConceptDesDepHash->count() > 0) { |
| 57 |
|
| 58 |
CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>* tmpAdditionalConDesDepHash = CObjectParameterizingAllocator< CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>,CContext* >::allocateAndConstructAndParameterize(mProcessContext->getUsedMemoryAllocationManager(),mProcessContext); |
| 59 |
if (copyConceptSaturationLabelSet->mAdditionalConceptDesDepHash) { |
| 60 |
if (copyConceptSaturationLabelSet->mAdditionalConceptDesDepHash->count() > copyConceptSaturationLabelSet->mConceptDesDepHash->count()) { |
| 61 |
*tmpAdditionalConDesDepHash = *copyConceptSaturationLabelSet->mAdditionalConceptDesDepHash; |
| 62 |
tmpAdditionalConDesDepHash->detach(); |
| 63 |
|
| 64 |
for (CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>::const_iterator it = copyConceptSaturationLabelSet->mConceptDesDepHash->constBegin(), itEnd = copyConceptSaturationLabelSet->mConceptDesDepHash->constEnd(); it != itEnd; ++it) { |
| 65 |
cint64 conTag = it.key(); |
| 66 |
const CConceptSaturationDescriptorReapplyData& conDesReapplyData(it.value()); |
| 67 |
CConceptSaturationDescriptorReapplyData& newConDesReapplyData = (*tmpAdditionalConDesDepHash)[conTag]; |
| 68 |
if (conDesReapplyData.mConSatDes) { |
| 69 |
newConDesReapplyData.mConSatDes = conDesReapplyData.mConSatDes; |
| 70 |
} |
| 71 |
if (conDesReapplyData.mImpReapplyConSatDes) { |
| 72 |
newConDesReapplyData.mImpReapplyConSatDes = conDesReapplyData.mImpReapplyConSatDes; |
| 73 |
} |
| 74 |
} |
| 75 |
} else { |
| 76 |
*tmpAdditionalConDesDepHash = *copyConceptSaturationLabelSet->mConceptDesDepHash; |
| 77 |
tmpAdditionalConDesDepHash->detach(); |
| 78 |
|
| 79 |
for (CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>::const_iterator it = copyConceptSaturationLabelSet->mAdditionalConceptDesDepHash->constBegin(), itEnd = copyConceptSaturationLabelSet->mAdditionalConceptDesDepHash->constEnd(); it != itEnd; ++it) { |
| 80 |
cint64 conTag = it.key(); |
| 81 |
const CConceptSaturationDescriptorReapplyData& conDesReapplyData(it.value()); |
| 82 |
CConceptSaturationDescriptorReapplyData& newConDesReapplyData = (*tmpAdditionalConDesDepHash)[conTag]; |
| 83 |
if (conDesReapplyData.mConSatDes) { |
| 84 |
newConDesReapplyData.mConSatDes = conDesReapplyData.mConSatDes; |
| 85 |
} |
| 86 |
if (conDesReapplyData.mImpReapplyConSatDes) { |
| 87 |
newConDesReapplyData.mImpReapplyConSatDes = conDesReapplyData.mImpReapplyConSatDes; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
copyConceptSaturationLabelSet->mAdditionalConceptDesDepHash = tmpAdditionalConDesDepHash; |
| 92 |
} else { |
| 93 |
copyConceptSaturationLabelSet->mAdditionalConceptDesDepHash = copyConceptSaturationLabelSet->mConceptDesDepHash; |
| 94 |
} |
| 95 |
CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>* tmpNewConDesDepHash = CObjectParameterizingAllocator< CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>,CContext* >::allocateAndConstructAndParameterize(mProcessContext->getUsedMemoryAllocationManager(),mProcessContext); |
| 96 |
copyConceptSaturationLabelSet->mConceptDesDepHash = tmpNewConDesDepHash; |
| 97 |
} |
| 98 |
|
| 99 |
*mConceptDesDepHash = *copyConceptSaturationLabelSet->mConceptDesDepHash; |
| 100 |
mConceptDesDepHash->detach(); |
| 101 |
mAdditionalConceptDesDepHash = copyConceptSaturationLabelSet->mAdditionalConceptDesDepHash; |
| 102 |
mConceptSatDesLinker = copyConceptSaturationLabelSet->mConceptSatDesLinker; |
| 103 |
mLastNominalIndepConSatDes = copyConceptSaturationLabelSet->mLastNominalIndepConSatDes; |
| 104 |
return this; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
bool CReapplyConceptSaturationLabelSet::getConceptDescriptorAndReapplyQueue(CConcept* concept, CConceptSaturationDescriptor*& conSatDes, CImplicationReapplyConceptSaturationDescriptor*& impReapplyConSatDes) { |
| 109 |
return getConceptDescriptorAndReapplyQueue(concept->getConceptTag(),conSatDes,impReapplyConSatDes); |
| 110 |
} |
| 111 |
|
| 112 |
bool CReapplyConceptSaturationLabelSet::getConceptDescriptorAndReapplyQueue(cint64 conTag, CConceptSaturationDescriptor*& conSatDes, CImplicationReapplyConceptSaturationDescriptor*& impReapplyConSatDes) { |
| 113 |
CConceptSaturationDescriptorReapplyData* conDesDepData = nullptr; |
| 114 |
bool contained = mConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 115 |
if (!contained && mAdditionalConceptDesDepHash) { |
| 116 |
contained = mAdditionalConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 117 |
} |
| 118 |
if (contained) { |
| 119 |
conSatDes = conDesDepData->mConSatDes; |
| 120 |
impReapplyConSatDes = conDesDepData->mImpReapplyConSatDes; |
| 121 |
} |
| 122 |
return contained; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
bool CReapplyConceptSaturationLabelSet::containsConceptOrReapllyQueue(cint64 conTag) { |
| 128 |
CConceptSaturationDescriptorReapplyData* conDesDepData = nullptr; |
| 129 |
bool contained = mConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 130 |
if (!contained && mAdditionalConceptDesDepHash) { |
| 131 |
contained = mAdditionalConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 132 |
} |
| 133 |
if (contained) { |
| 134 |
return conDesDepData->mConSatDes || conDesDepData->mImpReapplyConSatDes; |
| 135 |
} |
| 136 |
return false; |
| 137 |
} |
| 138 |
|
| 139 |
cint64 CReapplyConceptSaturationLabelSet::getConceptCount() { |
| 140 |
return mConceptCount; |
| 141 |
} |
| 142 |
|
| 143 |
cint64 CReapplyConceptSaturationLabelSet::getTotalCount() { |
| 144 |
return mTotelCount; |
| 145 |
} |
| 146 |
|
| 147 |
bool CReapplyConceptSaturationLabelSet::getConceptSaturationDescriptor(CConcept* concept, CConceptSaturationDescriptor*& conSatDes, CImplicationReapplyConceptSaturationDescriptor*& impReapplyConSatDes) { |
| 148 |
return getConceptSaturationDescriptor(concept->getConceptTag(),conSatDes,impReapplyConSatDes); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
bool CReapplyConceptSaturationLabelSet::getConceptSaturationDescriptor(cint64 conTag, CConceptSaturationDescriptor*& conSatDes, CImplicationReapplyConceptSaturationDescriptor*& impReapplyConSatDes) { |
| 153 |
CConceptSaturationDescriptorReapplyData* conDesDepData = nullptr; |
| 154 |
bool contained = mConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 155 |
if (!contained && mAdditionalConceptDesDepHash) { |
| 156 |
contained = mAdditionalConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 157 |
} |
| 158 |
if (contained) { |
| 159 |
conSatDes = conDesDepData->mConSatDes; |
| 160 |
if (conSatDes) { |
| 161 |
impReapplyConSatDes = conDesDepData->mImpReapplyConSatDes; |
| 162 |
} else { |
| 163 |
impReapplyConSatDes = nullptr; |
| 164 |
} |
| 165 |
contained &= conSatDes != nullptr; |
| 166 |
} |
| 167 |
return contained; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
bool CReapplyConceptSaturationLabelSet::hasConceptSaturationDescriptor(CConceptSaturationDescriptor* conSatDes) { |
| 172 |
return hasConcept(conSatDes->getConcept(),conSatDes->isNegated()); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
bool CReapplyConceptSaturationLabelSet::hasConcept(CConcept* concept, bool negated) { |
| 177 |
if (!mConceptFlags.containsConceptFlags(concept, negated)) { |
| 178 |
return false; |
| 179 |
} |
| 180 |
cint64 conTag = concept->getConceptTag(); |
| 181 |
return hasConcept(conTag,negated); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
bool CReapplyConceptSaturationLabelSet::hasConcept(cint64 conTag, bool negated) { |
| 186 |
CConceptSaturationDescriptorReapplyData* conDesDepData = nullptr; |
| 187 |
bool isContained = mConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 188 |
if (!isContained && mAdditionalConceptDesDepHash) { |
| 189 |
isContained = mAdditionalConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 190 |
} |
| 191 |
return isContained && conDesDepData->mConSatDes && conDesDepData->mConSatDes->isNegated() == negated; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
bool CReapplyConceptSaturationLabelSet::hasConcept(CConcept* concept, bool* containsNegated) { |
| 196 |
if (!mConceptFlags.containsConceptFlags(concept)) { |
| 197 |
return false; |
| 198 |
} |
| 199 |
cint64 conTag = concept->getConceptTag(); |
| 200 |
return hasConcept(conTag,containsNegated); |
| 201 |
} |
| 202 |
|
| 203 |
bool CReapplyConceptSaturationLabelSet::hasConcept(cint64 conTag, bool* containsNegated) { |
| 204 |
CConceptSaturationDescriptorReapplyData* conDesDepData = nullptr; |
| 205 |
bool isContained = mConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 206 |
if (!isContained && mAdditionalConceptDesDepHash) { |
| 207 |
isContained = mAdditionalConceptDesDepHash->tryGetValuePointer(conTag,conDesDepData); |
| 208 |
} |
| 209 |
if (isContained && containsNegated) { |
| 210 |
*containsNegated = conDesDepData->mConSatDes && conDesDepData->mConSatDes->isNegated(); |
| 211 |
} |
| 212 |
return isContained && conDesDepData->mConSatDes; |
| 213 |
} |
| 214 |
|
| 215 |
bool CReapplyConceptSaturationLabelSet::containsConcept(CConcept* concept, bool* containsNegated) { |
| 216 |
return hasConcept(concept,containsNegated); |
| 217 |
} |
| 218 |
|
| 219 |
bool CReapplyConceptSaturationLabelSet::containsConcept(CConcept* concept, bool negated) { |
| 220 |
return hasConcept(concept,negated); |
| 221 |
} |
| 222 |
|
| 223 |
bool CReapplyConceptSaturationLabelSet::containsConceptSaturationDescriptor(CConceptSaturationDescriptor* conSatDes) { |
| 224 |
return hasConceptSaturationDescriptor(conSatDes); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
bool CReapplyConceptSaturationLabelSet::hasModifiedUpdateLinkers() { |
| 229 |
return mModifiedUpdateLinker != nullptr; |
| 230 |
} |
| 231 |
|
| 232 |
CSaturationModifiedProcessUpdateLinker* CReapplyConceptSaturationLabelSet::getModifiedUpdateLinker() { |
| 233 |
return mModifiedUpdateLinker; |
| 234 |
} |
| 235 |
|
| 236 |
CReapplyConceptSaturationLabelSet* CReapplyConceptSaturationLabelSet::addModifiedUpdateLinker(CSaturationModifiedProcessUpdateLinker* modUpdateLinker) { |
| 237 |
mModifiedUpdateLinker = modUpdateLinker->append(mModifiedUpdateLinker); |
| 238 |
return this; |
| 239 |
} |
| 240 |
|
| 241 |
CReapplyConceptSaturationLabelSet* CReapplyConceptSaturationLabelSet::setModifiedUpdateLinker(CSaturationModifiedProcessUpdateLinker* modUpdateLinker) { |
| 242 |
mModifiedUpdateLinker = modUpdateLinker; |
| 243 |
return this; |
| 244 |
} |
| 245 |
|
| 246 |
bool CReapplyConceptSaturationLabelSet::insertConceptReturnClashed(CConceptSaturationDescriptor* conSatDes, bool* newInsertion, CImplicationReapplyConceptSaturationDescriptor*** impReapplyConSatDesPtr) { |
| 247 |
cint64 conTag = conSatDes->getConceptTag(); |
| 248 |
CConceptSaturationDescriptorReapplyData& conDesDepData = (*mConceptDesDepHash)[conTag]; |
| 249 |
if (!conDesDepData.mConSatDes && !conDesDepData.mImpReapplyConSatDes && mAdditionalConceptDesDepHash) { |
| 250 |
CConceptSaturationDescriptorReapplyData* prevConDesDepData = nullptr; |
| 251 |
bool contained = mAdditionalConceptDesDepHash->tryGetValuePointer(conTag,prevConDesDepData); |
| 252 |
if (contained && prevConDesDepData) { |
| 253 |
if (prevConDesDepData->mConSatDes) { |
| 254 |
conDesDepData.mConSatDes = prevConDesDepData->mConSatDes; |
| 255 |
} |
| 256 |
if (prevConDesDepData->mImpReapplyConSatDes) { |
| 257 |
conDesDepData.mImpReapplyConSatDes = prevConDesDepData->mImpReapplyConSatDes; |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
bool inserted = false; |
| 262 |
if (!conDesDepData.mConSatDes) { |
| 263 |
conDesDepData.mConSatDes = conSatDes; |
| 264 |
|
| 265 |
inserted = true; |
| 266 |
if (newInsertion) { |
| 267 |
*newInsertion = true; |
| 268 |
} |
| 269 |
mConceptSatDesLinker = conSatDes->append(mConceptSatDesLinker); |
| 270 |
mConceptFlags.addConceptFlags(conSatDes->getConcept(), conSatDes->getNegation()); |
| 271 |
++mConceptCount; |
| 272 |
++mTotelCount; |
| 273 |
} else if (conDesDepData.mConSatDes->isNegated() != conSatDes->isNegated()) { |
| 274 |
return true; |
| 275 |
} |
| 276 |
|
| 277 |
if (impReapplyConSatDesPtr) { |
| 278 |
*impReapplyConSatDesPtr = &conDesDepData.mImpReapplyConSatDes; |
| 279 |
} |
| 280 |
return false; |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
bool CReapplyConceptSaturationLabelSet::insertConceptReapplicationReturnTriggered(cint64 conTag, CImplicationReapplyConceptSaturationDescriptor* reapplyImpReapplyConSatDes, CConceptSaturationDescriptor** conSatDes) { |
| 286 |
CConceptSaturationDescriptorReapplyData& conDesDepData = (*mConceptDesDepHash)[conTag]; |
| 287 |
if (!conDesDepData.mConSatDes && !conDesDepData.mImpReapplyConSatDes && mAdditionalConceptDesDepHash) { |
| 288 |
CConceptSaturationDescriptorReapplyData* prevConDesDepData = nullptr; |
| 289 |
bool contained = mAdditionalConceptDesDepHash->tryGetValuePointer(conTag,prevConDesDepData); |
| 290 |
if (contained && prevConDesDepData) { |
| 291 |
if (prevConDesDepData->mConSatDes) { |
| 292 |
conDesDepData.mConSatDes = prevConDesDepData->mConSatDes; |
| 293 |
} |
| 294 |
if (prevConDesDepData->mImpReapplyConSatDes) { |
| 295 |
conDesDepData.mImpReapplyConSatDes = prevConDesDepData->mImpReapplyConSatDes; |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
bool triggered = conDesDepData.mConSatDes && !conDesDepData.mConSatDes->isNegated(); |
| 300 |
if (!conDesDepData.mImpReapplyConSatDes) { |
| 301 |
++mTotelCount; |
| 302 |
} |
| 303 |
if (triggered) { |
| 304 |
if (conSatDes) { |
| 305 |
*conSatDes = conDesDepData.mConSatDes; |
| 306 |
} |
| 307 |
} |
| 308 |
conDesDepData.mImpReapplyConSatDes = reapplyImpReapplyConSatDes->append(conDesDepData.mImpReapplyConSatDes); |
| 309 |
return triggered; |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
CConceptSaturationDescriptor* CReapplyConceptSaturationLabelSet::getConceptSaturationDescriptionLinker() { |
| 314 |
return mConceptSatDesLinker; |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
CReapplyConceptSaturationLabelSetIterator CReapplyConceptSaturationLabelSet::getIterator(bool iterateConSatDes, bool iterateReapplies) { |
| 319 |
if (mAdditionalConceptDesDepHash) { |
| 320 |
return CReapplyConceptSaturationLabelSetIterator(mConceptDesDepHash->begin(),mConceptDesDepHash->end(),mAdditionalConceptDesDepHash->begin(),mAdditionalConceptDesDepHash->end(),iterateConSatDes,iterateReapplies); |
| 321 |
} else { |
| 322 |
return CReapplyConceptSaturationLabelSetIterator(mConceptDesDepHash->begin(),mConceptDesDepHash->end(),mConceptDesDepHash->end(),mConceptDesDepHash->end(),iterateConSatDes,iterateReapplies); |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
bool CReapplyConceptSaturationLabelSet::areAllConceptsInAdditionalHash() { |
| 328 |
return mConceptDesDepHash->isEmpty(); |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
CConceptSetFlags* CReapplyConceptSaturationLabelSet::getConceptFlags() { |
| 334 |
return &mConceptFlags; |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
CConceptSaturationDescriptor* CReapplyConceptSaturationLabelSet::getLastNominalIndependentConceptSaturationDescriptorLinker() { |
| 341 |
return mLastNominalIndepConSatDes; |
| 342 |
} |
| 343 |
|
| 344 |
CReapplyConceptSaturationLabelSet* CReapplyConceptSaturationLabelSet::setLastNominalIndependentConceptSaturationDescriptorLinker(CConceptSaturationDescriptor* conSatDes) { |
| 345 |
mLastNominalIndepConSatDes = conSatDes; |
| 346 |
return this; |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
}; // end namespace Process |
| 352 |
|
| 353 |
}; // end namespace Kernel |
| 354 |
|
| 355 |
}; // end namespace Reasoner |
| 356 |
|
| 357 |
}; // end namespace Konclude |