Sha256: 261fa547cda0dc0441bb996e2f3ce72d26fc513ec5f871c7886bc5d031087f60

Contents?: true

Size: 855 Bytes

Versions: 20

Compression:

Stored size: 855 Bytes

Contents

require 'rdf/rdfxml'

module Ddr
  module Metadata
    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_hash)
      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
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ddr-models-1.11.8 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.11.7 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.11.6 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.11.5 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.11.4 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.11.3 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.11.2 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.11.1 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.11.0 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.10.0 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.9.0 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.8.1 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.8.0 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.7.0 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.6.0 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.5.0 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.4.0 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.3.0 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.2.1 lib/ddr/metadata/rdf_vocabulary_parser.rb
ddr-models-1.2.0 lib/ddr/metadata/rdf_vocabulary_parser.rb