Class: RDF::Graph
- Inherits:
-
Object
- Object
- RDF::Graph
- Includes:
- Countable, Durable, Enumerable, Mutable, Queryable, Resource
- Defined in:
- lib/rdf/model/graph.rb
Overview
An RDF graph.
Instance Attribute Summary (collapse)
-
- (RDF::Resource) context
(also: #name)
Name of this graph, if it is part of an Repository Enumerable supporting contexts will have a context.
-
- (RDF::Queryable) data
Queryable backing this graph.
-
- (Hash{Symbol => Object}) options
readonly
Returns the options passed to this graph when it was constructed.
Class Method Summary (collapse)
-
+ (Graph) load(url, options = {}) {|graph| ... }
Creates a new
Graphinstance populated by the RDF data returned by dereferencing the given context URL.
Instance Method Summary (collapse)
-
- (Boolean) ==(other)
Graph equivalence based on the contents of each graph being exactly the same.
-
- (Boolean) anonymous?
Returns
trueif this graph has an anonymous context,falseotherwise. -
- (Enumerator<RDF::Resource>) contexts(options = {})
Returns all unique RDF contexts for this graph.
-
- (Integer) count
Returns the number of RDF statements in this graph.
-
- (Boolean) durable?
A graph is durable if it's underlying data model is durable.
-
- (Enumerator) each {|statement| ... }
Enumerates each RDF statement in this graph.
-
- (Boolean) empty?
Returns
trueif this graph contains no RDF statements. -
- (Boolean) graph?
Returns
trueto indicate that this is a graph. -
- (Boolean) has_statement?(statement)
Returns
trueif this graph contains the given RDF statement. -
- (Graph) initialize(*args) {|graph| ... }
constructor
in the next release it will not.
- - load!(*args)
-
- (Boolean) named?
Returns
trueif this is a named graph. -
- (String) to_s
Returns a string representation of this graph.
-
- (RDF::Resource) to_uri
Returns the Resource representation of this graph.
-
- (Boolean) unnamed?
Returns
trueif this is a unnamed graph.
Methods included from Mutable
#<<, #clear, #delete, #delete_statements, #immutable?, #insert, #load, #method_missing, #mutable?, #update
Methods included from Util::Aliasing::LateBound
Methods included from Writable
#<<, #insert, #insert_graph, #insert_reader, #insert_statements, #writable?
Methods included from Readable
Methods included from Queryable
#first, #first_literal, #first_object, #first_predicate, #first_subject, #first_value, #query, #query_execute
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?, #invalid?, #method_missing, #objects, #predicates, #quads, #statements, #subjects, #supports?, #to_a, #to_hash, #to_set, #triples, #valid?, #validate!
Methods included from Durable
Methods included from Resource
Methods included from Term
#<=>, #eql?, #escape, #term?, #to_base
Methods included from Value
#constant?, #inspect, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #statement?, #term?, #to_nquads, #to_ntriples, #to_rdf, #type_error, #uri?, #valid?, #validate!, #variable?
Constructor Details
- (Graph) initialize(context, options) - (Graph) initialize(options)
Currently, context makes this a named garph;
in the next release it will not
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rdf/model/graph.rb', line 94 def initialize(*args, &block) context = args.shift unless args.first.is_a?(Hash) = args.first || {} @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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RDF::Mutable
Instance Attribute Details
- (RDF::Resource) context Also known as: name
In the next release, only projections from an
Name of this graph, if it is part of an Repository Enumerable supporting contexts will have a context.
44 45 46 |
# File 'lib/rdf/model/graph.rb', line 44 def context @context end |
- (RDF::Queryable) data
Queryable backing this graph.
53 54 55 |
# File 'lib/rdf/model/graph.rb', line 53 def data @data end |
- (Hash{Symbol => Object}) options (readonly)
Returns the options passed to this graph when it was constructed.
36 37 38 |
# File 'lib/rdf/model/graph.rb', line 36 def @options end |
Class Method Details
+ (Graph) load(url, options = {}) {|graph| ... }
Creates a new Graph instance populated by the RDF data returned by
dereferencing the given context URL.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rdf/model/graph.rb', line 66 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
- (Boolean) ==(other)
Graph equivalence based on the contents of each graph being exactly the same. To determine if the have the same meaning, consider rdf-isomorphic.
248 249 250 251 252 |
# File 'lib/rdf/model/graph.rb', line 248 def ==(other) other.is_a?(RDF::Graph) && context == other.context && statements.to_a == other.statements.to_a end |
- (Boolean) anonymous?
The next release, graphs will not be named, this will return true
Returns true if this graph has an anonymous context, false otherwise.
198 199 200 |
# File 'lib/rdf/model/graph.rb', line 198 def anonymous? context.nil? ? false : context.anonymous? end |
- (Enumerator<RDF::Resource>) contexts(options = {})
Returns all unique RDF contexts for this graph.
164 165 166 |
# File 'lib/rdf/model/graph.rb', line 164 def contexts( = {}) (named? ? [context] : []).to_enum.extend(RDF::Countable) end |
- (Integer) count
Returns the number of RDF statements in this graph.
207 208 209 |
# File 'lib/rdf/model/graph.rb', line 207 def count @data.query(:context => context || false).count end |
- (Boolean) durable?
A graph is durable if it's underlying data model is durable
156 157 158 |
# File 'lib/rdf/model/graph.rb', line 156 def durable? @data.durable? end |
- (Enumerator) each {|statement| ... }
Enumerates each RDF statement in this graph.
230 231 232 233 234 235 236 237 238 |
# File 'lib/rdf/model/graph.rb', line 230 def each(&block) if @data.respond_to?(:query) @data.query(:context => context || false, &block) elsif @data.respond_to?(:each) @data.each(&block) else @data.to_a.each(&block) end end |
- (Boolean) empty?
Returns true if this graph contains no RDF statements.
189 190 191 |
# File 'lib/rdf/model/graph.rb', line 189 def empty? !@data.has_context?(context || false) end |
- (Boolean) graph?
Returns true to indicate that this is a graph.
129 130 131 |
# File 'lib/rdf/model/graph.rb', line 129 def graph? true end |
- (Boolean) has_statement?(statement)
Returns true if this graph contains the given RDF statement.
217 218 219 220 221 |
# File 'lib/rdf/model/graph.rb', line 217 def has_statement?(statement) statement = statement.dup statement.context = context @data.has_statement?(statement) end |
- load!(*args)
The next release, graphs will not be named
This method returns an undefined value.
117 118 119 120 121 122 123 |
# File 'lib/rdf/model/graph.rb', line 117 def load!(*args) case when args.empty? load(context.to_s, context ? {:base_uri => context}.merge(@options) : @options) else super end end |
- (Boolean) named?
The next release, graphs will not be named, this will return false
Returns true if this is a named graph.
138 139 140 |
# File 'lib/rdf/model/graph.rb', line 138 def named? !unnamed? end |
- (String) to_s
Returns a string representation of this graph.
180 181 182 |
# File 'lib/rdf/model/graph.rb', line 180 def to_s named? ? context.to_s : "default" end |
- (RDF::Resource) to_uri
Returns the Resource representation of this graph.
172 173 174 |
# File 'lib/rdf/model/graph.rb', line 172 def to_uri context end |
- (Boolean) unnamed?
The next release, graphs will not be named, this will return true
Returns true if this is a unnamed graph.
147 148 149 |
# File 'lib/rdf/model/graph.rb', line 147 def unnamed? context.nil? end |