1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
/*
* Copyright (C) 2013, 2014, 2015 by the Konclude Developer Team.
*
* This file is part of the reasoning system Konclude.
* For details and support, see <http://konclude.com/>.
*
* Konclude is free software: you can redistribute it and/or modify it under
* the terms of version 2.1 of the GNU Lesser General Public License (LGPL2.1)
* as published by the Free Software Foundation.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Konclude. If not, see <http://www.gnu.org/licenses/>.
*
* Konclude is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more
* details, see GNU Lesser General Public License.
*
*/
#ifndef KONCLUDE_REASONER_PREPROCESS_CROLECHAINAUTOMATATRANSFORMATIONPREPROCESS_H
#define KONCLUDE_REASONER_PREPROCESS_CROLECHAINAUTOMATATRANSFORMATIONPREPROCESS_H
// Libraries includes
#include <QSet>
// Namespace includes
#include "CConcreteOntologyPreProcess.h"
#include "CConceptRoleIndividualLocator.h"
// Other includes
#include "Reasoner/Ontology/CBoxContext.h"
#include "Reasoner/Ontology/CConcept.h"
#include "Reasoner/Ontology/CRoleDependence.h"
#include "Reasoner/Ontology/CMBox.h"
#include "Utilities/CDynamicExpandingMemoryManager.hpp"
#include "Utilities/CSortedNegLinker.hpp"
#include "Parser/Expressions/CInverseObjectPropertyOfExpression.h"
// Logger includes
#include "Logger/CLogger.h"
namespace Konclude {
using namespace Parser::Expression;
namespace Reasoner {
using namespace Ontology;
namespace Preprocess {
typedef QPair<CRole*,bool> TRoleNegationPair;
class CRoleSubRoleChainData {
public:
CRole* mRole;
CRoleChain* mRoleChain;
bool mInverse;
CRoleSubRoleChainData(CRole* role = nullptr, CRoleChain* roleChain = nullptr, bool inverse = nullptr) {
mRole = role;
mRoleChain = roleChain;
mInverse = inverse;
}
};
class CRoleSubRoleChainDataItem {
public:
CRoleSubRoleChainDataItem(CRoleSubRoleChainData& roleChain) {
mChainData = roleChain;
mNegated = false;
mAllowPropagated = true;
}
CRoleSubRoleChainDataItem(CRoleSubRoleChainData& roleChain, bool negated) {
mChainData = roleChain;
mNegated = negated;
mAllowPropagated = false;
}
public:
CRoleSubRoleChainData mChainData;
bool mNegated;
bool mAllowPropagated;
};
class CRecTravSubRoleChainDataItem {
public:
CRecTravSubRoleChainDataItem() {
mRole = nullptr;
}
public:
CRole* mRole;
QList<CRoleSubRoleChainData> mDirectSubRoleChainDataList;
QList<TRoleNegationPair> mRecTraversalSubRoleList;
};
/*!
*
* \class CRoleChainAutomataTransformationPreProcess
* \author Andreas Steigmiller
* \version 0.1
* \brief TODO
*
*/
class CRoleChainAutomataTransformationPreProcess : public CConcreteOntologyPreProcess {
// public methods
public:
//! Constructor
CRoleChainAutomataTransformationPreProcess();
//! Destructor
virtual ~CRoleChainAutomataTransformationPreProcess();
virtual CConcreteOntology *preprocess(CConcreteOntology *ontology, CPreProcessContext* context);
virtual CConcreteOntology *preprocess(CConcreteOntology *ontology, QSet<CConcept*>* trasformConceptSet, CPreProcessContext* context);
// protected methods
protected:
// private methods
private:
enum TRANSLATIONTYPE { TTNORMAL, TTIMPL, TTBRANCH, TTPROPBIND, TTBACKPROP, TTVARBIND };
CRole* getLocalizedRole(CRole* role);
CRole* getLocalizedRole(cint64 roleTag);
bool hasInverseRole(CRole* role, bool searchInverseEquivalent = true);
CRole* getInverseRole(CRole* role, bool searchInverseEquivalent = true);
bool hasSuperRole(CRole* role, CRole* testingSuperRole, bool testInversed, bool superRoleInversedRequired);
bool hasSuperRole(CRole* role, CRole* testingSuperRole, bool superRoleInversedRequired);
bool hasInversedSuperRole(CRole* role, CRole* testingSuperRole);
bool hasNonInversedSuperRole(CRole* role, CRole* testingSuperRole);
bool hasInversedOrNonInversedSuperRole(CRole* role, CRole* testingSuperRole);
CRoleChainAutomataTransformationPreProcess* convertAutomatConcept(CConcept* concept);
CConcept* createAutomatGeneratingConcept(CSortedNegLinker<CConcept*>* opLinker, bool negate, CRole* role);
CRoleChainAutomataTransformationPreProcess* collectSubRoleChains();
CRoleChainAutomataTransformationPreProcess* createMissingInverseChainedRoles();
CRoleChainAutomataTransformationPreProcess* createInverseRoleChainLinkers();
CRoleChainAutomataTransformationPreProcess* createRecursiveTraversalData();
QList<CRoleSubRoleChainData> getRelevantChainDataList(CRole* role, const QList<CRoleSubRoleChainData>& roleSubChainDataList);
CRoleChainAutomataTransformationPreProcess* addRecursiveTraversalData(CRole* role, const QList<CRoleSubRoleChainData>& roleSubChainDataList);
bool isChainDataImplicit(const CRoleSubRoleChainData& testingImplicitChainData, const CRoleSubRoleChainData& chainData);
bool isChainLinkerImplicit(CXLinker<CRole*>* testingImplicitChainLinker, CXLinker<CRole*>* chainLinker, bool inversedTesting);
bool isTransitiveChainData(const CRoleSubRoleChainData& chainData);
bool isChainDataRecursiveTraversalCritical(CRole* role, const CRoleSubRoleChainData& chainData);
bool collectRecursiveTraversalCriticalRoles(CRole* role, const CRoleSubRoleChainData& chainData, QHash<CRole*,bool>* criticalRoleNegationHash);
QHash<CRole*,bool> getRelevantRecursiveTraversalCriticalRoles(QHash<CRole*,bool>* criticalRoleNegationHash);
bool requiresRecursiveTraversalForRole(CRole* role, const CRoleSubRoleChainData& chainData, QHash<CRole*,bool>* criticalRoleNegationHash);
bool generateRoleChainAutomatConcept(CRole* lastRole, const CRecTravSubRoleChainDataItem& recTravSubRoleChainDataItem, QSet<CRole*>& alreadyUnfoldRoleSet, CConcept* beginConcept, CConcept* endConcept, TRANSLATIONTYPE transType);
bool generateRoleChainAutomatConcept(CRole* lastRole, const QList<CRoleSubRoleChainData>& subRoleChainDataList, QSet<CRole*>& alreadyUnfoldRoleSet, CConcept* beginConcept, CConcept* endConcept, TRANSLATIONTYPE transType);
bool generateRoleChainAutomatConcept(CRole* lastRole, CRole* superRole, CRoleChain* descendingRoleChain, bool negatedChain, QSet<CRole*>& alreadyUnfoldRoleSet, CConcept* beginConcept, CConcept* endConcept, TRANSLATIONTYPE transType);
CConcept* createTransitionConcept(CRole* role, TRANSLATIONTYPE transType);
CSortedNegLinker<CConcept*>* createTransitionOperandConceptLinker(CConcept* operandConcept, bool negation);
CConcept* appendTransitionOperandConceptLinker(CConcept* concept, CSortedNegLinker<CConcept*>* opLinker);
CConcept* createStateConcept(TRANSLATIONTYPE transType);
bool hasPropagationConcept(bool negated, CConcept* concept, CRole* role, CSortedNegLinker<CRole*>* roleList, bool inverseDomRange);
bool hasPropagatedConcept(bool negated, CConcept* concept, CSortedNegLinker<CRole*>* roleList, bool inverseDomRange);
CRoleChainAutomataTransformationPreProcess* createDomainRangePropagations();
CRoleChainAutomataTransformationPreProcess* transformVALUERestrictions();
CConcept* createNominalConcept(CIndividual* individual);
// private variables
private:
CConcreteOntology* mOntology;
CRoleVector *mRoleVec;
CConceptVector *mConVec;
cint64 mNextConceptTag;
CMemoryAllocationManager* mMemMan;
typedef QPair<CConcept*,bool> TConceptNegPair;
QHash<CRole*,CRecTravSubRoleChainDataItem> mRoleRecTravSubRoleChainDataHash;
QHash<CRole*,CRoleSubRoleChainData> mRoleSubRoleChainDataHash;
QSet<CRoleChain*> mInverseUpdateRoleChainSet;
QHash<TConceptNegPair,CConcept*> mDomConPropConceptHash;
QHash<TConceptNegPair,CConcept*> mRanConPropConceptHash;
CBUILDHASH<CRole*,CObjectPropertyTermExpression*>* mRoleObjPropTermHash;
CBUILDHASH<CObjectPropertyTermExpression*,CRole*>* mObjPropTermRoleHash;
CBUILDLIST<CBuildExpression*>* mExpressionBuildContainerList;
CBUILDHASH<CObjectPropertyTermExpression*,CObjectPropertyTermExpression*>* mInverseObjectPropertyHash;
CBUILDHASH<CExpressionHasher,CBuildExpression*>* mExpressionBuildHash;
cint64 mStatAutomateStateConceptCount;
cint64 mStatAutomateTransitionConceptCount;
cint64 mStatAutomateTransformedConceptCount;
cint64 mStatAutomateTransitiveSavedCount;
cint64 mStatRangePropagationCount;
cint64 mStatDomainPropagationCount;
cint64 mStatCreatedRangePropagationCount;
cint64 mStatCreatedDomainPropagationCount;
cint64 mStatPropagationAlreadyInDomainRangeCount;
cint64 mStatPropagatedAlreadyInDomainRangeCount;
bool mConfSaveTransitiveTransitions;
};
}; // end namespace Preprocess
}; // end namespace Reasoner
}; // end namespace Konclude
#endif // KONCLUDE_REASONER_PREPROCESS_CROLECHAINAUTOMATATRANSFORMATIONPREPROCESS_H
|