| 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 "CInstancesQuery.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CInstancesQuery::CInstancesQuery(CConcreteOntology* ontology, CConfigurationBase* configuration, CConcept* concept, bool direct, const QString& conceptName, const QString& flatternedTypeQueryName) |
| 32 |
: CRealizationPremisingQuery(ontology,configuration) { |
| 33 |
mConceptName = conceptName; |
| 34 |
mConcept = concept; |
| 35 |
queryName = flatternedTypeQueryName; |
| 36 |
if (mConceptName.isEmpty()) { |
| 37 |
queryString = QString("Get Instances"); |
| 38 |
} else { |
| 39 |
queryString = QString("Get Instances for Type '%1'").arg(mConceptName); |
| 40 |
} |
| 41 |
mResult = nullptr; |
| 42 |
|
| 43 |
mUseAbbreviatedIRIs = CConfigDataReader::readConfigBoolean(configuration,"Konclude.OWLlink.AbbreviatedIRIs",false); |
| 44 |
mAnonymousIndividuals = CConfigDataReader::readConfigBoolean(configuration, "Konclude.OWLlink.ResultAnonymousIndividualsIntegration", false); |
| 45 |
|
| 46 |
mRealizationCalcError = false; |
| 47 |
mQueryConstructError = false; |
| 48 |
mDirect = direct; |
| 49 |
|
| 50 |
mCalcConfig = configuration; |
| 51 |
|
| 52 |
mDynamicRealisation = true; |
| 53 |
|
| 54 |
mRequiresConceptRealisation = true; |
| 55 |
mRequiresSameIndividualRealisation = true; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
CInstancesQuery::~CInstancesQuery() { |
| 60 |
if (mResult) { |
| 61 |
delete mResult; |
| 62 |
} |
| 63 |
delete mCalcConfig; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
CQueryResult* CInstancesQuery::getQueryResult() { |
| 68 |
return mResult; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
CQueryResult *CInstancesQuery::constructResult(CRealization* realization) { |
| 73 |
return constructIndividualSynsetsResult(realization); |
| 74 |
} |
| 75 |
|
| 76 |
CIndividualSynsetsResult *CInstancesQuery::constructIndividualSynsetsResult(CRealization* realization) { |
| 77 |
if (mResult) { |
| 78 |
delete mResult; |
| 79 |
mResult = 0; |
| 80 |
} |
| 81 |
if (realization) { |
| 82 |
CConceptRealization* conRealization = realization->getConceptRealization(); |
| 83 |
if (conRealization) { |
| 84 |
mResult = new CIndividualSynsetsResult(); |
| 85 |
CIndividualSynsetsResultVisitorGenerator resultGenerator(mResult,mUseAbbreviatedIRIs, mAnonymousIndividuals, mOntology->getIndividualNameResolver()); |
| 86 |
conRealization->visitInstances(mConcept,mDirect,&resultGenerator); |
| 87 |
} |
| 88 |
} |
| 89 |
return mResult; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
QString CInstancesQuery::getQueryName() { |
| 94 |
return queryName; |
| 95 |
} |
| 96 |
|
| 97 |
QString CInstancesQuery::getQueryString() { |
| 98 |
return queryString; |
| 99 |
} |
| 100 |
|
| 101 |
bool CInstancesQuery::hasAnswer() { |
| 102 |
return mResult != 0; |
| 103 |
} |
| 104 |
|
| 105 |
QString CInstancesQuery::getAnswerString() { |
| 106 |
if (!mResult) { |
| 107 |
return QString("Unknown Individuals"); |
| 108 |
} else { |
| 109 |
return mResult->getQueryResultString(); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
bool CInstancesQuery::hasError() { |
| 114 |
return mRealizationCalcError || mQueryConstructError || CQuery::hasError(); |
| 115 |
} |
| 116 |
|
| 117 |
bool CInstancesQuery::isDirect() { |
| 118 |
return mDirect; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
COntologyProcessingDynamicRealizationRequirement* CInstancesQuery::getDynamicRealizationRequirement() { |
| 123 |
return new COntologyProcessingConceptRealizationRequirement(mConcept, mDirect); |
| 124 |
} |
| 125 |
|
| 126 |
}; // end namespace Query |
| 127 |
|
| 128 |
}; // end namespace Reasoner |
| 129 |
|
| 130 |
}; // end namespace Konclude |