| 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 "CCLIConsistencyBatchProcessingLoader.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Control { |
| 27 |
|
| 28 |
namespace Loader { |
| 29 |
|
| 30 |
|
| 31 |
CCLIConsistencyBatchProcessingLoader::CCLIConsistencyBatchProcessingLoader() { |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
CCLIConsistencyBatchProcessingLoader::~CCLIConsistencyBatchProcessingLoader() { |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
void CCLIConsistencyBatchProcessingLoader::createTestingCommands() { |
| 43 |
createConsistencyTestingCommands(); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
void CCLIConsistencyBatchProcessingLoader::createConsistencyTestingCommands() { |
| 48 |
logOutputMessage(QString("Starting consistency checking for '%1'.").arg(mRequestFileString)); |
| 49 |
QString testKB = QString("http://konclude.com/test/kb"); |
| 50 |
CCreateKnowledgeBaseCommand* createKBCommand = new CCreateKnowledgeBaseCommand(testKB); |
| 51 |
QStringList ontoIRIList; |
| 52 |
ontoIRIList.append(mRequestFileString); |
| 53 |
//CLoadKnowledgeBaseOWLXMLOntologyCommand* loadKBCommand = new CLoadKnowledgeBaseOWLXMLOntologyCommand(testKB,ontoIRIList); |
| 54 |
CLoadKnowledgeBaseOWLAutoOntologyCommand* loadKBCommand = new CLoadKnowledgeBaseOWLAutoOntologyCommand(testKB,ontoIRIList); |
| 55 |
mConsistencyKBCommand = new CIsConsistentQueryCommand(testKB); |
| 56 |
mTriviallyConsistencyKBCommand = new CIsTriviallyConsistentQueryCommand(testKB); |
| 57 |
addProcessingCommand(createKBCommand); |
| 58 |
addProcessingCommand(loadKBCommand); |
| 59 |
addProcessingCommand(mTriviallyConsistencyKBCommand,false,"",true,mResponseFileString); |
| 60 |
processNextCommand(); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
void CCLIConsistencyBatchProcessingLoader::writeCommandOutput(const QString& outputFileName, CCommand* processedCommand) { |
| 65 |
bool outputWritten = false; |
| 66 |
bool requiresDetailedConsistencyChecking = true; |
| 67 |
CKnowledgeBaseQueryCommand* kbQueryCommand = dynamic_cast<CKnowledgeBaseQueryCommand*>(processedCommand); |
| 68 |
if (kbQueryCommand) { |
| 69 |
CQuery* query = kbQueryCommand->getCalculateQueryCommand()->getQuery(); |
| 70 |
if (query) { |
| 71 |
CQueryResult* queryResult = query->getQueryResult(); |
| 72 |
if (queryResult) { |
| 73 |
CBooleanQueryResult* boolQueryResult = dynamic_cast<CBooleanQueryResult*>(queryResult); |
| 74 |
if (boolQueryResult) { |
| 75 |
bool writeOutput = false; |
| 76 |
if (boolQueryResult->getResult() == true) { |
| 77 |
requiresDetailedConsistencyChecking = false; |
| 78 |
writeOutput = true; |
| 79 |
logOutputMessage(QString("Ontology '%1' is consistent.").arg(mRequestFileString)); |
| 80 |
} else { |
| 81 |
if (processedCommand == mConsistencyKBCommand) { |
| 82 |
requiresDetailedConsistencyChecking = false; |
| 83 |
writeOutput = true; |
| 84 |
logOutputMessage(QString("Ontology '%1' is inconsistent.").arg(mRequestFileString)); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
if (writeOutput) { |
| 89 |
outputWritten = true; |
| 90 |
if (!outputFileName.isEmpty()) { |
| 91 |
forcedPathCreated(outputFileName); |
| 92 |
QFile outputFile(outputFileName); |
| 93 |
if (outputFile.open(QIODevice::WriteOnly)) { |
| 94 |
QString outputData; |
| 95 |
if (boolQueryResult->getResult() == true) { |
| 96 |
outputData = QString("true\n"); |
| 97 |
} else { |
| 98 |
outputData = QString("false\n"); |
| 99 |
} |
| 100 |
outputFile.write(outputData.toUtf8()); |
| 101 |
outputFile.close(); |
| 102 |
} else { |
| 103 |
logOutputError(QString("Failed writing output to file '%1'.").arg(outputFileName)); |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
if (requiresDetailedConsistencyChecking) { |
| 112 |
addProcessingCommand(mConsistencyKBCommand,false,"",true,mResponseFileString); |
| 113 |
} else if (!outputWritten) { |
| 114 |
logOutputError("Consistency checking failed."); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
}; // end namespace Loader |
| 121 |
|
| 122 |
}; // end namespace Control |
| 123 |
|
| 124 |
}; // end namespace Konclude |