| 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 "CTriggeredImplicationGCIAbsorberPreProcess.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Preprocess { |
| 29 |
|
| 30 |
|
| 31 |
#ifdef KONCLUDE_FORCE_ALL_DEBUG_DEACTIVATED |
| 32 |
#define KONCLUCE_PREPROCESSING_TRIGGERED_IMPLICATION_STRING_INSTRUCTION(a) |
| 33 |
#else |
| 34 |
//#define KONCLUCE_PREPROCESSING_TRIGGERED_IMPLICATION_STRING_INSTRUCTION(a) a |
| 35 |
#define KONCLUCE_PREPROCESSING_TRIGGERED_IMPLICATION_STRING_INSTRUCTION(a) |
| 36 |
#endif |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
CTriggeredImplicationGCIAbsorberPreProcess::CTriggeredImplicationGCIAbsorberPreProcess() { |
| 41 |
mConfRequiresExistingInverseRole = false; |
| 42 |
mConfAbsorbEqClassDefinitions = true; |
| 43 |
mConfAbsorbDisjunctions = true; |
| 44 |
mConfAbsorbSimpleDisjunctions = true; |
| 45 |
mConfPartialGCIAbsorption = true; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
CTriggeredImplicationGCIAbsorberPreProcess::~CTriggeredImplicationGCIAbsorberPreProcess() { |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
CConcreteOntology *CTriggeredImplicationGCIAbsorberPreProcess::preprocess(CConcreteOntology *ontology, CPreProcessContext* context) { |
| 54 |
CMBox *mBox = ontology->getDataBoxes()->getMBox(); |
| 55 |
CTBox *tBox = ontology->getDataBoxes()->getTBox(); |
| 56 |
CRBox *rBox = ontology->getDataBoxes()->getRBox(); |
| 57 |
CABox *aBox = ontology->getDataBoxes()->getABox(); |
| 58 |
|
| 59 |
mConceptVec = tBox->getConceptVector(); |
| 60 |
cint64 conceptCount = mConceptVec->getItemCount(); |
| 61 |
|
| 62 |
CRoleVector *roles = rBox->getRoleVector(); |
| 63 |
|
| 64 |
CConcept *topConcept = tBox->getTopConcept(); |
| 65 |
mBottomConcept = tBox->getBottomConcept(); |
| 66 |
|
| 67 |
mMemMan = ontology->getDataBoxes()->getBoxContext()->getMemoryAllocationManager(); |
| 68 |
mOnto = ontology; |
| 69 |
|
| 70 |
|
| 71 |
CConfiguration* config = context->getConfiguration(); |
| 72 |
mConfAbsorbDisjunctions = CConfigDataReader::readConfigBoolean(config,"Konclude.Calculation.Preprocessing.DisjunctionToImplicationAbsorption",true); |
| 73 |
mConfAbsorbSimpleDisjunctions = CConfigDataReader::readConfigBoolean(config,"Konclude.Calculation.Preprocessing.DisjunctionToImplicationAbsorptionByExistingTriggers",true); |
| 74 |
mConfAbsorbEqClassDefinitions = CConfigDataReader::readConfigBoolean(config,"Konclude.Calculation.Preprocessing.EquivalentDefinitionToSubclassImplicationAbsorption",true); |
| 75 |
mConfPartialGCIAbsorption = CConfigDataReader::readConfigBoolean(config,"Konclude.Calculation.Preprocessing.PartialGCIImplicationAbsorption",true); |
| 76 |
|
| 77 |
|
| 78 |
CImplicationReplacementVector* impRepVec = nullptr; |
| 79 |
if (mConfAbsorbDisjunctions || mConfAbsorbSimpleDisjunctions) { |
| 80 |
impRepVec = mBox->getImplicationReplacementVector(true); |
| 81 |
} |
| 82 |
|
| 83 |
mTriggerImplHash = tBox->getTriggerImplicationHash(true); |
| 84 |
|
| 85 |
|
| 86 |
mStatInvRolesGenerated = 0; |
| 87 |
mStatGCIAbsorbed = 0; |
| 88 |
mStatGCINormalAbsorbed = 0; |
| 89 |
mStatGCITotal = 0; |
| 90 |
mStatEqAbsorbed = 0; |
| 91 |
mStatEqTotal = 0; |
| 92 |
mStatImplConceptsGenerated = 0; |
| 93 |
mStatGCIAbsorptionPartialExtended = 0; |
| 94 |
mStatGCIPartialAbsorbed = 0; |
| 95 |
|
| 96 |
if (mConfAbsorbEqClassDefinitions) { |
| 97 |
QList<CConcept*> equivConceptAbsorbList; |
| 98 |
// try to absorb equivalent classes expressions |
| 99 |
for (cint64 conIdx = 0; conIdx < conceptCount; conIdx++) { |
| 100 |
CConcept* concept = mConceptVec->getLocalData(conIdx); |
| 101 |
if (concept) { |
| 102 |
cint64 opCode = concept->getOperatorCode(); |
| 103 |
if (opCode == CCEQ) { |
| 104 |
++mStatEqTotal; |
| 105 |
if (isEquivalenceConceptTriggeredImplicationAbsorbable(concept,false)) { |
| 106 |
// absorb to subclass and implication trigger |
| 107 |
concept->setOperatorCode(CCSUB); |
| 108 |
equivConceptAbsorbList.append(concept); |
| 109 |
++mStatEqAbsorbed; |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
foreach (CConcept* concept, equivConceptAbsorbList) { |
| 116 |
createEquivalenceAbsorbedTriggeredImplication(concept,false); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
mFirstNewConceptTag = mConceptVec->getItemCount(); |
| 121 |
mLastNewConceptTag = mFirstNewConceptTag; |
| 122 |
|
| 123 |
|
| 124 |
if (topConcept) { |
| 125 |
CSortedNegLinker<CConcept*>* lastgciConLinker = nullptr; |
| 126 |
CSortedNegLinker<CConcept*>* gciConLinker = topConcept->getOperandList(); |
| 127 |
CSortedNegLinker<CConcept*>* gciConLinkerIt = gciConLinker; |
| 128 |
while (gciConLinkerIt) { |
| 129 |
CConcept* opCon = gciConLinkerIt->getData(); |
| 130 |
bool opNegation = gciConLinkerIt->isNegated(); |
| 131 |
++mStatGCITotal; |
| 132 |
bool absorbed = false; |
| 133 |
|
| 134 |
mFirstNewConceptTag = mLastNewConceptTag; |
| 135 |
|
| 136 |
KONCLUCE_PREPROCESSING_TRIGGERED_IMPLICATION_STRING_INSTRUCTION(mDebugLastGCIString = generateDebugGCIConceptString(opCon,opNegation)); |
| 137 |
|
| 138 |
if (absorbGCIConceptsToTriggeredImplications(opCon,opNegation)) { |
| 139 |
++mStatGCINormalAbsorbed; |
| 140 |
KONCLUCE_PREPROCESSING_TRIGGERED_IMPLICATION_STRING_INSTRUCTION(mDebugLastAbsorbedGCITechniqueString = QString("implication absorbed")); |
| 141 |
absorbed = true; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
if (!absorbed && mConfPartialGCIAbsorption) { |
| 146 |
if (absorbPartialGCIConceptsToTriggeredImplications(opCon,opNegation)) { |
| 147 |
++mStatGCIPartialAbsorbed; |
| 148 |
KONCLUCE_PREPROCESSING_TRIGGERED_IMPLICATION_STRING_INSTRUCTION(mDebugLastAbsorbedGCITechniqueString = QString("partial implication absorbed")); |
| 149 |
absorbed = true; |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
if (absorbed) { |
| 155 |
++mStatGCIAbsorbed; |
| 156 |
mLastNewConceptTag = mConceptVec->getItemCount(); |
| 157 |
KONCLUCE_PREPROCESSING_TRIGGERED_IMPLICATION_STRING_INSTRUCTION(mDebugLastAbsorbedGCIConceptString = generateDebugGeneratedAbsorbedImplicationString(mFirstNewConceptTag,mLastNewConceptTag)); |
| 158 |
KONCLUCE_PREPROCESSING_TRIGGERED_IMPLICATION_STRING_INSTRUCTION(mDebugLastAbsorbedGCIString = QString("GCI:<br>\r\n<br>\r\n%1<br>\r\n%2 to<br>\r\n<br>\r\n%3<p>\r\n\r\n").arg(mDebugLastGCIString).arg(mDebugLastAbsorbedGCITechniqueString).arg(mDebugLastAbsorbedGCIConceptString)); |
| 159 |
KONCLUCE_PREPROCESSING_TRIGGERED_IMPLICATION_STRING_INSTRUCTION(mDebugTotalAbsorbedGCIString += mDebugLastAbsorbedGCIString); |
| 160 |
if (lastgciConLinker) { |
| 161 |
lastgciConLinker->setNext(gciConLinkerIt->getNext()); |
| 162 |
} else { |
| 163 |
topConcept->setOperandList(gciConLinkerIt->getNext()); |
| 164 |
} |
| 165 |
topConcept->incOperandCount(-1); |
| 166 |
} else { |
| 167 |
lastgciConLinker = gciConLinkerIt; |
| 168 |
} |
| 169 |
|
| 170 |
gciConLinkerIt = gciConLinkerIt->getNext(); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
if (mConfAbsorbDisjunctions || mConfAbsorbSimpleDisjunctions) { |
| 176 |
for (cint64 conIdx = 0; conIdx < conceptCount; conIdx++) { |
| 177 |
CConcept* concept = mConceptVec->getLocalData(conIdx); |
| 178 |
bool localRepData = false; |
| 179 |
CReplacementData* prevReplData = impRepVec->getData(conIdx,&localRepData); |
| 180 |
if (concept && (!prevReplData || !localRepData)) { |
| 181 |
cint64 opCode = concept->getOperatorCode(); |
| 182 |
bool absorbable = false; |
| 183 |
bool absorbNeg = false; |
| 184 |
bool absorbPos = false; |
| 185 |
cint64 opCount = concept->getOperandCount(); |
| 186 |
if (opCount > 1) { |
| 187 |
if (opCode == CCAND) { |
| 188 |
absorbNeg = true; |
| 189 |
absorbPos = true; |
| 190 |
} else if (opCode == CCOR) { |
| 191 |
absorbNeg = false; |
| 192 |
absorbPos = true; |
| 193 |
} |
| 194 |
if (absorbPos) { |
| 195 |
if (mConfAbsorbSimpleDisjunctions && isDisjunctionConceptSimpleTriggeredImplicationAbsorbable(concept,absorbNeg)) { |
| 196 |
absorbable = true; |
| 197 |
} else if (mConfAbsorbDisjunctions && isDisjunctionConceptTriggeredImplicationAbsorbable(concept,absorbNeg)) { |
| 198 |
// add implication trigger absorption |
| 199 |
absorbable = true; |
| 200 |
} |
| 201 |
} |
| 202 |
if (absorbable) { |
| 203 |
CConcept* absorbedImpCon = createDisjunctionAbsorbedTriggeredImplication(concept,absorbNeg); |
| 204 |
|
| 205 |
CReplacementData* replData = prevReplData; |
| 206 |
if (!localRepData) { |
| 207 |
replData = CObjectAllocator<CReplacementData>::allocateAndConstruct(mMemMan); |
| 208 |
replData->initReplacementData(prevReplData); |
| 209 |
impRepVec->setData(concept->getConceptTag(),replData); |
| 210 |
} |
| 211 |
replData->setImplicationReplacementConcept(absorbedImpCon); |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
LOG(INFO,"::Konclude::Reasoner::Preprocess::TriggeredImplicationAbsorber",logTr("Absorbed %1 of %2 equivalence class definitions.").arg(mStatEqAbsorbed).arg(mStatEqTotal),this); |
| 219 |
LOG(INFO,"::Konclude::Reasoner::Preprocess::TriggeredImplicationAbsorber",logTr("Absorbed %1 of %2 GCI definitions.").arg(mStatGCIAbsorbed).arg(mStatGCITotal),this); |
| 220 |
if (mStatGCITotal > 0) { |
| 221 |
LOG(INFO,"::Konclude::Reasoner::Preprocess::TriggeredImplicationAbsorber",logTr("Absorbed %1 GCI definitions only partially and extended %2 absorptions partially.").arg(mStatGCIPartialAbsorbed).arg(mStatGCIAbsorptionPartialExtended),this); |
| 222 |
} |
| 223 |
LOG(INFO,"::Konclude::Reasoner::Preprocess::TriggeredImplicationAbsorber",logTr("Generated %1 triggered implication concepts and %2 additional inverse roles.").arg(mStatImplConceptsGenerated).arg(mStatInvRolesGenerated),this); |
| 224 |
|
| 225 |
return ontology; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
QString CTriggeredImplicationGCIAbsorberPreProcess::generateDebugGCIConceptString(CConcept* concept, bool conceptNegation) { |
| 232 |
mDebugGCIString = CConceptTextFormater::getConceptString(concept,conceptNegation); |
| 233 |
return mDebugGCIString; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
QString CTriggeredImplicationGCIAbsorberPreProcess::generateDebugGeneratedAbsorbedImplicationString(cint64 minNewConceptTag, cint64 lastNewConceptTag) { |
| 238 |
QString absorbedString; |
| 239 |
for (cint64 tag = minNewConceptTag; tag <= lastNewConceptTag; ++tag) { |
| 240 |
CConcept* concept = mConceptVec->getData(tag); |
| 241 |
if (concept) { |
| 242 |
QString tmpString = CConceptTextFormater::getConceptString(concept,false); |
| 243 |
absorbedString += QString("%1<br>\r\n").arg(tmpString); |
| 244 |
} |
| 245 |
} |
| 246 |
mDebugAbsorbedString = absorbedString; |
| 247 |
return absorbedString; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
CConcept* CTriggeredImplicationGCIAbsorberPreProcess::createImpliedConcept() { |
| 252 |
CConcept* concept = CObjectAllocator< CConcept >::allocateAndConstruct(mMemMan); |
| 253 |
concept->initConcept(); |
| 254 |
cint64 nextConTag = mConceptVec->getItemCount(); |
| 255 |
concept->initTag(nextConTag); |
| 256 |
concept->setOperatorCode(CCAND); |
| 257 |
mConceptVec->setLocalData(nextConTag,concept); |
| 258 |
return concept; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
bool CTriggeredImplicationGCIAbsorberPreProcess::addConceptToImplied(CConcept* impliedConcept, CConcept* concept, bool negated) { |
| 263 |
CSortedNegLinker<CConcept*>* newBaseOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(mMemMan); |
| 264 |
newBaseOpCon->init(concept,negated,impliedConcept->getOperandList()); |
| 265 |
impliedConcept->setOperandList(newBaseOpCon); |
| 266 |
impliedConcept->incOperandCount(); |
| 267 |
return true; |
| 268 |
} |
| 269 |
|
| 270 |
bool CTriggeredImplicationGCIAbsorberPreProcess::addSubClassConcept(CConcept* subclassConcept, CConcept* addedConcept, bool negated) { |
| 271 |
CSortedNegLinker<CConcept*>* newBaseOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(mMemMan); |
| 272 |
newBaseOpCon->init(addedConcept,negated,subclassConcept->getOperandList()); |
| 273 |
subclassConcept->setOperandList(newBaseOpCon); |
| 274 |
subclassConcept->incOperandCount(); |
| 275 |
subclassConcept->setOperatorCode(CCSUB); |
| 276 |
return true; |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
bool CTriggeredImplicationGCIAbsorberPreProcess::addRoleDomainConcept(CRole* role, CConcept* addedConcept, bool negated) { |
| 281 |
CSortedNegLinker<CConcept*>* newBaseOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(mMemMan); |
| 282 |
newBaseOpCon->init(addedConcept,negated,role->getDomainConceptList()); |
| 283 |
role->setDomainConceptList(newBaseOpCon); |
| 284 |
return true; |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
CConcept* CTriggeredImplicationGCIAbsorberPreProcess::createImplicationConcept(CConcept* impliedConcept, bool negated) { |
| 290 |
CConcept* concept = CObjectAllocator< CConcept >::allocateAndConstruct(mMemMan); |
| 291 |
concept->initConcept(); |
| 292 |
cint64 nextConTag = mConceptVec->getItemCount(); |
| 293 |
concept->initTag(nextConTag); |
| 294 |
concept->setOperatorCode(CCIMPL); |
| 295 |
|
| 296 |
CSortedNegLinker<CConcept*>* newBaseOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(mMemMan); |
| 297 |
newBaseOpCon->init(impliedConcept,negated); |
| 298 |
concept->setOperandList(newBaseOpCon); |
| 299 |
concept->incOperandCount(); |
| 300 |
|
| 301 |
mConceptVec->setLocalData(nextConTag,concept); |
| 302 |
++mStatImplConceptsGenerated; |
| 303 |
return concept; |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
CConcept* CTriggeredImplicationGCIAbsorberPreProcess::createImplicationTriggerConcept(CConcept* impConcept, bool negated) { |
| 309 |
CConcept* concept = CObjectAllocator< CConcept >::allocateAndConstruct(mMemMan); |
| 310 |
concept->initConcept(); |
| 311 |
cint64 nextConTag = mConceptVec->getItemCount(); |
| 312 |
concept->initTag(nextConTag); |
| 313 |
concept->setOperatorCode(CCIMPLTRIG); |
| 314 |
mConceptVec->setLocalData(nextConTag,concept); |
| 315 |
if (impConcept) { |
| 316 |
addConceptToImplied(concept,impConcept,negated); |
| 317 |
} |
| 318 |
return concept; |
| 319 |
} |
| 320 |
|
| 321 |
bool CTriggeredImplicationGCIAbsorberPreProcess::addImplicationTrigger(CConcept* implConcept, CConcept* triggerConcept, bool negated) { |
| 322 |
CSortedNegLinker<CConcept*>* newTriggerOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(mMemMan); |
| 323 |
newTriggerOpCon->init(triggerConcept,negated,implConcept->getOperandList()->getNext()); |
| 324 |
implConcept->getOperandList()->setNext(newTriggerOpCon); |
| 325 |
implConcept->incOperandCount(); |
| 326 |
mTriggerImplHash->insertMulti(triggerConcept,implConcept); |
| 327 |
return true; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
CConcept* CTriggeredImplicationGCIAbsorberPreProcess::createTriggerPropagationConcept(CConcept* destConcept, CRole* backwardPropRole) { |
| 332 |
CConcept* concept = CObjectAllocator< CConcept >::allocateAndConstruct(mMemMan); |
| 333 |
CRole* invRole = getInverseRole(backwardPropRole); |
| 334 |
concept->initConcept(); |
| 335 |
cint64 nextConTag = mConceptVec->getItemCount(); |
| 336 |
concept->initTag(nextConTag); |
| 337 |
concept->setOperatorCode(CCIMPLALL); |
| 338 |
concept->setRole(invRole); |
| 339 |
CSortedNegLinker<CConcept*>* newTriggerOpCon = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(mMemMan); |
| 340 |
newTriggerOpCon->init(destConcept,false); |
| 341 |
concept->setOperandList(newTriggerOpCon); |
| 342 |
concept->incOperandCount(); |
| 343 |
mConceptVec->setLocalData(nextConTag,concept); |
| 344 |
return concept; |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
CRole* CTriggeredImplicationGCIAbsorberPreProcess::getInverseRole(CRole* role) { |
| 349 |
CSortedNegLinker<CRole*>* eqInvRoleIt = role->getInverseEquivalentRoleList(); |
| 350 |
while (eqInvRoleIt) { |
| 351 |
if (eqInvRoleIt->isNegated()) { |
| 352 |
return eqInvRoleIt->getData(); |
| 353 |
} |
| 354 |
eqInvRoleIt = eqInvRoleIt->getNext(); |
| 355 |
} |
| 356 |
CSortedNegLinker<CRole*>* superRoleIt = role->getIndirectSuperRoleList(); |
| 357 |
while (superRoleIt) { |
| 358 |
if (superRoleIt->isNegated()) { |
| 359 |
CRole* superRole = superRoleIt->getData(); |
| 360 |
CSortedNegLinker<CRole*>* superRoleSuperRoleIt = superRole->getIndirectSuperRoleList(); |
| 361 |
while (superRoleSuperRoleIt) { |
| 362 |
if (superRoleSuperRoleIt->isNegated() && superRoleSuperRoleIt->getData() == role) { |
| 363 |
return superRole; |
| 364 |
} |
| 365 |
superRoleSuperRoleIt = superRoleSuperRoleIt->getNext(); |
| 366 |
} |
| 367 |
} |
| 368 |
superRoleIt = superRoleIt->getNext(); |
| 369 |
} |
| 370 |
|
| 371 |
// create inverse role |
| 372 |
CRole* invRole = CConcreteOntologyInverseRoleBuilder::createInverseRole(role,mOnto); |
| 373 |
++mStatInvRolesGenerated; |
| 374 |
return invRole; |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
CConcept* CTriggeredImplicationGCIAbsorberPreProcess::createEquivalenceAbsorbedTriggeredImplication(CConcept* eqConcept, bool negated) { |
| 380 |
CConcept* impliedConcept = eqConcept; |
| 381 |
CConcept* implicationConcept = createImplicationConcept(impliedConcept,false); |
| 382 |
|
| 383 |
|
| 384 |
//if (eqConcept->hasClassName()) { |
| 385 |
// QString iriClassNameString = CIRIName::getRecentIRIName(eqConcept->getClassNameLinker()); |
| 386 |
// if (iriClassNameString == QString("http://www.owllink.org/testsuite/galen#LungPathology")) { |
| 387 |
// bool bug = true; |
| 388 |
// } |
| 389 |
//} |
| 390 |
|
| 391 |
|
| 392 |
CSortedNegLinker<CConcept*>* opConLinkerIt = eqConcept->getOperandList(); |
| 393 |
while (opConLinkerIt) { |
| 394 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 395 |
bool opNegated = opConLinkerIt->isNegated(); |
| 396 |
createImplicationAddedToTrigger(implicationConcept,nullptr,opConcept,opNegated); |
| 397 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 398 |
} |
| 399 |
return implicationConcept; |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
CConcept* CTriggeredImplicationGCIAbsorberPreProcess::createDisjunctionAbsorbedTriggeredImplication(CConcept* orConcept, bool negated) { |
| 406 |
CConcept* impliedConcept = createImpliedConcept(); |
| 407 |
CConcept* implicationConcept = createImplicationConcept(impliedConcept,false); |
| 408 |
|
| 409 |
bool oneNotTriggered = false; |
| 410 |
|
| 411 |
CSortedNegLinker<CConcept*>* opConLinkerIt = orConcept->getOperandList(); |
| 412 |
while (opConLinkerIt) { |
| 413 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 414 |
bool opNegated = opConLinkerIt->isNegated(); |
| 415 |
if (!oneNotTriggered && !opConLinkerIt->hasNext() || !isConceptImplicationTriggerable(opConcept,!(negated^opNegated))) { |
| 416 |
oneNotTriggered = true; |
| 417 |
addConceptToImplied(impliedConcept,opConcept,negated^opNegated); |
| 418 |
} else { |
| 419 |
createTrigger(implicationConcept,nullptr,opConcept,!(negated^opNegated),nullptr,nullptr); |
| 420 |
} |
| 421 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 422 |
} |
| 423 |
if (impliedConcept->getOperandCount() >= 1) { |
| 424 |
impliedConcept->setOperatorCode(CCOR); |
| 425 |
} else { |
| 426 |
impliedConcept->setOperatorCode(CCAND); |
| 427 |
} |
| 428 |
return implicationConcept; |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
cint64 CTriggeredImplicationGCIAbsorberPreProcess::createImplicationAddedToTrigger(CConcept* implicationConcept, CConcept* triggerConcept, CConcept* concept, bool negated) { |
| 434 |
cint64 triggerCount = 0; |
| 435 |
cint64 maxImpAddTriggerCount = 0; |
| 436 |
CConcept* maxImpAddTriggerConcept = nullptr; |
| 437 |
if (!implicationConcept) { |
| 438 |
implicationConcept = createImplicationConcept(triggerConcept,false); |
| 439 |
triggerConcept = nullptr; |
| 440 |
} |
| 441 |
|
| 442 |
triggerCount = createTrigger(implicationConcept,triggerConcept,concept,negated,&maxImpAddTriggerCount,&maxImpAddTriggerConcept); |
| 443 |
|
| 444 |
if (maxImpAddTriggerConcept) { |
| 445 |
cint64 opCode = maxImpAddTriggerConcept->getOperatorCode(); |
| 446 |
if (opCode != CCNONE) { |
| 447 |
addConceptToImplied(maxImpAddTriggerConcept,implicationConcept,false); |
| 448 |
} else { |
| 449 |
addSubClassConcept(maxImpAddTriggerConcept,implicationConcept,false); |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
return triggerCount; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
cint64 CTriggeredImplicationGCIAbsorberPreProcess::createTrigger(CConcept* implicationConcept, CConcept* triggerConcept, CConcept* concept, bool negated, cint64* impAddTriggerCount, CConcept** impAddTriggerConcept) { |
| 459 |
cint64 triggerCount = 0; |
| 460 |
cint64 triggerForAddingImpCount = 0; |
| 461 |
CConcept* triggerForAddingImpConcept = nullptr; |
| 462 |
cint64 opCode = concept->getOperatorCode(); |
| 463 |
cint64 parm = concept->getParameter(); |
| 464 |
cint64 opCount = concept->getOperandCount(); |
| 465 |
CRole* role = concept->getRole(); |
| 466 |
CSortedNegLinker<CConcept*>* opConLinker = concept->getOperandList(); |
| 467 |
if (!negated && (opCode == CCIMPLALL || opCode == CCIMPL || opCode == CCIMPLTRIG)) { |
| 468 |
// nothing to do |
| 469 |
} else if (!negated && (opCode == CCATOM || opCode == CCSUB)) { |
| 470 |
CConcept* locatedConcept = CConceptRoleIndividualLocator::getLocatedConcept(concept,mOnto); |
| 471 |
|
| 472 |
//if (concept->hasClassName()) { |
| 473 |
// QString iriClassNameString = CIRIName::getRecentIRIName(concept->getClassNameLinker()); |
| 474 |
// if (iriClassNameString == QString("http://www.owllink.org/testsuite/galen#nonNormal")) { |
| 475 |
// bool bug = true; |
| 476 |
// } |
| 477 |
//} |
| 478 |
|
| 479 |
++triggerForAddingImpCount; |
| 480 |
++triggerCount; |
| 481 |
triggerForAddingImpConcept = locatedConcept; |
| 482 |
if (implicationConcept) { |
| 483 |
addImplicationTrigger(implicationConcept,concept,!negated); |
| 484 |
} else { |
| 485 |
addSubClassConcept(locatedConcept,triggerConcept,false); |
| 486 |
} |
| 487 |
} else if (!negated && (opCode == CCAND || opCode == CCEQ) || negated && (opCode == CCOR)) { |
| 488 |
// and trigger |
| 489 |
if (triggerConcept) { |
| 490 |
return createImplicationAddedToTrigger(implicationConcept,triggerConcept,concept,negated); |
| 491 |
} |
| 492 |
|
| 493 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 494 |
while (opConLinkerIt) { |
| 495 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 496 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 497 |
|
| 498 |
cint64 tmpImpAddTriggerCount = 0; |
| 499 |
CConcept* tmpImpAddTriggerConcept = nullptr; |
| 500 |
|
| 501 |
triggerCount += createTrigger(implicationConcept,triggerConcept,opConcept,opNegated,&tmpImpAddTriggerCount,&tmpImpAddTriggerConcept); |
| 502 |
|
| 503 |
if (triggerForAddingImpConcept == nullptr || tmpImpAddTriggerCount > triggerForAddingImpCount) { |
| 504 |
triggerForAddingImpCount = tmpImpAddTriggerCount; |
| 505 |
triggerForAddingImpConcept = tmpImpAddTriggerConcept; |
| 506 |
} |
| 507 |
|
| 508 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 509 |
} |
| 510 |
} else { |
| 511 |
CConcept* conTriggerConcept = mConceptTriggerHash.value(QPair<CConcept*,bool>(concept,negated)); |
| 512 |
if (implicationConcept && conTriggerConcept) { |
| 513 |
addImplicationTrigger(implicationConcept,conTriggerConcept,true); |
| 514 |
triggerForAddingImpCount += mTriggerCountHash.value(conTriggerConcept,0); |
| 515 |
triggerCount += triggerForAddingImpCount; |
| 516 |
triggerForAddingImpConcept = conTriggerConcept; |
| 517 |
} else { |
| 518 |
if (implicationConcept) { |
| 519 |
triggerConcept = createImplicationTriggerConcept(nullptr,false); |
| 520 |
addImplicationTrigger(implicationConcept,triggerConcept,true); |
| 521 |
mConceptTriggerHash.insert(QPair<CConcept*,bool>(concept,negated),triggerConcept); |
| 522 |
implicationConcept = nullptr; |
| 523 |
} |
| 524 |
if (!negated && (opCode == CCNOMINAL)) { |
| 525 |
CIndividual* individual = concept->getNominalIndividual(); |
| 526 |
CIndividual* locatedIndividual = CConceptRoleIndividualLocator::getLocatedIndividual(individual,mOnto); |
| 527 |
triggerCount += 2; |
| 528 |
CConceptAssertionLinker* assLinker = CObjectAllocator< CConceptAssertionLinker >::allocateAndConstruct(mMemMan); |
| 529 |
assLinker->initNegLinker(triggerConcept,false); |
| 530 |
locatedIndividual->addAssertionConceptLinker(assLinker); |
| 531 |
} else if (!negated && (opCode == CCOR) || negated && (opCode == CCAND || opCode == CCEQ)) { |
| 532 |
// or trigger |
| 533 |
|
| 534 |
cint64 minTriggerCount = 0; |
| 535 |
|
| 536 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 537 |
while (opConLinkerIt) { |
| 538 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 539 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 540 |
|
| 541 |
cint64 tmpTriggerCount = 0; |
| 542 |
|
| 543 |
tmpTriggerCount = createTrigger(implicationConcept,triggerConcept,opConcept,opNegated,nullptr,nullptr); |
| 544 |
|
| 545 |
if (minTriggerCount == 0 || tmpTriggerCount > 0 && tmpTriggerCount < minTriggerCount) { |
| 546 |
minTriggerCount = tmpTriggerCount; |
| 547 |
} |
| 548 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 549 |
} |
| 550 |
|
| 551 |
triggerCount += minTriggerCount; |
| 552 |
|
| 553 |
} else if (!negated && (opCode == CCSOME || opCode == CCSELF) || negated && (opCode == CCALL)) { |
| 554 |
if (opConLinker) { |
| 555 |
CConcept* nextLevelTrigger = createTriggerPropagationConcept(triggerConcept,role); |
| 556 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 557 |
while (opConLinkerIt) { |
| 558 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 559 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 560 |
triggerCount += createTrigger(implicationConcept,nextLevelTrigger,opConcept,opNegated,nullptr,nullptr); |
| 561 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 562 |
} |
| 563 |
} else { |
| 564 |
CRole* locatedRole = CConceptRoleIndividualLocator::getLocatedRole(role,mOnto); |
| 565 |
addRoleDomainConcept(locatedRole,triggerConcept,false); |
| 566 |
} |
| 567 |
// add one for role |
| 568 |
triggerCount += 1; |
| 569 |
} else if (!negated && (opCode == CCVALUE)) { |
| 570 |
CConcept* nextLevelTrigger = createTriggerPropagationConcept(triggerConcept,role); |
| 571 |
|
| 572 |
CIndividual* individual = concept->getNominalIndividual(); |
| 573 |
CIndividual* locatedIndividual = CConceptRoleIndividualLocator::getLocatedIndividual(individual,mOnto); |
| 574 |
triggerCount += 2; |
| 575 |
CConceptAssertionLinker* assLinker = CObjectAllocator< CConceptAssertionLinker >::allocateAndConstruct(mMemMan); |
| 576 |
assLinker->initNegLinker(nextLevelTrigger,false); |
| 577 |
locatedIndividual->addAssertionConceptLinker(assLinker); |
| 578 |
|
| 579 |
// add one for role |
| 580 |
triggerCount += 1; |
| 581 |
} else if (!negated && (opCode == CCATLEAST && parm == 1) || negated && (opCode == CCATMOST && parm == 2)) { |
| 582 |
if (opConLinker) { |
| 583 |
CConcept* nextLevelTrigger = createTriggerPropagationConcept(triggerConcept,role); |
| 584 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 585 |
while (opConLinkerIt) { |
| 586 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 587 |
bool opNegated = opConLinkerIt->isNegated(); |
| 588 |
triggerCount += createTrigger(implicationConcept,nextLevelTrigger,opConcept,opNegated,nullptr,nullptr); |
| 589 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 590 |
} |
| 591 |
} else { |
| 592 |
CRole* locatedRole = CConceptRoleIndividualLocator::getLocatedRole(role,mOnto); |
| 593 |
addRoleDomainConcept(locatedRole,triggerConcept,false); |
| 594 |
} |
| 595 |
triggerCount += 1; |
| 596 |
} |
| 597 |
mTriggerCountHash.insert(triggerConcept,triggerCount); |
| 598 |
triggerForAddingImpConcept = triggerConcept; |
| 599 |
triggerForAddingImpCount = triggerCount; |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
if (impAddTriggerConcept && impAddTriggerCount) { |
| 604 |
if (*impAddTriggerCount < triggerForAddingImpCount) { |
| 605 |
*impAddTriggerCount = triggerForAddingImpCount; |
| 606 |
*impAddTriggerConcept = triggerForAddingImpConcept; |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
return triggerCount; |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
bool CTriggeredImplicationGCIAbsorberPreProcess::isDisjunctionConceptSimpleTriggeredImplicationAbsorbable(CConcept* orConcept, bool negated) { |
| 615 |
cint64 notAbsorbableCount = 0; |
| 616 |
cint64 absorbableCount = 0; |
| 617 |
CSortedNegLinker<CConcept*>* opConLinkerIt = orConcept->getOperandList(); |
| 618 |
while (opConLinkerIt) { |
| 619 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 620 |
bool opNegated = opConLinkerIt->isNegated(); |
| 621 |
if (isConceptSimpleImplicationTriggerable(opConcept,!opNegated^negated)) { |
| 622 |
absorbableCount++; |
| 623 |
} else { |
| 624 |
notAbsorbableCount++; |
| 625 |
} |
| 626 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 627 |
} |
| 628 |
if (notAbsorbableCount <= 1) { |
| 629 |
return true; |
| 630 |
} |
| 631 |
return false; |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
bool CTriggeredImplicationGCIAbsorberPreProcess::isDisjunctionConceptTriggeredImplicationAbsorbable(CConcept* orConcept, bool negated) { |
| 638 |
cint64 notAbsorbableCount = 0; |
| 639 |
cint64 absorbableCount = 0; |
| 640 |
CSortedNegLinker<CConcept*>* opConLinkerIt = orConcept->getOperandList(); |
| 641 |
while (opConLinkerIt) { |
| 642 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 643 |
bool opNegated = opConLinkerIt->isNegated(); |
| 644 |
if (isConceptImplicationTriggerable(opConcept,!opNegated^negated)) { |
| 645 |
absorbableCount++; |
| 646 |
} else { |
| 647 |
notAbsorbableCount++; |
| 648 |
} |
| 649 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 650 |
} |
| 651 |
if (notAbsorbableCount <= 1) { |
| 652 |
return true; |
| 653 |
} |
| 654 |
return false; |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
bool CTriggeredImplicationGCIAbsorberPreProcess::isEquivalenceConceptTriggeredImplicationAbsorbable(CConcept* orConcept, bool negated, cint64* notAbsorbableOperandsCount) { |
| 660 |
cint64 notAbsorbableCount = 0; |
| 661 |
cint64 opCode = orConcept->getOperatorCode(); |
| 662 |
if (!negated && opCode == CCEQ) { |
| 663 |
CSortedNegLinker<CConcept*>* opConLinkerIt = orConcept->getOperandList(); |
| 664 |
while (opConLinkerIt) { |
| 665 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 666 |
bool opNegated = opConLinkerIt->isNegated(); |
| 667 |
if (!isConceptImplicationTriggerable(opConcept,opNegated)) { |
| 668 |
return false; |
| 669 |
} |
| 670 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 671 |
} |
| 672 |
} |
| 673 |
return true; |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
bool CTriggeredImplicationGCIAbsorberPreProcess::isGCIConceptTriggeredImplicationAbsorbable(CConcept* orConcept, bool negated, cint64* notAbsorbableOperandsCount) { |
| 678 |
bool absorbable = false; |
| 679 |
cint64 notAbsorbableCount = 0; |
| 680 |
cint64 opCode = orConcept->getOperatorCode(); |
| 681 |
if (!negated && opCode == CCOR || negated && opCode == CCAND) { |
| 682 |
CSortedNegLinker<CConcept*>* opConLinkerIt = orConcept->getOperandList(); |
| 683 |
while (opConLinkerIt) { |
| 684 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 685 |
bool opNegated = opConLinkerIt->isNegated(); |
| 686 |
if (isConceptImplicationTriggerable(opConcept,!opNegated)) { |
| 687 |
absorbable = true; |
| 688 |
} else { |
| 689 |
notAbsorbableCount++; |
| 690 |
} |
| 691 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 692 |
} |
| 693 |
} |
| 694 |
if (notAbsorbableOperandsCount) { |
| 695 |
*notAbsorbableOperandsCount = notAbsorbableCount; |
| 696 |
} |
| 697 |
return absorbable; |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
bool CTriggeredImplicationGCIAbsorberPreProcess::isConceptSimpleImplicationTriggerable(CConcept* concept, bool negated) { |
| 702 |
cint64 opCode = concept->getOperatorCode(); |
| 703 |
cint64 parm = concept->getParameter(); |
| 704 |
cint64 opCount = concept->getOperandCount(); |
| 705 |
CSortedNegLinker<CConcept*>* opConLinker = concept->getOperandList(); |
| 706 |
if (!negated && (opCode == CCSUB || opCode == CCATOM)) { |
| 707 |
return true; |
| 708 |
} else if (!negated && (opCode == CCAND || opCode == CCEQ) || negated && opCode == CCOR) { |
| 709 |
if (opCount >= 1) { |
| 710 |
bool allOpsTriggerable = true; |
| 711 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 712 |
while (opConLinkerIt && allOpsTriggerable) { |
| 713 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 714 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 715 |
allOpsTriggerable &= isConceptSimpleImplicationTriggerable(opConcept,opNegated); |
| 716 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 717 |
} |
| 718 |
return allOpsTriggerable; |
| 719 |
} |
| 720 |
} else { |
| 721 |
CConcept* conTriggerConcept = mConceptTriggerHash.value(QPair<CConcept*,bool>(concept,negated)); |
| 722 |
if (conTriggerConcept) { |
| 723 |
return true; |
| 724 |
} |
| 725 |
} |
| 726 |
return false; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
bool CTriggeredImplicationGCIAbsorberPreProcess::isConceptImplicationTriggerable(CConcept* concept, bool negated) { |
| 731 |
cint64 opCode = concept->getOperatorCode(); |
| 732 |
cint64 parm = concept->getParameter(); |
| 733 |
cint64 opCount = concept->getOperandCount(); |
| 734 |
CSortedNegLinker<CConcept*>* opConLinker = concept->getOperandList(); |
| 735 |
if (!negated && (opCode == CCSUB || opCode == CCATOM)) { |
| 736 |
return true; |
| 737 |
} else if (!negated && (opCode == CCNOMINAL)) { |
| 738 |
return true; |
| 739 |
} else if (!negated && (opCode == CCVALUE)) { |
| 740 |
return true; |
| 741 |
} else if (!negated && (opCode == CCSOME || opCode == CCSELF) || negated && (opCode == CCALL)) { |
| 742 |
if (!opConLinker) { |
| 743 |
return true; |
| 744 |
} else { |
| 745 |
bool allOpsTriggerable = true; |
| 746 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 747 |
while (opConLinkerIt && allOpsTriggerable) { |
| 748 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 749 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 750 |
allOpsTriggerable &= isConceptImplicationTriggerable(opConcept,opNegated); |
| 751 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 752 |
} |
| 753 |
return allOpsTriggerable; |
| 754 |
} |
| 755 |
} else if (!negated && (opCode == CCATLEAST && parm == 1) || negated && (opCode == CCATMOST && parm == 0)) { |
| 756 |
if (!opConLinker) { |
| 757 |
return true; |
| 758 |
} else { |
| 759 |
bool allOpsTriggerable = true; |
| 760 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 761 |
while (opConLinkerIt && allOpsTriggerable) { |
| 762 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 763 |
bool opNegated = opConLinkerIt->isNegated(); |
| 764 |
allOpsTriggerable &= isConceptImplicationTriggerable(opConcept,opNegated); |
| 765 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 766 |
} |
| 767 |
return allOpsTriggerable; |
| 768 |
} |
| 769 |
} else if (opCode == CCAND || opCode == CCEQ || opCode == CCOR) { |
| 770 |
if (opCount >= 1) { |
| 771 |
bool allOpsTriggerable = true; |
| 772 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 773 |
while (opConLinkerIt && allOpsTriggerable) { |
| 774 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 775 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 776 |
allOpsTriggerable &= isConceptImplicationTriggerable(opConcept,opNegated); |
| 777 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 778 |
} |
| 779 |
return allOpsTriggerable; |
| 780 |
} |
| 781 |
} |
| 782 |
return false; |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
bool CTriggeredImplicationGCIAbsorberPreProcess::absorbGCIConceptsToTriggeredImplications(CConcept* orConcept, bool negated) { |
| 793 |
cint64 opCode = orConcept->getOperatorCode(); |
| 794 |
if (!negated && opCode == CCOR || negated && opCode == CCAND) { |
| 795 |
QList< QPair<CConcept*,bool> > candList; |
| 796 |
if (addAbsorbableDisjunctCandidates(orConcept,negated,candList)) { |
| 797 |
if (candList.count() >= 1) { |
| 798 |
QList< QPair<CConcept*,bool> > absorbList(splitAbsorbableDisjuncts(candList)); |
| 799 |
if (!absorbList.isEmpty()) { |
| 800 |
createGCIAbsorbedTriggeredImplication(orConcept,negated,absorbList,candList); |
| 801 |
return true; |
| 802 |
} |
| 803 |
} |
| 804 |
} |
| 805 |
} |
| 806 |
return false; |
| 807 |
} |
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
bool CTriggeredImplicationGCIAbsorberPreProcess::isConceptPartialImplicationTriggerable(CConcept* concept, bool negated) { |
| 815 |
cint64 opCode = concept->getOperatorCode(); |
| 816 |
cint64 parm = concept->getParameter(); |
| 817 |
cint64 opCount = concept->getOperandCount(); |
| 818 |
CSortedNegLinker<CConcept*>* opConLinker = concept->getOperandList(); |
| 819 |
if (!negated && (opCode == CCSUB || opCode == CCATOM)) { |
| 820 |
return true; |
| 821 |
} else if (!negated && (opCode == CCNOMINAL)) { |
| 822 |
return true; |
| 823 |
} else if (!negated && (opCode == CCVALUE)) { |
| 824 |
return true; |
| 825 |
} else if (!negated && (opCode == CCSOME || opCode == CCSELF) || negated && (opCode == CCALL)) { |
| 826 |
return true; |
| 827 |
} else if (!negated && (opCode == CCATLEAST && parm >= 1) || negated && (opCode == CCATMOST && parm >= 0)) { |
| 828 |
return true; |
| 829 |
} else if (!negated && (opCode == CCAND || opCode == CCEQ) || negated && opCode == CCOR) { |
| 830 |
// OR, at least one operand has to be triggerable |
| 831 |
if (opCount >= 1) { |
| 832 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 833 |
while (opConLinkerIt) { |
| 834 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 835 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 836 |
if (isConceptPartialImplicationTriggerable(opConcept,opNegated)) { |
| 837 |
return true; |
| 838 |
} |
| 839 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 840 |
} |
| 841 |
} |
| 842 |
} else if (negated && (opCode == CCAND || opCode == CCEQ) || !negated && opCode == CCOR) { |
| 843 |
// OR, all operands have to be triggerable |
| 844 |
if (opCount >= 1) { |
| 845 |
bool allOpsTriggerable = true; |
| 846 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 847 |
while (opConLinkerIt && allOpsTriggerable) { |
| 848 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 849 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 850 |
allOpsTriggerable &= isConceptPartialImplicationTriggerable(opConcept,opNegated); |
| 851 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 852 |
} |
| 853 |
return allOpsTriggerable; |
| 854 |
} |
| 855 |
} |
| 856 |
return false; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
bool CTriggeredImplicationGCIAbsorberPreProcess::absorbPartialGCIConceptsToTriggeredImplications(CConcept* orConcept, bool negated) { |
| 863 |
cint64 opCode = orConcept->getOperatorCode(); |
| 864 |
if (!negated && opCode == CCOR || negated && opCode == CCAND) { |
| 865 |
QList< QPair<CConcept*,bool> > candList; |
| 866 |
if (addAbsorbableDisjunctCandidates(orConcept,negated,candList)) { |
| 867 |
if (candList.count() >= 1) { |
| 868 |
QList< QPair<CConcept*,bool> > absorbList(getPartialAbsorbableDisjuncts(candList)); |
| 869 |
if (!absorbList.isEmpty()) { |
| 870 |
createGCIPartialAbsorbedTriggeredImplication(orConcept,negated,absorbList); |
| 871 |
return true; |
| 872 |
} |
| 873 |
} |
| 874 |
} |
| 875 |
} |
| 876 |
return false; |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
CConcept* CTriggeredImplicationGCIAbsorberPreProcess::createGCIPartialAbsorbedTriggeredImplication(CConcept* orConcept, bool negated, const QList< QPair<CConcept*,bool> >& absorbList) { |
| 882 |
CConcept* implicationConcept = createImplicationConcept(orConcept,negated); |
| 883 |
for (QList< QPair<CConcept*,bool> >::const_iterator it = absorbList.constBegin(), itEnd = absorbList.constEnd(); it != itEnd; ++it) { |
| 884 |
QPair<CConcept*,bool> conNegPair(*it); |
| 885 |
CConcept* concept = conNegPair.first; |
| 886 |
bool negated = conNegPair.second; |
| 887 |
createPartialImplicationAddedToTrigger(implicationConcept,nullptr,concept,!negated); |
| 888 |
} |
| 889 |
return implicationConcept; |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
CConcept* CTriggeredImplicationGCIAbsorberPreProcess::createPartialExtendedGCIAbsorbedTriggeredImplication(CConcept* implicationConcept, const QList< QPair<CConcept*,bool> >& absorbList) { |
| 895 |
cint64 maxImpAddTriggerCount = 0; |
| 896 |
CConcept* maxImpAddTriggerConcept = nullptr; |
| 897 |
for (QList< QPair<CConcept*,bool> >::const_iterator it = absorbList.constBegin(), itEnd = absorbList.constEnd(); it != itEnd; ++it) { |
| 898 |
QPair<CConcept*,bool> conNegPair(*it); |
| 899 |
CConcept* concept = conNegPair.first; |
| 900 |
bool negated = conNegPair.second; |
| 901 |
createPartialTrigger(implicationConcept,nullptr,concept,!negated,&maxImpAddTriggerCount,&maxImpAddTriggerConcept); |
| 902 |
} |
| 903 |
return implicationConcept; |
| 904 |
} |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
CConcept* CTriggeredImplicationGCIAbsorberPreProcess::createGCIAbsorbedTriggeredImplication(CConcept* orConcept, bool negated, QList< QPair<CConcept*,bool> >& absorbList, QList< QPair<CConcept*,bool> >& candList) { |
| 909 |
CConcept* impliedConcept = nullptr; |
| 910 |
bool impliedNegation = false; |
| 911 |
QList< QPair<CConcept*,bool> > partialAbsorbableList; |
| 912 |
|
| 913 |
if (candList.isEmpty()) { |
| 914 |
//candList.append(mBottomConcept); |
| 915 |
candList.append(absorbList.takeFirst()); |
| 916 |
} |
| 917 |
if (candList.count() > 1) { |
| 918 |
impliedConcept = createImpliedConcept(); |
| 919 |
for (QList< QPair<CConcept*,bool> >::const_iterator it = candList.constBegin(), itEnd = candList.constEnd(); it != itEnd; ++it) { |
| 920 |
QPair<CConcept*,bool> conNegPair(*it); |
| 921 |
CConcept* concept = conNegPair.first; |
| 922 |
bool negated = conNegPair.second; |
| 923 |
addConceptToImplied(impliedConcept,concept,negated); |
| 924 |
} |
| 925 |
impliedConcept->setOperatorCode(CCOR); |
| 926 |
if (mConfPartialGCIAbsorption) { |
| 927 |
partialAbsorbableList = getPartialAbsorbableDisjuncts(candList); |
| 928 |
} |
| 929 |
} else { |
| 930 |
QPair<CConcept*,bool> conNegPair(candList.takeFirst()); |
| 931 |
CConcept* concept = conNegPair.first; |
| 932 |
bool negated = conNegPair.second; |
| 933 |
impliedNegation = negated; |
| 934 |
impliedConcept = concept; |
| 935 |
} |
| 936 |
|
| 937 |
CConcept* implicationConcept = createImplicationConcept(impliedConcept,impliedNegation); |
| 938 |
|
| 939 |
if (!partialAbsorbableList.isEmpty()) { |
| 940 |
createPartialExtendedGCIAbsorbedTriggeredImplication(implicationConcept,partialAbsorbableList); |
| 941 |
++mStatGCIAbsorptionPartialExtended; |
| 942 |
} |
| 943 |
|
| 944 |
for (QList< QPair<CConcept*,bool> >::const_iterator it = absorbList.constBegin(), itEnd = absorbList.constEnd(); it != itEnd; ++it) { |
| 945 |
QPair<CConcept*,bool> conNegPair(*it); |
| 946 |
CConcept* concept = conNegPair.first; |
| 947 |
bool negated = conNegPair.second; |
| 948 |
createImplicationAddedToTrigger(implicationConcept,nullptr,concept,!negated); |
| 949 |
} |
| 950 |
return implicationConcept; |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
cint64 CTriggeredImplicationGCIAbsorberPreProcess::createPartialImplicationAddedToTrigger(CConcept* implicationConcept, CConcept* triggerConcept, CConcept* concept, bool negated) { |
| 957 |
cint64 triggerCount = 0; |
| 958 |
cint64 maxImpAddTriggerCount = 0; |
| 959 |
CConcept* maxImpAddTriggerConcept = nullptr; |
| 960 |
if (!implicationConcept) { |
| 961 |
implicationConcept = createImplicationConcept(triggerConcept,false); |
| 962 |
triggerConcept = nullptr; |
| 963 |
} |
| 964 |
|
| 965 |
triggerCount = createPartialTrigger(implicationConcept,triggerConcept,concept,negated,&maxImpAddTriggerCount,&maxImpAddTriggerConcept); |
| 966 |
|
| 967 |
if (maxImpAddTriggerConcept) { |
| 968 |
cint64 opCode = maxImpAddTriggerConcept->getOperatorCode(); |
| 969 |
if (opCode != CCNONE) { |
| 970 |
addConceptToImplied(maxImpAddTriggerConcept,implicationConcept,false); |
| 971 |
} else { |
| 972 |
addSubClassConcept(maxImpAddTriggerConcept,implicationConcept,false); |
| 973 |
} |
| 974 |
} |
| 975 |
|
| 976 |
return triggerCount; |
| 977 |
} |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
cint64 CTriggeredImplicationGCIAbsorberPreProcess::createPartialTrigger(CConcept* implicationConcept, CConcept* triggerConcept, CConcept* concept, bool negated, cint64* impAddTriggerCount, CConcept** impAddTriggerConcept) { |
| 983 |
cint64 triggerCount = 0; |
| 984 |
cint64 triggerForAddingImpCount = 0; |
| 985 |
CConcept* triggerForAddingImpConcept = nullptr; |
| 986 |
cint64 opCode = concept->getOperatorCode(); |
| 987 |
cint64 parm = concept->getParameter(); |
| 988 |
cint64 opCount = concept->getOperandCount(); |
| 989 |
CRole* role = concept->getRole(); |
| 990 |
CSortedNegLinker<CConcept*>* opConLinker = concept->getOperandList(); |
| 991 |
if (!negated && (opCode == CCIMPLALL || opCode == CCIMPL || opCode == CCIMPLTRIG)) { |
| 992 |
// nothing to do |
| 993 |
} else if (!negated && (opCode == CCATOM || opCode == CCSUB)) { |
| 994 |
CConcept* locatedConcept = CConceptRoleIndividualLocator::getLocatedConcept(concept,mOnto); |
| 995 |
|
| 996 |
//if (concept->hasClassName()) { |
| 997 |
// QString iriClassNameString = CIRIName::getRecentIRIName(concept->getClassNameLinker()); |
| 998 |
// if (iriClassNameString == QString("http://www.owllink.org/testsuite/galen#nonNormal")) { |
| 999 |
// bool bug = true; |
| 1000 |
// } |
| 1001 |
//} |
| 1002 |
|
| 1003 |
++triggerForAddingImpCount; |
| 1004 |
++triggerCount; |
| 1005 |
triggerForAddingImpConcept = locatedConcept; |
| 1006 |
if (implicationConcept) { |
| 1007 |
addImplicationTrigger(implicationConcept,concept,!negated); |
| 1008 |
} else { |
| 1009 |
addSubClassConcept(locatedConcept,triggerConcept,false); |
| 1010 |
} |
| 1011 |
} else if (!negated && (opCode == CCAND || opCode == CCEQ) || negated && (opCode == CCOR)) { |
| 1012 |
// and trigger |
| 1013 |
if (triggerConcept) { |
| 1014 |
return createPartialImplicationAddedToTrigger(implicationConcept,triggerConcept,concept,negated); |
| 1015 |
} |
| 1016 |
|
| 1017 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 1018 |
while (opConLinkerIt) { |
| 1019 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 1020 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 1021 |
|
| 1022 |
if (isConceptPartialImplicationTriggerable(opConcept,opNegated)) { |
| 1023 |
|
| 1024 |
cint64 tmpImpAddTriggerCount = 0; |
| 1025 |
CConcept* tmpImpAddTriggerConcept = nullptr; |
| 1026 |
|
| 1027 |
triggerCount += createPartialTrigger(implicationConcept,triggerConcept,opConcept,opNegated,&tmpImpAddTriggerCount,&tmpImpAddTriggerConcept); |
| 1028 |
|
| 1029 |
if (triggerForAddingImpConcept == nullptr || tmpImpAddTriggerCount > triggerForAddingImpCount) { |
| 1030 |
triggerForAddingImpCount = tmpImpAddTriggerCount; |
| 1031 |
triggerForAddingImpConcept = tmpImpAddTriggerConcept; |
| 1032 |
} |
| 1033 |
} |
| 1034 |
|
| 1035 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 1036 |
} |
| 1037 |
} else { |
| 1038 |
CConcept* conTriggerConcept = mConceptTriggerHash.value(QPair<CConcept*,bool>(concept,negated)); |
| 1039 |
if (implicationConcept && conTriggerConcept) { |
| 1040 |
addImplicationTrigger(implicationConcept,conTriggerConcept,true); |
| 1041 |
triggerForAddingImpCount += mTriggerCountHash.value(conTriggerConcept,0); |
| 1042 |
triggerCount += triggerForAddingImpCount; |
| 1043 |
triggerForAddingImpConcept = conTriggerConcept; |
| 1044 |
} else { |
| 1045 |
if (implicationConcept) { |
| 1046 |
triggerConcept = createImplicationTriggerConcept(nullptr,false); |
| 1047 |
addImplicationTrigger(implicationConcept,triggerConcept,true); |
| 1048 |
mConceptTriggerHash.insert(QPair<CConcept*,bool>(concept,negated),triggerConcept); |
| 1049 |
implicationConcept = nullptr; |
| 1050 |
} |
| 1051 |
if (!negated && (opCode == CCNOMINAL)) { |
| 1052 |
CIndividual* individual = concept->getNominalIndividual(); |
| 1053 |
CIndividual* locatedIndividual = CConceptRoleIndividualLocator::getLocatedIndividual(individual,mOnto); |
| 1054 |
triggerCount += 2; |
| 1055 |
CConceptAssertionLinker* assLinker = CObjectAllocator< CConceptAssertionLinker >::allocateAndConstruct(mMemMan); |
| 1056 |
assLinker->initNegLinker(triggerConcept,false); |
| 1057 |
locatedIndividual->addAssertionConceptLinker(assLinker); |
| 1058 |
} else if (!negated && (opCode == CCOR) || negated && (opCode == CCAND || opCode == CCEQ)) { |
| 1059 |
// or trigger |
| 1060 |
|
| 1061 |
cint64 minTriggerCount = 0; |
| 1062 |
|
| 1063 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 1064 |
while (opConLinkerIt) { |
| 1065 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 1066 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 1067 |
|
| 1068 |
cint64 tmpTriggerCount = 0; |
| 1069 |
|
| 1070 |
tmpTriggerCount = createPartialTrigger(implicationConcept,triggerConcept,opConcept,opNegated,nullptr,nullptr); |
| 1071 |
|
| 1072 |
if (minTriggerCount == 0 || tmpTriggerCount > 0 && tmpTriggerCount < minTriggerCount) { |
| 1073 |
minTriggerCount = tmpTriggerCount; |
| 1074 |
} |
| 1075 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 1076 |
} |
| 1077 |
|
| 1078 |
triggerCount += minTriggerCount; |
| 1079 |
|
| 1080 |
} else if (!negated && (opCode == CCSOME || opCode == CCSELF) || negated && (opCode == CCALL)) { |
| 1081 |
bool absorbOperands = true; |
| 1082 |
if (opConLinker) { |
| 1083 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 1084 |
while (opConLinkerIt) { |
| 1085 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 1086 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 1087 |
if (!isConceptPartialImplicationTriggerable(opConcept,opNegated)) { |
| 1088 |
absorbOperands = false; |
| 1089 |
} |
| 1090 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 1091 |
} |
| 1092 |
} else { |
| 1093 |
absorbOperands = false; |
| 1094 |
} |
| 1095 |
if (absorbOperands) { |
| 1096 |
CConcept* nextLevelTrigger = createTriggerPropagationConcept(triggerConcept,role); |
| 1097 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 1098 |
while (opConLinkerIt) { |
| 1099 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 1100 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 1101 |
triggerCount += createPartialTrigger(implicationConcept,nextLevelTrigger,opConcept,opNegated,nullptr,nullptr); |
| 1102 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 1103 |
} |
| 1104 |
} else { |
| 1105 |
CRole* locatedRole = CConceptRoleIndividualLocator::getLocatedRole(role,mOnto); |
| 1106 |
addRoleDomainConcept(locatedRole,triggerConcept,false); |
| 1107 |
} |
| 1108 |
// add one for role |
| 1109 |
triggerCount += 1; |
| 1110 |
} else if (!negated && (opCode == CCVALUE)) { |
| 1111 |
CConcept* nextLevelTrigger = createTriggerPropagationConcept(triggerConcept,role); |
| 1112 |
|
| 1113 |
CIndividual* individual = concept->getNominalIndividual(); |
| 1114 |
CIndividual* locatedIndividual = CConceptRoleIndividualLocator::getLocatedIndividual(individual,mOnto); |
| 1115 |
triggerCount += 2; |
| 1116 |
CConceptAssertionLinker* assLinker = CObjectAllocator< CConceptAssertionLinker >::allocateAndConstruct(mMemMan); |
| 1117 |
assLinker->initNegLinker(nextLevelTrigger,false); |
| 1118 |
locatedIndividual->addAssertionConceptLinker(assLinker); |
| 1119 |
|
| 1120 |
// add one for role |
| 1121 |
triggerCount += 1; |
| 1122 |
} else if (!negated && (opCode == CCATLEAST && parm >= 1) || negated && (opCode == CCATMOST && parm >= 2)) { |
| 1123 |
bool absorbOperands = true; |
| 1124 |
if (opConLinker) { |
| 1125 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 1126 |
while (opConLinkerIt) { |
| 1127 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 1128 |
bool opNegated = opConLinkerIt->isNegated(); |
| 1129 |
if (!isConceptPartialImplicationTriggerable(opConcept,opNegated)) { |
| 1130 |
absorbOperands = false; |
| 1131 |
} |
| 1132 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 1133 |
} |
| 1134 |
} else { |
| 1135 |
absorbOperands = false; |
| 1136 |
} |
| 1137 |
if (absorbOperands) { |
| 1138 |
CConcept* nextLevelTrigger = createTriggerPropagationConcept(triggerConcept,role); |
| 1139 |
CSortedNegLinker<CConcept*>* opConLinkerIt = opConLinker; |
| 1140 |
while (opConLinkerIt) { |
| 1141 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 1142 |
bool opNegated = opConLinkerIt->isNegated(); |
| 1143 |
triggerCount += createPartialTrigger(implicationConcept,nextLevelTrigger,opConcept,opNegated,nullptr,nullptr); |
| 1144 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 1145 |
} |
| 1146 |
} else { |
| 1147 |
CRole* locatedRole = CConceptRoleIndividualLocator::getLocatedRole(role,mOnto); |
| 1148 |
addRoleDomainConcept(locatedRole,triggerConcept,false); |
| 1149 |
} |
| 1150 |
triggerCount += 1; |
| 1151 |
} |
| 1152 |
mTriggerCountHash.insert(triggerConcept,triggerCount); |
| 1153 |
triggerForAddingImpConcept = triggerConcept; |
| 1154 |
triggerForAddingImpCount = triggerCount; |
| 1155 |
} |
| 1156 |
} |
| 1157 |
|
| 1158 |
if (impAddTriggerConcept && impAddTriggerCount) { |
| 1159 |
if (*impAddTriggerCount < triggerForAddingImpCount) { |
| 1160 |
*impAddTriggerCount = triggerForAddingImpCount; |
| 1161 |
*impAddTriggerConcept = triggerForAddingImpConcept; |
| 1162 |
} |
| 1163 |
} |
| 1164 |
|
| 1165 |
return triggerCount; |
| 1166 |
} |
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
bool CTriggeredImplicationGCIAbsorberPreProcess::addAbsorbableDisjunctCandidates(CConcept* orConcept, bool negated, QList< QPair<CConcept*,bool> >& list) { |
| 1171 |
bool absorbableDisjuncts = false; |
| 1172 |
cint64 opCode = orConcept->getOperatorCode(); |
| 1173 |
if (!negated && opCode == CCOR || negated && opCode == CCAND) { |
| 1174 |
CSortedNegLinker<CConcept*>* opConLinkerIt = orConcept->getOperandList(); |
| 1175 |
while (opConLinkerIt) { |
| 1176 |
CConcept* opConcept = opConLinkerIt->getData(); |
| 1177 |
bool opNegated = opConLinkerIt->isNegated()^negated; |
| 1178 |
|
| 1179 |
cint64 opOpCode = opConcept->getOperatorCode(); |
| 1180 |
if (!opNegated && opOpCode == CCOR || opNegated && opOpCode == CCAND) { |
| 1181 |
absorbableDisjuncts |= addAbsorbableDisjunctCandidates(opConcept,opNegated,list); |
| 1182 |
} else { |
| 1183 |
list.append(QPair<CConcept*,bool>(opConcept,opNegated)); |
| 1184 |
absorbableDisjuncts = true; |
| 1185 |
} |
| 1186 |
|
| 1187 |
opConLinkerIt = opConLinkerIt->getNext(); |
| 1188 |
} |
| 1189 |
} |
| 1190 |
return absorbableDisjuncts; |
| 1191 |
} |
| 1192 |
|
| 1193 |
QList< QPair<CConcept*,bool> > CTriggeredImplicationGCIAbsorberPreProcess::splitAbsorbableDisjuncts(QList< QPair<CConcept*,bool> >& list) { |
| 1194 |
QList< QPair<CConcept*,bool> > absorbableList; |
| 1195 |
cint64 count = list.count(); |
| 1196 |
for (cint64 nr = 0; nr < count; ++nr) { |
| 1197 |
QPair<CConcept*,bool> conNegPair(list.takeFirst()); |
| 1198 |
CConcept* concept = conNegPair.first; |
| 1199 |
bool negated = conNegPair.second; |
| 1200 |
if (isConceptImplicationTriggerable(concept,!negated)) { |
| 1201 |
absorbableList.append(conNegPair); |
| 1202 |
} else { |
| 1203 |
list.append(conNegPair); |
| 1204 |
} |
| 1205 |
} |
| 1206 |
return absorbableList; |
| 1207 |
} |
| 1208 |
|
| 1209 |
QList< QPair<CConcept*,bool> > CTriggeredImplicationGCIAbsorberPreProcess::getPartialAbsorbableDisjuncts(QList< QPair<CConcept*,bool> >& list) { |
| 1210 |
QList< QPair<CConcept*,bool> > absorbableList; |
| 1211 |
cint64 count = list.count(); |
| 1212 |
for (QList< QPair<CConcept*,bool> >::const_iterator it = list.constBegin(), itEnd = list.constEnd(); it != itEnd; ++it) { |
| 1213 |
QPair<CConcept*,bool> conNegPair(*it); |
| 1214 |
CConcept* concept = conNegPair.first; |
| 1215 |
bool negated = conNegPair.second; |
| 1216 |
if (isConceptPartialImplicationTriggerable(concept,!negated)) { |
| 1217 |
absorbableList.append(conNegPair); |
| 1218 |
} |
| 1219 |
} |
| 1220 |
return absorbableList; |
| 1221 |
} |
| 1222 |
|
| 1223 |
}; // end namespace Preprocess |
| 1224 |
|
| 1225 |
}; // end namespace Reasoner |
| 1226 |
|
| 1227 |
}; // end namespace Konclude |