Beispiel #1
0
  librdf_node* RdfStorePrivate::RdfNodeToLibRdfNode(RdfNode node) const
  {
    librdf_node* newNode = nullptr;

    switch (node.GetType())
    {
    case RdfNode::NOTHING:
      break;
    case RdfNode::BLANK:
      newNode = librdf_new_node_from_blank_identifier(m_World, (const unsigned char*) node.GetValue().c_str());
      break;
    case RdfNode::LITERAL:
      {
        if (node.GetDatatype() != RdfUri())
        {
          librdf_uri* typeUri = RdfUriToLibRdfUri(node.GetDatatype());
          newNode = librdf_new_node_from_typed_literal(m_World, (const unsigned char*) node.GetValue().c_str(), nullptr, typeUri);
        }
        else
        {
          newNode = librdf_new_node_from_literal(m_World, (const unsigned char*) node.GetValue().c_str(), nullptr, 0);
        }
      }
      break;
    case RdfNode::URI:
      newNode = librdf_new_node_from_uri( m_World, librdf_new_uri(m_World, (const unsigned char*) node.GetValue().c_str()) );
      break;
    default:
      break;
    }
    return newNode;
  }
Beispiel #2
0
/**
 * librdf_storage_trees_get_feature:
 * @storage: #librdf_storage object
 * @feature: #librdf_uri feature property
 *
 * Get the value of a storage feature.
 * 
 * Return value: #librdf_node feature value or NULL if no such feature
 * exists or the value is empty.
 **/
static librdf_node*
librdf_storage_trees_get_feature(librdf_storage* storage, librdf_uri* feature)
{
#ifdef RDF_STORAGE_TREES_WITH_CONTEXTS
  librdf_storage_trees_instance* scontext=(librdf_storage_trees_instance*)storage->instance;
  unsigned char *uri_string;

  if(!feature)
    return NULL;

  uri_string=librdf_uri_as_string(feature);
  if(!uri_string)
    return NULL;
  
  if(!strcmp((const char*)uri_string, LIBRDF_MODEL_FEATURE_CONTEXTS)) {
    unsigned char value[2];

    sprintf((char*)value, "%d", (scontext->contexts != NULL));
    return librdf_new_node_from_typed_literal(storage->world, 
                                              value, NULL, NULL);
  }
#endif

  return NULL;
}
Beispiel #3
0
static librdf_node*
rasqal_literal_to_redland_node(librdf_world *world, rasqal_literal* l)
{
  rasqal_literal_type type;

  if(!l)
    return NULL;
  
  /* FIXME: Workaround for Issue #0000519
   * http://bugs.librdf.org/mantis/view.php?id=519
   *
   * Remove this 'if' when RASQAL_MIN_VERSION is 0.9.30 or larger
   */
  if(l->type == RASQAL_LITERAL_INTEGER_SUBTYPE)
    type = RASQAL_LITERAL_STRING;
  else
    type = rasqal_literal_get_rdf_term_type(l);

  if(type == RASQAL_LITERAL_URI)
    return librdf_new_node_from_uri(world, (librdf_uri*)l->value.uri);
  else if (type == RASQAL_LITERAL_STRING)
    return librdf_new_node_from_typed_literal(world, 
                                              (unsigned char*)l->string, 
                                              l->language, 
                                              (librdf_uri*)l->datatype);
  else if (type == RASQAL_LITERAL_BLANK)
    return librdf_new_node_from_blank_identifier(world,
                                                 (unsigned char*)l->string);

  LIBRDF_DEBUG2("Could not convert literal type %d to librdf_node\n", type);
  return NULL;
}
Beispiel #4
0
static librdf_statement*
librdf_storage_tstore_statement_from_rs_triple(librdf_world* world,
                                               rs_triple *triple)
{
  librdf_node *subject_node;
  librdf_node *predicate_node;
  librdf_node *object_node;

  if(triple->subject) {
    if(!strncmp(triple->subject, "_:",2))
      subject_node=librdf_new_node_from_blank_identifier(world, 
                                                         (const unsigned char *)triple->subject+2);
    else
      subject_node=librdf_new_node_from_uri_string(world, 
                                                   (const unsigned char *)triple->subject);

    if(!subject_node)
      return NULL;

  } else
    subject_node=NULL;
  
  if(triple->predicate) {
    predicate_node=librdf_new_node_from_uri_string(world,
                                                   (const unsigned char *)triple->predicate);

    if(!predicate_node) {
      librdf_free_node(subject_node);
      return NULL;
    }
  } else
    predicate_node=NULL;
  
  if(triple->object) {
    if(triple->literal)
      object_node=librdf_new_node_from_typed_literal(world, 
                                                     (const unsigned char *)triple->object,
                                                     NULL, NULL);
    else if(!strncmp(triple->object, ":", 2))
      object_node=librdf_new_node_from_blank_identifier(world, 
                                                        (const unsigned char *)triple->object+2);
    else
      object_node=librdf_new_node_from_uri_string(world, 
                                                  (const unsigned char *)triple->object);

    if(!object_node) {
      librdf_free_node(subject_node);
      librdf_free_node(predicate_node);
      return NULL;
    }
  } else
    object_node=NULL;  
  
  return librdf_new_statement_from_nodes(world, subject_node, predicate_node, object_node);
}
Beispiel #5
0
static librdf_node *new_node_from_integer(librdf_world * world, int i)
{
  librdf_uri *xsd_integer_uri = NULL;
  librdf_node *node = NULL;
  unsigned char *string = NULL;

#define INTEGER_BUFFER_SIZE 20
  string = (unsigned char *) malloc(INTEGER_BUFFER_SIZE + 1);
  if (!string)
    return NULL;

  // snprintf() takes as length the buffer size including NULL
  snprintf((char *) string, INTEGER_BUFFER_SIZE + 1, "%d", i);

  xsd_integer_uri =
      librdf_new_uri(world, (unsigned char *) "http://www.w3.org/2001/XMLSchema#integer");

  node = librdf_new_node_from_typed_literal(world, string, NULL, xsd_integer_uri);

  if (xsd_integer_uri)
    librdf_free_uri(xsd_integer_uri);

  return node;
}
/**
 * librdf_storage_cassandra_get_feature:
 * @storage: #librdf_storage object
 * @feature: #librdf_uri feature property
 *
 * Get the value of a storage feature.
 * 
 * Return value: #librdf_node feature value or NULL if no such feature
 * exists or the value is empty.
 **/
