Debian Codegraph @

Source/Reasoner/Query/CObjectPropertySourcesTargetsResultVisitCallbackQuery.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 "CObjectPropertySourcesTargetsResultVisitCallbackQuery.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Query {
29
30
31 CObjectPropertySourcesTargetsResultVisitCallbackQuery::CObjectPropertySourcesTargetsResultVisitCallbackQuery(CConcreteOntology* ontology, CConfigurationBase* configuration, CIndividual* individual, CRole* role, bool sources, bool targets, const QString& objectPropertyTargetQueryName)
32 : CRealizationPremisingQuery(ontology,configuration) {
33 mIndividual = individual;
34 mRole = role;
35
36 mIndividualName = CIRIName::getRecentIRIName(individual->getIndividualNameLinker());
37 mRoleName = CIRIName::getRecentIRIName(role->getPropertyNameLinker());
38
39 queryName = objectPropertyTargetQueryName;
40 if (queryName.isEmpty()) {
41 QString sourcesTargetsString = QString("Sources/Targets");
42 if (mSources && !mTargets) {
43 sourcesTargetsString = QString("Sources");
44 } else if (!mSources && mTargets) {
45 sourcesTargetsString = QString("Targets");
46 }
47 if (!mIndividualName.isEmpty() && !mRoleName.isEmpty()) {
48 queryString = QString("Get Object Property %1").arg(sourcesTargetsString);
49 } else {
50 queryString = QString("Get Object Property %1 for Individual '%2'").arg(sourcesTargetsString).arg(mIndividualName);
51 }
52 }
53 mResult = nullptr;
54
55 mRealizationCalcError = false;
56 mQueryConstructError = false;
57
58 mSources = sources;
59 mTargets = targets;
60
61 mRequiresRoleRealisation = true;
62 mRequiresSameIndividualRealisation = true;
63
64 mCalcConfig = configuration;
65 }
66
67 CObjectPropertySourcesTargetsResultVisitCallbackQuery::~CObjectPropertySourcesTargetsResultVisitCallbackQuery() {
68 if (mResult) {
69 delete mResult;
70 }
71 delete mCalcConfig;
72 }
73
74
75 CQueryResult* CObjectPropertySourcesTargetsResultVisitCallbackQuery::getQueryResult() {
76 return mResult;
77 }
78
79
80
81 CQueryResult *CObjectPropertySourcesTargetsResultVisitCallbackQuery::constructResult(CRealization* realization) {
82 if (mResult) {
83 delete mResult;
84 }
85 mRoleRealization = nullptr;
86 if (realization) {
87 mRoleRealization = realization->getRoleRealization();
88 if (mRoleRealization) {
89 mResult = new CSucceedQueryResult();
90 }
91 }
92 return mResult;
93 }
94
95 bool CObjectPropertySourcesTargetsResultVisitCallbackQuery::callbackVisitingIndividuals(CSetOfEntityExpressionSetResultVisitingCallback* visitingCallback) {
96 if (mRoleRealization) {
97 CSetOfEntityExpressionSetResultVisitingCallbackGenerator resultGenerator(visitingCallback,mOntology);
98 if (mSources) {
99 mRoleRealization->visitSourceIndividuals(mIndividual,mRole,&resultGenerator);
100 }
101 if (mTargets) {
102 mRoleRealization->visitTargetIndividuals(mIndividual,mRole,&resultGenerator);
103 }
104 return true;
105 }
106 return false;
107 }
108
109
110
111 QString CObjectPropertySourcesTargetsResultVisitCallbackQuery::getQueryName() {
112 return queryName;
113 }
114
115 QString CObjectPropertySourcesTargetsResultVisitCallbackQuery::getQueryString() {
116 return queryString;
117 }
118
119 bool CObjectPropertySourcesTargetsResultVisitCallbackQuery::hasAnswer() {
120 return mResult != 0;
121 }
122
123 QString CObjectPropertySourcesTargetsResultVisitCallbackQuery::getAnswerString() {
124 if (!mResult) {
125 return QString("Unknown Individuals");
126 } else {
127 return mResult->getQueryResultString();
128 }
129 }
130
131 bool CObjectPropertySourcesTargetsResultVisitCallbackQuery::hasError() {
132 return mRealizationCalcError || mQueryConstructError || CQuery::hasError();
133 }
134
135
136 }; // end namespace Query
137
138 }; // end namespace Reasoner
139
140 }; // end namespace Konclude