Debian Codegraph @

Source/Test/Evaluation/CReasonerEvaluationClassificationTimeExtractor.cpp

raw
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 "CReasonerEvaluationClassificationTimeExtractor.h"
22
23
24 namespace Konclude {
25
26 namespace Test {
27
28 namespace Evaluation {
29
30
31
32 CReasonerEvaluationClassificationTimeExtractor::CReasonerEvaluationClassificationTimeExtractor(double timelimit, double errorPunishmentTime, CReasonerEvaluationDataValueCacher* cacher) {
33 mTimelimit = timelimit;
34 mErrorPunishmentTime = errorPunishmentTime;
35 mCacher = cacher;
36
37 mExtractorType = CLASSIFICATIONTIMEEXTRACTOR;
38 }
39
40
41 CReasonerEvaluationClassificationTimeExtractor::~CReasonerEvaluationClassificationTimeExtractor() {
42 }
43
44 CReasonerEvaluationDataValue* CReasonerEvaluationClassificationTimeExtractor::extractEvaluationData(const QString& responseFileString) {
45 CReasonerEvaluationDoubleDataValue* doubleEvalValue = nullptr;
46
47 if (mCacher) {
48 doubleEvalValue = dynamic_cast<CReasonerEvaluationDoubleDataValue*>(mCacher->getCachedDataValue(responseFileString,(cint64)mExtractorType));
49 }
50
51 if (!doubleEvalValue) {
52 double doubleValue = 0;
53 bool errorOccured = false;
54 bool timeoutOccured = false;
55 bool allRespTimeValid = true;
56 QFile responseFile(responseFileString);
57 if (responseFile.open(QIODevice::ReadOnly)) {
58 QDomDocument document;
59 document.setContent(&responseFile,false);
60 QDomElement rootEl = document.documentElement();
61 responseFile.close();
62
63
64 QString timeoutString = rootEl.attribute("timeout");
65 if (timeoutString == "1") {
66 timeoutOccured = true;
67 }
68
69 QDomElement childEl = rootEl.firstChildElement();
70 while (!childEl.isNull()) {
71 timeoutString = rootEl.attribute("timeout");
72 if (timeoutString == "1") {
73 timeoutOccured = true;
74 }
75
76 QString requestCommandString = childEl.attribute("request-command");
77 if (requestCommandString == "GetSubClassHierarchy" || requestCommandString == "Classify" || requestCommandString == "GetSubClasses" || requestCommandString == "GetSuperClasses" || requestCommandString == "GetEquivalentClasses") {
78 bool validResponseTime = false;
79 if (childEl.tagName() != "Error") {
80 QString respTimeString = childEl.attribute("response-time","timeout");
81 double respTime = respTimeString.toDouble(&validResponseTime);
82 if (validResponseTime) {
83 doubleValue += respTime;
84 }
85 } else {
86 validResponseTime = false;
87 }
88 allRespTimeValid &= validResponseTime;
89 }
90 childEl = childEl.nextSiblingElement();
91 }
92
93 if (timeoutOccured) {
94 doubleValue = mTimelimit;
95 }
96 if (mTimelimit >= 0) {
97 doubleValue = qMin(mTimelimit,doubleValue);
98 }
99 if (errorOccured || !allRespTimeValid) {
100 if (mTimelimit >= 0) {
101 doubleValue = mTimelimit+mErrorPunishmentTime;
102 } else {
103 doubleValue = mErrorPunishmentTime;
104 }
105 }
106 doubleEvalValue = new CReasonerEvaluationDoubleDataValue(doubleValue);
107
108 if (mCacher) {
109 mCacher->addDataValueToCache(responseFileString,(cint64)mExtractorType,doubleEvalValue);
110 }
111 }
112
113 }
114 return doubleEvalValue;
115 }
116
117
118 }; // end namespace Evaluation
119
120 }; // end namespace Test
121
122 }; // end namespace Konclude