Comparing
version 36 and
version 35 backh1. 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
h1. 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
h1. Example
h2. Create and edit people
require 'active_rdf'
# we load activerdf
# 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/'
# 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
# now we construct Ruby classes for the currently existing RDFS classes
ObjectManager.construct_classes
# and we can use these classes
armin = TEST::Person.new 'http://armin-haller.com/#me'
# we cannot change anything, since SPARQL endpoints have just read-only access
h2. 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}"