| 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 "CSubPropertyHierarchyQuery.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CSubPropertyHierarchyQuery::CSubPropertyHierarchyQuery(CConcreteOntology *ontology, CConfigurationBase *configuration, CRole* role, bool dataProperties, const QString &superPropertyName, const QString &subPropertyHierarchyQueryName) |
| 32 |
: CObjectDataPropertyClassificationPremisingQuery(ontology,configuration,dataProperties) { |
| 33 |
mPropertyName = superPropertyName; |
| 34 |
mQueryName = subPropertyHierarchyQueryName; |
| 35 |
mRole = role; |
| 36 |
if (mPropertyName.isEmpty()) { |
| 37 |
mQueryString = QString("Get Subproperty Hierarchy"); |
| 38 |
} else { |
| 39 |
mQueryString = QString("Get Subproperty Hierarchy of property '%1'").arg(mPropertyName); |
| 40 |
} |
| 41 |
mResult = nullptr; |
| 42 |
|
| 43 |
mUseAbbreviatedIRIs = CConfigDataReader::readConfigBoolean(configuration,"Konclude.OWLlink.AbbreviatedIRIs",false); |
| 44 |
|
| 45 |
mClassificationCalcError = false; |
| 46 |
mQueryConstructError = false; |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
CSubPropertyHierarchyQuery::~CSubPropertyHierarchyQuery() { |
| 51 |
if (mResult) { |
| 52 |
delete mResult; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
CQueryResult *CSubPropertyHierarchyQuery::getQueryResult() { |
| 60 |
return mResult; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
CQueryResult *CSubPropertyHierarchyQuery::constructResult(CClassification* classification) { |
| 65 |
CPropertyRoleClassification* roleClassification = nullptr; |
| 66 |
if (isDataPropertyQuery()) { |
| 67 |
roleClassification = classification->getDataPropertyRoleClassification(); |
| 68 |
} else { |
| 69 |
roleClassification = classification->getObjectPropertyRoleClassification(); |
| 70 |
} |
| 71 |
if (roleClassification) { |
| 72 |
return constructSubPropertyHierarchyResult(roleClassification->getRolePropertiesHierarchy()); |
| 73 |
} |
| 74 |
return nullptr; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
CPropertyHierarchyResult *CSubPropertyHierarchyQuery::constructSubPropertyHierarchyResult(CRolePropertiesHierarchy *hierarchy) { |
| 79 |
if (mResult) { |
| 80 |
delete mResult; |
| 81 |
mResult = nullptr; |
| 82 |
} |
| 83 |
CRolePropertiesHierarchyNode *topNode = hierarchy->getTopHierarchyNode(); |
| 84 |
if (!mPropertyName.isEmpty()) { |
| 85 |
topNode = hierarchy->getHierarchyNode(mRole); |
| 86 |
} |
| 87 |
CRolePropertiesHierarchyNode *bottomNode = hierarchy->getBottomHierarchyNode(); |
| 88 |
if (topNode) { |
| 89 |
mResult = new CPropertyHierarchyResult(bottomNode->getEquivalentRoleStringList(mUseAbbreviatedIRIs),topNode->getEquivalentRoleStringList(mUseAbbreviatedIRIs), mDataPropertiesRolesQuery); |
| 90 |
QList<CRolePropertiesHierarchyNode *> processNodeList; |
| 91 |
QSet<CRolePropertiesHierarchyNode *> processNodeSet; |
| 92 |
processNodeList.append(topNode); |
| 93 |
while (!processNodeList.isEmpty()) { |
| 94 |
CRolePropertiesHierarchyNode *procNode = processNodeList.takeFirst(); |
| 95 |
QSet<CRolePropertiesHierarchyNode *>* childNodeSet(procNode->getChildNodeSet()); |
| 96 |
foreach (CRolePropertiesHierarchyNode *childNode, *childNodeSet) { |
| 97 |
if (childNode != bottomNode) { |
| 98 |
mResult->addSubPropertyRelation(mResult->getPropertySynset(procNode->getEquivalentRoleStringList(mUseAbbreviatedIRIs)),mResult->getPropertySynset(childNode->getEquivalentRoleStringList(mUseAbbreviatedIRIs))); |
| 99 |
if (!processNodeSet.contains(childNode)) { |
| 100 |
processNodeSet.insert(childNode); |
| 101 |
processNodeList.append(childNode); |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
return mResult; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
QString CSubPropertyHierarchyQuery::getQueryName() { |
| 112 |
return mQueryName; |
| 113 |
} |
| 114 |
|
| 115 |
QString CSubPropertyHierarchyQuery::getQueryString() { |
| 116 |
return mQueryString; |
| 117 |
} |
| 118 |
|
| 119 |
bool CSubPropertyHierarchyQuery::hasAnswer() { |
| 120 |
return mResult != 0; |
| 121 |
} |
| 122 |
|
| 123 |
QString CSubPropertyHierarchyQuery::getAnswerString() { |
| 124 |
if (!mResult) { |
| 125 |
return QString("Unknown Subproperty Hierarchy"); |
| 126 |
} else { |
| 127 |
return mResult->getQueryResultString(); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
bool CSubPropertyHierarchyQuery::hasError() { |
| 133 |
return mClassificationCalcError || mQueryConstructError || CQuery::hasError(); |
| 134 |
} |
| 135 |
|
| 136 |
}; // end namespace Query |
| 137 |
|
| 138 |
}; // end namespace Reasoner |
| 139 |
|
| 140 |
}; // end namespace Konclude |