Class: Ddr::Vocab::RDFVocabularyParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ddr/vocab/rdf_vocabulary_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, prefix = "") ⇒ RDFVocabularyParser

Returns a new instance of RDFVocabularyParser.



8
9
10
11
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 8

def initialize(source, prefix = "")
  @source = source
  @prefix = prefix
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



6
7
8
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 6

def prefix
  @prefix
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 6

def source
  @source
end

Instance Method Details

#graphObject



38
39
40
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 38

def graph
  @graph ||= RDF::Graph.load(source).freeze
end

#propertiesObject



25
26
27
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 25

def properties
  RDF::Query.execute(graph, properties_query)
end

#properties_queryObject



29
30
31
32
33
34
35
36
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 29

def properties_query
  {:resource => {
     RDF.type => RDF.Property,
     RDF::RDFS.label => :label,
     RDF::RDFS.comment => :comment
   }
  }
end

#term_namesObject



13
14
15
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 13

def term_names
  @term_names ||= terms.collect { |t| t[:resource].to_s.sub(prefix, "") }.freeze
end

#term_symbolsObject



17
18
19
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 17

def term_symbols
  term_names.map(&:to_sym)
end

#termsObject



21
22
23
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 21

def terms
  properties.map(&:to_h)
end