Class: RDF::Graph
- Inherits:
-
Object
- Object
- RDF::Graph
- Defined in:
- lib/rdf/model/graph.rb
Overview
An RDF graph.
Instance Attribute Summary collapse
- #context ⇒ RDF::Resource
- #data ⇒ RDF::Queryable
-
#options ⇒ Hash{Symbol => Object}
readonly
Returns the options passed to this graph when it was constructed.
Class Method Summary collapse
-
.load(url, options = {}) {|graph| ... } ⇒ Graph
Creates a new ‘Graph` instance populated by the RDF data returned by dereferencing the given context URL.
Instance Method Summary collapse
-
#anonymous? ⇒ Boolean
Returns ‘true` if this graph has an anonymous context, `false` otherwise.
-
#contexts ⇒ Enumerator<RDF::Resource>
Returns all unique RDF contexts for this graph.
-
#count ⇒ Integer
Returns the number of RDF statements in this graph.
-
#durable? ⇒ Boolean
Returns ‘false` to indicate that this graph is not durable.
-
#each {|statement| ... } ⇒ Enumerator
Enumerates each RDF statement in this graph.
- #each_graph(&block) ⇒ Object
-
#empty? ⇒ Boolean
Returns ‘true` if this graph contains no RDF statements.
-
#graph? ⇒ Boolean
Returns ‘true` to indicate that this is a graph.
- #graphs ⇒ Object
-
#has_statement?(statement) ⇒ Boolean
Returns ‘true` if this graph contains the given RDF statement.
-
#initialize(context = nil, options = {}) {|graph| ... } ⇒ Graph
constructor
A new instance of Graph.
- #load!(*args) ⇒ void
-
#named? ⇒ Boolean
Returns ‘true` if this is a named graph.
-
#to_s ⇒ String
Returns a string representation of this graph.
-
#to_uri ⇒ RDF::URI
Returns the URI representation of this graph.
-
#unnamed? ⇒ Boolean
Returns ‘true` if this is a unnamed graph.
Methods included from Mutable
#<<, #clear, #delete, #immutable?, #insert, #load, #mutable?, #update
Methods included from Util::Aliasing::LateBound
Methods included from Writable
Methods included from Readable
Methods included from Queryable
#first, #first_literal, #first_object, #first_predicate, #first_subject, #first_value, #query
Methods included from Enumerable
#dump, #each_context, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_triple, #enum_context, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_triple, #has_context?, #has_object?, #has_predicate?, #has_quad?, #has_subject?, #has_triple?, #objects, #predicates, #quads, #statements, #subjects, #supports?, #to_a, #to_hash, #to_set, #triples
Methods included from Countable
Methods included from Durable
Methods included from Resource
Methods included from Term
#<=>, #==, #constant?, #eql?, #variable?
Methods included from Value
#inspect, #inspect!, #iri?, #literal?, #node?, #resource?, #statement?, #to_ntriples, #to_quad, #to_rdf, #type_error, #uri?, #variable?
Constructor Details
#initialize(context = nil, options = {}) {|graph| ... } ⇒ Graph
Returns a new instance of Graph.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rdf/model/graph.rb', line 74 def initialize(context = nil, = {}, &block) @context = case context when nil then nil when RDF::Resource then context else RDF::URI.new(context) end @options = .dup @data = @options.delete(:data) || RDF::Repository.new if block_given? case block.arity when 1 then block.call(self) else instance_eval(&block) end end end |
Instance Attribute Details
#options ⇒ Hash{Symbol => Object} (readonly)
Returns the options passed to this graph when it was constructed.
35 36 37 |
# File 'lib/rdf/model/graph.rb', line 35 def @options end |
Class Method Details
.load(url, options = {}) {|graph| ... } ⇒ Graph
Creates a new ‘Graph` instance populated by the RDF data returned by dereferencing the given context URL.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rdf/model/graph.rb', line 56 def self.load(url, = {}, &block) self.new(url, ) do |graph| graph.load! unless graph.unnamed? if block_given? case block.arity when 1 then block.call(graph) else graph.instance_eval(&block) end end end end |
Instance Method Details
#anonymous? ⇒ Boolean
Returns ‘true` if this graph has an anonymous context, `false` otherwise.
172 173 174 |
# File 'lib/rdf/model/graph.rb', line 172 def anonymous? context.nil? ? false : context.anonymous? end |
#contexts ⇒ Enumerator<RDF::Resource>
Returns all unique RDF contexts for this graph.
139 140 141 |
# File 'lib/rdf/model/graph.rb', line 139 def contexts (named? ? [context] : []).to_enum.extend(RDF::Countable) end |
#count ⇒ Integer
Returns the number of RDF statements in this graph.
181 182 183 |
# File 'lib/rdf/model/graph.rb', line 181 def count @data.query(:context => context).count end |
#durable? ⇒ Boolean
Returns ‘false` to indicate that this graph is not durable
131 132 133 |
# File 'lib/rdf/model/graph.rb', line 131 def durable? false end |
#each {|statement| ... } ⇒ Enumerator
Enumerates each RDF statement in this graph.
204 205 206 |
# File 'lib/rdf/model/graph.rb', line 204 def each(&block) @data.query(:context => context).each(&block) end |
#each_graph(&block) ⇒ Object
259 260 261 |
# File 'lib/rdf/model/graph.rb', line 259 def each_graph(&block) block_given? ? block.call(self) : enum_graph end |
#empty? ⇒ Boolean
Returns ‘true` if this graph contains no RDF statements.
164 165 166 |
# File 'lib/rdf/model/graph.rb', line 164 def empty? @data.empty? end |
#graph? ⇒ Boolean
Returns ‘true` to indicate that this is a graph.
106 107 108 |
# File 'lib/rdf/model/graph.rb', line 106 def graph? true end |
#graphs ⇒ Object
251 252 253 |
# File 'lib/rdf/model/graph.rb', line 251 def graphs enum_graph end |
#has_statement?(statement) ⇒ Boolean
Returns ‘true` if this graph contains the given RDF statement.
191 192 193 194 195 |
# File 'lib/rdf/model/graph.rb', line 191 def has_statement?(statement) statement = statement.dup statement.context = context @data.has_statement?(statement) end |
#load!(*args) ⇒ void
This method returns an undefined value.
94 95 96 97 98 99 100 |
# File 'lib/rdf/model/graph.rb', line 94 def load!(*args) case when args.empty? load(context.to_s, context ? {:base_uri => context}.merge(@options) : @options) else super end end |
#named? ⇒ Boolean
Returns ‘true` if this is a named graph.
114 115 116 |
# File 'lib/rdf/model/graph.rb', line 114 def named? !unnamed? end |
#to_s ⇒ String
Returns a string representation of this graph.
155 156 157 |
# File 'lib/rdf/model/graph.rb', line 155 def to_s named? ? context.to_s : "<>" end |
#to_uri ⇒ RDF::URI
Returns the URI representation of this graph.
147 148 149 |
# File 'lib/rdf/model/graph.rb', line 147 def to_uri context end |
#unnamed? ⇒ Boolean
Returns ‘true` if this is a unnamed graph.
122 123 124 |
# File 'lib/rdf/model/graph.rb', line 122 def unnamed? context.nil? end |