Class: BELParser::Resource::EagerSPARQLReader
- Inherits:
-
SPARQLReader
- Object
- SPARQLReader
- BELParser::Resource::EagerSPARQLReader
- Defined in:
- lib/bel_parser/resource/eager_sparql_reader.rb
Overview
EagerSPARQLReader
Constant Summary
Constants inherited from SPARQLReader
SPARQLReader::ALLOW_HEADER, SPARQLReader::SCHEMES
Instance Method Summary collapse
-
#initialize(sparql_endpoint_url, validate_url = true) ⇒ EagerSPARQLReader
constructor
A new instance of EagerSPARQLReader.
- #retrieve_resource(resource_identifier) ⇒ Object
- #retrieve_value_from_resource(resource_identifier, value) ⇒ Object
- #retrieve_values_from_resource(resource_identifier) ⇒ Object
Methods included from Reader
Constructor Details
#initialize(sparql_endpoint_url, validate_url = true) ⇒ EagerSPARQLReader
Returns a new instance of EagerSPARQLReader.
9 10 11 12 13 |
# File 'lib/bel_parser/resource/eager_sparql_reader.rb', line 9 def initialize(sparql_endpoint_url, validate_url = true) @resources = Concurrent::Hash.new @locks = Concurrent::Hash.new super end |
Instance Method Details
#retrieve_resource(resource_identifier) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bel_parser/resource/eager_sparql_reader.rb', line 15 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 |
#retrieve_value_from_resource(resource_identifier, value) ⇒ Object
38 39 40 41 42 |
# File 'lib/bel_parser/resource/eager_sparql_reader.rb', line 38 def retrieve_value_from_resource(resource_identifier, value) concepts = @resources[resource_identifier] return super unless concepts concepts[value] end |
#retrieve_values_from_resource(resource_identifier) ⇒ Object
44 45 46 47 48 |
# File 'lib/bel_parser/resource/eager_sparql_reader.rb', line 44 def retrieve_values_from_resource(resource_identifier) concepts = @resources[resource_identifier] return super unless concepts concepts end |