Sha256: 85243328b8f83511867cd8fee7c2149888f7f75003637c07e15757c0e11e7cff

Contents?: true

Size: 1.07 KB

Versions: 44

Compression:

Stored size: 1.07 KB

Contents

module RDF
  class Graph
    # Resource properties
    #
    # Properties arranged as a hash with the predicate Term as index to an array of resources or literals
    #
    # Example:
    #   graph.load(':foo a :bar; rdfs:label "An example" .', "http://example.com/")
    #   graph.resources(URI.new("http://example.com/subject")) =>
    #   {
    #     "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" => [<http://example.com/#bar>],
    #     "http://example.com/#label"                       => ["An example"]
    #   }
    def properties(subject, recalc = false)
      @properties ||= {}
      @properties.delete(subject.to_s) if recalc
      @properties[subject.to_s] ||= begin
        hash = Hash.new
        self.query(:subject => subject) do |statement|
          pred = statement.predicate.to_s

          hash[pred] ||= []
          hash[pred] << statement.object
        end
        hash
      end
    end

    # Get type(s) of subject, returns a list of symbols
    def type_of(subject)
      query(:subject => subject, :predicate => RDF.type).map {|st| st.object}
    end
  end
end

Version data entries

44 entries across 44 versions & 5 rubygems

Version Path
rdf-rdfxml-0.3.8 lib/rdf/rdfxml/patches/graph_properties.rb
rdf-rdfxml-0.3.7 lib/rdf/rdfxml/patches/graph_properties.rb
rdf-rdfxml-0.3.6 lib/rdf/rdfxml/patches/graph_properties.rb
rdf-rdfxml-0.3.5 lib/rdf/rdfxml/patches/graph_properties.rb
rdf-rdfa-0.3.5.1 lib/rdf/rdfa/patches/graph_properties.rb
rdf-rdfxml-0.3.4 lib/rdf/rdfxml/patches/graph_properties.rb
rdf-rdfa-0.3.4.2 lib/rdf/rdfa/patches/graph_properties.rb
rdf-rdfa-0.3.4.1 lib/rdf/rdfa/patches/graph_properties.rb
rdf-n3-0.3.4.1 lib/rdf/n3/patches/graph_properties.rb
rdf-n3-0.3.4 lib/rdf/n3/patches/graph_properties.rb
json-ld-0.0.4 lib/json/ld/extensions.rb
rdf-rdfa-0.3.4 lib/rdf/rdfa/patches/graph_properties.rb
rdf-rdfa-0.3.3.3 lib/rdf/rdfa/patches/graph_properties.rb
rdf-rdfxml-0.3.3.1 lib/rdf/rdfxml/patches/graph_properties.rb
the-experimenters-rdf-rdfxml-0.3.4 lib/rdf/rdfxml/patches/graph_properties.rb
the-experimenters-rdf-rdfxml-0.3.3 lib/rdf/rdfxml/patches/graph_properties.rb
rdf-rdfa-0.3.3.2 lib/rdf/rdfa/patches/graph_properties.rb
rdf-rdfa-0.3.3.1 lib/rdf/rdfa/patches/graph_properties.rb
rdf-n3-0.3.3.1 lib/rdf/n3/patches/graph_properties.rb
rdf-rdfa-0.3.3 lib/rdf/rdfa/patches/graph_properties.rb