Debian Codegraph @

Source/Reasoner/Query/CTypesResultVisitCallbackQuery.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 "CTypesResultVisitCallbackQuery.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Query {
29
30
31 CTypesResultVisitCallbackQuery::CTypesResultVisitCallbackQuery(CConcreteOntology* ontology, CConfigurationBase* configuration, CIndividual* indi, bool direct, const QString& individualName, const QString& typeQueryName)
32 : CRealizationPremisingQuery(ontology,configuration) {
33 mIndividualName = individualName;
34 mIndividual = indi;
35 queryName = typeQueryName;
36 if (mIndividualName.isEmpty()) {
37 queryString = QString("Get Types");
38 } else {
39 queryString = QString("Get Types for individual '%1'").arg(mIndividualName);
40 }
41 mResult = nullptr;
42
43 mRealizationCalcError = false;
44 mQueryConstructError = false;
45 mDirect = direct;
46
47 mRequiresConceptRealisation = true;
48 mRequiresSameIndividualRealisation = true;
49
50 mCalcConfig = configuration;
51 }
52
53 CTypesResultVisitCallbackQuery::~CTypesResultVisitCallbackQuery() {
54 if (mResult) {
55 delete mResult;
56 }
57 delete mCalcConfig;
58 }
59
60
61 CQueryResult* CTypesResultVisitCallbackQuery::getQueryResult() {
62 return mResult;
63 }
64
65
66 CQueryResult *CTypesResultVisitCallbackQuery::constructResult(CRealization* realization) {
67 if (mResult) {
68 delete mResult;
69 }
70 mConRealization = nullptr;
71 if (realization) {
72 mConRealization = realization->getConceptRealization();
73 if (mConRealization) {
74 mResult = new CSucceedQueryResult();
75 }
76 }
77 return mResult;
78 }
79
80 bool CTypesResultVisitCallbackQuery::callbackVisitingTypes(CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) {
81 if (mConRealization) {
82 CSetOfEntityExpressionSetResultVisitingCallbackGenerator resultGenerator(visitingCallback,mOntology);
83 mConRealization->visitTypes(mIndividual,mDirect,&resultGenerator);
84 return true;
85 }
86 return false;
87 }
88
89
90 QString CTypesResultVisitCallbackQuery::getQueryName() {
91 return queryName;
92 }
93
94 QString CTypesResultVisitCallbackQuery::getQueryString() {
95 return queryString;
96 }
97
98 bool CTypesResultVisitCallbackQuery::hasAnswer() {
99 return mResult != 0;
100 }
101
102 QString CTypesResultVisitCallbackQuery::getAnswerString() {
103 if (!mResult) {
104 return QString("Unknown Types");
105 } else {
106 return mResult->getQueryResultString();
107 }
108 }
109
110 bool CTypesResultVisitCallbackQuery::hasError() {
111 return mRealizationCalcError || mQueryConstructError || CQuery::hasError();
112 }
113
114 bool CTypesResultVisitCallbackQuery::isDirect() {
115 return mDirect;
116 }
117
118 }; // end namespace Query
119
120 }; // end namespace Reasoner
121
122 }; // end namespace Konclude