| 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 "CEquivalentClassesResultVisitCallbackQuery.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CEquivalentClassesResultVisitCallbackQuery::CEquivalentClassesResultVisitCallbackQuery(CConcreteOntology* ontology, CConfigurationBase* configuration, CConcept* concept, const QString& className, const QString& queryName) |
| 32 |
: CTaxonomyPremisingQuery(ontology,configuration) { |
| 33 |
mClassName = className; |
| 34 |
mConcept = concept; |
| 35 |
mQueryName = queryName; |
| 36 |
|
| 37 |
if (mClassName.isEmpty()) { |
| 38 |
mQueryString = QString("Get Equivalent Classes"); |
| 39 |
} else { |
| 40 |
mQueryString = QString("Get Equivalent Classes for '%1'").arg(mClassName); |
| 41 |
} |
| 42 |
mResult = nullptr; |
| 43 |
|
| 44 |
mTaxonomyCalcError = false; |
| 45 |
mQueryConstructError = false; |
| 46 |
|
| 47 |
mNode = nullptr; |
| 48 |
|
| 49 |
mCalcConfig = configuration; |
| 50 |
} |
| 51 |
|
| 52 |
CEquivalentClassesResultVisitCallbackQuery::~CEquivalentClassesResultVisitCallbackQuery() { |
| 53 |
if (mResult) { |
| 54 |
delete mResult; |
| 55 |
} |
| 56 |
delete mCalcConfig; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
CQueryResult* CEquivalentClassesResultVisitCallbackQuery::getQueryResult() { |
| 61 |
return mResult; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
CQueryResult *CEquivalentClassesResultVisitCallbackQuery::constructResult(CTaxonomy *taxonomy) { |
| 66 |
if (mResult) { |
| 67 |
delete mResult; |
| 68 |
mResult = 0; |
| 69 |
} |
| 70 |
mNode = taxonomy->getHierarchyNode(mConcept); |
| 71 |
if (mNode) { |
| 72 |
mResult = new CSucceedQueryResult(); |
| 73 |
} |
| 74 |
return mResult; |
| 75 |
} |
| 76 |
|
| 77 |
bool CEquivalentClassesResultVisitCallbackQuery::callbackVisitingClasses(CEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 78 |
if (mNode) { |
| 79 |
QList<CConcept*>* eqConList = mNode->getEquivalentConceptList(); |
| 80 |
for (QList<CConcept*>::const_iterator it = eqConList->constBegin(), itEnd = eqConList->constEnd(); it != itEnd; ++it) { |
| 81 |
CConcept* concept(*it); |
| 82 |
visitingCallback->visitConceptAssociatedEntityExpression(concept,ontology); |
| 83 |
} |
| 84 |
return true; |
| 85 |
} |
| 86 |
return false; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
QString CEquivalentClassesResultVisitCallbackQuery::getQueryName() { |
| 91 |
return mQueryName; |
| 92 |
} |
| 93 |
|
| 94 |
QString CEquivalentClassesResultVisitCallbackQuery::getQueryString() { |
| 95 |
return mQueryString; |
| 96 |
} |
| 97 |
|
| 98 |
bool CEquivalentClassesResultVisitCallbackQuery::hasAnswer() { |
| 99 |
return mResult != 0; |
| 100 |
} |
| 101 |
|
| 102 |
QString CEquivalentClassesResultVisitCallbackQuery::getAnswerString() { |
| 103 |
if (!mResult) { |
| 104 |
return QString("Unknown Classes"); |
| 105 |
} else { |
| 106 |
return mResult->getQueryResultString(); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
bool CEquivalentClassesResultVisitCallbackQuery::hasError() { |
| 111 |
return mTaxonomyCalcError || mQueryConstructError || CQuery::hasError(); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
}; // end namespace Query |
| 116 |
|
| 117 |
}; // end namespace Reasoner |
| 118 |
|
| 119 |
}; // end namespace Konclude |