int main(int argc, char *argv[]) { fsp_link *link; fs_query_state *qs; fs_query *qr; raptor_uri *bu; int i; #ifdef LINUX mtrace(); #endif link = fsp_open_link("ukgov_finances_cra", NULL, FS_OPEN_HINT_RW); raptor_init(); fs_hash_init(fsp_hash_type(link)); bu = raptor_new_uri((unsigned char *)"local:"); fsp_no_op(link, 0); qs = fs_query_init(link); for (i=0;i<atoi(argv[1]);i++) { //printf("--------- %d ----------\n", i); qr = fs_query_execute(qs, link, bu, QUERY, 0, 3, 0); fs_query_free(qr); fs_query_cache_flush(qs, 0); } fs_query_fini(qs); raptor_free_uri(bu); raptor_finish(); fsp_close_link(link); #ifdef LINUX muntrace(); #endif }
int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s [--dump | --header] <rhash-file>\n", argv[0]); return 1; } fs_hash_init(FS_HASH_UMAC); int verbosity = 1; for (int i=1; i<argc; i++) { if (!strcmp(argv[i], "--dump")) { verbosity = 2; } else if (!strcmp(argv[i], "--header")) { verbosity = 0; } else { fs_rhash *rh = fs_rhash_open_filename(argv[i], 0); if (!rh) { printf("couldn't open hash\n"); return 1; } fs_rhash_print(rh, stdout, verbosity); fs_rhash_close(rh); } } return 0; }
int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "%s revision %s\n", argv[0], FS_BACKEND_VER); fprintf(stderr, "Usage: %s <uri> | \"literal\"\n", argv[0]); exit(1); } char *string = argv[1]; char lex[128], lang[128], type[128], uri[128]; fs_rid rid; #ifdef FS_MD5 fs_hash_init(FS_HASH_MD5); #endif #ifdef FS_CRC64 fs_hash_init(FS_HASH_CRC64); #endif #ifdef FS_UMAC fs_hash_init(FS_HASH_UMAC); #endif if (sscanf(string, "\"%127[^\"]\"@%127s", lex, lang) == 2) { rid = fs_hash_literal(lex,fs_hash_literal(lang, 0)); } else if (sscanf(string, "\"%127[^\"]\"^^%127s", lex, type) == 2) { rid = fs_hash_literal(lex,fs_hash_uri(type)); } else if (sscanf(string, "\"%127[^\"]\"", lex) == 1) { rid = fs_hash_literal(lex, 0); } else if (sscanf(string, "<%127[^>]>", uri) == 1) { rid = fs_hash_uri(uri); } else { fprintf(stderr, "Couldn't recognise a URI or literal in string '%s'\n", string); exit(1); } printf("%016llX\n", rid); }
//----------------------------------------------------------------------------------- // Function : fs_random_32 // Description : generates a 32 bit random number value // Arguments : none // : // return : random number generated value // notes : //----------------------------------------------------------------------------------- uint32_t fs_random_32() { uint32_t i; struct fs_hash_context fsDEsH; fs_hash_init(&fsDEsH); //uint32_t i; fs_hash_step(fsDEsRandom_state, &fsDEsH); fs_hash_step(time(NULL)+clock(), &fsDEsH); for(i=0;i<8; i++) fs_hash_step((i<<20)+fsDEsRandom_state, &fsDEsH); fsDEsRandom_state=fsDEsH.hash[0]; fs_hash_step(fsDEsRandom_state, &fsDEsH); return fsDEsH.hash[0]^fsDEsH.hash[1]; }
//----------------------------------------------------------------------------------- // Function : fs_random_64 // Description : generates a 64 bit random number value // Arguments : none // : // return : random number generated value // notes : //----------------------------------------------------------------------------------- uint64_t fs_random_64() { uint64_t tmp; uint32_t i; struct fs_hash_context fsDEsH; fs_hash_init(&fsDEsH); //uint32_t i; fs_hash_step(fsDEsRandom_state, &fsDEsH); fs_hash_step(time(NULL)+clock(), &fsDEsH); for(i=1;i<9; i++) fs_hash_step((i<<20)+fsDEsRandom_state, &fsDEsH); fsDEsRandom_state=fsDEsH.hash[0]; fs_hash_step(fsDEsRandom_state, &fsDEsH); tmp=fsDEsH.hash[0]; tmp=tmp<<32; tmp+=fsDEsH.hash[1]; return tmp; }
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[]) { 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; }
xmlChar *get_uri(fsp_link *link, fs_rid rid) { if (cache[rid & CACHE_MASK].rid == rid) { return (xmlChar *) cache[rid & CACHE_MASK].lex; } fs_rid_vector onerid = { .length = 1, .size = 1, .data = &rid }; fs_resource resource; fsp_resolve(link, FS_RID_SEGMENT(rid, segments), &onerid, &resource); return (xmlChar *) resource.lex; } xmlChar *get_attr(fsp_link *link, fs_rid rid) { if (attr_cache[rid & CACHE_MASK].rid == rid) { return (xmlChar *) attr_cache[rid & CACHE_MASK].lex; } fs_rid_vector onerid = { .length = 1, .size = 1, .data = &rid }; fs_resource resource; fsp_resolve(link, FS_RID_SEGMENT(rid, segments), &onerid, &resource); memcpy(&attr_cache[rid & ATTR_CACHE_MASK], &resource, sizeof(fs_resource)); return (xmlChar *) resource.lex; } xmlChar *get_literal(fsp_link *link, fs_rid rid, fs_rid *attr) { if (cache[rid & CACHE_MASK].rid == rid) { *attr = cache[rid & CACHE_MASK].attr; return (xmlChar *) cache[rid & CACHE_MASK].lex; } fs_rid_vector onerid = { .length = 1, .size = 1, .data = &rid }; fs_resource resource; fsp_resolve(link, FS_RID_SEGMENT(rid, segments), &onerid, &resource); *attr = resource.attr; return (xmlChar *) resource.lex; } void resolve_triples(fsp_link *link, fs_rid_vector **rids) { int quads = rids[0]->length; fs_rid_vector *todo[segments]; fs_segment segment; for (segment = 0; segment < segments; ++segment) { todo[segment] = fs_rid_vector_new(0); } for (int c = 0; c < 3; ++c) { for (int k = 0; k < quads; ++k) { const fs_rid rid = rids[c]->data[k]; if (FS_IS_BNODE(rid) || cache[rid & CACHE_MASK].rid == rid) continue; fs_rid_vector_append(todo[FS_RID_SEGMENT(rid, segments)], rid); cache[rid & CACHE_MASK].rid = rid; /* well, it will be soon */ } } int length[segments]; fs_resource *resources[segments]; for (segment = 0; segment < segments; ++segment) { length[segment] = todo[segment]->length; resources[segment] = calloc(length[segment], sizeof(fs_resource)); } fsp_resolve_all(link, todo, resources); for (segment = 0; segment < segments; ++segment) { fs_resource *res = resources[segment]; for (int k = 0; k < length[segment]; ++k) { free(cache[res[k].rid & CACHE_MASK].lex); memcpy(&cache[res[k].rid & CACHE_MASK], &res[k], sizeof(fs_resource)); } fs_rid_vector_free(todo[segment]); free(resources[segment]); } } void dump_model(fsp_link *link, fs_rid model, xmlTextWriterPtr xml) { fs_rid_vector none = { .length = 0, .size = 0, .data = 0 }; fs_rid_vector one = { .length = 1, .size = 1, .data = &model }; fs_rid_vector **results; double then; /* for time keeping */ then = fs_time(); fsp_bind_first_all(link, BIND_SPO, &one, &none, &none, &none, &results, QUAD_LIMIT); time_bind_first += (fs_time() - then); while (results != NULL) { long length = results[0]->length; if (length == 0) break; then = fs_time(); resolve_triples(link, results); time_resolving += (fs_time() - then); then = fs_time(); for (int k = 0; k < length; ++k) { xmlTextWriterStartElement(xml, (xmlChar *) "triple"); for (int r = 0; r < 3; ++r) { fs_rid rid = results[r]->data[k]; if (FS_IS_BNODE(rid)) { unsigned long long node = FS_BNODE_NUM(rid); xmlTextWriterWriteFormatElement(xml, (xmlChar *) "id", "%llu", node); } else if (FS_IS_URI(rid)) { xmlChar *uri = get_uri(link, rid); xmlTextWriterWriteElement(xml, (xmlChar *) "uri", uri); } else if (FS_IS_LITERAL(rid)) { fs_rid attr; xmlChar *lex = get_literal(link, rid, &attr); if (attr == fs_c.empty) { xmlTextWriterWriteElement(xml, (xmlChar *) "plainLiteral", lex); } else if (FS_IS_URI(attr)) { xmlChar *type = get_uri(link, attr); xmlTextWriterStartElement(xml, (xmlChar *) "typedLiteral"); xmlTextWriterWriteString(xml, (xmlChar *) lex); xmlTextWriterWriteAttribute(xml, (xmlChar *) "datatype", type); xmlTextWriterEndElement(xml); } else if (FS_IS_LITERAL(attr)) { xmlChar *lang = get_attr(link, attr); xmlTextWriterStartElement(xml, (xmlChar *) "plainLiteral"); xmlTextWriterWriteAttribute(xml, (xmlChar *) "xml:lang", lang); xmlTextWriterWriteString(xml, (xmlChar *) lex); xmlTextWriterEndElement(xml); } } } xmlTextWriterEndElement(xml); xmlTextWriterWriteString(xml, (xmlChar *) "\n"); } time_write_out += (fs_time() - then); fs_rid_vector_free(results[0]); fs_rid_vector_free(results[1]); fs_rid_vector_free(results[2]); free(results); then = fs_time(); fsp_bind_next_all(link, BIND_SPO, &results, QUAD_LIMIT); time_bind_next += (fs_time() - then); } fsp_bind_done_all(link); } void dump_trix(fsp_link *link, xmlTextWriterPtr xml) { fs_rid_vector **models; fs_rid_vector none = { .length = 0, .size = 0, .data = 0 }; fsp_bind_all(link, FS_BIND_DISTINCT | FS_BIND_MODEL | FS_BIND_BY_SUBJECT, &none, &none, &none, &none, &models); fs_rid_vector_sort(models[0]); fs_rid_vector_uniq(models[0], 1); long length = models[0]->length; for (int k = 0; k < length; ++k) { fs_rid model = models[0]->data[k]; xmlChar *model_uri = get_uri(link, model); xmlTextWriterStartElement(xml, (xmlChar *) "graph"); if (FS_IS_URI(model)) { xmlTextWriterWriteElement(xml, (xmlChar *) "uri", model_uri); } else { fs_error(LOG_WARNING, "model %lld is not a URI", model); } dump_model(link, model, xml); xmlTextWriterEndElement(xml); xmlTextWriterWriteString(xml, (xmlChar *) "\n"); printf("%5d/%ld: %4.5f %4.5f %4.5f %4.5f\n", k + 1, length, time_resolving, time_bind_first, time_bind_next, time_write_out); } } void dump_file(fsp_link *link, char *filename) { xmlTextWriterPtr xml = xmlNewTextWriterFilename(filename, TRUE); if (!xml) { fs_error(LOG_ERR, "Couldn't write output file, giving up"); exit(4); } xmlTextWriterStartDocument(xml, NULL, NULL, NULL); xmlTextWriterStartElement(xml, (xmlChar *) "TriX"); dump_trix(link, xml); xmlTextWriterEndDocument(xml); /* also closes TriX */ xmlFreeTextWriter(xml); } int main(int argc, char *argv[]) { char *password = fsp_argv_password(&argc, argv); if (argc != 3) { fprintf(stderr, "%s revision %s\n", argv[0], FS_FRONTEND_VER); fprintf(stderr, "Usage: %s <kbname> <uri>\n", argv[0]); exit(1); } fsp_link *link = fsp_open_link(argv[1], password, FS_OPEN_HINT_RO); if (!link) { fs_error (LOG_ERR, "couldn't connect to “%s”", argv[1]); exit(2); } fs_hash_init(fsp_hash_type(link)); segments = fsp_link_segments(link); dump_file(link, argv[2]); fsp_close_link(link); }
int main(int argc, char *argv[]) { char *format = "auto"; char *optstring = "m:M:f:"; int c, opt_index = 0; int files = 0; char *kb_name = NULL; char *model[argc], *uri[argc]; char *model_default = NULL; int help=0; static struct option long_options[] = { { "model", 1, 0, 'm' }, { "model-default", 1, 0, 'M' }, { "format", 1, 0, 'f' }, }; for (int i= 0; i < argc; ++i) { model[i] = NULL; } 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 == 'f') { format = optarg; } else { help = 1; fprintf(stderr, "Unknown parameter '%c' \n", c); fprintf(stderr, "Usage: %s <kbname> <rdf file/URI> ...\n", argv[0]); fprintf(stderr, " -m --model specify a model URI for the next RDF file\n"); fprintf(stderr, " -M --model-default specify a model URI for all RDF files\n"); fprintf(stderr, " -f --format specify an RDF syntax for the import\n"); exit(1); } } files = 0; for (int k = optind; k < argc; ++k) { if (!kb_name) { kb_name = argv[k]; } else { uri[files] = g_strdup(argv[k]); if (!model[files]) { if (!model_default) { model[files] = uri[files]; } else { model[files] = model_default; } } files++; } } if (help || !kb_name || files == 0) { help = 1; fprintf(stderr, "Usage: %s <kbname> <rdf file/URI> ...\n", argv[0]); fprintf(stderr, " -m --model specify a model URI for the next RDF file\n"); fprintf(stderr, " -M --model-default specify a model URI for all RDF files\n"); fprintf(stderr, " -f --format specify an RDF syntax for the import\n"); exit(1); } if (!g_thread_get_initialized()) g_thread_init(NULL); if (!fs_hash_uri) fs_hash_init(); //g_mem_set_vtable(glib_mem_profiler_table); //g_atexit(g_mem_profile); int res = do_import(kb_name,uri,model,format,files); #if 0 printf("press enter\n"); char foo; #endif exit(res); }
int main() { fs_hash_init(FS_HASH_UMAC); int passes = 0; int fails = 0; #if 1 #define DUMP(t) printf("%lld %s\n", fs_c.xsd_##t, #t); DUMP(double); DUMP(float); DUMP(decimal); DUMP(integer); DUMP(boolean); #endif #define TEST1(f, a, x) printf("[%s] ", fs_value_equal(f(NULL, a), x) ? "PASS" : "FAIL"); printf("%s(", #f); fs_value_print(a); printf(") = "); fs_value_print(f(NULL, a)); printf("\n"); if (!fs_value_equal(f(NULL, a), x)) { fails++; printf(" should have been "); fs_value_print(x); printf("\n"); } else { passes++; } #define TEST2(f, a, b, x) printf("[%s] ", fs_value_equal(f(NULL, a, b), x) ? "PASS" : "FAIL"); printf("%s(", #f); fs_value_print(a); printf(", "); fs_value_print(b); printf(") = "); fs_value_print(f(NULL, a, b)); printf("\n"); if (!fs_value_equal(f(NULL, a, b), x)) { fails++; printf(" should have been "); fs_value_print(x); printf("\n"); } else { passes++; } #define TEST3(f, a, b, c, x) printf("[%s] ", fs_value_equal(f(NULL, a, b, c), x) ? "PASS" : "FAIL"); printf("%s(", #f); fs_value_print(a); printf(", "); fs_value_print(b); printf(", "); fs_value_print(c); printf(") = "); fs_value_print(f(NULL, a, b, c)); printf("\n"); if (!fs_value_equal(f(NULL, a, b, c), x)) { fails++; printf(" should have been "); fs_value_print(x); printf("\n"); } else { passes++; } #define URI(x) fs_value_uri(x) #define RID(x) fs_value_rid(x) #define BND(x) fs_value_rid(0x8000000000000000LL | x) #define STR(x) fs_value_string(x) #define PLN(x) fs_value_plain(x) #define PLN_L(x, l) fs_value_plain_with_lang(x, l) #define DBL(x) fs_value_double(x) #define FLT(x) fs_value_float(x) #define DEC(x) fs_value_decimal(x) #define INT(x) fs_value_integer(x) #define BLN(x) fs_value_boolean(x) #define DAT(x) fs_value_datetime(x) #define DAT_S(x) fs_value_datetime_from_string(x) #define ERR() fs_value_error(FS_ERROR_INVALID_TYPE, NULL) #define BLK() fs_value_blank() TEST2(fn_numeric_add, BLK(), BLK(), ERR()); TEST2(fn_numeric_add, INT(1), URI("test:"), ERR()); TEST2(fn_numeric_add, STR("2"), INT(3), ERR()); TEST2(fn_numeric_add, INT(2), INT(3), INT(5)); TEST2(fn_numeric_add, DEC(2.5), DEC(-1), DEC(1.5)); TEST2(fn_numeric_add, DEC(-2.5), DEC(-1.5), DEC(-4)); TEST2(fn_numeric_subtract, INT(2), INT(3), INT(-1)); TEST2(fn_numeric_add, DBL(1), INT(2), DBL(3)); TEST2(fn_numeric_add, FLT(17000), INT(2), FLT(17002)); TEST2(fn_numeric_subtract, FLT(17000), INT(2), FLT(16998)); TEST2(fn_numeric_subtract, DEC(17000.5), INT(2), DEC(16998.5)); TEST2(fn_numeric_multiply, URI("http://example.com/"), INT(2), ERR()); TEST2(fn_numeric_multiply, DEC(3.5), INT(2), DEC(7)); TEST2(fn_numeric_multiply, DEC(35), DBL(-0.1), DBL(-3.5)); TEST2(fn_numeric_multiply, INT(1), FLT(23), FLT(23)); TEST2(fn_numeric_multiply, INT(10), INT(23), INT(230)); TEST2(fn_numeric_divide, INT(9), URI("http://example.org/"), ERR()); TEST2(fn_numeric_divide, INT(9), INT(2), DEC(4.5)); TEST2(fn_numeric_divide, INT(-9), INT(2), DEC(-4.5)); TEST2(fn_numeric_divide, INT(-9), INT(-2), DEC(4.5)); TEST2(fn_numeric_divide, DBL(90), FLT(10), DBL(9)); TEST2(fn_numeric_divide, FLT(99), FLT(-10), FLT(-9.9)); TEST2(fn_equal, URI("http://example.com/"), DEC(23), BLN(0)); TEST2(fn_equal, URI("http://example.com/"), URI("http://example.com/"), BLN(1)); TEST2(fn_equal, INT(23), DEC(23), BLN(1)); TEST2(fn_equal, fs_value_decimal_from_string("-23.0"), DEC(-23), BLN(1)); TEST2(fn_equal, STR("foo"), PLN("foo"), BLN(0)); TEST2(fn_equal, PLN("foo"), PLN("foo"), BLN(1)); TEST2(fn_equal, BLN(0), BLN(0), BLN(1)); TEST2(fn_greater_than, STR("BBB"), STR("AAA"), BLN(1)); TEST2(fn_greater_than, PLN("BBB"), PLN("AAA"), BLN(1)); TEST2(fn_greater_than, PLN("AAA"), PLN("BBB"), BLN(0)); TEST2(fn_less_than, PLN("BBB"), PLN("AAA"), BLN(0)); TEST2(fn_less_than, PLN("AAA"), PLN("BBB"), BLN(1)); TEST2(fn_less_than, INT(20), INT(15), BLN(0)); TEST2(fn_numeric_equal, INT(23), INT(23), BLN(1)); TEST2(fn_numeric_equal, INT(23), DEC(23), BLN(1)); TEST2(fn_numeric_equal, INT(23), FLT(23), BLN(1)); TEST2(fn_numeric_equal, INT(23), DBL(23), BLN(1)); TEST2(fn_numeric_equal, fn_minus(NULL, INT(23)), DBL(-23), BLN(1)); TEST2(fn_datetime_equal, DAT(1000), DAT(1000), BLN(1)); TEST2(fn_datetime_equal, DAT(time(NULL)), DAT(1000), BLN(0)); TEST2(fn_numeric_less_than, INT(0), DBL(23), BLN(1)); TEST2(fn_numeric_less_than, INT(23), DBL(23), BLN(0)); TEST2(fn_numeric_less_than, DBL(22.99999), INT(23), BLN(1)); TEST2(fn_numeric_less_than, DEC(-18.51), DEC(-18.5), BLN(1)); TEST2(fn_numeric_less_than, DBL(-18.51), DBL(-18.5), BLN(1)); TEST2(fn_numeric_less_than, DEC(-18.5), DEC(-18.51), BLN(0)); TEST2(fn_numeric_less_than, DBL(-18.5), DBL(-18.51), BLN(0)); TEST2(fn_numeric_greater_than, DEC(-121.98882), DEC(-121.739856), BLN(0)); TEST2(fn_numeric_greater_than, DEC(37.67473), DEC(37.677954), BLN(0)); TEST2(fn_numeric_greater_than, INT(0), DBL(23), BLN(0)); TEST2(fn_numeric_greater_than, INT(23), DBL(23), BLN(0)); TEST2(fn_numeric_greater_than, DBL(22.99999), INT(23), BLN(0)); TEST2(fn_numeric_greater_than, DEC(-18.51), DEC(-18.5), BLN(0)); TEST2(fn_numeric_greater_than, DBL(-18.51), DBL(-18.5), BLN(0)); TEST2(fn_numeric_greater_than, DEC(-18.5), DEC(-18.51), BLN(1)); TEST2(fn_numeric_greater_than, DBL(-18.5), DBL(-18.51), BLN(1)); TEST2(fn_logical_and, BLN(1), BLN(0), BLN(0)); TEST2(fn_logical_and, BLN(1), BLN(1), BLN(1)); TEST2(fn_logical_and, INT(0), INT(1), BLN(0)); TEST2(fn_logical_and, INT(1), INT(1), BLN(1)); TEST2(fn_logical_and, STR("true"), INT(1), BLN(1)); TEST2(fn_logical_and, STR("false"), INT(1), BLN(1)); TEST2(fn_logical_and, INT(1), ERR(), ERR()); TEST2(fn_logical_and, ERR(), INT(1), ERR()); TEST2(fn_logical_and, INT(0), ERR(), BLN(0)); TEST2(fn_logical_and, ERR(), INT(0), BLN(0)); TEST2(fn_logical_and, ERR(), ERR(), ERR()); TEST2(fn_logical_or, BLN(1), BLN(0), BLN(1)); TEST2(fn_logical_or, BLN(1), BLN(1), BLN(1)); TEST2(fn_logical_or, INT(0), INT(1), BLN(1)); TEST2(fn_logical_or, INT(1), INT(1), BLN(1)); TEST2(fn_logical_or, STR("true"), INT(32), BLN(1)); TEST2(fn_logical_or, STR("false"), INT(1), BLN(1)); TEST2(fn_logical_or, INT(1), ERR(), BLN(1)); TEST2(fn_logical_or, ERR(), INT(1), BLN(1)); TEST2(fn_logical_or, INT(0), ERR(), ERR()); TEST2(fn_logical_or, ERR(), INT(0), ERR()); TEST2(fn_logical_or, ERR(), ERR(), ERR()); TEST2(fn_compare, STR("AAA"), STR("BBB"), INT(-1)); TEST2(fn_compare, STR("BBB"), STR("BBB"), INT(0)); TEST2(fn_compare, STR("BBB"), STR("AAA"), INT(1)); TEST2(fn_compare, PLN("BBB"), PLN("AAA"), INT(1)); TEST2(fn_compare, STR("BBB"), PLN("BBB"), ERR()); TEST2(fn_compare, STR("http://example.com/"), URI("http://example.com/"), ERR()); TEST2(fn_compare, URI("http://example.com/"), URI("http://example.com/"), ERR()); TEST2(fn_compare, INT(1), PLN("BBB"), ERR()); TEST3(fn_matches, PLN("foobar"), PLN("foo"), BLK(), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("^foo"), BLK(), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("bar$"), BLK(), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("BAR"), STR("i"), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("^FOOB[AO]R$"), STR("i"), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("^bar"), BLK(), BLN(0)); TEST3(fn_matches, PLN("foobar"), PLN("^foo$"), BLK(), BLN(0)); TEST3(fn_matches, PLN("foobar"), PLN("foo bar"), PLN("x"), BLN(1)); TEST3(fn_matches, INT(23), PLN("foo bar"), PLN("x"), ERR()); TEST3(fn_matches, PLN("foobar"), DAT(1000), PLN("x"), ERR()); TEST1(fn_bound, URI("http://example.com/"), BLN(1)); TEST1(fn_bound, STR("http"), BLN(1)); TEST1(fn_bound, PLN(""), BLN(1)); TEST1(fn_bound, BND(100), BLN(1)); TEST1(fn_bound, RID(FS_RID_NULL), BLN(0)); TEST1(fn_is_blank, URI("http://example.com/"), BLN(0)); TEST1(fn_is_blank, STR("http"), BLN(0)); TEST1(fn_is_blank, PLN(""), BLN(0)); TEST1(fn_is_blank, BND(100), BLN(1)); TEST1(fn_is_blank, RID(FS_RID_NULL), BLN(0)); TEST1(fn_is_iri, URI("http://example.com/"), BLN(1)); TEST1(fn_is_iri, STR("http"), BLN(0)); TEST1(fn_is_iri, PLN(""), BLN(0)); TEST1(fn_is_iri, BND(100), BLN(0)); TEST1(fn_is_iri, RID(FS_RID_NULL), BLN(0)); TEST1(fn_is_literal, URI("http://example.com/"), BLN(0)); TEST1(fn_is_literal, STR("http"), BLN(1)); TEST1(fn_is_literal, PLN(""), BLN(1)); TEST1(fn_is_literal, BND(100), BLN(0)); TEST1(fn_is_literal, RID(FS_RID_NULL), BLN(0)); TEST1(fn_str, URI("http://example.com/"), PLN("http://example.com/")); TEST1(fn_str, STR("http"), PLN("http")); TEST1(fn_str, PLN(""), PLN("")); TEST1(fn_str, BLN(1), PLN("true")); TEST1(fn_str, INT(1), PLN("1")); TEST1(fn_str, FLT(11.1), PLN("11.100000")); TEST1(fn_str, DBL(11.1), PLN("11.100000")); TEST1(fn_str, DEC(23), PLN("23.000000")); TEST1(fn_str, DAT(1000), PLN("1970-01-01T00:16:40")); TEST1(fn_str, BND(100), ERR()); TEST1(fn_str, RID(FS_RID_NULL), ERR()); TEST1(fn_lang, PLN("foo"), PLN("")); TEST1(fn_lang, STR("foo"), PLN("")); TEST1(fn_lang, PLN_L("foo", "en"), PLN("en")); TEST1(fn_lang, PLN_L("foo", ""), PLN("")); TEST1(fn_lang, BLN(1), PLN("")); TEST1(fn_lang, INT(1), PLN("")); TEST1(fn_lang, DEC(1.1), PLN("")); TEST1(fn_lang, FLT(1.1), PLN("")); TEST1(fn_lang, DBL(1.1), PLN("")); TEST1(fn_lang, URI("http://example.org/"), ERR()); TEST1(fn_datatype, PLN("foo"), ERR()); TEST1(fn_datatype, STR("foo"), URI(XSD_STRING)); TEST1(fn_datatype, PLN_L("foo", "en"), ERR()); TEST1(fn_datatype, PLN_L("foo", ""), ERR()); TEST1(fn_datatype, BLN(1), URI(XSD_BOOLEAN)); TEST1(fn_datatype, INT(1), URI(XSD_INTEGER)); TEST1(fn_datatype, DEC(1.1), URI(XSD_DECIMAL)); TEST1(fn_datatype, FLT(1.1), URI(XSD_FLOAT)); TEST1(fn_datatype, DBL(1.1), URI(XSD_DOUBLE)); TEST1(fn_datatype, DAT(1000), URI(XSD_DATETIME)); TEST1(fn_datatype, URI("http://example.org/"), ERR()); TEST2(fn_equal, DAT_S("1975-01-07"), DAT(158284800), BLN(1)); TEST2(fn_equal, DAT_S("1975-01-07T00:00:01"), DAT(158284801), BLN(1)); TEST2(fn_equal, DAT_S("1975-01-07T01:00:01+0000"), DAT(158288401), BLN(1)); TEST2(fn_equal, DAT_S("1975-01-07T01:00:01-0900"), DAT(158320801), BLN(1)); TEST2(fn_cast, DBL(2.1), URI(XSD_INTEGER), INT(2)); TEST2(fn_cast, PLN("2.23"), URI(XSD_DOUBLE), DBL(2.23)); TEST2(fn_cast, PLN_L("2.23", "en"), URI(XSD_DOUBLE), DBL(2.23)); TEST2(fn_cast, STR("2.23"), URI(XSD_DOUBLE), DBL(2.23)); TEST2(fn_cast, URI("http://example.com/"), URI(XSD_STRING), ERR()); TEST2(fn_cast, DAT(1000), URI(XSD_STRING), STR("1970-01-01T00:16:40")); TEST2(fn_cast, STR("1975-01-07T01:00:01-0900"), URI(XSD_DATETIME), DAT(158320801)); printf("\n=== pass %d, fail %d\n", passes, fails); if (fails) { return 1; } return 0; }