| 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 "COWLlinkQtXMLCommandParser.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Parser { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
COWLlinkQtXMLCommandParser::COWLlinkQtXMLCommandParser(CConfiguration* config) : CLogIdentifier("::Konclude::Parser::OWLlinkQtCommandParser",this) { |
| 31 |
LOG(INFO,"::Konclude::Parser::OWLlinkQtCommandParser",logTr("OWLlink Parser initialized."),this); |
| 32 |
command = 0; |
| 33 |
recorder = 0; |
| 34 |
delegater = 0; |
| 35 |
|
| 36 |
mConfInversePropDirectSupport = true; |
| 37 |
if (config) { |
| 38 |
mConfInversePropDirectSupport = CConfigDataReader::readConfigBoolean(config,"Konclude.OWLlink.DirectInversePropertiesQuerySupport",true); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
COWLlinkQtXMLCommandParser::~COWLlinkQtXMLCommandParser() { |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
bool COWLlinkQtXMLCommandParser::realizeCommand(CParseOWLlinkCommandsCommand *parseCommand, CCommandDelegater *commandDelegater) { |
| 50 |
delegater = commandDelegater; |
| 51 |
command = parseCommand; |
| 52 |
if (command) { |
| 53 |
recorder = command->getRecorder(); |
| 54 |
} |
| 55 |
CStartProcessCommandRecord::makeRecord(recorder,getLogDomain(),command); |
| 56 |
QByteArray *byteArray = command->getByteArray(); |
| 57 |
bool success = parse(*byteArray); |
| 58 |
CStopProcessCommandRecord::makeRecord(recorder,getLogDomain(),command); |
| 59 |
CFinishProcessCommandRecord::makeRecord(recorder,getLogDomain(),command); |
| 60 |
return success; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
bool COWLlinkQtXMLCommandParser::parse(const QByteArray &content) { |
| 65 |
bool successfullParsed = true; |
| 66 |
|
| 67 |
|
| 68 |
QDomDocument document; |
| 69 |
|
| 70 |
document.setContent(content,true); |
| 71 |
|
| 72 |
QDomElement documentElement(document.documentElement()); |
| 73 |
|
| 74 |
successfullParsed = parse(&documentElement); |
| 75 |
|
| 76 |
return successfullParsed; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
bool COWLlinkQtXMLCommandParser::parse(QDomElement *node) { |
| 81 |
bool successfullParsed = true; |
| 82 |
|
| 83 |
QDomElement documentElement(*node); |
| 84 |
|
| 85 |
QString docElemName = documentElement.tagName(); |
| 86 |
if (docElemName == "ox:RequestMessage" || docElemName == "RequestMessage") { |
| 87 |
LOG(INFO,getLogDomain(),logTr("Found OWLlink-Request Node."),this); |
| 88 |
parseOWLlinkRequestNode(&documentElement); |
| 89 |
} else { |
| 90 |
successfullParsed = false; |
| 91 |
CNotSupportedNodeErrorRecord::makeRecord(docElemName,recorder,getLogDomain(),command); |
| 92 |
} |
| 93 |
|
| 94 |
return successfullParsed; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
void COWLlinkQtXMLCommandParser::parseOWLlinkRequestNode(QDomElement *requestNode) { |
| 101 |
QDomElement node = requestNode->firstChildElement(); |
| 102 |
|
| 103 |
CPreconditionCommand *lastPreComm = 0; |
| 104 |
|
| 105 |
QLinkedList<CPreconditionCommand *> prevCalcPreCommList; |
| 106 |
|
| 107 |
while (!node.isNull()) { |
| 108 |
// build for each node an expression |
| 109 |
|
| 110 |
CPreconditionCommand *preComm; |
| 111 |
|
| 112 |
QString namespaceString = node.namespaceURI(); |
| 113 |
QString docElemName = node.localName(); |
| 114 |
bool inversePropertiesDirectQuerySupport = false; |
| 115 |
|
| 116 |
if (docElemName.isEmpty()) { |
| 117 |
docElemName = node.tagName(); |
| 118 |
} |
| 119 |
|
| 120 |
if (namespaceString.isEmpty() || namespaceString == "http://www.owllink.org/owllink-xml#" || namespaceString == "http://www.owllink.org/owllink#" || namespaceString == "http://www.owllink.org/ext/retraction#") { |
| 121 |
|
| 122 |
|
| 123 |
if (docElemName == "ImmediatelyExit") { |
| 124 |
QCoreApplication::exit(); |
| 125 |
} else if (docElemName == "ox:GetDescription" || docElemName == "GetDescription") { |
| 126 |
preComm = parseGetDescriptionNode(&node); |
| 127 |
} else if (docElemName == "ox:CreateKB" || docElemName == "CreateKB") { |
| 128 |
preComm = parseCreateKnowledgeBaseNode(&node); |
| 129 |
} else if (docElemName == "ox:InsertResponseComment" || docElemName == "InsertResponseComment") { |
| 130 |
preComm = parseInsertResponseCommentNode(&node); |
| 131 |
} else if (docElemName == "ox:Tell" || docElemName == "Tell") { |
| 132 |
preComm = parseTellKnowledgeBaseNode(&node); |
| 133 |
} else if (docElemName == "rec:Retract" || docElemName == "Retract") { |
| 134 |
preComm = parseRectractKnowledgeBaseNode(&node); |
| 135 |
} else if (docElemName == "ox:LoadKRSSTestConcepts" || docElemName == "LoadKRSSTestConcepts") { |
| 136 |
preComm = parseLoadKnowledgeBaseKRSSTestConceptNode(&node); |
| 137 |
} else if (docElemName == "ox:LoadOntology" || docElemName == "LoadOntology") { |
| 138 |
preComm = parseLoadKnowledgeBaseOntologyNode(&node); |
| 139 |
} else if (docElemName == "ox:LoadOntologies" || docElemName == "LoadOntologies") { |
| 140 |
preComm = parseLoadKnowledgeBaseOntologyNode(&node); |
| 141 |
} else if (docElemName == "ox:SaveExtractedKB" || docElemName == "SaveExtractedKB") { |
| 142 |
preComm = parseSaveExtractedKnowledgeBaseNode(&node); |
| 143 |
} else if (docElemName == "ox:SaveExtractedOWLlinkTestCaseKB" || docElemName == "SaveExtractedOWLlinkTestCaseKB") { |
| 144 |
preComm = parseSaveExtractedOWLlinkTestCaseKnowledgeBaseNode(&node); |
| 145 |
} else if (docElemName == "ox:IsClassSatisfiable" || docElemName == "IsClassSatisfiable") { |
| 146 |
preComm = parseProcessQueryNode(&node); |
| 147 |
} else if (docElemName == "ox:AreClassesEquivalent" || docElemName == "AreClassesEquivalent") { |
| 148 |
preComm = parseProcessQueryNode(&node); |
| 149 |
} else if (docElemName == "ox:AreClassesDisjoint" || docElemName == "AreClassesDisjoint") { |
| 150 |
preComm = parseProcessQueryNode(&node); |
| 151 |
} else if (docElemName == "ox:IsClassSubsumedBy" || docElemName == "IsClassSubsumedBy") { |
| 152 |
preComm = parseProcessQueryNode(&node); |
| 153 |
} else if (docElemName == "ox:IsInstanceOf" || docElemName == "IsInstanceOf") { |
| 154 |
preComm = parseProcessQueryNode(&node); |
| 155 |
} else if (docElemName == "ox:GetFlattenedTypes" || docElemName == "GetFlattenedTypes") { |
| 156 |
preComm = parseProcessQueryNode(&node); |
| 157 |
} else if (docElemName == "ox:GetFlattenedInstances" || docElemName == "GetFlattenedInstances") { |
| 158 |
preComm = parseProcessQueryNode(&node); |
| 159 |
} else if (docElemName == "ox:GetTypes" || docElemName == "GetTypes") { |
| 160 |
preComm = parseProcessQueryNode(&node); |
| 161 |
} else if (docElemName == "ox:GetSameIndividuals" || docElemName == "GetSameIndividuals") { |
| 162 |
preComm = parseProcessQueryNode(&node); |
| 163 |
} else if (docElemName == "ox:GetInstances" || docElemName == "GetInstances") { |
| 164 |
preComm = parseProcessQueryNode(&node); |
| 165 |
} else if (docElemName == "ox:GetObjectPropertyTargets" || docElemName == "GetObjectPropertyTargets") { |
| 166 |
inversePropertiesDirectQuerySupport = mConfInversePropDirectSupport; |
| 167 |
preComm = parseProcessQueryNode(&node); |
| 168 |
} else if (docElemName == "ox:GetFlattenedObjectPropertyTargets" || docElemName == "GetFlattenedObjectPropertyTargets") { |
| 169 |
inversePropertiesDirectQuerySupport = mConfInversePropDirectSupport; |
| 170 |
preComm = parseProcessQueryNode(&node); |
| 171 |
} else if (docElemName == "ox:GetObjectPropertySources" || docElemName == "GetObjectPropertySources") { |
| 172 |
inversePropertiesDirectQuerySupport = mConfInversePropDirectSupport; |
| 173 |
preComm = parseProcessQueryNode(&node); |
| 174 |
} else if (docElemName == "ox:GetFlattenedObjectPropertySources" || docElemName == "GetFlattenedObjectPropertySources") { |
| 175 |
inversePropertiesDirectQuerySupport = mConfInversePropDirectSupport; |
| 176 |
preComm = parseProcessQueryNode(&node); |
| 177 |
} else if (docElemName == "ox:GetSubClasses" || docElemName == "GetSubClasses") { |
| 178 |
preComm = parseProcessQueryNode(&node); |
| 179 |
} else if (docElemName == "ox:GetSuperClasses" || docElemName == "GetSuperClasses") { |
| 180 |
preComm = parseProcessQueryNode(&node); |
| 181 |
} else if (docElemName == "ox:GetEquivalentClasses" || docElemName == "GetEquivalentClasses") { |
| 182 |
preComm = parseProcessQueryNode(&node); |
| 183 |
} else if (docElemName == "ox:IsEntailed" || docElemName == "IsEntailed") { |
| 184 |
preComm = parseProcessQueryNode(&node); |
| 185 |
|
| 186 |
} else if (docElemName == "ox:GetObjectPropertiesOfSource" || docElemName == "GetObjectPropertiesOfSource") { |
| 187 |
preComm = parseProcessQueryNode(&node); |
| 188 |
} else if (docElemName == "ox:GetObjectPropertiesOfTarget" || docElemName == "GetObjectPropertiesOfTarget") { |
| 189 |
preComm = parseProcessQueryNode(&node); |
| 190 |
} else if (docElemName == "ox:GetObjectPropertiesBetween" || docElemName == "GetObjectPropertiesBetween") { |
| 191 |
preComm = parseProcessQueryNode(&node); |
| 192 |
|
| 193 |
|
| 194 |
} else if (docElemName == "ox:GetSubObjectProperties" || docElemName == "GetSubObjectProperties") { |
| 195 |
preComm = parseProcessQueryNode(&node); |
| 196 |
} else if (docElemName == "ox:GetSuperObjectProperties" || docElemName == "GetSuperObjectProperties") { |
| 197 |
preComm = parseProcessQueryNode(&node); |
| 198 |
} else if (docElemName == "ox:GetEquivalentObjectProperties" || docElemName == "GetEquivalentObjectProperties") { |
| 199 |
preComm = parseProcessQueryNode(&node); |
| 200 |
} else if (docElemName == "ox:GetSubObjectPropertyHierarchy" || docElemName == "GetSubObjectPropertyHierarchy") { |
| 201 |
preComm = parseProcessQueryNode(&node); |
| 202 |
} else if (docElemName == "ox:IsObjectPropertySatisfiable" || docElemName == "IsObjectPropertySatisfiable") { |
| 203 |
preComm = parseProcessQueryNode(&node); |
| 204 |
|
| 205 |
} else if (docElemName == "ox:GetSubDataProperties" || docElemName == "GetSubDataProperties") { |
| 206 |
preComm = parseProcessQueryNode(&node); |
| 207 |
} else if (docElemName == "ox:GetSuperDataProperties" || docElemName == "GetSuperDataProperties") { |
| 208 |
preComm = parseProcessQueryNode(&node); |
| 209 |
} else if (docElemName == "ox:GetEquivalentDataProperties" || docElemName == "GetEquivalentDataProperties") { |
| 210 |
preComm = parseProcessQueryNode(&node); |
| 211 |
} else if (docElemName == "ox:GetSubDataPropertyHierarchy" || docElemName == "GetSubDataPropertyHierarchy") { |
| 212 |
preComm = parseProcessQueryNode(&node); |
| 213 |
} else if (docElemName == "ox:IsDataPropertySatisfiable" || docElemName == "IsDataPropertySatisfiable") { |
| 214 |
preComm = parseProcessQueryNode(&node); |
| 215 |
|
| 216 |
} else if (docElemName == "ox:GetNondeterministicIndividuals" || docElemName == "GetNondeterministicIndividuals") { |
| 217 |
preComm = parseProcessQueryNode(&node); |
| 218 |
} else if (docElemName == "ox:GetDeterministicIndividuals" || docElemName == "GetDeterministicIndividuals") { |
| 219 |
preComm = parseProcessQueryNode(&node); |
| 220 |
} else if (docElemName == "ox:GetNondeterministicClassAssertions" || docElemName == "GetNondeterministicClassAssertions" || docElemName == "ox:GetPossibleClassAssertions" || docElemName == "GetPossibleClassAssertions") { |
| 221 |
preComm = parseProcessQueryNode(&node); |
| 222 |
} else if (docElemName == "ox:GetDeterministicClassAssertions" || docElemName == "GetDeterministicClassAssertions" || docElemName == "ox:GetKnownClassAssertions" || docElemName == "GetKnownClassAssertions") { |
| 223 |
preComm = parseProcessQueryNode(&node); |
| 224 |
|
| 225 |
} else if (docElemName == "ox:GetSubClassHierarchy" || docElemName == "GetSubClassHierarchy") { |
| 226 |
preComm = parseGetSubClassHierarchyNode(&node); |
| 227 |
} else if (docElemName == "ox:IsKBSatisfiable" || docElemName == "IsKBSatisfiable") { |
| 228 |
preComm = parseIsConsistentNode(&node); |
| 229 |
} else if (docElemName == "ox:ReleaseKB" || docElemName == "ReleaseKB") { |
| 230 |
preComm = parseReleaseKnowledgeBaseNode(&node); |
| 231 |
} else if (docElemName == "ox:GetKBLanguage" || docElemName == "GetKBLanguage") { |
| 232 |
preComm = parseGetKnowledgeBaseLanguageNode(&node); |
| 233 |
} else if (docElemName == "ox:GetAllClasses" || docElemName == "GetAllClasses") { |
| 234 |
preComm = parseGetKnowledgeBaseClassEntitiesNode(&node); |
| 235 |
} else if (docElemName == "ox:GetAllObjectProperties" || docElemName == "GetAllObjectProperties") { |
| 236 |
preComm = parseGetKnowledgeBaseObjectPropertyEntitiesNode(&node); |
| 237 |
} else if (docElemName == "ox:GetAllIndividuals" || docElemName == "GetAllIndividuals") { |
| 238 |
preComm = parseGetKnowledgeBaseIndividualEntitiesNode(&node); |
| 239 |
} else if (docElemName == "ox:Classify" || docElemName == "Classify") { |
| 240 |
preComm = parseKnowledgeBaseClassifyNode(&node); |
| 241 |
} else if (docElemName == "ox:Realize" || docElemName == "Realize" || docElemName == "ox:Realise" || docElemName == "Realise") { |
| 242 |
preComm = parseKnowledgeBaseRealizeNode(&node); |
| 243 |
} else if (docElemName == "ox:TestTestsuite" || docElemName == "TestTestsuite") { |
| 244 |
preComm = parseTestTestsuiteNode(&node); |
| 245 |
} else if (docElemName == "ox:EvaluateTestsuite" || docElemName == "EvaluateTestsuite") { |
| 246 |
preComm = parseEvaluateTestsuiteNode(&node); |
| 247 |
} else if (docElemName == "ox:GetSetting" || docElemName == "GetSetting") { |
| 248 |
preComm = parseGetSettingNode(&node); |
| 249 |
} else if (docElemName == "ox:GetSettings" || docElemName == "GetSettings") { |
| 250 |
preComm = parseGetSettingsNode(&node); |
| 251 |
} else if (docElemName == "ox:Set" || docElemName == "Set" || docElemName == "ox:SetSetting" || docElemName == "SetSetting") { |
| 252 |
preComm = parseSetSettingNode(&node); |
| 253 |
} else { |
| 254 |
CNotSupportedNodeErrorRecord::makeRecord(docElemName,recorder,getLogDomain(),command); |
| 255 |
preComm = new CSkipUnsupportedCommandCommand(docElemName); |
| 256 |
} |
| 257 |
|
| 258 |
} else { |
| 259 |
QString namespaceNodeName = docElemName; |
| 260 |
if (!namespaceString.isEmpty()) { |
| 261 |
namespaceNodeName = namespaceString+":"+docElemName; |
| 262 |
} |
| 263 |
CNotSupportedNodeErrorRecord::makeRecord(namespaceNodeName,recorder,getLogDomain(),command); |
| 264 |
preComm = new CSkipUnsupportedCommandCommand(namespaceNodeName); |
| 265 |
} |
| 266 |
|
| 267 |
if (preComm) { |
| 268 |
|
| 269 |
CKnowledgeBaseQueryCommand *queryCommand = dynamic_cast<CKnowledgeBaseQueryCommand *>(preComm); |
| 270 |
if (queryCommand) { |
| 271 |
parseQueryExtensions(&node,queryCommand,inversePropertiesDirectQuerySupport); |
| 272 |
|
| 273 |
// build default structure for query commands |
| 274 |
CBuildQueryCommand *buildCommand = 0; |
| 275 |
CCalculateQueryCommand *calcCommand = 0; |
| 276 |
|
| 277 |
buildCommand = queryCommand->getBuildQueryCommand(); |
| 278 |
if (!buildCommand) { |
| 279 |
// generate a build query subcommand |
| 280 |
buildCommand = new CBuildQueryCommand(0,queryCommand); |
| 281 |
queryCommand->setBuildQueryCommand(buildCommand); |
| 282 |
} |
| 283 |
calcCommand = queryCommand->getCalculateQueryCommand(); |
| 284 |
if (!calcCommand) { |
| 285 |
calcCommand = new CCalculateQueryCommand(buildCommand,queryCommand); |
| 286 |
queryCommand->setCalculateQueryCommand(calcCommand); |
| 287 |
} |
| 288 |
prevCalcPreCommList.append(queryCommand); |
| 289 |
} else { |
| 290 |
foreach (CPreconditionCommand *calcPreComm, prevCalcPreCommList) { |
| 291 |
if (calcPreComm != lastPreComm) { |
| 292 |
preComm->addCommandPrecondition(new CCommandProcessedPrecondition(calcPreComm)); |
| 293 |
} |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
if (lastPreComm) { |
| 299 |
preComm->addCommandPrecondition(new CCommandProcessedPrecondition(lastPreComm)); |
| 300 |
} |
| 301 |
if (command) { |
| 302 |
command->makeToSubCommand(preComm); |
| 303 |
} |
| 304 |
if (delegater) { |
| 305 |
delegater->delegateCommand(preComm); |
| 306 |
} |
| 307 |
|
| 308 |
lastPreComm = preComm; |
| 309 |
|
| 310 |
|
| 311 |
if (queryCommand) { |
| 312 |
if (queryCommand->getBuildQueryCommand()) { |
| 313 |
// because of revision management, the system has not to wait until the calculation of a query has finished to continue |
| 314 |
// with the followed commands |
| 315 |
lastPreComm = queryCommand->getBuildQueryCommand(); |
| 316 |
} |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
preComm = 0; |
| 321 |
|
| 322 |
node = node.nextSiblingElement(); |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
CGetDescriptionCommand *COWLlinkQtXMLCommandParser::parseGetDescriptionNode(QDomElement *descriptionNode) { |
| 329 |
return new CGetDescriptionCommand(); |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
CInsertResponseCommentCommand *COWLlinkQtXMLCommandParser::parseInsertResponseCommentNode(QDomElement *node) { |
| 334 |
QString commentString; |
| 335 |
commentString = node->attribute(QString("commentText")); |
| 336 |
return new CInsertResponseCommentCommand(commentString); |
| 337 |
} |
| 338 |
|
| 339 |
CCreateKnowledgeBaseCommand *COWLlinkQtXMLCommandParser::parseCreateKnowledgeBaseNode(QDomElement *node) { |
| 340 |
QString kbName; |
| 341 |
bool hasKBName = true; |
| 342 |
if (!node->hasAttribute(QString("kb"))) { |
| 343 |
hasKBName = false; |
| 344 |
} else { |
| 345 |
kbName = node->attribute(QString("kb")); |
| 346 |
} |
| 347 |
CCreateKnowledgeBaseCommand* cKCommand = new CCreateKnowledgeBaseCommand(kbName); |
| 348 |
|
| 349 |
QDomElement childNode = node->firstChildElement("Prefix"); |
| 350 |
while (!childNode.isNull()) { |
| 351 |
QString name = childNode.attribute("name"); |
| 352 |
QString fullIRI = childNode.attribute("fullIRI"); |
| 353 |
if (!name.isEmpty() && !fullIRI.isEmpty()) { |
| 354 |
CNamePrefix* namePrefix = new CNamePrefix(name,fullIRI); |
| 355 |
cKCommand->addNamePrefix(namePrefix); |
| 356 |
} |
| 357 |
childNode = childNode.nextSiblingElement("Prefix"); |
| 358 |
} |
| 359 |
|
| 360 |
return cKCommand; |
| 361 |
} |
| 362 |
|
| 363 |
CReleaseKnowledgeBaseCommand *COWLlinkQtXMLCommandParser::parseReleaseKnowledgeBaseNode(QDomElement *node) { |
| 364 |
QString kbName; |
| 365 |
kbName = node->attribute(QString("kb")); |
| 366 |
return new CReleaseKnowledgeBaseCommand(kbName); |
| 367 |
} |
| 368 |
|
| 369 |
CClassifyQueryCommand* COWLlinkQtXMLCommandParser::parseKnowledgeBaseClassifyNode(QDomElement *node) { |
| 370 |
QString kbName = node->attribute(QString("kb")); |
| 371 |
return new CClassifyQueryCommand(kbName); |
| 372 |
} |
| 373 |
|
| 374 |
CRealizeQueryCommand* COWLlinkQtXMLCommandParser::parseKnowledgeBaseRealizeNode(QDomElement *node) { |
| 375 |
QString kbName = node->attribute(QString("kb")); |
| 376 |
return new CRealizeQueryCommand(kbName); |
| 377 |
} |
| 378 |
|
| 379 |
CParseTestsuiteXMLNodeCommand *COWLlinkQtXMLCommandParser::parseTestTestsuiteNode(QDomElement *node) { |
| 380 |
CParseTestsuiteXMLNodeCommand *parseTestsuiteComm = new CParseTestsuiteXMLNodeCommand(*node); |
| 381 |
if (command) { |
| 382 |
QString sourcePath = command->getSourcePath(); |
| 383 |
parseTestsuiteComm->setSourcePath(sourcePath); |
| 384 |
} |
| 385 |
return parseTestsuiteComm; |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
CGetKnowledgeBaseLanguageCommand *COWLlinkQtXMLCommandParser::parseGetKnowledgeBaseLanguageNode(QDomElement *node) { |
| 390 |
QString kbName; |
| 391 |
kbName = node->attribute(QString("kb")); |
| 392 |
return new CGetKnowledgeBaseLanguageCommand(kbName); |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
CGetKnowledgeBaseClassEntitiesCommand *COWLlinkQtXMLCommandParser::parseGetKnowledgeBaseClassEntitiesNode(QDomElement *node) { |
| 397 |
QString kbName; |
| 398 |
kbName = node->attribute(QString("kb")); |
| 399 |
return new CGetKnowledgeBaseClassEntitiesCommand(kbName); |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
CGetKnowledgeBaseObjectPropertyEntitiesCommand *COWLlinkQtXMLCommandParser::parseGetKnowledgeBaseObjectPropertyEntitiesNode(QDomElement *node) { |
| 404 |
QString kbName; |
| 405 |
kbName = node->attribute(QString("kb")); |
| 406 |
return new CGetKnowledgeBaseObjectPropertyEntitiesCommand(kbName); |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
CGetKnowledgeBaseNamedIndividualEntitiesCommand *COWLlinkQtXMLCommandParser::parseGetKnowledgeBaseIndividualEntitiesNode(QDomElement *node) { |
| 411 |
QString kbName; |
| 412 |
kbName = node->attribute(QString("kb")); |
| 413 |
return new CGetKnowledgeBaseNamedIndividualEntitiesCommand(kbName); |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
CEvaluateTestsuiteCommand* COWLlinkQtXMLCommandParser::parseEvaluateTestsuiteNode(QDomElement* node) { |
| 419 |
CReasonerEvaluationProgram* evalProg = new CReasonerEvaluationProgram(); |
| 420 |
QString testName = node->attribute("name"); |
| 421 |
QString configFile = node->attribute("configFile"); |
| 422 |
QString inputDir = node->attribute("inputDirectory"); |
| 423 |
QString outputDir = node->attribute("outputDirectory"); |
| 424 |
QString analysingDir = node->attribute("analysingDirectory"); |
| 425 |
evalProg->setConfigFileString(configFile); |
| 426 |
evalProg->setInputDirectoryString(inputDir); |
| 427 |
evalProg->setOutputDirectoryString(outputDir); |
| 428 |
evalProg->setAnalyserDirectoryString(analysingDir); |
| 429 |
evalProg->setProgramName(testName); |
| 430 |
|
| 431 |
QDomElement reasonerChildElm = node->firstChildElement("EvaluateReasoner"); |
| 432 |
while (!reasonerChildElm.isNull()) { |
| 433 |
QString initReasonerString = reasonerChildElm.attribute("initFile"); |
| 434 |
evalProg->appendReasonerString(initReasonerString); |
| 435 |
reasonerChildElm = reasonerChildElm.nextSiblingElement("EvaluateReasoner"); |
| 436 |
} |
| 437 |
|
| 438 |
QDomElement analyseChildElm = node->firstChildElement("Analysing"); |
| 439 |
while (!analyseChildElm.isNull()) { |
| 440 |
QString analyseString = analyseChildElm.attribute("analyseName"); |
| 441 |
evalProg->appendAnalyserString(analyseString); |
| 442 |
analyseChildElm = analyseChildElm.nextSiblingElement("Analysing"); |
| 443 |
} |
| 444 |
|
| 445 |
QDomElement filteringChildElm = node->firstChildElement("Filtering"); |
| 446 |
while (!filteringChildElm.isNull()) { |
| 447 |
QString filterFileString = filteringChildElm.attribute("filterFile"); |
| 448 |
evalProg->appendFilterString(filterFileString); |
| 449 |
filteringChildElm = filteringChildElm.nextSiblingElement("Filtering"); |
| 450 |
} |
| 451 |
|
| 452 |
CEvaluateTestsuiteCommand* evaluateTestsuiteComm = new CEvaluateTestsuiteCommand(testName,evalProg); |
| 453 |
return evaluateTestsuiteComm; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
CTellKnowledgeBaseOWL2XMLNodeCommand *COWLlinkQtXMLCommandParser::parseTellKnowledgeBaseNode(QDomElement *node) { |
| 458 |
QString kbName; |
| 459 |
kbName = node->attribute(QString("kb")); |
| 460 |
return new CTellKnowledgeBaseOWL2XMLNodeCommand(kbName,*node); |
| 461 |
} |
| 462 |
|
| 463 |
CTellKnowledgeBaseOWL2XMLNodeCommand *COWLlinkQtXMLCommandParser::parseRectractKnowledgeBaseNode(QDomElement *node) { |
| 464 |
QString kbName; |
| 465 |
kbName = node->attribute(QString("kb")); |
| 466 |
return new CTellKnowledgeBaseOWL2XMLNodeCommand(kbName,*node); |
| 467 |
} |
| 468 |
|
| 469 |
CLoadKnowledgeBaseKRSSTestConceptCommand *COWLlinkQtXMLCommandParser::parseLoadKnowledgeBaseKRSSTestConceptNode(QDomElement *node) { |
| 470 |
QString kbName = node->attribute(QString("kb")); |
| 471 |
QString defNames = node->attribute(QString("testConceptNames")); |
| 472 |
QString loadIRI = node->attribute(QString("loadIRI")); |
| 473 |
return new CLoadKnowledgeBaseKRSSTestConceptCommand(kbName,loadIRI,defNames); |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
CLoadKnowledgeBaseOWLAutoOntologyCommand *COWLlinkQtXMLCommandParser::parseLoadKnowledgeBaseOntologyNode(QDomElement *node) { |
| 478 |
QString kbName = node->attribute(QString("kb")); |
| 479 |
|
| 480 |
QStringList ontoIRIList; |
| 481 |
QDomElement childElm = node->firstChildElement("ontologyIRI"); |
| 482 |
while (!childElm.isNull()) { |
| 483 |
QString ontoIRIString = childElm.attribute("IRI"); |
| 484 |
ontoIRIList.append(ontoIRIString); |
| 485 |
childElm = childElm.nextSiblingElement("ontologyIRI"); |
| 486 |
} |
| 487 |
childElm = node->firstChildElement("OntologyIRI"); |
| 488 |
while (!childElm.isNull()) { |
| 489 |
QString ontoIRIString = childElm.attribute("IRI"); |
| 490 |
ontoIRIList.append(ontoIRIString); |
| 491 |
childElm = childElm.nextSiblingElement("OntologyIRI"); |
| 492 |
} |
| 493 |
return new CLoadKnowledgeBaseOWLAutoOntologyCommand(kbName,ontoIRIList); |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
CSaveOWL2XMLExtractedKnowledgeBaseCommand *COWLlinkQtXMLCommandParser::parseSaveExtractedKnowledgeBaseNode(QDomElement *node) { |
| 498 |
QString kbName = node->attribute(QString("kb")); |
| 499 |
QStringList entityNames; |
| 500 |
QDomElement childNode = node->firstChildElement(); |
| 501 |
while (!childNode.isNull()) { |
| 502 |
QString entityName = childNode.attribute("IRI"); |
| 503 |
if (!entityName.isEmpty()) { |
| 504 |
entityNames.append(entityName); |
| 505 |
} |
| 506 |
childNode = childNode.nextSiblingElement(); |
| 507 |
} |
| 508 |
QString saveIRI = node->attribute(QString("saveIRI")); |
| 509 |
return new CSaveOWL2XMLExtractedKnowledgeBaseCommand(kbName,saveIRI,entityNames); |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
CSaveOWLlinkOWL2XMLSatisfiableTestExtractedKnowledgeBaseCommand* COWLlinkQtXMLCommandParser::parseSaveExtractedOWLlinkTestCaseKnowledgeBaseNode(QDomElement *node) { |
| 514 |
QString kbName = node->attribute(QString("kb")); |
| 515 |
QStringList entityNames; |
| 516 |
QDomElement childNode = node->firstChildElement(); |
| 517 |
while (!childNode.isNull()) { |
| 518 |
QString entityName = childNode.attribute("IRI"); |
| 519 |
if (!entityName.isEmpty()) { |
| 520 |
entityNames.append(entityName); |
| 521 |
} |
| 522 |
childNode = childNode.nextSiblingElement(); |
| 523 |
} |
| 524 |
QString saveIRI = node->attribute(QString("saveIRI")); |
| 525 |
QString testKBName = node->attribute(QString("testKBName")); |
| 526 |
return new CSaveOWLlinkOWL2XMLSatisfiableTestExtractedKnowledgeBaseCommand(kbName,saveIRI,entityNames,testKBName); |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
CProcessQueryOWL2XMLNodeCommand *COWLlinkQtXMLCommandParser::parseProcessQueryNode(QDomElement *node) { |
| 531 |
QString kbName; |
| 532 |
kbName = node->attribute(QString("kb")); |
| 533 |
return new CProcessQueryOWL2XMLNodeCommand(kbName,*node); |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
CIsConsistentQueryOWL2XMLNodeCommand* COWLlinkQtXMLCommandParser::parseIsConsistentNode(QDomElement *node) { |
| 538 |
QString kbName; |
| 539 |
kbName = node->attribute(QString("kb")); |
| 540 |
return new CIsConsistentQueryOWL2XMLNodeCommand(kbName,*node); |
| 541 |
} |
| 542 |
|
| 543 |
CGetSubClassHierarchyQueryOWL2XMLNodeCommand *COWLlinkQtXMLCommandParser::parseGetSubClassHierarchyNode(QDomElement *node) { |
| 544 |
QString kbName; |
| 545 |
kbName = node->attribute(QString("kb")); |
| 546 |
return new CGetSubClassHierarchyQueryOWL2XMLNodeCommand(kbName,*node); |
| 547 |
} |
| 548 |
|
| 549 |
void COWLlinkQtXMLCommandParser::parseQueryExtensions(QDomElement *node, CKnowledgeBaseQueryCommand *queryCommand, bool inversePropDirectSupport) { |
| 550 |
|
| 551 |
|
| 552 |
CTestExtendedCalculateQueryCommand *testExtCalcQueryComm = dynamic_cast<CTestExtendedCalculateQueryCommand *>(queryCommand->getCalculateQueryCommand()); |
| 553 |
if (node->hasAttribute("timing")) { |
| 554 |
if (CStringPrimitiveConverter::convertStringToBoolean(node->attribute("result"),true)) { |
| 555 |
if (!testExtCalcQueryComm) { |
| 556 |
CBuildQueryCommand *buildCommand = queryCommand->getBuildQueryCommand(); |
| 557 |
if (!buildCommand) { |
| 558 |
// generate a build query subcommand |
| 559 |
buildCommand = new CBuildQueryCommand(0,queryCommand); |
| 560 |
queryCommand->setBuildQueryCommand(buildCommand); |
| 561 |
} |
| 562 |
testExtCalcQueryComm = new CTestExtendedCalculateQueryCommand(buildCommand,queryCommand); |
| 563 |
queryCommand->setCalculateQueryCommand(testExtCalcQueryComm); |
| 564 |
} |
| 565 |
testExtCalcQueryComm->setTimingReportLevel(1); |
| 566 |
} |
| 567 |
} |
| 568 |
if (requiresComplexQuery(node,inversePropDirectSupport)) { |
| 569 |
queryCommand->setQueryComplexity(true); |
| 570 |
} |
| 571 |
|
| 572 |
parseQueryExpectedResult(node,queryCommand); |
| 573 |
} |
| 574 |
|
| 575 |
void COWLlinkQtXMLCommandParser::parseQueryExpectedResult(QDomElement *node, CKnowledgeBaseQueryCommand *queryCommand) { |
| 576 |
CTestExtendedCalculateQueryCommand *testExtCalcQueryComm = dynamic_cast<CTestExtendedCalculateQueryCommand *>(queryCommand->getCalculateQueryCommand()); |
| 577 |
QDomElement expResNode = node->firstChildElement("ExpectedResult"); |
| 578 |
if (!expResNode.isNull()) { |
| 579 |
if (!testExtCalcQueryComm) { |
| 580 |
CBuildQueryCommand *buildCommand = queryCommand->getBuildQueryCommand(); |
| 581 |
if (!buildCommand) { |
| 582 |
// generate a build query subcommand |
| 583 |
buildCommand = new CBuildQueryCommand(0,queryCommand); |
| 584 |
queryCommand->setBuildQueryCommand(buildCommand); |
| 585 |
} |
| 586 |
testExtCalcQueryComm = new CTestExtendedCalculateQueryCommand(buildCommand,queryCommand); |
| 587 |
queryCommand->setCalculateQueryCommand(testExtCalcQueryComm); |
| 588 |
} |
| 589 |
CQueryResult *expectedResult = 0; |
| 590 |
expectedResult = parseQueryResult(&expResNode); |
| 591 |
testExtCalcQueryComm->setExpectedQueryResult(expectedResult); |
| 592 |
} |
| 593 |
|
| 594 |
} |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
bool COWLlinkQtXMLCommandParser::requiresComplexQuery(QDomElement *node, bool inversePropDirectSupport) { |
| 599 |
bool reComplex = false; |
| 600 |
QDomElement childEl = node->firstChildElement(); |
| 601 |
while (!reComplex && !childEl.isNull()) { |
| 602 |
bool childComplex = true; |
| 603 |
QString elName = childEl.tagName(); |
| 604 |
if (elName == "Class" || elName == "owl:Class") { |
| 605 |
childComplex = false; |
| 606 |
} else if (elName == "NamedIndividual" || elName == "owl:NamedIndividual") { |
| 607 |
childComplex = false; |
| 608 |
} else if (elName == "ObjectProperty" || elName == "owl:ObjectProperty") { |
| 609 |
childComplex = false; |
| 610 |
} else if (elName == "DataProperty" || elName == "owl:DataProperty") { |
| 611 |
childComplex = false; |
| 612 |
} else if (elName == "ExpectedResult") { |
| 613 |
childComplex = false; |
| 614 |
} else if (inversePropDirectSupport && elName == "ObjectInverseOf" || elName == "owl:ObjectInverseOf") { |
| 615 |
if (!requiresComplexQuery(&childEl,inversePropDirectSupport)) { |
| 616 |
childComplex = false; |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
reComplex |= childComplex; |
| 621 |
|
| 622 |
childEl = childEl.nextSiblingElement(); |
| 623 |
} |
| 624 |
return reComplex; |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
CQueryResult *COWLlinkQtXMLCommandParser::parseQueryResult(QDomElement *resultNode) { |
| 631 |
COWLlinkQtXMLResultParser resultParser; |
| 632 |
QDomElement node = resultNode->firstChildElement(); |
| 633 |
CQueryResult *queryResult = 0; |
| 634 |
while (!node.isNull() && !queryResult) { |
| 635 |
QString docElemName = node.tagName(); |
| 636 |
if (docElemName == "ox:BooleanResponse" || docElemName == "BooleanResponse") { |
| 637 |
queryResult = resultParser.parseBooleanQueryResult(&node); |
| 638 |
} else if (docElemName == "ox:ClassHierarchy" || docElemName == "ClassHierarchy") { |
| 639 |
queryResult = resultParser.parseClassHierarchyResult(&node); |
| 640 |
} else { |
| 641 |
node = node.nextSiblingElement(); |
| 642 |
} |
| 643 |
|
| 644 |
} |
| 645 |
return queryResult; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
CGetConfigCommand *COWLlinkQtXMLCommandParser::parseGetSettingNode(QDomElement *node) { |
| 650 |
QString kbName = node->attribute(QString("kb"),""); |
| 651 |
QString propertyName = node->attribute(QString("key"),""); |
| 652 |
propertyName = getOWLLinkMappedConfigString(propertyName); |
| 653 |
CGetConfigCommand *confComm = 0; |
| 654 |
if (!kbName.isEmpty()) { |
| 655 |
confComm = new CGetKnowledgeBaseConfigCommand(propertyName,kbName); |
| 656 |
} else { |
| 657 |
confComm = new CGetConfigCommand(propertyName); |
| 658 |
} |
| 659 |
return confComm; |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
CGetSettingsCommand *COWLlinkQtXMLCommandParser::parseGetSettingsNode(QDomElement *node) { |
| 664 |
QString kbName = node->attribute(QString("kb"),""); |
| 665 |
CGetSettingsCommand *confComm = 0; |
| 666 |
if (!kbName.isEmpty()) { |
| 667 |
confComm = new CGetKnowledgeBaseSettingsCommand(kbName); |
| 668 |
} else { |
| 669 |
confComm = new CGetSettingsCommand(); |
| 670 |
} |
| 671 |
return confComm; |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
CSetConfigCommand *COWLlinkQtXMLCommandParser::parseSetSettingNode(QDomElement *node) { |
| 676 |
QString kbName = node->attribute(QString("kb"),""); |
| 677 |
QString propertyName = node->attribute(QString("key"),""); |
| 678 |
QString propertyValue = node->firstChildElement("Literal").text(); |
| 679 |
propertyName = getOWLLinkMappedConfigString(propertyName); |
| 680 |
CSetConfigCommand *confComm = 0; |
| 681 |
if (!kbName.isEmpty()) { |
| 682 |
confComm = new CSetKnowledgeBaseConfigCommand(propertyName,propertyValue,kbName); |
| 683 |
} else { |
| 684 |
confComm = new CSetConfigCommand(propertyName,propertyValue); |
| 685 |
} |
| 686 |
return confComm; |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
QString COWLlinkQtXMLCommandParser::getOWLLinkMappedConfigString(const QString &keyName) { |
| 691 |
if (keyName == "abbreviatesIRIs") { |
| 692 |
return QString("Konclude.OWLlink.AbbreviatedIRIs"); |
| 693 |
} |
| 694 |
return keyName; |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
}; // end namespace Parser |
| 699 |
|
| 700 |
}; // end namespace Konclude |