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.



10
11
12
13
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 10

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

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#graphObject



40
41
42
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 40

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

#propertiesObject



27
28
29
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 27

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

#properties_queryObject



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

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

#term_namesObject



15
16
17
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 15

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

#term_symbolsObject



19
20
21
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 19

def term_symbols
  term_names.map(&:to_sym)
end

#termsObject



23
24
25
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 23

def terms
  properties.map(&:to_h)
end