A Ruby DSL for generating RDF in the Turtle format
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
bin
examples
lib
spec
.gitignore
README.rdoc
turtle.gemspec

README.rdoc

turtle.rb

turtle.rb is a internal Ruby DSL for quickly generating RDF in the turtle format.

Examples

The following simple document

Turtle.build do

  prefix "http://kimdalsgaard.com/documents/"
  prefix :dc, "http://purl.org/dc/elements/1.1/"

  subject [_, "foo"], [:dc, "title"], "Foo"

end

will produce the following result

@prefix : <http://kimdalsgaard.com/documents/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
:foo dc:title "Foo" .

Nested Predicates

Turtle.build do

  prefix "http://kimdalsgaard.com/documents/"
  prefix :dc, "http://purl.org/dc/elements/1.1/"

  subject [_, "foo"] do
    predicate [:dc, "title"], "Foo"
    predicate [:dc, "creator"], "Kim Dalsgaard"
  end        

end

results in

@prefix : <http://kimdalsgaard.com/documents/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
:foo
  dc:title "Foo" ;
  dc:creator "Kim Dalsgaard" .

Nested Objects

Turtle.build do

  prefix :foaf, "http://xmlns.com/foaf/0.1/"

  subject ["http://dalsgaardkirk.com#kim"], [:foaf, "knows"]  do
    object ["http://dalsgaardkirk.com#pernille"]
    object ["http://dalsgaardkirk.com#sophus"]
  end

end

results in

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://dalsgaardkirk.com#kim> foaf:knows
    <http://dalsgaardkirk.com#pernille> ,
    <http://dalsgaardkirk.com#sophus> .

Blank Nodes

Turtle.build do

  prefix :foaf, "http://xmlns.com/foaf/0.1/"

  subject _("foo"), a, [:foaf, "Person"]       
  subject _, a, [:foaf, "Person"]       
  subject _, a, [:foaf, "Group"]
  subject :bar, a, [:foaf, "Group"]

end

results in

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:foo a foaf:Person .
_:b0 a foaf:Person .
_:b1 a foaf:Group .
_:bar a foaf:Group .