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_triple(void* user_data,
                const char* subject, int subject_type,
                const char* predicate_nspace, const char* predicate_name,
                const char *object, int object_type,
                const char *datatype_uri)
{
  raptor_serializer* serializer = (raptor_serializer*)user_data;
  raptor_statement s; /* static */
  raptor_uri* predicate_ns_uri;
  raptor_uri* predicate_uri;
  
  raptor_statement_init(&s, rworld);
  
  if(subject_type == FLICKCURL_TERM_TYPE_RESOURCE)
    s.subject = raptor_new_term_from_uri_string(rworld, (const unsigned char*)subject);
  else /* blank node */
    s.subject = raptor_new_term_from_blank(rworld, (const unsigned char*)subject);

  predicate_ns_uri = raptor_new_uri(rworld, (const unsigned char*)predicate_nspace);
  predicate_uri = raptor_new_uri_from_uri_local_name(rworld, predicate_ns_uri,
                                                     (const unsigned char*)predicate_name);
  s.predicate = raptor_new_term_from_uri(rworld, predicate_uri);
  raptor_free_uri(predicate_uri);
  raptor_free_uri(predicate_ns_uri);

  if(object_type == FLICKCURL_TERM_TYPE_RESOURCE)
    s.object = (void*)raptor_new_term_from_uri_string(rworld, (const unsigned char*)object);
  else if(object_type == FLICKCURL_TERM_TYPE_BLANK)
    s.object = raptor_new_term_from_blank(rworld, (const unsigned char*)subject);
  else {
    /* literal */
    raptor_uri* raptor_datatype_uri = NULL;

    if(datatype_uri)
      raptor_datatype_uri = raptor_new_uri(rworld, (const unsigned char*)datatype_uri);

    s.object = raptor_new_term_from_literal(rworld, (const unsigned char*)object, raptor_datatype_uri, NULL /* language */);

    raptor_free_uri(raptor_datatype_uri);
  }

  raptor_serializer_serialize_statement(serializer, &s);

raptor_statement_clear(&s);

}
Exemplo n.º 4
0
static void
to_ntriples_write_triple(void* user_data, raptor_statement* triple)
{
  raptor_serializer_serialize_statement(rdf_serializer, triple);
}