Project

turtle

0.0
No commit activity in last 3 years
No release in over 3 years
A Ruby DSL for generating RDF in the Turtle format
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

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 .