SPARQL::Client::Repository and Spira

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 Saturday, 9 October 2010 14:55:44 UTC