void statement_in_tl(GSList ** list_, librdf_statement * statement) { GSList * list=*list_; ssTriple_t * triple; librdf_node* sub_node ; librdf_node* pred_node; librdf_node* obj_node ; sub_node = librdf_statement_get_subject(statement); pred_node = librdf_statement_get_predicate(statement); obj_node = librdf_statement_get_object(statement); triple =(ssTriple_t *) g_new0(ssTriple_t,1); triple->subject= g_strdup(librdf_uri_as_string( librdf_node_get_uri(sub_node))); triple->predicate = g_strdup(librdf_uri_as_string( librdf_node_get_uri(pred_node))); if (librdf_node_is_literal(obj_node)) { triple->object = g_strdup(librdf_node_get_literal_value(obj_node)); triple->objType = ssElement_TYPE_LIT; } else { triple->object = g_strdup(librdf_uri_as_string( librdf_node_get_uri(obj_node))); triple->objType = ssElement_TYPE_URI; } //printf ("statement to TL %s_%s_%s_%d\n", (char *)triple->subject, (char *)triple->predicate, (char *)triple->object, (bool *)triple->objType); list=g_slist_prepend(list, triple); /////////////////////////////////////////////////////////// *list_=list; }
/** * librdf_uri_print: * @uri: #librdf_uri object * @fh: file handle * * Print the URI to the given file handle. * **/ void librdf_uri_print (librdf_uri* uri, FILE *fh) { LIBRDF_ASSERT_OBJECT_POINTER_RETURN(uri, librdf_uri); fputs((const char*)librdf_uri_as_string(uri), fh); }
/** * librdf_uri_is_file_uri: * @uri: #librdf_uri object * * Test if a URI points to a filename. * * Return value: Non zero if the URI points to a file **/ int librdf_uri_is_file_uri(librdf_uri* uri) { LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(uri, librdf_uri, 1); return raptor_uri_uri_string_is_file_uri(librdf_uri_as_string(uri)); }
/** * librdf_new_serializer: * @world: redland world object * @name: the serializer factory name (or NULL or empty string if don't care) * @mime_type: the MIME type of the syntax (NULL if not used) * @type_uri: URI of syntax (NULL if not used) * * Constructor - create a new #librdf_serializer object. * * Return value: new #librdf_serializer object or NULL **/ librdf_serializer* librdf_new_serializer(librdf_world *world, const char *name, const char *mime_type, librdf_uri *type_uri) { librdf_serializer_factory* factory; librdf_world_open(world); factory = librdf_get_serializer_factory(world, name, mime_type, type_uri); if(!factory) { if(name) librdf_log(world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_SERIALIZER, NULL, "serializer '%s' not found", name); else if(mime_type) librdf_log(world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_SERIALIZER, NULL, "serializer for mime_type '%s' not found", mime_type); else if(type_uri) librdf_log(world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_SERIALIZER, NULL, "serializer for type URI '%s' not found", librdf_uri_as_string(type_uri)); else librdf_log(world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_SERIALIZER, NULL, "default serializer not found"); return NULL; } return librdf_new_serializer_from_factory(world, factory); }
RdfUri RdfStorePrivate::LibRdfUriToRdfUri(librdf_uri* uri) const { std::string str = (const char*) librdf_uri_as_string(uri); if (!str.empty()) return RdfUri(str); return RdfUri(); }
/** * 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; }
/** * librdf_uri_to_filename: * @uri: #librdf_uri object * * Return pointer to filename of URI. * * Returns a pointer to a newly allocated buffer that * the caller must free. This will fail if the URI * is not a file: URI. This can be checked with #librdf_uri_is_file_uri * * Return value: pointer to filename or NULL on failure **/ const char* librdf_uri_to_filename(librdf_uri* uri) { LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(uri, librdf_uri, NULL); return raptor_uri_uri_string_to_filename(librdf_uri_as_string(uri)); }
/** * librdf_storage_tstore_context_add_statement: * @storage: #librdf_storage object * @context_node: #librdf_node object * @statement: #librdf_statement statement to add * * Add a statement to a storage context. * * Return value: non 0 on failure **/ static int librdf_storage_tstore_context_add_statement(librdf_storage* storage, librdf_node* context_node, librdf_statement* statement) { librdf_storage_tstore_instance* context=(librdf_storage_tstore_instance*)storage->instance; librdf_node *subject_node=statement->subject; librdf_node *predicate_node=statement->predicate; librdf_node *object_node=statement->object; char *subject; char *predicate; char *object; rs_obj_type type; if(librdf_node_is_blank(subject_node)) { subject=(char*)librdf_node_get_blank_identifier(subject_node); } else subject=(char*)librdf_uri_as_string(librdf_node_get_uri(subject_node)); predicate=(char*)librdf_uri_as_string(librdf_node_get_uri(predicate_node)); /* Assumptions - FIXME */ if(librdf_node_is_literal(object_node)) { object=(char*)librdf_node_get_literal_value(object_node); type = ObjLiteral; } else if(librdf_node_is_blank(object_node)) { object=(char*)librdf_node_get_blank_identifier(object_node); type = ObjURI; } else { object=(char*)librdf_uri_as_string(librdf_node_get_uri(object_node)); type = ObjURI; } if(rs_assert_triple(context->rdfsql, subject, predicate, object, type)) return 1; return 0; }
void output_node(librdf_node* n) { if (librdf_node_is_literal(n)) { std::cout << librdf_node_get_literal_value(n); } if (librdf_node_is_resource(n)) { librdf_uri* uri = librdf_node_get_uri(n); std::cout << librdf_uri_as_string(uri); } }
/** Create a new SLV2Value from a librdf_node, or return NULL if impossible */ SLV2Value slv2_value_from_librdf_node(SLV2World world, librdf_node* node) { SLV2Value result = NULL; librdf_uri* datatype_uri = NULL; SLV2ValueType type = SLV2_VALUE_STRING; switch (librdf_node_get_type(node)) { case LIBRDF_NODE_TYPE_RESOURCE: type = SLV2_VALUE_URI; result = slv2_value_new_librdf_uri(world, librdf_node_get_uri(node)); break; case LIBRDF_NODE_TYPE_LITERAL: datatype_uri = librdf_node_get_literal_value_datatype_uri(node); if (datatype_uri) { if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), "http://www.w3.org/2001/XMLSchema#integer")) type = SLV2_VALUE_INT; else if (!strcmp((const char*)librdf_uri_as_string(datatype_uri), "http://www.w3.org/2001/XMLSchema#decimal")) type = SLV2_VALUE_FLOAT; else fprintf(stderr, "Unknown datatype %s\n", librdf_uri_as_string(datatype_uri)); } result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node)); break; case LIBRDF_NODE_TYPE_BLANK: type = SLV2_VALUE_STRING; result = slv2_value_new(world, type, (const char*)librdf_node_get_blank_identifier(node)); break; case LIBRDF_NODE_TYPE_UNKNOWN: default: fprintf(stderr, "Unknown RDF node type %d\n", librdf_node_get_type(node)); break; } return result; }
int librdf_serializer_set_namespace(librdf_serializer* serializer, librdf_uri *uri, const char *prefix) { LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(serializer, librdf_serializer, 1); if(uri && !*librdf_uri_as_string(uri)) uri=NULL; if(prefix && !*prefix) prefix=NULL; if(serializer->factory->set_namespace) return serializer->factory->set_namespace(serializer->context, uri, prefix); return 1; }
/* FIXME returns an alloced triple pointing to shared strings */ static rs_triple* librdf_storage_tstore_statement_as_rs_triple(librdf_statement *statement) { librdf_node *subject_node=statement->subject; librdf_node *predicate_node=statement->predicate; librdf_node *object_node=statement->object; rs_triple* triple=LIBRDF_MALLOC(rs_triple, sizeof(rs_triple)); if(subject_node) { if(librdf_node_is_blank(subject_node)) triple->subject=(char*)librdf_node_get_blank_identifier(subject_node); else triple->subject=(char*)librdf_uri_as_string(librdf_node_get_uri(subject_node)); } else triple->subject=NULL; if(predicate_node) triple->predicate=(char*)librdf_uri_as_string(librdf_node_get_uri(predicate_node)); else triple->predicate=NULL; /* Assumptions - FIXME */ triple->literal = 0; if(object_node) { if(librdf_node_is_literal(object_node)) { triple->object=(char*)librdf_node_get_literal_value(object_node); triple->literal = 1; } else if(librdf_node_is_blank(object_node)) { triple->object=(char*)librdf_node_get_blank_identifier(object_node); } else { triple->object=(char*)librdf_uri_as_string(librdf_node_get_uri(object_node)); } } else triple->object=NULL; return triple; }
/* * call-seq: * graph.load( uri ) -> Fixnum * * Parse the RDF at the specified +uri+ into the receiving graph. Returns the number of statements * added to the graph (if the underlying store supports ). * * graph = Redleaf::Graph.new * graph.load( "http://bigasterisk.com/foaf.rdf" ) * graph.load( "http://www.w3.org/People/Berners-Lee/card.rdf" ) * graph.load( "http://danbri.livejournal.com/data/foaf" ) * * graph.size */ static VALUE rleaf_redleaf_graph_load( VALUE self, VALUE uri ) { rleaf_GRAPH *ptr = rleaf_get_graph( self ); librdf_parser *parser = NULL; librdf_uri *rdfuri = NULL; int statement_count = librdf_model_size( ptr->model ); if ( (parser = librdf_new_parser( rleaf_rdf_world, NULL, NULL, NULL )) == NULL ) rb_raise( rleaf_eRedleafError, "failed to create a parser." ); rdfuri = rleaf_object_to_librdf_uri( uri ); if ( librdf_parser_parse_into_model(parser, rdfuri, NULL, ptr->model) != 0 ) rb_raise( rleaf_eRedleafError, "failed to load %s into %s", librdf_uri_as_string(rdfuri), RSTRING_PTR(rb_inspect( self )) ); return INT2FIX( librdf_model_size(ptr->model) - statement_count ); }
/* * Convert the given resource librdf_node to a Ruby URI object and return it. */ VALUE rleaf_librdf_uri_node_to_object( librdf_node *node ) { VALUE node_object = Qnil; librdf_uri *uri; const unsigned char *uristring = NULL; if ( !librdf_node_is_resource(node) ) rb_raise( rleaf_eRedleafError, "cannot convert a non-resource to a URI" ); if ( (uri = librdf_node_get_uri( node )) == NULL ) rb_raise( rleaf_eRedleafError, "unable to fetch a uri from resource node" ); if ( (uristring = librdf_uri_as_string( uri )) == NULL ) rb_raise( rleaf_eRedleafError, "unable to fetch a string from uri" ); // rleaf_log( "debug", "converting %s to a URI object", uristring ); node_object = rb_funcall( rleaf_rb_cURI, rb_intern("parse"), 1, rb_str_new2((const char *)uristring) ); return node_object; }
static void librdf_sql_config_store_triple(void *user_data, const raptor_statement *triple) { librdf_sql_config* config=(librdf_sql_config*)user_data; int i; for(i=0; i < config->predicates_count; i++) { if(triple->predicate_type != RAPTOR_IDENTIFIER_TYPE_RESOURCE || triple->object_type != RAPTOR_IDENTIFIER_TYPE_LITERAL) continue; if(!strcmp((const char*)librdf_uri_as_string((librdf_uri*)triple->predicate), config->predicate_uri_strings[i])) { config->values[i]=strdup((char*)triple->object); #if LIBRDF_DEBUG > 1 LIBRDF_DEBUG3("Set config value %d to '%s'\n", i, config->values[i]); #endif } } return; }
/** * 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; }
int main(int argc, char *argv[]) { const char *program=librdf_basename((const char*)argv[0]); librdf_world *world; librdf_uri* uri; librdf_node* node; unsigned char* actual; world=librdf_new_world(); librdf_world_open(world); uri=LIBRDF_MS_Seq_URI(world); if(!uri) { fprintf(stderr, "%s: Got no concept URI for rdf:Seq\n", program); exit(1); } actual=librdf_uri_as_string(uri); if(strcmp(EXPECTED_STRING, (const char*)actual)) { fprintf(stderr, "%s: Expected URI: <%s> Got: <%s>\n", program, EXPECTED_STRING, actual); exit(1); } node=librdf_get_concept_resource_by_index(world, LIBRDF_CONCEPT_LAST); if(!node) { fprintf(stderr, "%s: Got no concept node for the last concept\n", program); exit(1); } librdf_free_world(world); /* keep gcc -Wall happy */ return(0); }
int main(int argc, char *argv[]) { const unsigned char *hp_string=(const unsigned char*)"http://purl.org/net/dajobe/"; librdf_uri *uri1, *uri2, *uri3, *uri4, *uri5, *uri6, *uri7, *uri8, *uri9; librdf_digest *d; const char *program=librdf_basename((const char*)argv[0]); const char *file_string="/big/long/directory/file"; const unsigned char *file_uri_string=(const unsigned char*)"file:///big/long/directory/file"; const unsigned char *uri_string=(const unsigned char*)"http://example.com/big/long/directory/blah#frag"; const unsigned char *relative_uri_string1=(const unsigned char*)"#foo"; const unsigned char *relative_uri_string2=(const unsigned char*)"bar"; librdf_world *world; world=librdf_new_world(); librdf_world_open(world); fprintf(stderr, "%s: Creating new URI from string\n", program); uri1=librdf_new_uri(world, hp_string); if(!uri1) { fprintf(stderr, "%s: Failed to create URI from string '%s'\n", program, hp_string); return(1); } fprintf(stderr, "%s: Home page URI is ", program); librdf_uri_print(uri1, stderr); fputs("\n", stderr); fprintf(stderr, "%s: Creating URI from URI\n", program); uri2=librdf_new_uri_from_uri(uri1); if(!uri2) { fprintf(stderr, "%s: Failed to create new URI from old one\n", program); return(1); } fprintf(stderr, "%s: New URI is ", program); librdf_uri_print(uri2, stderr); fputs("\n", stderr); fprintf(stderr, "%s: Getting digest for URI\n", program); d = librdf_uri_get_digest(world, uri2); if(!d) { fprintf(stderr, "%s: Failed to get digest for URI %s\n", program, librdf_uri_as_string(uri2)); return(1); } fprintf(stderr, "%s: Digest is: ", program); librdf_digest_print(d, stderr); fputs("\n", stderr); librdf_free_digest(d); uri3=librdf_new_uri(world, (const unsigned char*)"file:/big/long/directory/"); uri4=librdf_new_uri(world, (const unsigned char*)"http://somewhere/dir/"); fprintf(stderr, "%s: Source URI is ", program); librdf_uri_print(uri3, stderr); fputs("\n", stderr); fprintf(stderr, "%s: Base URI is ", program); librdf_uri_print(uri4, stderr); fputs("\n", stderr); fprintf(stderr, "%s: URI string is '%s'\n", program, uri_string); uri5=librdf_new_uri_normalised_to_base(uri_string, uri3, uri4); fprintf(stderr, "%s: Normalised URI is ", program); librdf_uri_print(uri5, stderr); fputs("\n", stderr); uri6=librdf_new_uri_relative_to_base(uri5, relative_uri_string1); fprintf(stderr, "%s: URI + Relative URI %s gives ", program, relative_uri_string1); librdf_uri_print(uri6, stderr); fputs("\n", stderr); uri7=librdf_new_uri_relative_to_base(uri5, relative_uri_string2); fprintf(stderr, "%s: URI + Relative URI %s gives ", program, relative_uri_string2); librdf_uri_print(uri7, stderr); fputs("\n", stderr); uri8=librdf_new_uri_from_filename(world, file_string); uri9=librdf_new_uri(world, file_uri_string); if(!librdf_uri_equals(uri8, uri9)) { fprintf(stderr, "%s: URI string from filename %s returned %s, expected %s\n", program, file_string, librdf_uri_as_string(uri8), file_uri_string); return(1); } fprintf(stderr, "%s: Freeing URIs\n", program); librdf_free_uri(uri1); librdf_free_uri(uri2); librdf_free_uri(uri3); librdf_free_uri(uri4); librdf_free_uri(uri5); librdf_free_uri(uri6); librdf_free_uri(uri7); librdf_free_uri(uri8); librdf_free_uri(uri9); librdf_free_world(world); /* keep gcc -Wall happy */ return(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; }
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; }
static char* node_helper(librdf_storage* storage, librdf_node* node) { librdf_uri* uri; librdf_uri* dt_uri; const char* integer_type = "http://www.w3.org/2001/XMLSchema#integer"; const char* float_type = "http://www.w3.org/2001/XMLSchema#float"; const char* datetime_type = "http://www.w3.org/2001/XMLSchema#dateTime"; char* name; char data_type; switch(librdf_node_get_type(node)) { case LIBRDF_NODE_TYPE_RESOURCE: uri = librdf_node_get_uri(node); name = librdf_uri_as_string(uri); data_type = 'u'; break; case LIBRDF_NODE_TYPE_LITERAL: dt_uri = librdf_node_get_literal_value_datatype_uri(node); if (dt_uri == 0) data_type = 's'; else { const char* type_uri = librdf_uri_as_string(dt_uri); if (strcmp(type_uri, integer_type) == 0) data_type = 'i'; else if (strcmp(type_uri, float_type) == 0) data_type = 'f'; else if (strcmp(type_uri, datetime_type) == 0) data_type = 'd'; else data_type = 's'; } name = librdf_node_get_literal_value(node); break; case LIBRDF_NODE_TYPE_BLANK: name = librdf_node_get_blank_identifier(node); data_type = 'b'; break; case LIBRDF_NODE_TYPE_UNKNOWN: break; } char* term = malloc(5 + strlen(name)); if (term == 0) { fprintf(stderr, "malloc failed"); return 0; } sprintf(term, "%c:%s", data_type, name); return term; }
static void librdf_serializer_print_statement_as_ntriple(librdf_statement * statement, FILE *stream) { librdf_node *subject=librdf_statement_get_subject(statement); librdf_node *predicate=librdf_statement_get_predicate(statement); librdf_node *object=librdf_statement_get_object(statement); char *lang=NULL; librdf_uri *dt_uri=NULL; if(librdf_node_is_blank(subject)) fprintf(stream, "_:%s", librdf_node_get_blank_identifier(subject)); else if(librdf_node_is_resource(subject)) { /* Must be a URI */ fputc('<', stream); raptor_print_ntriples_string(stream, librdf_uri_as_string(librdf_node_get_uri(subject)), '\0'); fputc('>', stream); } else { LIBRDF_ERROR2(statement->world, "Do not know how to print triple subject type %d\n", librdf_node_get_type(subject)); return; } if(!librdf_node_is_resource(predicate)) { LIBRDF_ERROR2(statement->world, "Do not know how to print triple predicate type %d\n", librdf_node_get_type(predicate)); return; } fputc(' ', stream); fputc('<', stream); raptor_print_ntriples_string(stream, librdf_uri_as_string(librdf_node_get_uri(predicate)), '\0'); fputc('>', stream); fputc(' ', stream); switch(librdf_node_get_type(object)) { case LIBRDF_NODE_TYPE_LITERAL: fputc('"', stream); raptor_print_ntriples_string(stream, librdf_node_get_literal_value(object), '"'); fputc('"', stream); lang=librdf_node_get_literal_value_language(object); dt_uri=librdf_node_get_literal_value_datatype_uri(object); if(lang) { fputc('@', stream); fputs(lang, stream); } if(dt_uri) { fputs("^^<", stream); raptor_print_ntriples_string(stream, librdf_uri_as_string(dt_uri), '\0'); fputc('>', stream); } break; case LIBRDF_NODE_TYPE_BLANK: fputs("_:", stream); fputs((const char*)librdf_node_get_blank_identifier(object), stream); break; case LIBRDF_NODE_TYPE_RESOURCE: fputc('<', stream); raptor_print_ntriples_string(stream, librdf_uri_as_string(librdf_node_get_uri(object)), '\0'); fputc('>', stream); break; default: LIBRDF_ERROR2(statement->world, "Do not know how to print triple object type %d\n", librdf_node_get_type(object)); return; } fputs(" .", stream); }