- From: Peter Vandenabeele <peter@vandenabeele.com>
- Date: Thu, 20 Jun 2013 12:01:38 +0200
- To: Gregg Kellogg <gregg@greggkellogg.net>
- Cc: "public-rdf-ruby@w3.org" <public-rdf-ruby@w3.org>
- Message-ID: <CAC969dJNBMoD_im7ebu93KYviwOPMvHoF5EVtU762zMg8rc=TA@mail.gmail.com>
On Thu, Jun 20, 2013 at 11:21 AM, Gregg Kellogg <gregg@greggkellogg.net>wrote:
> On Jun 20, 2013, at 1:59 AM, Peter Vandenabeele <peter@vandenabeele.com>
> wrote:
>
> On Thu, Jun 20, 2013 at 1:31 AM, Gregg Kellogg <gregg@greggkellogg.net>wrote:
>
>> Just released SPARQL::Client version 1.0.4, which now works against an
>> RDF::Repository (actually any RDF::Queryable) in addition to remote
>> endpoints. This allows the DSL to be used along with the SPARQL gem to
>> access a local Repository, and runs in pure Ruby. For example:
>>
>> require 'rdf/turtle'
>> require 'sparql/client'
>> repository = RDF::Repository.load("
>> https://raw.github.com/ruby-rdf/sparql-client/master/etc/doap.ttl",
>> :format => :ttl)
>>
>> sparql = SPARQL::Client.new(repository)
>> query = sparql.select.where([:s, :p, :o]).offset(10).limit(10)
>>
>> Gregg Kellogg
>> gregg@greggkellogg.net
>>
>>
> Hi Gregg,
>
> I tried your script (in the context of an rvm gemset that was
> populated with this Gemfile):
>
> $ cat Gemfile
> source 'https://rubygems.org'
>
> gem 'rdf'
> gem 'rdf-turtle'
> gem 'sparql'
> gem 'sparql-client'
>
> I add the resulting Gemfile.lock below for detailed versions.
>
> It works, but I seem to miss the part to execute the actual query
> or ask the results from it? I must be missing something trivial ...
>
> The thrown execption is:
>
> NoMethodError: undefined method `execute' for SPARQL:Module
>
>
> This was based on an example from the README, other examples illustrate
> this:
>
> query.each_solution do |solution|
> puts solution
> end
>
>
Thanks for the fast reply and the link to the README of sparql-client.
I was able to get the example to work with an explicit require of 'sparql':
require 'rdf/turtle'
require 'sparql/client'
require 'sparql' ## <== This require is also needed
repository = RDF::Repository.load("
https://raw.github.com/ruby-rdf/sparql-client/master/etc/doap.ttl", :format
=> :ttl)
sparql = SPARQL::Client.new(repository)
query = sparql.select.where([:s, :p, :o]).offset(10).limit(2)
query.execute
Output from irb below as reference.
Thanks again,
peter_v
+++++++++++++++++
irb output:
$ irb
2.0.0p195 :001 > require 'rdf/turtle'
=> true
2.0.0p195 :002 > require 'sparql/client'
=> true
2.0.0p195 :003 > require 'sparql' ## <== This require is also needed
=> true
2.0.0p195 :004 > repository = RDF::Repository.load("
https://raw.github.com/ruby-rdf/sparql-client/master/etc/doap.ttl", :format
=> :ttl)
=> #<RDF::Repository:0x3fd06a248504()>
2.0.0p195 :005 > sparql = SPARQL::Client.new(repository)
=> #<SPARQL::Client:0x3fd06954a30c(#<RDF::Repository:0x007fa0d4490a08>)>
2.0.0p195 :006 > query = sparql.select.where([:s, :p,
:o]).offset(10).limit(2)
=> #<SPARQL::Client::Query:0x3fd0695a8128(SELECT * WHERE { ?s ?p ?o . }
OFFSET 10 LIMIT 2)>
2.0.0p195 :007 > query.execute
Could not load gem 'equivalent-xml'; XMLLiteral comparison performed using
REXML
=> [#<RDF::Query::Solution:0x3fd06b044c20({:s=>#<RDF::URI:0x3fd0694e9020(
http://rubygems.org/gems/rdf)>, :p=>#<RDF::URI:0x3fd06a103a7c(
http://usefulinc.com/ns/doap#implements)>, :o=>#<RDF::URI:0x3fd06a1028ac(
http://www.w3.org/TR/sparql11-query/)>})>,
#<RDF::Query::Solution:0x3fd06b044b58({:s=>#<RDF::URI:0x3fd0694e9020(
http://rubygems.org/gems/rdf)>, :p=>#<RDF::URI:0x3fd06a103a7c(
http://usefulinc.com/ns/doap#implements)>, :o=>#<RDF::URI:0x3fd06a106380(
http://www.w3.org/TR/sparql11-update/)>})>]
Received on Thursday, 20 June 2013 13:18:01 UTC