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.



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

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

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#graphObject



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

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

#propertiesObject



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

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

#properties_queryObject



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

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

#term_namesObject



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

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

#term_symbolsObject



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

def term_symbols
  term_names.map(&:to_sym)
end

#termsObject



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

def terms
  properties.map(&:to_hash)
end