| 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 "CConcreteOntologyQuerySimpleBuilder.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Generator { |
| 29 |
|
| 30 |
|
| 31 |
CConcreteOntologyQuerySimpleBuilder::CConcreteOntologyQuerySimpleBuilder(CConcreteOntology* ontology, CConfigurationBase *configuration) |
| 32 |
: CConcreteOntologyQueryBasicBuilder(ontology,configuration) { |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
CConcreteOntologyQuerySimpleBuilder::~CConcreteOntologyQuerySimpleBuilder() { |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
CQueryAreClassesEquivalentExpression *CConcreteOntologyQuerySimpleBuilder::getAreClassesEquivalenceQuery(const CEXPRESSIONLIST<CClassTermExpression*> &testClassExpressions, const QString& queryName) { |
| 46 |
CQueryAreClassesEquivalentExpression *classEqExp = new CQueryAreClassesEquivalentExpression(queryName,testClassExpressions); |
| 47 |
container.append(classEqExp); |
| 48 |
classEqExpList.append(classEqExp); |
| 49 |
return classEqExp; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
CQueryAreClassesDisjointExpression *CConcreteOntologyQuerySimpleBuilder::getAreClassesDisjointQuery(const CEXPRESSIONLIST<CClassTermExpression*> &testClassExpressions, const QString& queryName) { |
| 54 |
CQueryAreClassesDisjointExpression *classEqExp = new CQueryAreClassesDisjointExpression(queryName,testClassExpressions); |
| 55 |
container.append(classEqExp); |
| 56 |
classDisjointExpList.append(classEqExp); |
| 57 |
return classEqExp; |
| 58 |
} |
| 59 |
|
| 60 |
CQueryIsClassSubsumedByExpression *CConcreteOntologyQuerySimpleBuilder::getIsClassSubsumedByQuery(CClassTermExpression* subsumerClassExpression, CClassTermExpression* subsumedClassExpression, const QString& queryName) { |
| 61 |
CQueryIsClassSubsumedByExpression* classEqExp = new CQueryIsClassSubsumedByExpression(queryName,subsumerClassExpression,subsumedClassExpression); |
| 62 |
container.append(classEqExp); |
| 63 |
classSubsumedExpList.append(classEqExp); |
| 64 |
return classEqExp; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
CQueryIsEntailedExpression* CConcreteOntologyQuerySimpleBuilder::getIsEntailedQuery(const CEXPRESSIONLIST<CAxiomExpression*>& axiomExpressions, const QString& queryName) { |
| 69 |
return nullptr; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
bool CConcreteOntologyQuerySimpleBuilder::requiresPreprocessedOntology() { |
| 74 |
return true; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
QList<CQuery*> CConcreteOntologyQuerySimpleBuilder::generateQuerys() { |
| 79 |
QList<CQuery*> queryList; |
| 80 |
|
| 81 |
CSatisfiableCalculationJobGenerator* satCalcJobGenerator = new CSatisfiableCalculationJobGenerator(mOntology); |
| 82 |
|
| 83 |
bool confBuildQueryStats = true; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
foreach (CQueryAreClassesEquivalentExpression *classEqExp, classEqExpList) { |
| 88 |
QString queryName = classEqExp->getName(); |
| 89 |
QStringList conceptNamesStrings; |
| 90 |
foreach (CClassTermExpression *buildExp, *classEqExp->getClassTermExpressionList()) { |
| 91 |
CConcept *concept = getConceptFromBuildExpression(buildExp); |
| 92 |
if (concept) { |
| 93 |
QString className = getStringFromConcept(concept); |
| 94 |
conceptNamesStrings.append(className); |
| 95 |
} |
| 96 |
} |
| 97 |
CAreClassesEquivalentQuery *query = new CAreClassesEquivalentQuery(conceptNamesStrings,queryName); |
| 98 |
CCalculationConfigurationExtension *calcConfig = new CCalculationConfigurationExtension(config,0); |
| 99 |
CQueryStatisticsCollectionStrings* queryStats = nullptr; |
| 100 |
if (confBuildQueryStats) { |
| 101 |
queryStats = new CQueryStatisticsCollectionStrings(); |
| 102 |
} |
| 103 |
CEXPRESSIONLIST<CClassTermExpression*>* testClassExpressions = classEqExp->getClassTermExpressionList(); |
| 104 |
for (CEXPRESSIONLIST<CClassTermExpression*>::const_iterator it0 = testClassExpressions->constBegin(); it0 != testClassExpressions->constEnd(); ++it0) { |
| 105 |
CEXPRESSIONLIST<CClassTermExpression*>::const_iterator it1 = it0; |
| 106 |
if (++it1 == testClassExpressions->constEnd()) { |
| 107 |
it1 = testClassExpressions->constBegin(); |
| 108 |
} |
| 109 |
CClassTermExpression *buildExp1 = *it0; |
| 110 |
CClassTermExpression *buildExp2 = *it1; |
| 111 |
CConcept *concept1 = getConceptFromBuildExpression(buildExp1); |
| 112 |
CConcept *concept2 = getConceptFromBuildExpression(buildExp2); |
| 113 |
|
| 114 |
CSatisfiableCalculationJob* satCalcJob = satCalcJobGenerator->getSatisfiableCalculationJob(concept1,false,concept2,true); |
| 115 |
if (confBuildQueryStats) { |
| 116 |
satCalcJob->setCalclulationStatisticsCollector(queryStats->createCalculationStatisticsCollection()); |
| 117 |
} |
| 118 |
satCalcJob->setCalculationConfiguration(calcConfig); |
| 119 |
query->addTestSatisfiableCalculationJob(satCalcJob,false); |
| 120 |
} |
| 121 |
|
| 122 |
query->setQueryStatistics(queryStats); |
| 123 |
|
| 124 |
queryList.append(query); |
| 125 |
LOG(NOTICE,"::Konclude::Reasoner::Generator::ConcreteOntologyQueryBuilder",logTr("Generated AreClassesEquivalent-Query '%1' with question '%2'.").arg(query->getQueryName()).arg(query->getQueryString()),this); |
| 126 |
|
| 127 |
delete classEqExp; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
foreach (CQueryAreClassesDisjointExpression *classDisjExp, classDisjointExpList) { |
| 133 |
QString queryName = classDisjExp->getName(); |
| 134 |
QStringList conceptNamesStrings; |
| 135 |
foreach (CClassTermExpression *buildExp, *classDisjExp->getClassTermExpressionList()) { |
| 136 |
CConcept *concept = getConceptFromBuildExpression(buildExp); |
| 137 |
if (concept) { |
| 138 |
QString className = getStringFromConcept(concept); |
| 139 |
conceptNamesStrings.append(className); |
| 140 |
} |
| 141 |
} |
| 142 |
CAreClassesDisjointQuery *query = new CAreClassesDisjointQuery(conceptNamesStrings,queryName); |
| 143 |
CCalculationConfigurationExtension *calcConfig = new CCalculationConfigurationExtension(config,0); |
| 144 |
CQueryStatisticsCollectionStrings* queryStats = nullptr; |
| 145 |
if (confBuildQueryStats) { |
| 146 |
queryStats = new CQueryStatisticsCollectionStrings(); |
| 147 |
} |
| 148 |
|
| 149 |
CEXPRESSIONLIST<CClassTermExpression*>* testClassExpressions = classDisjExp->getClassTermExpressionList(); |
| 150 |
for (CEXPRESSIONLIST<CClassTermExpression*>::const_iterator it0 = testClassExpressions->constBegin(); it0 != testClassExpressions->constEnd(); ++it0) { |
| 151 |
for (CEXPRESSIONLIST<CClassTermExpression*>::const_iterator it1 = it0; it1 != testClassExpressions->constEnd(); ++it1) { |
| 152 |
CClassTermExpression *buildExp1 = *it0; |
| 153 |
CClassTermExpression *buildExp2 = *it1; |
| 154 |
CConcept *concept1 = getConceptFromBuildExpression(buildExp1); |
| 155 |
CConcept *concept2 = getConceptFromBuildExpression(buildExp2); |
| 156 |
|
| 157 |
CSatisfiableCalculationJob* satCalcJob = satCalcJobGenerator->getSatisfiableCalculationJob(concept1,false,concept2,false); |
| 158 |
if (confBuildQueryStats) { |
| 159 |
satCalcJob->setCalclulationStatisticsCollector(queryStats->createCalculationStatisticsCollection()); |
| 160 |
} |
| 161 |
satCalcJob->setCalculationConfiguration(calcConfig); |
| 162 |
query->addTestSatisfiableCalculationJob(satCalcJob,false); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
query->setQueryStatistics(queryStats); |
| 167 |
queryList.append(query); |
| 168 |
LOG(NOTICE,"::Konclude::Reasoner::Generator::ConcreteOntologyQueryBuilder",logTr("Generated AreClassesDisjoint-Query '%1' with question '%2'.").arg(query->getQueryName()).arg(query->getQueryString()),this); |
| 169 |
|
| 170 |
delete classDisjExp; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
foreach (CQueryIsClassSubsumedByExpression *classSubsumedExp, classSubsumedExpList) { |
| 176 |
QString queryName = classSubsumedExp->getName(); |
| 177 |
QStringList conceptNamesStrings; |
| 178 |
|
| 179 |
QString subsumedClassName; |
| 180 |
QString subsummerClassName; |
| 181 |
qint64 loopStep = 0; |
| 182 |
|
| 183 |
CConcept *subsumedConcept = 0; |
| 184 |
CConcept *subsumerConcept = 0; |
| 185 |
|
| 186 |
subsumedConcept = getConceptFromBuildExpression(classSubsumedExp->getSubsumedClassExpression()); |
| 187 |
subsumerConcept = getConceptFromBuildExpression(classSubsumedExp->getSubsumerClassExpression()); |
| 188 |
|
| 189 |
subsumedClassName = getStringFromConcept(subsumedConcept); |
| 190 |
subsummerClassName = getStringFromConcept(subsumerConcept); |
| 191 |
|
| 192 |
CIsClassSubsumedByQuery *query = new CIsClassSubsumedByQuery(subsumedClassName,subsummerClassName,queryName); |
| 193 |
CCalculationConfigurationExtension *calcConfig = new CCalculationConfigurationExtension(config,0); |
| 194 |
|
| 195 |
CSatisfiableCalculationJob* satCalcJob = satCalcJobGenerator->getSatisfiableCalculationJob(subsumerConcept,false,subsumedConcept,true); |
| 196 |
|
| 197 |
CQueryStatisticsCollectionStrings* queryStats = nullptr; |
| 198 |
if (confBuildQueryStats) { |
| 199 |
queryStats = new CQueryStatisticsCollectionStrings(); |
| 200 |
satCalcJob->setCalclulationStatisticsCollector(queryStats->createCalculationStatisticsCollection()); |
| 201 |
} |
| 202 |
query->setQueryStatistics(queryStats); |
| 203 |
satCalcJob->setCalculationConfiguration(calcConfig); |
| 204 |
query->addTestSatisfiableCalculationJob(satCalcJob,false); |
| 205 |
|
| 206 |
|
| 207 |
queryList.append(query); |
| 208 |
LOG(NOTICE,"::Konclude::Reasoner::Generator::ConcreteOntologyQueryBuilder",logTr("Generated IsClassSubsemedBy-Query '%1' with question '%2'.").arg(query->getQueryName()).arg(query->getQueryString()),this); |
| 209 |
|
| 210 |
delete classSubsumedExp; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
delete satCalcJobGenerator; |
| 215 |
|
| 216 |
|
| 217 |
queryList.append(CConcreteOntologyQueryBasicBuilder::generateQuerys()); |
| 218 |
return queryList; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
}; // end namespace Generator |
| 224 |
|
| 225 |
}; // end namespace Reasoner |
| 226 |
|
| 227 |
}; // end namespace Konclude |