Sha256: d2e425bc8e86bf1972d3fe4207c0670ab86be8d0eb9202d9a0e316eeeec4aaa9

Contents?: true

Size: 766 Bytes

Versions: 30

Compression:

Stored size: 766 Bytes

Contents

require 'rdf/rdfxml'

module Ddr::Vocab
  class RDFVocabularyParser

    attr_reader :source, :prefix

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

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

    def term_symbols
      term_names.map(&:to_sym)
    end

    def terms
      properties.map(&:to_h)
    end

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

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

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

  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
ddr-core-1.8.0 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.7.0 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.6.6 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.6.5 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.6.4 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.6.3 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.6.2 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.6.1 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.6.0 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.5.5 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.5.4 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.5.2 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.5.3 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.5.1 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.4.4 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.4.3 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.4.2 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.4.0 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.3.0 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.2.0 lib/ddr/vocab/rdf_vocabulary_parser.rb