| 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 "CSourceTargetBetweenPropertiesQuery.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CSourceTargetBetweenPropertiesQuery::CSourceTargetBetweenPropertiesQuery(CConcreteOntology* ontology, CConfigurationBase* configuration, const CIndividualReference& sourceIndi, const QString& sourceIndiName, const CIndividualReference& targetIndi, const QString& targetIndiName, const QString& queryName) |
| 32 |
: CRealizationPremisingQuery(ontology,configuration) { |
| 33 |
|
| 34 |
mSourceIndiName = sourceIndiName; |
| 35 |
mTargetIndiName = targetIndiName; |
| 36 |
mSourceIndi = sourceIndi; |
| 37 |
mTargetIndi = targetIndi; |
| 38 |
|
| 39 |
mQueryName = queryName; |
| 40 |
if (mQueryName.isEmpty()) { |
| 41 |
if (!mSourceIndiName.isEmpty() && mTargetIndiName.isEmpty()) { |
| 42 |
mQueryString = QString("Get properties between %1 and %2").arg(mSourceIndiName).arg(mTargetIndiName); |
| 43 |
} else if (!mSourceIndiName.isEmpty()) { |
| 44 |
mQueryString = QString("Get properties for source individual %1").arg(mSourceIndiName); |
| 45 |
} else if (!mTargetIndiName.isEmpty()) { |
| 46 |
mQueryString = QString("Get properties for target individual %1").arg(mTargetIndiName); |
| 47 |
} else { |
| 48 |
mQueryString = QString("Unknown get properties query"); |
| 49 |
} |
| 50 |
} |
| 51 |
mResult = nullptr; |
| 52 |
|
| 53 |
mUseAbbreviatedIRIs = CConfigDataReader::readConfigBoolean(configuration,"Konclude.OWLlink.AbbreviatedIRIs",false); |
| 54 |
|
| 55 |
mRealizationCalcError = false; |
| 56 |
mQueryConstructError = false; |
| 57 |
|
| 58 |
mRequiresRoleRealisation = true; |
| 59 |
mRequiresSameIndividualRealisation = true; |
| 60 |
mDynamicRealisation = true; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
CSourceTargetBetweenPropertiesQuery::~CSourceTargetBetweenPropertiesQuery() { |
| 65 |
if (mResult) { |
| 66 |
delete mResult; |
| 67 |
} |
| 68 |
delete mCalcConfig; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
CQueryResult* CSourceTargetBetweenPropertiesQuery::getQueryResult() { |
| 74 |
return mResult; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
CQueryResult *CSourceTargetBetweenPropertiesQuery::constructResult(CRealization* realization) { |
| 79 |
if (realization && realization->getRoleRealization()) { |
| 80 |
return constructPropertySynsetsResult(realization->getRoleRealization()); |
| 81 |
} |
| 82 |
return nullptr; |
| 83 |
} |
| 84 |
|
| 85 |
CPropertySynsetsResult *CSourceTargetBetweenPropertiesQuery::constructPropertySynsetsResult(CRoleRealization *roleRealization) { |
| 86 |
if (mResult) { |
| 87 |
delete mResult; |
| 88 |
mResult = 0; |
| 89 |
} |
| 90 |
if (roleRealization && (mSourceIndi.isNonEmpty() || mTargetIndi.isNonEmpty())) { |
| 91 |
mResult = new CPropertySynsetsResult(false); |
| 92 |
CPropertySynsetsResultVisitorGenerator propSynsetResVisGen(mResult, mUseAbbreviatedIRIs); |
| 93 |
if (mSourceIndi.isNonEmpty() && mTargetIndi.isNonEmpty()) { |
| 94 |
roleRealization->visitBetweeenIndividualRoles(mSourceIndi,mTargetIndi,&propSynsetResVisGen); |
| 95 |
} else if (mSourceIndi.isNonEmpty()) { |
| 96 |
roleRealization->visitSourceIndividualRoles(mSourceIndi,&propSynsetResVisGen); |
| 97 |
} else if (mTargetIndi.isNonEmpty()) { |
| 98 |
roleRealization->visitTargetIndividualRoles(mTargetIndi,&propSynsetResVisGen); |
| 99 |
} |
| 100 |
} |
| 101 |
return mResult; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
QString CSourceTargetBetweenPropertiesQuery::getQueryName() { |
| 106 |
return mQueryName; |
| 107 |
} |
| 108 |
|
| 109 |
QString CSourceTargetBetweenPropertiesQuery::getQueryString() { |
| 110 |
return mQueryString; |
| 111 |
} |
| 112 |
|
| 113 |
bool CSourceTargetBetweenPropertiesQuery::hasAnswer() { |
| 114 |
return mResult != 0; |
| 115 |
} |
| 116 |
|
| 117 |
QString CSourceTargetBetweenPropertiesQuery::getAnswerString() { |
| 118 |
if (!mResult) { |
| 119 |
return QString("Unknown Properties"); |
| 120 |
} else { |
| 121 |
return mResult->getQueryResultString(); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
bool CSourceTargetBetweenPropertiesQuery::hasError() { |
| 126 |
return mRealizationCalcError || mQueryConstructError || CQuery::hasError(); |
| 127 |
} |
| 128 |
|
| 129 |
COntologyProcessingDynamicRealizationRequirement* CSourceTargetBetweenPropertiesQuery::getDynamicRealizationRequirement() { |
| 130 |
if (mSourceIndi.isNonEmpty() && mTargetIndi.isNonEmpty()) { |
| 131 |
return new COntologyProcessingRoleRealizationRequirement(nullptr, false, mSourceIndi, mTargetIndi); |
| 132 |
} else if (mSourceIndi.isNonEmpty()) { |
| 133 |
return new COntologyProcessingRoleRealizationRequirement(nullptr, false, mSourceIndi, CIndividualReference()); |
| 134 |
} else if (mTargetIndi.isNonEmpty()) { |
| 135 |
return new COntologyProcessingRoleRealizationRequirement(nullptr, false, CIndividualReference(), mTargetIndi); |
| 136 |
} |
| 137 |
return nullptr; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
}; // end namespace Query |
| 142 |
|
| 143 |
}; // end namespace Reasoner |
| 144 |
|
| 145 |
}; // end namespace Konclude |