static raptor_parser *rdf_parser_parser_create(const char *resource_uri,const char *format) { raptor_parser *parser = NULL; if (strcmp(format, "auto")) { parser = raptor_new_parser(parser_world,format); } else if (strstr(resource_uri, ".n3") || strstr(resource_uri, ".ttl")) { parser = raptor_new_parser(parser_world,"turtle"); } else if (strstr(resource_uri, ".nt")) { parser = raptor_new_parser(parser_world,"ntriples"); } else { parser = raptor_new_parser(parser_world,"rdfxml"); } return parser; }
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; }
void raptorNewParser(string prs) { string_copyto(Seqbyte_print_buf,Seqbyte_print_buf_length,prs); theParser = raptor_new_parser(Seqbyte_print_buf); // raptor_set_feature(theParser,RAPTOR_FEATURE_SCANNING,1); raptor_set_fatal_error_handler(theParser,NULL,raptorErrorHandler); raptor_set_error_handler(theParser,NULL,raptorMessageHandler); raptor_set_warning_handler(theParser,NULL,raptorMessageHandler); raptor_set_statement_handler(theParser,NULL,raptorStatementHandler); }
CRDFParser::CRDFParser() : CRaptorInit(), mpParser(NULL) { mpParser = raptor_new_parser("rdfxml"); raptor_set_fatal_error_handler(mpParser, NULL, &CRDFParser::FatalErrorHandler); raptor_set_error_handler(mpParser, NULL, &CRDFParser::ErrorHandler); raptor_set_warning_handler(mpParser, NULL, &CRDFParser::WarningHandler); }
int main (int argc, char *argv[]) { raptor_parser* rdf_parser; raptor_uri* uri; my_data* me; const char *program; int rc; program=argv[0]; if(argc != 2) { fprintf(stderr, "%s: USAGE [RDF-XML content URI]\n", program); exit(1); } raptor_init(); me=(my_data*)malloc(sizeof(my_data)); if(!me) { fprintf(stderr, "%s: Out of memory\n", program); exit(1); } me->stream=stderr; me->count=0; me->max=5; uri=raptor_new_uri((const unsigned char*)argv[1]); rdf_parser=raptor_new_parser("rdfxml"); me->parser=rdf_parser; raptor_set_statement_handler(rdf_parser, me, handle_statements); me->stopped=0; rc=raptor_parse_uri(rdf_parser, uri, NULL); fprintf(stderr, "%s: Parser returned status %d, stopped? %s\n", program, rc, (me->stopped ? "yes" : "no")); free(me); raptor_free_parser(rdf_parser); raptor_free_uri(uri); raptor_finish(); 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; }
/** * librdf_parser_raptor_init: * @parser: the parser * @context: context * * Initialise the raptor RDF parser. * * Return value: non 0 on failure **/ static int librdf_parser_raptor_init(librdf_parser *parser, void *context) { librdf_parser_raptor_context* pcontext=(librdf_parser_raptor_context*)context; pcontext->parser = parser; pcontext->parser_name=pcontext->parser->factory->name; /* legacy name - see librdf_parser_raptor_constructor * from when there was just one parser */ if(!strcmp(pcontext->parser_name, "raptor")) pcontext->parser_name = "rdfxml"; pcontext->rdf_parser = raptor_new_parser(parser->world->raptor_world_ptr, pcontext->parser_name); if(!pcontext->rdf_parser) return 1; librdf_raptor_reset_bnode_hash(parser->world); return 0; }
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_parser* rdf_parser=NULL; unsigned char *uri_string=NULL; int free_uri_string=0; unsigned char *base_uri_string=NULL; int rc; int scanning=0; const char *syntax_name="rdfxml"; int strict_mode=0; int usage=0; int help=0; raptor_uri *base_uri; raptor_uri *uri; char *p; char *filename=NULL; program=argv[0]; if((p=strrchr(program, '/'))) program=p+1; else if((p=strrchr(program, '\\'))) program=p+1; argv[0]=program; raptor_init(); 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 'a': break; case 'c': count=1; break; case 'h': help=1; break; case 'n': syntax_name="ntriples"; break; case 's': scanning=1; break; case 'q': quiet=1; break; case 'r': replace_newlines=1; break; case 'm': if(optarg) { if(!strcmp(optarg, "strict")) strict_mode=1; else if (!strcmp(optarg, "lax")) strict_mode=0; else { fprintf(stderr, "%s: invalid argument `%s' for `" HELP_ARG(m, mode) "'\n", program, optarg); fprintf(stderr, "Valid arguments are:\n - `lax'\n - `strict'\n"); usage=1; } } break; case 'o': if(optarg) { if(!strcmp(optarg, "simple")) output_format=OUTPUT_FORMAT_SIMPLE; else if (!strcmp(optarg, "ntriples")) output_format=OUTPUT_FORMAT_NTRIPLES; else { fprintf(stderr, "%s: invalid argument `%s' for `" HELP_ARG(o, output) "'\n", program, optarg); fprintf(stderr, "Valid arguments are:\n `simple' for a simple format (default)\n `ntriples' for N-Triples\n"); usage=1; } } break; case 'i': if(optarg) { if(raptor_syntax_name_check(optarg)) syntax_name=optarg; else { int i; fprintf(stderr, "%s: invalid argument `%s' for `" HELP_ARG(i, input) "'\n", program, optarg); fprintf(stderr, "Valid arguments are:\n"); for(i=0; 1; i++) { const char *help_name; const char *help_label; if(raptor_syntaxes_enumerate(i, &help_name, &help_label, NULL, NULL)) break; printf(" %-12s for %s\n", help_name, help_label); } usage=1; break; } } break; case 'w': ignore_warnings=1; break; case 'e': ignore_errors=1; break; case 'v': fputs(raptor_version_string, stdout); fputc('\n', stdout); exit(0); } } if(optind != argc-1 && optind != argc-2 && !help && !usage) { usage=2; /* Title and usage */ } if(usage) { if(usage>1) { fprintf(stderr, title_format_string, raptor_version_string); fputs(raptor_short_copyright_string, stderr); fputc('\n', stderr); } fprintf(stderr, "Try `%s " HELP_ARG(h, help) "' for more information.\n", program); exit(1); } if(help) { int i; printf("Usage: %s [OPTIONS] <source URI> [base URI]\n", program); printf(title_format_string, raptor_version_string); puts(raptor_short_copyright_string); puts("Parse RDF content at the source URI into RDF triples."); puts("\nMain options:"); puts(HELP_TEXT(h, "help ", "Print this help, then exit")); puts(HELP_TEXT(i, "input FORMAT ", "Set input format to one of:")); for(i=0; 1; i++) { const char *help_name; const char *help_label; if(raptor_syntaxes_enumerate(i, &help_name, &help_label, NULL, NULL)) break; printf(" %-12s %s", help_name, help_label); if(!i) puts(" (default)"); else putchar('\n'); } puts(HELP_TEXT(o, "output FORMAT ", "Set output format to one of:")); puts(" 'simple' A simple format (default)\n 'ntriples' N-Triples"); puts(HELP_TEXT(m, "mode MODE ", "Set parser mode - 'lax' (default) or 'strict'")); puts("\nAdditional options:"); puts(HELP_TEXT(c, "count ", "Count triples - no output")); puts(HELP_TEXT(e, "ignore-errors ", "Ignore error messages")); puts(HELP_TEXT(q, "quiet ", "No extra information messages")); puts(HELP_TEXT(r, "replace-newlines", "Replace newlines with spaces in literals")); puts(HELP_TEXT(s, "scan ", "Scan for <rdf:RDF> element in source")); puts(HELP_TEXT(w, "ignore-warnings ", "Ignore warning messages")); puts(HELP_TEXT(v, "version ", "Print the Raptor version")); puts("\nReport bugs to <*****@*****.**>."); puts("Raptor home page: http://www.redland.opensource.ac.uk/raptor/"); exit(0); } if(optind == argc-1) uri_string=(unsigned char*)argv[optind]; else { uri_string=(unsigned char*)argv[optind++]; base_uri_string=(unsigned char*)argv[optind]; } /* If uri_string is "path-to-file", turn it into a file: URI */ if(!strcmp((const char*)uri_string, "-")) { if(!base_uri_string) { fprintf(stderr, "%s: A Base URI is required when reading from standard input.\n", program); return(1); } uri_string=NULL; } else if(!access((const char*)uri_string, R_OK)) { filename=(char*)uri_string; uri_string=raptor_uri_filename_to_uri_string(filename); free_uri_string=1; } if(uri_string) { uri=raptor_new_uri(uri_string); if(!uri) { fprintf(stderr, "%s: Failed to create URI for %s\n", program, uri_string); return(1); } } else uri=NULL; /* stdin */ if(!base_uri_string) { base_uri=raptor_uri_copy(uri); } else { base_uri=raptor_new_uri(base_uri_string); if(!base_uri) { fprintf(stderr, "%s: Failed to create URI for %s\n", program, base_uri_string); return(1); } } rdf_parser=raptor_new_parser(syntax_name); if(!rdf_parser) { fprintf(stderr, "%s: Failed to create raptor parser type %s\n", program, syntax_name); return(1); } raptor_set_error_handler(rdf_parser, rdf_parser, rdfdump_error_handler); raptor_set_warning_handler(rdf_parser, rdf_parser, rdfdump_warning_handler); raptor_set_parser_strict(rdf_parser, strict_mode); if(scanning) raptor_set_feature(rdf_parser, RAPTOR_FEATURE_SCANNING, 1); if(!quiet) { if (filename) { if(base_uri_string) fprintf(stdout, "%s: Parsing file %s with base URI %s\n", program, filename, base_uri_string); else fprintf(stdout, "%s: Parsing file %s\n", program, filename); } else { if(base_uri_string) fprintf(stdout, "%s: Parsing URI %s with base URI %s\n", program, uri_string, base_uri_string); else fprintf(stdout, "%s: Parsing URI %s\n", program, uri_string); } } raptor_set_statement_handler(rdf_parser, NULL, print_statements); /* PARSE the URI as RDF/XML */ rc=0; if(!uri || filename) { if(raptor_parse_file(rdf_parser, uri, base_uri)) { fprintf(stderr, "%s: Failed to parse file %s %s content\n", program, filename, syntax_name); rc=1; } } else { if(raptor_parse_uri(rdf_parser, uri, base_uri)) { fprintf(stderr, "%s: Failed to parse URI %s %s content\n", program, uri_string, syntax_name); rc=1; } } raptor_free_parser(rdf_parser); if(!quiet) fprintf(stdout, "%s: Parsing returned %d statements\n", program, statement_count); raptor_free_uri(base_uri); if(uri) raptor_free_uri(uri); if(free_uri_string) free(uri_string); raptor_finish(); if(error_count && !ignore_errors) return 1; if(warning_count && !ignore_warnings) return 2; return(rc); }
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; }
static int raptor_guess_parse_chunk(raptor_parser* rdf_parser, const unsigned char *buffer, size_t len, int is_end) { raptor_guess_parser_context* guess_parser = (raptor_guess_parser_context*)rdf_parser->context; if(guess_parser->do_guess) { const unsigned char *identifier = NULL; const char *name; guess_parser->do_guess = 0; if(rdf_parser->base_uri) identifier = raptor_uri_as_string(rdf_parser->base_uri); name = raptor_world_guess_parser_name(rdf_parser->world, NULL, guess_parser->content_type, buffer, len, identifier); if(!name) { raptor_parser_error(rdf_parser, "Failed to guess parser from content type '%s'", guess_parser->content_type ? guess_parser->content_type : "(none)"); raptor_parser_parse_abort(rdf_parser); if(guess_parser->parser) { raptor_free_parser(guess_parser->parser); guess_parser->parser = NULL; } return 1; } else { #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 RAPTOR_DEBUG2("Guessed parser name '%s'\n", name); #endif /* If there is an existing guessed parser factory present and * it's different from the wanted parser, free it */ if(guess_parser->parser) { raptor_parser_factory* factory = raptor_world_get_parser_factory(rdf_parser->world, name); if(guess_parser->parser->factory != factory) { raptor_free_parser(guess_parser->parser); guess_parser->parser = NULL; } } if(!guess_parser->parser) { guess_parser->parser = raptor_new_parser(rdf_parser->world, name); if(!guess_parser->parser) return 1; } /* copy any user data to the grddl parser */ if(raptor_parser_copy_user_state(guess_parser->parser, rdf_parser)) return 1; if(raptor_parser_parse_start(guess_parser->parser, rdf_parser->base_uri)) return 1; } } /* now we can pass on calls to internal guess_parser */ return raptor_parser_parse_chunk(guess_parser->parser, buffer, len, is_end); }
/** * librdf_new_sql_config: * @world: librdf_world * @storage_name: SQL storage name * @layout: SQL schema variant * @config_dir: directory for configuration files * @predicate_uri_strings: configuration predicate URIs to look for * * Constructor - Make a new SQL configuration for a layout from a file * * Uses SQL storage name @storage_name and with database schema * @layout to give a configuration that will contain an array of * string values in the #librdf_sql_config field values array. * * Return value: configuration or NULL on failure **/ librdf_sql_config* librdf_new_sql_config(librdf_world* world, const char* storage_name, const char* layout, const char* config_dir, const char** predicate_uri_strings) { raptor_parser* rdf_parser=NULL; unsigned char *uri_string=NULL; raptor_uri *base_uri; raptor_uri *uri; librdf_sql_config* config; size_t len; int i; librdf_world_open(world); config=(librdf_sql_config*)LIBRDF_MALLOC(librdf_sql_config, sizeof(librdf_sql_config)); len=strlen(config_dir) + 1 + strlen(storage_name) + 4 + 1; if(layout) len+= strlen(layout) + 1; config->filename=(char*)LIBRDF_MALLOC(cstring, len); if(layout) sprintf(config->filename, "%s/%s-%s.ttl", config_dir, storage_name, layout); else sprintf(config->filename, "%s/%s.ttl", config_dir, storage_name); config->predicate_uri_strings=predicate_uri_strings; for(i=0; config->predicate_uri_strings[i]; i++) ; config->predicates_count=i; config->values=(char**)LIBRDF_CALLOC(cstring, sizeof(char*), config->predicates_count); LIBRDF_DEBUG4("Attempting to open %s layout %s storage config file %s\n", storage_name, (layout ? layout: "(default)"), config->filename); if(access((const char*)config->filename, R_OK)) { librdf_log(world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE, NULL, "Failed to open configuration file %s for storage %s layout %s - %s", config->filename, storage_name, (layout ? layout: "(default)"), strerror(errno)); librdf_free_sql_config(config); return NULL; } uri_string=raptor_uri_filename_to_uri_string(config->filename); uri=raptor_new_uri(uri_string); base_uri=raptor_uri_copy(uri); rdf_parser=raptor_new_parser("turtle"); raptor_set_statement_handler(rdf_parser, config, librdf_sql_config_store_triple); raptor_parse_file(rdf_parser, uri, base_uri); raptor_free_parser(rdf_parser); raptor_free_uri(base_uri); raptor_free_memory(uri_string); raptor_free_uri(uri); /* Check all values are given */ for(i=0; i < config->predicates_count; i++) { if(!config->values[i]) { librdf_log(world, 0, LIBRDF_LOG_ERROR, LIBRDF_FROM_STORAGE, NULL, "Configuration %s missing for storage %s", config->predicate_uri_strings[i], storage_name); librdf_free_sql_config(config); return NULL; } } return config; }
/* ------------------------------------------------------------ RDF_parseFile Parses a file of RDF. Parameters: file_name - the name of the file to parse rdf_model - a list of RDF resources to update Returs: a pointer to an annotation's list or NULL if an error occurs during the parsing. ------------------------------------------------------------*/ List *RDF_parseFile (char *file_name, List **rdf_model) { ParseContext ctx; raptor_parser *rdfxml_parser=NULL; raptor_uri *uri = NULL; char *full_file_name; char *tmp, *path; ctx.annot_list = &annot_list; ctx.rdf_model = rdf_model; annot_list = NULL; rdfxml_parser = raptor_new_parser ("rdfxml"); if (!rdfxml_parser) { AnnotList_free (annot_list); /* do not free rdf_model here; it may not have been empty to start */ annot_list = NULL; return NULL; } /* @@ this is what we should do eventually */ /* if (!IsW3Path (file_name)) full_file_name = LocalToWWW (file_name); else */ /* raptor doesn't grok file URIs under windows. The following is a patch so that we can use it */ full_file_name = (char *)TtaGetMemory (strlen (file_name) + sizeof ("file:")); sprintf (full_file_name, "file:%s", file_name); #ifdef _WX path = (char *)TtaConvertMbsToByte ((unsigned char *)file_name, TtaGetLocaleCharset ()); /* remember the base name for anoynmous subjects */ tmp = (char *)TtaConvertMbsToByte ((unsigned char *)full_file_name, TtaGetLocaleCharset ()); /* remember the base name for anoynmous subjects */ TtaFreeMemory (full_file_name); full_file_name = tmp; #else /* _WX */ path = file_name; #endif /* _WX */ /* remember the base name for anoynmous subjects */ ctx.base_uri = full_file_name; raptor_set_statement_handler(rdfxml_parser, (void *) &ctx, triple_handler); tmp = (char *) raptor_uri_filename_to_uri_string ((const char *) path); uri = raptor_new_uri ((const unsigned char *) tmp); #ifdef _WX TtaFreeMemory (path); #endif /* _WX */ TtaFreeMemory (tmp); if (raptor_parse_file (rdfxml_parser, uri, NULL)) { AnnotList_free (annot_list); /* do not free rdf_model here; it may not have been empty to start */ annot_list = NULL; TtaFreeMemory (full_file_name); raptor_free_parser (rdfxml_parser); raptor_free_uri (uri); return NULL; } TtaFreeMemory (full_file_name); raptor_free_parser (rdfxml_parser); raptor_free_uri (uri); Finish_FindAnnot(); /* output whatever we parsed */ #ifdef _RDFDEBUG AnnotList_print (annot_list); #endif /* _RDFDEBUG */ return (annot_list); }
int fs_import(fsp_link *link, const char *model_uri, char *resource_uri, const char *format, int verbosity, int dryrun, int has_o_index, FILE *msg, int *count) { raptor_parser *rdf_parser = NULL; raptor_uri ruri = NULL; int ret = 0; const int segments = fsp_link_segments(link); parse_data.ext_count = count; if (!inited) { inited = 1; parse_data.link = link; parse_data.segments = fsp_link_segments(link); for (int i=0; i<parse_data.segments; i++) { for (int j=0; j<RES_BUF_SIZE; j++) { lex_tmp[i][j] = malloc(RES_BUF_SIZE); } } memset(nodecache, 0, sizeof(nodecache)); parse_data.quad_fn = g_strdup(FS_TMP_PATH "/importXXXXXX"); parse_data.quad_fd = mkstemp(parse_data.quad_fn); if (parse_data.quad_fd < 0) { fs_error(LOG_ERR, "Cannot create tmp file “%s”", parse_data.quad_fn); return 1; } gettimeofday(&then_last, 0); } parse_data.verbosity = verbosity; parse_data.model = g_strdup(model_uri); parse_data.model_hash = fs_hash_uri(model_uri); parse_data.count_trip = 0; parse_data.last_count = 0; parse_data.dryrun = dryrun; parse_data.has_o_index = has_o_index; /* store the model uri */ buffer_res(link, segments, parse_data.model_hash, parse_data.model, FS_RID_NULL, dryrun); if (strcmp(format, "auto")) { rdf_parser = raptor_new_parser(format); } else if (strstr(resource_uri, ".n3") || strstr(resource_uri, ".ttl")) { rdf_parser = raptor_new_parser("turtle"); } else if (strstr(resource_uri, ".nt")) { rdf_parser = raptor_new_parser("ntriples"); } else { rdf_parser = raptor_new_parser("rdfxml"); } if (!rdf_parser) { fs_error(LOG_ERR, "failed to create RDF parser"); return 1; } raptor_set_statement_handler(rdf_parser, &parse_data, store_stmt); raptor_set_graph_handler(rdf_parser, &parse_data, graph_handler); ruri = raptor_new_uri((unsigned char *) resource_uri); parse_data.muri = raptor_new_uri((unsigned char *) model_uri); if (raptor_parse_uri(rdf_parser, ruri, parse_data.muri)) { fs_error(LOG_ERR, "failed to parse file “%s”", resource_uri); ret++; } if (verbosity) { printf("Pass 1, processed %d triples (%d)\n", total_triples_parsed, parse_data.count_trip); } raptor_free_parser(rdf_parser); raptor_free_uri(ruri); raptor_free_uri(parse_data.muri); g_free(parse_data.model); fs_hash_freshen(); /* blank nodes are unique per file */ return ret; }