| 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 "CWriteQueryFileOWL2XMLSerializer.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CWriteQueryFileOWL2XMLSerializer::CWriteQueryFileOWL2XMLSerializer(const QString& fileString) : CWriteQueryFileSerializer(fileString) { |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
bool CWriteQueryFileOWL2XMLSerializer::startWritingOutput() { |
| 37 |
if (CWriteQueryFileSerializer::startWritingOutput()) { |
| 38 |
|
| 39 |
mCurrentOutputStreamWriter = new QXmlStreamWriter(mCurrentOutputFile); |
| 40 |
mCurrentOutputStreamWriter->setAutoFormatting(true); |
| 41 |
mCurrentOutputStreamWriter->writeStartDocument(); |
| 42 |
return true; |
| 43 |
} |
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
bool CWriteQueryFileOWL2XMLSerializer::endWritingOutput() { |
| 50 |
if (mCurrentOutputFile) { |
| 51 |
mCurrentOutputStreamWriter->writeEndDocument(); |
| 52 |
mCurrentOutputFile->close(); |
| 53 |
delete mCurrentOutputStreamWriter; |
| 54 |
delete mCurrentOutputFile; |
| 55 |
return true; |
| 56 |
} |
| 57 |
return false; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
void CWriteQueryFileOWL2XMLSerializer::writeObjectPropertyEquivalenceRelations(const QStringList& propertyNameList) { |
| 63 |
mCurrentOutputStreamWriter->writeStartElement("EquivalentObjectProperties"); |
| 64 |
foreach (const QString& propertyName, propertyNameList) { |
| 65 |
mCurrentOutputStreamWriter->writeStartElement("ObjectProperty"); |
| 66 |
mCurrentOutputStreamWriter->writeAttribute("IRI",propertyName); |
| 67 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 68 |
} |
| 69 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 70 |
} |
| 71 |
|
| 72 |
void CWriteQueryFileOWL2XMLSerializer::writeDataPropertyEquivalenceRelations(const QStringList& propertyNameList) { |
| 73 |
mCurrentOutputStreamWriter->writeStartElement("EquivalentDataProperties"); |
| 74 |
foreach (const QString& propertyName, propertyNameList) { |
| 75 |
mCurrentOutputStreamWriter->writeStartElement("DataProperty"); |
| 76 |
mCurrentOutputStreamWriter->writeAttribute("IRI",propertyName); |
| 77 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 78 |
} |
| 79 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
void CWriteQueryFileOWL2XMLSerializer::writeClassEquivalenceRelations(const QStringList& classNameList) { |
| 86 |
mCurrentOutputStreamWriter->writeStartElement("EquivalentClasses"); |
| 87 |
foreach (const QString& className, classNameList) { |
| 88 |
mCurrentOutputStreamWriter->writeStartElement("Class"); |
| 89 |
mCurrentOutputStreamWriter->writeAttribute("IRI",className); |
| 90 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 91 |
} |
| 92 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
void CWriteQueryFileOWL2XMLSerializer::writeClassDeclaration(const QString& className) { |
| 100 |
mCurrentOutputStreamWriter->writeStartElement("Declaration"); |
| 101 |
mCurrentOutputStreamWriter->writeStartElement("Class"); |
| 102 |
mCurrentOutputStreamWriter->writeAttribute("IRI",className); |
| 103 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 104 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
void CWriteQueryFileOWL2XMLSerializer::writeObjectPropertyDeclaration(const QString& propertyName) { |
| 109 |
mCurrentOutputStreamWriter->writeStartElement("Declaration"); |
| 110 |
mCurrentOutputStreamWriter->writeStartElement("ObjectProperty"); |
| 111 |
mCurrentOutputStreamWriter->writeAttribute("IRI",propertyName); |
| 112 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 113 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 114 |
} |
| 115 |
|
| 116 |
void CWriteQueryFileOWL2XMLSerializer::writeDataPropertyDeclaration(const QString& propertyName) { |
| 117 |
mCurrentOutputStreamWriter->writeStartElement("Declaration"); |
| 118 |
mCurrentOutputStreamWriter->writeStartElement("DataProperty"); |
| 119 |
mCurrentOutputStreamWriter->writeAttribute("IRI",propertyName); |
| 120 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 121 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
void CWriteQueryFileOWL2XMLSerializer::writeOntologyStart() { |
| 128 |
mCurrentOutputStreamWriter->writeStartElement("Ontology"); |
| 129 |
mCurrentOutputStreamWriter->writeAttribute("xmlns:rdfs","http://www.w3.org/2000/01/rdf-schema#"); |
| 130 |
mCurrentOutputStreamWriter->writeAttribute("xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#"); |
| 131 |
mCurrentOutputStreamWriter->writeAttribute("xmlns","http://www.w3.org/2002/07/owl#"); |
| 132 |
mCurrentOutputStreamWriter->writeAttribute("xmlns:xml","http://www.w3.org/XML/1998/namespace"); |
| 133 |
mCurrentOutputStreamWriter->writeAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema#"); |
| 134 |
|
| 135 |
writeOntologyPrefix("","http://www.w3.org/2002/07/owl#"); |
| 136 |
writeOntologyPrefix("owl","http://www.w3.org/2002/07/owl#"); |
| 137 |
writeOntologyPrefix("rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#"); |
| 138 |
writeOntologyPrefix("xml","http://www.w3.org/XML/1998/namespace"); |
| 139 |
writeOntologyPrefix("xsd","http://www.w3.org/2001/XMLSchema#"); |
| 140 |
writeOntologyPrefix("rdfs","http://www.w3.org/2000/01/rdf-schema#"); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
void CWriteQueryFileOWL2XMLSerializer::writeOntologyPrefix(const QString& prefixName, const QString& prefixIRI) { |
| 146 |
mCurrentOutputStreamWriter->writeStartElement("Prefix"); |
| 147 |
mCurrentOutputStreamWriter->writeAttribute("name",prefixName); |
| 148 |
mCurrentOutputStreamWriter->writeAttribute("IRI",prefixIRI); |
| 149 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
void CWriteQueryFileOWL2XMLSerializer::writeOntologyEnd() { |
| 154 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
void CWriteQueryFileOWL2XMLSerializer::writeSubClassRelation(const QString& subClassName, const QString& superClassName) { |
| 161 |
mCurrentOutputStreamWriter->writeStartElement("SubClassOf"); |
| 162 |
mCurrentOutputStreamWriter->writeStartElement("Class"); |
| 163 |
mCurrentOutputStreamWriter->writeAttribute("IRI",subClassName); |
| 164 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 165 |
mCurrentOutputStreamWriter->writeStartElement("Class"); |
| 166 |
mCurrentOutputStreamWriter->writeAttribute("IRI",superClassName); |
| 167 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 168 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 169 |
} |
| 170 |
|
| 171 |
void CWriteQueryFileOWL2XMLSerializer::writeSubObjectPropertyRelation(const QString& subPropertyName, const QString& superPropertyName) { |
| 172 |
mCurrentOutputStreamWriter->writeStartElement("SubObjectPropertyOf"); |
| 173 |
mCurrentOutputStreamWriter->writeStartElement("ObjectProperty"); |
| 174 |
mCurrentOutputStreamWriter->writeAttribute("IRI",subPropertyName); |
| 175 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 176 |
mCurrentOutputStreamWriter->writeStartElement("ObjectProperty"); |
| 177 |
mCurrentOutputStreamWriter->writeAttribute("IRI",superPropertyName); |
| 178 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 179 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 180 |
} |
| 181 |
|
| 182 |
void CWriteQueryFileOWL2XMLSerializer::writeSubDataPropertyRelation(const QString& subPropertyName, const QString& superPropertyName) { |
| 183 |
mCurrentOutputStreamWriter->writeStartElement("SubDataPropertyOf"); |
| 184 |
mCurrentOutputStreamWriter->writeStartElement("DataProperty"); |
| 185 |
mCurrentOutputStreamWriter->writeAttribute("IRI",subPropertyName); |
| 186 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 187 |
mCurrentOutputStreamWriter->writeStartElement("DataProperty"); |
| 188 |
mCurrentOutputStreamWriter->writeAttribute("IRI",superPropertyName); |
| 189 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 190 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
void CWriteQueryFileOWL2XMLSerializer::writeNamedIndividualType(const QString& individualName, const QString& className) { |
| 195 |
mCurrentOutputStreamWriter->writeStartElement("ClassAssertion"); |
| 196 |
mCurrentOutputStreamWriter->writeStartElement("Class"); |
| 197 |
mCurrentOutputStreamWriter->writeAttribute("IRI",className); |
| 198 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 199 |
mCurrentOutputStreamWriter->writeStartElement("NamedIndividual"); |
| 200 |
mCurrentOutputStreamWriter->writeAttribute("IRI",individualName); |
| 201 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 202 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
void CWriteQueryFileOWL2XMLSerializer::writeAnonymousIndividualType(const QString& individualName, const QString& className) { |
| 207 |
mCurrentOutputStreamWriter->writeStartElement("ClassAssertion"); |
| 208 |
mCurrentOutputStreamWriter->writeStartElement("Class"); |
| 209 |
mCurrentOutputStreamWriter->writeAttribute("IRI", className); |
| 210 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 211 |
mCurrentOutputStreamWriter->writeStartElement("AnonymousIndividual"); |
| 212 |
mCurrentOutputStreamWriter->writeAttribute("nodeID", individualName); |
| 213 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 214 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 215 |
} |
| 216 |
|
| 217 |
void CWriteQueryFileOWL2XMLSerializer::writeNamedIndividualDeclaration(const QString& className) { |
| 218 |
mCurrentOutputStreamWriter->writeStartElement("Declaration"); |
| 219 |
mCurrentOutputStreamWriter->writeStartElement("NamedIndividual"); |
| 220 |
mCurrentOutputStreamWriter->writeAttribute("IRI",className); |
| 221 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 222 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
void CWriteQueryFileOWL2XMLSerializer::writeAnonymousIndividualDeclaration(const QString& className) { |
| 227 |
mCurrentOutputStreamWriter->writeStartElement("Declaration"); |
| 228 |
mCurrentOutputStreamWriter->writeStartElement("AnonymousIndividual"); |
| 229 |
mCurrentOutputStreamWriter->writeAttribute("nodeID", className); |
| 230 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 231 |
mCurrentOutputStreamWriter->writeEndElement(); |
| 232 |
} |
| 233 |
|
| 234 |
}; // end namespace Query |
| 235 |
|
| 236 |
}; // end namespace Reasoner |
| 237 |
|
| 238 |
}; // end namespace Konclude |