| 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 "CReasonerEvaluationFiltering.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Test { |
| 27 |
|
| 28 |
namespace Evaluation { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
CReasonerEvaluationFiltering::CReasonerEvaluationFiltering(const QString& statisticsBasePath) : CLogIdentifier("::Konclude::Test::Evaluation::Filtering",this) { |
| 33 |
mStatisticsBasePath = statisticsBasePath; |
| 34 |
} |
| 35 |
|
| 36 |
bool CReasonerEvaluationFiltering::loadFilterFromFile(const QString& filterNameString) { |
| 37 |
CReasonerEvaluationFilter* filter = new CReasonerEvaluationFilter(); |
| 38 |
LOG(INFO,getLogDomain(),logTr("Loading filter from file '%1'.").arg(filterNameString),this); |
| 39 |
if (filter->loadFilterConditionFile(filterNameString)) { |
| 40 |
mFilterList.append(filter); |
| 41 |
LOG(INFO,getLogDomain(),logTr("Successfully loaded filter from file '%1'.").arg(filterNameString),this); |
| 42 |
return true; |
| 43 |
} else { |
| 44 |
delete filter; |
| 45 |
LOG(ERROR,getLogDomain(),logTr("Loading filter from file '%1' failed.").arg(filterNameString),this); |
| 46 |
return false; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
bool CReasonerEvaluationFiltering::loadEmptyFilter() { |
| 52 |
CReasonerEvaluationFilter* filter = new CReasonerEvaluationFilter(); |
| 53 |
mFilterList.append(filter); |
| 54 |
return true; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
bool CReasonerEvaluationFiltering::loadFiltersFromFile(const QStringList& filterNameStringList) { |
| 59 |
bool loadedOne = false; |
| 60 |
foreach (const QString& fileName, filterNameStringList) { |
| 61 |
loadedOne |= loadFilterFromFile(fileName); |
| 62 |
} |
| 63 |
return loadedOne; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
bool CReasonerEvaluationFiltering::testSatisfiesFilter(const QString& testFileNameString, const QString& testFilePathString, const QString& subDirPathString, const QStringList& statisticList) { |
| 68 |
foreach (CReasonerEvaluationFilter* filter, mFilterList) { |
| 69 |
if (filter->testSatisfiesFilterConditions(testFileNameString,testFilePathString,subDirPathString,statisticList)) { |
| 70 |
return true; |
| 71 |
} |
| 72 |
} |
| 73 |
return false; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
bool CReasonerEvaluationFiltering::testSatisfiesFilter(const QStringList& statisticList) { |
| 78 |
foreach (CReasonerEvaluationFilter* filter, mFilterList) { |
| 79 |
if (filter->testSatisfiesFilterConditions(statisticList)) { |
| 80 |
return true; |
| 81 |
} |
| 82 |
} |
| 83 |
return false; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
bool CReasonerEvaluationFiltering::testSatisfiesFilter(const QString& testFileNameString, const QStringList& statisticList) { |
| 89 |
foreach (CReasonerEvaluationFilter* filter, mFilterList) { |
| 90 |
if (filter->testSatisfiesFilterConditions(testFileNameString,statisticList)) { |
| 91 |
return true; |
| 92 |
} |
| 93 |
} |
| 94 |
return false; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
QStringList CReasonerEvaluationFiltering::loadStatistics(const QString& testFileNameString, const QString& subDirPathString) { |
| 100 |
return loadStatistics(subDirPathString+testFileNameString); |
| 101 |
} |
| 102 |
|
| 103 |
QStringList CReasonerEvaluationFiltering::loadStatistics(const QString& subDirPathTestFileNameString) { |
| 104 |
QString useStatisticsBasePath = mStatisticsBasePath; |
| 105 |
QStringList statisticList; |
| 106 |
QString statisticFileString = useStatisticsBasePath+subDirPathTestFileNameString+".txt"; |
| 107 |
QFile statisticFile(statisticFileString); |
| 108 |
if (statisticFile.open(QIODevice::ReadOnly)) { |
| 109 |
while (!statisticFile.atEnd()) { |
| 110 |
QByteArray statDataLine(statisticFile.readLine()); |
| 111 |
statisticList.append(statDataLine.trimmed()); |
| 112 |
} |
| 113 |
statisticFile.close(); |
| 114 |
} else { |
| 115 |
//LOG(INFO,getLogDomain(),logTr("Could not open statistics file '%1'.").arg(statisticFileString),this); |
| 116 |
} |
| 117 |
return statisticList; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
}; // end namespace Evaluation |
| 122 |
|
| 123 |
}; // end namespace Test |
| 124 |
|
| 125 |
}; // end namespace Konclude |