/* * call-seq: * graph.contexts -> array * * Returns an Array of URIs describing the contexts in the receiving graph. * */ static VALUE rleaf_redleaf_graph_contexts( VALUE self ) { rleaf_GRAPH *ptr = rleaf_get_graph( self ); librdf_iterator *iter; librdf_node *context_node; VALUE context = Qnil; VALUE rval = rb_ary_new(); int count = 0; if ( (iter = librdf_model_get_contexts(ptr->model)) == NULL ) { rleaf_log_with_context( self, "info", "couldn't fetch a context iterator; " "contexts not supported?" ); return rval; } rleaf_log_with_context( self, "debug", "iterating over contexts for graph 0x%x", self ); while ( ! librdf_iterator_end(iter) ) { context_node = librdf_iterator_get_context( iter ); context = rleaf_librdf_uri_node_to_object( context_node ); rleaf_log_with_context( self, "debug", " context %d: %s", count, RSTRING_PTR(rb_inspect(context)) ); rb_ary_push( rval, context ); librdf_iterator_next( iter ); } librdf_free_iterator( iter ); return rval; }
static int rasqal_redland_new_triples_source(rasqal_query* rdf_query, void *factory_user_data, void *user_data, rasqal_triples_source *rts) { librdf_world *world=(librdf_world*)factory_user_data; rasqal_redland_triples_source_user_data* rtsc=(rasqal_redland_triples_source_user_data*)user_data; raptor_sequence *seq; librdf_query_rasqal_context *context; librdf_iterator* cit; rtsc->world = world; rtsc->query = (librdf_query*)rasqal_query_get_user_data(rdf_query); context = (librdf_query_rasqal_context*)rtsc->query->context; rtsc->model = context->model; seq = rasqal_query_get_data_graph_sequence(rdf_query); /* FIXME: queries with data graphs in them (such as FROM in SPARQL) * are deleted, so that there are no unexpected data loads */ if(seq) { while(raptor_sequence_size(seq)) { rasqal_data_graph* dg=(rasqal_data_graph*)raptor_sequence_pop(seq); rasqal_free_data_graph(dg); } } if(librdf_model_supports_contexts(rtsc->model)) { /* Add all contexts (named graphs) to the query so Rasqal can bind them */ cit = librdf_model_get_contexts(rtsc->model); while(!librdf_iterator_end(cit)) { librdf_node* node = (librdf_node*)librdf_iterator_get_object(cit); librdf_uri* uri; raptor_uri* source_uri; rasqal_data_graph* dg; uri = librdf_node_get_uri(node); source_uri = (raptor_uri*)raptor_new_uri(world->raptor_world_ptr, librdf_uri_as_string(uri)); dg = rasqal_new_data_graph_from_uri(world->rasqal_world_ptr, source_uri, source_uri, RASQAL_DATA_GRAPH_NAMED, NULL, NULL, NULL); rasqal_query_add_data_graph(rdf_query, dg); raptor_free_uri(source_uri); librdf_iterator_next(cit); } librdf_free_iterator(cit); } #ifdef RASQAL_TRIPLES_SOURCE_MIN_VERSION rts->version = 1; #endif rts->init_triples_match=rasqal_redland_init_triples_match; rts->triple_present=rasqal_redland_triple_present; rts->free_triples_source=rasqal_redland_free_triples_source; return 0; }