Debian Codegraph @

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