Debian Codegraph @

Source/Control/Loader/CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader.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 "CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader.h"
22
23
24 namespace Konclude {
25
26 namespace Control {
27
28 namespace Loader {
29
30
31 CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader::CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader() {
32 loaderConfig = nullptr;
33 }
34
35
36
37 CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader::~CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader() {
38 }
39
40
41 CLoader *CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader::init(CLoaderFactory *loaderFactory, CConfiguration *config) {
42 loaderConfig = config;
43 mInputDir = CConfigDataReader::readConfigString(config,"Konclude.Test.Generator.InputDirectory");
44 if (!mInputDir.endsWith("/")) {
45 mInputDir += QString("/");
46 }
47 mResponseStatisticsOutputDir = CConfigDataReader::readConfigString(config,"Konclude.Test.Generator.OutputDirectory");
48 if (!mResponseStatisticsOutputDir.endsWith("/")) {
49 mResponseStatisticsOutputDir += QString("/");
50 }
51
52 mOntologyStatisticsDir = CConfigDataReader::readConfigString(config,"Konclude.Test.Generator.OntologyStatisticsDirectory");
53 if (!mOntologyStatisticsDir.endsWith("/")) {
54 mOntologyStatisticsDir += QString("/");
55 }
56
57 return this;
58 }
59
60 QStringList CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader::collectOntologyIRIs(const QDomElement& element) {
61 QStringList iriList;
62 if (element.tagName() == "OntologyIRI") {
63 QString iri = element.attribute("IRI");
64 if (!iri.isEmpty()) {
65 iriList.append(iri);
66 }
67 }
68 QDomElement childElement = element.firstChildElement();
69 while (!childElement.isNull()) {
70 iriList += collectOntologyIRIs(childElement);
71 childElement = childElement.nextSiblingElement();
72 }
73 return iriList;
74 }
75
76
77 QStringList CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader::collectOntologyIRIsStatistics(const QStringList& ontoIRIList) {
78 QStringList statisticList;
79 if (ontoIRIList.size() == 1) {
80 QString ontologyIRI = ontoIRIList.first();
81 if (ontologyIRI.startsWith("file:")) {
82 ontologyIRI.replace(0,5,"");
83 }
84 if (ontologyIRI.startsWith("Evaluation/")) {
85 ontologyIRI.replace(0,11,"");
86 }
87 if (ontologyIRI.startsWith("Ontologies/")) {
88 ontologyIRI.replace(0,11,"");
89 }
90 QString ontoStatFileString = mOntologyStatisticsDir+ontologyIRI+".txt";
91 QFile ontoStatFile(ontoStatFileString);
92 if (ontoStatFile.open(QIODevice::ReadOnly)) {
93 while (!ontoStatFile.atEnd()) {
94 QByteArray statDataLine(ontoStatFile.readLine());
95 statisticList.append(statDataLine.trimmed());
96 }
97 ontoStatFile.close();
98 }
99 }
100 return statisticList;
101 }
102
103
104 CLoader* CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader::collectTestcasesStatisticsForTestcase(const QString& testFileNameString, const QString& testFilePathString, const QString& subDirPathString) {
105
106 QFile testcasteFile(testFilePathString+testFileNameString);
107 if (testcasteFile.open(QIODevice::ReadOnly)) {
108 QDomDocument document;
109 document.setContent(&testcasteFile,true);
110 QDomElement documentElement(document.documentElement());
111 QStringList ontologyIRIs = collectOntologyIRIs(documentElement);
112 testcasteFile.close();
113
114 QStringList statList = collectOntologyIRIsStatistics(ontologyIRIs);
115 if (!statList.isEmpty()) {
116 QDir outputDir(mResponseStatisticsOutputDir);
117 outputDir.mkpath(subDirPathString);
118 QString responseStatFileString(mResponseStatisticsOutputDir+subDirPathString+testFileNameString+".txt");
119 QFile responseStatFile(responseStatFileString);
120 if (responseStatFile.open(QIODevice::WriteOnly)) {
121 responseStatFile.write(statList.join("\r\n").toLocal8Bit());
122 responseStatFile.close();
123 }
124 }
125 }
126
127 return this;
128 }
129
130
131 CLoader* CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader::collectTestcasesStatisticsForDirectory(const QString& dirString, const QString& subDirPathString) {
132 QDir inputDir(dirString);
133 foreach (const QString& subDirString, inputDir.entryList(QDir::Dirs)) {
134 if (subDirString != ".." && subDirString != ".") {
135 collectTestcasesStatisticsForDirectory(dirString+subDirString+"/",subDirPathString+subDirString+"/");
136 }
137 }
138 foreach (const QString& fileString, inputDir.entryList(QDir::Files)) {
139
140 collectTestcasesStatisticsForTestcase(fileString,dirString,subDirPathString);
141
142 }
143 LOG(INFO,"::Konclude::Generator::TestCaseGenerator",logTr("Generated test cases for all files in %1.").arg(dirString),this);
144 return this;
145 }
146
147
148 CLoader *CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader::load() {
149 collectTestcasesStatisticsForDirectory(mInputDir,"");
150 return this;
151 }
152
153
154
155
156 CLoader *CReasonerEvaluationTestcaseStatisticCollectionGeneratorLoader::exit() {
157 return this;
158 }
159
160
161
162 }; // end namespace Loader
163
164 }; // end namespace Control
165
166 }; // end namespace Konclude