| 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 |
#ifndef KONCLUDE_REASONER_PREPROCESS_CROLECHAINAUTOMATATRANSFORMATIONPREPROCESS_H |
| 22 |
#define KONCLUDE_REASONER_PREPROCESS_CROLECHAINAUTOMATATRANSFORMATIONPREPROCESS_H |
| 23 |
|
| 24 |
// Libraries includes |
| 25 |
#include <QSet> |
| 26 |
|
| 27 |
// Namespace includes |
| 28 |
#include "CConcreteOntologyContinuablePreProcess.h" |
| 29 |
#include "CConceptRoleIndividualLocator.h" |
| 30 |
|
| 31 |
|
| 32 |
// Other includes |
| 33 |
#include "Reasoner/Ontology/CBoxContext.h" |
| 34 |
#include "Reasoner/Ontology/CConcept.h" |
| 35 |
#include "Reasoner/Ontology/CRoleDependence.h" |
| 36 |
#include "Reasoner/Ontology/CMBox.h" |
| 37 |
|
| 38 |
#include "Utilities/CDynamicExpandingMemoryManager.hpp" |
| 39 |
#include "Utilities/CSortedNegLinker.hpp" |
| 40 |
|
| 41 |
#include "Parser/Expressions/CInverseObjectPropertyOfExpression.h" |
| 42 |
|
| 43 |
// Logger includes |
| 44 |
#include "Logger/CLogger.h" |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
namespace Konclude { |
| 49 |
|
| 50 |
using namespace Parser::Expression; |
| 51 |
|
| 52 |
namespace Reasoner { |
| 53 |
|
| 54 |
using namespace Ontology; |
| 55 |
|
| 56 |
namespace Preprocess { |
| 57 |
|
| 58 |
|
| 59 |
typedef QPair<CRole*,bool> TRoleNegationPair; |
| 60 |
|
| 61 |
|
| 62 |
class CRoleSubRoleChainData { |
| 63 |
public: |
| 64 |
CRole* mRole; |
| 65 |
CRoleChain* mRoleChain; |
| 66 |
bool mInverse; |
| 67 |
|
| 68 |
CRoleSubRoleChainData(CRole* role = nullptr, CRoleChain* roleChain = nullptr, bool inverse = false) { |
| 69 |
mRole = role; |
| 70 |
mRoleChain = roleChain; |
| 71 |
mInverse = inverse; |
| 72 |
} |
| 73 |
}; |
| 74 |
|
| 75 |
class CRoleSubRoleChainDataItem { |
| 76 |
public: |
| 77 |
CRoleSubRoleChainDataItem(CRoleSubRoleChainData& roleChain) { |
| 78 |
mChainData = roleChain; |
| 79 |
mNegated = false; |
| 80 |
mAllowPropagated = true; |
| 81 |
} |
| 82 |
CRoleSubRoleChainDataItem(CRoleSubRoleChainData& roleChain, bool negated) { |
| 83 |
mChainData = roleChain; |
| 84 |
mNegated = negated; |
| 85 |
mAllowPropagated = false; |
| 86 |
} |
| 87 |
public: |
| 88 |
CRoleSubRoleChainData mChainData; |
| 89 |
bool mNegated; |
| 90 |
bool mAllowPropagated; |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
class CRecTravSubRoleChainDataItem { |
| 95 |
public: |
| 96 |
CRecTravSubRoleChainDataItem() { |
| 97 |
mRole = nullptr; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
public: |
| 102 |
CRole* mRole; |
| 103 |
QList<CRoleSubRoleChainData> mDirectSubRoleChainDataList; |
| 104 |
QList<TRoleNegationPair> mRecTraversalSubRoleList; |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
/*! |
| 109 |
* |
| 110 |
* \class CRoleChainAutomataTransformationPreProcess |
| 111 |
* \author Andreas Steigmiller |
| 112 |
* \version 0.1 |
| 113 |
* \brief TODO |
| 114 |
* |
| 115 |
*/ |
| 116 |
class CRoleChainAutomataTransformationPreProcess : public CConcreteOntologyContinuablePreProcess { |
| 117 |
// public methods |
| 118 |
public: |
| 119 |
//! Constructor |
| 120 |
CRoleChainAutomataTransformationPreProcess(); |
| 121 |
|
| 122 |
//! Destructor |
| 123 |
virtual ~CRoleChainAutomataTransformationPreProcess(); |
| 124 |
|
| 125 |
|
| 126 |
virtual CConcreteOntology *preprocess(CConcreteOntology *ontology, CPreProcessContext* context); |
| 127 |
virtual CConcreteOntology* continuePreprocessing(); |
| 128 |
|
| 129 |
virtual CConcreteOntology *preprocess(CConcreteOntology *ontology, QSet<CConcept*>* trasformConceptSet, CPreProcessContext* context); |
| 130 |
|
| 131 |
|
| 132 |
// protected methods |
| 133 |
protected: |
| 134 |
|
| 135 |
// private methods |
| 136 |
private: |
| 137 |
enum TRANSLATIONTYPE { TTNORMAL, TTIMPL, TTBRANCH, TTPROPBIND, TTBACKPROP, TTVARBIND }; |
| 138 |
|
| 139 |
CRole* getLocalizedRole(CRole* role); |
| 140 |
CRole* getLocalizedRole(cint64 roleTag); |
| 141 |
bool hasInverseRole(CRole* role, bool searchInverseEquivalent = true); |
| 142 |
CRole* getInverseRole(CRole* role, bool searchInverseEquivalent = true); |
| 143 |
bool hasSuperRole(CRole* role, CRole* testingSuperRole, bool testInversed, bool superRoleInversedRequired); |
| 144 |
bool hasSuperRole(CRole* role, CRole* testingSuperRole, bool superRoleInversedRequired); |
| 145 |
bool hasInversedSuperRole(CRole* role, CRole* testingSuperRole); |
| 146 |
bool hasNonInversedSuperRole(CRole* role, CRole* testingSuperRole); |
| 147 |
bool hasInversedOrNonInversedSuperRole(CRole* role, CRole* testingSuperRole); |
| 148 |
|
| 149 |
CRoleChainAutomataTransformationPreProcess* convertAutomatConcept(CConcept* concept); |
| 150 |
|
| 151 |
CConcept* createAutomatGeneratingConcept(CSortedNegLinker<CConcept*>* opLinker, bool negate, CRole* role); |
| 152 |
|
| 153 |
CRoleChainAutomataTransformationPreProcess* collectSubRoleChains(); |
| 154 |
CRoleChainAutomataTransformationPreProcess* createMissingInverseChainedRoles(); |
| 155 |
CRoleChainAutomataTransformationPreProcess* createInverseRoleChainLinkers(); |
| 156 |
CRoleChainAutomataTransformationPreProcess* createRecursiveTraversalData(); |
| 157 |
CRoleChainAutomataTransformationPreProcess* transformFORALLPropagations(); |
| 158 |
|
| 159 |
|
| 160 |
QList<CRoleSubRoleChainData> getRelevantChainDataList(CRole* role, const QList<CRoleSubRoleChainData>& roleSubChainDataList); |
| 161 |
CRoleChainAutomataTransformationPreProcess* addRecursiveTraversalData(CRole* role, const QList<CRoleSubRoleChainData>& roleSubChainDataList); |
| 162 |
|
| 163 |
|
| 164 |
bool isChainDataImplicit(const CRoleSubRoleChainData& testingImplicitChainData, const CRoleSubRoleChainData& chainData); |
| 165 |
bool isChainLinkerImplicit(CXLinker<CRole*>* testingImplicitChainLinker, CXLinker<CRole*>* chainLinker, bool inversedTesting); |
| 166 |
bool isTransitiveChainData(const CRoleSubRoleChainData& chainData); |
| 167 |
|
| 168 |
bool isChainDataRecursiveTraversalCritical(CRole* role, const CRoleSubRoleChainData& chainData); |
| 169 |
bool collectRecursiveTraversalCriticalRoles(CRole* role, const CRoleSubRoleChainData& chainData, QHash<CRole*,bool>* criticalRoleNegationHash); |
| 170 |
QHash<CRole*,bool> getRelevantRecursiveTraversalCriticalRoles(QHash<CRole*,bool>* criticalRoleNegationHash); |
| 171 |
|
| 172 |
bool requiresRecursiveTraversalForRole(CRole* role, const CRoleSubRoleChainData& chainData, QHash<CRole*,bool>* criticalRoleNegationHash); |
| 173 |
|
| 174 |
|
| 175 |
bool generateRoleChainAutomatConcept(CRole* lastRole, const CRecTravSubRoleChainDataItem& recTravSubRoleChainDataItem, QSet<CRole*>& alreadyUnfoldRoleSet, CConcept* beginConcept, CConcept* endConcept, TRANSLATIONTYPE transType); |
| 176 |
bool generateRoleChainAutomatConcept(CRole* lastRole, const QList<CRoleSubRoleChainData>& subRoleChainDataList, QSet<CRole*>& alreadyUnfoldRoleSet, CConcept* beginConcept, CConcept* endConcept, TRANSLATIONTYPE transType); |
| 177 |
bool generateRoleChainAutomatConcept(CRole* lastRole, CRole* superRole, CRoleChain* descendingRoleChain, bool negatedChain, QSet<CRole*>& alreadyUnfoldRoleSet, CConcept* beginConcept, CConcept* endConcept, TRANSLATIONTYPE transType); |
| 178 |
CConcept* createTransitionConcept(CRole* role, TRANSLATIONTYPE transType); |
| 179 |
CSortedNegLinker<CConcept*>* createTransitionOperandConceptLinker(CConcept* operandConcept, bool negation); |
| 180 |
CConcept* appendTransitionOperandConceptLinker(CConcept* concept, CSortedNegLinker<CConcept*>* opLinker); |
| 181 |
CConcept* createStateConcept(TRANSLATIONTYPE transType); |
| 182 |
|
| 183 |
bool hasPropagationConcept(bool negated, CConcept* concept, CRole* role, CSortedNegLinker<CRole*>* roleList, bool inverseDomRange); |
| 184 |
bool hasPropagatedConcept(bool negated, CConcept* concept, CSortedNegLinker<CRole*>* roleList, bool inverseDomRange); |
| 185 |
CRoleChainAutomataTransformationPreProcess* createDomainRangePropagations(); |
| 186 |
CRoleChainAutomataTransformationPreProcess* transformVALUERestrictions(); |
| 187 |
|
| 188 |
CConcept* createNominalConcept(CIndividual* individual); |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
// private variables |
| 194 |
private: |
| 195 |
CRoleVector *mRoleVec; |
| 196 |
CConceptVector *mConVec; |
| 197 |
cint64 mNextConceptTag; |
| 198 |
|
| 199 |
CMemoryAllocationManager* mMemMan; |
| 200 |
|
| 201 |
typedef QPair<CConcept*,bool> TConceptNegPair; |
| 202 |
|
| 203 |
|
| 204 |
QHash<CRole*,CRecTravSubRoleChainDataItem> mRoleRecTravSubRoleChainDataHash; |
| 205 |
|
| 206 |
|
| 207 |
QHash<CRole*,CRoleSubRoleChainData> mRoleSubRoleChainDataHash; |
| 208 |
QSet<CRoleChain*> mInverseUpdateRoleChainSet; |
| 209 |
|
| 210 |
QHash<TConceptNegPair,CConcept*> mDomConPropConceptHash; |
| 211 |
QHash<TConceptNegPair,CConcept*> mRanConPropConceptHash; |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
CBUILDHASH<CRole*,CObjectPropertyTermExpression*>* mRoleObjPropTermHash; |
| 216 |
CBUILDHASH<CObjectPropertyTermExpression*,CRole*>* mObjPropTermRoleHash; |
| 217 |
CBUILDLIST<CBuildExpression*>* mExpressionBuildContainerList; |
| 218 |
CBUILDHASH<CObjectPropertyTermExpression*,CObjectPropertyTermExpression*>* mInverseObjectPropertyHash; |
| 219 |
CBUILDHASH<CExpressionHasher,CBuildExpression*>* mExpressionBuildHash; |
| 220 |
|
| 221 |
|
| 222 |
cint64 mStatAutomateStateConceptCount; |
| 223 |
cint64 mStatAutomateTransitionConceptCount; |
| 224 |
cint64 mStatAutomateTransformedConceptCount; |
| 225 |
cint64 mStatAutomateTransitiveSavedCount; |
| 226 |
|
| 227 |
cint64 mStatRangePropagationCount; |
| 228 |
cint64 mStatDomainPropagationCount; |
| 229 |
cint64 mStatCreatedRangePropagationCount; |
| 230 |
cint64 mStatCreatedDomainPropagationCount; |
| 231 |
|
| 232 |
cint64 mStatPropagationAlreadyInDomainRangeCount; |
| 233 |
cint64 mStatPropagatedAlreadyInDomainRangeCount; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
bool mConfSaveTransitiveTransitions; |
| 238 |
|
| 239 |
|
| 240 |
cint64 mLastConceptForallId; |
| 241 |
cint64 mLastConceptValueId; |
| 242 |
|
| 243 |
|
| 244 |
}; |
| 245 |
|
| 246 |
}; // end namespace Preprocess |
| 247 |
|
| 248 |
}; // end namespace Reasoner |
| 249 |
|
| 250 |
}; // end namespace Konclude |
| 251 |
|
| 252 |
#endif // KONCLUDE_REASONER_PREPROCESS_CROLECHAINAUTOMATATRANSFORMATIONPREPROCESS_H |