Question

J'essaie un moment pour analyser certains fichiers RDF / XML avec la bibliothèque Raptor2 C. Cet exemple de code va lire un fichier Ntriples et l'imprimera, mais pas rdf / xml.

de Tutoriel de raptor :

#include <stdio.h>
#include <raptor2.h>

/* rdfcat.c: parse any RDF syntax and serialize to RDF/XML-Abbrev */

static raptor_serializer* rdf_serializer;

static void
serialize_triple(void* user_data, raptor_statement* triple) 
{
  raptor_serializer_serialize_statement(rdf_serializer, triple);
}

static void
declare_namespace(void* user_data, raptor_namespace *nspace)
{
  raptor_serializer_set_namespace_from_namespace(rdf_serializer, nspace);
}

int
main(int argc, char *argv[])
{
  raptor_world *world = NULL;
  raptor_parser* rdf_parser = NULL;
  unsigned char *uri_string;
  raptor_uri *uri, *base_uri;

  world = raptor_new_world();

  uri_string = raptor_uri_filename_to_uri_string(argv[1]);
  uri = raptor_new_uri(world, uri_string);
  base_uri = raptor_uri_copy(uri);

  /* Ask raptor to work out which parser to use */
  rdf_parser = raptor_new_parser(world, "guess");
  raptor_parser_set_statement_handler(rdf_parser, NULL, serialize_triple);
  raptor_parser_set_namespace_handler(rdf_parser, NULL, declare_namespace);

  rdf_serializer = raptor_new_serializer(world, "rdfxml-abbrev");

  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);
  raptor_free_memory(uri_string);

  raptor_free_world(world);

  return 0;
}

Voici un exemple de Wikipedia du même RDF écrit dans les deux formats . La première version imprime (avec quelques erreurs de couple, mais je ne pense pas que ce soit important), mais le second ne le fait pas.

Ntriples:

<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Document> .
<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://purl.org/dc/terms/title> "N-Triples"@en-US .
<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://xmlns.com/foaf/0.1/maker> _:art .
<http://www.w3.org/2001/sw/RDFCore/ntriples/> <http://xmlns.com/foaf/0.1/maker> _:dave .

_:art <http://www.w3.org/1999/02/22-rdf-syntax-ns#> <http://xmlns.com/foaf/0.1/Person> .
_:art <http://xmlns.com/foaf/0.1/name> "Art Barstow".

_:dave <http://www.w3.org/1999/02/22-rdf-syntax-ns#> <http://xmlns.com/foaf/0.1/Person> .
_:dave <http://xmlns.com/foaf/0.1/name> "Dave Beckett".

rdfxml:

<rdf:RDF 
    xmlns="http://xmlns.com/foaf/0.1/"
    xmlns:dc="http://purl.org/dc/terms/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

    <Document rdf:about="http://www.w3.org/2001/sw/RDFCore/ntriples/">
        <dc:title xml:lang="en-US">N-Triples</dc:title>
        <maker>
            <Person rdf:nodeID="art">
                <name>Art Barstow</name>
            </Person>
        </maker>
        <maker>
            <Person rdf:nodeID="dave">
                <name>Dave Beckett</name>
            </Person>
        </maker>
    </Document>
</rdf:RDF>

Des idées pourquoi? Merci!

EDIT: Le RDFXML ONE doit être valide car il passe le Validator W3C RDF . < / p>

Edit: Définit explicitement l'analyseur sur "rdfxml" ne vous aide pas. En fait, je viens de découvrir l'option de suppose de cet exemple et était excitée car avant que je vérifiais manuellement l'extension et l'appelant avec "ntriples" ou "rdfxml".

Était-ce utile?

La solution

It's still just guessing what the input format is - the parser is "guess":

  /* Ask raptor to work out which parser to use */

Guesses can be wrong. Set the parser explicitly to "ntriples" or "rdfxml" and it won't guess, it'll parse exactly what you give it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top