| 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 |
#ifdef KONCLUDE_REDLAND_INTEGRATION |
| 21 |
|
| 22 |
#include "CRedlandRasqalModelSubQueryResolver.h" |
| 23 |
|
| 24 |
|
| 25 |
namespace Konclude { |
| 26 |
|
| 27 |
namespace Reasoner { |
| 28 |
|
| 29 |
namespace Answerer { |
| 30 |
|
| 31 |
|
| 32 |
CRedlandRasqalModelSubQueryResolver::CRedlandRasqalModelSubQueryResolver(QVector<CRedlandRasqalSubQueryProcessingData*>* subQueryProcDataVec, librdf_world* world, librdf_query* redlandQuery, rasqal_query* rasqalQuery, QHash<QString, TDependentOntologyPair>* queryKbNameDepOntPair) { |
| 33 |
mSubQueryProcDataVec = subQueryProcDataVec; |
| 34 |
mWorld = world; |
| 35 |
mRedlandQuery = redlandQuery; |
| 36 |
mRasqalQuery = rasqalQuery; |
| 37 |
mResolvingModel = nullptr; |
| 38 |
mQueryKbNameDepOntPairHash = queryKbNameDepOntPair; |
| 39 |
|
| 40 |
|
| 41 |
raptor_sequence* tripleSeq = rasqal_query_get_triple_sequence(mRasqalQuery); |
| 42 |
int tripleSeqSize = raptor_sequence_size(tripleSeq); |
| 43 |
mTriplesContextLiteralVector.resize(tripleSeqSize); |
| 44 |
for (int i = 0; i < tripleSeqSize; ++i) { |
| 45 |
rasqal_triple* triple = (rasqal_triple*)raptor_sequence_get_at(tripleSeq, i); |
| 46 |
rasqal_literal* lit = rasqal_triple_get_origin(triple); |
| 47 |
mTriplesContextLiteralVector[i] = lit; |
| 48 |
} |
| 49 |
mTriplesContextLiteralsReset = false; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
CRedlandRasqalModelSubQueryResolver::~CRedlandRasqalModelSubQueryResolver() { |
| 55 |
releaseRedlandResolvingModel(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
/* A Model Factory */ |
| 61 |
struct librdf_model_factory_s { |
| 62 |
char* name; |
| 63 |
char* label; |
| 64 |
|
| 65 |
/* the rest of this structure is populated by the |
| 66 |
model-specific register function */ |
| 67 |
size_t context_length; |
| 68 |
|
| 69 |
/* init the factory */ |
| 70 |
void(*init)(void); |
| 71 |
|
| 72 |
/* terminate the factory */ |
| 73 |
void(*terminate)(void); |
| 74 |
|
| 75 |
/* create a new model */ |
| 76 |
int(*create)(librdf_model* model, librdf_storage* storage, librdf_hash* options); |
| 77 |
|
| 78 |
/* copy a model */ |
| 79 |
/* clone is assumed to do leave the new model in the same state |
| 80 |
* after an init() method on an existing model - i.e ready to |
| 81 |
* use but closed. |
| 82 |
*/ |
| 83 |
librdf_model* (*clone)(librdf_model* new_model); |
| 84 |
|
| 85 |
/* destroy model */ |
| 86 |
void(*destroy)(librdf_model* model); |
| 87 |
|
| 88 |
/* return the number of statements in the model for model */ |
| 89 |
int(*size)(librdf_model* model); |
| 90 |
|
| 91 |
/* add a statement to the model from the given model */ |
| 92 |
int(*add_statement)(librdf_model* model, librdf_statement* statement); |
| 93 |
|
| 94 |
/* add a statement to the model from the given model */ |
| 95 |
int(*add_statements)(librdf_model* model, librdf_stream* statement_stream); |
| 96 |
|
| 97 |
/* remove a statement from the model */ |
| 98 |
int(*remove_statement)(librdf_model* model, librdf_statement* statement); |
| 99 |
|
| 100 |
/* check if statement in model */ |
| 101 |
int(*contains_statement)(librdf_model* model, librdf_statement* statement); |
| 102 |
/* check for [node, property, ?] */ |
| 103 |
int(*has_arc_in)(librdf_model *model, librdf_node *node, librdf_node *property); |
| 104 |
/* check for [?, property, node] */ |
| 105 |
int(*has_arc_out)(librdf_model *model, librdf_node *node, librdf_node *property); |
| 106 |
|
| 107 |
|
| 108 |
/* serialise the model in model */ |
| 109 |
librdf_stream* (*serialise)(librdf_model* model); |
| 110 |
|
| 111 |
/* serialise the results of a query */ |
| 112 |
librdf_stream* (*find_statements)(librdf_model* model, librdf_statement* statement); |
| 113 |
librdf_stream* (*find_statements_with_options)(librdf_model* model, librdf_statement* statement, librdf_node* context_node, librdf_hash* options); |
| 114 |
|
| 115 |
/* return a list of Nodes marching given arc, target */ |
| 116 |
librdf_iterator* (*get_sources)(librdf_model* model, librdf_node *arc, librdf_node *target); |
| 117 |
|
| 118 |
/* return a list of Nodes marching given source, target */ |
| 119 |
librdf_iterator* (*get_arcs)(librdf_model* model, librdf_node *source, librdf_node *target); |
| 120 |
|
| 121 |
/* return a list of Nodes marching given source, target */ |
| 122 |
librdf_iterator* (*get_targets)(librdf_model* model, librdf_node *source, librdf_node *target); |
| 123 |
|
| 124 |
/* return list of properties to/from a node */ |
| 125 |
librdf_iterator* (*get_arcs_in)(librdf_model *model, librdf_node *node); |
| 126 |
librdf_iterator* (*get_arcs_out)(librdf_model *model, librdf_node *node); |
| 127 |
|
| 128 |
/* add a statement to the model from the context */ |
| 129 |
int(*context_add_statement)(librdf_model* model, librdf_node* context, librdf_statement *statement); |
| 130 |
|
| 131 |
/* remove a statement from the context */ |
| 132 |
int(*context_remove_statement)(librdf_model* model, librdf_node* context, librdf_statement *statement); |
| 133 |
|
| 134 |
/* list statements in a context */ |
| 135 |
librdf_stream* (*context_serialize)(librdf_model* model, librdf_node* context); |
| 136 |
|
| 137 |
/* query the model */ |
| 138 |
librdf_query_results* (*query_execute)(librdf_model* model, librdf_query* query); |
| 139 |
|
| 140 |
/* sync the model to the storage - OPTIONAL */ |
| 141 |
int(*sync)(librdf_model* model); |
| 142 |
|
| 143 |
/* add a statement from the context - OPTIONAL (librdf_model will |
| 144 |
* implement using context_add_statement if missing) |
| 145 |
*/ |
| 146 |
int(*context_add_statements)(librdf_model* model, librdf_node* context, librdf_stream *stream); |
| 147 |
|
| 148 |
/* remove a statement from the context - OPTIONAL (librdf_model will |
| 149 |
* implement using context_remove_statement if missing) |
| 150 |
*/ |
| 151 |
int(*context_remove_statements)(librdf_model* model, librdf_node* context); |
| 152 |
|
| 153 |
/* get the single storage for this model if there is one - OPTIONAL */ |
| 154 |
librdf_storage* (*get_storage)(librdf_model* model); |
| 155 |
|
| 156 |
/* search for statement in a context - OPTIONAL (rdf_model will do |
| 157 |
* it using find_statements if missing) |
| 158 |
*/ |
| 159 |
librdf_stream* (*find_statements_in_context)(librdf_model* model, librdf_statement* statement, librdf_node* context_node); |
| 160 |
|
| 161 |
/* return an iterator of context nodes in the store - OPTIONAL |
| 162 |
* (returning NULL) |
| 163 |
*/ |
| 164 |
librdf_iterator* (*get_contexts)(librdf_model* model); |
| 165 |
|
| 166 |
/* features - OPTIONAL */ |
| 167 |
librdf_node* (*get_feature)(librdf_model* model, librdf_uri* feature); |
| 168 |
int(*set_feature)(librdf_model* model, librdf_uri* feature, librdf_node* value); |
| 169 |
|
| 170 |
/* transactions - OPTIONAL */ |
| 171 |
int(*transaction_start)(librdf_model* model); |
| 172 |
int(*transaction_start_with_handle)(librdf_model* model, void* handle); |
| 173 |
int(*transaction_commit)(librdf_model* model); |
| 174 |
int(*transaction_rollback)(librdf_model* model); |
| 175 |
void* (*transaction_get_handle)(librdf_model* model); |
| 176 |
|
| 177 |
|
| 178 |
/* check if statement in model */ |
| 179 |
int(*contains_statement_with_context)(librdf_model* model, librdf_statement* statement, librdf_node* context_node); |
| 180 |
|
| 181 |
|
| 182 |
}; |
| 183 |
|
| 184 |
|
| 185 |
struct librdf_model_s { |
| 186 |
librdf_world *world; |
| 187 |
|
| 188 |
/* usage: usage count of this instance |
| 189 |
* |
| 190 |
* Used by other redland classes such as iterator, stream |
| 191 |
* via librdf_model_add_reference librdf_model_remove_reference |
| 192 |
* The usage count of model after construction is 1. |
| 193 |
*/ |
| 194 |
int usage; |
| 195 |
|
| 196 |
/* sub_models: list of sub librdf_model* */ |
| 197 |
librdf_list* sub_models; |
| 198 |
|
| 199 |
/* supports_contexts : does the storage model support redland contexts? */ |
| 200 |
int supports_contexts; |
| 201 |
|
| 202 |
/* context : model implementation user data */ |
| 203 |
void *context; |
| 204 |
|
| 205 |
struct librdf_model_factory_s* factory; |
| 206 |
}; |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
/** |
| 212 |
* librdf_storage_factory: |
| 213 |
* @version: Interface version. Only version 1 is defined. |
| 214 |
* @name: Name (ID) of this storage, e.g. "megastore" |
| 215 |
* @label: Label of this storage, e.g. "Megastore Storage" |
| 216 |
* @init: Create a new storage. |
| 217 |
* This method should create the required instance data and store it with |
| 218 |
* librdf_storage_set_instance() so it can be used in other methods. |
| 219 |
* @clone: Copy a storage. |
| 220 |
* This is assumed to leave the new storage in the same state as an existing |
| 221 |
* storage after an init() method - i.e ready to use but closed. |
| 222 |
* @terminate: Destroy a storage. |
| 223 |
* This method is responsible for freeing all memory allocated in the init method. |
| 224 |
* @open: Make storage be associated with model |
| 225 |
* @close: Close storage/model context |
| 226 |
* @size: Return the number of statements in the storage for model |
| 227 |
* @add_statement: Add a statement to the storage from the given model. OPTIONAL |
| 228 |
* @add_statements: Add a statement to the storage from the given model. OPTIONAL |
| 229 |
* @remove_statement: Remove a statement from the storage. OPTIONAL |
| 230 |
* @contains_statement: Check if statement is in storage |
| 231 |
* @has_arc_in: Check for [node, property, ?] |
| 232 |
* @has_arc_out: Check for [?, property, node] |
| 233 |
* @serialise: Serialise the model in storage |
| 234 |
* @find_statements: Return a stream of triples matching a triple pattern |
| 235 |
* @find_statements_with_options: Return a stream of triples matching a triple pattern with some options. OPTIONAL |
| 236 |
* @find_sources: Return a list of Nodes marching given arc, target |
| 237 |
* @find_arcs: Return a list of Nodes marching given source, target |
| 238 |
* @find_targets: Return a list of Nodes marching given source, target |
| 239 |
* @get_arcs_in: Return list of properties to a node (i.e. with node as the object) |
| 240 |
* @get_arcs_out: Return list of properties from a node (i.e. with node as the subject) |
| 241 |
* @context_add_statement: Add a statement to the storage from the context. |
| 242 |
* NOTE: If context is NULL, this MUST be equivalent to @add_statement. OPTIONAL. |
| 243 |
* @context_remove_statement: Remove a statement from a context. |
| 244 |
* NOTE: if context is NULL, this MUST be equivalent to remove_statement. OPTIONAL. |
| 245 |
* @context_serialise: Serialise statements in a context. OPTIONAL |
| 246 |
* @sync: Synchronise to underlying storage. OPTIONAL |
| 247 |
* @context_add_statements: Add statements to a context. storage core will do this using context_add_statement if missing. |
| 248 |
* NOTE: If context is NULL, this MUST be equivalent to add_statements. OPTIONAL |
| 249 |
* @context_remove_statements: Remove statements from a context. storage core will do this using context_remove_statement if missing). OPTIONAL |
| 250 |
* @find_statements_in_context: Search for statement in a context. storage core will do this using find_statements if missing. OPTIONAL |
| 251 |
* @get_contexts: Return an iterator of context nodes. Returns NULL if contexts not supported. OPTIONAL |
| 252 |
* @get_feature: Get a feature. OPTIONAL |
| 253 |
* @set_feature: Set a feature. OPTIONAL |
| 254 |
* @transaction_start: Begin a transaction. OPTIONAL |
| 255 |
* @transaction_start_with_handle: Begin a transaction with opaque data handle. OPTIONAL |
| 256 |
* @transaction_commit: Commit a transaction. OPTIONAL |
| 257 |
* @transaction_rollback: Rollback a transaction. OPTIONAL |
| 258 |
* @transaction_get_handle: Get opaque data handle passed to transaction_start_with_handle. OPTIONAL |
| 259 |
* |
| 260 |
* A Storage Factory |
| 261 |
*/ |
| 262 |
struct librdf_storage_factory_s { |
| 263 |
/* Interface version */ |
| 264 |
int version; |
| 265 |
|
| 266 |
/* Name (ID) of this storage */ |
| 267 |
char* name; |
| 268 |
|
| 269 |
/* Label of this storage */ |
| 270 |
char* label; |
| 271 |
|
| 272 |
/* The rest of this structure is populated by the storage-specific |
| 273 |
* register function |
| 274 |
*/ |
| 275 |
|
| 276 |
/* Create a new storage. */ |
| 277 |
int(*init)(librdf_storage* storage, const char *name, librdf_hash* options); |
| 278 |
|
| 279 |
/* Copy a storage. */ |
| 280 |
int(*clone)(librdf_storage* new_storage, librdf_storage* old_storage); |
| 281 |
|
| 282 |
/* Destroy a storage. */ |
| 283 |
void(*terminate)(librdf_storage* storage); |
| 284 |
|
| 285 |
/* Make storage be associated with model */ |
| 286 |
int(*open)(librdf_storage* storage, librdf_model* model); |
| 287 |
|
| 288 |
/* Close storage/model context */ |
| 289 |
int(*close)(librdf_storage* storage); |
| 290 |
|
| 291 |
/* Return the number of statements in the storage for model */ |
| 292 |
int(*size)(librdf_storage* storage); |
| 293 |
|
| 294 |
/* Add a statement to the storage from the given model */ |
| 295 |
int(*add_statement)(librdf_storage* storage, librdf_statement* statement); |
| 296 |
|
| 297 |
/* Add a statement to the storage from the given model */ |
| 298 |
int(*add_statements)(librdf_storage* storage, librdf_stream* statement_stream); |
| 299 |
|
| 300 |
/* Remove a statement from the storage */ |
| 301 |
int(*remove_statement)(librdf_storage* storage, librdf_statement* statement); |
| 302 |
|
| 303 |
/* Check if statement is in storage */ |
| 304 |
int(*contains_statement)(librdf_storage* storage, librdf_statement* statement); |
| 305 |
|
| 306 |
/* Check for [node, property, ?] */ |
| 307 |
int(*has_arc_in)(librdf_storage *storage, librdf_node *node, librdf_node *property); |
| 308 |
|
| 309 |
/* Check for [?, property, node] */ |
| 310 |
int(*has_arc_out)(librdf_storage *storage, librdf_node *node, librdf_node *property); |
| 311 |
|
| 312 |
/* Serialise the model in storage */ |
| 313 |
librdf_stream* (*serialise)(librdf_storage* storage); |
| 314 |
|
| 315 |
/* Return a stream of triples matching a triple pattern */ |
| 316 |
librdf_stream* (*find_statements)(librdf_storage* storage, librdf_statement* statement); |
| 317 |
|
| 318 |
/* Return a stream of triples matching a triple pattern with some options. */ |
| 319 |
librdf_stream* (*find_statements_with_options)(librdf_storage* storage, librdf_statement* statement, librdf_node* context_node, librdf_hash* options); |
| 320 |
|
| 321 |
/* Return a list of Nodes marching given arc, target */ |
| 322 |
librdf_iterator* (*find_sources)(librdf_storage* storage, librdf_node *arc, librdf_node *target); |
| 323 |
|
| 324 |
/* Return a list of Nodes marching given source, target */ |
| 325 |
librdf_iterator* (*find_arcs)(librdf_storage* storage, librdf_node *src, librdf_node *target); |
| 326 |
|
| 327 |
/* Return a list of Nodes marching given source, target */ |
| 328 |
librdf_iterator* (*find_targets)(librdf_storage* storage, librdf_node *src, librdf_node *target); |
| 329 |
|
| 330 |
/** Return list of properties to a node (i.e. with node as the object) */ |
| 331 |
librdf_iterator* (*get_arcs_in)(librdf_storage *storage, librdf_node *node); |
| 332 |
|
| 333 |
/* Return list of properties from a node (i.e. with node as the subject) */ |
| 334 |
librdf_iterator* (*get_arcs_out)(librdf_storage *storage, librdf_node *node); |
| 335 |
|
| 336 |
/* Add a statement to the storage from the context */ |
| 337 |
int(*context_add_statement)(librdf_storage* storage, librdf_node* context, librdf_statement *statement); |
| 338 |
|
| 339 |
/* Remove a statement from a context */ |
| 340 |
int(*context_remove_statement)(librdf_storage* storage, librdf_node* context, librdf_statement *statement); |
| 341 |
|
| 342 |
/* Serialise statements in a context */ |
| 343 |
librdf_stream* (*context_serialise)(librdf_storage* storage, librdf_node* context); |
| 344 |
|
| 345 |
/* Synchronise to underlying storage */ |
| 346 |
int(*sync)(librdf_storage* storage); |
| 347 |
|
| 348 |
/* Add statements to a context */ |
| 349 |
int(*context_add_statements)(librdf_storage* storage, librdf_node* context, librdf_stream *stream); |
| 350 |
|
| 351 |
/* Remove statements from a context */ |
| 352 |
int(*context_remove_statements)(librdf_storage* storage, librdf_node* context); |
| 353 |
|
| 354 |
/* Search for statement in a context */ |
| 355 |
librdf_stream* (*find_statements_in_context)(librdf_storage* storage, |
| 356 |
librdf_statement* statement, librdf_node* context_node); |
| 357 |
|
| 358 |
/* Return an iterator of context nodes */ |
| 359 |
librdf_iterator* (*get_contexts)(librdf_storage* storage); |
| 360 |
|
| 361 |
/* Get a feature */ |
| 362 |
librdf_node* (*get_feature)(librdf_storage* storaage, librdf_uri* feature); |
| 363 |
|
| 364 |
/* Set a feature */ |
| 365 |
int(*set_feature)(librdf_storage* storage, librdf_uri* feature, librdf_node* value); |
| 366 |
|
| 367 |
/* Begin a transaction */ |
| 368 |
int(*transaction_start)(librdf_storage* storage); |
| 369 |
|
| 370 |
/* Begin a transaction with opaque data handle */ |
| 371 |
int(*transaction_start_with_handle)(librdf_storage* storage, void* handle); |
| 372 |
|
| 373 |
/* Commit a transaction */ |
| 374 |
int(*transaction_commit)(librdf_storage* storage); |
| 375 |
|
| 376 |
/* Rollback a transaction */ |
| 377 |
int(*transaction_rollback)(librdf_storage* storage); |
| 378 |
|
| 379 |
/* Get opaque data handle passed to transaction_start_with_handle */ |
| 380 |
void* (*transaction_get_handle)(librdf_storage* storage); |
| 381 |
|
| 382 |
/** Storage engine supports querying - OPTIONAL */ |
| 383 |
int(*supports_query)(librdf_storage* storage, librdf_query *query); |
| 384 |
|
| 385 |
/** Storage engine returns query results - OPTIONAL */ |
| 386 |
librdf_query_results* (*query_execute)(librdf_storage* storage, librdf_query *query); |
| 387 |
}; |
| 388 |
|
| 389 |
|
| 390 |
/** A storage object */ |
| 391 |
struct librdf_storage_s { |
| 392 |
librdf_world *world; |
| 393 |
|
| 394 |
/* usage count of this instance |
| 395 |
* Used by other redland classes such as model, iterator, stream |
| 396 |
* via librdf_storage_add_reference librdf_storage_remove_reference |
| 397 |
* The usage count of storage after construction is 1. |
| 398 |
*/ |
| 399 |
int usage; |
| 400 |
|
| 401 |
librdf_model *model; |
| 402 |
void *instance; |
| 403 |
int index_contexts; |
| 404 |
struct librdf_storage_factory_s* factory; |
| 405 |
}; |
| 406 |
|
| 407 |
typedef struct { |
| 408 |
librdf_storage *storage; |
| 409 |
} librdf_model_storage_context; |
| 410 |
|
| 411 |
|
| 412 |
struct rasqal_graph_pattern_s { |
| 413 |
rasqal_query* query; |
| 414 |
|
| 415 |
/* operator for this graph pattern's contents */ |
| 416 |
rasqal_graph_pattern_operator op; |
| 417 |
|
| 418 |
raptor_sequence* triples; /* ... rasqal_triple* */ |
| 419 |
raptor_sequence* graph_patterns; /* ... rasqal_graph_pattern* */ |
| 420 |
|
| 421 |
int start_column; |
| 422 |
int end_column; |
| 423 |
|
| 424 |
/* the FILTER / LET expression */ |
| 425 |
rasqal_expression* filter_expression; |
| 426 |
|
| 427 |
/* index of the graph pattern in the query (0.. query->graph_pattern_count-1) */ |
| 428 |
int gp_index; |
| 429 |
|
| 430 |
/* Graph literal / SERVICE literal */ |
| 431 |
rasqal_literal *origin; |
| 432 |
|
| 433 |
/* Variable for LET graph pattern */ |
| 434 |
rasqal_variable *var; |
| 435 |
|
| 436 |
/* SELECT projection */ |
| 437 |
//rasqal_projection* projection; |
| 438 |
void* projection; |
| 439 |
|
| 440 |
/* SELECT modifiers */ |
| 441 |
//rasqal_solution_modifier* modifier; |
| 442 |
void* modifier; |
| 443 |
|
| 444 |
/* SILENT flag for SERVICE graph pattern */ |
| 445 |
unsigned int silent : 1; |
| 446 |
|
| 447 |
/* SELECT graph pattern: sequence of #rasqal_data_graph */ |
| 448 |
raptor_sequence* data_graphs; |
| 449 |
|
| 450 |
/* VALUES bindings for VALUES and sub-SELECT graph patterns */ |
| 451 |
//rasqal_bindings* bindings; |
| 452 |
void* bindings; |
| 453 |
}; |
| 454 |
|
| 455 |
|
| 456 |
static librdf_node* rasqal_literal_to_redland_node(librdf_world *world, rasqal_literal* l) { |
| 457 |
rasqal_literal_type type; |
| 458 |
|
| 459 |
if (!l) |
| 460 |
return NULL; |
| 461 |
|
| 462 |
/* FIXME: Workaround for Issue #0000519 |
| 463 |
* http://bugs.librdf.org/mantis/view.php?id=519 |
| 464 |
* |
| 465 |
* Remove this 'if' when RASQAL_MIN_VERSION is 0.9.30 or larger |
| 466 |
*/ |
| 467 |
if (l->type == RASQAL_LITERAL_INTEGER_SUBTYPE) |
| 468 |
type = RASQAL_LITERAL_STRING; |
| 469 |
else |
| 470 |
type = rasqal_literal_get_rdf_term_type(l); |
| 471 |
|
| 472 |
if (type == RASQAL_LITERAL_URI) |
| 473 |
return librdf_new_node_from_uri(world, (librdf_uri*)l->value.uri); |
| 474 |
else if (type == RASQAL_LITERAL_STRING) |
| 475 |
return librdf_new_node_from_typed_literal(world, |
| 476 |
(unsigned char*)l->string, |
| 477 |
l->language, |
| 478 |
(librdf_uri*)l->datatype); |
| 479 |
else if (type == RASQAL_LITERAL_BLANK) |
| 480 |
return librdf_new_node_from_blank_identifier(world, |
| 481 |
(unsigned char*)l->string); |
| 482 |
|
| 483 |
return NULL; |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
#define LIBRDF_MALLOC(type, size) (type)malloc(size) |
| 541 |
#define LIBRDF_CALLOC(type, size, count) (type)calloc(size, count) |
| 542 |
#define LIBRDF_FREE(type, ptr) free(ptr) |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
rasqal_literal* |
| 547 |
redland_node_to_rasqal_literal(librdf_world* world, librdf_node *node) { |
| 548 |
rasqal_literal* l; |
| 549 |
rasqal_world* rasqal_world_ptr = librdf_world_get_rasqal(world); |
| 550 |
|
| 551 |
if (librdf_node_is_resource(node)) { |
| 552 |
raptor_uri* uri = (raptor_uri*)librdf_new_uri_from_uri(librdf_node_get_uri(node)); |
| 553 |
l = rasqal_new_uri_literal(rasqal_world_ptr, uri); /* transfer uri ownership to literal */ |
| 554 |
} else if (librdf_node_is_literal(node)) { |
| 555 |
unsigned char *string; |
| 556 |
librdf_uri *uri; |
| 557 |
unsigned char *new_string; |
| 558 |
char *new_language = NULL; |
| 559 |
raptor_uri *new_datatype = NULL; |
| 560 |
size_t len; |
| 561 |
|
| 562 |
string = librdf_node_get_literal_value_as_counted_string(node, &len); |
| 563 |
new_string = (unsigned char*)rasqal_alloc_memory(len + 1); |
| 564 |
if (!new_string) |
| 565 |
return NULL; |
| 566 |
strcpy((char*)new_string, (const char*)string); |
| 567 |
|
| 568 |
string = (unsigned char*)librdf_node_get_literal_value_language(node); |
| 569 |
if (string) { |
| 570 |
new_language = (char*)rasqal_alloc_memory(strlen((const char*)string) + 1); |
| 571 |
if (!new_language) { |
| 572 |
rasqal_free_memory((void*)new_string); |
| 573 |
return NULL; |
| 574 |
} |
| 575 |
strcpy((char*)new_language, (const char*)string); |
| 576 |
} |
| 577 |
uri = librdf_node_get_literal_value_datatype_uri(node); |
| 578 |
if (uri) |
| 579 |
new_datatype = (raptor_uri*)librdf_new_uri_from_uri(uri); |
| 580 |
/* transfer new_string,new_language,new_datatype ownership to literal */ |
| 581 |
l = rasqal_new_string_literal(rasqal_world_ptr, (const unsigned char*)new_string, new_language, new_datatype, NULL); |
| 582 |
} else { |
| 583 |
unsigned char *blank = librdf_node_get_blank_identifier(node); |
| 584 |
unsigned char *new_blank; |
| 585 |
if (!blank) |
| 586 |
return NULL; |
| 587 |
new_blank = (unsigned char*)rasqal_alloc_memory(strlen((const char*)blank) + 1); |
| 588 |
if (!new_blank) |
| 589 |
return NULL; |
| 590 |
strcpy((char*)new_blank, (const char*)blank); |
| 591 |
/* transfer new_blank ownership to literal */ |
| 592 |
l = rasqal_new_simple_literal(rasqal_world_ptr, RASQAL_LITERAL_BLANK, (const unsigned char*)new_blank); |
| 593 |
} |
| 594 |
|
| 595 |
return l; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
/** A query object */ |
| 600 |
struct librdf_query_s { |
| 601 |
librdf_world *world; |
| 602 |
int usage; |
| 603 |
void *context; |
| 604 |
void* factory; |
| 605 |
|
| 606 |
/* list of all the results for this query */ |
| 607 |
librdf_query_results* results; |
| 608 |
}; |
| 609 |
|
| 610 |
typedef struct { |
| 611 |
librdf_query *query; /* librdf query object */ |
| 612 |
librdf_model *model; |
| 613 |
rasqal_query *rq; |
| 614 |
rasqal_query_results *results; |
| 615 |
char *language; /* rasqal query language name to use */ |
| 616 |
unsigned char *query_string; |
| 617 |
librdf_uri *uri; /* base URI or NULL */ |
| 618 |
|
| 619 |
int errors; |
| 620 |
int warnings; |
| 621 |
} librdf_query_rasqal_context; |
| 622 |
|
| 623 |
|
| 624 |
/* prototypes for local functions */ |
| 625 |
static int rasqal_redland_init_triples_match(rasqal_triples_match* rtm, rasqal_triples_source *rts, void *user_data, rasqal_triple_meta *m, rasqal_triple *t); |
| 626 |
static int rasqal_redland_triple_present(rasqal_triples_source *rts, void *user_data, rasqal_triple *t); |
| 627 |
static void rasqal_redland_free_triples_source(void *user_data); |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
typedef struct { |
| 635 |
librdf_world *world; |
| 636 |
librdf_query *query; |
| 637 |
librdf_model *model; |
| 638 |
} rasqal_redland_triples_source_user_data; |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
static int |
| 643 |
rasqal_redland_new_triples_source(rasqal_query* rdf_query, |
| 644 |
void *factory_user_data, |
| 645 |
void *user_data, |
| 646 |
rasqal_triples_source *rts) { |
| 647 |
librdf_world *world = (librdf_world*)factory_user_data; |
| 648 |
rasqal_redland_triples_source_user_data* rtsc = (rasqal_redland_triples_source_user_data*)user_data; |
| 649 |
rasqal_world* rasqal_world_ptr = librdf_world_get_rasqal(world); |
| 650 |
raptor_world* raptor_world_ptr = rasqal_world_get_raptor(rasqal_world_ptr); |
| 651 |
|
| 652 |
raptor_sequence *seq; |
| 653 |
librdf_query_rasqal_context *context; |
| 654 |
librdf_iterator* cit; |
| 655 |
|
| 656 |
rtsc->world = world; |
| 657 |
rtsc->query = (librdf_query*)rasqal_query_get_user_data(rdf_query); |
| 658 |
context = (librdf_query_rasqal_context*)((librdf_query_s*)rtsc->query)->context; |
| 659 |
rtsc->model = context->model; |
| 660 |
|
| 661 |
seq = rasqal_query_get_data_graph_sequence(rdf_query); |
| 662 |
|
| 663 |
/* FIXME: queries with data graphs in them (such as FROM in SPARQL) |
| 664 |
* are deleted, so that there are no unexpected data loads |
| 665 |
*/ |
| 666 |
if (seq) { |
| 667 |
while (raptor_sequence_size(seq)) { |
| 668 |
rasqal_data_graph* dg = (rasqal_data_graph*)raptor_sequence_pop(seq); |
| 669 |
rasqal_free_data_graph(dg); |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
if (librdf_model_supports_contexts(rtsc->model)) { |
| 674 |
/* Add all contexts (named graphs) to the query so Rasqal can bind them */ |
| 675 |
cit = librdf_model_get_contexts(rtsc->model); |
| 676 |
while (!librdf_iterator_end(cit)) { |
| 677 |
librdf_node* node = (librdf_node*)librdf_iterator_get_object(cit); |
| 678 |
librdf_uri* uri; |
| 679 |
raptor_uri* source_uri; |
| 680 |
rasqal_data_graph* dg; |
| 681 |
|
| 682 |
uri = librdf_node_get_uri(node); |
| 683 |
source_uri = (raptor_uri*)raptor_new_uri(raptor_world_ptr, |
| 684 |
librdf_uri_as_string(uri)); |
| 685 |
|
| 686 |
dg = rasqal_new_data_graph_from_uri(rasqal_world_ptr, |
| 687 |
source_uri, source_uri, |
| 688 |
RASQAL_DATA_GRAPH_NAMED, |
| 689 |
NULL, NULL, NULL); |
| 690 |
rasqal_query_add_data_graph(rdf_query, dg); |
| 691 |
|
| 692 |
raptor_free_uri(source_uri); |
| 693 |
librdf_iterator_next(cit); |
| 694 |
} |
| 695 |
librdf_free_iterator(cit); |
| 696 |
} |
| 697 |
|
| 698 |
#ifdef RASQAL_TRIPLES_SOURCE_MIN_VERSION |
| 699 |
rts->version = 1; |
| 700 |
#endif |
| 701 |
|
| 702 |
rts->init_triples_match = rasqal_redland_init_triples_match; |
| 703 |
rts->triple_present = rasqal_redland_triple_present; |
| 704 |
rts->free_triples_source = rasqal_redland_free_triples_source; |
| 705 |
|
| 706 |
return 0; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
/** |
| 712 |
* librdf_model_contains_statement: |
| 713 |
* @model: the model object |
| 714 |
* @statement: the statement |
| 715 |
* |
| 716 |
* Check for a statement in the model. |
| 717 |
* |
| 718 |
* It must be a complete statement - all of subject, predicate, |
| 719 |
* object parts must be present and a legal RDF triple. Use |
| 720 |
* librdf_model_find_statements to search for partial statement |
| 721 |
* matches. |
| 722 |
* |
| 723 |
* WARNING: librdf_model_contains_statement may not work correctly |
| 724 |
* with stores using contexts. In this case, a search using |
| 725 |
* librdf_model_find_statements for a non-empty list will |
| 726 |
* return the correct result. |
| 727 |
* |
| 728 |
* Return value: non 0 if the model contains the statement (>0 if the statement is illegal) |
| 729 |
**/ |
| 730 |
int librdf_model_contains_statement_with_context(librdf_model* model, librdf_statement* statement, librdf_node* context) { |
| 731 |
//if (!librdf_statement_is_complete(statement)) |
| 732 |
// return 1; |
| 733 |
|
| 734 |
return ((librdf_model_factory_s*)((librdf_model_s*)model)->factory)->contains_statement_with_context(model, statement, context) ? -1 : 0; |
| 735 |
} |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
static int |
| 740 |
rasqal_redland_triple_present(rasqal_triples_source *rts, void *user_data, |
| 741 |
rasqal_triple *t) { |
| 742 |
rasqal_redland_triples_source_user_data* rtsc = (rasqal_redland_triples_source_user_data*)user_data; |
| 743 |
librdf_node* nodes[4]; |
| 744 |
librdf_statement *s; |
| 745 |
int rc; |
| 746 |
|
| 747 |
/* ASSUMPTION: all the parts of the triple are not variables */ |
| 748 |
/* FIXME: and no error checks */ |
| 749 |
//nodes[0] = rasqal_literal_to_redland_node(rtsc->world, t->subject); |
| 750 |
//nodes[1] = rasqal_literal_to_redland_node(rtsc->world, t->predicate); |
| 751 |
//nodes[2] = rasqal_literal_to_redland_node(rtsc->world, t->object); |
| 752 |
nodes[0] = NULL; |
| 753 |
nodes[1] = NULL; |
| 754 |
nodes[2] = NULL; |
| 755 |
if (t->origin != NULL) { |
| 756 |
//nodes[3] = rasqal_literal_to_redland_node(rtsc->world, t->origin); |
| 757 |
//nodes[3] = (librdf_node*)t->origin; |
| 758 |
nodes[3] = (librdf_node*)t->origin; |
| 759 |
//nodes[3] = (librdf_node*)t->origin; |
| 760 |
} else { |
| 761 |
nodes[3] = NULL; |
| 762 |
} |
| 763 |
|
| 764 |
//s = librdf_new_statement_from_nodes(rtsc->world, nodes[0], nodes[1], nodes[2]); |
| 765 |
s = NULL; |
| 766 |
|
| 767 |
//rc = librdf_model_contains_statement(rtsc->model, s); |
| 768 |
rc = librdf_model_contains_statement_with_context(rtsc->model, s, nodes[3]); |
| 769 |
//librdf_free_statement(s); |
| 770 |
return rc; |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
static void |
| 776 |
rasqal_redland_free_triples_source(void *user_data) { |
| 777 |
/* rasqal_redland_triples_source_user_data* rtsc=(rasqal_redland_triples_source_user_data*)user_data; */ |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
#ifdef RASQAL_TRIPLES_SOURCE_FACTORY_MIN_VERSION |
| 782 |
#define RTS_RET int |
| 783 |
#else |
| 784 |
#define RTS_RET void |
| 785 |
#endif |
| 786 |
|
| 787 |
static RTS_RET |
| 788 |
rasqal_redland_register_triples_source_factory(rasqal_triples_source_factory *factory) { |
| 789 |
#ifdef RASQAL_TRIPLES_SOURCE_FACTORY_MIN_VERSION |
| 790 |
factory->version = 1; |
| 791 |
#endif |
| 792 |
factory->user_data_size = sizeof(rasqal_redland_triples_source_user_data); |
| 793 |
factory->new_triples_source = rasqal_redland_new_triples_source; |
| 794 |
|
| 795 |
#ifdef RASQAL_TRIPLES_SOURCE_FACTORY_MIN_VERSION |
| 796 |
return 0; |
| 797 |
#endif |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
struct librdf_stream_s { |
| 803 |
librdf_world *world; |
| 804 |
void *context; |
| 805 |
int is_finished; /* 1 when have no more statements */ |
| 806 |
int is_updated; /* 1 when we know there is a current item */ |
| 807 |
int is_updating; /* 1 when are in the middle of update process */ |
| 808 |
|
| 809 |
/* Used when mapping */ |
| 810 |
librdf_statement *current; |
| 811 |
librdf_list *map_list; /* non-empty means there is a list of maps */ |
| 812 |
|
| 813 |
int(*is_end_method)(void*); |
| 814 |
int(*next_method)(void*); |
| 815 |
void* (*get_method)(void*, int); /* flags: type of get */ |
| 816 |
void(*finished_method)(void*); |
| 817 |
}; |
| 818 |
|
| 819 |
typedef struct { |
| 820 |
librdf_node* nodes[3]; |
| 821 |
librdf_node* origin; |
| 822 |
/* query statement, made from the nodes above (even when exact) */ |
| 823 |
librdf_statement *qstatement; |
| 824 |
librdf_stream *stream; |
| 825 |
} rasqal_redland_triples_match_context; |
| 826 |
|
| 827 |
|
| 828 |
static rasqal_triple_parts |
| 829 |
rasqal_redland_bind_match(struct rasqal_triples_match_s* rtm, |
| 830 |
void *user_data, |
| 831 |
rasqal_variable* bindings[4], |
| 832 |
rasqal_triple_parts parts) { |
| 833 |
rasqal_redland_triples_match_context* rtmc = (rasqal_redland_triples_match_context*)rtm->user_data; |
| 834 |
rasqal_literal* l; |
| 835 |
librdf_statement* statement; |
| 836 |
rasqal_triple_parts result = (rasqal_triple_parts)0; |
| 837 |
librdf_world *world = ((librdf_stream_s*)rtmc->stream)->world; |
| 838 |
|
| 839 |
statement = librdf_stream_get_object(rtmc->stream); |
| 840 |
if (!statement) |
| 841 |
return (rasqal_triple_parts)0; |
| 842 |
|
| 843 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 844 |
LIBRDF_DEBUG1(" matched statement "); |
| 845 |
librdf_statement_print(statement, stderr); |
| 846 |
fputc('\n', stderr); |
| 847 |
#endif |
| 848 |
|
| 849 |
/* set 1 or 2 variable values from the fields of statement */ |
| 850 |
|
| 851 |
if (bindings[0] && (parts & RASQAL_TRIPLE_SUBJECT)) { |
| 852 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 853 |
LIBRDF_DEBUG1("binding subject to variable\n"); |
| 854 |
#endif |
| 855 |
|
| 856 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 857 |
l = redland_node_to_rasqal_literal(world, |
| 858 |
librdf_statement_get_subject(statement)); |
| 859 |
#else |
| 860 |
l = (rasqal_literal*)librdf_statement_get_subject(statement); |
| 861 |
statement->subject = NULL; |
| 862 |
#endif // KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 863 |
|
| 864 |
|
| 865 |
rasqal_variable_set_value(bindings[0], l); |
| 866 |
result = RASQAL_TRIPLE_SUBJECT; |
| 867 |
} |
| 868 |
|
| 869 |
if (bindings[1] && (parts & RASQAL_TRIPLE_PREDICATE)) { |
| 870 |
if ( |
| 871 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 872 |
false && |
| 873 |
#endif // KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 874 |
bindings[0] == bindings[1]) { |
| 875 |
/* check matching(?x, ?x, ...) / subject=predicate */ |
| 876 |
if (!librdf_node_equals(librdf_statement_get_subject(statement), |
| 877 |
librdf_statement_get_predicate(statement))) |
| 878 |
return (rasqal_triple_parts)0; |
| 879 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 880 |
LIBRDF_DEBUG1("subject and predicate values match\n"); |
| 881 |
#endif |
| 882 |
} else { |
| 883 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 884 |
LIBRDF_DEBUG1("binding predicate to variable\n"); |
| 885 |
#endif |
| 886 |
|
| 887 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 888 |
l = redland_node_to_rasqal_literal(world, |
| 889 |
librdf_statement_get_predicate(statement)); |
| 890 |
#else |
| 891 |
l = (rasqal_literal*)librdf_statement_get_predicate(statement); |
| 892 |
statement->predicate = NULL; |
| 893 |
#endif // KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 894 |
|
| 895 |
|
| 896 |
rasqal_variable_set_value(bindings[1], l); |
| 897 |
result = (rasqal_triple_parts)(result | RASQAL_TRIPLE_PREDICATE); |
| 898 |
} |
| 899 |
} |
| 900 |
|
| 901 |
if (bindings[2] && (parts & RASQAL_TRIPLE_OBJECT)) { |
| 902 |
int bind = 1; |
| 903 |
|
| 904 |
if ( |
| 905 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 906 |
false && |
| 907 |
#endif // KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 908 |
bindings[0] == bindings[2]) { |
| 909 |
/* check matching (?x, ..., ?x) / subject=object */ |
| 910 |
if (!librdf_node_equals(librdf_statement_get_subject(statement), |
| 911 |
librdf_statement_get_object(statement))) |
| 912 |
return (rasqal_triple_parts)0; |
| 913 |
bind = 0; |
| 914 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 915 |
LIBRDF_DEBUG1("subject and object values match\n"); |
| 916 |
#endif |
| 917 |
} |
| 918 |
if ( |
| 919 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 920 |
false && |
| 921 |
#endif // KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 922 |
(bindings[1] == bindings[2]) && |
| 923 |
!(bindings[0] == bindings[1])) { |
| 924 |
/* check matching (..., ?x, ?x) / predicate=object |
| 925 |
* Don't do this if matching (?x, ?x, ...) / subject=predicate |
| 926 |
* was already done since that would mean the match was (?x, ?x, ?x) |
| 927 |
*/ |
| 928 |
if (!librdf_node_equals(librdf_statement_get_predicate(statement), |
| 929 |
librdf_statement_get_object(statement))) |
| 930 |
return (rasqal_triple_parts)0; |
| 931 |
bind = 0; |
| 932 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 933 |
LIBRDF_DEBUG1("predicate and object values match\n"); |
| 934 |
#endif |
| 935 |
} |
| 936 |
|
| 937 |
if (bind) { |
| 938 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 939 |
LIBRDF_DEBUG1("binding object to variable\n"); |
| 940 |
#endif |
| 941 |
|
| 942 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 943 |
l = redland_node_to_rasqal_literal(world, |
| 944 |
librdf_statement_get_object(statement)); |
| 945 |
#else |
| 946 |
l = (rasqal_literal*)librdf_statement_get_object(statement); |
| 947 |
statement->object = NULL; |
| 948 |
#endif // KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 949 |
|
| 950 |
rasqal_variable_set_value(bindings[2], l); |
| 951 |
result = (rasqal_triple_parts)(result | RASQAL_TRIPLE_OBJECT); |
| 952 |
} |
| 953 |
} |
| 954 |
|
| 955 |
/* Contexts */ |
| 956 |
if ( |
| 957 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 958 |
false && |
| 959 |
#endif // KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 960 |
bindings[3] && (parts & RASQAL_TRIPLE_ORIGIN)) { |
| 961 |
int bind = 1; |
| 962 |
librdf_node* context_node = librdf_stream_get_context2(rtmc->stream); |
| 963 |
|
| 964 |
if (bindings[0] == bindings[3]) { |
| 965 |
/* check matching (?x, ..., ...) in context ?x */ |
| 966 |
if (!librdf_node_equals(librdf_statement_get_subject(statement), |
| 967 |
context_node)) |
| 968 |
return (rasqal_triple_parts)0; |
| 969 |
bind = 0; |
| 970 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 971 |
LIBRDF_DEBUG1("subject and context values match\n"); |
| 972 |
#endif |
| 973 |
} |
| 974 |
|
| 975 |
if (bindings[1] == bindings[3]) { |
| 976 |
/* check matching (..., ?x, ...) in context ?x */ |
| 977 |
if (!librdf_node_equals(librdf_statement_get_predicate(statement), |
| 978 |
context_node)) |
| 979 |
return (rasqal_triple_parts)0; |
| 980 |
bind = 0; |
| 981 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 982 |
LIBRDF_DEBUG1("predicate and context values match\n"); |
| 983 |
#endif |
| 984 |
} |
| 985 |
|
| 986 |
if (bindings[2] == bindings[3]) { |
| 987 |
/* check matching (..., ..., ?x) in context ?x */ |
| 988 |
if (!librdf_node_equals(librdf_statement_get_object(statement), |
| 989 |
context_node)) |
| 990 |
return (rasqal_triple_parts)0; |
| 991 |
bind = 0; |
| 992 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 993 |
LIBRDF_DEBUG1("object and context values match\n"); |
| 994 |
#endif |
| 995 |
} |
| 996 |
|
| 997 |
if (bind) { |
| 998 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 999 |
LIBRDF_DEBUG1("binding origin to variable\n"); |
| 1000 |
#endif |
| 1001 |
if (context_node) |
| 1002 |
l = redland_node_to_rasqal_literal(world, context_node); |
| 1003 |
else |
| 1004 |
l = NULL; |
| 1005 |
rasqal_variable_set_value(bindings[3], l); |
| 1006 |
result = (rasqal_triple_parts)(result | RASQAL_TRIPLE_ORIGIN); |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 1012 |
if (statement->subject) { |
| 1013 |
rasqal_free_literal((rasqal_literal*)statement->subject); |
| 1014 |
statement->subject = NULL; |
| 1015 |
} |
| 1016 |
if (statement->predicate) { |
| 1017 |
rasqal_free_literal((rasqal_literal*)statement->predicate); |
| 1018 |
statement->predicate = NULL; |
| 1019 |
} |
| 1020 |
if (statement->object) { |
| 1021 |
rasqal_free_literal((rasqal_literal*)statement->object); |
| 1022 |
statement->object = NULL; |
| 1023 |
} |
| 1024 |
#endif // KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 1025 |
|
| 1026 |
return parts; |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
static void |
| 1031 |
rasqal_redland_next_match(struct rasqal_triples_match_s* rtm, |
| 1032 |
void *user_data) { |
| 1033 |
rasqal_redland_triples_match_context* rtmc = (rasqal_redland_triples_match_context*)rtm->user_data; |
| 1034 |
|
| 1035 |
librdf_stream_next(rtmc->stream); |
| 1036 |
} |
| 1037 |
|
| 1038 |
static int |
| 1039 |
rasqal_redland_is_end(struct rasqal_triples_match_s* rtm, |
| 1040 |
void *user_data) { |
| 1041 |
rasqal_redland_triples_match_context* rtmc = (rasqal_redland_triples_match_context*)rtm->user_data; |
| 1042 |
|
| 1043 |
return librdf_stream_end(rtmc->stream); |
| 1044 |
} |
| 1045 |
|
| 1046 |
|
| 1047 |
static void |
| 1048 |
rasqal_redland_finish_triples_match(struct rasqal_triples_match_s* rtm, |
| 1049 |
void *user_data) { |
| 1050 |
rasqal_redland_triples_match_context* rtmc = (rasqal_redland_triples_match_context*)rtm->user_data; |
| 1051 |
|
| 1052 |
if (rtmc) { |
| 1053 |
if (rtmc->stream) { |
| 1054 |
librdf_free_stream(rtmc->stream); |
| 1055 |
rtmc->stream = NULL; |
| 1056 |
} |
| 1057 |
if (rtmc->qstatement) { |
| 1058 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 1059 |
if (rtmc->qstatement->subject) { |
| 1060 |
rasqal_free_literal((rasqal_literal*)rtmc->qstatement->subject); |
| 1061 |
rtmc->qstatement->subject = NULL; |
| 1062 |
} |
| 1063 |
if (rtmc->qstatement->predicate) { |
| 1064 |
rasqal_free_literal((rasqal_literal*)rtmc->qstatement->predicate); |
| 1065 |
rtmc->qstatement->predicate = NULL; |
| 1066 |
} |
| 1067 |
if (rtmc->qstatement->object) { |
| 1068 |
rasqal_free_literal((rasqal_literal*)rtmc->qstatement->object); |
| 1069 |
rtmc->qstatement->object = NULL; |
| 1070 |
} |
| 1071 |
#endif // KONCLUDE_REDLAND_RASQAL_SUBQUERY_DIRECT_RASQAL_LITERAL_RESOLVING |
| 1072 |
librdf_free_statement(rtmc->qstatement); |
| 1073 |
rtmc->qstatement = NULL; |
| 1074 |
} |
| 1075 |
LIBRDF_FREE(rasqal_redland_triples_match_context, rtmc); |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
|
| 1080 |
static int |
| 1081 |
rasqal_redland_init_triples_match(rasqal_triples_match* rtm, |
| 1082 |
rasqal_triples_source *rts, void *user_data, |
| 1083 |
rasqal_triple_meta *m, rasqal_triple *t) { |
| 1084 |
rasqal_redland_triples_source_user_data* rtsc = (rasqal_redland_triples_source_user_data*)user_data; |
| 1085 |
rasqal_redland_triples_match_context* rtmc; |
| 1086 |
rasqal_variable* var; |
| 1087 |
|
| 1088 |
rtm->bind_match = rasqal_redland_bind_match; |
| 1089 |
rtm->next_match = rasqal_redland_next_match; |
| 1090 |
rtm->is_end = rasqal_redland_is_end; |
| 1091 |
rtm->finish = rasqal_redland_finish_triples_match; |
| 1092 |
|
| 1093 |
rtmc = LIBRDF_CALLOC(rasqal_redland_triples_match_context*, 1, sizeof(*rtmc)); |
| 1094 |
if (!rtmc) |
| 1095 |
return 1; |
| 1096 |
|
| 1097 |
rtm->user_data = rtmc; |
| 1098 |
|
| 1099 |
|
| 1100 |
/* at least one of the triple terms is a variable and we need to |
| 1101 |
* do a triplesMatching() aka librdf_model_find_statements |
| 1102 |
* |
| 1103 |
* redland find_statements will do the right thing and internally |
| 1104 |
* pick the most efficient, indexed way to get the answer. |
| 1105 |
*/ |
| 1106 |
|
| 1107 |
if ((var = rasqal_literal_as_variable(t->subject))) { |
| 1108 |
if (var->value) { |
| 1109 |
//rtmc->nodes[0] = rasqal_literal_to_redland_node(rtsc->world, var->value); |
| 1110 |
rtmc->nodes[0] = NULL; |
| 1111 |
var = NULL; |
| 1112 |
} else { |
| 1113 |
rtmc->nodes[0] = NULL; |
| 1114 |
} |
| 1115 |
} else { |
| 1116 |
//rtmc->nodes[0] = rasqal_literal_to_redland_node(rtsc->world, t->subject); |
| 1117 |
rtmc->nodes[0] = NULL; |
| 1118 |
} |
| 1119 |
|
| 1120 |
m->bindings[0] = var; |
| 1121 |
|
| 1122 |
|
| 1123 |
if ((var = rasqal_literal_as_variable(t->predicate))) { |
| 1124 |
if (var->value) { |
| 1125 |
//rtmc->nodes[1] = rasqal_literal_to_redland_node(rtsc->world, var->value); |
| 1126 |
rtmc->nodes[1] = NULL; |
| 1127 |
var = NULL; |
| 1128 |
} else { |
| 1129 |
rtmc->nodes[1] = NULL; |
| 1130 |
} |
| 1131 |
} else { |
| 1132 |
//rtmc->nodes[1] = rasqal_literal_to_redland_node(rtsc->world, t->predicate); |
| 1133 |
rtmc->nodes[1] = NULL; |
| 1134 |
} |
| 1135 |
|
| 1136 |
m->bindings[1] = var; |
| 1137 |
|
| 1138 |
|
| 1139 |
if ((var = rasqal_literal_as_variable(t->object))) { |
| 1140 |
if (var->value) { |
| 1141 |
//rtmc->nodes[2] = rasqal_literal_to_redland_node(rtsc->world, var->value); |
| 1142 |
rtmc->nodes[2] = NULL; |
| 1143 |
var = NULL; |
| 1144 |
} else { |
| 1145 |
rtmc->nodes[2] = NULL; |
| 1146 |
} |
| 1147 |
} else { |
| 1148 |
//rtmc->nodes[2] = rasqal_literal_to_redland_node(rtsc->world, t->object); |
| 1149 |
rtmc->nodes[2] = NULL; |
| 1150 |
} |
| 1151 |
|
| 1152 |
m->bindings[2] = var; |
| 1153 |
|
| 1154 |
|
| 1155 |
if (t->origin != NULL) { |
| 1156 |
//if ((var = rasqal_literal_as_variable(t->origin))) { |
| 1157 |
// if (var->value) { |
| 1158 |
// rtmc->origin = rasqal_literal_to_redland_node(rtsc->world, var->value); |
| 1159 |
// } |
| 1160 |
//} else { |
| 1161 |
// rtmc->origin = rasqal_literal_to_redland_node(rtsc->world, t->origin); |
| 1162 |
rtmc->origin = (librdf_node*)t->origin; |
| 1163 |
//rtmc->origin = (librdf_node*)t->origin; |
| 1164 |
//} |
| 1165 |
//m->bindings[3] = var; |
| 1166 |
} |
| 1167 |
|
| 1168 |
rtmc->qstatement = NULL; |
| 1169 |
//rtmc->qstatement = librdf_new_statement_from_nodes(rtsc->world, |
| 1170 |
// rtmc->nodes[0], |
| 1171 |
// rtmc->nodes[1], |
| 1172 |
// rtmc->nodes[2]); |
| 1173 |
//if (!rtmc->qstatement) { |
| 1174 |
// return 1; |
| 1175 |
//} |
| 1176 |
|
| 1177 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 1178 |
//LIBRDF_DEBUG1("query statement: "); |
| 1179 |
//librdf_statement_print(rtmc->qstatement, stderr); |
| 1180 |
//if (rtmc->origin) { |
| 1181 |
// fput(" with context node: ", stderr); |
| 1182 |
// librdf_node_print(rtmc->origin, stderr); |
| 1183 |
//} |
| 1184 |
//fputc('\n', stderr); |
| 1185 |
#endif |
| 1186 |
|
| 1187 |
if (rtmc->origin) { |
| 1188 |
rtmc->stream = ((librdf_model_factory_s*)((librdf_model_s*)rtsc->model)->factory)->find_statements_in_context(rtsc->model, rtmc->qstatement, rtmc->origin); |
| 1189 |
} else { |
| 1190 |
rtmc->stream = ((librdf_model_factory_s*)((librdf_model_s*)rtsc->model)->factory)->find_statements(rtsc->model, rtmc->qstatement); |
| 1191 |
} |
| 1192 |
|
| 1193 |
if (!rtmc->stream) |
| 1194 |
return 1; |
| 1195 |
|
| 1196 |
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1 |
| 1197 |
LIBRDF_DEBUG1("rasqal_init_triples_match done\n"); |
| 1198 |
#endif |
| 1199 |
|
| 1200 |
return 0; |
| 1201 |
} |
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
rasqal_literal* create_literal_from_binding(CRedlandRasqalSubQueryProcessingData* subQueryProcData, CVariableBindingResult* varBin) { |
| 1318 |
rasqal_literal* l = nullptr; |
| 1319 |
librdf_world* world = subQueryProcData->getRedlandWorld(); |
| 1320 |
rasqal_world* rasqal_world_ptr = librdf_world_get_rasqal(world); |
| 1321 |
if (varBin) { |
| 1322 |
if (varBin->isNamedIndividualBindingType() ) { |
| 1323 |
QByteArray bytes = varBin->getNamedIndividualBindingString().toUtf8(); |
| 1324 |
raptor_uri* uri = (raptor_uri*)librdf_new_uri(world, (const unsigned char*)bytes.constData()); |
| 1325 |
l = rasqal_new_uri_literal(rasqal_world_ptr, uri); /* transfer uri ownership to literal */ |
| 1326 |
} else if (varBin->isClassBindingType()) { |
| 1327 |
QByteArray bytes = varBin->getClassBindingString().toUtf8(); |
| 1328 |
raptor_uri* uri = (raptor_uri*)librdf_new_uri(world, (const unsigned char*)bytes.constData()); |
| 1329 |
l = rasqal_new_uri_literal(rasqal_world_ptr, uri); /* transfer uri ownership to literal */ |
| 1330 |
} else if (varBin->isPropertyBindingType()) { |
| 1331 |
QByteArray bytes = varBin->getPropertyBindingString().toUtf8(); |
| 1332 |
raptor_uri* uri = (raptor_uri*)librdf_new_uri(world, (const unsigned char*)bytes.constData()); |
| 1333 |
l = rasqal_new_uri_literal(rasqal_world_ptr, uri); /* transfer uri ownership to literal */ |
| 1334 |
} else if (varBin->isAnonymousIndividualBindingType()) { |
| 1335 |
} else if (varBin->isLiteralBindingType()) { |
| 1336 |
QPair<QString, QString> litTypePair = varBin->getLiteralDatatypeDatavalueBindingStringPair(); |
| 1337 |
QByteArray datatypeBytes = litTypePair.first.toUtf8(); |
| 1338 |
QByteArray literalBytes = litTypePair.second.toUtf8(); |
| 1339 |
|
| 1340 |
//librdf_uri* datatypeUri = librdf_new_uri(world, (const unsigned char*)datatypeBytes.constData()); |
| 1341 |
raptor_uri* datatypeUri = raptor_new_uri(librdf_world_get_raptor(world), (const unsigned char*)datatypeBytes.constData()); |
| 1342 |
//uri = librdf_node_get_literal_value_datatype_uri(node); |
| 1343 |
//new_datatype = (raptor_uri*)librdf_new_uri_from_uri(uri); |
| 1344 |
//node = librdf_new_node_from_typed_literal(world, (const unsigned char*)literalBytes.constData(), NULL, datatypeUri); |
| 1345 |
|
| 1346 |
char *new_language = NULL; |
| 1347 |
unsigned char* new_string = (unsigned char*)rasqal_alloc_memory(literalBytes.length() + 1); |
| 1348 |
strcpy((char*)new_string, (const char*)literalBytes.constData()); |
| 1349 |
|
| 1350 |
l = rasqal_new_string_literal(rasqal_world_ptr, (const unsigned char*)new_string, new_language, datatypeUri, NULL); |
| 1351 |
} |
| 1352 |
} |
| 1353 |
return l; |
| 1354 |
} |
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
librdf_node* create_node_from_binding(CRedlandRasqalSubQueryProcessingData* subQueryProcData, CVariableBindingResult* varBin) { |
| 1362 |
librdf_node* node = nullptr; |
| 1363 |
librdf_world* world = subQueryProcData->getRedlandWorld(); |
| 1364 |
rasqal_world* rasqal_world_ptr = librdf_world_get_rasqal(world); |
| 1365 |
|
| 1366 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1367 |
if (varBin) { |
| 1368 |
if (varBin->isNamedIndividualBindingType()) { |
| 1369 |
QByteArray bytes = varBin->getNamedIndividualBindingString().toUtf8(); |
| 1370 |
librdf_uri *uri = librdf_new_uri(world, (const unsigned char*)bytes.constData()); |
| 1371 |
node = librdf_new_node_from_uri(world, uri); |
| 1372 |
} else if ( varBin->isPropertyBindingType()) { |
| 1373 |
QByteArray bytes = varBin->getPropertyBindingString().toUtf8(); |
| 1374 |
librdf_uri *uri = librdf_new_uri(world, (const unsigned char*)bytes.constData()); |
| 1375 |
node = librdf_new_node_from_uri(world, uri); |
| 1376 |
} else if ( varBin->isClassBindingType()) { |
| 1377 |
QByteArray bytes = varBin->getClassBindingString().toUtf8(); |
| 1378 |
librdf_uri *uri = librdf_new_uri(world, (const unsigned char*)bytes.constData()); |
| 1379 |
node = librdf_new_node_from_uri(world, uri); |
| 1380 |
} else if (varBin->isAnonymousIndividualBindingType()) { |
| 1381 |
} else if (varBin->isLiteralBindingType()) { |
| 1382 |
QPair<QString, QString> litTypePair = varBin->getLiteralDatatypeDatavalueBindingStringPair(); |
| 1383 |
QByteArray datatypeBytes = litTypePair.first.toUtf8(); |
| 1384 |
QByteArray literalBytes = litTypePair.second.toUtf8(); |
| 1385 |
librdf_uri* datatypeUri = librdf_new_uri(world, (const unsigned char*)datatypeBytes.constData()); |
| 1386 |
node = librdf_new_node_from_typed_literal(world, (const unsigned char*)literalBytes.constData(), NULL, datatypeUri); |
| 1387 |
} |
| 1388 |
} else { |
| 1389 |
node = librdf_new_node_from_node(subQueryProcData->getDefaultReturningNode()); |
| 1390 |
} |
| 1391 |
|
| 1392 |
|
| 1393 |
#else |
| 1394 |
rasqal_literal* l = create_literal_from_binding(subQueryProcData, varBin); |
| 1395 |
node = (librdf_node*)l; |
| 1396 |
#endif |
| 1397 |
|
| 1398 |
return node; |
| 1399 |
} |
| 1400 |
|
| 1401 |
librdf_node* create_node_from_binding(CRedlandRasqalSubQueryProcessingData* subQueryProcData, QVector<CVariableBindingResult*>* bindingsVec, CRedlandRasqalSubQueryTripleResolvingData* resolvingData, cint64 pos) { |
| 1402 |
librdf_node* node = nullptr; |
| 1403 |
librdf_world* world = subQueryProcData->getRedlandWorld(); |
| 1404 |
if (!resolvingData->getVariableBound(pos)) { |
| 1405 |
cint64 bindingPos = resolvingData->getBindingsVectorResolvingPosition(pos); |
| 1406 |
if (bindingPos >= 0) { |
| 1407 |
if (bindingPos < bindingsVec->size()) { |
| 1408 |
CVariableBindingResult* varBin = (*bindingsVec)[bindingPos]; |
| 1409 |
node = create_node_from_binding(subQueryProcData, varBin); |
| 1410 |
} else { |
| 1411 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1412 |
node = librdf_new_node_from_node(subQueryProcData->getDefaultReturningNode()); |
| 1413 |
#else |
| 1414 |
node = (librdf_node*)rasqal_new_literal_from_literal((rasqal_literal*)subQueryProcData->getDefaultReturningNode()); |
| 1415 |
#endif |
| 1416 |
} |
| 1417 |
} else { |
| 1418 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1419 |
node = librdf_new_node_from_node(subQueryProcData->getDefaultReturningNode()); |
| 1420 |
#else |
| 1421 |
node = NULL; |
| 1422 |
#endif |
| 1423 |
} |
| 1424 |
} else { |
| 1425 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1426 |
node = librdf_new_node_from_node(resolvingData->getBoundNode(pos)); |
| 1427 |
#else |
| 1428 |
//node = (librdf_node*)rasqal_new_literal_from_literal(resolvingData->getBoundLiteral(pos)); |
| 1429 |
node = NULL; |
| 1430 |
#endif |
| 1431 |
} |
| 1432 |
return node; |
| 1433 |
} |
| 1434 |
|
| 1435 |
|
| 1436 |
librdf_statement* create_statement_from_bindings(CRedlandRasqalSubQueryProcessingData* subQueryProcData, QVector<CVariableBindingResult*>* bindingsVec, CRedlandRasqalSubQueryTripleResolvingData* resolvingData) { |
| 1437 |
librdf_world* world = subQueryProcData->getRedlandWorld(); |
| 1438 |
librdf_node* subjectNode = create_node_from_binding(subQueryProcData, bindingsVec, resolvingData, 0); |
| 1439 |
librdf_node* predicateNode = create_node_from_binding(subQueryProcData, bindingsVec, resolvingData, 1); |
| 1440 |
librdf_node* objectNode = create_node_from_binding(subQueryProcData, bindingsVec, resolvingData, 2); |
| 1441 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1442 |
librdf_statement* statement = librdf_new_statement_from_nodes(world, subjectNode, predicateNode, objectNode); |
| 1443 |
#else |
| 1444 |
librdf_statement* statement = resolvingData->getNextTransferringStatement(); |
| 1445 |
if (statement->subject) { |
| 1446 |
rasqal_free_literal((rasqal_literal*)statement->subject); |
| 1447 |
statement->subject = NULL; |
| 1448 |
} |
| 1449 |
if (statement->predicate) { |
| 1450 |
rasqal_free_literal((rasqal_literal*)statement->predicate); |
| 1451 |
statement->predicate = NULL; |
| 1452 |
} |
| 1453 |
if (statement->object) { |
| 1454 |
rasqal_free_literal((rasqal_literal*)statement->object); |
| 1455 |
statement->object = NULL; |
| 1456 |
} |
| 1457 |
statement->subject = subjectNode; |
| 1458 |
statement->predicate = predicateNode; |
| 1459 |
statement->object = objectNode; |
| 1460 |
#endif |
| 1461 |
return statement; |
| 1462 |
} |
| 1463 |
|
| 1464 |
|
| 1465 |
void load_next_bindings(CRedlandRasqalSubQueryProcessingData* subQueryProcData) { |
| 1466 |
*subQueryProcData->getCurrentBindingsVector() = *subQueryProcData->getNextBindingsVector(); |
| 1467 |
CVariableBindingsResultIterator* varBindIt = subQueryProcData->getVariableBindingsIterator(); |
| 1468 |
for (cint64 i = 0; i < subQueryProcData->getNextBindingsVector()->count(); ++i) { |
| 1469 |
(*subQueryProcData->getNextBindingsVector())[i] = nullptr; |
| 1470 |
} |
| 1471 |
for (cint64 i = 0; i < subQueryProcData->getTriplesResolvingDataVector()->count(); ++i) { |
| 1472 |
(*subQueryProcData->getTriplesResolvingDataVector())[i]->setResolved(false); |
| 1473 |
} |
| 1474 |
if (varBindIt) { |
| 1475 |
cint64 nextPos = 0; |
| 1476 |
while (varBindIt->hasNext()) { |
| 1477 |
CVariableBindingResult* varBin = varBindIt->getNext(true); |
| 1478 |
(*subQueryProcData->getNextBindingsVector())[nextPos++] = varBin; |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
} |
| 1483 |
|
| 1484 |
|
| 1485 |
int is_end_method_stream_next_answer_resolving(void* context) { |
| 1486 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = (CRedlandRasqalSubQueryProcessingData*)context; |
| 1487 |
subQueryProcData->setNextReturningPosition(subQueryProcData->getFirstTripleReturningBinding() + 1); |
| 1488 |
CVariableBindingsResultIterator* varBindIt = subQueryProcData->getVariableBindingsIterator(); |
| 1489 |
if (!varBindIt) { |
| 1490 |
return 1; |
| 1491 |
} |
| 1492 |
return 0; |
| 1493 |
} |
| 1494 |
|
| 1495 |
int next_method_stream_next_answer_resolving(void* context) { |
| 1496 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = (CRedlandRasqalSubQueryProcessingData*)context; |
| 1497 |
subQueryProcData->setNextReturningPosition(subQueryProcData->getFirstTripleReturningBinding() + 1); |
| 1498 |
CVariableBindingsAnswersResultIterator* answersIt = subQueryProcData->getAnswersIterator(); |
| 1499 |
CVariableBindingsResultIterator* varBindIt = subQueryProcData->getVariableBindingsIterator(); |
| 1500 |
if (answersIt) { |
| 1501 |
CVariableBindingsAnswerResult* varBindAnswer = answersIt->getNext(true); |
| 1502 |
if (varBindAnswer) { |
| 1503 |
varBindIt = varBindAnswer->getVariableBindingsIterator(varBindIt); |
| 1504 |
subQueryProcData->setVariableBindingsIterator(varBindIt); |
| 1505 |
if (!answersIt->hasNext()) { |
| 1506 |
subQueryProcData->setAnswersIterator(nullptr); |
| 1507 |
delete answersIt; |
| 1508 |
} |
| 1509 |
} else { |
| 1510 |
delete varBindIt; |
| 1511 |
varBindIt = nullptr; |
| 1512 |
subQueryProcData->setVariableBindingsIterator(varBindIt); |
| 1513 |
} |
| 1514 |
} else { |
| 1515 |
delete varBindIt; |
| 1516 |
varBindIt = nullptr; |
| 1517 |
subQueryProcData->setVariableBindingsIterator(varBindIt); |
| 1518 |
} |
| 1519 |
subQueryProcData->incVisitedResultCountStatistics(); |
| 1520 |
load_next_bindings(subQueryProcData); |
| 1521 |
if (!varBindIt) { |
| 1522 |
return 1; |
| 1523 |
} |
| 1524 |
return 0; |
| 1525 |
} |
| 1526 |
|
| 1527 |
void* get_method_stream_next_answer_resolving(void* context, int flags) { |
| 1528 |
librdf_node* node = nullptr; |
| 1529 |
|
| 1530 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = (CRedlandRasqalSubQueryProcessingData*)context; |
| 1531 |
QVector<CVariableBindingResult*>* nextBindingsVec = subQueryProcData->getNextBindingsVector(); |
| 1532 |
librdf_world* world = subQueryProcData->getRedlandWorld(); |
| 1533 |
subQueryProcData->setNextReturningPosition(subQueryProcData->getFirstTripleReturningBinding() + 1); |
| 1534 |
|
| 1535 |
CRedlandRasqalSubQueryTripleResolvingData* resolvingData = (*subQueryProcData->getTriplesResolvingDataVector())[subQueryProcData->getFirstTripleReturningBinding()]; |
| 1536 |
|
| 1537 |
librdf_statement* statement = create_statement_from_bindings(subQueryProcData, nextBindingsVec, resolvingData); |
| 1538 |
return (void*)statement; |
| 1539 |
} |
| 1540 |
|
| 1541 |
void finished_method_stream_next_answer_resolving(void* context) { |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
int is_end_method_stream_next_binding_resolving(void* context) { |
| 1553 |
|
| 1554 |
CRedlandRasqalSubQueryTripleResolvingData* bindingResolvingData = (CRedlandRasqalSubQueryTripleResolvingData*)context; |
| 1555 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = (CRedlandRasqalSubQueryProcessingData*)bindingResolvingData->getSubQueryProcessingData(); |
| 1556 |
|
| 1557 |
if (!subQueryProcData->getBaseAnswerResult() || subQueryProcData->getBaseAnswerResult()->getResultCount() <= 0) { |
| 1558 |
return 1; |
| 1559 |
} |
| 1560 |
|
| 1561 |
if (bindingResolvingData->isResolved()) { |
| 1562 |
return 1; |
| 1563 |
} |
| 1564 |
return 0; |
| 1565 |
} |
| 1566 |
|
| 1567 |
int next_method_stream_next_binding_resolving(void* context) { |
| 1568 |
CRedlandRasqalSubQueryTripleResolvingData* bindingResolvingData = (CRedlandRasqalSubQueryTripleResolvingData*)context; |
| 1569 |
bindingResolvingData->setResolved(true); |
| 1570 |
return 1; |
| 1571 |
} |
| 1572 |
|
| 1573 |
void* get_method_stream_next_binding_resolving(void* context, int flags) { |
| 1574 |
CRedlandRasqalSubQueryTripleResolvingData* bindingResolvingData = (CRedlandRasqalSubQueryTripleResolvingData*)context; |
| 1575 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = (CRedlandRasqalSubQueryProcessingData*)bindingResolvingData->getSubQueryProcessingData(); |
| 1576 |
QVector<CVariableBindingResult*>* currentBindingsVec = subQueryProcData->getCurrentBindingsVector(); |
| 1577 |
|
| 1578 |
librdf_statement* statement = create_statement_from_bindings(subQueryProcData, currentBindingsVec, bindingResolvingData); |
| 1579 |
|
| 1580 |
return (void*)statement; |
| 1581 |
} |
| 1582 |
|
| 1583 |
void finished_method_stream_next_binding_resolving(void* context) { |
| 1584 |
} |
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
int is_end_method_stream_next_boolean_result(void* context) { |
| 1606 |
|
| 1607 |
CRedlandRasqalSubQueryTripleResolvingData* bindingResolvingData = (CRedlandRasqalSubQueryTripleResolvingData*)context; |
| 1608 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = (CRedlandRasqalSubQueryProcessingData*)bindingResolvingData->getSubQueryProcessingData(); |
| 1609 |
|
| 1610 |
|
| 1611 |
if (!subQueryProcData->getBooleanQueryResult()) { |
| 1612 |
return 1; |
| 1613 |
} |
| 1614 |
|
| 1615 |
if (bindingResolvingData->isResolved()) { |
| 1616 |
return 1; |
| 1617 |
} |
| 1618 |
return 0; |
| 1619 |
} |
| 1620 |
|
| 1621 |
int next_method_stream_next_boolean_result(void* context) { |
| 1622 |
CRedlandRasqalSubQueryTripleResolvingData* bindingResolvingData = (CRedlandRasqalSubQueryTripleResolvingData*)context; |
| 1623 |
bindingResolvingData->setResolved(true); |
| 1624 |
return 1; |
| 1625 |
} |
| 1626 |
|
| 1627 |
void* get_method_stream_next_boolean_result(void* context, int flags) { |
| 1628 |
CRedlandRasqalSubQueryTripleResolvingData* bindingResolvingData = (CRedlandRasqalSubQueryTripleResolvingData*)context; |
| 1629 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = (CRedlandRasqalSubQueryProcessingData*)bindingResolvingData->getSubQueryProcessingData(); |
| 1630 |
QVector<CVariableBindingResult*>* currentBindingsVec = subQueryProcData->getCurrentBindingsVector(); |
| 1631 |
|
| 1632 |
librdf_statement* statement = create_statement_from_bindings(subQueryProcData, currentBindingsVec, bindingResolvingData); |
| 1633 |
|
| 1634 |
return (void*)statement; |
| 1635 |
} |
| 1636 |
|
| 1637 |
void finished_method_stream_next_boolean_result(void* context) { |
| 1638 |
} |
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
CRedlandRasqalSubQueryTripleResolvingData* get_triple_resolving_data(CRedlandRasqalSubQueryProcessingData* subQueryProcData, librdf_statement* statement, cint64 triplePos) { |
| 1653 |
QVector<CRedlandRasqalSubQueryTripleResolvingData*>* triplesResolvingDataVec = subQueryProcData->getTriplesResolvingDataVector(); |
| 1654 |
return (*triplesResolvingDataVec)[triplePos]; |
| 1655 |
} |
| 1656 |
|
| 1657 |
|
| 1658 |
bool update_triple_bound_variables_resolving_data(CRedlandRasqalSubQueryProcessingData* subQueryProcData, rasqal_triple* triple, cint64 triplePos, QVector<rasqal_literal*>& varBoundVec) { |
| 1659 |
bool requiresBindingReturning = false; |
| 1660 |
QVector<CRedlandRasqalSubQueryTripleResolvingData*>* triplesResolvingDataVec = subQueryProcData->getTriplesResolvingDataVector(); |
| 1661 |
librdf_world* world = subQueryProcData->getRedlandWorld(); |
| 1662 |
CRedlandRasqalSubQueryTripleResolvingData* tripleResolveData = (*triplesResolvingDataVec)[triplePos]; |
| 1663 |
|
| 1664 |
if (RASQAL_LITERAL_VARIABLE == rasqal_literal_get_type(triple->subject)) { |
| 1665 |
rasqal_variable * var = rasqal_literal_as_variable(triple->subject); |
| 1666 |
tripleResolveData->setSubjectVariable(var); |
| 1667 |
tripleResolveData->setSubjectVariableBound(var->value != nullptr); |
| 1668 |
cint64 bindingPos = tripleResolveData->getSubjectBindingsVectorResolvingPosition(); |
| 1669 |
if (var->value && !varBoundVec[bindingPos]) { |
| 1670 |
rasqal_literal* lit = rasqal_new_literal_from_literal(var->value); |
| 1671 |
varBoundVec[bindingPos] = lit; |
| 1672 |
tripleResolveData->setSubjectBoundLiteral(lit); |
| 1673 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1674 |
librdf_node* boundNode = rasqal_literal_to_redland_node(world, var->value); |
| 1675 |
tripleResolveData->setSubjectBoundNode(boundNode); |
| 1676 |
#endif |
| 1677 |
} else { |
| 1678 |
requiresBindingReturning = true; |
| 1679 |
tripleResolveData->setSubjectBoundNode(nullptr); |
| 1680 |
} |
| 1681 |
} else { |
| 1682 |
tripleResolveData->setSubjectVariable(nullptr); |
| 1683 |
} |
| 1684 |
|
| 1685 |
if (RASQAL_LITERAL_VARIABLE == rasqal_literal_get_type(triple->predicate)) { |
| 1686 |
rasqal_variable * var = rasqal_literal_as_variable(triple->predicate); |
| 1687 |
tripleResolveData->setPredicateVariable(var); |
| 1688 |
tripleResolveData->setPredicateVariableBound(var->value != nullptr); |
| 1689 |
cint64 bindingPos = tripleResolveData->getPredicateBindingsVectorResolvingPosition(); |
| 1690 |
if (var->value && !varBoundVec[bindingPos]) { |
| 1691 |
rasqal_literal* lit = rasqal_new_literal_from_literal(var->value); |
| 1692 |
varBoundVec[bindingPos] = lit; |
| 1693 |
tripleResolveData->setPredicateBoundLiteral(lit); |
| 1694 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1695 |
librdf_node* boundNode = rasqal_literal_to_redland_node(world, var->value); |
| 1696 |
tripleResolveData->setPredicateBoundNode(boundNode); |
| 1697 |
#endif |
| 1698 |
} else { |
| 1699 |
requiresBindingReturning = true; |
| 1700 |
tripleResolveData->setPredicateBoundNode(nullptr); |
| 1701 |
} |
| 1702 |
} else { |
| 1703 |
tripleResolveData->setPredicateVariable(nullptr); |
| 1704 |
} |
| 1705 |
|
| 1706 |
if (RASQAL_LITERAL_VARIABLE == rasqal_literal_get_type(triple->object)) { |
| 1707 |
rasqal_variable * var = rasqal_literal_as_variable(triple->object); |
| 1708 |
tripleResolveData->setObjectVariable(var); |
| 1709 |
tripleResolveData->setObjectVariableBound(var->value != nullptr); |
| 1710 |
cint64 bindingPos = tripleResolveData->getObjectBindingsVectorResolvingPosition(); |
| 1711 |
if (var->value && !varBoundVec[bindingPos]) { |
| 1712 |
rasqal_literal* lit = rasqal_new_literal_from_literal(var->value); |
| 1713 |
varBoundVec[bindingPos] = lit; |
| 1714 |
tripleResolveData->setObjectBoundLiteral(lit); |
| 1715 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1716 |
librdf_node* boundNode = rasqal_literal_to_redland_node(world, var->value); |
| 1717 |
tripleResolveData->setObjectBoundNode(boundNode); |
| 1718 |
#endif |
| 1719 |
} else { |
| 1720 |
requiresBindingReturning = true; |
| 1721 |
tripleResolveData->setObjectBoundNode(nullptr); |
| 1722 |
} |
| 1723 |
} else { |
| 1724 |
tripleResolveData->setObjectVariable(nullptr); |
| 1725 |
} |
| 1726 |
|
| 1727 |
return requiresBindingReturning; |
| 1728 |
} |
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
CRedlandRasqalSubQueryTripleResolvingData* create_triple_resolving_data(CRedlandRasqalSubQueryProcessingData* subQueryProcData, rasqal_triple* triple, cint64 triplePos) { |
| 1733 |
|
| 1734 |
QVector<CRedlandRasqalSubQueryTripleResolvingData*>* triplesResolvingDataVec = subQueryProcData->getTriplesResolvingDataVector(); |
| 1735 |
if (triplesResolvingDataVec->count() <= triplePos) { |
| 1736 |
|
| 1737 |
cint64 nextVariableBindingPos = subQueryProcData->getNextBindingsVariablePosition(); |
| 1738 |
QStringList* varList = subQueryProcData->getTriplesRemainingBindingVariableList(); |
| 1739 |
|
| 1740 |
cint64 tripleVariableCount = 0; |
| 1741 |
|
| 1742 |
cint64 subjectBindingPos = -1; |
| 1743 |
cint64 predicateBindingPos = -1; |
| 1744 |
cint64 objectBindingPos = -1; |
| 1745 |
|
| 1746 |
if (RASQAL_LITERAL_VARIABLE == rasqal_literal_get_type(triple->subject)) { |
| 1747 |
subjectBindingPos = nextVariableBindingPos; |
| 1748 |
if (!varList->isEmpty()) { |
| 1749 |
varList->removeFirst(); |
| 1750 |
if (!varList->isEmpty()) { |
| 1751 |
nextVariableBindingPos++; |
| 1752 |
++tripleVariableCount; |
| 1753 |
subQueryProcData->incNextBindingsVariablePosition(); |
| 1754 |
} |
| 1755 |
} |
| 1756 |
} |
| 1757 |
|
| 1758 |
|
| 1759 |
if (RASQAL_LITERAL_VARIABLE == rasqal_literal_get_type(triple->predicate)) { |
| 1760 |
predicateBindingPos = nextVariableBindingPos; |
| 1761 |
if (!varList->isEmpty()) { |
| 1762 |
varList->removeFirst(); |
| 1763 |
if (!varList->isEmpty()) { |
| 1764 |
nextVariableBindingPos++; |
| 1765 |
++tripleVariableCount; |
| 1766 |
subQueryProcData->incNextBindingsVariablePosition(); |
| 1767 |
} |
| 1768 |
} |
| 1769 |
} |
| 1770 |
if (RASQAL_LITERAL_VARIABLE == rasqal_literal_get_type(triple->object)) { |
| 1771 |
objectBindingPos = nextVariableBindingPos; |
| 1772 |
if (!varList->isEmpty()) { |
| 1773 |
varList->removeFirst(); |
| 1774 |
if (!varList->isEmpty()) { |
| 1775 |
nextVariableBindingPos++; |
| 1776 |
++tripleVariableCount; |
| 1777 |
subQueryProcData->incNextBindingsVariablePosition(); |
| 1778 |
} |
| 1779 |
} |
| 1780 |
} |
| 1781 |
|
| 1782 |
CRedlandRasqalSubQueryTripleResolvingData* newTripleResolvingData = new CRedlandRasqalSubQueryTripleResolvingData(subQueryProcData, triplePos, subjectBindingPos, predicateBindingPos, objectBindingPos); |
| 1783 |
|
| 1784 |
if (triplesResolvingDataVec->size() <= triplePos) { |
| 1785 |
triplesResolvingDataVec->resize(triplePos + 1); |
| 1786 |
} |
| 1787 |
(*triplesResolvingDataVec)[triplePos] = newTripleResolvingData; |
| 1788 |
} |
| 1789 |
|
| 1790 |
return (*triplesResolvingDataVec)[triplePos]; |
| 1791 |
} |
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
CRedlandRasqalSubQueryProcessingData* get_sub_query_processing_data(librdf_model* model, librdf_node* context_node) { |
| 1799 |
librdf_model_storage_context* storageContext = (librdf_model_storage_context*)((librdf_model_s*)model)->context; |
| 1800 |
CRedlandRasqalModelSubQueryResolver* resolver = (CRedlandRasqalModelSubQueryResolver*)((librdf_storage_s*)storageContext->storage)->instance; |
| 1801 |
librdf_world* world = resolver->getRedlandWorld(); |
| 1802 |
|
| 1803 |
if (!resolver->isTriplesContextLiteralsReset()) { |
| 1804 |
QVector<rasqal_literal*>* triplesContextLiteralVector = resolver->getTriplesContextLiteralVector(); |
| 1805 |
rasqal_query* rasqalQuery = resolver->getRasqalQuery(); |
| 1806 |
raptor_sequence* tripleSeq = rasqal_query_get_triple_sequence(rasqalQuery); |
| 1807 |
int tripleSeqSize = raptor_sequence_size(tripleSeq); |
| 1808 |
for (int i = 0; i < tripleSeqSize; ++i) { |
| 1809 |
rasqal_triple* triple = (rasqal_triple*)raptor_sequence_get_at(tripleSeq, i); |
| 1810 |
rasqal_literal* tripleContextLit = rasqal_triple_get_origin(triple); |
| 1811 |
if (tripleContextLit != (*triplesContextLiteralVector)[i]) { |
| 1812 |
rasqal_triple_set_origin(triple, (*triplesContextLiteralVector)[i]); |
| 1813 |
} |
| 1814 |
} |
| 1815 |
|
| 1816 |
|
| 1817 |
resolver->setTriplesContextLiteralsReset(true); |
| 1818 |
} |
| 1819 |
|
| 1820 |
QVector<CRedlandRasqalSubQueryProcessingData*>* subQueryProcDataVec = resolver->getSubQueryProcessingDataVector(); |
| 1821 |
|
| 1822 |
bool firstTriple = false; |
| 1823 |
cint64 subQueryId = -1; |
| 1824 |
|
| 1825 |
if (context_node) { |
| 1826 |
rasqal_literal* rasqContNode = (rasqal_literal*)context_node; |
| 1827 |
const unsigned char* chrString = rasqal_literal_as_string(rasqContNode); |
| 1828 |
int i = 0; |
| 1829 |
|
| 1830 |
if (chrString[0] == '-') { |
| 1831 |
++i; |
| 1832 |
firstTriple = true; |
| 1833 |
} |
| 1834 |
subQueryId = 0; |
| 1835 |
while (true) { |
| 1836 |
subQueryId += (chrString[i] - '0'); |
| 1837 |
if (chrString[i + 1] != 0) { |
| 1838 |
++i; |
| 1839 |
subQueryId *= 10; |
| 1840 |
} else { |
| 1841 |
break; |
| 1842 |
} |
| 1843 |
} |
| 1844 |
subQueryId = subQueryId - 1; |
| 1845 |
} |
| 1846 |
|
| 1847 |
//if (context_node && librdf_node_is_literal(context_node)) { |
| 1848 |
// unsigned char* chrString = librdf_node_get_literal_value(context_node); |
| 1849 |
// int i = 0; |
| 1850 |
|
| 1851 |
// if (chrString[0] == '-') { |
| 1852 |
// ++i; |
| 1853 |
// firstTriple = true; |
| 1854 |
// } |
| 1855 |
// subQueryId = 0; |
| 1856 |
// while (true) { |
| 1857 |
// subQueryId += (chrString[i] - '0'); |
| 1858 |
// if (chrString[i + 1] != 0) { |
| 1859 |
// ++i; |
| 1860 |
// subQueryId *= 10; |
| 1861 |
// } else { |
| 1862 |
// break; |
| 1863 |
// } |
| 1864 |
// } |
| 1865 |
// subQueryId = subQueryId - 1; |
| 1866 |
//} |
| 1867 |
|
| 1868 |
//if (context_node != NULL) { |
| 1869 |
// subQueryId = (cint64)subQueryId; |
| 1870 |
// if (subQueryId < 0) { |
| 1871 |
// firstTriple = true; |
| 1872 |
// subQueryId = -subQueryId; |
| 1873 |
// } |
| 1874 |
// subQueryId = subQueryId - 1; |
| 1875 |
//} |
| 1876 |
|
| 1877 |
|
| 1878 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = subQueryProcDataVec->at(subQueryId); |
| 1879 |
if (firstTriple) { |
| 1880 |
subQueryProcData->setNextReturningPosition(0); |
| 1881 |
} |
| 1882 |
return subQueryProcData; |
| 1883 |
} |
| 1884 |
|
| 1885 |
|
| 1886 |
void initialize_update_resolving(CRedlandRasqalSubQueryProcessingData* subQueryProcData) { |
| 1887 |
rasqal_graph_pattern* subqueryGraphPattern = subQueryProcData->getSubqueryGraphPattern(); |
| 1888 |
rasqal_graph_pattern_s *gps = (rasqal_graph_pattern_s*)subqueryGraphPattern; |
| 1889 |
int triplesStartColumn = subQueryProcData->getGPTripleStartPos(); |
| 1890 |
int triplesEndColumn = subQueryProcData->getGPTriplesEndPos(); |
| 1891 |
|
| 1892 |
librdf_world* world = subQueryProcData->getRedlandWorld(); |
| 1893 |
rasqal_world* rasqal_world_ptr = librdf_world_get_rasqal(world); |
| 1894 |
|
| 1895 |
if (!subQueryProcData->isInitialized()) { |
| 1896 |
if (subQueryProcData->isBooleanSubQuery()) { |
| 1897 |
QVector<rasqal_literal*> varBoundVec(1); |
| 1898 |
rasqal_triple* triple = (rasqal_triple*)raptor_sequence_get_at(gps->triples, 0); |
| 1899 |
create_triple_resolving_data(subQueryProcData, triple, 0); |
| 1900 |
|
| 1901 |
QByteArray bytes = QString("x").toUtf8(); |
| 1902 |
raptor_uri* uri = (raptor_uri*)librdf_new_uri(world, (const unsigned char*)bytes.constData()); |
| 1903 |
|
| 1904 |
#ifdef KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1905 |
librdf_node* defaultNode = librdf_new_node_from_uri(world, uri); |
| 1906 |
subQueryProcData->setDefaultReturningNode(defaultNode); |
| 1907 |
#else |
| 1908 |
librdf_node* defaultNode = (librdf_node*)rasqal_new_uri_literal(rasqal_world_ptr, uri); |
| 1909 |
subQueryProcData->setDefaultReturningNode(defaultNode); |
| 1910 |
#endif //KONCLUDE_REDLAND_RASQAL_SUBQUERY_LIBRDF_NODE_RESOLVING |
| 1911 |
|
| 1912 |
} else { |
| 1913 |
CQueryResult* queryResult = subQueryProcData->getSubQuery()->getQueryResult(); |
| 1914 |
CVariableBindingsAnswersResult* varIndBindsResult = dynamic_cast<CVariableBindingsAnswersResult*>(queryResult); |
| 1915 |
if (varIndBindsResult) { |
| 1916 |
const QStringList& varList = varIndBindsResult->getVariableNames(); |
| 1917 |
*subQueryProcData->getTriplesRemainingBindingVariableList() = varList; |
| 1918 |
subQueryProcData->getCurrentBindingsVector()->resize(varList.size()); |
| 1919 |
subQueryProcData->getNextBindingsVector()->resize(varList.size()); |
| 1920 |
subQueryProcData->setBindingsCount(varList.size()); |
| 1921 |
subQueryProcData->getBindingPositionVariableBoundRedlandNodeVector()->resize(varList.size()); |
| 1922 |
|
| 1923 |
QByteArray bytes = QString("x").toUtf8(); |
| 1924 |
librdf_uri *uri = librdf_new_uri(world, (const unsigned char*)bytes.constData()); |
| 1925 |
librdf_node* defaultNode = librdf_new_node_from_uri(world, uri); |
| 1926 |
subQueryProcData->setDefaultReturningNode(defaultNode); |
| 1927 |
|
| 1928 |
cint64 triplePos = 0; |
| 1929 |
for (int i = triplesStartColumn; i <= triplesEndColumn; ++i) { |
| 1930 |
rasqal_triple* triple = (rasqal_triple*)raptor_sequence_get_at(gps->triples, i); |
| 1931 |
create_triple_resolving_data(subQueryProcData, triple, triplePos++); |
| 1932 |
} |
| 1933 |
subQueryProcData->setTotalResultCountStatistics(varIndBindsResult->getResultCount()); |
| 1934 |
} |
| 1935 |
} |
| 1936 |
subQueryProcData->setInitialized(true); |
| 1937 |
} |
| 1938 |
|
| 1939 |
if (!subQueryProcData->isBooleanSubQuery()) { |
| 1940 |
// analyze which variables are already bound |
| 1941 |
cint64 triplePos = 0; |
| 1942 |
QVector<rasqal_literal*> varBoundVec(subQueryProcData->getBindingsCount()); |
| 1943 |
QVector<rasqal_literal*>* bindPosVarBoundNodeVec = subQueryProcData->getBindingPositionVariableBoundRedlandNodeVector(); |
| 1944 |
int triplePosFIrstBindingReturning = -1; |
| 1945 |
for (int i = triplesStartColumn; i <= triplesEndColumn; ++i) { |
| 1946 |
rasqal_triple* triple = (rasqal_triple*)raptor_sequence_get_at(gps->triples, i); |
| 1947 |
if (update_triple_bound_variables_resolving_data(subQueryProcData, triple, triplePos++, varBoundVec)) { |
| 1948 |
if (triplePosFIrstBindingReturning == -1) { |
| 1949 |
triplePosFIrstBindingReturning = i - triplesStartColumn; |
| 1950 |
} |
| 1951 |
} |
| 1952 |
} |
| 1953 |
subQueryProcData->setFirstTripleReturningBinding(triplePosFIrstBindingReturning); |
| 1954 |
bool hasBoundVariables = false; |
| 1955 |
for (int i = 0; i < subQueryProcData->getBindingsCount(); ++i) { |
| 1956 |
rasqal_literal*& prevNode = (*bindPosVarBoundNodeVec)[i]; |
| 1957 |
if (prevNode) { |
| 1958 |
rasqal_free_literal(prevNode); |
| 1959 |
} |
| 1960 |
prevNode = varBoundVec[i]; |
| 1961 |
if (prevNode) { |
| 1962 |
hasBoundVariables = true; |
| 1963 |
} |
| 1964 |
} |
| 1965 |
subQueryProcData->setBoundVariables(hasBoundVariables); |
| 1966 |
|
| 1967 |
|
| 1968 |
CVariableBindingsAnswersResult* baseAnswerResult = nullptr; |
| 1969 |
if (!hasBoundVariables) { |
| 1970 |
CQueryResult* queryResult = subQueryProcData->getSubQuery()->getQueryResult(); |
| 1971 |
baseAnswerResult = dynamic_cast<CVariableBindingsAnswersResult*>(queryResult); |
| 1972 |
} else { |
| 1973 |
subQueryProcData->incResultOrderingCountStatistics(); |
| 1974 |
CRedlandRasqalSubQueryBoundNodeResolvingHashData* bindingsPosResolveData = subQueryProcData->getBoundResolvingDataBase(); |
| 1975 |
for (cint64 i = 0; i < subQueryProcData->getBindingsCount() && bindingsPosResolveData->getResolvedVariableBindingsResult() && bindingsPosResolveData->getResolvedVariableBindingsResult()->getResultCount() > 0; ++i) { |
| 1976 |
rasqal_literal* boundLiteral = (*bindPosVarBoundNodeVec)[i]; |
| 1977 |
if (boundLiteral) { |
| 1978 |
CRedlandRasqalSubQueryBindingPositionResolvingHash* bindingsPosResolveHash = bindingsPosResolveData->getBindingPositionResolvingHash(); |
| 1979 |
CRedlandRasqalSubQueryBoundNodeResolvingHash* boundNodeResolvHash = bindingsPosResolveHash->getBindingPositionResolvingData(i)->getBoundNodeResolvingHash(); |
| 1980 |
if (!boundNodeResolvHash->isResolved()) { |
| 1981 |
//QString resHashString; |
| 1982 |
CVariableBindingsAnswersResult* varIndBindsResult = boundNodeResolvHash->getResolvingVariableBindingsResult(); |
| 1983 |
// resolve |
| 1984 |
CVariableBindingsAnswersResultIterator* answersIt = varIndBindsResult->getVariableBindingsAnswersIterator(); |
| 1985 |
while (answersIt->hasNext()) { |
| 1986 |
CVariableBindingsAnswerResult* varBindAnswer = answersIt->getNext(); |
| 1987 |
CVariableBindingsListAnswerResult* listVarBindAnswer = dynamic_cast<CVariableBindingsListAnswerResult*>(varBindAnswer); |
| 1988 |
if (listVarBindAnswer && i < listVarBindAnswer->getResultCount()) { |
| 1989 |
CVariableBindingResult* varBindRes = listVarBindAnswer->getResult(i); |
| 1990 |
rasqal_literal* literal = create_literal_from_binding(subQueryProcData, varBindRes); |
| 1991 |
//resHashString += QString("%1\r\n").arg(QString::fromUtf8((const char*)rasqal_literal_as_string(literal))); |
| 1992 |
boundNodeResolvHash->getBoundNodeResolvingData(literal)->getResolvedVariableBindingsResult()->addResultVariableBindings(varBindAnswer); |
| 1993 |
} |
| 1994 |
} |
| 1995 |
boundNodeResolvHash->setResolved(true); |
| 1996 |
//if (subQueryProcData->getSubQueryId() == 3) { |
| 1997 |
// cout << "\r\n resolving " << rasqal_literal_as_string(boundLiteral) << " \r\n"; |
| 1998 |
// bool debug = true; |
| 1999 |
//} |
| 2000 |
|
| 2001 |
} |
| 2002 |
bindingsPosResolveData = boundNodeResolvHash->getBoundNodeResolvingData(boundLiteral); |
| 2003 |
} |
| 2004 |
} |
| 2005 |
baseAnswerResult = bindingsPosResolveData->getResolvedVariableBindingsResult(); |
| 2006 |
subQueryProcData->setLastBoundResolvingData(bindingsPosResolveData); |
| 2007 |
} |
| 2008 |
subQueryProcData->setBaseAnswerResult(baseAnswerResult); |
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
CVariableBindingsAnswersResultIterator* answersIt = subQueryProcData->getAnswersIterator(); |
| 2013 |
CVariableBindingsResultIterator* varBindIt = subQueryProcData->getVariableBindingsIterator(); |
| 2014 |
|
| 2015 |
if (answersIt) { |
| 2016 |
delete answersIt; |
| 2017 |
answersIt = nullptr; |
| 2018 |
} |
| 2019 |
if (varBindIt) { |
| 2020 |
delete varBindIt; |
| 2021 |
varBindIt = nullptr; |
| 2022 |
} |
| 2023 |
|
| 2024 |
CVariableBindingsAnswersResult* varIndBindsResult = baseAnswerResult; |
| 2025 |
|
| 2026 |
if (varIndBindsResult) { |
| 2027 |
answersIt = varIndBindsResult->getVariableBindingsAnswersIterator(); |
| 2028 |
if (answersIt && answersIt->hasNext()) { |
| 2029 |
CVariableBindingsAnswerResult* varBindAnswer = answersIt->getNext(true); |
| 2030 |
varBindIt = varBindAnswer->getVariableBindingsIterator(varBindIt); |
| 2031 |
} else { |
| 2032 |
delete answersIt; |
| 2033 |
answersIt = nullptr; |
| 2034 |
} |
| 2035 |
} |
| 2036 |
subQueryProcData->setAnswersIterator(answersIt); |
| 2037 |
subQueryProcData->setVariableBindingsIterator(varBindIt); |
| 2038 |
subQueryProcData->setCurrentVariableBinding(nullptr); |
| 2039 |
|
| 2040 |
load_next_bindings(subQueryProcData); |
| 2041 |
} |
| 2042 |
} |
| 2043 |
|
| 2044 |
|
| 2045 |
librdf_stream* find_statements_context_resolving(librdf_model* model, librdf_statement* statement, librdf_node* context_node) { |
| 2046 |
librdf_model_storage_context* storageContext = (librdf_model_storage_context*)((librdf_model_s*)model)->context; |
| 2047 |
CRedlandRasqalModelSubQueryResolver* resolver = (CRedlandRasqalModelSubQueryResolver*)((librdf_storage_s*)storageContext->storage)->instance; |
| 2048 |
librdf_world* world = resolver->getRedlandWorld(); |
| 2049 |
|
| 2050 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = get_sub_query_processing_data(model, context_node); |
| 2051 |
|
| 2052 |
cint64 nextPos = subQueryProcData->getNextReturningPosition(); |
| 2053 |
subQueryProcData->setNextReturningPosition(nextPos + 1); |
| 2054 |
|
| 2055 |
|
| 2056 |
if (nextPos == 0) { |
| 2057 |
initialize_update_resolving(subQueryProcData); |
| 2058 |
} |
| 2059 |
if (subQueryProcData->isBooleanSubQuery()) { |
| 2060 |
CRedlandRasqalSubQueryTripleResolvingData* tripleResolvData = get_triple_resolving_data(subQueryProcData, statement, 0); |
| 2061 |
librdf_stream * stream = librdf_new_stream(world, tripleResolvData, is_end_method_stream_next_boolean_result, next_method_stream_next_boolean_result, get_method_stream_next_boolean_result, finished_method_stream_next_boolean_result); |
| 2062 |
return stream; |
| 2063 |
|
| 2064 |
} else if (nextPos == subQueryProcData->getFirstTripleReturningBinding()) { |
| 2065 |
librdf_stream * stream = librdf_new_stream(world, subQueryProcData, is_end_method_stream_next_answer_resolving, next_method_stream_next_answer_resolving, get_method_stream_next_answer_resolving, finished_method_stream_next_answer_resolving); |
| 2066 |
return stream; |
| 2067 |
} else { |
| 2068 |
CRedlandRasqalSubQueryTripleResolvingData* tripleResolvData = get_triple_resolving_data(subQueryProcData, statement, nextPos); |
| 2069 |
librdf_stream * stream = librdf_new_stream(world, tripleResolvData, is_end_method_stream_next_binding_resolving, next_method_stream_next_binding_resolving, get_method_stream_next_binding_resolving, finished_method_stream_next_binding_resolving); |
| 2070 |
return stream; |
| 2071 |
} |
| 2072 |
} |
| 2073 |
|
| 2074 |
librdf_stream* find_statements_resolving(librdf_model* model, librdf_statement* statement) { |
| 2075 |
return NULL; |
| 2076 |
} |
| 2077 |
|
| 2078 |
|
| 2079 |
int contains_statement_with_context_resolving(librdf_model* model, librdf_statement* statement, librdf_node* context_node) { |
| 2080 |
|
| 2081 |
librdf_model_storage_context* storageContext = (librdf_model_storage_context*)((librdf_model_s*)model)->context; |
| 2082 |
CRedlandRasqalModelSubQueryResolver* resolver = (CRedlandRasqalModelSubQueryResolver*)((librdf_storage_s*)storageContext->storage)->instance; |
| 2083 |
librdf_world* world = resolver->getRedlandWorld(); |
| 2084 |
|
| 2085 |
CRedlandRasqalSubQueryProcessingData* subQueryProcData = get_sub_query_processing_data(model, context_node); |
| 2086 |
|
| 2087 |
cint64 nextPos = subQueryProcData->getNextReturningPosition(); |
| 2088 |
subQueryProcData->setNextReturningPosition(nextPos + 1); |
| 2089 |
if (nextPos == 0) { |
| 2090 |
initialize_update_resolving(subQueryProcData); |
| 2091 |
} |
| 2092 |
|
| 2093 |
if (subQueryProcData->isBooleanSubQuery()) { |
| 2094 |
if (subQueryProcData->getBooleanQueryResult()) { |
| 2095 |
return 1; |
| 2096 |
} else { |
| 2097 |
return 0; |
| 2098 |
} |
| 2099 |
} |
| 2100 |
|
| 2101 |
if (!subQueryProcData->getBaseAnswerResult() || subQueryProcData->getBaseAnswerResult()->getResultCount() <= 0) { |
| 2102 |
return 0; |
| 2103 |
} |
| 2104 |
|
| 2105 |
return 1; |
| 2106 |
} |
| 2107 |
|
| 2108 |
int contains_statement_resolving(librdf_model* model, librdf_statement* statement) { |
| 2109 |
return -1; |
| 2110 |
} |
| 2111 |
|
| 2112 |
|
| 2113 |
void destroy_resolving(librdf_model* model) { |
| 2114 |
} |
| 2115 |
|
| 2116 |
|
| 2117 |
librdf_world* CRedlandRasqalModelSubQueryResolver::getRedlandWorld() { |
| 2118 |
return mWorld; |
| 2119 |
} |
| 2120 |
|
| 2121 |
|
| 2122 |
void CRedlandRasqalModelSubQueryResolver::releaseRedlandResolvingModel() { |
| 2123 |
if (mResolvingModel) { |
| 2124 |
for (CRedlandRasqalSubQueryProcessingData* subQueryProcData : *mSubQueryProcDataVec) { |
| 2125 |
subQueryProcData->deleteBoundResolvingData(); |
| 2126 |
} |
| 2127 |
librdf_model_s* tmpModel = (librdf_model_s*)mResolvingModel; |
| 2128 |
delete tmpModel->factory; |
| 2129 |
delete ((librdf_storage_s*)((librdf_model_storage_context*)tmpModel->context)->storage)->factory; |
| 2130 |
delete ((librdf_model_storage_context*)tmpModel->context)->storage; |
| 2131 |
delete tmpModel->context; |
| 2132 |
delete mResolvingModel; |
| 2133 |
mResolvingModel = nullptr; |
| 2134 |
} |
| 2135 |
} |
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
void rasqal_log_handler_error_notifier_resolving(void *user_data, raptor_log_message *message) { |
| 2140 |
QString** rasqalParsingErrorString = (QString**)user_data; |
| 2141 |
if (message->level <= 50 && *rasqalParsingErrorString == nullptr) { |
| 2142 |
*rasqalParsingErrorString = new QString(QString("%1").arg(message->text)); |
| 2143 |
} |
| 2144 |
} |
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
int get_contexts_resolving_iterator_is_end(void* data) { |
| 2149 |
CRedlandRasqalModelSubQueryResolver* resolver = (CRedlandRasqalModelSubQueryResolver*)data; |
| 2150 |
QHash<QString, TDependentOntologyPair>::const_iterator it = resolver->getQueryKnowledgeBaseNameDependentOntologyPairHashIterator(); |
| 2151 |
QHash<QString, TDependentOntologyPair>::const_iterator itEnd = resolver->getQueryKnowledgeBaseNameDependentOntologyPairHash()->constEnd(); |
| 2152 |
if (it != itEnd) { |
| 2153 |
return 0; |
| 2154 |
} |
| 2155 |
return 1; |
| 2156 |
} |
| 2157 |
|
| 2158 |
int get_contexts_resolving_iterator_next(void* data) { |
| 2159 |
CRedlandRasqalModelSubQueryResolver* resolver = (CRedlandRasqalModelSubQueryResolver*)data; |
| 2160 |
QHash<QString, TDependentOntologyPair>::const_iterator it = resolver->getQueryKnowledgeBaseNameDependentOntologyPairHashIterator(); |
| 2161 |
QHash<QString, TDependentOntologyPair>::const_iterator itEnd = resolver->getQueryKnowledgeBaseNameDependentOntologyPairHash()->constEnd(); |
| 2162 |
if (it != itEnd) { |
| 2163 |
resolver->setQueryKnowledgeBaseNameDependentOntologyPairHashIterator(++it); |
| 2164 |
return 0; |
| 2165 |
} |
| 2166 |
return 1; |
| 2167 |
} |
| 2168 |
|
| 2169 |
void* get_contexts_resolving_iterator_get(void* data, int flags) { |
| 2170 |
CRedlandRasqalModelSubQueryResolver* resolver = (CRedlandRasqalModelSubQueryResolver*)data; |
| 2171 |
librdf_world* world = resolver->getRedlandWorld(); |
| 2172 |
QHash<QString, TDependentOntologyPair>::const_iterator it = resolver->getQueryKnowledgeBaseNameDependentOntologyPairHashIterator(); |
| 2173 |
QHash<QString, TDependentOntologyPair>::const_iterator itEnd = resolver->getQueryKnowledgeBaseNameDependentOntologyPairHash()->constEnd(); |
| 2174 |
if (it != itEnd) { |
| 2175 |
QString kbName = it.key(); |
| 2176 |
QByteArray kbNameData = kbName.toUtf8(); |
| 2177 |
librdf_node* node = librdf_new_node_from_uri_string(world, (const unsigned char*)kbNameData.constData()); |
| 2178 |
return node; |
| 2179 |
} |
| 2180 |
return NULL; |
| 2181 |
} |
| 2182 |
|
| 2183 |
void get_contexts_resolving_iterator_finished(void* data) { |
| 2184 |
} |
| 2185 |
|
| 2186 |
librdf_iterator* get_contexts_resolving(librdf_model* model) { |
| 2187 |
librdf_model_storage_context* storageContext = (librdf_model_storage_context*)((librdf_model_s*)model)->context; |
| 2188 |
CRedlandRasqalModelSubQueryResolver* resolver = (CRedlandRasqalModelSubQueryResolver*)((librdf_storage_s*)storageContext->storage)->instance; |
| 2189 |
librdf_world* world = resolver->getRedlandWorld(); |
| 2190 |
resolver->setQueryKnowledgeBaseNameDependentOntologyPairHashIterator(resolver->getQueryKnowledgeBaseNameDependentOntologyPairHash()->constBegin()); |
| 2191 |
|
| 2192 |
librdf_iterator * iterator = librdf_new_iterator(world, resolver, &get_contexts_resolving_iterator_is_end, &get_contexts_resolving_iterator_next, &get_contexts_resolving_iterator_get, &get_contexts_resolving_iterator_finished); |
| 2193 |
|
| 2194 |
return iterator; |
| 2195 |
} |
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
librdf_model* CRedlandRasqalModelSubQueryResolver::getRedlandResolvingModel() { |
| 2200 |
if (!mResolvingModel) { |
| 2201 |
|
| 2202 |
librdf_storage* indexedStorage = librdf_new_storage(mWorld, "hashes", NULL, "hash-type='memory',index-predicates='yes'"); |
| 2203 |
librdf_model* indexedModel = librdf_new_model(mWorld, indexedStorage, NULL); |
| 2204 |
|
| 2205 |
|
| 2206 |
rasqal_world* rasqal_world_ptr = librdf_world_get_rasqal(mWorld); |
| 2207 |
rasqal_world_set_log_handler(rasqal_world_ptr, &mRasqalErrorString, &rasqal_log_handler_error_notifier_resolving); |
| 2208 |
|
| 2209 |
rasqal_set_triples_source_factory(rasqal_world_ptr, rasqal_redland_register_triples_source_factory, mWorld); |
| 2210 |
|
| 2211 |
|
| 2212 |
librdf_model_s* tmpModel = new librdf_model_s(); |
| 2213 |
tmpModel->factory = new librdf_model_factory_s(); |
| 2214 |
tmpModel->supports_contexts = 1; |
| 2215 |
//tmpModel->factory->supports_query = &supports_query_resolving; |
| 2216 |
tmpModel->factory->find_statements = &find_statements_resolving; |
| 2217 |
tmpModel->factory->find_statements_in_context = &find_statements_context_resolving; |
| 2218 |
tmpModel->factory->query_execute = ((librdf_model_s*)indexedModel)->factory->query_execute; |
| 2219 |
tmpModel->factory->contains_statement_with_context = &contains_statement_with_context_resolving; |
| 2220 |
tmpModel->factory->contains_statement = &contains_statement_resolving; |
| 2221 |
tmpModel->factory->destroy = &destroy_resolving; |
| 2222 |
tmpModel->factory->get_contexts = &get_contexts_resolving; |
| 2223 |
tmpModel->usage = 1; |
| 2224 |
|
| 2225 |
|
| 2226 |
librdf_model_storage_context* modelStorageContext = new librdf_model_storage_context(); |
| 2227 |
librdf_storage_s* storage = new librdf_storage_s(); |
| 2228 |
librdf_storage_factory_s* storageFactory = new librdf_storage_factory_s(); |
| 2229 |
storageFactory->supports_query = nullptr; |
| 2230 |
storage->factory = storageFactory; |
| 2231 |
modelStorageContext->storage = (librdf_storage*)storage; |
| 2232 |
storage->instance = this; |
| 2233 |
|
| 2234 |
tmpModel->context = modelStorageContext; |
| 2235 |
|
| 2236 |
mResolvingModel = (librdf_model*)tmpModel; |
| 2237 |
|
| 2238 |
librdf_free_model(indexedModel); |
| 2239 |
librdf_free_storage(indexedStorage); |
| 2240 |
} |
| 2241 |
return mResolvingModel; |
| 2242 |
} |
| 2243 |
|
| 2244 |
|
| 2245 |
QVector<CRedlandRasqalSubQueryProcessingData*>* CRedlandRasqalModelSubQueryResolver::getSubQueryProcessingDataVector() { |
| 2246 |
return mSubQueryProcDataVec; |
| 2247 |
} |
| 2248 |
|
| 2249 |
|
| 2250 |
QString CRedlandRasqalModelSubQueryResolver::getIterationStatusString() { |
| 2251 |
QString statString = QString("Redland Rasqal query processing"); |
| 2252 |
for (CRedlandRasqalSubQueryProcessingData* subQueryProcData : *mSubQueryProcDataVec) { |
| 2253 |
QString subQueryStatString = QString(", visited %2 of %3 results of SubQuery-%1 (with %4 reorderings/lookups)").arg(subQueryProcData->getSubQueryId()).arg(subQueryProcData->getVisitedResultCountStatistics()).arg(subQueryProcData->getTotalResultCountStatistics()).arg(subQueryProcData->getResultOrderingCountStatistics()); |
| 2254 |
statString += subQueryStatString; |
| 2255 |
} |
| 2256 |
return statString; |
| 2257 |
} |
| 2258 |
|
| 2259 |
|
| 2260 |
QHash<QString, TDependentOntologyPair>* CRedlandRasqalModelSubQueryResolver::getQueryKnowledgeBaseNameDependentOntologyPairHash() { |
| 2261 |
return mQueryKbNameDepOntPairHash; |
| 2262 |
} |
| 2263 |
|
| 2264 |
QHash<QString, TDependentOntologyPair>::const_iterator CRedlandRasqalModelSubQueryResolver::getQueryKnowledgeBaseNameDependentOntologyPairHashIterator() { |
| 2265 |
return mQueryKbNameDepOntPairHashIt; |
| 2266 |
} |
| 2267 |
|
| 2268 |
CRedlandRasqalModelSubQueryResolver* CRedlandRasqalModelSubQueryResolver::setQueryKnowledgeBaseNameDependentOntologyPairHashIterator(QHash<QString, TDependentOntologyPair>::const_iterator it) { |
| 2269 |
mQueryKbNameDepOntPairHashIt = it; |
| 2270 |
return this; |
| 2271 |
} |
| 2272 |
|
| 2273 |
QVector<rasqal_literal*>* CRedlandRasqalModelSubQueryResolver::getTriplesContextLiteralVector() { |
| 2274 |
return &mTriplesContextLiteralVector; |
| 2275 |
} |
| 2276 |
|
| 2277 |
bool CRedlandRasqalModelSubQueryResolver::isTriplesContextLiteralsReset() { |
| 2278 |
return mTriplesContextLiteralsReset; |
| 2279 |
} |
| 2280 |
|
| 2281 |
CRedlandRasqalModelSubQueryResolver* CRedlandRasqalModelSubQueryResolver::setTriplesContextLiteralsReset(bool reset) { |
| 2282 |
mTriplesContextLiteralsReset = reset; |
| 2283 |
return this; |
| 2284 |
} |
| 2285 |
|
| 2286 |
rasqal_query* CRedlandRasqalModelSubQueryResolver::getRasqalQuery() { |
| 2287 |
return mRasqalQuery; |
| 2288 |
} |
| 2289 |
|
| 2290 |
|
| 2291 |
}; // end namespace Answerer |
| 2292 |
|
| 2293 |
}; // end namespace Reasoner |
| 2294 |
|
| 2295 |
}; // end namespace Konclude |
| 2296 |
|
| 2297 |
|
| 2298 |
#endif // KONCLUDE_REDLAND_INTEGRATION |