| 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 "CEquivalentPropertiesResultVisitCallbackQuery.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CEquivalentPropertiesResultVisitCallbackQuery::CEquivalentPropertiesResultVisitCallbackQuery(CConcreteOntology* ontology, CConfigurationBase* configuration, CRole* role, bool dataProperty, const QString& propertyName, const QString& queryName) |
| 32 |
: CObjectDataPropertyClassificationPremisingQuery(ontology,configuration,dataProperty) { |
| 33 |
mPropertyName = propertyName; |
| 34 |
mRole = role; |
| 35 |
mQueryName = queryName; |
| 36 |
|
| 37 |
if (mPropertyName.isEmpty()) { |
| 38 |
mQueryString = QString("Get Equivalent Properties"); |
| 39 |
} else { |
| 40 |
mQueryString = QString("Get Equivalent Properties for '%1'").arg(mPropertyName); |
| 41 |
} |
| 42 |
mResult = nullptr; |
| 43 |
|
| 44 |
mClassificationCalcError = false; |
| 45 |
mQueryConstructError = false; |
| 46 |
|
| 47 |
mNode = nullptr; |
| 48 |
|
| 49 |
mCalcConfig = configuration; |
| 50 |
} |
| 51 |
|
| 52 |
CEquivalentPropertiesResultVisitCallbackQuery::~CEquivalentPropertiesResultVisitCallbackQuery() { |
| 53 |
if (mResult) { |
| 54 |
delete mResult; |
| 55 |
} |
| 56 |
delete mCalcConfig; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
CQueryResult* CEquivalentPropertiesResultVisitCallbackQuery::getQueryResult() { |
| 61 |
return mResult; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
CQueryResult *CEquivalentPropertiesResultVisitCallbackQuery::constructResult(CClassification* classification) { |
| 66 |
if (mResult) { |
| 67 |
delete mResult; |
| 68 |
mResult = 0; |
| 69 |
} |
| 70 |
CPropertyRoleClassification* roleClassification = nullptr; |
| 71 |
if (isDataPropertyQuery()) { |
| 72 |
roleClassification = classification->getDataPropertyRoleClassification(); |
| 73 |
} else { |
| 74 |
roleClassification = classification->getObjectPropertyRoleClassification(); |
| 75 |
} |
| 76 |
if (roleClassification) { |
| 77 |
CRolePropertiesHierarchy* hierarchy = roleClassification->getRolePropertiesHierarchy(); |
| 78 |
mNode = hierarchy->getHierarchyNode(mRole); |
| 79 |
} |
| 80 |
if (mNode) { |
| 81 |
mResult = new CSucceedQueryResult(); |
| 82 |
} |
| 83 |
return mResult; |
| 84 |
} |
| 85 |
|
| 86 |
bool CEquivalentPropertiesResultVisitCallbackQuery::callbackVisitingProperties(CEntityExpressionSetResultVisitingCallback* visitingCallback) { |
| 87 |
if (mNode) { |
| 88 |
QList<CRole*>* eqRoleList = mNode->getEquivalentRoleList(); |
| 89 |
for (QList<CRole*>::const_iterator it = eqRoleList->constBegin(), itEnd = eqRoleList->constEnd(); it != itEnd; ++it) { |
| 90 |
CRole* role(*it); |
| 91 |
visitingCallback->visitRoleAssociatedEntityExpression(role,mOntology); |
| 92 |
} |
| 93 |
return true; |
| 94 |
} |
| 95 |
return false; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
QString CEquivalentPropertiesResultVisitCallbackQuery::getQueryName() { |
| 100 |
return mQueryName; |
| 101 |
} |
| 102 |
|
| 103 |
QString CEquivalentPropertiesResultVisitCallbackQuery::getQueryString() { |
| 104 |
return mQueryString; |
| 105 |
} |
| 106 |
|
| 107 |
bool CEquivalentPropertiesResultVisitCallbackQuery::hasAnswer() { |
| 108 |
return mResult != 0; |
| 109 |
} |
| 110 |
|
| 111 |
QString CEquivalentPropertiesResultVisitCallbackQuery::getAnswerString() { |
| 112 |
if (!mResult) { |
| 113 |
return QString("Unknown Properties"); |
| 114 |
} else { |
| 115 |
return mResult->getQueryResultString(); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
bool CEquivalentPropertiesResultVisitCallbackQuery::hasError() { |
| 120 |
return mClassificationCalcError || mQueryConstructError || CQuery::hasError(); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
}; // end namespace Query |
| 125 |
|
| 126 |
}; // end namespace Reasoner |
| 127 |
|
| 128 |
}; // end namespace Konclude |