| 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 "CClassificationManager.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Classifier { |
| 29 |
|
| 30 |
|
| 31 |
CClassificationManager::CClassificationManager() { |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
CClassificationManager::~CClassificationManager() { |
| 36 |
if (mClassifierFac) { |
| 37 |
delete mClassifierFac; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
cint64 CClassificationManager::getActiveClassifierCount() { |
| 43 |
readWriteLock.lockForRead(); |
| 44 |
cint64 activeCount = 0; |
| 45 |
foreach (CSubsumptionClassifier* classifier, mOntoClassifierSet) { |
| 46 |
CSubsumptionClassifierThread* threadClassifier = dynamic_cast<CSubsumptionClassifierThread*>(classifier); |
| 47 |
if (threadClassifier && threadClassifier->isClassifierActive()) { |
| 48 |
++activeCount; |
| 49 |
} |
| 50 |
} |
| 51 |
readWriteLock.unlock(); |
| 52 |
return activeCount; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
CClassificationManager *CClassificationManager::initializeManager(CSubsumptionClassifierFactory *takeClassifierFactory, CConfigurationProvider *configurationProvider) { |
| 57 |
mClassifierFac = takeClassifierFactory; |
| 58 |
return this; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
CSubsumptionClassifier *CClassificationManager::getClassClassifier(CConcreteOntology *ontology, CConfigurationBase *config, bool create, bool backgroundClassification) { |
| 63 |
readWriteLock.lockForRead(); |
| 64 |
CSubsumptionClassifier *classifier = mOntoClassifierHash.value(ontology); |
| 65 |
readWriteLock.unlock(); |
| 66 |
if (!classifier) { |
| 67 |
readWriteLock.lockForWrite(); |
| 68 |
classifier = mOntoClassifierHash.value(ontology); |
| 69 |
if (!classifier) { |
| 70 |
classifier = mClassifierFac->createClassifier(ontology,config); |
| 71 |
mOntoClassifierSet.insert(classifier); |
| 72 |
mOntoClassifierHash.insert(ontology,classifier); |
| 73 |
} |
| 74 |
readWriteLock.unlock(); |
| 75 |
} |
| 76 |
return classifier; |
| 77 |
} |
| 78 |
|
| 79 |
CClassifierStatistics *CClassificationManager::collectClassificationStatistics(CClassifierStatistics *statistics) { |
| 80 |
statistics->resetValues(); |
| 81 |
readWriteLock.lockForRead(); |
| 82 |
foreach (CSubsumptionClassifier *classifier, mOntoClassifierSet) { |
| 83 |
CClassifierStatistics *classifierStatistics = classifier->getClassificationStatistics(); |
| 84 |
statistics->appendStatistics(classifierStatistics); |
| 85 |
} |
| 86 |
readWriteLock.unlock(); |
| 87 |
return statistics; |
| 88 |
} |
| 89 |
|
| 90 |
QList<CSubsumptionClassifier *> CClassificationManager::getClassifierList() { |
| 91 |
readWriteLock.lockForRead(); |
| 92 |
QList<CSubsumptionClassifier *> list(mOntoClassifierSet.values()); |
| 93 |
readWriteLock.unlock(); |
| 94 |
return list; |
| 95 |
} |
| 96 |
|
| 97 |
CClassificationProgress* CClassificationManager::getClassificationProgress() { |
| 98 |
CClassificationProgress newClassProg; |
| 99 |
readWriteLock.lockForRead(); |
| 100 |
double percentAvg = 0; |
| 101 |
cint64 percentCount = 0; |
| 102 |
foreach (CSubsumptionClassifier *classifier, mOntoClassifierSet) { |
| 103 |
CClassificationProgress* classificationProgress = classifier->getClassificationProgress(); |
| 104 |
if (classificationProgress) { |
| 105 |
newClassProg.setTotalSatisfiable(newClassProg.getTotalSatisfiable()+classificationProgress->getTotalSatisfiable()); |
| 106 |
newClassProg.setClassificationCount(newClassProg.getClassificationCount()+classificationProgress->getClassificationCount()); |
| 107 |
newClassProg.setTestedSatisfiable(newClassProg.getTestedSatisfiable()+classificationProgress->getTestedSatisfiable()); |
| 108 |
newClassProg.setTestedSubsumptions(newClassProg.getTestedSubsumptions()+classificationProgress->getTestedSubsumptions()); |
| 109 |
newClassProg.setTotalSubsumptions(newClassProg.getTotalSubsumptions()+classificationProgress->getTotalSubsumptions()); |
| 110 |
newClassProg.setRemainingMilliSeconds(qMax(newClassProg.getRemainingMilliSeconds(),classificationProgress->getRemainingMilliSeconds())); |
| 111 |
percentAvg += classificationProgress->getProgessPercent(); |
| 112 |
++percentCount; |
| 113 |
} |
| 114 |
} |
| 115 |
readWriteLock.unlock(); |
| 116 |
if (percentCount != 0) { |
| 117 |
percentAvg /= (double)percentCount; |
| 118 |
} |
| 119 |
newClassProg.setProgessPercent(percentAvg); |
| 120 |
mClassificationProgress = newClassProg; |
| 121 |
return &mClassificationProgress; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
CSubsumptionClassifier* CClassificationManager::getDataPropertyClassifier(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 127 |
readWriteLock.lockForRead(); |
| 128 |
CSubsumptionClassifier *classifier = mOntoDataPropertyClassifierHash.value(ontology); |
| 129 |
readWriteLock.unlock(); |
| 130 |
if (!classifier) { |
| 131 |
readWriteLock.lockForWrite(); |
| 132 |
classifier = mOntoDataPropertyClassifierHash.value(ontology); |
| 133 |
if (!classifier) { |
| 134 |
classifier = mClassifierFac->getDataPropertyClassifier(ontology,config); |
| 135 |
mOntoClassifierSet.insert(classifier); |
| 136 |
mOntoDataPropertyClassifierHash.insert(ontology,classifier); |
| 137 |
} |
| 138 |
readWriteLock.unlock(); |
| 139 |
} |
| 140 |
return classifier; |
| 141 |
} |
| 142 |
|
| 143 |
CSubsumptionClassifier* CClassificationManager::getObjectPropertyClassifier(CConcreteOntology *ontology, CConfigurationBase *config) { |
| 144 |
readWriteLock.lockForRead(); |
| 145 |
CSubsumptionClassifier *classifier = mOntoObjectPropertyClassifierHash.value(ontology); |
| 146 |
readWriteLock.unlock(); |
| 147 |
if (!classifier) { |
| 148 |
readWriteLock.lockForWrite(); |
| 149 |
classifier = mOntoObjectPropertyClassifierHash.value(ontology); |
| 150 |
if (!classifier) { |
| 151 |
classifier = mClassifierFac->getObjectPropertyClassifier(ontology,config); |
| 152 |
mOntoClassifierSet.insert(classifier); |
| 153 |
mOntoObjectPropertyClassifierHash.insert(ontology,classifier); |
| 154 |
} |
| 155 |
readWriteLock.unlock(); |
| 156 |
} |
| 157 |
return classifier; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
}; // end namespace Classifier |
| 164 |
|
| 165 |
}; // end namespace Reasoner |
| 166 |
|
| 167 |
}; // end namespace Konclude |