Re: SPARQL client executes against local repository

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

Gregg

> Thanks,
> 
> Peter Vandenabeele
> 
> 
> $ irb
> 2.0.0p195 :001 > require 'rdf/turtle'
>  => true 
> 2.0.0p195 :002 > require 'sparql/client'
>  => true 
> 2.0.0p195 :003 > repository = RDF::Repository.load("https://raw.github.com/ruby-rdf/sparql-client/master/etc/doap.ttl", :format => :ttl)
>  => #<RDF::Repository:0x3ff7f4e347f8()> 
> 2.0.0p195 :004 > 
> 2.0.0p195 :005 > sparql = SPARQL::Client.new(repository)
>  => #<SPARQL::Client:0x3ff7f50d7438(#<RDF::Repository:0x007fefe9c68ff0>)> 
> 2.0.0p195 :006 > query = sparql.select.where([:s, :p, :o]).offset(10).limit(10)
>  => #<SPARQL::Client::Query:0x3ff7f51130a0(SELECT * WHERE { ?s ?p ?o . } OFFSET 10 LIMIT 10)> 
> 2.0.0p195 :007 > query.result  ## same execption for `query.execute`
> NoMethodError: undefined method `execute' for SPARQL:Module
>     from /Users/peter_v/.rvm/gems/ruby-2.0.0-p195@ruby-rdf/gems/sparql-client-1.0.4/lib/sparql/client.rb:259:in `query'
>     from /Users/peter_v/.rvm/gems/ruby-2.0.0-p195@ruby-rdf/gems/sparql-client-1.0.4/lib/sparql/client.rb:232:in `block in call_query_method'
>     from /Users/peter_v/.rvm/gems/ruby-2.0.0-p195@ruby-rdf/gems/sparql-client-1.0.4/lib/sparql/client/query.rb:306:in `result'
>     from (irb):7
>     from /Users/peter_v/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>'
> 
> 
> As a reference, the Gemfile.lock with the actual versions:
> 
> /Users/peter_v/data/rdf/rdf-ruby $ cat Gemfile.lock 
> GEM
>   remote: https://rubygems.org/
>   specs:
>     addressable (2.3.4)
>     builder (3.2.2)
>     ebnf (0.3.1)
>       rdf
>       sxp
>     json (1.8.0)
>     json_pure (1.8.0)
>     mini_portile (0.5.0)
>     net-http-persistent (2.8)
>     nokogiri (1.6.0)
>       mini_portile (~> 0.5.0)
>     rdf (1.0.7)
>       addressable (>= 2.2)
>     rdf-aggregate-repo (0.1.2)
>       rdf (>= 1.0)
>     rdf-turtle (1.0.8)
>       ebnf (>= 0.3.0)
>       rdf (>= 1.0.7)
>     rdf-xsd (1.0.2.1)
>       nokogiri (>= 1.5.0)
>       rdf (>= 0.3.4)
>     sparql (1.0.8)
>       builder (>= 3.0)
>       ebnf (>= 0.3.0)
>       json (>= 1.7)
>       rdf (>= 1.0.6)
>       rdf-aggregate-repo
>       rdf-xsd (>= 1.0)
>       sparql-client (>= 1.0)
>       sxp (>= 0.1.0)
>     sparql-client (1.0.4)
>       json_pure (>= 1.4)
>       net-http-persistent (>= 1.4)
>       rdf (>= 1.0)
>     sxp (0.1.3)
>       json (>= 1.1.1)
> 
> PLATFORMS
>   ruby
> 
> DEPENDENCIES
>   rdf
>   rdf-turtle
>   sparql
>   sparql-client
> 
> 
> -- 
> Peter Vandenabeele
> http://www.linkedin.com/in/petervandenabeele
> https://github.com/petervandenabeele
> https://twitter.com/peter_v
> gsm: +32-478-27.40.69
> e-mail: peter@vandenabeele.com
> skype: peter_v_be

Received on Thursday, 20 June 2013 09:22:10 UTC