Class: RDF::Graph
- Inherits:
-
Object
- Object
- RDF::Graph
- Defined in:
- lib/json/ld/extensions.rb
Instance Method Summary collapse
-
#properties(subject, recalc = false) ⇒ Object
Resource properties.
-
#type_of(subject) ⇒ Object
Get type(s) of subject, returns a list of symbols.
Instance Method Details
#properties(subject, recalc = false) ⇒ Object
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"\]
}
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/json/ld/extensions.rb', line 14 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 |
#type_of(subject) ⇒ Object
Get type(s) of subject, returns a list of symbols
30 31 32 |
# File 'lib/json/ld/extensions.rb', line 30 def type_of(subject) query(:subject => subject, :predicate => RDF.type).map {|st| st.object} end |