Debian Codegraph @

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