Skip to content

Instantly share code, notes, and snippets.

@bhuga
Created April 2, 2010 21:27
Show Gist options
  • Save bhuga/353733 to your computer and use it in GitHub Desktop.
Save bhuga/353733 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rdf'
require 'do_sqlite3'
require 'rdf/do'
$:.unshift '~/repos/RDFObjects/lib'
require 'rdf_objects'
rdfobject = RDFObject::Resource.new('http://example.org/1234')
rdfobject.assert('http://purl.org/dc/elements/1.1/creator', 'William Shakespeare')
rdfobject.assert("[foaf:name]", "William Shakespeare")
rdfobject.relate("[rdf:type]", "[foaf:Person]")
repo = RDF::DataObjects::Repository.new 'sqlite3:test.db'
repo.insert(*rdfobject)
puts repo.count # => 3
# meanwhile, in sqlite...
#ben:junk ben$ !sql
#sqlite3 test.db
#SQLite version 3.6.23
#Enter ".help" for instructions
#Enter SQL statements terminated with a ";"
#sqlite> .headers on
#sqlite> select * from quads;
#subject|predicate|object|context
#<http://example.org/1234>|<http://xmlns.com/foaf/0.1/name>|"William Shakespeare"|nil
#<http://example.org/1234>|<http://purl.org/dc/elements/1.1/creator>|"William Shakespeare"|nil
#<http://example.org/1234>|<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>|<http://xmlns.com/foaf/0.1/Person>|nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment