require 'rubygems' require 'active_rdf' ConnectionPool.add_data_source :type => :sparql, :url => "http://m3pe.org:8080/repositories/test-people", :results => :sparql_xml # we need to register a short-hand notation for the namespace used in this test data Namespace.register :test, 'http://activerdf.org/test/' # 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 # 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 # lets create an instance of one of the classes, that were constructed in that way # armin will be of rdfs:type test:person armin = TEST::Person.new 'http://armin-haller.com/#me' # we cannot change anything, since SPARQL endpoints have just read-only access # now lets search for something in the triple store all_resources = RDFS::Resource.find_all # 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 # find all people aged 27 almost_thirties = TEST::Person.find_by_age(27) puts "the following people are almost thirty: #{almost_thirties}"