Class: Ddr::Vocab::RDFVocabularyParser
- Inherits:
-
Object
- Object
- Ddr::Vocab::RDFVocabularyParser
- Defined in:
- lib/ddr/vocab/rdf_vocabulary_parser.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #graph ⇒ Object
-
#initialize(source, prefix = "") ⇒ RDFVocabularyParser
constructor
A new instance of RDFVocabularyParser.
- #properties ⇒ Object
- #properties_query ⇒ Object
- #term_names ⇒ Object
- #term_symbols ⇒ Object
- #terms ⇒ Object
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
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 6 def prefix @prefix end |
#source ⇒ Object (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
#graph ⇒ Object
38 39 40 |
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 38 def graph @graph ||= RDF::Graph.load(source).freeze end |
#properties ⇒ Object
25 26 27 |
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 25 def properties RDF::Query.execute(graph, properties_query) end |
#properties_query ⇒ Object
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_names ⇒ Object
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_symbols ⇒ Object
17 18 19 |
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 17 def term_symbols term_names.map(&:to_sym) end |
#terms ⇒ Object
21 22 23 |
# File 'lib/ddr/vocab/rdf_vocabulary_parser.rb', line 21 def terms properties.map(&:to_h) end |