| 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 "CReasonerEvaluationEvaluatorOWLlink.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Test { |
| 27 |
|
| 28 |
namespace Evaluation { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
CReasonerEvaluationEvaluatorOWLlink::CReasonerEvaluationEvaluatorOWLlink() { |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
CReasonerEvaluationEvaluatorOWLlink::~CReasonerEvaluationEvaluatorOWLlink() { |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
bool CReasonerEvaluationEvaluatorOWLlink::evaluateResults(CReasonerEvaluationRequestResult* requestResult, CReasonerEvaluationTerminationResult* terminationResult, const QString& inputFileString, const QString& responseFileString, CConfiguration* config) { |
| 41 |
QDomDocument document = createResponseDocument(); |
| 42 |
QDomElement responseNode = document.documentElement(); |
| 43 |
responseNode.setAttribute("response-time",requestResult->getResponseTime()); |
| 44 |
responseNode.setAttribute("test",inputFileString); |
| 45 |
if (!requestResult->getResponsedInTime()) { |
| 46 |
responseNode.setAttribute("timeout",1); |
| 47 |
} else { |
| 48 |
responseNode.setAttribute("timeout",0); |
| 49 |
} |
| 50 |
|
| 51 |
QDateTime dateTime = QDateTime::currentDateTime(); |
| 52 |
responseNode.appendChild(document.createComment(QString("Executed date: %1").arg(dateTime.toString()))); |
| 53 |
|
| 54 |
if (terminationResult->hasProcessError()) { |
| 55 |
responseNode.appendChild(document.createComment(QString("Reasoner error: %1").arg(terminationResult->getErrorText()))); |
| 56 |
} |
| 57 |
|
| 58 |
QString output = terminationResult->getStandardOutputText().replace("--", "##"); |
| 59 |
if (output.isEmpty()) { |
| 60 |
output = terminationResult->getErrorOutputText().replace("--", "##"); |
| 61 |
} |
| 62 |
responseNode.appendChild(document.createComment(QString("Reasoner output:\r\n%1").arg(output))); |
| 63 |
|
| 64 |
|
| 65 |
QList<CReasonerEvaluationRequestResponse*>* responseList = requestResult->getResponseList(); |
| 66 |
foreach (CReasonerEvaluationRequestResponse* response, *responseList) { |
| 67 |
CReasonerEvaluationRequestResponseOWLlink* owllinkResponse = (CReasonerEvaluationRequestResponseOWLlink*)response; |
| 68 |
if (response->isTimedOut()) { |
| 69 |
QDomElement errorElm = document.createElement("Error"); |
| 70 |
errorElm.setAttribute("timeout",1); |
| 71 |
cint64 responseTime = response->getResponseTime(); |
| 72 |
errorElm.setAttribute("response-time",responseTime); |
| 73 |
errorElm.setAttribute("error","timeout"); |
| 74 |
errorElm.setAttribute("request-command", owllinkResponse->getRequestNode().tagName()); |
| 75 |
responseNode.appendChild(errorElm); |
| 76 |
} else if (response->hasResponseError()) { |
| 77 |
QDomElement errorElm = document.createElement("Error"); |
| 78 |
cint64 responseTime = response->getResponseTime(); |
| 79 |
errorElm.setAttribute("response-time",responseTime); |
| 80 |
errorElm.setAttribute("error","unknown error"); |
| 81 |
errorElm.setAttribute("request-command", owllinkResponse->getRequestNode().tagName()); |
| 82 |
responseNode.appendChild(errorElm); |
| 83 |
} else { |
| 84 |
QDomElement domElm = owllinkResponse->getResponseNode(); |
| 85 |
cint64 responseTime = response->getResponseTime(); |
| 86 |
QDomNode importedNode = document.importNode(domElm,true); |
| 87 |
QDomElement impDomElm = importedNode.toElement(); |
| 88 |
impDomElm.setAttribute("response-time",responseTime); |
| 89 |
impDomElm.setAttribute("request-command", owllinkResponse->getRequestNode().tagName()); |
| 90 |
responseNode.appendChild(impDomElm); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
QFile file(responseFileString); |
| 95 |
if (file.open(QIODevice::WriteOnly)) { |
| 96 |
file.write(document.toByteArray()); |
| 97 |
file.close(); |
| 98 |
} |
| 99 |
|
| 100 |
return true; |
| 101 |
} |
| 102 |
|
| 103 |
QDomDocument CReasonerEvaluationEvaluatorOWLlink::createResponseDocument() { |
| 104 |
QDomDocument document; |
| 105 |
|
| 106 |
QString owllinkNS = "http://www.owllink.org/owllink#"; |
| 107 |
QString owlNS = "http://www.w3.org/2002/07/owl#"; |
| 108 |
|
| 109 |
QDomElement rootNode; |
| 110 |
|
| 111 |
rootNode = document.createElementNS(owllinkNS,"ResponseMessage"); |
| 112 |
//rootNode.setAttributeNS("xsi:schemaLocation","http://www.owllink.org/owllink# http://www.owllink.org/owllink-20091116.xsd"); |
| 113 |
rootNode.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance","xsi:schemaLocation","http://www.owllink.org/owllink# http://www.owllink.org/owllink-20091116.xsd"); |
| 114 |
rootNode.setAttribute("xmlns:owl",owlNS); |
| 115 |
document.appendChild(rootNode); |
| 116 |
|
| 117 |
return document; |
| 118 |
} |
| 119 |
|
| 120 |
}; // end namespace Evaluation |
| 121 |
|
| 122 |
}; // end namespace Test |
| 123 |
|
| 124 |
}; // end namespace Konclude |