Debian Codegraph @

Source/Parser/CSPARQLRedlandRasqalReasoningBGPQueryParser.h

raw ◀ ▶
1 Debian patch touch this file
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 #ifdef KONCLUDE_REDLAND_INTEGRATION
22
23
24 #ifndef KONCLUDE_PARSER_CSPARQLREDLANDRASQALREASONINGBGPQUERYPARSER_H
25 #define KONCLUDE_PARSER_CSPARQLREDLANDRASQALREASONINGBGPQUERYPARSER_H
26
27 // Libraries includes
•28 #include <librdf.h>
29 #include <QRegularExpression>
30
31
32 // Namespace includes
33 #include "CQueryParser.h"
34 #include "COntologyParser.h"
35 #include "CSPARQLQueryBuilder.h"
36 #include "COntologyBuilder.h"
37 #include "CSPARQLExtendedMappingBuildingParser.h"
38 #include "CSPARQLQueryParser.h"
39
40
41 // Other includes
42 #include "Parser/Expressions/CQuerySPARQLBasicGraphPatternExpression.h"
43 #include "Parser/Expressions/COrderingVariableExpression.h"
44
45 #include "Config/CConfigDataReader.h"
46
47 #include "Parser/Expressions/CFilteringTermExpression.h"
48
49 // Logger includes
50 #include "Logger/CLogger.h"
51
52 using namespace Konclude::Logger;
53
54
55 namespace Konclude {
56
57 using namespace Config;
58
59 namespace Parser {
60
61 using namespace Expression;
62
63
64 /*!
65 *
66 * \class CSPARQLRedlandRasqalReasoningBGPQueryParser
67 * \author Andreas Steigmiller
68 * \version 0.1
69 * \brief TODO
70 *
71 */
72 class CSPARQLRedlandRasqalReasoningBGPQueryParser : public CSPARQLExtendedMappingBuildingParser {
73 // public methods
74 public:
75 //! Constructor
76 CSPARQLRedlandRasqalReasoningBGPQueryParser(CSPARQLQueryBuilder *queryBuilder, COntologyBuilder* ontoBuilder, CConcreteOntology* ontology, CConfigurationBase* config);
77
78 //! Destructor
79 virtual ~CSPARQLRedlandRasqalReasoningBGPQueryParser();
80
81
82 class CRedlandRasqalBGPSubQueryData {
83 public:
84 rasqal_graph_pattern* bgp = nullptr;
85 int tripleStartPos = 0;
86 int tripleEndPos = 0;
87 bool completelyHandledResultsTransfer = false;
88 cint64 subQueryId = 0;
89 QList<cint64> dependentSubQueryIds;
90 };
91
92 QHash<QString, CRedlandRasqalBGPSubQueryData*> parseBGPReasoningSubQueries(librdf_world* world, librdf_query* redlandQuery, rasqal_query* rasqalQuery, const QString& queryText, const QString& knowledgeBase, bool defaultKnowledgeBase, cint64& nextSubQueryId);
93
94 // protected variables
95 protected:
96
97 class CBGPSubQueryGenerationData {
98 public:
99 CRedlandRasqalBGPSubQueryData* bgpData = nullptr;
100 cint64 subQueryId = 0;
101
102 QList<CRDFStringTriple*> connectedTripleStringList;
103 QList<CRDFStringTriple> convertingStringTriplesList;
104 QSet<cint64> usedtriplePosSet;
105 QList<CRDFStringTriple> additionalIntegratingStringTriplesList;
106
107
108 QSet<QString> connectedVariableSet;
109 QStringList subQueryVarStringList;
110 QSet<QString> distinguishedVariableSet;
111 QStringList distinguishedVariableStringList;
112
113 QSet<QString> additionalIntegratedVariableSet;
114
115 };
116
117
118 // protected methods
119 protected:
120
121
122
123 bool identifySubBGPsDistinctComputable(rasqal_graph_pattern * basicGrapPattern, QSet<rasqal_graph_pattern*>& distinctSubBGPsSet);
124
125 bool identifyHandlingKnowledgeBaseRelevantBGPs(rasqal_graph_pattern* grapPattern, bool rootPattern, QSet<rasqal_graph_pattern*>& kbRelevantBGPsSet, const QString& kbName, bool defaultKB);
126
127 bool checkSingleBGPResultsDirectUsable(bool singleBGPResultsDirectlyUsable, rasqal_graph_pattern * basicGrapPattern, rasqal_query* rasqalQuery);
128
129 bool identifyBGPBasedSubQueryTriples(rasqal_graph_pattern* grapPattern);
130 bool identifyBGPBasedSubQueries(rasqal_graph_pattern* grapPattern);
131
132 CBGPSubQueryGenerationData* createSubQueryGenerationData(rasqal_query *query, CSPARQLRedlandRasqalReasoningBGPQueryParser::CRedlandRasqalBGPSubQueryData* bgpData);
133
134 bool generateBGPBasedSubQueries(const QStringList& projectedVarList);
135
136 bool integrateFollowingSubQueryRestrictions(CBGPSubQueryGenerationData* subQueryBGPData, CBGPSubQueryGenerationData* followingSubQueryBGPData);
137
138 // protected variables
139 protected:
140 CSPARQLQueryBuilder* mQueryBuilder;
141 QString mQueryText;
142 librdf_query* mRedlandQuery;
143 rasqal_query* mRasqalQuery;
144 rasqal_world* mRasqalWorld;
145 librdf_world* mRedlandWorld;
146 raptor_world* mRaptorWorld;
147 cint64 mNextSubQueryId = 0;
148
149 QSet<rasqal_graph_pattern*> mKnowledgeBaseRelevantBGPsSet;
150 bool mQueryContainsSelectAll = false;
151 QSet<rasqal_graph_pattern*> mDistinctSubBGPsSet;
152 bool mSingleBGPResultsDirectlyUsable = false;
153
154 QList<CQuerySPARQLBasicGraphPatternExpression*> mSPARQLBGPQueryList;
155
156 CConfigurationBase* mConfig;
157 bool mConfWriteQueryStructure = false;
158 bool mConfForceDistinctSubQueries = false;
159 bool mConfReduceBGPSubQueryAnswerVariables = false;
160 bool mConfPropagateBGPSubQueryDistinct = false;
161 bool mConfMinimizeBGPTriples = false;
162 bool mConfAllowResultStreamingFromSingleSubQuery = false;
163 bool mConfSubQueriesDependencyIdentification = false;
164 bool mConfSubQueriesFollowingRestrictionsIntegration = false;
165 bool mConfWriteSubQueryTriples = false;
166
167 QHash<cint64, CBGPSubQueryGenerationData*> mIdSubQueryIdDataHash;
168 QHash<rasqal_graph_pattern*, CBGPSubQueryGenerationData*> mBGPSubQueryIdDataHash;
169 QHash<QString, CRedlandRasqalBGPSubQueryData*> mBGPSubQueryNameHash;
170
171 // private methods
172 private:
173
174
175 // private variables
176 private:
177
178
179
180 };
181
182 }; // end namespace Parser
183
184 }; // end namespace Konclude
185
186 #endif // KONCLUDE_PARSER_CSPARQLREDLANDRASQALREASONINGBGPQUERYPARSER_H
187
188 #endif // KONCLUDE_REDLAND_INTEGRATION