RDF.rb: Linked Data for Ruby

This is a pure-Ruby library for working with Resource Description Framework (RDF) data.

Features

Tutorials

Examples

require 'rdf'

include RDF

Writing RDF data using the N-Triples format

require 'rdf/ntriples'

RDF::Writer.open("hello.nt") do |writer|
  writer << RDF::Graph.new do |graph|
    graph << [:hello, RDF::DC.title, "Hello, world!"]
  end
end

Reading RDF data in the N-Triples format

require 'rdf/ntriples'

RDF::Reader.open("http://rdf.rubyforge.org/doap.nt") do |reader|
  reader.each_statement do |statement|
    puts statement.inspect
  end
end

Querying RDF data using basic graph patterns (BGPs)

require 'rdf/ntriples'

graph = RDF::Graph.load("http://rdf.rubyforge.org/doap.nt")
query = RDF::Query.new({
  :person => {
    RDF.type  => FOAF.Person,
    FOAF.name => :name,
    FOAF.mbox => :email,
  }
})

query.execute(graph).each do |solution|
  puts "name=#{solution.name} email=#{solution.email}"
end

Using pre-defined RDF vocabularies

DC.title      #=> RDF::URI("http://purl.org/dc/terms/title")
FOAF.knows    #=> RDF::URI("http://xmlns.com/foaf/0.1/knows")
RDF.type      #=> RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
RDFS.seeAlso  #=> RDF::URI("http://www.w3.org/2000/01/rdf-schema#seeAlso")
RSS.title     #=> RDF::URI("http://purl.org/rss/1.0/title")
OWL.sameAs    #=> RDF::URI("http://www.w3.org/2002/07/owl#sameAs")
XSD.dateTime  #=> RDF::URI("http://www.w3.org/2001/XMLSchema#dateTime")

Using ad-hoc RDF vocabularies

foaf = RDF::Vocabulary.new("http://xmlns.com/foaf/0.1/")
foaf.knows    #=> RDF::URI("http://xmlns.com/foaf/0.1/knows")
foaf[:name]   #=> RDF::URI("http://xmlns.com/foaf/0.1/name")
foaf['mbox']  #=> RDF::URI("http://xmlns.com/foaf/0.1/mbox")

Documentation

http://rdf.rubyforge.org/

RDF Object Model

http://blog.datagraph.org/2010/03/rdf-for-ruby

RDF Serialization

http://blog.datagraph.org/2010/04/parsing-rdf-with-ruby

RDF Serialization Formats

RDF Storage

http://blog.datagraph.org/2010/04/rdf-repository-howto

RDF Querying

RDF Vocabularies

Dependencies

Installation

The recommended installation method is via RubyGems. To install the latest official release of RDF.rb, do:

% [sudo] gem install rdf             # Ruby 1.8.7+ or 1.9.x
% [sudo] gem install backports rdf   # Ruby 1.8.1+

Download

To get a local working copy of the development repository, do:

% git clone git://github.com/bendiken/rdf.git

Alternatively, download the latest development version as a tarball as follows:

% wget http://github.com/bendiken/rdf/tarball/master

Resources

Mailing List

Authors

Contributors

Contributing

License

This is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.