| 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 "CSubClassHierarchyQuery.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CSubClassHierarchyQuery::CSubClassHierarchyQuery(CConcreteOntology *premisingTaxonomyOntology, CTaxonomyPremisingQuerySupport *taxonomyQuerySupport, CConfigurationBase *configuration, const QString &superClassName, const QString &subClassHierarchyQueryName) |
| 32 |
: CTaxonomyPremisingQuery(premisingTaxonomyOntology,configuration) { |
| 33 |
className = superClassName; |
| 34 |
queryName = subClassHierarchyQueryName; |
| 35 |
if (className.isEmpty()) { |
| 36 |
queryString = QString("Get Subclass Hierarchy"); |
| 37 |
} else { |
| 38 |
queryString = QString("Get Subclass Hierarchy of class '%1'").arg(className); |
| 39 |
} |
| 40 |
result = 0; |
| 41 |
taxQuerySupport = taxonomyQuerySupport; |
| 42 |
|
| 43 |
useAbbreviatedIRIs = CConfigDataReader::readConfigBoolean(configuration,"Konclude.OWLlink.AbbreviatedIRIs",false); |
| 44 |
|
| 45 |
mTaxCalcError = false; |
| 46 |
mQueryConstructError = false; |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
CSubClassHierarchyQuery::~CSubClassHierarchyQuery() { |
| 51 |
if (result) { |
| 52 |
delete result; |
| 53 |
} |
| 54 |
if (taxQuerySupport) { |
| 55 |
delete taxQuerySupport; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
CQueryResult *CSubClassHierarchyQuery::getQueryResult() { |
| 61 |
return result; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
CQueryResult *CSubClassHierarchyQuery::constructResult(CTaxonomy *taxonomy) { |
| 66 |
return constructSubClassHierarchyResult(taxonomy); |
| 67 |
} |
| 68 |
|
| 69 |
CClassHierarchyResult *CSubClassHierarchyQuery::constructSubClassHierarchyResult(CTaxonomy *taxonomy) { |
| 70 |
if (result) { |
| 71 |
delete result; |
| 72 |
result = 0; |
| 73 |
} |
| 74 |
CHierarchyNode *topNode = taxonomy->getTopHierarchyNode(); |
| 75 |
if (!className.isEmpty()) { |
| 76 |
topNode = taxonomy->getHierarchyNode(ontology->getConcept(className)); |
| 77 |
} |
| 78 |
CHierarchyNode *bottomNode = taxonomy->getBottomHierarchyNode(); |
| 79 |
if (topNode) { |
| 80 |
result = new CClassHierarchyResult(bottomNode->getEquivalentConceptStringList(useAbbreviatedIRIs),topNode->getEquivalentConceptStringList(useAbbreviatedIRIs)); |
| 81 |
QList<CHierarchyNode *> processNodeList; |
| 82 |
QSet<CHierarchyNode *> processNodeSet; |
| 83 |
processNodeList.append(topNode); |
| 84 |
while (!processNodeList.isEmpty()) { |
| 85 |
CHierarchyNode *procNode = processNodeList.takeFirst(); |
| 86 |
QSet<CHierarchyNode *>* childNodeSet(procNode->getChildNodeSet()); |
| 87 |
foreach (CHierarchyNode *childNode, *childNodeSet) { |
| 88 |
if (childNode != bottomNode) { |
| 89 |
result->addSubClassRelation(result->getClassSynset(procNode->getEquivalentConceptStringList(useAbbreviatedIRIs)),result->getClassSynset(childNode->getEquivalentConceptStringList(useAbbreviatedIRIs))); |
| 90 |
if (!processNodeSet.contains(childNode)) { |
| 91 |
processNodeSet.insert(childNode); |
| 92 |
processNodeList.append(childNode); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
return result; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
QString CSubClassHierarchyQuery::getQueryName() { |
| 103 |
return queryName; |
| 104 |
} |
| 105 |
|
| 106 |
QString CSubClassHierarchyQuery::getQueryString() { |
| 107 |
return queryString; |
| 108 |
} |
| 109 |
|
| 110 |
bool CSubClassHierarchyQuery::hasAnswer() { |
| 111 |
return result != 0; |
| 112 |
} |
| 113 |
|
| 114 |
QString CSubClassHierarchyQuery::getAnswerString() { |
| 115 |
if (!result) { |
| 116 |
return QString("Unknown Subclass Hierarchy"); |
| 117 |
} else { |
| 118 |
return result->getQueryResultString(); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
CResultInterceptionData *CSubClassHierarchyQuery::getPossibleResultInterception() { |
| 123 |
return 0; |
| 124 |
} |
| 125 |
|
| 126 |
CTaxonomyPremisingQuerySupport *CSubClassHierarchyQuery::getTaxonomyQuerySupport() { |
| 127 |
return taxQuerySupport; |
| 128 |
} |
| 129 |
|
| 130 |
bool CSubClassHierarchyQuery::hasError() { |
| 131 |
return mTaxCalcError || mQueryConstructError || CQuery::hasError(); |
| 132 |
} |
| 133 |
|
| 134 |
}; // end namespace Query |
| 135 |
|
| 136 |
}; // end namespace Reasoner |
| 137 |
|
| 138 |
}; // end namespace Konclude |