| 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 "CSPARQLRecordInterpreter.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Control { |
| 27 |
|
| 28 |
namespace Interface { |
| 29 |
|
| 30 |
namespace SPARQL { |
| 31 |
|
| 32 |
CSPARQLRecordInterpreter::CSPARQLRecordInterpreter(CCommandDelegater *commandDelegater, CConfiguration* config) |
| 33 |
: CCommandRecorder() { |
| 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 |
mConfig = config; |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
CSPARQLRecordInterpreter::~CSPARQLRecordInterpreter() { |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
CCommandDelegater *CSPARQLRecordInterpreter::delegateCommand(CCommand *command) { |
| 52 |
if (dynamic_cast<CCalculateQueryCommand *>(command)) { |
| 53 |
seqSyncMutex.lock(); |
| 54 |
commandSequenceHash.insert(command, nextSeqNumber++); |
| 55 |
seqSyncMutex.unlock(); |
| 56 |
} |
| 57 |
if (delegater) { |
| 58 |
delegater->delegateCommand(command); |
| 59 |
} |
| 60 |
return this; |
| 61 |
} |
| 62 |
|
| 63 |
CCommandRecorder *CSPARQLRecordInterpreter::recordData(CCommandRecordData *recData) { |
| 64 |
CCommandRecorder::recordData(recData); |
| 65 |
if (dynamic_cast<CClosureProcessCommandRecord *>(recData)) { |
| 66 |
if (recData) { |
| 67 |
CCommand *command = recData->getCommand(); |
| 68 |
if (command) { |
| 69 |
|
| 70 |
if (commandSequenceHash.contains(command)) { |
| 71 |
|
| 72 |
|
| 73 |
if (dynamic_cast<CCalculateQueryCommand *>(command)) { |
| 74 |
CCalculateQueryCommand *calcQueryCommand = dynamic_cast<CCalculateQueryCommand *>(command); |
| 75 |
if (calcQueryCommand) { |
| 76 |
if (command->getMaxErrorLevel() <= 0) { |
| 77 |
|
| 78 |
CQuery *query = calcQueryCommand->getQuery(); |
| 79 |
if (query) { |
| 80 |
qint64 seqNumber = commandSequenceHash.value(command); |
| 81 |
if (query->hasError()) { |
| 82 |
QString errorString = query->getErrorStringList().join(" "); |
| 83 |
mSerializer.addResultError(errorString, "Error", seqNumber); |
| 84 |
} else { |
| 85 |
CQueryResult* queryResult = query->getQueryResult(); |
| 86 |
if (queryResult) { |
| 87 |
CVariableBindingsAnswersResult* varIndBindsResult = dynamic_cast<CVariableBindingsAnswersResult*>(queryResult); |
| 88 |
if (varIndBindsResult) { |
| 89 |
mSerializer.addResultSerialization(varIndBindsResult->getVariableNames(), varIndBindsResult, seqNumber); |
| 90 |
|
| 91 |
} |
| 92 |
CBooleanQueryResult* booleanResult = dynamic_cast<CBooleanQueryResult*>(queryResult); |
| 93 |
if (booleanResult) { |
| 94 |
mSerializer.addResultSerialization(booleanResult, seqNumber); |
| 95 |
} |
| 96 |
} |
| 97 |
CQueryStatistics* stats = query->getQueryStatistics(); |
| 98 |
if (stats) { |
| 99 |
mSerializer.addResultStatistics(stats, seqNumber); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
} else { |
| 109 |
qint64 seqNumber = commandSequenceHash.value(command); |
| 110 |
QString errorString = getErrorString(recData, "Error"); |
| 111 |
mSerializer.addResultError(errorString, "Error", seqNumber); |
| 112 |
} |
| 113 |
} |
| 114 |
} else { |
| 115 |
if (command->getMaxErrorLevel() > 0) { |
| 116 |
qint64 seqNumber = commandSequenceHash.value(command); |
| 117 |
QString errorString = getErrorString(recData, "Error"); |
| 118 |
mSerializer.addResultError(errorString, "Error", seqNumber); |
| 119 |
} |
| 120 |
|
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
return this; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
QByteArray CSPARQLRecordInterpreter::getByteArray() { |
| 134 |
return mSerializer.getCombinedResultSerialization(); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
QString CSPARQLRecordInterpreter::getErrorString(CCommandRecordData *recData, const QString &nodeString) { |
| 141 |
QString errorText; |
| 142 |
if (recData) { |
| 143 |
errorText = QString("An error has occurred while processing '%1',\n%2 process protocol:\n").arg(recData->getCommand()->getBriefCommandDescription()).arg(nodeString); |
| 144 |
|
| 145 |
CCommandRecordData *nextRecData = recData; |
| 146 |
|
| 147 |
while (nextRecData) { |
| 148 |
errorText += QString("{%3}, [%1]:%2\n").arg(nextRecData->getRecordDomain()).arg(nextRecData->getRecordMessage()).arg(getErrorLevelString(nextRecData->getRecordErrorLevel())); |
| 149 |
nextRecData = nextRecData->getNextCommandRecordData(); |
| 150 |
} |
| 151 |
|
| 152 |
CCommand *command = recData->getCommand(); |
| 153 |
CLinker<CCommand *> *subCommIt = command->getSubCommandLinker(); |
| 154 |
QString subNodeString = QString("Sub-%1").arg(nodeString); |
| 155 |
while (subCommIt) { |
| 156 |
CCommand *subCommand = subCommIt->getData(); |
| 157 |
if (subCommand->getMaxErrorLevel() > 0) { |
| 158 |
CCommandRecordData *subCommandRecData = subCommand->getRecordData(); |
| 159 |
if (subCommandRecData) { |
| 160 |
QString subErrorString = QString("{%1}, %2").arg(getErrorLevelString(subCommand->getMaxErrorLevel())).arg(getErrorString(subCommandRecData, subNodeString)); |
| 161 |
errorText += subErrorString; |
| 162 |
} |
| 163 |
} |
| 164 |
subCommIt = subCommIt->getNext(); |
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
else { |
| 169 |
errorText = QString("An error has occurred while processing, process Interface not available"); |
| 170 |
} |
| 171 |
return errorText; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
QString CSPARQLRecordInterpreter::getErrorLevelString(double level) { |
| 178 |
QString logLevelString; |
| 179 |
if (level >= 90) { |
| 180 |
logLevelString = "catastrophic error"; |
| 181 |
} |
| 182 |
else if (level >= 80) { |
| 183 |
logLevelString = "exception error"; |
| 184 |
} |
| 185 |
else if (level >= 70) { |
| 186 |
logLevelString = "error"; |
| 187 |
} |
| 188 |
else if (level >= 60) { |
| 189 |
logLevelString = "warning"; |
| 190 |
} |
| 191 |
else if (level >= 30) { |
| 192 |
logLevelString = "info"; |
| 193 |
} |
| 194 |
else { |
| 195 |
logLevelString = "notice"; |
| 196 |
} |
| 197 |
return logLevelString; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
}; // end namespace SPARQL |
| 203 |
|
| 204 |
}; // end namespace Interface |
| 205 |
|
| 206 |
}; // end namespace Control |
| 207 |
|
| 208 |
}; // end namespace Konclude |