/***** ** 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; }
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; }
/** * librdf_init_raptor: * @world: librdf_world object * * INTERNAL - Initialize the raptor library. * * Initializes the raptor library unless a raptor instance is provided * externally with librdf_world_set_raptor() (and using raptor v2 APIs). * Sets raptor uri handlers to work with #librdf_uri objects. * * Return value: non-0 on failure **/ int librdf_init_raptor(librdf_world* world) { if(!world->raptor_world_ptr) { world->raptor_world_ptr = raptor_new_world(); world->raptor_world_allocated_here = 1; if(world->raptor_world_ptr && world->raptor_init_handler) { world->raptor_init_handler(world->raptor_init_handler_user_data, world->raptor_world_ptr); } if(!world->raptor_world_ptr || raptor_world_open(world->raptor_world_ptr)) { LIBRDF_FATAL1(world, LIBRDF_FROM_PARSER, "failed to initialize raptor"); return 1; } } /* New in-memory hash for mapping bnode IDs */ world->bnode_hash = librdf_new_hash(world, NULL); if(!world->bnode_hash) return 1; /* set up log handler */ raptor_world_set_log_handler(world->raptor_world_ptr, world, librdf_raptor_log_handler); /* set up blank node identifier generation handler */ raptor_world_set_generate_bnodeid_handler(world->raptor_world_ptr, world, librdf_raptor_generate_id_handler); return 0; }
int main (int argc, char *argv[]) { const char *program = raptor_basename(argv[0]); raptor_world *world; const char *uri_string; raptor_www *www; const char *user_agent = "raptor_www_test/0.1"; raptor_uri *uri; void *string = NULL; size_t string_length = 0; if(argc > 1) uri_string = argv[1]; else uri_string = "http://librdf.org/"; world = raptor_new_world(); if(!world || raptor_world_open(world)) exit(1); uri = raptor_new_uri(world, (const unsigned char*)uri_string); if(!uri) { fprintf(stderr, "%s: Failed to create Raptor URI for %s\n", program, uri_string); exit(1); } www = raptor_new_www(world); raptor_www_set_content_type_handler(www, write_content_type, (void*)stderr); raptor_www_set_user_agent(www, user_agent); /* start retrieval (always a GET) */ if(raptor_www_fetch_to_string(www, uri, &string, &string_length, malloc)) { fprintf(stderr, "%s: WWW fetch failed\n", program); } else { #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 fprintf(stderr, "%s: HTTP response status %d\n", program, www->status_code); fprintf(stderr, "%s: Returned %d bytes of content\n", program, (int)string_length); #endif } if(string) free(string); raptor_free_www(www); raptor_free_uri(uri); raptor_free_world(world); return 0; }
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[]) { flickcurl *fc = NULL; int rc = 0; int usage = 0; int help = 0; const char* home; char config_path[1024]; char* photo_id = NULL; const char* prefix_uri = "http://www.flickr.com/photos/"; size_t prefix_uri_len = strlen(prefix_uri); const char *serializer_syntax_name = "ntriples"; raptor_uri* base_uri = NULL; raptor_serializer* serializer = NULL; int request_delay= -1; flickcurl_serializer* fs = NULL; flickcurl_photo* photo = NULL; program = my_basename(argv[0]); flickcurl_init(); rworld = raptor_new_world(); raptor_world_open(rworld); home = getenv("HOME"); if(home) sprintf(config_path, "%s/%s", home, config_filename); else strcpy(config_path, config_filename); while (!usage && !help) { int c; #ifdef HAVE_GETOPT_LONG int option_index = 0; c = getopt_long (argc, argv, GETOPT_STRING, long_options, &option_index); #else c = getopt (argc, argv, GETOPT_STRING); #endif if (c == -1) break; switch (c) { case 0: case '?': /* getopt() - unknown option */ usage = 1; break; case 'd': if(optarg) request_delay = atoi(optarg); break; case 'D': debug = 1; break; case 'h': help = 1; break; case 'o': if(optarg) { if(raptor_world_is_serializer_name(rworld, optarg)) serializer_syntax_name = optarg; else { int i; fprintf(stderr, "%s: invalid argument `%s' for `" HELP_ARG(o, output) "'\n", program, optarg); fprintf(stderr, "Valid arguments are:\n"); for(i = 0; 1; i++) { const raptor_syntax_description *d; d = raptor_world_get_serializer_description(rworld, i); if(!d) break; printf(" %-12s for %s\n", d->names[0], d->label); } usage = 1; break; } } break; case 'v': fputs(flickcurl_version_string, stdout); fputc('\n', stdout); exit(0); } } argv+= optind; argc-= optind; if(!help && argc < 1) usage = 2; /* Title and usage */ if(!help && !argc) { fprintf(stderr, "%s: No photo URI given\n", program); usage = 1; goto usage; } if(usage || help) goto usage; photo_id = argv[0]; if(strncmp(photo_id, prefix_uri, prefix_uri_len)) usage = 1; else { size_t len; photo_id+= prefix_uri_len; len = strlen(photo_id); if(!len) usage = 1; else { if(photo_id[len-1] == '/') photo_id[--len] = '\0'; while(*photo_id && *photo_id != '/') photo_id++; if(!*photo_id) usage = 1; else photo_id++; } } if(usage) { fprintf(stderr, "%s: Argument is not a Flickr photo URI like\n" " http://www.flickr.com/photos/USER/PHOTO/\n", program); goto usage; } serializer = raptor_new_serializer(rworld, serializer_syntax_name); if(!serializer) { fprintf(stderr, "%s: Failed to create raptor serializer type %s\n", program, serializer_syntax_name); return(1); } base_uri = raptor_new_uri(rworld, (const unsigned char*)argv[0]); raptor_serializer_start_to_file_handle(serializer, base_uri, stdout); /* Initialise the Flickcurl library */ fc = flickcurl_new(); if(!fc) { rc = 1; goto tidy; } flickcurl_set_error_handler(fc, my_message_handler, NULL); if(!access((const char*)config_path, R_OK)) { if(flickcurl_config_read_ini(fc, config_path, config_section, fc, flickcurl_config_var_handler)) { rc = 1; goto tidy; } } usage: if(usage) { if(usage>1) { fprintf(stderr, title_format_string, flickcurl_version_string); fputs("Flickcurl home page: ", stderr); fputs(flickcurl_home_url_string, stderr); fputc('\n', stderr); fputs(flickcurl_copyright_string, stderr); fputs("\nLicense: ", stderr); fputs(flickcurl_license_string, stderr); fputs("\n\n", stderr); } fprintf(stderr, "Try `%s " HELP_ARG(h, help) "' for more information.\n", program); rc = 1; goto tidy; } if(help) { int i; printf(title_format_string, flickcurl_version_string); puts("Get Triples from Flickr photos."); printf("Usage: %s [OPTIONS] FLICKR-PHOTO-URI\n\n", program); fputs(flickcurl_copyright_string, stdout); fputs("\nLicense: ", stdout); puts(flickcurl_license_string); fputs("Flickcurl home page: ", stdout); puts(flickcurl_home_url_string); fputs("\n", stdout); puts(HELP_TEXT("d", "delay DELAY ", "Set delay between requests in milliseconds")); puts(HELP_TEXT("D", "debug ", "Print lots of output")); puts(HELP_TEXT("h", "help ", "Print this help, then exit")); puts(HELP_TEXT("o", "output FORMAT ", "Set output format to one of:")); for(i = 0; 1; i++) { const raptor_syntax_description* d; d = raptor_world_get_serializer_description(rworld, i); if(!d) break; if(!strcmp(d->names[0], serializer_syntax_name)) printf(" %-15s %s (default)\n", d->names[0], d->label); else printf(" %-15s %s\n", d->names[0], d->label); } #ifdef HAVE_RAPTOR printf(" via Raptor %s serializers\n", raptor_version_string); #else puts(" via internal RDF serializer"); #endif puts(HELP_TEXT("v", "version ", "Print the flickcurl version")); rc = 0; goto tidy; } if(request_delay >= 0) flickcurl_set_request_delay(fc, request_delay); fs = flickcurl_new_serializer(fc, serializer, &flickrdf_serializer_factory); if(!fs) { fprintf(stderr, "%s: Failed to create Flickcurl serializer\n", program); goto tidy; } photo = flickcurl_photos_getInfo(fc, photo_id); if(!photo) goto tidy; if(debug) fprintf(stderr, "%s: Photo with URI %s ID %s has %d tags\n", program, photo->uri, photo->id, photo->tags_count); rc = flickcurl_serialize_photo(fs, photo); tidy: if(photo) flickcurl_free_photo(photo); if(fs) flickcurl_free_serializer(fs); if(fc) flickcurl_free(fc); if(serializer) raptor_free_serializer(serializer); if(base_uri) raptor_free_uri(base_uri); if(rworld) raptor_free_world(rworld); flickcurl_finish(); return(rc); }
int main(int argc, char *argv[]) { int rc = 1; int i; int parsers_count = 0; int serializers_count = 0; int mime_types_count = 0; raptor_syntax_description** parsers = NULL; raptor_syntax_description** serializers = NULL; raptor_iostream* iostr = NULL; type_syntax* type_syntaxes = NULL; int type_syntaxes_count = 0; if(argc != 1) { fprintf(stderr, "%s: USAGE: %s\n", program, program); return 1; } world = raptor_new_world(); if(!world) goto tidy; for(i = 0; 1; i++) { raptor_syntax_description* sd; sd = (raptor_syntax_description*)raptor_world_get_parser_description(world, i); if(!sd) break; parsers_count++; mime_types_count += sd->mime_types_count; } for(i = 0; 1; i++) { raptor_syntax_description* sd; sd = (raptor_syntax_description*)raptor_world_get_serializer_description(world, i); if(!sd) break; serializers_count++; mime_types_count += sd->mime_types_count; } parsers = (raptor_syntax_description**)calloc(parsers_count, sizeof(raptor_syntax_description*)); if(!parsers) goto tidy; serializers = (raptor_syntax_description**)calloc(serializers_count, sizeof(raptor_syntax_description*)); if(!serializers) goto tidy; type_syntaxes = (type_syntax*)calloc(mime_types_count, sizeof(type_syntax)); if(!type_syntaxes) goto tidy; type_syntaxes_count = 0; for(i = 0; 1; i++) { raptor_syntax_description* sd; unsigned int m; sd = (raptor_syntax_description*)raptor_world_get_parser_description(world, i); if(!sd) break; parsers[i] = sd; for(m = 0; m < sd->mime_types_count; m++) { type_syntaxes[type_syntaxes_count].mime_type = sd->mime_types[m].mime_type; type_syntaxes[type_syntaxes_count].q = sd->mime_types[m].q; type_syntaxes[type_syntaxes_count].parser_sd = sd; type_syntaxes_count++; } } qsort(parsers, parsers_count, sizeof(raptor_syntax_description*), sort_sd_by_name); for(i = 0; 1; i++) { raptor_syntax_description* sd; unsigned int m; sd = (raptor_syntax_description*)raptor_world_get_serializer_description(world, i); if(!sd) break; serializers[i] = sd; for(m = 0; m < sd->mime_types_count; m++) { type_syntaxes[type_syntaxes_count].mime_type = sd->mime_types[m].mime_type; type_syntaxes[type_syntaxes_count].q = sd->mime_types[m].q; type_syntaxes[type_syntaxes_count].serializer_sd = sd; type_syntaxes_count++; } } qsort(serializers, serializers_count, sizeof(raptor_syntax_description*), sort_sd_by_name); iostr = raptor_new_iostream_to_file_handle(world, stdout); if(!iostr) goto tidy; /* MIME Types by parser */ emit_header("raptor-formats", iostr); emit_start_section("raptor-formats-intro", "Introduction", iostr); raptor_iostream_string_write( "<para>\n" "The parsers and serializers in raptor can handle different MIME Types with different levels of quality (Q). A Q of 1.0 indicates that the parser or serializer will be able to read or write the full format with high quality, and it should be the prefered parser or serializer for that mime type. Lower Q values indicate either additional mime type support (for parsing) or less-preferred mime types (for serializing). A serializer typically has just 1 mime type of Q 1.0; the preferred type." "</para>\n" , iostr); emit_end_section(iostr); emit_start_section("raptor-formats-types-by-parser", "MIME Types by Parser", iostr); emit_start_desc_list(NULL, iostr); for(i = 0; i < parsers_count; i++) { emit_format_description(NULL, parsers[i], iostr); } emit_end_desc_list(iostr); emit_end_section(iostr); /* MIME Types by serializer */ emit_start_section("raptor-formats-types-by-serializer", "MIME Types by Serializer", iostr); emit_start_desc_list(NULL, iostr); for(i = 0; i < serializers_count; i++) { emit_format_description(NULL, serializers[i], iostr); } emit_end_desc_list(iostr); emit_end_section(iostr); /* MIME Types index */ qsort(type_syntaxes, type_syntaxes_count, sizeof(type_syntax), sort_type_syntax_by_mime_type); emit_start_section("raptor-formats-types-index", "MIME Types Index", iostr); emit_start_desc_list(NULL, iostr); if(1) { const char* last_mime_type = NULL; int last_start_index = -1; for(i = 0; i < type_syntaxes_count; i++) { const char *this_mime_type = type_syntaxes[i].mime_type; if(last_start_index < 0) { last_mime_type = this_mime_type; last_start_index = i; continue; } /* continue if same mime type */ if(!strcmp(last_mime_type, this_mime_type)) continue; emit_format_to_syntax_list(iostr, type_syntaxes, last_mime_type, last_start_index, i-1); last_mime_type = type_syntaxes[i].mime_type; last_start_index = i; } emit_format_to_syntax_list(iostr, type_syntaxes, last_mime_type, last_start_index, i-1); } emit_end_desc_list(iostr); emit_end_section(iostr); emit_footer(iostr); raptor_free_iostream(iostr); iostr = NULL; /* success */ rc = 0; tidy: if(iostr) raptor_free_iostream(iostr); if(parsers) free(parsers); if(serializers) free(serializers); if(type_syntaxes) free(type_syntaxes); if(world) raptor_free_world(world); return rc; }
int main(int argc, char *argv[]) { char *password = fsp_argv_password(&argc, argv); static char *optstring = "hevf:PO:Ib:rs:d"; char *format = getenv("FORMAT"); char *kb_name = NULL, *query = NULL; int programatic = 0, help = 0; int c, opt_index = 0; int verbosity = 0; int opt_level = 3; int insert_mode = 0; int restricted = 0; int soft_limit = 0; int explain = 0; int default_graph = 0; char *base_uri = "local:"; raptor_world *rw = NULL; static struct option long_options[] = { { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, { "verbose", 0, 0, 'v' }, { "explain", 0, 0, 'e' }, { "format", 1, 0, 'f' }, { "programatic", 0, 0, 'P' }, { "opt-level", 1, 0, 'O' }, { "insert", 0, 0, 'I' }, { "restricted", 0, 0, 'r' }, { "soft-limit", 1, 0, 's' }, { "default-graph", 0, 0, 'd' }, { "base", 1, 0, 'b' }, { 0, 0, 0, 0 } }; int help_return = 1; while ((c = getopt_long (argc, argv, optstring, long_options, &opt_index)) != -1) { if (c == 'f') { format = optarg; } else if (c == 'P') { programatic = TRUE; } else if (c == 'v') { verbosity++; } else if (c == 'O') { opt_level = atoi(optarg); } else if (c == 'I') { insert_mode = 1; } else if (c == 'r') { restricted = 1; } else if (c == 's') { soft_limit = atoi(optarg); } else if (c == 'd') { default_graph = 1; } else if (c == 'b') { base_uri = optarg; } else if (c == 'h') { help = 1; help_return = 0; } else if (c == 'e') { explain = 1; } else if (c == 'V') { printf("%s, built for 4store %s\n", argv[0], GIT_REV); exit(0); } else { help = 1; } } for (int k = optind; k < argc; ++k) { if (!kb_name) { kb_name = argv[k]; } else if (!query && !programatic) { query = argv[k]; } else { help = 1; } } if (help || !kb_name) { char *langs = ""; if (fs_query_have_laqrs()) { langs = "/LAQRS"; } fprintf(stdout, "%s revision %s\n", basename(argv[0]), GIT_REV); fprintf(stdout, "Usage: %s <kbname> [-f format] [-O opt-level] [-I] [-b uri] [query]\n", argv[0]); fprintf(stdout, " or: %s <kbname> -P\n", basename(argv[0])); fprintf(stdout, " query is a SPARQL%s query, remember to use" " shell quoting if necessary\n", langs); fprintf(stdout, " -f Output format one of, sparql, text, json, or testcase\n"); fprintf(stdout, " -O, --opt-level Set optimisation level, range 0-3\n"); fprintf(stdout, " -I, --insert Interpret CONSTRUCT statements as inserts\n"); fprintf(stdout, " -r, --restricted Enable query complexity restriction\n"); fprintf(stdout, " -s, --soft-limit Override default soft limit on search breadth\n"); fprintf(stdout, " -d, --default-graph Enable SPARQL default graph support\n"); fprintf(stdout, " -b, --base Set base URI for query\n"); fprintf(stdout, " -e, --explain Show explain results for execution plan\n"); exit(help_return); } if (programatic || query) { /* don't syslog interactive errors */ fsp_syslog_enable(); } double then = ftime(); /* if query does UPDATE or DELETE operations this needs a re-think */ fsp_link *link = fsp_open_link(kb_name, password, FS_OPEN_HINT_RO); double now = ftime(); show_timing = (getenv("SHOW_TIMING") != NULL) | (verbosity > 1); if (show_timing) { printf("Link open time: %f\n", now-then); } if (!link) { fs_error(LOG_ERR, "couldn't connect to “%s”", kb_name); return 2; } const int segments = fsp_link_segments(link); fs_query_timing timing[segments]; memset(timing, 0, sizeof(fs_query_timing) * segments); if (show_timing) { for (int seg = 0; seg < segments; seg++) { fsp_get_query_times(link, seg, timing+seg); } } if (fsp_no_op(link, 0)) { fs_error(LOG_ERR, "NO-OP failed for “%s”", kb_name); return 2; } rw = raptor_new_world(); fs_hash_init(fsp_hash_type(link)); raptor_uri *bu = raptor_new_uri(rw, (unsigned char *)base_uri); unsigned int flags = FS_QUERY_CONSOLE_OUTPUT; /* signal that we're using the */ /* console, allows better explain functionality */ flags |= insert_mode ? FS_RESULT_FLAG_CONSTRUCT_AS_INSERT : 0; flags |= restricted ? FS_QUERY_RESTRICTED : 0; flags |= default_graph ? FS_QUERY_DEFAULT_GRAPH : 0; if (programatic) { programatic_io(link, bu, "sparql", format, timing, verbosity, opt_level, FS_RESULT_FLAG_HEADERS | flags, soft_limit, rw); } else if (!query) { if (!format) format = "text"; interactive(link, bu, format, verbosity, opt_level, insert_mode ? FS_RESULT_FLAG_CONSTRUCT_AS_INSERT : flags, soft_limit, rw); } int ret = 0; fs_query_state *qs = fs_query_init(link, NULL, NULL); qs->verbosity = verbosity; fs_query *qr = fs_query_execute(qs, link, bu, query, flags, opt_level, soft_limit, explain); if (fs_query_errors(qr)) { ret = 1; } fs_query_results_output(qr, format, 0, stdout); fs_query_free(qr); if (show_timing) { printf("seg bind\t(secs)\t\tprice\t(secs)\t\tresolve\t(secs)\t\twait (secs)\n"); long long *tics = fsp_profile_write(link); for (int seg = 0; seg < segments; seg++) { fs_query_timing newtimes; fsp_get_query_times(link, seg, &newtimes); printf("%2d: %4d\t%f\t%4d\t%f\t%4d\t%f\t%f\n", seg, newtimes.bind_count - timing[seg].bind_count, newtimes.bind - timing[seg].bind, newtimes.price_count - timing[seg].price_count, newtimes.price - timing[seg].price, newtimes.resolve_count - timing[seg].resolve_count, newtimes.resolve - timing[seg].resolve, tics[seg] * 0.001); } } raptor_free_uri(bu); raptor_free_world(rw); fs_query_cache_flush(qs, verbosity); fs_query_fini(qs); fsp_close_link(link); return ret; }
int main(int argc, char *argv[]) { int verbosity = 0; int dryrun = 0; char *password = NULL; char *format = "auto"; FILE *msg = stderr; char *optstring = "am:M:vnf:"; int c, opt_index = 0, help = 0; int files = 0, adding = 0; char *kb_name = NULL; char *model[argc], *uri[argc]; char *model_default = NULL; password = fsp_argv_password(&argc, argv); static struct option long_options[] = { { "add", 0, 0, 'a' }, { "model", 1, 0, 'm' }, { "model-default", 1, 0, 'M' }, { "verbose", 0, 0, 'v' }, { "dryrun", 0, 0, 'n' }, { "no-resources", 0, 0, 'R' }, { "no-quads", 0, 0, 'Q' }, { "format", 1, 0, 'f' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, { 0, 0, 0, 0 } }; for (int i= 0; i < argc; ++i) { model[i] = NULL; } int help_return = 1; while ((c = getopt_long (argc, argv, optstring, long_options, &opt_index)) != -1) { if (c == 'm') { model[files++] = optarg; } else if (c == 'M') { model_default = optarg; } else if (c == 'v') { verbosity++; } else if (c == 'a') { adding = 1; } else if (c == 'n') { dryrun |= FS_DRYRUN_DELETE | FS_DRYRUN_RESOURCES | FS_DRYRUN_QUADS; } else if (c == 'R') { dryrun |= FS_DRYRUN_RESOURCES; } else if (c == 'Q') { dryrun |= FS_DRYRUN_QUADS; } else if (c == 'f') { format = optarg; } else if (c == 'h') { help = 1; help_return = 0; } else if (c == 'V') { printf("%s, built for 4store %s\n", argv[0], GIT_REV); exit(0); } else { help = 1; } } if (verbosity > 0) { if (dryrun & FS_DRYRUN_DELETE) { printf("warning: not deleting old model\n"); } if (dryrun & FS_DRYRUN_RESOURCES) { printf("warning: not importing resource nodes\n"); } if (dryrun & FS_DRYRUN_QUADS) { printf("warning: not importing quad graph\n"); } } files = 0; for (int k = optind; k < argc; ++k) { if (!kb_name) { kb_name = argv[k]; } else { if (strchr(argv[k], ':')) { uri[files] = g_strdup(argv[k]); } else { uri[files] = (char *)raptor_uri_filename_to_uri_string(argv[k]); } if (!model[files]) { if (!model_default) { model[files] = uri[files]; } else { model[files] = model_default; } } files++; } } raptor_world *rw = raptor_new_world(); if (help || !kb_name || files == 0) { fprintf(stdout, "%s revision %s\n", argv[0], FS_FRONTEND_VER); fprintf(stdout, "Usage: %s <kbname> <rdf file/URI> ...\n", argv[0]); fprintf(stdout, " -v --verbose increase verbosity (can repeat)\n"); fprintf(stdout, " -a --add add data to models instead of replacing\n"); fprintf(stdout, " -m --model specify a model URI for the next RDF file\n"); fprintf(stdout, " -M --model-default specify a model URI for all RDF files\n"); fprintf(stdout, " -f --format specify an RDF syntax for the import\n"); fprintf(stdout, "\n available formats are:\n"); for (unsigned int i=0; 1; i++) { const raptor_syntax_description *desc = raptor_world_get_parser_description(rw, i); if (!desc) { break; } fprintf(stdout, " %12s - %s\n", desc->names[0], desc->label); } exit(help_return); } fsp_syslog_enable(); fsplink = fsp_open_link(kb_name, password, FS_OPEN_HINT_RW); if (!fsplink) { fs_error (LOG_ERR, "couldn't connect to “%s”", kb_name); exit(2); } const char *features = fsp_link_features(fsplink); int has_o_index = !(strstr(features, "no-o-index")); /* tweak */ fs_hash_init(fsp_hash_type(fsplink)); const int segments = fsp_link_segments(fsplink); int total_triples = 0; fs_import_timing timing[segments]; for (int seg = 0; seg < segments; seg++) { fsp_get_import_times(fsplink, seg, &timing[seg]); } gettimeofday(&then, 0); if (fsp_start_import_all(fsplink)) { fs_error(LOG_ERR, "aborting import"); exit(3); } #if 0 printf("press enter\n"); char foo; read(0, &foo, 1); #endif fs_rid_vector *mvec = fs_rid_vector_new(0); for (int f= 0; f < files; ++f) { fs_rid muri = fs_hash_uri(model[f]); fs_rid_vector_append(mvec, muri); } if (!adding) { if (verbosity) { printf("removing old data\n"); fflush(stdout); } if (!(dryrun & FS_DRYRUN_DELETE)) { if (fsp_delete_model_all(fsplink, mvec)) { fs_error(LOG_ERR, "model delete failed"); return 1; } for (int i=0; i<mvec->length; i++) { if (mvec->data[i] == fs_c.system_config) { fs_import_reread_config(); } } } fsp_new_model_all(fsplink, mvec); } fs_rid_vector_free(mvec); gettimeofday(&then_last, 0); for (int f = 0; f < files; ++f) { if (verbosity) { printf("Reading <%s>\n", uri[f]); if (strcmp(uri[f], model[f])) { printf(" into <%s>\n", model[f]); } fflush(stdout); } fs_import(fsplink, model[f], uri[f], format, verbosity, dryrun, has_o_index, msg, &total_triples); if (verbosity) { fflush(stdout); } } double sthen = fs_time(); int ret = fs_import_commit(fsplink, verbosity, dryrun, has_o_index, msg, &total_triples); if (verbosity > 0) { printf("Updating index\n"); fflush(stdout); } fsp_stop_import_all(fsplink); if (verbosity > 0) { printf("Index update took %f seconds\n", fs_time()-sthen); } if (!ret) { gettimeofday(&now, 0); double diff = (now.tv_sec - then.tv_sec) + (now.tv_usec - then.tv_usec) * 0.000001; if (verbosity && total_triples > 0) { printf("Imported %d triples, average %d triples/s\n", total_triples, (int)((double)total_triples/diff)); fflush(stdout); } } if (verbosity > 1) { printf("seg add_q\tadd_r\t\tcommit_q\tcommit_r\tremove\t\trebuild\t\twrite\n"); long long *tics = fsp_profile_write(fsplink); for (int seg = 0; seg < segments; seg++) { fs_import_timing newtimes; fsp_get_import_times(fsplink, seg, &newtimes); printf("%2d: %f\t%f\t%f\t%f\t%f\t%f\t%f\n", seg, newtimes.add_s - timing[seg].add_s, newtimes.add_r - timing[seg].add_r, newtimes.commit_q - timing[seg].commit_q, newtimes.commit_r - timing[seg].commit_r, newtimes.remove - timing[seg].remove, newtimes.rebuild - timing[seg].rebuild, tics[seg] * 0.001); } } fsp_close_link(fsplink); raptor_free_world(rw); return 0; }
int main(int argc, char *argv[]) { raptor_world *world; const char *program = raptor_basename(argv[0]); raptor_iostream *iostr; raptor_namespace_stack *nstack; raptor_namespace* foo_ns; raptor_xml_writer* xml_writer; raptor_uri* base_uri; raptor_qname* el_name; raptor_xml_element *element; unsigned long offset; raptor_qname **attrs; raptor_uri* base_uri_copy = NULL; /* for raptor_new_iostream_to_string */ void *string = NULL; size_t string_len = 0; world = raptor_new_world(); if(!world || raptor_world_open(world)) exit(1); iostr = raptor_new_iostream_to_string(world, &string, &string_len, NULL); if(!iostr) { fprintf(stderr, "%s: Failed to create iostream to string\n", program); exit(1); } nstack = raptor_new_namespaces(world, 1); xml_writer = raptor_new_xml_writer(world, nstack, iostr); if(!xml_writer) { fprintf(stderr, "%s: Failed to create xml_writer to iostream\n", program); exit(1); } base_uri = raptor_new_uri(world, base_uri_string); foo_ns = raptor_new_namespace(nstack, (const unsigned char*)"foo", (const unsigned char*)"http://example.org/foo-ns#", 0); el_name = raptor_new_qname_from_namespace_local_name(world, foo_ns, (const unsigned char*)"bar", NULL); base_uri_copy = base_uri ? raptor_uri_copy(base_uri) : NULL; element = raptor_new_xml_element(el_name, NULL, /* language */ base_uri_copy); raptor_xml_writer_start_element(xml_writer, element); raptor_xml_writer_cdata_counted(xml_writer, (const unsigned char*)"hello\n", 6); raptor_xml_writer_comment_counted(xml_writer, (const unsigned char*)"comment", 7); raptor_xml_writer_cdata(xml_writer, (const unsigned char*)"\n"); raptor_xml_writer_end_element(xml_writer, element); raptor_free_xml_element(element); raptor_xml_writer_cdata(xml_writer, (const unsigned char*)"\n"); el_name = raptor_new_qname(nstack, (const unsigned char*)"blah", NULL /* no attribute value - element */); base_uri_copy = base_uri ? raptor_uri_copy(base_uri) : NULL; element = raptor_new_xml_element(el_name, NULL, /* language */ base_uri_copy); attrs = (raptor_qname **)RAPTOR_CALLOC(qnamearray, 1, sizeof(raptor_qname*)); attrs[0] = raptor_new_qname(nstack, (const unsigned char*)"a", (const unsigned char*)"b" /* attribute value */); raptor_xml_element_set_attributes(element, attrs, 1); raptor_xml_writer_empty_element(xml_writer, element); raptor_xml_writer_cdata(xml_writer, (const unsigned char*)"\n"); raptor_free_xml_writer(xml_writer); raptor_free_xml_element(element); raptor_free_namespace(foo_ns); raptor_free_namespaces(nstack); raptor_free_uri(base_uri); offset = raptor_iostream_tell(iostr); #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Freeing iostream\n", program); #endif raptor_free_iostream(iostr); if(offset != OUT_BYTES_COUNT) { fprintf(stderr, "%s: I/O stream wrote %d bytes, expected %d\n", program, (int)offset, (int)OUT_BYTES_COUNT); fputs("[[", stderr); (void)fwrite(string, 1, string_len, stderr); fputs("]]\n", stderr); return 1; } if(!string) { fprintf(stderr, "%s: I/O stream failed to create a string\n", program); return 1; } string_len = strlen((const char*)string); if(string_len != offset) { fprintf(stderr, "%s: I/O stream created a string length %d, expected %d\n", program, (int)string_len, (int)offset); return 1; } #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Made XML string of %d bytes\n", program, (int)string_len); fputs("[[", stderr); (void)fwrite(string, 1, string_len, stderr); fputs("]]\n", stderr); #endif raptor_free_memory(string); raptor_free_world(world); /* keep gcc -Wall happy */ return(0); }
int main(int argc, char *argv[]) { raptor_world *world; const char *program = raptor_basename(argv[0]); #define ITEM_COUNT 8 const char *items[ITEM_COUNT+1] = { "ron", "amy", "jen", "bij", "jib", "daj", "jim", "def", NULL }; #define DELETE_COUNT 2 const char *delete_items[DELETE_COUNT+1] = { "jen", "jim", NULL }; #define RESULT_COUNT (ITEM_COUNT-DELETE_COUNT) const char *results[RESULT_COUNT+1] = { "amy", "bij", "daj", "def", "jib", "ron", NULL}; raptor_avltree* tree; raptor_avltree_iterator* iter; visit_state vs; int i; world = raptor_new_world(); if(!world || raptor_world_open(world)) exit(1); tree = raptor_new_avltree(compare_strings, NULL, /* no free as they are static pointers above */ 0); if(!tree) { fprintf(stderr, "%s: Failed to create tree\n", program); exit(1); } for(i = 0; items[i]; i++) { int rc; void* node; #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Adding tree item '%s'\n", program, items[i]); #endif rc = raptor_avltree_add(tree, (void*)items[i]); if(rc) { fprintf(stderr, "%s: Adding tree item %d '%s' failed, returning error %d\n", program, i, items[i], rc); exit(1); } #ifdef RAPTOR_DEBUG raptor_avltree_check(tree); #endif node = raptor_avltree_search(tree, (void*)items[i]); if(!node) { fprintf(stderr, "%s: Tree did NOT contain item %d '%s' as expected\n", program, i, items[i]); exit(1); } } #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Printing tree\n", program); vs.fh = stderr; vs.count = 0; raptor_avltree_visit(tree, print_string, &vs); fprintf(stderr, "%s: Dumping tree\n", program); raptor_avltree_dump(tree, stderr); #endif for(i = 0; delete_items[i]; i++) { int rc; #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Deleting tree item '%s'\n", program, delete_items[i]); #endif rc = raptor_avltree_delete(tree, (void*)delete_items[i]); if(!rc) { fprintf(stderr, "%s: Deleting tree item %d '%s' failed, returning error %d\n", program, i, delete_items[i], rc); exit(1); } #ifdef RAPTOR_DEBUG raptor_avltree_check(tree); #endif } #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Walking tree forwards via iterator\n", program); #endif iter = raptor_new_avltree_iterator(tree, NULL, NULL, 1); for(i = 0; 1; i++) { const char* data = (const char*)raptor_avltree_iterator_get(iter); const char* result = results[i]; if((!data && data != result) || (data && strcmp(data, result))) { fprintf(stderr, "%3d: Forwards iterator expected '%s' but found '%s'\n", i, result, data); exit(1); } #if RAPTOR_DEBUG > 1 fprintf(stderr, "%3d: Got '%s'\n", i, data); #endif if(raptor_avltree_iterator_next(iter)) break; if(i > RESULT_COUNT) { fprintf(stderr, "Forward iterator did not end on result %i as expected\n", i); exit(1); } } raptor_free_avltree_iterator(iter); #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Checking tree\n", program); #endif vs.count = 0; vs.results = results; vs.failed = 0; raptor_avltree_visit(tree, check_string, &vs); if(vs.failed) { fprintf(stderr, "%s: Checking tree failed\n", program); exit(1); } for(i = 0; results[i]; i++) { const char* result = results[i]; char* data = (char*)raptor_avltree_remove(tree, (void*)result); if(!data) { fprintf(stderr, "%s: remove %i failed at item '%s'\n", program, i, result); exit(1); } if(strcmp(data, result)) { fprintf(stderr, "%s: remove %i returned %s not %s as expected\n", program, i, data, result); exit(1); } } #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Freeing tree\n", program); #endif raptor_free_avltree(tree); raptor_free_world(world); /* keep gcc -Wall happy */ return(0); }
int main(int argc, char *argv[]) { raptor_world *world; const char *program = raptor_basename(argv[0]); int rc = 0; raptor_term* term1 = NULL; /* URI string 1 */ raptor_term* term2 = NULL; /* literal string1 */ raptor_term* term3 = NULL; /* blank node 1 */ raptor_term* term4 = NULL; /* URI string 2 */ raptor_term* term5 = NULL; /* URI string 1 again */ raptor_uri* uri1; unsigned char* uri_str; size_t uri_len; world = raptor_new_world(); if(!world || raptor_world_open(world)) exit(1); /* check a term for NULL URI fails */ term1 = raptor_new_term_from_uri(world, NULL); if(term1) { fprintf(stderr, "%s: raptor_new_uri(NULL) returned object rather than failing\n", program); rc = 1; goto tidy; } /* check a term for non-NULL URI succeeds */ uri1 = raptor_new_uri(world, uri_string1); if(!uri1) { fprintf(stderr, "%s: raptor_new_uri(%s) failed\n", program, uri_string1); rc = 1; goto tidy; } term1 = raptor_new_term_from_uri(world, uri1); if(!term1) { fprintf(stderr, "%s: raptor_new_term_from_uri_string(URI %s) failed\n", program, uri_string1); rc = 1; goto tidy; } raptor_free_uri(uri1); uri1 = NULL; if(term1->type != uri_string1_type) { fprintf(stderr, "%s: raptor term 1 is of type %d expected %d\n", program, term1->type, uri_string1_type); rc = 1; goto tidy; } /* returns a pointer to shared string */ uri_str = raptor_uri_as_counted_string(term1->value.uri, &uri_len); if(!uri_str) { fprintf(stderr, "%s: raptor_uri_as_counted_string term 1 failed\n", program); rc = 1; goto tidy; } if(uri_len != uri_string1_len) { fprintf(stderr, "%s: raptor term 1 URI is of length %d expected %d\n", program, (int)uri_len, (int)uri_string1_len); rc = 1; goto tidy; } /* check an empty literal is created from a NULL literal pointer succeeds */ term2 = raptor_new_term_from_counted_literal(world, NULL, 0, NULL, NULL, 0); if(!term2) { fprintf(stderr, "%s: raptor_new_term_from_counted_literal() with all NULLs failed\n", program); rc = 1; goto tidy; } raptor_free_term(term2); /* check an empty literal from an empty language literal pointer succeeds */ term2 = raptor_new_term_from_counted_literal(world, NULL, 0, NULL, (const unsigned char*)"", 0); if(!term2) { fprintf(stderr, "%s: raptor_new_term_from_counted_literal() with empty language failed\n", program); rc = 1; goto tidy; } raptor_free_term(term2); /* check a literal with language and datatype fails */ uri1 = raptor_new_uri(world, uri_string1); if(!uri1) { fprintf(stderr, "%s: raptor_new_uri(%s) failed\n", program, uri_string1); rc = 1; goto tidy; } term2 = raptor_new_term_from_counted_literal(world, literal_string1, literal_string1_len, uri1, language1, 0); raptor_free_uri(uri1); uri1 = NULL; if(term2) { fprintf(stderr, "%s: raptor_new_term_from_counted_literal() with language and datatype returned object rather than failing\n", program); rc = 1; goto tidy; } /* check a literal with no language and no datatype succeeds */ term2 = raptor_new_term_from_counted_literal(world, literal_string1, literal_string1_len, NULL, NULL, 0); if(!term2) { fprintf(stderr, "%s: raptor_new_term_from_counted_literal(%s) failed\n", program, literal_string1); rc = 1; goto tidy; } if(term2->type != literal_string1_type) { fprintf(stderr, "%s: raptor term 2 is of type %d expected %d\n", program, term2->type, literal_string1_type); rc = 1; goto tidy; } /* check a blank node term with NULL id generates a new identifier */ term3 = raptor_new_term_from_counted_blank(world, NULL, 0); if(!term3) { fprintf(stderr, "%s: raptor_new_term_from_counted_blank(NULL) failed\n", program); rc = 1; goto tidy; } if(term3->type != bnodeid1_type) { fprintf(stderr, "%s: raptor term 3 is of type %d expected %d\n", program, term3->type, bnodeid1_type); rc = 1; goto tidy; } raptor_free_term(term3); /* check a blank node term with an identifier succeeds */ term3 = raptor_new_term_from_counted_blank(world, bnodeid1, bnodeid1_len); if(!term3) { fprintf(stderr, "%s: raptor_new_term_from_counted_blank(%s) failed\n", program, bnodeid1); rc = 1; goto tidy; } if(term3->type != bnodeid1_type) { fprintf(stderr, "%s: raptor term 3 is of type %d expected %d\n", program, term3->type, bnodeid1_type); rc = 1; goto tidy; } /* check a different URI term succeeds */ term4 = raptor_new_term_from_counted_uri_string(world, uri_string2, uri_string2_len); if(!term4) { fprintf(stderr, "%s: raptor_new_term_from_counted_uri_string(URI %s) failed\n", program, uri_string2); rc = 1; goto tidy; } if(term4->type != uri_string2_type) { fprintf(stderr, "%s: raptor term 4 is of type %d expected %d\n", program, term4->type, uri_string2_type); rc = 1; goto tidy; } /* returns a pointer to shared string */ uri_str = raptor_uri_as_counted_string(term4->value.uri, &uri_len); if(!uri_str) { fprintf(stderr, "%s: raptor_uri_as_counted_string term 4 failed\n", program); rc = 1; goto tidy; } if(uri_len != uri_string2_len) { fprintf(stderr, "%s: raptor term 4 URI is of length %d expected %d\n", program, (int)uri_len, (int)uri_string2_len); rc = 1; goto tidy; } /* check the same URI term as term1 succeeds */ term5 = raptor_new_term_from_uri_string(world, uri_string1); if(!term5) { fprintf(stderr, "%s: raptor_new_term_from_uri_string(URI %s) failed\n", program, uri_string1); rc = 1; goto tidy; } if(raptor_term_equals(term1, term2)) { fprintf(stderr, "%s: raptor_term_equals (URI %s, literal %s) returned equal, expected not-equal\n", program, uri_string1, literal_string1); rc = 1; goto tidy; } if(raptor_term_equals(term1, term3)) { fprintf(stderr, "%s: raptor_term_equals (URI %s, bnode %s) returned equal, expected not-equal\n", program, uri_string1, bnodeid1); rc = 1; goto tidy; } if(raptor_term_equals(term1, term4)) { fprintf(stderr, "%s: raptor_term_equals (URI %s, URI %s) returned equal, expected not-equal\n", program, uri_string1, uri_string2); rc = 1; goto tidy; } if(!raptor_term_equals(term1, term5)) { fprintf(stderr, "%s: raptor_term_equals (URI %s, URI %s) returned not-equal, expected equal\n", program, uri_string1, uri_string1); rc = 1; goto tidy; } if(term1->value.uri != term5->value.uri) { fprintf(stderr, "%s: term1 and term5 URI objects returned not-equal pointers, expected equal\n", program); /* This is not necessarily a failure if the raptor_uri module has had * the URI interning disabled with * raptor_world_set_flag(world, RAPTOR_WORLD_FLAG_URI_INTERNING, 0) * however this test suite does not do that, so it is a failure here. */ rc = 1; goto tidy; } tidy: if(term1) raptor_free_term(term1); if(term2) raptor_free_term(term2); if(term3) raptor_free_term(term3); if(term4) raptor_free_term(term4); if(term5) raptor_free_term(term5); raptor_free_world(world); return rc; }
void rdf_parser_init() { //TODO: mutex, race condition ... more than 1 thread init ?? parser_world = raptor_new_world(); }
/** * rasqal_world_open: * @world: rasqal_world object * * Initialise the rasqal library. * * Initializes a #rasqal_world object created by rasqal_new_world(). * Allocation and initialization are decoupled to allow * changing settings on the world object before init. * These settings include e.g. the raptor library instance set with * rasqal_world_set_raptor(). * * The initialized world object is used with subsequent rasqal API calls. * * Return value: non-0 on failure **/ int rasqal_world_open(rasqal_world *world) { int rc; if(!world) return -1; if(world->opened++) return 0; /* not an error */ /* Create and init a raptor_world unless one is provided externally with rasqal_world_set_raptor() */ if(!world->raptor_world_ptr) { world->raptor_world_ptr = raptor_new_world(); if(!world->raptor_world_ptr) return -1; world->raptor_world_allocated_here = 1; rc = raptor_world_open(world->raptor_world_ptr); if(rc) return rc; } rc = rasqal_uri_init(world); if(rc) return rc; rc = rasqal_xsd_init(world); if(rc) return rc; world->query_languages = raptor_new_sequence((raptor_data_free_handler)rasqal_free_query_language_factory, NULL); if(!world->query_languages) return 1; /* first query language declared is the default */ #ifdef RASQAL_QUERY_SPARQL rc = rasqal_init_query_language_sparql(world); if(rc) return rc; rc = rasqal_init_query_language_sparql11(world); if(rc) return rc; #endif #ifdef RASQAL_QUERY_LAQRS rc = rasqal_init_query_language_laqrs(world); if(rc) return rc; #endif rc = rasqal_raptor_init(world); if(rc) return rc; rc = rasqal_init_query_results(); if(rc) return rc; rc = rasqal_init_result_formats(world); if(rc) return rc; return 0; }
int main(int argc, char *argv[]) { raptor_world *world; const char *program = raptor_basename(argv[0]); const char *items[8] = { "ron", "amy", "jen", "bij", "jib", "daj", "jim", NULL }; raptor_id_set *set; raptor_uri *base_uri; int i = 0; world = raptor_new_world(); if(!world || raptor_world_open(world)) exit(1); base_uri = raptor_new_uri(world, (const unsigned char*)"http://example.org/base#"); #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Creating set\n", program); #endif set = raptor_new_id_set(world); if(!set) { fprintf(stderr, "%s: Failed to create set\n", program); exit(1); } for(i = 0; items[i]; i++) { size_t len = strlen(items[i]); int rc; #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Adding set item '%s'\n", program, items[i]); #endif rc = raptor_id_set_add(set, base_uri, (const unsigned char*)items[i], len); if(rc) { fprintf(stderr, "%s: Adding set item %d '%s' failed, returning error %d\n", program, i, items[i], rc); exit(1); } } for(i = 0; items[i]; i++) { size_t len = strlen(items[i]); int rc; #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Adding duplicate set item '%s'\n", program, items[i]); #endif rc = raptor_id_set_add(set, base_uri, (const unsigned char*)items[i], len); if(rc <= 0) { fprintf(stderr, "%s: Adding duplicate set item %d '%s' succeeded, should have failed, returning error %d\n", program, i, items[i], rc); exit(1); } } #if RAPTOR_DEBUG > 1 raptor_id_set_stats_print(set, stderr); #endif #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Freeing set\n", program); #endif raptor_free_id_set(set); raptor_free_uri(base_uri); raptor_free_world(world); /* keep gcc -Wall happy */ return(0); }
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; }
int main(int argc, char *argv[]) { raptor_world *world; FILE *handle = NULL; int failures = 0; program = raptor_basename(argv[0]); world = raptor_new_world(); if(!world || raptor_world_open(world)) exit(1); /* Write tests */ failures+= test_write_to_filename(world, (const char*)OUT_FILENAME, TEST_STRING, TEST_STRING_LEN, (int)OUT_BYTES_COUNT); handle = fopen((const char*)OUT_FILENAME, "wb"); if(!handle) { fprintf(stderr, "%s: Failed to create write file handle to file %s\n", program, OUT_FILENAME); failures++; } else { failures+= test_write_to_file_handle(world, handle, TEST_STRING, TEST_STRING_LEN, (int)OUT_BYTES_COUNT); fclose(handle); remove(OUT_FILENAME); } failures+= test_write_to_string(world, TEST_STRING, TEST_STRING_LEN, (int)OUT_BYTES_COUNT); failures+= test_write_to_sink(world, TEST_STRING, TEST_STRING_LEN, (int)OUT_BYTES_COUNT); remove(OUT_FILENAME); /* Read tests */ handle = fopen((const char*)IN_FILENAME, "wb"); if(!handle) { fprintf(stderr, "%s: Failed to create write handle to file %s\n", program, IN_FILENAME); failures++; } else { fwrite(TEST_STRING, 1, TEST_STRING_LEN, handle); fclose(handle); failures+= test_read_from_filename(world, (const char*)IN_FILENAME, TEST_STRING, TEST_STRING_LEN, TEST_STRING_LEN, 0); handle = fopen((const char*)IN_FILENAME, "rb"); if(!handle) { fprintf(stderr, "%s: Failed to create read file handle to file %s\n", program, IN_FILENAME); failures++; } else { failures+= test_read_from_file_handle(world, handle, TEST_STRING, TEST_STRING_LEN, TEST_STRING_LEN, 0); fclose(handle); handle = NULL; } } failures+= test_read_from_string(world, TEST_STRING, TEST_STRING_LEN, TEST_STRING_LEN); failures+= test_read_from_sink(world, TEST_STRING_LEN, 0); remove(IN_FILENAME); raptor_free_world(world); return failures; }
int main(int argc, char *argv[]) { raptor_world *world; const char *program = raptor_basename(argv[0]); raptor_iostream *iostr; raptor_namespace_stack *nstack; raptor_namespace* ex_ns; raptor_turtle_writer* turtle_writer; raptor_uri* base_uri; raptor_qname* el_name; unsigned long count; raptor_uri* datatype; /* for raptor_new_iostream_to_string */ void *string = NULL; size_t string_len = 0; world = raptor_new_world(); if(!world || raptor_world_open(world)) exit(1); iostr = raptor_new_iostream_to_string(world, &string, &string_len, NULL); if(!iostr) { fprintf(stderr, "%s: Failed to create iostream to string\n", program); exit(1); } nstack = raptor_new_namespaces(world, 1); base_uri = raptor_new_uri(world, base_uri_string); turtle_writer = raptor_new_turtle_writer(world, base_uri, 1, nstack, iostr); if(!turtle_writer) { fprintf(stderr, "%s: Failed to create turtle_writer to iostream\n", program); exit(1); } raptor_turtle_writer_set_option(turtle_writer, RAPTOR_OPTION_WRITER_AUTO_INDENT, 1); ex_ns = raptor_new_namespace(nstack, (const unsigned char*)"ex", (const unsigned char*)"http://example.org/ns#", 0); raptor_turtle_writer_namespace_prefix(turtle_writer, ex_ns); raptor_turtle_writer_reference(turtle_writer, base_uri); raptor_turtle_writer_increase_indent(turtle_writer); raptor_turtle_writer_newline(turtle_writer); raptor_turtle_writer_raw(turtle_writer, (const unsigned char*)"ex:foo "); raptor_turtle_writer_quoted_counted_string(turtle_writer, longstr, strlen((const char*)longstr)); raptor_turtle_writer_raw_counted(turtle_writer, (const unsigned char*)" ;", 2); raptor_turtle_writer_newline(turtle_writer); el_name = raptor_new_qname_from_namespace_local_name(world, ex_ns, (const unsigned char*)"bar", NULL); raptor_turtle_writer_qname(turtle_writer, el_name); raptor_free_qname(el_name); raptor_turtle_writer_raw_counted(turtle_writer, (const unsigned char*)" ", 1); datatype = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#decimal"); raptor_turtle_writer_literal(turtle_writer, nstack, (const unsigned char*)"10.0", NULL, datatype); raptor_free_uri(datatype); raptor_turtle_writer_newline(turtle_writer); raptor_turtle_writer_decrease_indent(turtle_writer); raptor_turtle_writer_raw_counted(turtle_writer, (const unsigned char*)".", 1); raptor_turtle_writer_newline(turtle_writer); raptor_free_turtle_writer(turtle_writer); raptor_free_namespace(ex_ns); raptor_free_namespaces(nstack); raptor_free_uri(base_uri); count = raptor_iostream_tell(iostr); #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Freeing iostream\n", program); #endif raptor_free_iostream(iostr); if(count != OUT_BYTES_COUNT) { fprintf(stderr, "%s: I/O stream wrote %d bytes, expected %d\n", program, (int)count, (int)OUT_BYTES_COUNT); fputs("[[", stderr); (void)fwrite(string, 1, string_len, stderr); fputs("]]\n", stderr); return 1; } if(!string) { fprintf(stderr, "%s: I/O stream failed to create a string\n", program); return 1; } string_len = strlen((const char*)string); if(string_len != count) { fprintf(stderr, "%s: I/O stream created a string length %d, expected %d\n", program, (int)string_len, (int)count); return 1; } #if RAPTOR_DEBUG > 1 fprintf(stderr, "%s: Made Turtle string of %d bytes\n", program, (int)string_len); fputs("[[", stderr); (void)fwrite(string, 1, string_len, stderr); fputs("]]\n", stderr); #endif raptor_free_memory(string); raptor_free_world(world); /* keep gcc -Wall happy */ return(0); }