Class: BELParser::Resource::JenaTDBReader

Inherits:
Object
  • Object
show all
Includes:
LRUReader, Reader
Defined in:
lib/bel_parser/resource/jena_tdb_reader.rb

Defined Under Namespace

Classes: Concept, ConceptScheme

Constant Summary collapse

BELV =
RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')
SKOS =
RDF::Vocab::SKOS
DC =
RDF::Vocab::DC
VALUE_PREDICATE_ORDER =
[
  SKOS.prefLabel,
  DC.identifier,
  DC.title,
  SKOS.altLabel
]

Instance Method Summary collapse

Methods included from Reader

assert_reader

Constructor Details

#initialize(tdb_directory_path) ⇒ JenaTDBReader

Returns a new instance of JenaTDBReader.



27
28
29
# File 'lib/bel_parser/resource/jena_tdb_reader.rb', line 27

def initialize(tdb_directory_path)
  @rdf = RDF::Jena::Repository.new(tdb_directory_path)
end

Instance Method Details

#retrieve_resource(identifier) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bel_parser/resource/jena_tdb_reader.rb', line 31

def retrieve_resource(identifier)
  uri   = RDF::URI(identifier)
  domain, prefix, pref_label = nil
  types                      = []
  @rdf.query([:subject => uri]).each do |solution|
    case solution.predicate
    when RDF.type
      types << solution.object
    when BELV.domain
      domain = solution.object.to_s
    when BELV.prefix
      prefix = solution.object.to_s
    when SKOS.prefLabel
      pref_label = solution.object.to_s
    end
  end
  return nil unless types.any?(&method(:scheme_class?))
  ConceptScheme.new(uri.to_s, domain, prefix, pref_label, types.map(&:to_s))
end

#retrieve_value_from_resource(identifier, value) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/bel_parser/resource/jena_tdb_reader.rb', line 51

def retrieve_value_from_resource(identifier, value)
  concept_scheme = retrieve_resource(identifier)
  return nil unless concept_scheme

  template_binding = binding
  sparql_query     = RESOLVE_CONCEPT.result(template_binding)
  to_concept       = method(:hash_to_concept).to_proc.curry[concept_scheme]

  @rdf.query_execute(sparql_query).map(&to_concept)
end

#retrieve_values_from_resource(identifier) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/bel_parser/resource/jena_tdb_reader.rb', line 62

def retrieve_values_from_resource(identifier)
  concept_scheme = retrieve_resource(identifier)
  return nil unless concept_scheme

  template_binding = binding
  sparql_query     = RESOLVE_CONCEPTS.result(template_binding)
  to_concept       = method(:hash_to_concept).to_proc.curry[concept_scheme]

  @rdf.query_execute(sparql_query).map(&to_concept)
end