Debian Codegraph @

Source/Reasoner/Query/CFlattenedInstancesQuery.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 "CFlattenedInstancesQuery.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Query {
29
30
31 CFlattenedInstancesQuery::CFlattenedInstancesQuery(CConcreteOntology* ontology, CConfigurationBase* configuration, CConcept* concept, bool direct, const QString& conceptName, const QString& flatternedTypeQueryName)
32 : CRealizationPremisingQuery(ontology,configuration) {
33 mConceptName = conceptName;
34 mConcept = concept;
35 queryName = flatternedTypeQueryName;
36 if (mConceptName.isEmpty()) {
37 queryString = QString("Get Flattened Instances");
38 } else {
39 queryString = QString("Get Flattened Instances for Type '%1'").arg(mConceptName);
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 mDirect = direct;
49
50 mRequiresSameIndividualRealisation = true;
51 mRequiresConceptRealisation = true;
52
53 mCalcConfig = configuration;
54 }
55
56 CFlattenedInstancesQuery::~CFlattenedInstancesQuery() {
57 if (mResult) {
58 delete mResult;
59 }
60 delete mCalcConfig;
61 }
62
63
64 CQueryResult* CFlattenedInstancesQuery::getQueryResult() {
65 return mResult;
66 }
67
68
69 CQueryResult *CFlattenedInstancesQuery::constructResult(CRealization* realization) {
70 return constructIndividualsResult(realization);
71 }
72
73 CIndividualsResult *CFlattenedInstancesQuery::constructIndividualsResult(CRealization* realization) {
74 if (mResult) {
75 delete mResult;
76 mResult = 0;
77 }
78 if (realization) {
79 CConceptRealization* conRealization = realization->getConceptRealization();
80 if (conRealization) {
81 mResult = new CIndividualsResult();
82 CIndividualsResultVisitorGenerator resultGenerator(mResult,mUseAbbreviatedIRIs, mAnonymousIndividuals, mOntology->getIndividualNameResolver());
83 conRealization->visitInstances(mConcept,mDirect,&resultGenerator);
84 }
85 }
86 return mResult;
87 }
88
89
90 QString CFlattenedInstancesQuery::getQueryName() {
91 return queryName;
92 }
93
94 QString CFlattenedInstancesQuery::getQueryString() {
95 return queryString;
96 }
97
98 bool CFlattenedInstancesQuery::hasAnswer() {
99 return mResult != 0;
100 }
101
102 QString CFlattenedInstancesQuery::getAnswerString() {
103 if (!mResult) {
104 return QString("Unknown Individuals");
105 } else {
106 return mResult->getQueryResultString();
107 }
108 }
109
110 bool CFlattenedInstancesQuery::hasError() {
111 return mRealizationCalcError || mQueryConstructError || CQuery::hasError();
112 }
113
114 bool CFlattenedInstancesQuery::isDirect() {
115 return mDirect;
116 }
117
118 }; // end namespace Query
119
120 }; // end namespace Reasoner
121
122 }; // end namespace Konclude