Debian Codegraph @

Source/Reasoner/Query/CEquivalentPropertiesQuery.cpp

raw
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 "CEquivalentPropertiesQuery.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Query {
29
30
31 CEquivalentPropertiesQuery::CEquivalentPropertiesQuery(CConcreteOntology* ontology, CConfigurationBase* configuration, CRole* role, const QString& propertyName, bool dataProperties, const QString& queryName)
32 : CObjectDataPropertyClassificationPremisingQuery(ontology,configuration,dataProperties) {
33 mPropertyName = propertyName;
34 mRole = role;
35 mQueryName = queryName;
36 if (mPropertyName.isEmpty()) {
37 mQueryString = QString("Get Equivalent Properties");
38 } else {
39 mQueryString = QString("Get Equivalent Properties for role '%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 mCalcConfig = configuration;
49 }
50
51 CEquivalentPropertiesQuery::~CEquivalentPropertiesQuery() {
52 if (mResult) {
53 delete mResult;
54 }
55 delete mCalcConfig;
56 }
57
58
59 CQueryResult* CEquivalentPropertiesQuery::getQueryResult() {
60 return mResult;
61 }
62
63
64 CQueryResult *CEquivalentPropertiesQuery::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 constructPropertiesResult(roleClassification->getRolePropertiesHierarchy());
73 }
74 return nullptr;
75 }
76
77 CPropertySetResult *CEquivalentPropertiesQuery::constructPropertiesResult(CRolePropertiesHierarchy *hierarchy) {
78 if (mResult) {
79 delete mResult;
80 mResult = 0;
81 }
82 if (hierarchy) {
83 CRolePropertiesHierarchyNode* node = hierarchy->getHierarchyNode(mRole);
84 if (node) {
85 mResult = new CPropertySetResult(mDataPropertiesRolesQuery);
86 foreach (const QString& propertyName, node->getEquivalentRoleStringList(mUseAbbreviatedIRIs)) {
87 mResult->addProperty(propertyName);
88 }
89 }
90 }
91 return mResult;
92 }
93
94
95 QString CEquivalentPropertiesQuery::getQueryName() {
96 return mQueryName;
97 }
98
99 QString CEquivalentPropertiesQuery::getQueryString() {
100 return mQueryString;
101 }
102
103 bool CEquivalentPropertiesQuery::hasAnswer() {
104 return mResult != 0;
105 }
106
107 QString CEquivalentPropertiesQuery::getAnswerString() {
108 if (!mResult) {
109 return QString("Unknown Properties");
110 } else {
111 return mResult->getQueryResultString();
112 }
113 }
114
115 bool CEquivalentPropertiesQuery::hasError() {
116 return mClassificationCalcError || mQueryConstructError || CQuery::hasError();
117 }
118
119
120
121 }; // end namespace Query
122
123 }; // end namespace Reasoner
124
125 }; // end namespace Konclude