Debian Codegraph @

Source/Reasoner/Query/CSuperClassesQuery.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 "CSuperClassesQuery.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Query {
29
30
31 CSuperClassesQuery::CSuperClassesQuery(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 Super Classes");
38 } else {
39 mQueryString = QString("Get Super 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 CSuperClassesQuery::~CSuperClassesQuery() {
53 if (mResult) {
54 delete mResult;
55 }
56 delete mCalcConfig;
57 }
58
59
60 CQueryResult* CSuperClassesQuery::getQueryResult() {
61 return mResult;
62 }
63
64
65 CQueryResult *CSuperClassesQuery::constructResult(CTaxonomy *taxonomy) {
66 return constructClassSynsetsResult(taxonomy);
67 }
68
69 CClassSynsetsResult *CSuperClassesQuery::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*>* parentNodeSet = node->getParentNodeSet();
84 for (QSet<CHierarchyNode*>::const_iterator it = parentNodeSet->constBegin(), itEnd = parentNodeSet->constEnd(); it != itEnd; ++it) {
85 CHierarchyNode* parentNode(*it);
86 visitHierNodetList.append(parentNode);
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*>* tmpParentNodeSet = nextNode->getParentNodeSet();
95 for (QSet<CHierarchyNode*>::const_iterator it = tmpParentNodeSet->constBegin(), itEnd = tmpParentNodeSet->constEnd(); it != itEnd; ++it) {
96 CHierarchyNode* nextParentNode(*it);
97 if (!visitedHierNodeSet->contains(nextParentNode)) {
98 visitedHierNodeSet->insert(nextParentNode);
99 visitHierNodetList.append(nextParentNode);
100 }
101 }
102 }
103 }
104 delete visitedHierNodeSet;
105
106 }
107 }
108 return mResult;
109 }
110
111
112 QString CSuperClassesQuery::getQueryName() {
113 return mQueryName;
114 }
115
116 QString CSuperClassesQuery::getQueryString() {
117 return mQueryString;
118 }
119
120 bool CSuperClassesQuery::hasAnswer() {
121 return mResult != 0;
122 }
123
124 QString CSuperClassesQuery::getAnswerString() {
125 if (!mResult) {
126 return QString("Unknown Classes");
127 } else {
128 return mResult->getQueryResultString();
129 }
130 }
131
132 bool CSuperClassesQuery::hasError() {
133 return mTaxonomyCalcError || mQueryConstructError || CQuery::hasError();
134 }
135
136 bool CSuperClassesQuery::isDirect() {
137 return mDirect;
138 }
139
140 }; // end namespace Query
141
142 }; // end namespace Reasoner
143
144 }; // end namespace Konclude