static void raptor_librdfa_generate_statement(rdftriple* triple, void* callback_data) { raptor_parser* parser=(raptor_parser*)callback_data; raptor_statement *s=&parser->statement; raptor_uri *subject_uri=NULL; raptor_uri *predicate_uri=NULL; raptor_uri *object_uri=NULL; raptor_uri *datatype_uri=NULL; if(!triple->subject || !triple->predicate || !triple->object) { RAPTOR_FATAL1("Triple has NULL parts\n"); rdfa_free_triple(triple); return; } if(triple->object_type == RDF_TYPE_NAMESPACE_PREFIX) { RAPTOR_FATAL1("Triple has namespace object type\n"); rdfa_free_triple(triple); return; } if((triple->subject[0] == '_') && (triple->subject[1] == ':')) { s->subject_type = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS; s->subject= (triple->subject + 2); } else { s->subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; subject_uri=raptor_new_uri((const unsigned char*)triple->subject); if(!subject_uri) goto cleanup; s->subject=subject_uri; } predicate_uri=raptor_new_uri((const unsigned char*)triple->predicate); if(!predicate_uri) goto cleanup; s->predicate=predicate_uri; s->predicate_type=RAPTOR_IDENTIFIER_TYPE_RESOURCE; s->object = triple->object; s->object_literal_datatype=NULL; s->object_literal_language=NULL; if(triple->object_type == RDF_TYPE_IRI) { if((triple->object[0] == '_') && (triple->object[1] == ':')) { s->object_type = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS; s->object = (triple->object + 2); } else { s->object_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; object_uri=raptor_new_uri((const unsigned char*)triple->object); if(!object_uri) goto cleanup; s->object=object_uri; } } else if(triple->object_type == RDF_TYPE_PLAIN_LITERAL) { s->object_type=RAPTOR_IDENTIFIER_TYPE_LITERAL; if(triple->language) s->object_literal_language=(const unsigned char*)triple->language; } else if(triple->object_type == RDF_TYPE_XML_LITERAL) { s->object_type = RAPTOR_IDENTIFIER_TYPE_XML_LITERAL; } else if(triple->object_type == RDF_TYPE_TYPED_LITERAL) { s->object_type=RAPTOR_IDENTIFIER_TYPE_LITERAL; if(triple->language) s->object_literal_language=(const unsigned char*)triple->language; if(triple->datatype) { datatype_uri=raptor_new_uri((const unsigned char*)triple->datatype); if(!datatype_uri) goto cleanup; s->object_literal_datatype=datatype_uri; /* If datatype, no language allowed */ s->object_literal_language=NULL; } } else { RAPTOR_FATAL2("Triple has unknown object type %d\n", s->object_type); goto cleanup; } if(!parser->statement_handler) goto cleanup; /* Generate triple */ (*parser->statement_handler)(parser->user_data, s); cleanup: rdfa_free_triple(triple); if(subject_uri) raptor_free_uri(subject_uri); if(predicate_uri) raptor_free_uri(predicate_uri); if(object_uri) raptor_free_uri(object_uri); if(datatype_uri) raptor_free_uri(datatype_uri); }
static void processor_graph_triple(rdftriple* triple, void* callback_data) { printf("Processor Graph Triple:\n"); rdfa_print_triple(triple); rdfa_free_triple(triple); }
static void default_graph_triple(rdftriple* triple, void* callback_data) { rdfa_print_triple(triple); rdfa_free_triple(triple); }
void process_triple(rdftriple* triple, void* callback_data) { rdfa_free_triple(triple); }
static void raptor_librdfa_generate_statement(rdftriple* triple, void* callback_data) { raptor_parser* parser = (raptor_parser*)callback_data; raptor_statement *s = &parser->statement; raptor_term *subject_term = NULL; raptor_term *predicate_term = NULL; raptor_uri *predicate_uri = NULL; raptor_term *object_term = NULL; if(!parser->emitted_default_graph) { raptor_parser_start_graph(parser, NULL, 0); parser->emitted_default_graph++; } if(!parser->statement_handler) goto cleanup; if(!triple->subject || !triple->predicate || !triple->object) { #ifdef RAPTOR_DEBUG RAPTOR_FATAL1("Triple has NULL parts\n"); #else rdfa_free_triple(triple); return; #endif } if(triple->predicate[0] == '_') { raptor_parser_warning(parser, "Ignoring RDFa triple with blank node predicate %s.", triple->predicate); rdfa_free_triple(triple); return; } if(triple->object_type == RDF_TYPE_NAMESPACE_PREFIX) { #ifdef RAPTOR_DEBUG RAPTOR_FATAL1("Triple has namespace object type\n"); #else rdfa_free_triple(triple); return; #endif } if((triple->subject[0] == '_') && (triple->subject[1] == ':')) { subject_term = raptor_new_term_from_blank(parser->world, (const unsigned char*)triple->subject + 2); } else { raptor_uri* subject_uri; subject_uri = raptor_new_uri(parser->world, (const unsigned char*)triple->subject); subject_term = raptor_new_term_from_uri(parser->world, subject_uri); raptor_free_uri(subject_uri); subject_uri = NULL; } s->subject = subject_term; predicate_uri = raptor_new_uri(parser->world, (const unsigned char*)triple->predicate); if(!predicate_uri) goto cleanup; predicate_term = raptor_new_term_from_uri(parser->world, predicate_uri); raptor_free_uri(predicate_uri); predicate_uri = NULL; s->predicate = predicate_term; if(triple->object_type == RDF_TYPE_IRI) { if((triple->object[0] == '_') && (triple->object[1] == ':')) { object_term = raptor_new_term_from_blank(parser->world, (const unsigned char*)triple->object + 2); } else { raptor_uri* object_uri; object_uri = raptor_new_uri(parser->world, (const unsigned char*)triple->object); if(!object_uri) goto cleanup; object_term = raptor_new_term_from_uri(parser->world, object_uri); raptor_free_uri(object_uri); } } else if(triple->object_type == RDF_TYPE_PLAIN_LITERAL) { object_term = raptor_new_term_from_literal(parser->world, (const unsigned char*)triple->object, NULL, (const unsigned char*)triple->language); } else if(triple->object_type == RDF_TYPE_XML_LITERAL) { raptor_uri* datatype_uri; datatype_uri = raptor_new_uri_from_counted_string(parser->world, (const unsigned char*)raptor_xml_literal_datatype_uri_string, raptor_xml_literal_datatype_uri_string_len); object_term = raptor_new_term_from_literal(parser->world, (const unsigned char*)triple->object, datatype_uri, NULL); raptor_free_uri(datatype_uri); } else if(triple->object_type == RDF_TYPE_TYPED_LITERAL) { raptor_uri *datatype_uri = NULL; const unsigned char* language = (const unsigned char*)triple->language; if(triple->datatype) { /* If datatype, no language allowed */ language = NULL; datatype_uri = raptor_new_uri(parser->world, (const unsigned char*)triple->datatype); if(!datatype_uri) goto cleanup; } object_term = raptor_new_term_from_literal(parser->world, (const unsigned char*)triple->object, datatype_uri, language); raptor_free_uri(datatype_uri); } else { raptor_log_error_formatted(parser->world, RAPTOR_LOG_LEVEL_ERROR, NULL, "Triple has unknown object term type %u", s->object->type); goto cleanup; } s->object = object_term; /* Generate statement */ (*parser->statement_handler)(parser->user_data, s); cleanup: rdfa_free_triple(triple); if(subject_term) raptor_free_term(subject_term); if(predicate_term) raptor_free_term(predicate_term); if(object_term) raptor_free_term(object_term); }
static void process_triple(rdftriple* triple, void* callback_data) { rdfa_print_triple(triple); rdfa_free_triple(triple); }