Debian Codegraph @

Source/Test/COWLFileOWLlinkRealizeRequestGenerator.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 "COWLFileOWLlinkRealizeRequestGenerator.h"
22
23
24 namespace Konclude {
25
26 namespace Test {
27
28
29
30 COWLFileOWLlinkRealizeRequestGenerator::COWLFileOWLlinkRealizeRequestGenerator(CConfiguration *config)
31 : CLogIdentifier("::Konclude::Test::OWLFileOWLlinkIndividualifyRequestGenerator",this),mConfig(config) {
32
33
34 mReasonerTestKBName = "http://www.konclude.com/evaluation-testsuite/test-ontology";
35 }
36
37
38 COWLFileOWLlinkRealizeRequestGenerator::~COWLFileOWLlinkRealizeRequestGenerator() {
39 }
40
41
42
43 QDomDocument COWLFileOWLlinkRealizeRequestGenerator::createRequestDocument() {
44 QDomDocument document;
45
46 QString owllinkNS = "http://www.owllink.org/owllink#";
47 QString owlNS = "http://www.w3.org/2002/07/owl#";
48
49 QDomElement rootNode;
50
51 rootNode = document.createElementNS(owllinkNS,"RequestMessage");
52 rootNode.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance","xsi:schemaLocation","http://www.owllink.org/owllink# http://www.owllink.org/owllink-20091116.xsd");
53 rootNode.setAttribute("xmlns:owl",owlNS);
54 document.appendChild(rootNode);
55
56 return document;
57 }
58
59
60 QSet<QString> COWLFileOWLlinkRealizeRequestGenerator::loadIndividualEntities(const QString& requestFileName) {
61
62 CConcreteOntologyEntityCollectorBuilder entityGenBuilder;
63 COWL2QtXMLOntologyStreamParser* owl2Parser = new COWL2QtXMLOntologyStreamParser(&entityGenBuilder);
64 owl2Parser->parseOntology(requestFileName);
65 delete owl2Parser;
66
67 QSet<QString> individualNameSet = *entityGenBuilder.getIndividualNameSet();
68 return individualNameSet;
69 }
70
71
72
73 bool COWLFileOWLlinkRealizeRequestGenerator::generateOWLlinkRealizeRequest(const QString& requestFileName, const QString& responseFileName) {
74 bool generatedTestfiles = false;
75 QSet<QString> individualNameTestingSet;
76 QSet<QString> individualNameSet = loadIndividualEntities(requestFileName);
77
78 if (!individualNameSet.isEmpty()) {
79
80 QDomDocument requestDocument = createRequestDocument();
81 QDomElement rootElement = requestDocument.documentElement();
82
83 QDomElement cKBElement = requestDocument.createElement("CreateKB");
84 cKBElement.setAttribute("kb",mReasonerTestKBName);
85 rootElement.appendChild(cKBElement);
86
87 QDomElement loadElement = requestDocument.createElement("LoadOntologies");
88 loadElement.setAttribute("kb",mReasonerTestKBName);
89 QDomElement ontoIRIElement = requestDocument.createElement("OntologyIRI");
90 ontoIRIElement.setAttribute("IRI",QString("file:%1").arg(requestFileName));
91 loadElement.appendChild(ontoIRIElement);
92 rootElement.appendChild(loadElement);
93
94 QDomElement realizeKBElement = requestDocument.createElement("Realize");
95 realizeKBElement.setAttribute("kb",mReasonerTestKBName);
96 rootElement.appendChild(realizeKBElement);
97
98 QDomElement releaseKBElement = requestDocument.createElement("ReleaseKB");
99 releaseKBElement.setAttribute("kb",mReasonerTestKBName);
100 rootElement.appendChild(releaseKBElement);
101
102 QFile outFile(responseFileName);
103 if (outFile.open(QIODevice::WriteOnly)) {
104 outFile.write(requestDocument.toByteArray());
105 outFile.close();
106 }
107
108 LOG(INFO,getLogDomain(),logTr("Generated OWLlink realize request '%1' for ontology '%2'.").arg(responseFileName).arg(requestFileName),this);
109
110 generatedTestfiles = true;
111 }
112 return generatedTestfiles;
113 }
114
115
116
117 }; // end namespace Test
118
119 }; // end namespace Konclude