| 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 "CSubClassesQuery.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CSubClassesQuery::CSubClassesQuery(CConcreteOntology* ontology, CConfigurationBase* configuration, CConcept* concept, bool direct, const QString& className, const QString& queryName) |
| 32 |
: CTaxonomyPremisingQuery(ontology,configuration) { |
| 33 |
mClassName = className; |
| 34 |
mConcept = concept; |
| 35 |
mQueryName = queryName; |
| 36 |
if (mClassName.isEmpty()) { |
| 37 |
mQueryString = QString("Get Sub Classes"); |
| 38 |
} else { |
| 39 |
mQueryString = QString("Get Sub Classes for concept '%1'").arg(mClassName); |
| 40 |
} |
| 41 |
mResult = nullptr; |
| 42 |
|
| 43 |
mUseAbbreviatedIRIs = CConfigDataReader::readConfigBoolean(configuration,"Konclude.OWLlink.AbbreviatedIRIs",false); |
| 44 |
|
| 45 |
mTaxonomyCalcError = false; |
| 46 |
mQueryConstructError = false; |
| 47 |
mDirect = direct; |
| 48 |
|
| 49 |
mCalcConfig = configuration; |
| 50 |
} |
| 51 |
|
| 52 |
CSubClassesQuery::~CSubClassesQuery() { |
| 53 |
if (mResult) { |
| 54 |
delete mResult; |
| 55 |
} |
| 56 |
delete mCalcConfig; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
CQueryResult* CSubClassesQuery::getQueryResult() { |
| 61 |
return mResult; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
CQueryResult *CSubClassesQuery::constructResult(CTaxonomy *taxonomy) { |
| 66 |
return constructClassSynsetsResult(taxonomy); |
| 67 |
} |
| 68 |
|
| 69 |
CClassSynsetsResult *CSubClassesQuery::constructClassSynsetsResult(CTaxonomy *taxonomy) { |
| 70 |
if (mResult) { |
| 71 |
delete mResult; |
| 72 |
mResult = 0; |
| 73 |
} |
| 74 |
if (taxonomy) { |
| 75 |
CHierarchyNode* node = taxonomy->getHierarchyNode(mConcept); |
| 76 |
if (node) { |
| 77 |
mResult = new CClassSynsetsResult(); |
| 78 |
QSet<CHierarchyNode*>* visitedHierNodeSet = nullptr; |
| 79 |
if (!mDirect) { |
| 80 |
visitedHierNodeSet = new QSet<CHierarchyNode*>(); |
| 81 |
} |
| 82 |
QList<CHierarchyNode*> visitHierNodetList; |
| 83 |
QSet<CHierarchyNode*>* childNodeSet = node->getChildNodeSet(); |
| 84 |
for (QSet<CHierarchyNode*>::const_iterator it = childNodeSet->constBegin(), itEnd = childNodeSet->constEnd(); it != itEnd; ++it) { |
| 85 |
CHierarchyNode* childNode(*it); |
| 86 |
visitHierNodetList.append(childNode); |
| 87 |
} |
| 88 |
|
| 89 |
while (!visitHierNodetList.isEmpty()) { |
| 90 |
CHierarchyNode* nextNode = visitHierNodetList.takeFirst(); |
| 91 |
CClassSynsetResult* nextSubClassSynset = new CClassSynsetResult(nextNode->getEquivalentConceptStringList(mUseAbbreviatedIRIs)); |
| 92 |
mResult->addClassSynset(nextSubClassSynset); |
| 93 |
if (!mDirect) { |
| 94 |
QSet<CHierarchyNode*>* tmpChildNodeSet = nextNode->getChildNodeSet(); |
| 95 |
for (QSet<CHierarchyNode*>::const_iterator it = tmpChildNodeSet->constBegin(), itEnd = tmpChildNodeSet->constEnd(); it != itEnd; ++it) { |
| 96 |
CHierarchyNode* nextChildNode(*it); |
| 97 |
if (!visitedHierNodeSet->contains(nextChildNode)) { |
| 98 |
visitedHierNodeSet->insert(nextChildNode); |
| 99 |
visitHierNodetList.append(nextChildNode); |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
delete visitedHierNodeSet; |
| 105 |
|
| 106 |
} |
| 107 |
} |
| 108 |
return mResult; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
QString CSubClassesQuery::getQueryName() { |
| 113 |
return mQueryName; |
| 114 |
} |
| 115 |
|
| 116 |
QString CSubClassesQuery::getQueryString() { |
| 117 |
return mQueryString; |
| 118 |
} |
| 119 |
|
| 120 |
bool CSubClassesQuery::hasAnswer() { |
| 121 |
return mResult != 0; |
| 122 |
} |
| 123 |
|
| 124 |
QString CSubClassesQuery::getAnswerString() { |
| 125 |
if (!mResult) { |
| 126 |
return QString("Unknown Classes"); |
| 127 |
} else { |
| 128 |
return mResult->getQueryResultString(); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
bool CSubClassesQuery::hasError() { |
| 133 |
return mTaxonomyCalcError || mQueryConstructError || CQuery::hasError(); |
| 134 |
} |
| 135 |
|
| 136 |
bool CSubClassesQuery::isDirect() { |
| 137 |
return mDirect; |
| 138 |
} |
| 139 |
|
| 140 |
}; // end namespace Query |
| 141 |
|
| 142 |
}; // end namespace Reasoner |
| 143 |
|
| 144 |
}; // end namespace Konclude |