예제 #1
0
static rasqal_data_graph*
rasqal_new_data_graph_common(rasqal_world* world,
                             raptor_uri* uri,
                             raptor_iostream* iostr, raptor_uri* base_uri,
                             raptor_uri* name_uri, int flags,
                             const char* format_type,
                             const char* format_name,
                             raptor_uri* format_uri)
{
  rasqal_data_graph* dg;

  dg = (rasqal_data_graph*)RASQAL_CALLOC(rasqal_data_graph, 1, sizeof(*dg));
  if(dg) {
    dg->world = world;

    dg->usage = 1;

    if(iostr)
      dg->iostr = iostr;
    else if(uri)
      dg->uri = raptor_uri_copy(uri);

    if(name_uri)
      dg->name_uri = raptor_uri_copy(name_uri);

    dg->flags = flags;

    if(format_type) {
      size_t len = strlen(format_type);
      dg->format_type = RASQAL_MALLOC(string, len + 1);
      if(!dg->format_type)
        goto error;

      memcpy(dg->format_type, format_type, len + 1);
    }

    if(format_name) {
      size_t len = strlen(format_name);
      dg->format_name = RASQAL_MALLOC(string, len + 1);
      if(!dg->format_name)
        goto error;

      memcpy(dg->format_name, format_name, len + 1);
    }

    if(format_uri)
      dg->format_uri = raptor_uri_copy(format_uri);

    if(base_uri)
      dg->base_uri = raptor_uri_copy(base_uri);
  }

  return dg;

  error:
  rasqal_free_data_graph(dg);
  return NULL;
}
예제 #2
0
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;
}