static librdf_node*
librdf_storage_cassandra_get_feature(librdf_storage* storage, librdf_uri* feature)
{
    /* librdf_storage_cassandra_instance* scontext; */
    unsigned char *uri_string;

    /* scontext = (librdf_storage_cassandra_instance*)storage->instance; */

    if(!feature)
	return NULL;

    uri_string = librdf_uri_as_string(feature);
    if(!uri_string)
	return NULL;

    // FIXME: This is a lie.  Contexts not implemented. :-/
    if(!strcmp((const char*)uri_string, LIBRDF_MODEL_FEATURE_CONTEXTS)) {
	return librdf_new_node_from_typed_literal(storage->world,
						  (const unsigned char*)"1",
						  NULL, NULL);
    }

    return NULL;
}
Beispiel #7
0
/*
 * librdf_parser_raptor_new_statement_handler - helper callback function for raptor RDF when a new triple is asserted
 * @context: context for callback
 * @statement: raptor_statement
 *
 * Adds the statement to the list of statements.
 */
static void
librdf_parser_raptor_new_statement_handler(void *context,
                                           raptor_statement *rstatement)
{
  librdf_parser_raptor_stream_context* scontext=(librdf_parser_raptor_stream_context*)context;
  librdf_node* node;
  librdf_statement* statement;
  librdf_world* world=scontext->pcontext->parser->world;
  int rc;

  statement=librdf_new_statement(world);
  if(!statement)
    return;

  if(rstatement->subject->type == RAPTOR_TERM_TYPE_BLANK) {
    node = librdf_new_node_from_blank_identifier(world, (const unsigned char*)rstatement->subject->value.blank.string);
  } else if (rstatement->subject->type == RAPTOR_TERM_TYPE_URI) {
    node = librdf_new_node_from_uri(world, (librdf_uri*)rstatement->subject->value.uri);
  } else {
    librdf_log(world,
               0, LIBRDF_LOG_ERROR, LIBRDF_FROM_PARSER, NULL,
               "Unknown Raptor subject identifier type %d",
               rstatement->subject->type);
    librdf_free_statement(statement);
    return;
  }

  if(!node) {
    librdf_log(world,
               0, LIBRDF_LOG_FATAL, LIBRDF_FROM_PARSER, NULL,
               "Cannot create subject node");
    librdf_free_statement(statement);
    return;
  }

  librdf_statement_set_subject(statement, node);


  if(rstatement->predicate->type == RAPTOR_TERM_TYPE_URI) {
    node = librdf_new_node_from_uri(world, (librdf_uri*)rstatement->predicate->value.uri);
  } else {
    librdf_log(world,
               0, LIBRDF_LOG_ERROR, LIBRDF_FROM_PARSER, NULL,
               "Unknown Raptor predicate identifier type %d",
               rstatement->predicate->type);
    librdf_free_statement(statement);
    return;
  }

  if(!node) {
    librdf_log(world,
               0, LIBRDF_LOG_FATAL, LIBRDF_FROM_PARSER, NULL,
               "Cannot create predicate node");
    librdf_free_statement(statement);
    return;
  }

  librdf_statement_set_predicate(statement, node);

  if(rstatement->object->type == RAPTOR_TERM_TYPE_LITERAL) {
    node = librdf_new_node_from_typed_literal(world,
                                              rstatement->object->value.literal.string,
                                              (const char *)rstatement->object->value.literal.language,
                                              (librdf_uri*)rstatement->object->value.literal.datatype);
  } else if(rstatement->object->type == RAPTOR_TERM_TYPE_BLANK) {
    node = librdf_new_node_from_blank_identifier(world, rstatement->object->value.blank.string);
  } else if(rstatement->object->type == RAPTOR_TERM_TYPE_URI) {
    node = librdf_new_node_from_uri(world, (librdf_uri*)rstatement->object->value.uri);
  } else {
    librdf_log(world,
               0, LIBRDF_LOG_ERROR, LIBRDF_FROM_PARSER, NULL,
               "Unknown Raptor object identifier type %d",
               rstatement->object->type);
    librdf_free_statement(statement);
    return;
  }

  if(!node) {
    librdf_log(world,
               0, LIBRDF_LOG_FATAL, LIBRDF_FROM_PARSER, NULL,
               "Cannot create object node");
    librdf_free_statement(statement);
    return;
  }

  librdf_statement_set_object(statement, node);

#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1
  if(1) {
    raptor_iostream *iostr;
    iostr = raptor_new_iostream_to_file_handle(world->raptor_world_ptr, stderr);
    librdf_statement_write(statement, iostr);
    raptor_free_iostream(iostr);
  }
#endif

  if(scontext->model) {
    rc=librdf_model_add_statement(scontext->model, statement);
    librdf_free_statement(statement);
  } else {
    rc=librdf_list_add(scontext->statements, statement);
    if(rc)
      librdf_free_statement(statement);
  }
  if(rc) {
    librdf_log(world,
               0, LIBRDF_LOG_FATAL, LIBRDF_FROM_PARSER, NULL,
               "Cannot add statement to model");
  }
}
Beispiel #8
0
static int
librdf_query_rasqal_query_results_update_statement(void* context)
{
  librdf_query_rasqal_stream_context* scontext=(librdf_query_rasqal_stream_context*)context;
  librdf_world* world=scontext->query->world;
  librdf_node* node;
  
  raptor_statement *rstatement=rasqal_query_results_get_triple(scontext->qcontext->results);
  if(!rstatement)
    return 1;
  
  scontext->statement=librdf_new_statement(world);
  if(!scontext->statement)
    return 1;

  /* subject */
  
  if(rstatement->subject->type == RAPTOR_TERM_TYPE_BLANK) {
    node = librdf_new_node_from_blank_identifier(world, rstatement->subject->value.blank.string);
  } else if(rstatement->subject->type == RAPTOR_TERM_TYPE_URI) {
    node = librdf_new_node_from_uri_string(world,
                                           librdf_uri_as_string((librdf_uri*)rstatement->subject->value.uri));
  } else {
    librdf_log(world,
               0, LIBRDF_LOG_ERROR, LIBRDF_FROM_QUERY, NULL,
               "Unknown Raptor subject identifier type %d",
               rstatement->subject->type);
    goto fail;
  }

  if(!node) {
    librdf_log(world,
               0, LIBRDF_LOG_ERROR, LIBRDF_FROM_QUERY, NULL,
               "Could not create subject node");
    goto fail;
  }
  
  librdf_statement_set_subject(scontext->statement, node);

  /* predicate */

  if(rstatement->predicate->type == RAPTOR_TERM_TYPE_URI) {
    node = librdf_new_node_from_uri_string(world,
                                           librdf_uri_as_string((librdf_uri*)rstatement->predicate->value.uri));
  } else {
    librdf_log(world,
               0, LIBRDF_LOG_ERROR, LIBRDF_FROM_QUERY, NULL,
               "Unknown Raptor predicate identifier type %d",
               rstatement->predicate->type);
    goto fail;
  }

  if(!node) {
    librdf_log(world,
               0, LIBRDF_LOG_ERROR, LIBRDF_FROM_QUERY, NULL,
               "Could not create predicate node");
    goto fail;
  }
  
  librdf_statement_set_predicate(scontext->statement, node);
  
  /* object */

  if(rstatement->object->type == RAPTOR_TERM_TYPE_LITERAL) {
    node = librdf_new_node_from_typed_literal(world,
                                              rstatement->object->value.literal.string,
                                              (const char*)rstatement->object->value.literal.language,
                                              (librdf_uri*)rstatement->object->value.literal.datatype);
  } else if(rstatement->object->type == RAPTOR_TERM_TYPE_BLANK) {
    node = librdf_new_node_from_blank_identifier(world, rstatement->object->value.blank.string);
  } else if(rstatement->object->type == RAPTOR_TERM_TYPE_URI) {
    node = librdf_new_node_from_uri_string(world,
                                           librdf_uri_as_string((librdf_uri*)rstatement->object->value.uri));
  } else {
    librdf_log(world,
               0, LIBRDF_LOG_ERROR, LIBRDF_FROM_PARSER, NULL,
               "Unknown Raptor object identifier type %d",
               rstatement->object->type);
    goto fail;
  }

  if(!node) {
    librdf_log(world,
               0, LIBRDF_LOG_ERROR, LIBRDF_FROM_QUERY, NULL,
               "Could not create object node");
    goto fail;
  }

  librdf_statement_set_object(scontext->statement, node);

  return 0; /* success */

  fail:
  librdf_free_statement(scontext->statement);
  scontext->statement=NULL;
  return 1;
}