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.2.0.rc3 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.2.0.rc2 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.2.0.rc1 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.1.2 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.1.1 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.1.0 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-1.0.0 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-0.3.0 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-0.2.2 lib/ddr/vocab/rdf_vocabulary_parser.rb
ddr-core-0.2.1 lib/ddr/vocab/rdf_vocabulary_parser.rb