sign in
Home | Updates | Pages | Users | Admin | Help

ActiveRDF

Overview

ActiveRDF is a library for accessing RDF data from Ruby programs. It can be used as data layer in Ruby-on-Rails, similar to ?ActiveRecord (which provides an O/R mapping to relational databases). ActiveRDF in RoR allows you to create semantic web applications very rapidly. ActiveRDF gives you a Domain Specific Language (DSL) for your RDF model: you can address RDF resources, classes, properties, etc. programmatically, without queries.

  • ActiveRDF can be used with various RDF stores, more adapters are easy to add
  • ActiveRDF uses convention over configuration, working nicely in 90% of the cases
  • ActiveRDF is in active development
  • ActiveRDF is open source, released under GPL license

Getting started

Check out our GettingStartedGuide which shows you:
  • how to install ActiveRDF and its Adapters
  • how to read and write to RDF triple stores
  • how to create a Ruby on Rails application that gets its data from a triple store

Example

Create and edit people

require ‘active_rdf’
  1. we load activerdf
  2. we add an existing SPARQL database as datasource ConnectionPool.add_data_source :type => :sparql, :url => “http://m3pe.org:8080/repositories/test-people”, :results => :sparql_xml
  3. we register a short-hand notation for the namespace used in this test data Namespace.register :test, ‘http://activerdf.org/test/’
  4. now we can access all RDF properties of a person as Ruby attributes: eyal = RDFS::Resource.new ‘http://activerdf.org/test/eyal’ puts eyal.age puts eyal.eye puts eyal.class
  5. now we construct Ruby classes for the currently existing RDFS classes ObjectManager.construct_classes
  6. and we can use these classes armin = TEST::Person.new ‘http://armin-haller.com/#me’
  7. we cannot change anything, since SPARQL endpoints have just read-only access

Find resources


require 'active_rdf'

# we add an existing SPARQL database as datasource
ConnectionPool.add_data_source :type => :sparql, :url => "http://m3pe.org:8080/repositories/test-people", :results => :sparql_xml 

# we register a short-hand notation for the namespace used in this test data 
Namespace.register :test, 'http://activerdf.org/test/'
ObjectManager.construct_classes

all_people = TEST::Person.find_all
all_resources = RDFS::Resource.find_all

# print all the people, and their friends
all_people.each do |person|
  puts "#{person} has #{person.eye} eyes" 
end

# find all people aged 27
almost_thirties = TEST::Person.find_by_age(27)
puts "the following people are almost thirty: #{almost_thirties}" 

Powered by JunebugWiki v0.0.31 Page last edited by ikbeneyal on May 06, 2007 11:37 PM (diff)
Version 36 «oldernewer»currentversions