DllExport int call_conv load_nquad_file(CTXTdecl) { char *filename = p2c_string(reg_term(CTXTdecl 1)); unsigned char *uri_string; raptor_uri *uri, *base_uri; world = raptor_new_world(); rdf_parser = raptor_new_parser(world, "nquads"); raptor_parser_set_statement_handler(rdf_parser, NULL, handle_term); uri_string = raptor_uri_filename_to_uri_string(filename); uri = raptor_new_uri(world, uri_string); base_uri = raptor_uri_copy(uri); raptor_parser_parse_file(rdf_parser, uri, base_uri); raptor_free_parser(rdf_parser); raptor_free_uri(base_uri); raptor_free_uri(uri); raptor_free_memory(uri_string); raptor_free_world(world); return 1; }
/***** ** Lee el archivo que contiene las tripletas RDF ** y hace el llamado a la funcion save_triple() para guardarlos *****/ void rdf_database_read_file(rdf_database db, const char *file) { raptor_world *world = NULL; unsigned char *uri_string; raptor_uri *uri, *base_uri; // parser world = raptor_new_world(); rdf_parser = raptor_new_parser(world, "rdfxml"); // seteo funcion handler para cada nodo raptor_parser_set_statement_handler(rdf_parser, (void*)db, save_triple); uri_string = raptor_uri_filename_to_uri_string(file); uri = raptor_new_uri(world, uri_string); base_uri = raptor_uri_copy(uri); // empieza parseo y guardado en memoria raptor_parser_parse_file(rdf_parser, uri, base_uri); // liberar ram raptor_free_parser(rdf_parser); raptor_free_uri(base_uri); raptor_free_uri(uri); raptor_free_memory(uri_string); raptor_free_world(world); }
int main(int argc, char *argv[]) { #ifdef HAVE_RAPTOR raptor_world *world = NULL; raptor_parser* rdf_parser = NULL; unsigned char *uri_string; raptor_uri *uri, *base_uri; world = raptor_new_world(); rdf_parser = raptor_new_parser(world, "ntriples"); raptor_parser_set_statement_handler(rdf_parser, NULL, print_triple); uri_string = raptor_uri_filename_to_uri_string(argv[1]); uri = raptor_new_uri(world, uri_string); base_uri = raptor_uri_copy(uri); raptor_parser_parse_file(rdf_parser, uri, base_uri); raptor_free_parser(rdf_parser); raptor_free_uri(base_uri); raptor_free_uri(uri); raptor_free_memory(uri_string); raptor_free_world(world); #endif return EXIT_SUCCESS; }
fs_metadata *fs_metadata_open(const char *kb) { fs_metadata *m = calloc(1, sizeof(fs_metadata)); gchar *fs_md_file_uri_format; fs_md_file_uri_format = g_strconcat("file://", fs_get_md_file_format(), NULL); m->size = 16; m->length = 0; m->entries = calloc(m->size, sizeof(struct m_entry)); m->uri = g_strdup_printf(fs_md_file_uri_format, kb); g_free(fs_md_file_uri_format); int fd; if ((fd = open(m->uri + 7, FS_O_NOATIME | O_CREAT, FS_FILE_MODE)) == -1) { fs_error(LOG_CRIT, "failed to touch metadata file %s: %s", m->uri, strerror(errno)); free(m); return NULL; } close(fd); m->rw = raptor_new_world(); if (!m->rw) { fs_error(LOG_CRIT, "failed to initialise raptor"); free(m); return NULL; } raptor_parser *rdf_parser = raptor_new_parser(m->rw, "turtle"); raptor_parser_set_statement_handler(rdf_parser, m, parse_stmt); char *uri = strdup(m->uri); raptor_uri *ruri = raptor_new_uri(m->rw, (unsigned char *) uri); raptor_uri *muri = raptor_new_uri(m->rw, (unsigned char *) uri); free(uri); if (raptor_parser_parse_uri(rdf_parser, ruri, muri)) { fs_error(LOG_ERR, "failed to parse metadata file “%s”", m->uri); return NULL; } raptor_free_parser(rdf_parser); raptor_free_uri(ruri); raptor_free_uri(muri); return m; }
turtle_input::turtle_input(const std::string& path) { raptor_world* world = raptor_new_world(); raptor_parser* parser = raptor_new_parser(world, "turtle"); unsigned char* uri_string; raptor_uri *uri, *base_uri; uri_string = raptor_uri_filename_to_uri_string(path.c_str()); uri = raptor_new_uri(world, uri_string); base_uri = raptor_uri_copy(uri); std::pair<triples_t*, raptor_uri*> user_data(&triples_, base_uri); raptor_parser_set_statement_handler(parser, (void*)&user_data, &statement_handler); triples_.clear(); raptor_parser_parse_file(parser, uri, base_uri); raptor_free_uri(base_uri); raptor_free_uri(uri); raptor_free_memory(uri_string); raptor_free_parser(parser); raptor_free_world(world); }
int main(int argc, char *argv[]) { raptor_world *world = NULL; raptor_parser* rdf_parser = NULL; unsigned char *uri_string; raptor_uri *uri; raptor_uri *base_uri; int rc = 0; int free_uri_string = 0; rdf_serializer = NULL; if(argc < 2 || argc > 3) { fprintf(stderr, "USAGE: %s RDF-FILE [BASE-URI]\n", program); rc = 1; goto tidy; } world = raptor_new_world(); uri_string = (unsigned char*)argv[1]; if(!access((const char*)uri_string, R_OK)) { uri_string = raptor_uri_filename_to_uri_string((char*)uri_string); uri = raptor_new_uri(world, uri_string); free_uri_string = 1; } else { uri = raptor_new_uri(world, (const unsigned char*)uri_string); } if(argc == 3) { char* base_uri_string = argv[2]; base_uri = raptor_new_uri(world, (unsigned char*)(base_uri_string)); } else { base_uri = raptor_uri_copy(uri); } rdf_parser = raptor_new_parser(world, "guess"); raptor_world_set_log_handler(world, rdf_parser, to_ntriples_log_handler); raptor_parser_set_statement_handler(rdf_parser, NULL, to_ntriples_write_triple); rdf_serializer = raptor_new_serializer(world, "ntriples"); raptor_serializer_start_to_file_handle(rdf_serializer, base_uri, stdout); raptor_parser_parse_file(rdf_parser, uri, base_uri); raptor_serializer_serialize_end(rdf_serializer); raptor_free_serializer(rdf_serializer); raptor_free_parser(rdf_parser); raptor_free_uri(base_uri); raptor_free_uri(uri); if(free_uri_string) raptor_free_memory(uri_string); raptor_free_world(world); tidy: if(warning_count) rc = 2; else if(error_count) rc = 1; return rc; }