Debian Codegraph @

Source/Reasoner/Revision/Persistence/COntologyRevisionDirectoryOWL2XMLFilePersistencer.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 "COntologyRevisionDirectoryOWL2XMLFilePersistencer.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Revision {
29
30 namespace Persistence {
31
32 COntologyRevisionDirectoryOWL2XMLFilePersistencer::COntologyRevisionDirectoryOWL2XMLFilePersistencer(CConfiguration* config) : COntologyRevisionDirectoryFilePersistencerBase(config) {
33 mConfEnforceUTF8ConvertingParsing = CConfigDataReader::readConfigBoolean(mConfig, "Konclude.Parser.UTF8CompatibilityEnforcedXMLStreamParsing");
34 QString confOWL2XMLBaseDirectory = CConfigDataReader::readConfigString(mConfig, "Konclude.Persistence.DirectoryOWL2XMLFilePersistencer.BaseDirectory", "./Data/Ontologies/Persistence/");
35 if (!confOWL2XMLBaseDirectory.isEmpty()) {
36 mConfBaseDirectory = confOWL2XMLBaseDirectory;
37 }
38 mFileEndingWritingName = CConfigDataReader::readConfigString(mConfig, "Konclude.Persistence.DirectoryOWLRDFFilePersistencer.WritingFileEnding");
39 }
40
41 COntologyRevisionDirectoryOWL2XMLFilePersistencer::~COntologyRevisionDirectoryOWL2XMLFilePersistencer() {
42 }
43
44
45
46 bool COntologyRevisionDirectoryOWL2XMLFilePersistencer::writeOntologyToFile(QFile* file, COntologyRevision* ontoRev) {
47
48 CConcreteOntology* ontology = ontoRev->getOntology();
49
50 COntologyAxiomExpressionsRenderVisitor renderer;
51 COntologyOWL2QtXMLRenderer owlXMLRenderer("");
52
53 CONTOLOGYAXIOMSET<CAxiomExpression*>* currAxiomSet = ontology->getBuildData()->getTellAxiomSet();
54 CQtList<CAxiomExpression*> axiomList;
55 for (CAxiomExpression* axiomExp : *currAxiomSet) {
56 axiomList.append(axiomExp);
57 }
58
59 renderer.visitAndRender(axiomList, ontology, &owlXMLRenderer);
60
61 QList<CTriplesData*> triplesDataList;
62 COntologyTriplesData* ontTriplesData = ontoRev->getOntology()->getOntologyTriplesData();
63 if (ontTriplesData) {
64 for (CTriplesData* tripleData : *ontTriplesData->getAllTriplesData()) {
65 triplesDataList.append(tripleData);
66 }
67 }
68
69 renderer.visitAndRender(&triplesDataList, ontology, &owlXMLRenderer);
70
71
72
73 QDomDocument document;
74 QDomProcessingInstruction procInstHeader = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
75 document.appendChild(procInstHeader);
76 QDomElement rootNode = document.createElementNS(mOWLNS, "Ontology");
77 rootNode.setAttribute("xmlns:owl", mOWLNS);
78 rootNode.setAttribute("xml:base", mOWLNS);
79 rootNode.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema#");
80 rootNode.setAttribute("xmlns:rdfs", "http://www.w3.org/2000/01/rdf-schema#");
81 rootNode.setAttribute("xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
82 rootNode.setAttribute("xmlns:xml", "http://www.w3.org/XML/1998/namespace");
83 document.appendChild(rootNode);
84
85 //<Ontology xmlns = "http://www.w3.org/2002/07/owl#"
86 // xml:base = "http://LUBM-1"
87 // xmlns : rdfs = "http://www.w3.org/2000/01/rdf-schema#"
88 // xmlns : xsd = "http://www.w3.org/2001/XMLSchema#"
89 // xmlns : rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
90 // xmlns : xml = "http://www.w3.org/XML/1998/namespace"
91 // ontologyIRI = "http://LUBM-1">
92 // <Prefix name = "rdf" IRI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" / >
93 // <Prefix name = "rdfs" IRI = "http://www.w3.org/2000/01/rdf-schema#" / >
94 // <Prefix name = "xsd" IRI = "http://www.w3.org/2001/XMLSchema#" / >
95 // <Prefix name = "owl" IRI = "http://www.w3.org/2002/07/owl#" / >
96 owlXMLRenderer.addRenderedAxiomsToDomElement(rootNode);
97
98 const QByteArray& byteArray = document.toByteArray();
99
100 cint64 written = file->write(byteArray);
101 if (written == byteArray.size()) {
102 return true;
103 }
104
105 return false;
106 }
107
108
109
110
111
112
113
114 }; // end namespace Persistence
115
116 }; // end namespace Revision
117
118 }; // end namespace Reasoner
119
120 }; // end namespace Konclude