Debian Codegraph @

Source/Control/Loader/CCLISatisfiabilityBatchProcessingLoader.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 "CCLISatisfiabilityBatchProcessingLoader.h"
22
23
24 namespace Konclude {
25
26 namespace Control {
27
28 namespace Loader {
29
30
31 CCLISatisfiabilityBatchProcessingLoader::CCLISatisfiabilityBatchProcessingLoader() {
32 }
33
34
35
36 CCLISatisfiabilityBatchProcessingLoader::~CCLISatisfiabilityBatchProcessingLoader() {
37 }
38
39
40
41
42 void CCLISatisfiabilityBatchProcessingLoader::createTestingCommands() {
43 createSatisfiabilityTesingCommands();
44 }
45
46
47 void CCLISatisfiabilityBatchProcessingLoader::createSatisfiabilityTesingCommands() {
48 logOutputMessage(QString("Starting satisfiability 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 CProcessClassNameSatisfiableQueryCommand* consistencyKBCommand = new CProcessClassNameSatisfiableQueryCommand(testKB,mIRINameString);
56 addProcessingCommand(createKBCommand);
57 addProcessingCommand(loadKBCommand);
58 addProcessingCommand(consistencyKBCommand,false,"",true,mResponseFileString);
59 processNextCommand();
60 }
61
62
63 void CCLISatisfiabilityBatchProcessingLoader::writeCommandOutput(const QString& outputFileName, CCommand* processedCommand) {
64 bool outputWritten = false;
65 CKnowledgeBaseQueryCommand* kbQueryCommand = dynamic_cast<CKnowledgeBaseQueryCommand*>(processedCommand);
66 if (kbQueryCommand) {
67 CQuery* query = kbQueryCommand->getCalculateQueryCommand()->getQuery();
68 if (query) {
69 CQueryResult* queryResult = query->getQueryResult();
70 if (queryResult) {
71 CBooleanQueryResult* boolQueryResult = dynamic_cast<CBooleanQueryResult*>(queryResult);
72 if (boolQueryResult) {
73 outputWritten = true;
74 if (boolQueryResult->getResult() == true) {
75 logOutputMessage(QString("Class '%1' for ontology '%2' is satisfiable.").arg(mIRINameString).arg(mRequestFileString));
76 } else {
77 logOutputMessage(QString("Class '%1' for ontology '%2' is not satisfiable.").arg(mIRINameString).arg(mRequestFileString));
78 }
79
80 if (!outputFileName.isEmpty()) {
81 forcedPathCreated(outputFileName);
82 QFile outputFile(outputFileName);
83 if (outputFile.open(QIODevice::WriteOnly)) {
84 QString outputData;
85 if (boolQueryResult->getResult() == true) {
86 outputData = QString("true\n");
87 } else {
88 outputData = QString("false\n");
89 }
90 outputFile.write(outputData.toUtf8());
91 outputFile.close();
92 } else {
93 logOutputError(QString("Failed writing output to file '%1'.").arg(outputFileName));
94 }
95 }
96 }
97 }
98 }
99 }
100 if (!outputWritten) {
101 logOutputError("Satisfiability checking failed.");
102 }
103 }
104
105
106
107 }; // end namespace Loader
108
109 }; // end namespace Control
110
111 }; // end namespace Konclude