Skip to content

Instantly share code, notes, and snippets.

@bbartley
Last active September 19, 2015 18:13
Show Gist options
  • Save bbartley/786b4710af4b8d5db61f to your computer and use it in GitHub Desktop.
Save bbartley/786b4710af4b8d5db61f to your computer and use it in GitHub Desktop.
Reading an RDF/XML file with Raptor
#define SBOL_URI "http://sbolstandard.org/v2"
static void
print_triple(void* user_data, raptor_statement* triple)
{
raptor_statement_print_as_ntriples(triple, stdout);
fputc('\n', stdout);
}
void Document::read(std::string filename)
{
FILE* fh = fopen(filename.c_str(), "rb");
raptor_parser* rdf_parser = raptor_new_parser(this->rdf_graph, "rdfxml");
raptor_iostream* ios = raptor_new_iostream_to_file_handle(this->rdf_graph, fh);
raptor_parser_set_statement_handler(rdf_parser, NULL, print_triple);
raptor_uri *sbol_uri = raptor_new_uri(this->rdf_graph, (const unsigned char *)SBOL_URI "#");
raptor_parser_parse_iostream(rdf_parser, ios, sbol_uri);
raptor_free_parser(rdf_parser);
raptor_free_uri(sbol_uri);
}
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:sbol="http://sbolstandard.org/v2#">
<sbol:Identified rdf:about="http://examples.com/Identified/0">
<sbol:identity>http://examples.com/Identified/0</sbol:identity>
<sbol:persistentIdentity>http://sbolstandard.org/v2/Identified/example</sbol:persistentIdentity>
</sbol:Identified>
<sbol:ComponentDefinition rdf:about="http://examples.com/cdef_obj">
<dcterms:description></dcterms:description>
<dcterms:title></dcterms:title>
<sbol:displayId>cdef_obj</sbol:displayId>
<sbol:identity>http://examples.com/cdef_obj</sbol:identity>
<sbol:persistentIdentity>http://examples.com/cdef_obj</sbol:persistentIdentity>
<sbol:type>SO_0000001</sbol:type>
<rdf:type rdf:resource="http://sbolstandard.org/v2#sequenceAnnotation"/>
</sbol:ComponentDefinition>
<sbol:ComponentDefinition rdf:about="http://sbolstandard.org/v2/ComponentDefinition/example">
<dcterms:description></dcterms:description>
<dcterms:title></dcterms:title>
<sbol:displayId>example</sbol:displayId>
<sbol:identity>http://sbolstandard.org/v2/ComponentDefinition/example</sbol:identity>
<sbol:persistentIdentity>http://sbolstandard.org/v2/ComponentDefinition/example</sbol:persistentIdentity>
<sbol:sequenceAnnotation rdf:resource="http://sbolstandard.org/v2/SequenceAnnotation/example"/>
<sbol:type>SO_0000001</sbol:type>
<rdf:type rdf:resource="http://sbolstandard.org/v2#sequenceAnnotation"/>
</sbol:ComponentDefinition>
<sbol:SequenceAnnotation rdf:about="http://sbolstandard.org/v2/SequenceAnnotation/example">
<sbol:identity>http://sbolstandard.org/v2/SequenceAnnotation/example</sbol:identity>
<sbol:persistentIdentity>http://sbolstandard.org/v2/SequenceAnnotation/example</sbol:persistentIdentity>
<sbol:start>10</sbol:start>
</sbol:SequenceAnnotation>
</rdf:RDF>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment