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; }
static librdf_node* sd_get_endpoint_node(const char * request_url_str) { librdf_uri *request_uri = NULL, *endpoint_uri = NULL; librdf_node *endpoint_node = NULL; request_uri = librdf_new_uri(world, (unsigned char*)request_url_str); if (!request_uri) { redstore_error("Failed to create request_uri"); goto CLEANUP; } endpoint_uri = librdf_new_uri_relative_to_base(request_uri, (unsigned char*)"sparql"); if (!endpoint_uri) { redstore_error("Failed to create endpoint_uri"); goto CLEANUP; } endpoint_node = librdf_new_node_from_uri(world, endpoint_uri); if (!endpoint_uri) { redstore_error("Failed to create endpoint_node"); goto CLEANUP; } CLEANUP: if (request_uri) librdf_free_uri(request_uri); if (endpoint_uri) librdf_free_uri(endpoint_uri); return endpoint_node; }
librdf_node * node_create_from_uri (librdf_uri * uri) { librdf_node *node; node = librdf_new_node_from_uri (rdf_world::get_world (), uri); return node; }
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; }
/* * 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"); } }