| 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 "CReasonerEvaluationGroupRequestReasonerResultCountingAnalyser.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Test { |
| 27 |
|
| 28 |
namespace Evaluation { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
CReasonerEvaluationGroupRequestReasonerResultCountingAnalyser::CReasonerEvaluationGroupRequestReasonerResultCountingAnalyser() { |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
CReasonerEvaluationGroupRequestReasonerResultCountingAnalyser::~CReasonerEvaluationGroupRequestReasonerResultCountingAnalyser() { |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
cint64 CReasonerEvaluationGroupRequestReasonerResultCountingAnalyser::getResultCount(const QString& groupString, const QString& requestString, const QString& reasonerString, CReasonerEvaluationStringListValue* stringListDataValue, const QStringList& reasonerList, const QString& detailedReportingOutputDirectory) { |
| 42 |
cint64 totalResultCount = 0; |
| 43 |
const QStringList& responseFileStringList = stringListDataValue->getValue(); |
| 44 |
if (!responseFileStringList.isEmpty()) { |
| 45 |
QString responseFileString = responseFileStringList.first(); |
| 46 |
QFile responseFile(responseFileString); |
| 47 |
|
| 48 |
QDomDocument document; |
| 49 |
if (responseFile.open(QIODevice::ReadOnly)) { |
| 50 |
document.setContent(&responseFile, false); |
| 51 |
responseFile.close(); |
| 52 |
} |
| 53 |
QDomElement rootEl = document.documentElement(); |
| 54 |
QDomElement resultElement = rootEl.firstChildElement(); |
| 55 |
bool foundResult = false; |
| 56 |
bool foundError = false; |
| 57 |
if (!resultElement.isNull()) { |
| 58 |
while (!resultElement.isNull()) { |
| 59 |
|
| 60 |
if (resultElement.nodeName() == "Error") { |
| 61 |
foundError = true; |
| 62 |
break; |
| 63 |
|
| 64 |
} else if (resultElement.nodeName() == "results") { |
| 65 |
foundResult = true; |
| 66 |
|
| 67 |
cint64 resultCount = 0; |
| 68 |
|
| 69 |
|
| 70 |
if (resultElement.nodeName() == "results") { |
| 71 |
// handle SPARQL binding results |
| 72 |
CVariableBindingsAnswersListResult* variableBindingsResult = nullptr; |
| 73 |
QHash<QString, cint64> variableNameIndexHash; |
| 74 |
if (!variableBindingsResult) { |
| 75 |
variableBindingsResult = mSPARQLResultParser.parseVariableBindingsList(&resultElement, &variableNameIndexHash, true); |
| 76 |
if (variableBindingsResult) { |
| 77 |
resultCount += variableBindingsResult->getResultCount(); |
| 78 |
delete variableBindingsResult; |
| 79 |
} |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
totalResultCount += resultCount; |
| 87 |
|
| 88 |
|
| 89 |
} |
| 90 |
resultElement = resultElement.nextSiblingElement(); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
} |
| 96 |
return totalResultCount; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
bool CReasonerEvaluationGroupRequestReasonerResultCountingAnalyser::analyseGroupedEvaluationData(const QStringList& groubList, const QStringList& requestList, const QStringList& reasonerList, const QString& outputDirectory, CReasonerEvaluationAnalyseContext* context, CReasonerEvaluationGroupRequestSelector* selector) { |
| 105 |
|
| 106 |
mOutputFileName = QString("%1").arg(selector->getOutputString()); |
| 107 |
|
| 108 |
bool hasSelectedRequestFile = false; |
| 109 |
|
| 110 |
QStringList titleList; |
| 111 |
titleList.append("Requests"); |
| 112 |
titleList.append(reasonerList); |
| 113 |
titleList.append("Average"); |
| 114 |
titleList.append("Min"); |
| 115 |
titleList.append("Max"); |
| 116 |
|
| 117 |
QDir outDir(outputDirectory); |
| 118 |
outDir.mkpath(mOutputFileName); |
| 119 |
QString outputFileString(outputDirectory+mOutputFileName+"result-counting"); |
| 120 |
|
| 121 |
QString detailedOutputReportingDirectory = QString(outputDirectory + mOutputFileName + "/result-counting-reports/"); |
| 122 |
outDir.mkpath(mOutputFileName + "/result-counting-reports"); |
| 123 |
|
| 124 |
CReasonerEvaluationTableMultiFormatOutputWriter<double> tableMultiFormatOutputWriter; |
| 125 |
tableMultiFormatOutputWriter.addColumnTitles(titleList); |
| 126 |
|
| 127 |
foreach (QString groupString, groubList) { |
| 128 |
|
| 129 |
if (selector->isGroupSelected(groupString)) { |
| 130 |
|
| 131 |
QSet<QString>* groupRequestList = getGroupRequests(groupString); |
| 132 |
foreach (QString requestString, *groupRequestList) { |
| 133 |
|
| 134 |
if (selector->isRequestSelected(groupString,requestString)) { |
| 135 |
|
| 136 |
bool allDataAvailable = true; |
| 137 |
foreach (QString reasonerString, reasonerList) { |
| 138 |
CReasonerEvaluationDataValue* evalData = getGroupRequestReasonerEvaluationData(groupString,requestString,reasonerString); |
| 139 |
if (!evalData || evalData->hasDataNotAvailableFlag()) { |
| 140 |
allDataAvailable = false; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
if (allDataAvailable) { |
| 146 |
|
| 147 |
hasSelectedRequestFile = true; |
| 148 |
double min = DOUBLE_MAX; |
| 149 |
double max = DOUBLE_MIN; |
| 150 |
double mean = 0.; |
| 151 |
cint64 count = 0; |
| 152 |
|
| 153 |
tableMultiFormatOutputWriter.addNewTableRow(requestString); |
| 154 |
|
| 155 |
foreach (QString reasonerString, reasonerList) { |
| 156 |
CReasonerEvaluationDataValue* evalData = getGroupRequestReasonerEvaluationData(groupString,requestString,reasonerString); |
| 157 |
CReasonerEvaluationDoubleDataValue* doubleDataValue = dynamic_cast<CReasonerEvaluationDoubleDataValue*>(evalData); |
| 158 |
if (doubleDataValue) { |
| 159 |
double resultCountValue = doubleDataValue->getValue(); |
| 160 |
|
| 161 |
tableMultiFormatOutputWriter.addValuesToLastTableRow(QList<double>() << resultCountValue); |
| 162 |
|
| 163 |
mean += resultCountValue; |
| 164 |
min = qMin(min, resultCountValue); |
| 165 |
max = qMax(max, resultCountValue); |
| 166 |
count++; |
| 167 |
} |
| 168 |
|
| 169 |
} |
| 170 |
mean /= (double)count; |
| 171 |
tableMultiFormatOutputWriter.addValuesToLastTableRow(QList<double>()<<mean<<min<<max); |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
if (hasSelectedRequestFile) { |
| 179 |
|
| 180 |
QStringList reasonerCompGNUPlotFileList; |
| 181 |
QStringList reasonerCompHighchartPlotFileList; |
| 182 |
|
| 183 |
tableMultiFormatOutputWriter.buildSortedIndex(); |
| 184 |
reasonerCompHighchartPlotFileList += tableMultiFormatOutputWriter.writeCVSTable(outputFileString); |
| 185 |
reasonerCompHighchartPlotFileList += tableMultiFormatOutputWriter.writeCVSTablesSorted(outputFileString); |
| 186 |
tableMultiFormatOutputWriter.writeCVSTablesSeparateSorted(outputFileString); |
| 187 |
|
| 188 |
if (context->isGNUPlottingActivated()) { |
| 189 |
reasonerCompGNUPlotFileList += tableMultiFormatOutputWriter.writeGNUPlotDataTable(outputFileString); |
| 190 |
reasonerCompGNUPlotFileList += tableMultiFormatOutputWriter.writeGNUPlotDataTablesSorted(outputFileString); |
| 191 |
foreach (QString plotFileString, reasonerCompGNUPlotFileList) { |
| 192 |
if (true /*plotFileString.contains("-by-Average-")*/) { |
| 193 |
QString outputFile = plotFileString; |
| 194 |
outputFile.remove(".dat"); |
| 195 |
QString title = getPrettyTitleFromOutputFile(outputFile); |
| 196 |
context->getGNUPlotPlotter()->createReasonerComparisonPlot(plotFileString,context->getAdditionalTitleString()+title+"[# results]",reasonerList,outputFile); |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
if (context->isHighchartPlottingActivated()) { |
| 201 |
foreach (QString plotFileString, reasonerCompHighchartPlotFileList) { |
| 202 |
if (true /*plotFileString.contains("-by-Average-")*/) { |
| 203 |
QString outputFile = plotFileString; |
| 204 |
outputFile.remove(".csv"); |
| 205 |
QString title = getPrettyTitleFromOutputFile(outputFile); |
| 206 |
context->getHighchartPlotter()->createReasonerCountingPlot(plotFileString,context->getAdditionalTitleString()+title+"[# results]",reasonerList,outputFile,selector->getNameString()+" :: "+context->getAdditionalTitleString()); |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
} |
| 212 |
|
| 213 |
return true; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
QString CReasonerEvaluationGroupRequestReasonerResultCountingAnalyser::getPrettyTitleFromOutputFile(const QString& outputFile) { |
| 219 |
QString title = outputFile; |
| 220 |
title.remove("table"); |
| 221 |
cint64 slashPos = title.lastIndexOf("/"); |
| 222 |
if (slashPos >= 0) { |
| 223 |
title = title.mid(slashPos+1); |
| 224 |
} |
| 225 |
title.replace("-"," "); |
| 226 |
title.replace("result counts","Result Counting, "); |
| 227 |
title.replace("sorted","Sorted"); |
| 228 |
if (title.contains(" ascending")) { |
| 229 |
title.replace(" ascending",""); |
| 230 |
title.append(" in Ascending Order "); |
| 231 |
} |
| 232 |
if (title.contains(" descending")) { |
| 233 |
title.replace(" descending",""); |
| 234 |
title.append(" in Descending Order "); |
| 235 |
} |
| 236 |
return title; |
| 237 |
} |
| 238 |
}; // end namespace Evaluation |
| 239 |
|
| 240 |
}; // end namespace Test |
| 241 |
|
| 242 |
}; // end namespace Konclude |