Skip to content

ruby-rdf/ruby-rdf.github.com

Repository files navigation

Linked Data for Ruby

This is the home of Ruby RDF. This project collects numerous gems supporting Linked Data and Semantic Web programming in Ruby.

The primary gem is RDF.rb, which contains the core algorithms and classes used for doing basic programming of [RDF][], including support for Repositories, Graphs, Statements, URIs, Literals, and BNodes.

The Ruby RDF account also collects numerous gems used for reading and writing different RDF formats. At present, this includes the following:

In addition to basic Query mechanisms

Web infrastructure

There are also storage adaptors for popular Triple-stores, Graph-stores SQL, and other NOSQL stores.

There is also a LinkedData gem, which combines a core set of these together.

Gems

Gem Category Support Maintainer
json-ld Format Core @gkellogg
ld-patch Format Community @gkellogg
linkeddata Format Core @ruby-rdf
rack-linkeddata Server Community @ruby-rdf
rack-sesame Server Obsolete -
rack-sparql Server Obsolete -
rdf Core Core @ruby-rdf
rdf-aggregate-repo Storage Core @gkellogg
rdf-agraph Storage Vendor @emk
rdf-arq Query Obsolete -
rdf-bert RPC Obsolete -
rdf-blazegraph Storage Vendor @no-reply
rdf-cassandra Storage Obsolete -
rdf-do Storage Core @ruby-rdf
rdf-isomorphic Misc Core @ruby-rdf
rdf-json Format Core @ruby-rdf
rdf-ldp Server Community @no-reply
rdf-microdata Format Core @ruby-rdf
rdf-mongo Storage Community @gkellogg
rdf-n3 Format Core @ruby-rdf
rdf-normalize Extension Core @gkellogg
rdf-raptor Format Community @dwbutler
rdf-rasqal Query Obsolete -
rdf-rdfa Format Core @ruby-rdf
rdf-rdfxml Format Core @ruby-rdf
rdf-reasoner Reasoner Core @gkellogg
rdf-sesame Storage Community @abrisse
rdf-source Extension Obsolete -
rdf-spec Testing Core @ruby-rdf
rdf-tabular Format Community @gkellogg
rdf-talis Storage Obsolete -
rdf-trig Format Core @ruby-rdf
rdf-trix Format Core @ruby-rdf
rdf-turtle Format Core @ruby-rdf
rdf-vcf Format Community @bendiken
rdf-virtuoso Storage Vendor @digibib
rdf-vocab Extension Core @ruby-rdf
rdf-xsd Extension Core @ruby-rdf
rdfs Reasoner Obsolete @ruby-rdf
sinatra-linkeddata Server Core -
sparql Query Core @ruby-rdf
sparql-client Client Core @ruby-rdf
spira ORM Community @cordawyn
trinity CMS Obsolete -

Examples

require 'linkeddata'

Writing RDF data using the N-Triples format

require 'rdf/ntriples'
graph = RDF::Graph.new << [:hello, RDF::Vocab::DC.title, "Hello, world!"]
graph.dump(:ntriples)

or

RDF::Writer.open("hello.nt") { |writer| writer << graph }

Reading RDF data in the N-Triples format

require 'rdf/ntriples'
graph = RDF::Graph.load("https://ruby-rdf.github.io/rdf/etc/doap.nt")

or

RDF::Reader.open("https://ruby-rdf.github.io/rdf/etc/doap.nt") do |reader|
  reader.each_statement do |statement|
    puts statement.inspect
  end
end

Reading RDF data in other formats

{RDF::Reader.open} and {RDF::Repository.load} use a number of mechanisms to determine the appropriate reader to use when loading a file. The specific format to use can be forced using, e.g. :format => :ntriples option where the specific format symbol is determined by the available readers. Both also use MimeType or file extension, where available.

require 'linkeddata'

repo = RDF::Repository.load("https://ruby-rdf.github.io/rdf-turtle/etc/doap.ttl")

A specific sub-type of Reader can also be invoked directly:

require 'rdf/turtle'

RDF::Reader.open("https://ruby-rdf.github.io/rdf-turtle/etc/doap.ttl") do |reader|
  reader.each_statement do |statement|
    puts statement.inspect
  end
end

Writing RDF data using other formats

RDF::Writer.open, RDF::Enumerable#dump, RDF::Writer.dump take similar options to RDF::Reader.open to determine the appropriate writer to use.

require 'linkeddata'

RDF::NTriples::Writer.open("doap.nt") do |writer|
  writer << RDF::Reader.open("https://ruby-rdf.github.io/rdf/etc/doap.nt")
end

A specific sub-type of Writer can also be invoked directly:

require 'rdf/nquads'

graph.dump(:nquads)

Querying RDF data using basic graph patterns (BGPs)

require 'rdf/nquads'

repo = RDF::Repository.load("https://ruby-rdf.github.io/rdf/etc/doap.nq")
query = RDF::Query.new({
  :person => {
    RDF.type  => RDF::Vocab::FOAF.Person,
    RDF::Vocab::FOAF.name => :name,
    RDF::Vocab::FOAF.mbox => :email,
  }
})

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

A separate [SPARQL][SPARQL doc] gem builds on basic BGP support to provide full support for SPARQL 1.1 queries and updates.

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")

Presentations on RDF.rb and related technologies

About

Source repository for the ruby-rdf.github.com website.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published