| 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 "CConfigDependedSubsumptionClassifierFactory.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Classifier { |
| 29 |
|
| 30 |
|
| 31 |
CConfigDependedSubsumptionClassifierFactory::CConfigDependedSubsumptionClassifierFactory(CReasonerManager *reasonerManager) { |
| 32 |
reasonerMan = reasonerManager; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
CConfigDependedSubsumptionClassifierFactory::~CConfigDependedSubsumptionClassifierFactory() { |
| 37 |
} |
| 38 |
|
| 39 |
CSubsumptionClassifier *CConfigDependedSubsumptionClassifierFactory::createClassifier(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 40 |
CSubsumptionClassifier *classifier = 0; |
| 41 |
bool automatedClassifierSelection = CConfigDataReader::readConfigBoolean(config,"Konclude.Calculation.Classification.AutomatedOptimizedClassifierSelection",true); |
| 42 |
if (automatedClassifierSelection) { |
| 43 |
|
| 44 |
bool onlyChangedABoxAxioms = ontology->getIncrementalRevisionData()->getAxiomChangeData()->hasOnlyChangedABoxAxioms(); |
| 45 |
bool previousClassifiedOntologyVersion = ontology->getIncrementalRevisionData()->getPreviousClassesClassifiedOntology() != nullptr; |
| 46 |
if (previousClassifiedOntologyVersion && onlyChangedABoxAxioms) { |
| 47 |
classifier = new CIncrementalKPSetClassSubsumptionClassifierThread(reasonerMan); |
| 48 |
} else if (isClassificationBySaturationCalculationSufficient(ontology,config)) { |
| 49 |
LOG(INFO,"::Konclude::Reasoner::Classifier::Factory",logTr("Ontology '%1' has been sufficiently saturated, extracting data for classification.").arg(ontology->getOntologyName()),this); |
| 50 |
classifier = new COptimizedClassExtractedSaturationSubsumptionClassifierThread(reasonerMan); |
| 51 |
} else if (isClassificationBySatisfiableCalculationSufficient(ontology,config)) { |
| 52 |
LOG(INFO,"::Konclude::Reasoner::Classifier::Factory",logTr("Ontology '%1' is deterministic, using satisfiable tests for classification.").arg(ontology->getOntologyName()),this); |
| 53 |
classifier = new COptimizedSubClassSubsumptionClassifierThread(reasonerMan); |
| 54 |
} |
| 55 |
} |
| 56 |
if (!classifier) { |
| 57 |
QString classifierName = CConfigDataReader::readConfigString(config,"Konclude.Calculation.Classification.Classifier","Konclude.Calculation.Classification.Classifier.OptimizedKPSetClassClassifier"); |
| 58 |
|
| 59 |
if (classifierName == "Konclude.Calculation.Classification.Classifier.OptimizedSubClassClassifier") { |
| 60 |
classifier = new COptimizedSubClassSubsumptionClassifierThread(reasonerMan); |
| 61 |
} else if (classifierName == "Konclude.Calculation.Classification.Classifier.OptimizedKPSetClassClassifier") { |
| 62 |
classifier = new COptimizedKPSetClassSubsumptionClassifierThread(reasonerMan); |
| 63 |
} else if (classifierName == "Konclude.Calculation.Classification.Classifier.OptimizedClassExtractedSaturationClassifier") { |
| 64 |
classifier = new COptimizedClassExtractedSaturationSubsumptionClassifierThread(reasonerMan); |
| 65 |
} |
| 66 |
} |
| 67 |
return classifier; |
| 68 |
} |
| 69 |
|
| 70 |
CSubsumptionClassifier *CConfigDependedSubsumptionClassifierFactory::createBackgroundClassifier(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 71 |
CSubsumptionClassifier *classifier = createClassifier(ontology,config); |
| 72 |
return classifier; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
bool CConfigDependedSubsumptionClassifierFactory::isClassificationBySatisfiableCalculationSufficient(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 77 |
COntologyStructureSummary* ontoStrSum = ontology->getStructureSummary(); |
| 78 |
if (ontoStrSum) { |
| 79 |
return ontoStrSum->hasOnlyDeterministicConceptClasses(); |
| 80 |
} else { |
| 81 |
return false; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
bool CConfigDependedSubsumptionClassifierFactory::isClassificationBySaturationCalculationSufficient(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 86 |
|
| 87 |
bool subsumerSaturationExtraction = CConfigDataReader::readConfigBoolean(config,"Konclude.Calculation.Classification.SaturationSubsumerExtraction",true); |
| 88 |
if (!subsumerSaturationExtraction) { |
| 89 |
return false; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
CSaturationData* satData = ontology->getPrecomputation()->getSaturationModelData(); |
| 94 |
if (satData) { |
| 95 |
CSaturationTaskData* satTaskData = dynamic_cast<CSaturationTaskData*>(satData); |
| 96 |
if (satTaskData) { |
| 97 |
CSatisfiableCalculationTask* satCalcTask = satTaskData->getSaturationTask(); |
| 98 |
if (!satCalcTask->getProcessingDataBox()->isInsufficientNodeOccured() && !satCalcTask->getProcessingDataBox()->isProblematicEQCandidateOccured()) { |
| 99 |
CBOXSET<CConcept*>* eqConceptNonCandSet = ontology->getTBox()->getEquivalentConceptNonCandidateSet(false); |
| 100 |
if (!eqConceptNonCandSet || eqConceptNonCandSet->isEmpty()) { |
| 101 |
return true; |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
return false; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
CSubsumptionClassifier* CConfigDependedSubsumptionClassifierFactory::getDataPropertyClassifier(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 113 |
return new COptimizedKPSetRoleSubsumptionClassifierThread(reasonerMan,true); |
| 114 |
} |
| 115 |
|
| 116 |
CSubsumptionClassifier* CConfigDependedSubsumptionClassifierFactory::getObjectPropertyClassifier(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 117 |
return new COptimizedKPSetRoleSubsumptionClassifierThread(reasonerMan,false); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
}; // end namespace Classifier |
| 123 |
|
| 124 |
}; // end namespace Reasoner |
| 125 |
|
| 126 |
}; // end namespace Konclude |