| 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 "CJNIQueryProcessor.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Control { |
| 27 |
|
| 28 |
namespace Interface { |
| 29 |
|
| 30 |
namespace JNI { |
| 31 |
|
| 32 |
|
| 33 |
CJNIQueryProcessor::CJNIQueryProcessor(CJNIInstanceManager* jniInstanceManager, CJNIOntologyRevisionData* ontRevData) { |
| 34 |
mOntRevData = ontRevData; |
| 35 |
mJNIInstanceManager = jniInstanceManager; |
| 36 |
mJNICommandProcessor = jniInstanceManager->getJNICommandProcessor(); |
| 37 |
} |
| 38 |
|
| 39 |
CJNIQueryProcessor::~CJNIQueryProcessor() { |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
bool CJNIQueryProcessor::checkIsOntologyConsistent() { |
| 44 |
bool consistent = false; |
| 45 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 46 |
CIsConsistentQuery* consistencyQuery = new CIsConsistentQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig); |
| 47 |
mJNICommandProcessor->calculateOntologyQuery(consistencyQuery); |
| 48 |
CQueryResult* result = consistencyQuery->getQueryResult(); |
| 49 |
if (result) { |
| 50 |
CBooleanQueryResult* boolQueryResult = dynamic_cast<CBooleanQueryResult*>(result); |
| 51 |
consistent = boolQueryResult->getResult(); |
| 52 |
} |
| 53 |
delete consistencyQuery; |
| 54 |
return consistent; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
bool CJNIQueryProcessor::queryOntologySubClasses(const QString& className, bool direct, CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 63 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 64 |
CConcept* concept = ont->getStringMapping()->getConceptFromName(className); |
| 65 |
if (concept) { |
| 66 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 67 |
CSubSuperClassesResultVisitCallbackQuery* subSuperClassQuery = new CSubSuperClassesResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,concept,className,true,false,direct); |
| 68 |
mJNICommandProcessor->calculateOntologyQuery(subSuperClassQuery); |
| 69 |
CQueryResult* result = subSuperClassQuery->getQueryResult(); |
| 70 |
if (result) { |
| 71 |
subSuperClassQuery->callbackVisitingClasses(visitingCallback); |
| 72 |
} |
| 73 |
delete subSuperClassQuery; |
| 74 |
return result != nullptr; |
| 75 |
} |
| 76 |
return false; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
bool CJNIQueryProcessor::queryOntologySuperClasses(const QString& className, bool direct, CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 81 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 82 |
CConcept* concept = ont->getStringMapping()->getConceptFromName(className); |
| 83 |
if (concept) { |
| 84 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 85 |
CSubSuperClassesResultVisitCallbackQuery* subSuperClassQuery = new CSubSuperClassesResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,concept,className,false,true,direct); |
| 86 |
mJNICommandProcessor->calculateOntologyQuery(subSuperClassQuery); |
| 87 |
CQueryResult* result = subSuperClassQuery->getQueryResult(); |
| 88 |
if (result) { |
| 89 |
subSuperClassQuery->callbackVisitingClasses(visitingCallback); |
| 90 |
} |
| 91 |
delete subSuperClassQuery; |
| 92 |
return result != nullptr; |
| 93 |
} |
| 94 |
return false; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
bool CJNIQueryProcessor::queryOntologyEquivalentClasses(const QString& className, CEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 99 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 100 |
CConcept* concept = ont->getStringMapping()->getConceptFromName(className); |
| 101 |
if (concept) { |
| 102 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 103 |
CEquivalentClassesResultVisitCallbackQuery* equivClassQuery = new CEquivalentClassesResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,concept,className); |
| 104 |
mJNICommandProcessor->calculateOntologyQuery(equivClassQuery); |
| 105 |
CQueryResult* result = equivClassQuery->getQueryResult(); |
| 106 |
if (result) { |
| 107 |
equivClassQuery->callbackVisitingClasses(visitingCallback); |
| 108 |
} |
| 109 |
delete equivClassQuery; |
| 110 |
return result != nullptr; |
| 111 |
} else { |
| 112 |
LOG(INFO,"::Konclude::JNIQueryProcessor",logTr("Could not resolve concept for '%1'.").arg(className),0); |
| 113 |
} |
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
bool CJNIQueryProcessor::queryOntologySubObjectProperties(const QString& propertyName, bool direct, CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 127 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 128 |
CRole* role = ont->getStringMapping()->getRoleFromName(propertyName); |
| 129 |
if (role) { |
| 130 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 131 |
CSubSuperPropertiesResultVisitCallbackQuery* subSuperPropertiesQuery = new CSubSuperPropertiesResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,role,propertyName,true,false,false,direct); |
| 132 |
mJNICommandProcessor->calculateOntologyQuery(subSuperPropertiesQuery); |
| 133 |
CQueryResult* result = subSuperPropertiesQuery->getQueryResult(); |
| 134 |
if (result) { |
| 135 |
subSuperPropertiesQuery->callbackVisitingProperties(visitingCallback); |
| 136 |
} |
| 137 |
delete subSuperPropertiesQuery; |
| 138 |
return result != nullptr; |
| 139 |
} |
| 140 |
return false; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
bool CJNIQueryProcessor::queryOntologySuperObjectProperties(const QString& propertyName, bool direct, CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 145 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 146 |
CRole* role = ont->getStringMapping()->getRoleFromName(propertyName); |
| 147 |
if (role) { |
| 148 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 149 |
CSubSuperPropertiesResultVisitCallbackQuery* subSuperPropertiesQuery = new CSubSuperPropertiesResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,role,propertyName,false,true,false,direct); |
| 150 |
mJNICommandProcessor->calculateOntologyQuery(subSuperPropertiesQuery); |
| 151 |
CQueryResult* result = subSuperPropertiesQuery->getQueryResult(); |
| 152 |
if (result) { |
| 153 |
subSuperPropertiesQuery->callbackVisitingProperties(visitingCallback); |
| 154 |
} |
| 155 |
delete subSuperPropertiesQuery; |
| 156 |
return result != nullptr; |
| 157 |
} |
| 158 |
return false; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
bool CJNIQueryProcessor::queryOntologyEquivalentObjectProperties(const QString& propertyName, CEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 163 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 164 |
CRole* role = ont->getStringMapping()->getRoleFromName(propertyName); |
| 165 |
if (role) { |
| 166 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 167 |
CEquivalentPropertiesResultVisitCallbackQuery* equivPropQuery = new CEquivalentPropertiesResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,role,false,propertyName); |
| 168 |
mJNICommandProcessor->calculateOntologyQuery(equivPropQuery); |
| 169 |
CQueryResult* result = equivPropQuery->getQueryResult(); |
| 170 |
if (result) { |
| 171 |
equivPropQuery->callbackVisitingProperties(visitingCallback); |
| 172 |
} |
| 173 |
delete equivPropQuery; |
| 174 |
return result != nullptr; |
| 175 |
} else { |
| 176 |
LOG(INFO,"::Konclude::JNIQueryProcessor",logTr("Could not resolve role for '%1'.").arg(propertyName),0); |
| 177 |
} |
| 178 |
return false; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
bool CJNIQueryProcessor::queryOntologyInstances(const QString& className, bool direct, CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 188 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 189 |
CConcept* concept = ont->getStringMapping()->getConceptFromName(className); |
| 190 |
if (concept) { |
| 191 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 192 |
CInstancesResultVisitCallbackQuery* instancesQuery = new CInstancesResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,concept,direct,className); |
| 193 |
mJNICommandProcessor->calculateOntologyQuery(instancesQuery); |
| 194 |
CQueryResult* result = instancesQuery->getQueryResult(); |
| 195 |
if (result) { |
| 196 |
instancesQuery->callbackVisitingInstances(visitingCallback); |
| 197 |
} |
| 198 |
delete instancesQuery; |
| 199 |
return result != nullptr; |
| 200 |
} else { |
| 201 |
LOG(INFO,"::Konclude::JNIQueryProcessor",logTr("Could not resolve concept for '%1'.").arg(className),0); |
| 202 |
} |
| 203 |
return false; |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
bool CJNIQueryProcessor::queryOntologyTypes(const QString& indiName, bool direct, CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 210 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 211 |
CIndividual* indi = ont->getStringMapping()->getIndividualFromName(indiName); |
| 212 |
if (indi) { |
| 213 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 214 |
CTypesResultVisitCallbackQuery* typesQuery = new CTypesResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,indi,direct,indiName); |
| 215 |
mJNICommandProcessor->calculateOntologyQuery(typesQuery); |
| 216 |
CQueryResult* result = typesQuery->getQueryResult(); |
| 217 |
if (result) { |
| 218 |
typesQuery->callbackVisitingTypes(visitingCallback); |
| 219 |
} |
| 220 |
delete typesQuery; |
| 221 |
return result != nullptr; |
| 222 |
} else { |
| 223 |
LOG(INFO,"::Konclude::JNIQueryProcessor",logTr("Could not resolve individual for '%1'.").arg(indiName),0); |
| 224 |
} |
| 225 |
return false; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
bool CJNIQueryProcessor::queryOntologySameIndividuals(const QString& indiName, CEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 231 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 232 |
CIndividual* indi = ont->getStringMapping()->getIndividualFromName(indiName); |
| 233 |
if (indi) { |
| 234 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 235 |
CSameIndividualsResultVisitCallbackQuery* sameIndiQuery = new CSameIndividualsResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,indi,indiName); |
| 236 |
mJNICommandProcessor->calculateOntologyQuery(sameIndiQuery); |
| 237 |
CQueryResult* result = sameIndiQuery->getQueryResult(); |
| 238 |
if (result) { |
| 239 |
sameIndiQuery->callbackVisitingInstances(visitingCallback); |
| 240 |
} |
| 241 |
delete sameIndiQuery; |
| 242 |
return result != nullptr; |
| 243 |
} |
| 244 |
return false; |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
bool CJNIQueryProcessor::queryOntologyObjectPropertySources(const QString& indiName, const QString& propertyName, CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 251 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 252 |
CIndividual* indi = ont->getStringMapping()->getIndividualFromName(indiName); |
| 253 |
CRole* role = ont->getStringMapping()->getRoleFromName(propertyName); |
| 254 |
if (indi && role) { |
| 255 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 256 |
CObjectPropertySourcesTargetsResultVisitCallbackQuery* propertySouTarQuery = new CObjectPropertySourcesTargetsResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,indi,role,true,false); |
| 257 |
mJNICommandProcessor->calculateOntologyQuery(propertySouTarQuery); |
| 258 |
CQueryResult* result = propertySouTarQuery->getQueryResult(); |
| 259 |
if (result) { |
| 260 |
propertySouTarQuery->callbackVisitingIndividuals(visitingCallback); |
| 261 |
} |
| 262 |
delete propertySouTarQuery; |
| 263 |
return result != nullptr; |
| 264 |
} |
| 265 |
return false; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
bool CJNIQueryProcessor::queryOntologyObjectPropertyTargets(const QString& indiName, const QString& propertyName, CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 272 |
CConcreteOntology* ont = mOntRevData->getOntologyRevision()->getOntology(); |
| 273 |
CIndividual* indi = ont->getStringMapping()->getIndividualFromName(indiName); |
| 274 |
CRole* role = ont->getStringMapping()->getRoleFromName(propertyName); |
| 275 |
if (indi && role) { |
| 276 |
CCalculationConfigurationExtension* calcConfig = new CCalculationConfigurationExtension(mOntRevData->getOntologyRevision()->getOntologyConfiguration()); |
| 277 |
CObjectPropertySourcesTargetsResultVisitCallbackQuery* propertySouTarQuery = new CObjectPropertySourcesTargetsResultVisitCallbackQuery(mOntRevData->getOntologyRevision()->getOntology(),calcConfig,indi,role,false,true); |
| 278 |
mJNICommandProcessor->calculateOntologyQuery(propertySouTarQuery); |
| 279 |
CQueryResult* result = propertySouTarQuery->getQueryResult(); |
| 280 |
if (result) { |
| 281 |
propertySouTarQuery->callbackVisitingIndividuals(visitingCallback); |
| 282 |
} |
| 283 |
delete propertySouTarQuery; |
| 284 |
return result != nullptr; |
| 285 |
} |
| 286 |
return false; |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
}; // end namespace JNI |
| 295 |
|
| 296 |
}; // end namespace Interface |
| 297 |
|
| 298 |
}; // end namespace Control |
| 299 |
|
| 300 |
}; // end namespace Konclude |