Class: BELParser::Resource::SPARQLReader
- Inherits:
-
Object
- Object
- BELParser::Resource::SPARQLReader
- Defined in:
- lib/bel_parser/resource/sparql_reader.rb
Overview
SPARQLReader
Direct Known Subclasses
Constant Summary collapse
- SCHEMES =
[URI::HTTP, URI::HTTPS].freeze
- ALLOW_HEADER =
'Allow'.freeze
Instance Method Summary collapse
-
#initialize(sparql_endpoint_url, validate_url = false) ⇒ SPARQLReader
constructor
A new instance of SPARQLReader.
- #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 = false) ⇒ SPARQLReader
Returns a new instance of SPARQLReader.
21 22 23 24 |
# File 'lib/bel_parser/resource/sparql_reader.rb', line 21 def initialize(sparql_endpoint_url, validate_url = false) validate_sparql_endpoint_url(sparql_endpoint_url) if validate_url @sparql_repository = SPARQL::Client.new(sparql_endpoint_url) end |
Instance Method Details
#retrieve_resource(resource_identifier) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/bel_parser/resource/sparql_reader.rb', line 26 def retrieve_resource(resource_identifier) uri = URI(resource_identifier.to_s) template_binding = binding sparql_query = RESOLVE_CONCEPT_SCHEME.result(template_binding) hash_to_concept_scheme(resource_identifier, execute_select(sparql_query).first) end |
#retrieve_value_from_resource(resource_identifier, value) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bel_parser/resource/sparql_reader.rb', line 34 def retrieve_value_from_resource(resource_identifier, value) uri = URI(resource_identifier.to_s) template_binding = binding sparql_query = RESOLVE_CONCEPT.result(template_binding) concept_scheme = retrieve_resource(resource_identifier) to_concept = method(:hash_to_concept).to_proc.curry[concept_scheme] concepts = execute_select(sparql_query).map(&to_concept).compact return nil if concepts.empty? concepts end |
#retrieve_values_from_resource(resource_identifier) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bel_parser/resource/sparql_reader.rb', line 46 def retrieve_values_from_resource(resource_identifier) uri = URI(resource_identifier.to_s) template_binding = binding sparql_query = RESOLVE_CONCEPTS.result(template_binding) concept_scheme = retrieve_resource(resource_identifier) to_concept = method(:hash_to_concept).to_proc.curry[concept_scheme] concepts = execute_select(sparql_query).map(&to_concept).compact return nil if concepts.empty? concepts end |