Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
189 lines (139 sloc) 5.33 KB

RDF.rb: Linked Data for Ruby

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


  • 100% pure Ruby with minimal dependencies and no bloat.
  • 100% free and unencumbered public domain software.
  • Provides a clean, well-designed RDF object model and related APIs.
  • Supports parsing and serializing N-Triples out of the box, with more serialization format support available through add-on plugins.
  • Plays nice with others: entirely contained in the RDF module, and does not modify any of Ruby's core classes or standard library.
  • Based entirely on Ruby's autoloading, meaning that you can generally make use of any one part of the library without needing to load up the rest.
  • Compatible with Ruby 1.8.x, Ruby 1.9.x, and JRuby (tested with JRuby 1.4).


require 'rdf'

Creating an RDF statement

s = RDF::URI("")
p = RDF::DC.creator
o = RDF::URI("")

stmt = RDF::Statement(s, p, o)

Using pre-defined RDF vocabularies

include RDF

DC.title      #=> RDF::URI("")
FOAF.knows    #=> RDF::URI("")
RDF.type      #=> RDF::URI("")
RDFS.seeAlso  #=> RDF::URI("")
RSS.title     #=> RDF::URI("")
OWL.sameAs    #=> RDF::URI("")
XSD.dateTime  #=> RDF::URI("")

Using ad-hoc RDF vocabularies

foaf ="")
foaf.knows    #=> RDF::URI("")
foaf[:name]   #=> RDF::URI("")
foaf['mbox']  #=> RDF::URI("")

Reading N-Triples data"spec/data/test.nt") do |reader|
  reader.each_statement do |statement|
    puts statement.inspect


RDF Object Model

  • {RDF::Value}
    • {RDF::Literal}
    • {RDF::Resource}
      • {RDF::Node}
      • {RDF::URI}
      • {RDF::Graph}
    • {RDF::Statement}

RDF Serialization

  • {RDF::Format}
  • {RDF::Reader}
  • {RDF::Writer}

RDF Serialization Formats

RDF Storage

RDF Querying

  • {RDF::Query}
    • {RDF::Query::Pattern}
    • {RDF::Query::Solution}
    • {RDF::Query::Variable}

RDF Vocabularies

  • {RDF::CC} - Creative Commons (CC)
  • {RDF::DC} - Dublin Core (DC)
  • {RDF::DOAP} - Description of a Project (DOAP)
  • {RDF::EXIF} - Exchangeable Image File Format (EXIF)
  • {RDF::FOAF} - Friend of a Friend (FOAF)
  • {RDF::HTTP} - Hypertext Transfer Protocol (HTTP)
  • {RDF::OWL} - Web Ontology Language (OWL)
  • {RDF::RDFS} - RDF Schema (RDFS)
  • {RDF::RSS} - RDF Site Summary (RSS)
  • {RDF::SIOC} - Semantically-Interlinked Online Communities (SIOC)
  • {RDF::SKOS} - Simple Knowledge Organization System (SKOS)
  • {RDF::WOT} - Web of Trust (WOT)
  • {RDF::XHTML} - Extensible HyperText Markup Language (XHTML)
  • {RDF::XSD} - XML Schema (XSD)



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

% [sudo] gem install rdf


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

% git clone git://

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

% wget


See Also



RDF.rb is free and unencumbered public domain software. For more information, see or the accompanying UNLICENSE file.

Jump to Line
Something went wrong with that request. Please try again.