Sha256: 3d917bb0fb1a9221ad94cd12d6b8dca9e83a6f81ec0ea67342edff64ac146b4c

Contents?: true

Size: 1.35 KB

Versions: 111

Compression:

Stored size: 1.35 KB

Contents

require 'concurrent/hash'

require_relative 'sparql_reader'

module BELParser
  module Resource
    # EagerSPARQLReader
    class EagerSPARQLReader < SPARQLReader
      def initialize(sparql_endpoint_url, validate_url = true)
        @resources = Concurrent::Hash.new
        @locks     = Concurrent::Hash.new
        super
      end

      def retrieve_resource(resource_identifier)
        if @resources.key?(resource_identifier)
          concepts = @resources[resource_identifier]
          concepts[value]
        else
          lock = @locks[resource_identifier] ||= Mutex.new
          if lock.try_lock
            Thread.new do
              concepts = retrieve_values_from_resource(resource_identifier).to_a
              @resources[resource_identifier] = 
                Hash[
                  concepts.map do |c|
                    [c.name, c]
                  end
                ]
              lock.unlock
            end
          end

          super
        end
      end

      def retrieve_value_from_resource(resource_identifier, value)
        concepts = @resources[resource_identifier]
        return super unless concepts
        concepts[value]
      end

      def retrieve_values_from_resource(resource_identifier)
        concepts = @resources[resource_identifier]
        return super unless concepts
        concepts
      end
    end
  end
end

Version data entries

111 entries across 111 versions & 1 rubygems

Version Path
bel_parser-1.1.6-java lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.6 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.5 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.4-java lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.4 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.3-java lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.3 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.2-java lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.2 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.1-java lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.1.1 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.0.8-java lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.0.8 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.0.7-java lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.0.7 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.0.6-java lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.0.6 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.0.5-java lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.0.5 lib/bel_parser/resource/eager_sparql_reader.rb
bel_parser-1.0.4-java lib/bel_parser/resource/eager_sparql_reader.rb