Skip to content

Instantly share code, notes, and snippets.

@gkellogg
Created April 6, 2011 18:37
Show Gist options
  • Save gkellogg/906236 to your computer and use it in GitHub Desktop.
Save gkellogg/906236 to your computer and use it in GitHub Desktop.
Original example
#!/usr/bin/env ruby
require 'rdf'
require 'rdf/n3'
doc = %q(
@prefix dms: <http://example.stanford.edu/ns/> .
@prefix ore: <http://www.openarchives.org/ore/terms/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix item: <http://example.stanford.edu/item/> .
@prefix doc001: <http://example.stanford.edu/item/> .
<http://dmstech.groups.stanford.edu/ccc001/manifest/NormalSequence> a dms:Sequence,
ore:Aggregation,
rdf:List;
ore:aggregates <http://example.stanford.edu/item/DOC001/1V>,
<http://example.stanford.edu/item/DOC001/1R>,
<http://example.stanford.edu/item/DOC001/2V>,
<http://example.stanford.edu/item/DOC001/2R>,
<http://example.stanford.edu/item/DOC001/bib>,
<http://example.stanford.edu/item/DOC001/bob>,
<http://example.stanford.edu/item/DOC001/fib>,
<http://example.stanford.edu/item/DOC001/fob>,
<http://example.stanford.edu/item/DOC001/iR>,
<http://example.stanford.edu/item/DOC001/iV>,
<http://example.stanford.edu/item/DOC001/iiR>,
<http://example.stanford.edu/item/DOC001/iiV>,
<http://example.stanford.edu/item/DOC001/iiiR>,
<http://example.stanford.edu/item/DOC001/iiiV>,
<http://example.stanford.edu/item/DOC001/ivR>,
<http://example.stanford.edu/item/DOC001/ivV>;
rdf:first <http://example.stanford.edu/item/DOC001/fob>;
rdf:rest ( <http://example.stanford.edu/item/DOC001/fib> <http://example.stanford.edu/item/DOC001/iR> <http://example.stanford.edu/item/DOC001/iV> <http://example.stanford.edu/item/DOC001/iiR> <http://example.stanford.edu/item/DOC001/iiV> <http://example.stanford.edu/item/DOC001/1R> <http://example.stanford.edu/item/DOC001/1V> <http://example.stanford.edu/item/DOC001/2R> <http://example.stanford.edu/item/DOC001/2V> <http://example.stanford.edu/item/DOC001/iiiR> <http://example.stanford.edu/item/DOC001/iiiV> <http://example.stanford.edu/item/DOC001/ivR> <http://example.stanford.edu/item/DOC001/ivV> <http://example.stanford.edu/item/DOC001/bib> <http://example.stanford.edu/item/DOC001/bob> ) .
)
r = RDF::N3::Reader.new(doc)
g = RDF::Graph.new << r
puts "NTriples Representation"
puts g.dump(:ntriples)
puts "Turtle/N3 Representation"
puts g.dump(:n3, :prefixes => r.prefixes, :base => "http://dmstech.groups.stanford.edu/ccc001/manifest/NormalSequence")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment