| 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 "COWLLinkRecordInterpreter.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Control { |
| 27 |
|
| 28 |
namespace Interface { |
| 29 |
|
| 30 |
namespace OWLlink { |
| 31 |
|
| 32 |
COWLLinkRecordInterpreter::COWLLinkRecordInterpreter(CCommandDelegater *commandDelegater, CConfiguration* config) |
| 33 |
: CCommandRecorder(),document("ResponseMessage") { |
| 34 |
delegater = commandDelegater; |
| 35 |
nextSeqNumber = 0; |
| 36 |
recNextSeqNumber = 0; |
| 37 |
|
| 38 |
owllinkNS = "http://www.owllink.org/owllink#"; |
| 39 |
owlNS = "http://www.w3.org/2002/07/owl#"; |
| 40 |
|
| 41 |
|
| 42 |
QDomProcessingInstruction procInstHeader = document.createProcessingInstruction("xml","version=\"1.0\" encoding=\"utf-8\""); |
| 43 |
document.appendChild(procInstHeader); |
| 44 |
rootNode = document.createElementNS(owllinkNS,"ResponseMessage"); |
| 45 |
//rootNode.setAttributeNS("xsi:schemaLocation","http://www.owllink.org/owllink# http://www.owllink.org/owllink-20091116.xsd"); |
| 46 |
//rootNode.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance","xsi:schemaLocation","http://www.owllink.org/owllink# http://www.owllink.org/owllink-20091116.xsd"); |
| 47 |
rootNode.setAttribute("xmlns:owl",owlNS); |
| 48 |
rootNode.setAttribute("xml:base",owlNS); |
| 49 |
rootNode.setAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema#"); |
| 50 |
document.appendChild(rootNode); |
| 51 |
|
| 52 |
mConfFileAppendSimpleStats = false; |
| 53 |
mStatFileString = "reasoning-statistics.txt"; |
| 54 |
mStatStringList.append("calculation-reasoning-time"); |
| 55 |
mStatStringList.append("task-process-change-count"); |
| 56 |
mStatStringList.append("calculation-memory-consumption"); |
| 57 |
mStatStringList.append("individual-node-switch-count"); |
| 58 |
mStatStringList.append("unsatisfiable-cache-used-count"); |
| 59 |
mStatStringList.append("created-successor-individual-node-count"); |
| 60 |
mStatVector.resize(mStatStringList.count()); |
| 61 |
mCalculatedWrongResult = false; |
| 62 |
mRespondQueryStatistics = true; |
| 63 |
mConfig = config; |
| 64 |
|
| 65 |
mConfExtendedErrorReporting = CConfigDataReader::readConfigBoolean(mConfig,"Konclude.OWLlink.ExtendedErrorReporting",false); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
COWLLinkRecordInterpreter::~COWLLinkRecordInterpreter() { |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
CCommandDelegater *COWLLinkRecordInterpreter::delegateCommand(CCommand *command) { |
| 74 |
seqSyncMutex.lock(); |
| 75 |
commandSequenceHash.insert(command,nextSeqNumber++); |
| 76 |
seqSyncMutex.unlock(); |
| 77 |
if (delegater) { |
| 78 |
delegater->delegateCommand(command); |
| 79 |
} |
| 80 |
return this; |
| 81 |
} |
| 82 |
|
| 83 |
bool COWLLinkRecordInterpreter::hasReasonerCalculatedWrongResult() { |
| 84 |
return mCalculatedWrongResult; |
| 85 |
} |
| 86 |
|
| 87 |
CCommandRecorder *COWLLinkRecordInterpreter::recordData(CCommandRecordData *recData) { |
| 88 |
CCommandRecorder::recordData(recData); |
| 89 |
if (dynamic_cast<CClosureProcessCommandRecord *>(recData)) { |
| 90 |
if (recData) { |
| 91 |
CCommand *command = recData->getCommand(); |
| 92 |
if (command) { |
| 93 |
|
| 94 |
if (commandSequenceHash.contains(command)) { |
| 95 |
|
| 96 |
QDomNode domEl; |
| 97 |
|
| 98 |
if (dynamic_cast<CGetDescriptionCommand *>(command)) { |
| 99 |
CGetDescriptionCommand *desCommand = dynamic_cast<CGetDescriptionCommand *>(command); |
| 100 |
if (desCommand) { |
| 101 |
if (command->getMaxErrorLevel() <= 0) { |
| 102 |
CConfigurationBase *config = desCommand->getConfiguration(); |
| 103 |
if (config) { |
| 104 |
domEl = document.createElement("Description"); |
| 105 |
domEl.toElement().setAttribute("name",config->getRelatedConfigChange("Konclude.Name")->getString()); |
| 106 |
|
| 107 |
QDomElement protVerNode = document.createElement("ProtocolVersion"); |
| 108 |
protVerNode.setAttribute("major",config->getRelatedConfigChange("Konclude.OWLlink.Version.Major")->getString()); |
| 109 |
protVerNode.setAttribute("minor",config->getRelatedConfigChange("Konclude.OWLlink.Version.Minor")->getString()); |
| 110 |
domEl.appendChild(protVerNode); |
| 111 |
|
| 112 |
QDomElement reasVerNode = document.createElement("ReasonerVersion"); |
| 113 |
reasVerNode.setAttribute("major",config->getRelatedConfigChange("Konclude.Version.Major")->getString()); |
| 114 |
reasVerNode.setAttribute("minor",config->getRelatedConfigChange("Konclude.Version.Minor")->getString()); |
| 115 |
reasVerNode.setAttribute("build",config->getRelatedConfigChange("Konclude.Version.Build")->getString()); |
| 116 |
domEl.appendChild(reasVerNode); |
| 117 |
|
| 118 |
|
| 119 |
domEl.appendChild(getOneOfStringConfigNode("selectedProfile","SROIQV(D)","SROIQV(D)","Property")); |
| 120 |
domEl.appendChild(getOneOfStringConfigNode("appliedSemantics","direct","direct","Property")); |
| 121 |
|
| 122 |
domEl.appendChild(getBooleanConfigNode("abbreviatesIRIs",config->getRelatedConfigChange("Konclude.OWLlink.AbbreviatedIRIs")->getString(),"Setting")); |
| 123 |
domEl.appendChild(getBooleanConfigNode("ignoresAnnotations","true","Property")); |
| 124 |
domEl.appendChild(getBooleanConfigNode("ignoresDeclarations","true","Property")); |
| 125 |
domEl.appendChild(getBooleanConfigNode("uniqueNameAssumption","false","Property")); |
| 126 |
|
| 127 |
|
| 128 |
QDomElement supDatatypesNode = document.createElement("Property"); |
| 129 |
supDatatypesNode.setAttribute("key","supportedDatatypes"); |
| 130 |
QDomElement supDatatypesListNode = document.createElement("List"); |
| 131 |
supDatatypesListNode.setAttribute("abbreviatedIRI","xsd:anyURI"); |
| 132 |
supDatatypesNode.appendChild(supDatatypesListNode); |
| 133 |
|
| 134 |
domEl.appendChild(supDatatypesNode); |
| 135 |
|
| 136 |
|
| 137 |
} |
| 138 |
} else { |
| 139 |
domEl = getErrorNode(recData); |
| 140 |
} |
| 141 |
} |
| 142 |
} else if (dynamic_cast<CCreateKnowledgeBaseCommand *>(command)) { |
| 143 |
CCreateKnowledgeBaseCommand *createKBCommand = dynamic_cast<CCreateKnowledgeBaseCommand *>(command); |
| 144 |
if (createKBCommand) { |
| 145 |
if (command->getMaxErrorLevel() <= 0) { |
| 146 |
domEl = document.createElement("KB"); |
| 147 |
domEl.toElement().setAttribute("kb",createKBCommand->getKnowledgeBaseName()); |
| 148 |
} else { |
| 149 |
domEl = getErrorNode(recData); |
| 150 |
} |
| 151 |
} |
| 152 |
} else if (dynamic_cast<CKnowledgeBaseProcessCommand *>(command)) { |
| 153 |
CKnowledgeBaseProcessCommand *kbProcessCommand = dynamic_cast<CKnowledgeBaseProcessCommand *>(command); |
| 154 |
if (kbProcessCommand) { |
| 155 |
if (command->getMaxErrorLevel() <= 0) { |
| 156 |
domEl = document.createElement("OK"); |
| 157 |
} else { |
| 158 |
domEl = getErrorNode(recData); |
| 159 |
} |
| 160 |
} |
| 161 |
} else if (dynamic_cast<CLoadKnowledgeBaseKRSSTestConceptCommand *>(command)) { |
| 162 |
CLoadKnowledgeBaseKRSSTestConceptCommand *loadCommand = dynamic_cast<CLoadKnowledgeBaseKRSSTestConceptCommand *>(command); |
| 163 |
if (loadCommand) { |
| 164 |
mStatLoadString = loadCommand->getLoadIRIString(); |
| 165 |
if (command->getMaxErrorLevel() <= 0) { |
| 166 |
domEl = document.createElement("OK"); |
| 167 |
} else { |
| 168 |
domEl = getErrorNode(recData); |
| 169 |
} |
| 170 |
} |
| 171 |
} else if (dynamic_cast<CSetConfigCommand *>(command)) { |
| 172 |
CSetConfigCommand *setConfigCommand = dynamic_cast<CSetConfigCommand *>(command); |
| 173 |
if (setConfigCommand) { |
| 174 |
if (command->getMaxErrorLevel() <= 0) { |
| 175 |
domEl = document.createElement("OK"); |
| 176 |
} else { |
| 177 |
domEl = getErrorNode(recData); |
| 178 |
} |
| 179 |
} |
| 180 |
} else if (dynamic_cast<CGetConfigCommand *>(command)) { |
| 181 |
CGetConfigCommand *getConfigCommand = dynamic_cast<CGetConfigCommand *>(command); |
| 182 |
if (getConfigCommand) { |
| 183 |
if (command->getMaxErrorLevel() <= 0) { |
| 184 |
QString configName = getConfigCommand->getConfigNameString(); |
| 185 |
CConfigData *configData = getConfigCommand->getConfigData(); |
| 186 |
if (configData->supportsBooleanConvertion()) { |
| 187 |
bool configVal = configData->getBoolean(); |
| 188 |
QString configValString("false"); |
| 189 |
if (configVal) { |
| 190 |
configValString = "true"; |
| 191 |
} |
| 192 |
domEl = getBooleanConfigNode(configName,configValString,"Setting"); |
| 193 |
} else if (configData->supportsIntegerConvertion()) { |
| 194 |
qint64 integer = configData->getInteger(); |
| 195 |
domEl = getIntegerConfigNode(configName,integer,"Setting"); |
| 196 |
} else if (configData->supportsStringConvertion()) { |
| 197 |
domEl = getStringConfigNode(configName,configData->getString(),"Setting"); |
| 198 |
} else { |
| 199 |
domEl = document.createElement("Error"); |
| 200 |
domEl.toElement().setAttribute("error",QString("Convertion from config value to string not possible.")); |
| 201 |
} |
| 202 |
} else { |
| 203 |
domEl = getErrorNode(recData); |
| 204 |
} |
| 205 |
} |
| 206 |
} else if (dynamic_cast<CGetSettingsCommand *>(command)) { |
| 207 |
CGetSettingsCommand *getConfigCommand = dynamic_cast<CGetSettingsCommand*>(command); |
| 208 |
if (getConfigCommand) { |
| 209 |
if (command->getMaxErrorLevel() <= 0) { |
| 210 |
domEl = document.createElement("Settings"); |
| 211 |
CConfigurationBase *configuration = getConfigCommand->getConfiguration(); |
| 212 |
CConfigurationGroup *configGroup = configuration->getConfigurationGroup(); |
| 213 |
qint64 configCount = configGroup->getConfigPropertyCount(); |
| 214 |
for (qint64 configIdx = 0; configIdx < configCount; ++configIdx) { |
| 215 |
CConfigDescription *configDes = configGroup->getConfigDescription(configIdx); |
| 216 |
QString configName = configDes->getConfigName(); |
| 217 |
QDomElement settEl; |
| 218 |
if (configName.startsWith("Konclude.") || configName.startsWith("Konclude.OWLlink.")) { |
| 219 |
CConfigData *configData = configuration->getRelatedConfigChange(configIdx,true); |
| 220 |
if (configData) { |
| 221 |
if (configData->supportsBooleanConvertion()) { |
| 222 |
bool configVal = configData->getBoolean(); |
| 223 |
QString configValString("false"); |
| 224 |
if (configVal) { |
| 225 |
configValString = "true"; |
| 226 |
} |
| 227 |
settEl = getBooleanConfigNode(configName,configValString,"Setting"); |
| 228 |
} else if (configData->supportsIntegerConvertion()) { |
| 229 |
qint64 integer = configData->getInteger(); |
| 230 |
settEl = getIntegerConfigNode(configName,integer,"Setting"); |
| 231 |
} else if (configData->supportsStringConvertion()) { |
| 232 |
settEl = getStringConfigNode(configName,configData->getString(),"Setting"); |
| 233 |
} |
| 234 |
} |
| 235 |
} |
| 236 |
if (!settEl.isNull()) { |
| 237 |
domEl.appendChild(settEl); |
| 238 |
} |
| 239 |
} |
| 240 |
} else { |
| 241 |
domEl = getErrorNode(recData); |
| 242 |
} |
| 243 |
} |
| 244 |
} else if (dynamic_cast<CInsertResponseCommentCommand *>(command)) { |
| 245 |
CInsertResponseCommentCommand *commentCommand = dynamic_cast<CInsertResponseCommentCommand *>(command); |
| 246 |
if (commentCommand) { |
| 247 |
if (command->getMaxErrorLevel() <= 0) { |
| 248 |
domEl = document.createComment(commentCommand->getResponseComment()); |
| 249 |
} else { |
| 250 |
domEl = getErrorNode(recData); |
| 251 |
} |
| 252 |
} |
| 253 |
} else if (dynamic_cast<CTellKnowledgeBaseCommand *>(command)) { |
| 254 |
CTellKnowledgeBaseCommand *tellKBCommand = dynamic_cast<CTellKnowledgeBaseCommand *>(command); |
| 255 |
if (tellKBCommand) { |
| 256 |
if (command->getMaxErrorLevel() <= 0) { |
| 257 |
domEl = document.createElement("OK"); |
| 258 |
} else { |
| 259 |
domEl = getErrorNode(recData); |
| 260 |
} |
| 261 |
} |
| 262 |
} else if (dynamic_cast<CLoadKnowledgeBaseCommand *>(command)) { |
| 263 |
CLoadKnowledgeBaseCommand *loadKBCommand = dynamic_cast<CLoadKnowledgeBaseCommand *>(command); |
| 264 |
if (loadKBCommand) { |
| 265 |
if (command->getMaxErrorLevel() <= 0) { |
| 266 |
domEl = document.createElement("OK"); |
| 267 |
} else { |
| 268 |
domEl = getErrorNode(recData); |
| 269 |
} |
| 270 |
} |
| 271 |
} else if (dynamic_cast<CGetKnowledgeBaseLanguageCommand *>(command)) { |
| 272 |
CGetKnowledgeBaseLanguageCommand *getKBLanguageCommand = dynamic_cast<CGetKnowledgeBaseLanguageCommand *>(command); |
| 273 |
if (getKBLanguageCommand) { |
| 274 |
if (command->getMaxErrorLevel() <= 0) { |
| 275 |
QDomElement langEl = document.createElement("StringResponse"); |
| 276 |
langEl.setAttribute("result",getKBLanguageCommand->getLanguageString()); |
| 277 |
domEl = langEl; |
| 278 |
} else { |
| 279 |
domEl = getErrorNode(recData); |
| 280 |
} |
| 281 |
} |
| 282 |
} else if (dynamic_cast<CGetKnowledgeBaseClassEntitiesCommand *>(command)) { |
| 283 |
CGetKnowledgeBaseClassEntitiesCommand *getClassEntitiesCommand = dynamic_cast<CGetKnowledgeBaseClassEntitiesCommand *>(command); |
| 284 |
if (getClassEntitiesCommand) { |
| 285 |
if (command->getMaxErrorLevel() <= 0) { |
| 286 |
CExtractedKnowledgeBaseEntitiesContainer* entityContainer = getClassEntitiesCommand->getExtractedEntityContainer(); |
| 287 |
domEl = getEntitiesSetNode("SetOfClasses","owl:Class",entityContainer); |
| 288 |
} else { |
| 289 |
domEl = getErrorNode(recData); |
| 290 |
} |
| 291 |
} |
| 292 |
} else if (dynamic_cast<CGetKnowledgeBaseObjectPropertyEntitiesCommand *>(command)) { |
| 293 |
CGetKnowledgeBaseObjectPropertyEntitiesCommand *getObjectPropertyEntitiesCommand = dynamic_cast<CGetKnowledgeBaseObjectPropertyEntitiesCommand *>(command); |
| 294 |
if (getObjectPropertyEntitiesCommand) { |
| 295 |
if (command->getMaxErrorLevel() <= 0) { |
| 296 |
CExtractedKnowledgeBaseEntitiesContainer* entityContainer = getObjectPropertyEntitiesCommand->getExtractedEntityContainer(); |
| 297 |
domEl = getEntitiesSetNode("SetOfObjectProperties","owl:ObjectProperty",entityContainer); |
| 298 |
} else { |
| 299 |
domEl = getErrorNode(recData); |
| 300 |
} |
| 301 |
} |
| 302 |
} else if (dynamic_cast<CGetKnowledgeBaseNamedIndividualEntitiesCommand *>(command)) { |
| 303 |
CGetKnowledgeBaseNamedIndividualEntitiesCommand *getIndividualEntitiesCommand = dynamic_cast<CGetKnowledgeBaseNamedIndividualEntitiesCommand *>(command); |
| 304 |
if (getIndividualEntitiesCommand) { |
| 305 |
if (command->getMaxErrorLevel() <= 0) { |
| 306 |
CExtractedKnowledgeBaseEntitiesContainer* entityContainer = getIndividualEntitiesCommand->getExtractedEntityContainer(); |
| 307 |
domEl = getEntitiesSetNode("SetOfIndividuals","owl:NamedIndividual",entityContainer); |
| 308 |
} else { |
| 309 |
domEl = getErrorNode(recData); |
| 310 |
} |
| 311 |
} |
| 312 |
} else if (dynamic_cast<CKnowledgeBaseQueryCommand *>(command)) { |
| 313 |
CKnowledgeBaseQueryCommand *queryCommand = dynamic_cast<CKnowledgeBaseQueryCommand *>(command); |
| 314 |
if (queryCommand) { |
| 315 |
if (command->getMaxErrorLevel() <= 0) { |
| 316 |
bool wrongResult = false; |
| 317 |
CCalculateQueryCommand *calcQueryCommand = queryCommand->getCalculateQueryCommand(); |
| 318 |
CTestExtendedCalculateQueryCommand *testExtCalcQueryCommand = dynamic_cast<CTestExtendedCalculateQueryCommand *>(calcQueryCommand); |
| 319 |
CQuery *query = calcQueryCommand->getQuery(); |
| 320 |
CQueryResult *queryResult = 0; |
| 321 |
CQueryResult *expectedQueryResult = 0; |
| 322 |
QDomElement queryErrorNode; |
| 323 |
if (query) { |
| 324 |
QDomElement queryResultNode; |
| 325 |
queryResult = query->getQueryResult(); |
| 326 |
if (queryResult) { |
| 327 |
CBooleanQueryResult *boolQueryResult = dynamic_cast<CBooleanQueryResult *>(queryResult); |
| 328 |
if (boolQueryResult) { |
| 329 |
bool result = false; |
| 330 |
result = boolQueryResult->getResult(); |
| 331 |
queryResultNode = document.createElement("BooleanResponse"); |
| 332 |
if (result) { |
| 333 |
queryResultNode.setAttribute("result","true"); |
| 334 |
} else { |
| 335 |
queryResultNode.setAttribute("result","false"); |
| 336 |
} |
| 337 |
domEl = queryResultNode; |
| 338 |
} |
| 339 |
|
| 340 |
CClassHierarchyResult *subClassHierarchyResult = dynamic_cast<CClassHierarchyResult *>(queryResult); |
| 341 |
if (subClassHierarchyResult) { |
| 342 |
queryResultNode = document.createElement("ClassHierarchy"); |
| 343 |
CClassSynsetResult *bottomClassSynsetResult = subClassHierarchyResult->getBottomClassSynset(); |
| 344 |
QDomElement classSynsetNode = document.createElement("ClassSynset"); |
| 345 |
foreach (QString className, bottomClassSynsetResult->getEquivalentClassNameList()) { |
| 346 |
QDomElement classNameNode = document.createElement("owl:Class"); |
| 347 |
classNameNode.setAttribute("IRI",className); |
| 348 |
classSynsetNode.appendChild(classNameNode); |
| 349 |
} |
| 350 |
queryResultNode.appendChild(classSynsetNode); |
| 351 |
QList<CClassSynsetResult *> procList; |
| 352 |
QSet<CClassSynsetResult *> procSet; |
| 353 |
CClassSynsetResult *topClassSynsetResult = subClassHierarchyResult->getTopClassSynset(); |
| 354 |
procList.append(topClassSynsetResult); |
| 355 |
while (!procList.isEmpty()) { |
| 356 |
CClassSynsetResult *classSynsetResult = procList.takeFirst(); |
| 357 |
CClassSubClassesRelationResult *subClassRelationResult = subClassHierarchyResult->getSubClassRelation(classSynsetResult,false); |
| 358 |
if (subClassRelationResult) { |
| 359 |
QDomElement classSubClassPairNode = document.createElement("ClassSubClassesPair"); |
| 360 |
// super class serialization |
| 361 |
QDomElement superClassSynsetNode = document.createElement("ClassSynset"); |
| 362 |
foreach (QString className, classSynsetResult->getEquivalentClassNameList()) { |
| 363 |
QDomElement classNameNode = document.createElement("owl:Class"); |
| 364 |
classNameNode.setAttribute("IRI",className); |
| 365 |
superClassSynsetNode.appendChild(classNameNode); |
| 366 |
} |
| 367 |
classSubClassPairNode.appendChild(superClassSynsetNode); |
| 368 |
QDomElement subClassSynsetsNode = document.createElement("SubClassSynsets"); |
| 369 |
// sub classes serialization |
| 370 |
foreach (CClassSynsetResult *subClassSynsetResult, subClassRelationResult->getSubClassesSynsetList()) { |
| 371 |
QDomElement subClassSynsetNode = document.createElement("ClassSynset"); |
| 372 |
foreach (QString className, subClassSynsetResult->getEquivalentClassNameList()) { |
| 373 |
QDomElement classNameNode = document.createElement("owl:Class"); |
| 374 |
classNameNode.setAttribute("IRI",className); |
| 375 |
subClassSynsetNode.appendChild(classNameNode); |
| 376 |
} |
| 377 |
subClassSynsetsNode.appendChild(subClassSynsetNode); |
| 378 |
if (!procSet.contains(subClassSynsetResult)) { |
| 379 |
procSet.insert(subClassSynsetResult); |
| 380 |
procList.append(subClassSynsetResult); |
| 381 |
} |
| 382 |
} |
| 383 |
classSubClassPairNode.appendChild(subClassSynsetsNode); |
| 384 |
queryResultNode.appendChild(classSubClassPairNode); |
| 385 |
} |
| 386 |
} |
| 387 |
domEl = queryResultNode; |
| 388 |
} |
| 389 |
|
| 390 |
CClassesResult* classesResult = dynamic_cast<CClassesResult*>(queryResult); |
| 391 |
if (classesResult) { |
| 392 |
queryResultNode = document.createElement("Classes"); |
| 393 |
QSet<QString>* classesSet = classesResult->getClassesSet(); |
| 394 |
for (QSet<QString>::const_iterator it = classesSet->constBegin(), itEnd = classesSet->constEnd(); it != itEnd; ++it) { |
| 395 |
const QString& className(*it); |
| 396 |
QDomElement classNameNode = document.createElement("owl:Class"); |
| 397 |
classNameNode.setAttribute("IRI",className); |
| 398 |
queryResultNode.appendChild(classNameNode); |
| 399 |
} |
| 400 |
domEl = queryResultNode; |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
CClassSetResult* classSetResult = dynamic_cast<CClassSetResult*>(queryResult); |
| 405 |
if (classSetResult) { |
| 406 |
queryResultNode = document.createElement("SetOfClasses"); |
| 407 |
QSet<QString>* classesSet = classSetResult->getClassesSet(); |
| 408 |
for (QSet<QString>::const_iterator it = classesSet->constBegin(), itEnd = classesSet->constEnd(); it != itEnd; ++it) { |
| 409 |
const QString& className(*it); |
| 410 |
QDomElement classNameNode = document.createElement("owl:Class"); |
| 411 |
classNameNode.setAttribute("IRI",className); |
| 412 |
queryResultNode.appendChild(classNameNode); |
| 413 |
} |
| 414 |
domEl = queryResultNode; |
| 415 |
} |
| 416 |
|
| 417 |
CClassSynsetsResult* classSynsetsResult = dynamic_cast<CClassSynsetsResult*>(queryResult); |
| 418 |
if (classSynsetsResult) { |
| 419 |
queryResultNode = document.createElement("SetOfClassSynsets"); |
| 420 |
QList<CClassSynsetResult*>* classSynsetList = classSynsetsResult->getClassSynsetList(); |
| 421 |
for (QList<CClassSynsetResult*>::const_iterator it = classSynsetList->constBegin(), itEnd = classSynsetList->constEnd(); it != itEnd; ++it) { |
| 422 |
CClassSynsetResult* classSynset(*it); |
| 423 |
QDomElement superClassSynsetNode = document.createElement("ClassSynset"); |
| 424 |
foreach (QString className, classSynset->getEquivalentClassNameList()) { |
| 425 |
QDomElement classNameNode = document.createElement("owl:Class"); |
| 426 |
classNameNode.setAttribute("IRI",className); |
| 427 |
superClassSynsetNode.appendChild(classNameNode); |
| 428 |
} |
| 429 |
queryResultNode.appendChild(superClassSynsetNode); |
| 430 |
} |
| 431 |
domEl = queryResultNode; |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
CPropertyHierarchyResult *subPropertyHierarchyResult = dynamic_cast<CPropertyHierarchyResult *>(queryResult); |
| 440 |
if (subPropertyHierarchyResult) { |
| 441 |
|
| 442 |
bool dataPropertyQuery = subPropertyHierarchyResult->hasDataProperties(); |
| 443 |
QString dataObjectString = QString("Object"); |
| 444 |
if (dataPropertyQuery) { |
| 445 |
dataObjectString = QString("Data"); |
| 446 |
} |
| 447 |
|
| 448 |
queryResultNode = document.createElement(QString("%1PropertyHierarchy").arg(dataObjectString)); |
| 449 |
CPropertySynsetResult *bottomPropertySynsetResult = subPropertyHierarchyResult->getBottomPropertySynset(); |
| 450 |
QDomElement propertySynsetNode = document.createElement(QString("%1PropertySynset").arg(dataObjectString)); |
| 451 |
foreach (QString propertyName, bottomPropertySynsetResult->getEquivalentPropertyNameList()) { |
| 452 |
QDomElement propertyNameNode = document.createElement(QString("owl:%1Property").arg(dataObjectString)); |
| 453 |
propertyNameNode.setAttribute("IRI",propertyName); |
| 454 |
propertySynsetNode.appendChild(propertyNameNode); |
| 455 |
} |
| 456 |
queryResultNode.appendChild(propertySynsetNode); |
| 457 |
QList<CPropertySynsetResult *> procList; |
| 458 |
QSet<CPropertySynsetResult *> procSet; |
| 459 |
CPropertySynsetResult *topPropertySynsetResult = subPropertyHierarchyResult->getTopPropertySynset(); |
| 460 |
procList.append(topPropertySynsetResult); |
| 461 |
while (!procList.isEmpty()) { |
| 462 |
CPropertySynsetResult *propertySynsetResult = procList.takeFirst(); |
| 463 |
CPropertySubPropertiesRelationResult *subPropertyRelationResult = subPropertyHierarchyResult->getSubPropertyRelation(propertySynsetResult,false); |
| 464 |
if (subPropertyRelationResult) { |
| 465 |
QDomElement propertySubPropertyPairNode = document.createElement(QString("%1PropertySub%2PropertiesPair").arg(dataObjectString).arg(dataObjectString)); |
| 466 |
// super property serialization |
| 467 |
QDomElement superPropertySynsetNode = document.createElement(QString("%1PropertySynset").arg(dataObjectString)); |
| 468 |
foreach (QString propertyName, propertySynsetResult->getEquivalentPropertyNameList()) { |
| 469 |
QDomElement propertyNameNode = document.createElement(QString("owl:%1Property").arg(dataObjectString)); |
| 470 |
propertyNameNode.setAttribute("IRI",propertyName); |
| 471 |
superPropertySynsetNode.appendChild(propertyNameNode); |
| 472 |
} |
| 473 |
propertySubPropertyPairNode.appendChild(superPropertySynsetNode); |
| 474 |
QDomElement subPropertySynsetsNode = document.createElement(QString("Sub%1PropertySynsets").arg(dataObjectString)); |
| 475 |
// sub properties serialization |
| 476 |
foreach (CPropertySynsetResult *subPropertySynsetResult, subPropertyRelationResult->getSubPropertiesSynsetList()) { |
| 477 |
QDomElement subPropertySynsetNode = document.createElement(QString("%1PropertySynset").arg(dataObjectString)); |
| 478 |
foreach (QString propertyName, subPropertySynsetResult->getEquivalentPropertyNameList()) { |
| 479 |
QDomElement propertyNameNode = document.createElement(QString("owl:%1Property").arg(dataObjectString)); |
| 480 |
propertyNameNode.setAttribute("IRI",propertyName); |
| 481 |
subPropertySynsetNode.appendChild(propertyNameNode); |
| 482 |
} |
| 483 |
subPropertySynsetsNode.appendChild(subPropertySynsetNode); |
| 484 |
if (!procSet.contains(subPropertySynsetResult)) { |
| 485 |
procSet.insert(subPropertySynsetResult); |
| 486 |
procList.append(subPropertySynsetResult); |
| 487 |
} |
| 488 |
} |
| 489 |
propertySubPropertyPairNode.appendChild(subPropertySynsetsNode); |
| 490 |
queryResultNode.appendChild(propertySubPropertyPairNode); |
| 491 |
} |
| 492 |
} |
| 493 |
domEl = queryResultNode; |
| 494 |
} |
| 495 |
|
| 496 |
//CPropertiesResult* propertiesResult = dynamic_cast<CPropertiesResult*>(queryResult); |
| 497 |
//if (propertiesResult) { |
| 498 |
// queryResultNode = document.createElement("Properties"); |
| 499 |
// QSet<QString>* propertiesSet = propertiesResult->getPropertiesSet(); |
| 500 |
// for (QSet<QString>::const_iterator it = propertiesSet->constBegin(), itEnd = propertiesSet->constEnd(); it != itEnd; ++it) { |
| 501 |
// const QString& propertyName(*it); |
| 502 |
// QDomElement propertyNameNode = document.createElement("owl:Property"); |
| 503 |
// propertyNameNode.setAttribute("IRI",propertyName); |
| 504 |
// queryResultNode.appendChild(propertyNameNode); |
| 505 |
// } |
| 506 |
// domEl = queryResultNode; |
| 507 |
//} |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
CPropertySetResult* propertySetResult = dynamic_cast<CPropertySetResult*>(queryResult); |
| 515 |
if (propertySetResult) { |
| 516 |
|
| 517 |
QString dataObjectString = QString("Object"); |
| 518 |
bool dataPropertyResult = propertySetResult->hasDataProperties(); |
| 519 |
if (dataPropertyResult) { |
| 520 |
dataObjectString = QString("Data"); |
| 521 |
} |
| 522 |
|
| 523 |
if (dataPropertyResult) { |
| 524 |
queryResultNode = document.createElement(QString("DataPropertySynonyms")); |
| 525 |
} else { |
| 526 |
queryResultNode = document.createElement(QString("SetOfObjectProperties")); |
| 527 |
} |
| 528 |
QSet<QString>* propertiesSet = propertySetResult->getPropertiesSet(); |
| 529 |
for (QSet<QString>::const_iterator it = propertiesSet->constBegin(), itEnd = propertiesSet->constEnd(); it != itEnd; ++it) { |
| 530 |
const QString& propertyName(*it); |
| 531 |
QDomElement propertyNameNode = document.createElement(QString("owl:%1Property").arg(dataObjectString)); |
| 532 |
propertyNameNode.setAttribute("IRI", propertyName); |
| 533 |
queryResultNode.appendChild(propertyNameNode); |
| 534 |
} |
| 535 |
domEl = queryResultNode; |
| 536 |
} |
| 537 |
|
| 538 |
CPropertySynsetsResult* propertySynsetsResult = dynamic_cast<CPropertySynsetsResult*>(queryResult); |
| 539 |
if (propertySynsetsResult) { |
| 540 |
QString dataObjectString = QString("Object"); |
| 541 |
bool dataPropertyResult = propertySynsetsResult->hasDataProperties(); |
| 542 |
if (dataPropertyResult) { |
| 543 |
dataObjectString = QString("Data"); |
| 544 |
} |
| 545 |
|
| 546 |
queryResultNode = document.createElement(QString("SetOf%1PropertySynsets").arg(dataObjectString)); |
| 547 |
QList<CPropertySynsetResult*>* propertySynsetList = propertySynsetsResult->getPropertySynsetList(); |
| 548 |
for (QList<CPropertySynsetResult*>::const_iterator it = propertySynsetList->constBegin(), itEnd = propertySynsetList->constEnd(); it != itEnd; ++it) { |
| 549 |
CPropertySynsetResult* propertySynset(*it); |
| 550 |
QDomElement superPropertySynsetNode = document.createElement(QString("%1PropertySynset").arg(dataObjectString)); |
| 551 |
foreach(QString propertyName, propertySynset->getEquivalentPropertyNameList()) { |
| 552 |
QDomElement propertyNameNode = document.createElement(QString("owl:%1Property").arg(dataObjectString)); |
| 553 |
propertyNameNode.setAttribute("IRI", propertyName); |
| 554 |
superPropertySynsetNode.appendChild(propertyNameNode); |
| 555 |
} |
| 556 |
queryResultNode.appendChild(superPropertySynsetNode); |
| 557 |
} |
| 558 |
domEl = queryResultNode; |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
CIndividualSynonymsResult* individualSynonymsResult = dynamic_cast<CIndividualSynonymsResult*>(queryResult); |
| 572 |
if (individualSynonymsResult) { |
| 573 |
queryResultNode = document.createElement("IndividualSynonyms"); |
| 574 |
QSet<QString>* individualsSet = individualSynonymsResult->getIndividualsSet(); |
| 575 |
for (QSet<QString>::const_iterator it = individualsSet->constBegin(), itEnd = individualsSet->constEnd(); it != itEnd; ++it) { |
| 576 |
const QString& indiName(*it); |
| 577 |
QDomElement indiNameNode = document.createElement("owl:NamedIndividual"); |
| 578 |
indiNameNode.setAttribute("IRI",indiName); |
| 579 |
queryResultNode.appendChild(indiNameNode); |
| 580 |
} |
| 581 |
domEl = queryResultNode; |
| 582 |
} else { |
| 583 |
CIndividualsResult* individualResult = dynamic_cast<CIndividualsResult*>(queryResult); |
| 584 |
if (individualResult) { |
| 585 |
queryResultNode = document.createElement("SetOfIndividuals"); |
| 586 |
QSet<QString>* individualsSet = individualResult->getIndividualsSet(); |
| 587 |
for (QSet<QString>::const_iterator it = individualsSet->constBegin(), itEnd = individualsSet->constEnd(); it != itEnd; ++it) { |
| 588 |
const QString& indiName(*it); |
| 589 |
QDomElement indiNameNode = document.createElement("owl:NamedIndividual"); |
| 590 |
indiNameNode.setAttribute("IRI",indiName); |
| 591 |
queryResultNode.appendChild(indiNameNode); |
| 592 |
} |
| 593 |
domEl = queryResultNode; |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
CIndividualClassAssertionsResult* classAssertionResult = dynamic_cast<CIndividualClassAssertionsResult*>(queryResult); |
| 599 |
if (classAssertionResult) { |
| 600 |
queryResultNode = document.createElement("SetOfClassAssertions"); |
| 601 |
QSet< QPair<QString,QString> >* individualClassAssSet = classAssertionResult->getIndividualConceptAssertionSet(); |
| 602 |
for (QSet< QPair<QString,QString> >::const_iterator it = individualClassAssSet->constBegin(), itEnd = individualClassAssSet->constEnd(); it != itEnd; ++it) { |
| 603 |
const QPair<QString,QString>& indiClassNamePair(*it); |
| 604 |
QDomElement classAssNode = document.createElement("owl:ClassAssertion"); |
| 605 |
QDomElement indiNameNode = document.createElement("owl:NamedIndividual"); |
| 606 |
QDomElement classNode = document.createElement("owl:Class"); |
| 607 |
indiNameNode.setAttribute("IRI",indiClassNamePair.first); |
| 608 |
classNode.setAttribute("IRI",indiClassNamePair.second); |
| 609 |
classAssNode.appendChild(classNode); |
| 610 |
classAssNode.appendChild(indiNameNode); |
| 611 |
queryResultNode.appendChild(classAssNode); |
| 612 |
} |
| 613 |
domEl = queryResultNode; |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
CIndividualSynsetsResult* individualSynsetsResult = dynamic_cast<CIndividualSynsetsResult*>(queryResult); |
| 618 |
if (individualSynsetsResult) { |
| 619 |
queryResultNode = document.createElement("SetOfIndividualSynsets"); |
| 620 |
QList<CIndividualSynsetResult*>* individualSynsetList = individualSynsetsResult->getIndividualSynsetList(); |
| 621 |
for (QList<CIndividualSynsetResult*>::const_iterator it = individualSynsetList->constBegin(), itEnd = individualSynsetList->constEnd(); it != itEnd; ++it) { |
| 622 |
CIndividualSynsetResult* individualSynset(*it); |
| 623 |
QDomElement superIndividualSynsetNode = document.createElement("IndividualSynset"); |
| 624 |
foreach (QString individualName, individualSynset->getEquivalentIndividualNameList()) { |
| 625 |
QDomElement individualNameNode = document.createElement("owl:NamedIndividual"); |
| 626 |
individualNameNode.setAttribute("IRI",individualName); |
| 627 |
superIndividualSynsetNode.appendChild(individualNameNode); |
| 628 |
} |
| 629 |
queryResultNode.appendChild(superIndividualSynsetNode); |
| 630 |
} |
| 631 |
domEl = queryResultNode; |
| 632 |
} |
| 633 |
|
| 634 |
CSucceedQueryResult* succeedResult = dynamic_cast<CSucceedQueryResult*>(queryResult); |
| 635 |
if (succeedResult) { |
| 636 |
queryResultNode = document.createElement("OK"); |
| 637 |
domEl = queryResultNode; |
| 638 |
} |
| 639 |
|
| 640 |
if (testExtCalcQueryCommand) { |
| 641 |
expectedQueryResult = testExtCalcQueryCommand->getExpectedQueryResult(); |
| 642 |
if (expectedQueryResult) { |
| 643 |
if (!expectedQueryResult->isResultEquivalentTo(queryResult)) { |
| 644 |
wrongResult = true; |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
if (testExtCalcQueryCommand->getTimingReportLevel() > 0) { |
| 649 |
queryResultNode.setAttribute("response-time",QString::number(testExtCalcQueryCommand->getCreationElapsedMilliSeconds())); |
| 650 |
} |
| 651 |
|
| 652 |
} |
| 653 |
} |
| 654 |
if (query->hasError()) { |
| 655 |
CQueryInconsitentOntologyError* inOnEr = CQueryInconsitentOntologyError::getInconsistentOntologyError(query->getQueryErrorLinker()); |
| 656 |
if (inOnEr) { |
| 657 |
QDomElement erDomEl = getErrorNode(inOnEr->getErrorString(),"UnsatisfiableKBError"); |
| 658 |
queryErrorNode = erDomEl; |
| 659 |
} else { |
| 660 |
QString errorString = query->getErrorStringList().join(" "); |
| 661 |
if (errorString.isEmpty()) { |
| 662 |
errorString = QString("Unknown error."); |
| 663 |
} |
| 664 |
QDomElement erDomEl = getErrorNode(errorString); |
| 665 |
queryErrorNode = erDomEl; |
| 666 |
} |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
#ifndef KONCLUDE_FORCE_STATISTIC_DEACTIVATED |
| 671 |
CQueryStatistics* queryStats = query->getQueryStatistics(); |
| 672 |
if (queryStats && mRespondQueryStatistics) { |
| 673 |
QList<QString> statStrings(queryStats->getStatisticsNameStringList()); |
| 674 |
if (statStrings.count() >= 1) { |
| 675 |
QVector<QDomElement> statNodeVec(statStrings.count()+1); |
| 676 |
QList<QDomElement> statMoreNodeList; |
| 677 |
QList<QDomElement> statClassNodeList; |
| 678 |
QDomElement statNode = document.createElement("ResponseStatistics"); |
| 679 |
foreach (QString statName, statStrings) { |
| 680 |
if (mConfFileAppendSimpleStats) { |
| 681 |
for (cint64 i = 0; i < mStatStringList.count(); ++i) { |
| 682 |
if (statName == mStatStringList[i]) { |
| 683 |
cint64 statValue = queryStats->getStatisticIntegerValue(statName); |
| 684 |
mStatVector[i] = statValue; |
| 685 |
break; |
| 686 |
} |
| 687 |
} |
| 688 |
} |
| 689 |
cint64 index = CProcessingStatistics::getIndexFromProcessingStatisticDescriptionName(statName); |
| 690 |
if (index >= 0) { |
| 691 |
QDomElement statValueNode = document.createElement("CountedProcessStatistic"); |
| 692 |
statValueNode.setAttribute("statistic-name",statName); |
| 693 |
statValueNode.setAttribute("statistic-value",queryStats->getStatisticIntegerValue(statName)); |
| 694 |
statNodeVec[index] = statValueNode; |
| 695 |
} else { |
| 696 |
if (statName.startsWith("class-classification")) { |
| 697 |
QDomElement statValueNode = document.createElement("ClassClassificationStatistic"); |
| 698 |
statValueNode.setAttribute("statistic-name",statName); |
| 699 |
statValueNode.setAttribute("statistic-value",queryStats->getStatisticIntegerValue(statName)); |
| 700 |
statClassNodeList.append(statValueNode); |
| 701 |
} else { |
| 702 |
QDomElement statValueNode = document.createElement("CalculationStatistic"); |
| 703 |
statValueNode.setAttribute("statistic-name",statName); |
| 704 |
statValueNode.setAttribute("statistic-value",queryStats->getStatisticIntegerValue(statName)); |
| 705 |
statMoreNodeList.append(statValueNode); |
| 706 |
} |
| 707 |
} |
| 708 |
} |
| 709 |
foreach (QDomElement statValueNode, statMoreNodeList) { |
| 710 |
statNode.appendChild(statValueNode); |
| 711 |
} |
| 712 |
foreach (QDomElement statValueNode, statClassNodeList) { |
| 713 |
statNode.appendChild(statValueNode); |
| 714 |
} |
| 715 |
for (cint64 index = 0; index < statNodeVec.count(); ++index) { |
| 716 |
QDomElement statValueNode = statNodeVec[index]; |
| 717 |
if (!statValueNode.isNull()) { |
| 718 |
statNode.appendChild(statValueNode); |
| 719 |
} |
| 720 |
} |
| 721 |
if (!queryResultNode.isNull()) { |
| 722 |
queryResultNode.appendChild(statNode); |
| 723 |
} else if (!queryErrorNode.isNull()) { |
| 724 |
queryErrorNode.appendChild(statNode); |
| 725 |
} |
| 726 |
} |
| 727 |
} |
| 728 |
#endif |
| 729 |
} else { |
| 730 |
domEl = getErrorNode(recData); |
| 731 |
} |
| 732 |
|
| 733 |
if (wrongResult) { |
| 734 |
mCalculatedWrongResult = true; |
| 735 |
LOG(WARNING,"::Konclude::Control::Interface::OWLlink::OWLlinkRecordInterpreter",logTr("Reasoner calculated unexpected result on query %1.").arg(query->getQueryString()),this); |
| 736 |
QDomElement errorMistakeNode = getErrorNode(QString("Reasoner calculated unexpected result")); |
| 737 |
QDomNode prevDomEl = domEl; |
| 738 |
errorMistakeNode.appendChild(prevDomEl); |
| 739 |
QDomElement expQueryResultNode = document.createElement("ExpectedResponse"); |
| 740 |
CBooleanQueryResult *boolExpecQueRes = dynamic_cast<CBooleanQueryResult *>(expectedQueryResult); |
| 741 |
if (boolExpecQueRes) { |
| 742 |
QDomElement expBoolQueryResultNode = document.createElement("BooleanResponse"); |
| 743 |
bool expecQueRes = boolExpecQueRes->getResult(); |
| 744 |
if (expecQueRes) { |
| 745 |
expBoolQueryResultNode.setAttribute("result","true"); |
| 746 |
} else { |
| 747 |
expBoolQueryResultNode.setAttribute("result","false"); |
| 748 |
} |
| 749 |
expQueryResultNode.appendChild(expBoolQueryResultNode); |
| 750 |
} |
| 751 |
errorMistakeNode.appendChild(expQueryResultNode); |
| 752 |
domEl = errorMistakeNode; |
| 753 |
} else if (mConfFileAppendSimpleStats) { |
| 754 |
CIsClassSatisfiableQuery* satQuery = dynamic_cast<CIsClassSatisfiableQuery*>(query); |
| 755 |
if (satQuery) { |
| 756 |
mStatQueryString = satQuery->getClassStringName(); |
| 757 |
} |
| 758 |
//QFile mStatFile(mStatFileString); |
| 759 |
//if (!mStatFile.exists()) { |
| 760 |
// if (mStatFile.open(QIODevice::WriteOnly)) { |
| 761 |
// mStatFile.write((QString("test-name ")+mStatStringList.join(" ").append("\r\n")).toLocal8Bit()); |
| 762 |
// mStatFile.close(); |
| 763 |
// } |
| 764 |
//} |
| 765 |
//if (mStatFile.open(QIODevice::Append)) { |
| 766 |
// mStatKBString = queryCommand->getKnowledgeBaseName(); |
| 767 |
// QString appendString = QString("%1#%2#%3").arg(mStatKBString).arg(mStatLoadString).arg(mStatQueryString); |
| 768 |
// mStatKBString = ""; |
| 769 |
// mStatLoadString = ""; |
| 770 |
// mStatQueryString = ""; |
| 771 |
// for (cint64 i = 0; i < mStatVector.count(); ++i) { |
| 772 |
// cint64 statValue = mStatVector[i]; |
| 773 |
// if (!appendString.isEmpty()) { |
| 774 |
// appendString.append(" "); |
| 775 |
// } |
| 776 |
// appendString.append(QString("%1").arg(statValue)); |
| 777 |
// } |
| 778 |
// appendString.append(QString("\r\n")); |
| 779 |
// mStatFile.write(appendString.toLocal8Bit()); |
| 780 |
// mStatFile.close(); |
| 781 |
//} |
| 782 |
} |
| 783 |
|
| 784 |
if (!queryErrorNode.isNull()) { |
| 785 |
if (!domEl.isNull()) { |
| 786 |
queryErrorNode.appendChild(domEl); |
| 787 |
} |
| 788 |
domEl = queryErrorNode; |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
} else { |
| 793 |
domEl = getErrorNode(recData); |
| 794 |
} |
| 795 |
} |
| 796 |
} else if (dynamic_cast<CSkipUnsupportedCommandCommand *>(command)) { |
| 797 |
CSkipUnsupportedCommandCommand *skipUnsCommand = dynamic_cast<CSkipUnsupportedCommandCommand *>(command); |
| 798 |
if (skipUnsCommand) { |
| 799 |
if (command->getMaxErrorLevel() <= 0) { |
| 800 |
QDomElement errorNode = getErrorNode(QString("Instruction '%1' is currently not supported.").arg(skipUnsCommand->getSkippedCommandString()),"Error"); |
| 801 |
domEl = errorNode; |
| 802 |
|
| 803 |
} else { |
| 804 |
domEl = getErrorNode(recData); |
| 805 |
} |
| 806 |
} |
| 807 |
} else if (dynamic_cast<CReleaseKnowledgeBaseCommand *>(command)) { |
| 808 |
CReleaseKnowledgeBaseCommand *relCommand = dynamic_cast<CReleaseKnowledgeBaseCommand *>(command); |
| 809 |
if (relCommand) { |
| 810 |
if (command->getMaxErrorLevel() <= 0) { |
| 811 |
QDomElement releasedNode = document.createElement("OK"); |
| 812 |
domEl = releasedNode; |
| 813 |
|
| 814 |
} else { |
| 815 |
domEl = getErrorNode(recData); |
| 816 |
} |
| 817 |
} |
| 818 |
} else if (dynamic_cast<CParseTestsuiteXMLNodeCommand *>(command)) { |
| 819 |
CParseTestsuiteXMLNodeCommand *parseTestCommand = dynamic_cast<CParseTestsuiteXMLNodeCommand *>(command); |
| 820 |
CTestTestsuiteCommand *testsuiteCommand = 0; |
| 821 |
CLinker<CCommand *> *subCommIt = parseTestCommand->getSubCommandLinker(); |
| 822 |
while (subCommIt && !testsuiteCommand) { |
| 823 |
testsuiteCommand = dynamic_cast<CTestTestsuiteCommand *>(subCommIt->getData()); |
| 824 |
subCommIt = subCommIt->getNext(); |
| 825 |
} |
| 826 |
if (testsuiteCommand && testsuiteCommand->getMaxErrorLevel() <= 0) { |
| 827 |
CReasonerTestsuiteTest *testsuiteTest = testsuiteCommand->getTestsuiteTest(); |
| 828 |
QLinkedList<CReasonerTestfileTest *> testfileTestList = testsuiteTest->getTestfileTestList(); |
| 829 |
QDomElement resultNode = document.createElement("TestsuiteResult"); |
| 830 |
|
| 831 |
resultNode.setAttribute("totalTestingTime",testsuiteTest->getTestsuiteResult()->getTotalTestingTime()); |
| 832 |
|
| 833 |
foreach (CReasonerTestfileTest *testfileTest, testfileTestList) { |
| 834 |
CReasonerTestfileTestResult *testfileTestResult = testfileTest->getTestResults(); |
| 835 |
QDomElement testfileResultNode = document.createElement("TestfileResult"); |
| 836 |
testfileResultNode.setAttribute("testSource",testfileTest->getTestRequestFile()); |
| 837 |
testfileResultNode.setAttribute("testLoopCount",testfileTestResult->getTotalTestCount()); |
| 838 |
if (testfileTestResult->getFailedCount() > 0) { |
| 839 |
testfileResultNode.setAttribute("failedCount",testfileTestResult->getFailedCount()); |
| 840 |
} |
| 841 |
if (testfileTestResult->getCrashCount() > 0) { |
| 842 |
testfileResultNode.setAttribute("crashCount",testfileTestResult->getCrashCount()); |
| 843 |
} |
| 844 |
if (testfileTestResult->getErrorCount() > 0) { |
| 845 |
testfileResultNode.setAttribute("errorCount",testfileTestResult->getErrorCount()); |
| 846 |
} |
| 847 |
if (testfileTestResult->getWrongResponseCount() > 0) { |
| 848 |
testfileResultNode.setAttribute("wrongCount",testfileTestResult->getWrongResponseCount()); |
| 849 |
} |
| 850 |
if (testfileTestResult->getTimeoutCount() > 0) { |
| 851 |
testfileResultNode.setAttribute("timeoutCount",testfileTestResult->getTimeoutCount()); |
| 852 |
} |
| 853 |
testfileResultNode.setAttribute("correctCount",testfileTestResult->getCorrectResponseCount()); |
| 854 |
if (testfileTestResult->getAverageCorrectResponseTime() > 0) { |
| 855 |
testfileResultNode.setAttribute("averageCorrectResponseTime",testfileTestResult->getAverageCorrectResponseTime()); |
| 856 |
} |
| 857 |
resultNode.appendChild(testfileResultNode); |
| 858 |
} |
| 859 |
domEl = resultNode; |
| 860 |
|
| 861 |
} else { |
| 862 |
domEl = getErrorNode(recData); |
| 863 |
} |
| 864 |
} |
| 865 |
|
| 866 |
if (domEl.isNull()) { |
| 867 |
domEl = getErrorNode(QString("No handler for '%1' command ").arg(command->getBriefCommandDescription())); |
| 868 |
} |
| 869 |
|
| 870 |
|
| 871 |
if (!domEl.isNull()) { |
| 872 |
seqSyncMutex.lock(); |
| 873 |
qint64 seqNumber = commandSequenceHash.value(command); |
| 874 |
seqNodeHash.insert(seqNumber,domEl); |
| 875 |
seqSyncMutex.unlock(); |
| 876 |
|
| 877 |
} |
| 878 |
|
| 879 |
while (seqNodeHash.contains(recNextSeqNumber)) { |
| 880 |
seqSyncMutex.lock(); |
| 881 |
if (seqNodeHash.contains(recNextSeqNumber)) { |
| 882 |
rootNode.appendChild(seqNodeHash.value(recNextSeqNumber)); |
| 883 |
recNextSeqNumber++; |
| 884 |
} |
| 885 |
seqSyncMutex.unlock(); |
| 886 |
} |
| 887 |
|
| 888 |
} |
| 889 |
|
| 890 |
} |
| 891 |
} |
| 892 |
} |
| 893 |
return this; |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
QDomElement COWLLinkRecordInterpreter::getEntitiesSetNode(const QString &nodeString, const QString &entityString, CExtractedKnowledgeBaseEntitiesContainer* entityContainer) { |
| 899 |
QDomElement entitySetNode = document.createElement(nodeString); |
| 900 |
QStringList* entitySet = entityContainer->getExtractedEntityList(); |
| 901 |
for (QStringList::const_iterator it = entitySet->constBegin(), itEnd = entitySet->constEnd(); it != itEnd; ++it) { |
| 902 |
const QString& entityName(*it); |
| 903 |
QDomElement entityNameNode = document.createElement(entityString); |
| 904 |
entityNameNode.setAttribute("IRI",entityName); |
| 905 |
entitySetNode.appendChild(entityNameNode); |
| 906 |
} |
| 907 |
return entitySetNode; |
| 908 |
} |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
QDomElement COWLLinkRecordInterpreter::getErrorNode(CCommandRecordData *recData, const QString &nodeString) { |
| 913 |
QDomElement errorNode = document.createElement(nodeString); |
| 914 |
|
| 915 |
QDomElement errorTextNodePa = document.createElement(QString("%1Text").arg(nodeString)); |
| 916 |
|
| 917 |
QString errorText = getErrorString(recData,nodeString); |
| 918 |
|
| 919 |
QDomText errorTextNode = document.createTextNode(errorText); |
| 920 |
errorNode.setAttribute("error",errorText); |
| 921 |
|
| 922 |
errorTextNodePa.appendChild(errorTextNode); |
| 923 |
errorNode.appendChild(errorTextNodePa); |
| 924 |
|
| 925 |
return errorNode; |
| 926 |
} |
| 927 |
|
| 928 |
|
| 929 |
QDomElement COWLLinkRecordInterpreter::getErrorNode(const QString& errorText, const QString &nodeString) { |
| 930 |
QDomElement errorNode = document.createElement(nodeString); |
| 931 |
|
| 932 |
QDomElement errorTextNodePa = document.createElement(QString("%1Text").arg(nodeString)); |
| 933 |
|
| 934 |
QDomText errorTextNode = document.createTextNode(errorText); |
| 935 |
errorNode.setAttribute("error",errorText); |
| 936 |
|
| 937 |
errorTextNodePa.appendChild(errorTextNode); |
| 938 |
errorNode.appendChild(errorTextNodePa); |
| 939 |
|
| 940 |
return errorNode; |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
QString COWLLinkRecordInterpreter::getErrorLevelString(double level) { |
| 945 |
QString logLevelString; |
| 946 |
if (level >= 90) { |
| 947 |
logLevelString = "catastrophic error"; |
| 948 |
} else if (level >= 80) { |
| 949 |
logLevelString = "exception error"; |
| 950 |
} else if (level >= 70) { |
| 951 |
logLevelString = "error"; |
| 952 |
} else if (level >= 60) { |
| 953 |
logLevelString = "warning"; |
| 954 |
} else if (level >= 30) { |
| 955 |
logLevelString = "info"; |
| 956 |
} else { |
| 957 |
logLevelString = "notice"; |
| 958 |
} |
| 959 |
return logLevelString; |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
QString COWLLinkRecordInterpreter::getErrorString(CCommandRecordData *recData, const QString &nodeString) { |
| 964 |
QString errorText; |
| 965 |
if (recData) { |
| 966 |
errorText = QString("An error has occurred while processing '%1',\n%2 process protocol:\n").arg(recData->getCommand()->getBriefCommandDescription()).arg(nodeString); |
| 967 |
|
| 968 |
CCommandRecordData *nextRecData = recData; |
| 969 |
|
| 970 |
while (nextRecData) { |
| 971 |
errorText += QString("{%3}, [%1]:%2\n").arg(nextRecData->getRecordDomain()).arg(nextRecData->getRecordMessage()).arg(getErrorLevelString(nextRecData->getRecordErrorLevel())); |
| 972 |
nextRecData = nextRecData->getNextCommandRecordData(); |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
CCommand *command = recData->getCommand(); |
| 978 |
CLinker<CCommand *> *subCommIt = command->getSubCommandLinker(); |
| 979 |
QString subNodeString = QString("Sub-%1").arg(nodeString); |
| 980 |
while (subCommIt) { |
| 981 |
CCommand *subCommand = subCommIt->getData(); |
| 982 |
if (subCommand->getMaxErrorLevel() > 0) { |
| 983 |
CCommandRecordData *subCommandRecData = subCommand->getRecordData(); |
| 984 |
if (subCommandRecData) { |
| 985 |
QString subErrorString = QString("{%1}, %2").arg(getErrorLevelString(subCommand->getMaxErrorLevel())).arg(getErrorString(subCommandRecData,subNodeString)); |
| 986 |
errorText += subErrorString; |
| 987 |
} |
| 988 |
} |
| 989 |
subCommIt = subCommIt->getNext(); |
| 990 |
} |
| 991 |
|
| 992 |
} else { |
| 993 |
errorText = QString("An error has occurred while processing, process Interface not available"); |
| 994 |
} |
| 995 |
return errorText; |
| 996 |
} |
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
QDomElement COWLLinkRecordInterpreter::getOneOfStringConfigNode(const QString &keyString, const QString &oneOfOptions, const QString &defaultOption, const QString &nodeString) { |
| 1001 |
QDomElement configNode = document.createElement(nodeString); |
| 1002 |
configNode.setAttribute("key",getOWLLinkMappedConfigString(keyString)); |
| 1003 |
|
| 1004 |
QDomElement oneOfNode = document.createElement("OneOf"); |
| 1005 |
oneOfNode.setAttribute("abbreviatedIRI","xsd:string"); |
| 1006 |
configNode.appendChild(oneOfNode); |
| 1007 |
|
| 1008 |
QStringList optionsList(oneOfOptions); |
| 1009 |
foreach (QString optionString, optionsList) { |
| 1010 |
QDomElement litNode = document.createElement("Literal"); |
| 1011 |
QDomText optTextNode = document.createTextNode(optionString); |
| 1012 |
litNode.appendChild(optTextNode); |
| 1013 |
oneOfNode.appendChild(litNode); |
| 1014 |
} |
| 1015 |
|
| 1016 |
QDomElement litNode = document.createElement("Literal"); |
| 1017 |
QDomText optTextNode = document.createTextNode(defaultOption); |
| 1018 |
litNode.appendChild(optTextNode); |
| 1019 |
configNode.appendChild(litNode); |
| 1020 |
|
| 1021 |
return configNode; |
| 1022 |
} |
| 1023 |
|
| 1024 |
|
| 1025 |
QDomElement COWLLinkRecordInterpreter::getBooleanConfigNode(const QString &keyString, const QString &defaultValue, const QString &nodeString) { |
| 1026 |
QDomElement configNode = document.createElement(nodeString); |
| 1027 |
configNode.setAttribute("key",getOWLLinkMappedConfigString(keyString)); |
| 1028 |
|
| 1029 |
QDomElement datatypeNode = document.createElement("Datatype"); |
| 1030 |
datatypeNode.setAttribute("abbreviatedIRI","xsd:boolean"); |
| 1031 |
configNode.appendChild(datatypeNode); |
| 1032 |
|
| 1033 |
QDomElement litNode = document.createElement("Literal"); |
| 1034 |
QDomText optTextNode = document.createTextNode(defaultValue); |
| 1035 |
litNode.appendChild(optTextNode); |
| 1036 |
configNode.appendChild(litNode); |
| 1037 |
|
| 1038 |
return configNode; |
| 1039 |
} |
| 1040 |
|
| 1041 |
QDomElement COWLLinkRecordInterpreter::getIntegerConfigNode(const QString &keyString, qint64 integer, const QString &nodeString) { |
| 1042 |
QDomElement configNode = document.createElement(nodeString); |
| 1043 |
configNode.setAttribute("key",getOWLLinkMappedConfigString(keyString)); |
| 1044 |
|
| 1045 |
QDomElement datatypeNode = document.createElement("Datatype"); |
| 1046 |
datatypeNode.setAttribute("abbreviatedIRI","xsd:integer"); |
| 1047 |
configNode.appendChild(datatypeNode); |
| 1048 |
|
| 1049 |
QDomElement litNode = document.createElement("Literal"); |
| 1050 |
QDomText optTextNode = document.createTextNode(QString::number(integer)); |
| 1051 |
litNode.appendChild(optTextNode); |
| 1052 |
configNode.appendChild(litNode); |
| 1053 |
|
| 1054 |
return configNode; |
| 1055 |
} |
| 1056 |
|
| 1057 |
QDomElement COWLLinkRecordInterpreter::getStringConfigNode(const QString &keyString, const QString &defaultValue, const QString &nodeString) { |
| 1058 |
QDomElement configNode = document.createElement(nodeString); |
| 1059 |
configNode.setAttribute("key",getOWLLinkMappedConfigString(keyString)); |
| 1060 |
|
| 1061 |
QDomElement datatypeNode = document.createElement("Datatype"); |
| 1062 |
datatypeNode.setAttribute("abbreviatedIRI","xsd:string"); |
| 1063 |
configNode.appendChild(datatypeNode); |
| 1064 |
|
| 1065 |
QDomElement litNode = document.createElement("Literal"); |
| 1066 |
QDomText optTextNode = document.createTextNode(defaultValue); |
| 1067 |
litNode.appendChild(optTextNode); |
| 1068 |
configNode.appendChild(litNode); |
| 1069 |
|
| 1070 |
return configNode; |
| 1071 |
} |
| 1072 |
|
| 1073 |
QByteArray COWLLinkRecordInterpreter::getByteArray() { |
| 1074 |
return document.toString().toUtf8(); |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
QString COWLLinkRecordInterpreter::getOWLLinkMappedConfigString(const QString &keyName) { |
| 1079 |
if (keyName == "Konclude.OWLlink.AbbreviatedIRIs") { |
| 1080 |
return QString("abbreviatesIRIs"); |
| 1081 |
} |
| 1082 |
return keyName; |
| 1083 |
} |
| 1084 |
|
| 1085 |
}; // end namespace OWLlink |
| 1086 |
|
| 1087 |
}; // end namespace Interface |
| 1088 |
|
| 1089 |
}; // end namespace Control |
| 1090 |
|
| 1091 |
}; // end namespace Konclude |