Debian Codegraph @

Source/Renderer/CRenderWriteManager.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 "CRenderWriteManager.h"
22
23
24 namespace Konclude {
25
26 namespace Renderer {
27
28
29 CRenderWriteManager::CRenderWriteManager() : CLogIdentifier("::Konclude::Renderer::RenderWriteManager",this) {
30 }
31
32 bool CRenderWriteManager::realizeCommand(CCommand* command) {
33 if (dynamic_cast<CWriteOntologyCommand*>(command)) {
34 if (dynamic_cast<CWriteOWL2XMLOntologyCommand*>(command)) {
35 CCommandRecordRouter commandRecordRouter(command,this);
36 CStartProcessCommandRecord::makeRecord(&commandRecordRouter);
37
38 CWriteOWL2XMLOntologyCommand* writeOWL2XMLOntC = (CWriteOWL2XMLOntologyCommand*)command;
39 COntologyOWL2QtXMLRenderer* renderer = writeOWL2XMLOntC->getOWL2XMLRenderer();
40 QString writeFileName = writeOWL2XMLOntC->getWriteFileName();
41 QFile file(writeFileName);
42
43 if (file.open(QIODevice::WriteOnly)) {
44
45 QString owlNS = "http://www.w3.org/2002/07/owl#";
46
47 QDomDocument document;
48 QDomElement rootNode = document.createElementNS(owlNS,"Ontology");
49 rootNode.setAttribute("xmlns:owl",owlNS);
50 renderer->addRenderedAxiomsToDomElement(rootNode);
51 document.appendChild(rootNode);
52
53 file.write(document.toByteArray());
54 file.close();
55 }
56
57 CStopProcessCommandRecord::makeRecord(&commandRecordRouter);
58 CFinishProcessCommandRecord::makeRecord(&commandRecordRouter);
59 return true;
60 } else if (dynamic_cast<CWriteOWLlinkOWL2XMLSatisfiableTestCommand*>(command)) {
61 CCommandRecordRouter commandRecordRouter(command,this);
62 CStartProcessCommandRecord::makeRecord(&commandRecordRouter);
63
64 CWriteOWLlinkOWL2XMLSatisfiableTestCommand* writeOWL2XMLOntC = (CWriteOWLlinkOWL2XMLSatisfiableTestCommand*)command;
65 COntologyOWL2QtXMLRenderer* renderer = writeOWL2XMLOntC->getOWL2XMLRenderer();
66 QString writeFileName = writeOWL2XMLOntC->getWriteFileName();
67 QString destKBName = writeOWL2XMLOntC->getTestKBName();
68 QStringList testClassNames = writeOWL2XMLOntC->getSatisfiableTestClassesList();
69 QFile file(writeFileName);
70
71 if (file.open(QIODevice::WriteOnly)) {
72
73 QString owlNS = "http://www.w3.org/2002/07/owl#";
74 QString owllinkNS = "http://www.owllink.org/owllink#";
75
76 QDomDocument document;
77 QDomProcessingInstruction header = document.createProcessingInstruction("xml","version=\"1.0\"");
78 document.appendChild(header);
79 QDomElement rootNode = document.createElementNS(owllinkNS,"RequestMessage");
80 rootNode.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance","xsi:schemaLocation","http://www.owllink.org/owllink# http://www.owllink.org/owllink-20091116.xsd");
81 rootNode.setAttribute("xmlns:owl",owlNS);
82 document.appendChild(rootNode);
83
84
85 QDomElement createOntologyNode = document.createElement("CreateKB");
86 createOntologyNode.setAttribute(QString("kb"),QString(destKBName));
87 rootNode.appendChild(createOntologyNode);
88
89 QDomElement tellOntologyNode = document.createElement("Tell");
90 tellOntologyNode.setAttribute(QString("kb"),QString(destKBName));
91 renderer->addRenderedAxiomsToDomElement(tellOntologyNode);
92 rootNode.appendChild(tellOntologyNode);
93
94
95 foreach (QString testClass, testClassNames) {
96 QDomElement queryOntologyNode = document.createElement("IsClassSatisfiable");
97 queryOntologyNode.setAttribute(QString("kb"),QString(destKBName));
98 queryOntologyNode.setAttribute(QString("timing"),QString("simple"));
99 QDomElement classEl = document.createElement("owl:Class");
100 classEl.setAttribute("IRI",testClass);
101 queryOntologyNode.appendChild(classEl);
102 rootNode.appendChild(queryOntologyNode);
103 }
104
105 QDomElement releaseOntologyNode = document.createElement("ReleaseKB");
106 releaseOntologyNode.setAttribute(QString("kb"),QString(destKBName));
107 rootNode.appendChild(releaseOntologyNode);
108
109 document.appendChild(rootNode);
110
111 file.write(document.toByteArray());
112 file.close();
113 }
114
115 CStopProcessCommandRecord::makeRecord(&commandRecordRouter);
116 CFinishProcessCommandRecord::makeRecord(&commandRecordRouter);
117 return true;
118 }
119 }
120 return false;
121 }
122
123 }; // end namespace Renderer
124
125 }; // end namespace Konclude