| 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_CLASSIFIER_COptimizedKPSetRoleSubsumptionClassifierThread_H |
| 22 |
#define KONCLUDE_REASONER_CLASSIFIER_COptimizedKPSetRoleSubsumptionClassifierThread_H |
| 23 |
|
| 24 |
// Libraries includes |
| 25 |
#include <QLinkedList> |
| 26 |
|
| 27 |
// Namespace includes |
| 28 |
#include "ClassifierSettings.h" |
| 29 |
#include "CSubsumptionClassifier.h" |
| 30 |
#include "CSubsumptionClassifierThread.h" |
| 31 |
#include "CPropertyClassificationComputationItem.h" |
| 32 |
#include "COptimizedKPSetRoleOntologyClassificationItem.h" |
| 33 |
#include "COptimizedKPSetRolePossibleSubsumptionData.h" |
| 34 |
#include "COptimizedKPSetRoleTestingItem.h" |
| 35 |
#include "CClassificationPropertySubsumptionMessageData.h" |
| 36 |
#include "CClassificationInitializePossiblePropertySubsumptionMessageData.h" |
| 37 |
#include "CClassificationUpdatePossiblePropertySubsumptionMessageData.h" |
| 38 |
|
| 39 |
// Other includes |
| 40 |
#include "Context/CContextBase.h" |
| 41 |
|
| 42 |
#include "Reasoner/Revision/COntologyRevision.h" |
| 43 |
|
| 44 |
#include "Reasoner/Ontology/CConceptProcessData.h" |
| 45 |
#include "Reasoner/Ontology/CConceptSaturationReferenceLinkingData.h" |
| 46 |
|
| 47 |
|
| 48 |
#include "Reasoner/Preprocess/CPreProcessContextBase.h" |
| 49 |
#include "Reasoner/Preprocess/CRoleChainAutomataTransformationPreProcess.h" |
| 50 |
|
| 51 |
#include "Reasoner/Generator/CSatisfiableCalculationJobGenerator.h" |
| 52 |
|
| 53 |
#include "Reasoner/Kernel/Task/CSatisfiableCalculationTask.h" |
| 54 |
#include "Reasoner/Kernel/Task/CConsistenceTaskData.h" |
| 55 |
|
| 56 |
|
| 57 |
#include "Utilities/Memory/CTempMemoryPoolContainerAllocationManager.h" |
| 58 |
|
| 59 |
#include "KoncludeSettings.h" |
| 60 |
|
| 61 |
// Logger includes |
| 62 |
#include "Logger/CLogger.h" |
| 63 |
#include "Logger/CLogIdentifier.h" |
| 64 |
|
| 65 |
#include <iostream> |
| 66 |
|
| 67 |
using namespace std; |
| 68 |
|
| 69 |
|
| 70 |
namespace Konclude { |
| 71 |
|
| 72 |
using namespace Context; |
| 73 |
using namespace Utilities::Memory; |
| 74 |
|
| 75 |
namespace Reasoner { |
| 76 |
|
| 77 |
using namespace Revision; |
| 78 |
using namespace Ontology; |
| 79 |
using namespace Generator; |
| 80 |
using namespace Preprocess; |
| 81 |
|
| 82 |
using namespace Kernel; |
| 83 |
using namespace Task; |
| 84 |
|
| 85 |
namespace Classifier { |
| 86 |
|
| 87 |
#ifndef KONCLUDE_FORCE_ALL_DEBUG_DEACTIVATED |
| 88 |
|
| 89 |
//#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGCOUTOUTPUT |
| 90 |
//#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGTAXONOMYCOUTOUTPUT |
| 91 |
//#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGLOGOUTPUT |
| 92 |
//#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGBOXDESCRIPTION |
| 93 |
#define OPTIMIZEDKPSETCLASSCLASSIFIERDEBUGSTATUSDESCRIPTION |
| 94 |
|
| 95 |
#endif |
| 96 |
|
| 97 |
|
| 98 |
/*! |
| 99 |
* |
| 100 |
* \class COptimizedKPSetRoleSubsumptionClassifierThread |
| 101 |
* \author Andreas Steigmiller |
| 102 |
* \version 0.1 |
| 103 |
* \brief TODO |
| 104 |
* |
| 105 |
*/ |
| 106 |
class COptimizedKPSetRoleSubsumptionClassifierThread : public CSubsumptionClassifierThread, public CLogIdentifier { |
| 107 |
// public methods |
| 108 |
public: |
| 109 |
//! Constructor |
| 110 |
COptimizedKPSetRoleSubsumptionClassifierThread(CReasonerManager *reasonerManager, bool dataRoleClassification); |
| 111 |
|
| 112 |
//! Destructor |
| 113 |
virtual ~COptimizedKPSetRoleSubsumptionClassifierThread(); |
| 114 |
|
| 115 |
virtual QString getStatusString(); |
| 116 |
virtual CClassificationProgress* getClassificationProgress(); |
| 117 |
|
| 118 |
// protected methods |
| 119 |
protected: |
| 120 |
virtual bool finishOntologyClassification(COntologyPropertyRoleClassificationItem *ontPropItem); |
| 121 |
virtual CSubsumptionClassifierThread *scheduleOntologyClassification(CConcreteOntology *ontology, CClassificationCalculationSupport *classificationSupport, CConfigurationBase *config); |
| 122 |
|
| 123 |
|
| 124 |
COptimizedKPSetRoleSubsumptionClassifierThread* createTemporaryRoleClassificationOntology(COptimizedKPSetRoleOntologyClassificationItem* item); |
| 125 |
void addTemporaryConceptOperand(CConcept* concept, CConcept* opConcept, bool negated, CConcreteOntology* tmpRoleRealOntology); |
| 126 |
CConcept* createTemporaryConcept(CConcreteOntology* tmpRoleRealOntology); |
| 127 |
COptimizedKPSetRoleSubsumptionClassifierThread* createInitialSubsumptionSatisfiabilityTestingOrderFromBuildData(COptimizedKPSetRoleOntologyClassificationItem* ontPropItem); |
| 128 |
|
| 129 |
|
| 130 |
virtual CSubsumptionClassifierThread *processCalculationJob(CSatisfiableCalculationJob* job, COntologyPropertyRoleClassificationItem *ontPropItem, CPropertyClassificationComputationItem* workItem); |
| 131 |
|
| 132 |
virtual void readCalculationConfig(CCalculationConfigurationExtension *config); |
| 133 |
|
| 134 |
virtual bool interpreteSubsumptionResult(COntologyPropertyRoleClassificationItem *ontPropItem, CRole *subsumerRole, CRole *subsumedRole, bool isSubsumption); |
| 135 |
virtual bool interpreteSatisfiableResult(COntologyPropertyRoleClassificationItem *ontPropItem, CRole *satisfiableRole, bool isSatis); |
| 136 |
|
| 137 |
virtual bool interpreteTestResults(CTestCalculatedCallbackEvent *testResult); |
| 138 |
|
| 139 |
|
| 140 |
virtual bool createNextSubsumtionTest(); |
| 141 |
virtual CRolePropertiesHierarchy *createInitialHierarchyForOntology(CConcreteOntology *ontology, CConfigurationBase *config); |
| 142 |
|
| 143 |
virtual bool interpreteToldSubsumptionResult(COntologyPropertyRoleClassificationItem *ontPropItem, const QList< QPair<CRole*,CRole*> > &subSumRelList, bool isSubSum); |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
bool calculateSatisfiable(COptimizedKPSetRoleOntologyClassificationItem *optSubClassItem, COptimizedKPSetRoleTestingItem* nextSatTestItem); |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
virtual bool processToldClassificationMessage(COntologyClassificationItem *ontPropItem, CClassificationMessageData* messageData, CMemoryPool* memoryPools); |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
bool calculateSubsumption(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* subsumedItem, COptimizedKPSetRoleTestingItem* possSubsumerItem, COptimizedKPSetRolePossibleSubsumptionData* possSubsumData); |
| 156 |
|
| 157 |
COptimizedKPSetRolePossibleSubsumptionData* getNextPossibleSubsumptionCalculation(COptimizedKPSetRoleOntologyClassificationItem *ontPropItem, COptimizedKPSetRoleTestingItem* classItem); |
| 158 |
|
| 159 |
|
| 160 |
bool prunePossibleSubsumptions(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* item, COptimizedKPSetRolePossibleSubsumptionData* possSubsumData); |
| 161 |
bool propagateDownSubsumption(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* item, COptimizedKPSetRoleTestingItem* subsumerItem); |
| 162 |
bool pruneDownSubsumption(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* item, CRole* subsumerRole); |
| 163 |
bool pruneUpNotSubsumption(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* item, CRole* notSubsumerRole); |
| 164 |
|
| 165 |
bool propagateUnsatisfiability(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRoleTestingItem* item); |
| 166 |
|
| 167 |
QString createDebugKPSetString(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, const QString& filename); |
| 168 |
void testDebugPossibleSubsumerCorrectCounted(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem); |
| 169 |
void testDebugPossibleSubsumerCorrectReferenced(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem); |
| 170 |
|
| 171 |
void incRemainingPossibleSubsumptionTestingCount(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRolePossibleSubsumptionMap* posSubsumMap); |
| 172 |
void decRemainingPossibleSubsumptionTestingCount(COptimizedKPSetRoleOntologyClassificationItem *optKPSetClassificationItem, COptimizedKPSetRolePossibleSubsumptionMap* posSubsumMap, bool subsumptionConfirmed); |
| 173 |
|
| 174 |
|
| 175 |
// protected variables |
| 176 |
protected: |
| 177 |
QHash<CPropertyClassificationComputationItem *, COntologyPropertyRoleClassificationItem *> workOntItemHash; |
| 178 |
|
| 179 |
QStringList satTestedConList; |
| 180 |
QStringList possSubsumInitConList; |
| 181 |
QString statusString; |
| 182 |
QMutex statUpdateMutex; |
| 183 |
|
| 184 |
CClassificationProgress mClassifyProgess; |
| 185 |
cint64 satTestedCount; |
| 186 |
cint64 totalToSatTestClassCount; |
| 187 |
|
| 188 |
cint64 subsumTestedCount; |
| 189 |
cint64 totalToSubsumTestCount; |
| 190 |
QTime classStartTime; |
| 191 |
|
| 192 |
QSet<QPair<CConcept *, CConcept *> > subsumCalcedSet; |
| 193 |
|
| 194 |
bool mConfPossSubsumCalcOrderTopDown; |
| 195 |
bool mConfPossSubsumCalcOrderBottomUp; |
| 196 |
|
| 197 |
bool mConfPossSubsumCalcOrderRoleSorted; |
| 198 |
bool mConfPossSubsumCalcOrderFewestSubsumptionSorted; |
| 199 |
|
| 200 |
bool mConfPossSubsumPseudoModelPretest; |
| 201 |
|
| 202 |
bool mConfPossSubsumPseudoModelTest; |
| 203 |
bool mConfWriteDebuggingData; |
| 204 |
|
| 205 |
cint64 mStatProcesedSubsumMessCount; |
| 206 |
cint64 mStatProcesedPossSubsumInitMessCount; |
| 207 |
cint64 mStatProcesedPossSubsumUpdateMessCount; |
| 208 |
cint64 mStatProcesedPseudoModelMessCount; |
| 209 |
|
| 210 |
|
| 211 |
cint64 mInterpretedSubsumptionCalculationCount; |
| 212 |
cint64 mOrderedSubsumptionCalculationCount; |
| 213 |
cint64 mPseudoModelPretestSubsumptionCalculationCount; |
| 214 |
cint64 mCreatedCalculationTaskCount; |
| 215 |
cint64 mRecievedCallbackCount; |
| 216 |
|
| 217 |
bool mDataRolesClassification; |
| 218 |
|
| 219 |
|
| 220 |
// private methods |
| 221 |
private: |
| 222 |
|
| 223 |
// private variables |
| 224 |
private: |
| 225 |
|
| 226 |
}; |
| 227 |
|
| 228 |
}; // end namespace Classifier |
| 229 |
|
| 230 |
}; // end namespace Reasoner |
| 231 |
|
| 232 |
}; // end namespace Konclude |
| 233 |
|
| 234 |
#endif // KONCLUDE_REASONER_CLASSIFIER_COptimizedKPSetRoleSubsumptionClassifierThread_H |