Runs some Ruby.
require 'rubygems'
require 'active_rdf'
puts <<END
To access some RDF data, we have to open a connection to a triple store.
In this example we will open a connection to a SPARQL endpoint, with this command:
ConnectionPool.add_data_source :type => :sparql,
:url => "http://m3pe.org:8080/repositories/test-people",
:results => :sparql_xml
END
prompt "commence connecting!"
ConnectionPool.add_data_source :type => :sparql,
:url => "http://m3pe.org:8080/repositories/test-people",
:results => :sparql_xml
puts <<END
Through ActiveRDF 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
END
prompt "register test namespace"
Namespace.register :test, 'http://activerdf.org/test/'
prompt "do it?"
eyal = RDFS::Resource.new 'http://activerdf.org/test/eyal'
puts eyal.age
puts eyal.eye
puts eyal.class
puts <<END
We can register the Namespace used in this example, so that we can use
Namespaces and local names in a very similiar way, as they are used in RDF:
Namespace.register :test, 'http://activerdf.org/test/'
END
puts <<END
after registering the namespace, we now tell the ObjectManager to search for all
RDFS classes in the triple store, and construct corresponding Ruby classes,
so that there is no difference between constructing standard Ruby objects, and
Ruby objects, which are completly backed by the triple store:
ObjectManager.construct_classes
END
prompt "construct classes"
ObjectManager.construct_classes
puts "registering armin..."
prompt "create the Person Armin:"
armin = TEST::Person.new('http://armin-haller.com/#me')
puts <<END
We cannot change anything, since SPARQL endpoints have just read-only access
Now lets search for something in the triple store:
Print all the people, and their friends:
all_people = TEST::Person.find_all
all_people.each do |person|
puts "#{person} has #{person.eye} eyes"
end
END
prompt "print eye color of all People found:"
all_people = TEST::Person.find_all
all_people.each do |person|
puts "#{person} has #{person.eye} eyes"
end
puts <<END
Find all people aged 27:
almost_thirties = TEST::Person.find_by_age(27)
END
prompt "search for 27 year old Persons:"
almost_thirties = TEST::Person.find_by_age(27)
puts "the following people are almost thirty: #{almost_thirties}"