W3C home > Mailing lists > Public > public-rdf-ruby@w3.org > October 2010

Re: SPARQL::Client::Repository and Spira

From: Ben Lavender <blavender@gmail.com>
Date: Thu, 14 Oct 2010 08:40:47 +0000
Message-ID: <AANLkTi=tpn2=OxyzSv21jtGU=uowyhb9NuqEuKw7y-Se@mail.gmail.com>
To: Christoph Badura <bad@bsd.de>
Cc: public-rdf-ruby@w3.org
So if you can use edge sparql-client, this is fixed in master.  See
the updates at http://github.com/bendiken/sparql-client/commits/master.

A gem will happen in The Mysterious Future.

Ben

On Mon, Oct 11, 2010 at 10:42 AM, Ben Lavender <blavender@gmail.com> wrote:
> The issue is in the SPARQL repository, which is currently handing off
> hash queries to the default rdf.rb implementation.  I think this may
> end up being an RDF.rb bug, because as I recall, repositories are only
> supposed to need to define query_pattern these days, which the SPARQL
> repo does.  It also defines query, though, which may be its own bug.
>
> Unfortunately there's no immediate workaround for this, because Spira
> defines the query, and uses the hash form.  One would have to hack the
> repository or Spira for an immediate solution.
>
> Issue opened for SPARQL client at
> http://github.com/bendiken/sparql-client/issues/issue/11
>
> A minimal reproduction is (I had a hacked local copy of SPARQL repo to
> inspect on query to find this):
>
> #!/usr/bin/env ruby
>
> require 'sparql/client'
>
> repo = SPARQL::Client::Repository.new 'http://sparql.org/books'
>
> p repo.query(:subject => RDF::URI.new("http://example.com/foo/1")).to_a
> #=> "CONSTRUCT { ?s ?p ?o . } WHERE { ?s ?p ?o . }"
> p repo.query(RDF::Statement.new(RDF::URI.new("http://example.com/foo/1"),
> nil, nil)).to_a
> #=> "CONSTRUCT { <http://example.com/foo/1> ?p ?o . } WHERE {
> <http://example.com/foo/1> ?p ?o . }"
>
> Thanks for reporting this.  As it's an undeniable catastrophe for
> Spira, I'm going to get it done as soon as I remind myself what the
> correct way to do it is.  Unfortunately that might be as late as
> Wednesday.
>
> Ben
>
> On Sun, Oct 10, 2010 at 1:26 PM, Ben Lavender <blavender@gmail.com> wrote:
>> Going over this initially, I'm not sure why it would be happening.
>> #empty? is being called on a query result set, not the repository.
>>
>> Unfortunately, I'm traveling for work and don't have a local SPARQL
>> endpoint to test with.  I'll figure something out tomorrow and try and
>> get you a response as soon as possible, since, well, yeah, this is a
>> pretty huge problem.
>>
>> Not that it means the current example is not a bug, but note that the
>> SPARQL repository is more of an example/base, since SPARQL varies from
>> implementation to implementation.  ARQ, for example, includes a
>> non-standard count function, which prevents the default
>> iterate-and-count implementation.  It's probably not a big deal to
>> create an ARQ SPARQL repository class that has support for that, and
>> I'd help you work on that if you wanted.
>>
>> Ben
>>
>> On Sat, Oct 9, 2010 at 10:55 AM, Christoph Badura <bad@bsd.de> wrote:
>>> I'm trying to use SPARQL::Client as a Repository for Spira.
>>>
>>>    require 'spira'
>>>    require 'sparql/client'
>>>
>>>    class Foo
>>>      include Spira::Resource
>>>
>>>      property :whatever, :predicate => DC.whatever
>>>    end
>>>
>>>    repo = SPARQL::Client::Repository.new 'http://localhost:2020/sparql'
>>>    Spira.add_repository! :default, repo
>>>
>>>    foo = Foo.for(RDF::URI.new("http://example.com/foo/1"))
>>>
>>> As soon as I access the first property, the sparql server (i'm using joseki)
>>> is reporting the first query:
>>>
>>>    INFO  SPARQL               :: Query: CONSTRUCT { ?s ?p ?o . } WHERE { ?s ?p ?o . }
>>>
>>> Returning all the triples in the graph will take a while for any real world
>>> repository.  The test data I have loaded is some 40MB.
>>>
>>> The reason for this are the "unless stamtements.empty?" modifiers used in
>>> #reload_attributes.  Countable#empty? relies on #each and SPARQL::Client::
>>> Repository#each does
>>>    client.construct([:s, :p, :o]).where([:s, :p, :o]).each_statement(&block)
>>>
>>> I haven't come up with a useful test case, so I'm posting here instead.
>>>
>>> Here's relevant info from the stacktraces:
>>>
>>> (rdb:1) l
>>> [8, 17] in /usr/pkg/lib/ruby/gems/1.8/gems/rdf-0.2.3/lib/rdf/mixin/countable.rb
>>>   8      # Returns `true` if `self` contains no RDF statements.
>>>   9      #
>>>   10      # @return [Boolean]
>>>   11      def empty?
>>>   12        empty = true
>>> => 13        each { empty = false; break }
>>>   14        empty
>>>   15      end
>>>   16
>>>   17      ##
>>> (rdb:1) up
>>> #4 /usr/pkg/lib/ruby/gems/1.8/gems/spira-0.0.8/lib/spira/resource/instance_methods.rb:87:in `reload_attributes'
>>> (rdb:1) where
>>>    #1 /usr/pkg/lib/ruby/gems/1.8/gems/sparql-client-0.0.5/lib/sparql/client/repository.rb:26:in `each'
>>>    #2 /usr/pkg/lib/ruby/gems/1.8/gems/rdf-0.2.3/lib/rdf/mixin/queryable.rb:67:in `query_pattern'
>>>    #3 /usr/pkg/lib/ruby/gems/1.8/gems/rdf-0.2.3/lib/rdf/mixin/countable.rb:13:in `empty?'
>>> --> #4 /usr/pkg/lib/ruby/gems/1.8/gems/spira-0.0.8/lib/spira/resource/instance_methods.rb:87:in `reload_attributes'
>>>    #5 /usr/pkg/lib/ruby/gems/1.8/gems/spira-0.0.8/lib/spira/resource/instance_methods.rb:57:in `reload'
>>>    #6 /usr/pkg/lib/ruby/gems/1.8/gems/promise-0.3.0/lib/promise.rb:89:in `method_missing'
>>>    #7 /usr/pkg/lib/ruby/gems/1.8/gems/spira-0.0.8/lib/spira/resource/instance_methods.rb:323:in `attribute_get'
>>>    #8 /usr/pkg/lib/ruby/gems/1.8/gems/spira-0.0.8/lib/spira/resource/dsl.rb:254:in `identifier'
>>>    #9 test-sparql.rb:10
>>> (rdb:1)
>>>  down 3
>>> #1 /usr/pkg/lib/ruby/gems/1.8/gems/sparql-client-0.0.5/lib/sparql/client/repository.rb:26:in `each'
>>> (rdb:1) l
>>> [21, 30] in /usr/pkg/lib/ruby/gems/1.8/gems/sparql-client-0.0.5/lib/sparql/client/repository.rb
>>>   21      # @yield  [statement]
>>>   22      # @yieldparam [RDF::Statement] statement
>>>   23      # @return [Enumerator]
>>>   24      # @see    RDF::Repository#each
>>>   25      def each(&block)
>>> => 26        unless block_given?
>>>   27          RDF::Enumerator.new(self, :each)
>>>   28        else
>>>   29          client.construct([:s, :p, :o]).where([:s, :p, :o]).each_statement(&block)
>>>   30        end
>>> (rdb:1) p block_given?
>>> true
>>> (rdb:1)
>>>
>>> --chris
>>>
>>>
>>
>
Received on Thursday, 14 October 2010 08:41:41 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 14 October 2010 08:41:41 GMT