Exemplo n.º 1
0
int fs_metadata_flush(fs_metadata *m)
{
    raptor_serializer *ser = raptor_new_serializer(m->rw, "turtle");
    if (!ser) {
        fs_error(LOG_CRIT, "cannot create turtle serialiser for metadata");

        return 1;
    }
    raptor_serializer_start_to_filename(ser, m->uri+7);

    raptor_statement st;
    for (int e=0; e < m->length; e++) {
        st.subject = raptor_new_term_from_uri_string(m->rw, (unsigned char *)m->uri);
        st.predicate = raptor_new_term_from_uri_string(m->rw, (unsigned char *)m->entries[e].key);
        st.object = raptor_new_term_from_literal(m->rw,
            (unsigned char *)m->entries[e].val, NULL, NULL);
        raptor_serializer_serialize_statement(ser, &st);
        raptor_free_term(st.subject);
        raptor_free_term(st.predicate);
        raptor_free_term(st.object);
    }

    raptor_serializer_serialize_end(ser);
    raptor_free_serializer(ser);

    return 0;
}
Exemplo n.º 2
0
static int
print_graph_result(rasqal_query* rq,
                   rasqal_query_results *results,
                   raptor_world* raptor_world_ptr,
                   FILE* output,
                   const char* serializer_syntax_name, raptor_uri* base_uri,
                   int quiet)
{
    int triple_count = 0;
    rasqal_prefix* prefix;
    int i;
    raptor_serializer* serializer = NULL;

    if(!quiet)
        fprintf(stderr, "%s: Query has a graph result:\n", program);

    if(!raptor_world_is_serializer_name(raptor_world_ptr, serializer_syntax_name)) {
        fprintf(stderr,
                "%s: invalid query result serializer name `%s' for `" HELP_ARG(r, results) "'\n",
                program, serializer_syntax_name);
        return 1;
    }

    serializer = raptor_new_serializer(raptor_world_ptr,
                                       serializer_syntax_name);
    if(!serializer) {
        fprintf(stderr, "%s: Failed to create raptor serializer type %s\n",
                program, serializer_syntax_name);
        return(1);
    }

    /* Declare any query namespaces in the output serializer */
    for(i = 0; (prefix = rasqal_query_get_prefix(rq, i)); i++)
        raptor_serializer_set_namespace(serializer, prefix->uri, prefix->prefix);
    raptor_serializer_start_to_file_handle(serializer, base_uri, output);

    while(1) {
        raptor_statement *rs = rasqal_query_results_get_triple(results);
        if(!rs)
            break;

        raptor_serializer_serialize_statement(serializer, rs);
        triple_count++;

        if(rasqal_query_results_next_triple(results))
            break;
    }

    raptor_serializer_serialize_end(serializer);
    raptor_free_serializer(serializer);

    if(!quiet)
        fprintf(stderr, "%s: Total %d triples\n", program, triple_count);

    return 0;
}
Exemplo n.º 3
0
static void
ser_emit_finish(void* user_data)
{
  raptor_serializer* serializer = (raptor_serializer*)user_data;
  raptor_serializer_serialize_end(serializer);
}
Exemplo n.º 4
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;
}