Class: RDF::Graph
- Inherits:
-
Object
- Object
- RDF::Graph
- Includes:
- Countable, Enumerable, Mutable, Queryable, Resource
- Defined in:
- lib/rdf/model/graph.rb
Overview
An RDF graph.
Instance Attribute Summary (collapse)
- - (RDF::Resource) context
- - (RDF::Queryable) data
-
- (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) anonymous?
Returns
trueif this graph has an anonymous context,falseotherwise. -
- (Enumerator<RDF::Resource>) contexts
Returns all unique RDF contexts for this graph.
-
- (Integer) count
Returns the number of RDF statements in this graph.
-
- (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(context = nil, options = {}) {|graph| ... }
constructor
A new instance of Graph.
- - load!(*args)
-
- (Boolean) named?
Returns
trueif this is a named graph. -
- (String) to_s
Returns a string representation of this graph.
-
- (RDF::URI) to_uri
Returns the URI representation of this graph.
-
- (Boolean) unnamed?
Returns
trueif this is a unnamed graph.
Methods included from Mutable
#<<, #clear, #delete, #delete_statements, #immutable?, #insert, #load, #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?, #objects, #predicates, #quads, #statements, #subjects, #to_a, #to_hash, #to_set, #triples
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
- (Graph) initialize(context = nil, options = {}) {|graph| ... }
A new instance of Graph
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rdf/model/graph.rb', line 73 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
- (RDF::Resource) context
38 39 40 |
# File 'lib/rdf/model/graph.rb', line 38 def context @context end |
- (Hash{Symbol => Object}) options (readonly)
Returns the options passed to this graph when it was constructed.
34 35 36 |
# File 'lib/rdf/model/graph.rb', line 34 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.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rdf/model/graph.rb', line 55 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) anonymous?
Returns true if this graph has an anonymous context, false otherwise.
162 163 164 |
# File 'lib/rdf/model/graph.rb', line 162 def anonymous? context.nil? ? false : context.anonymous? end |
- (Enumerator<RDF::Resource>) contexts
Returns all unique RDF contexts for this graph.
129 130 131 |
# File 'lib/rdf/model/graph.rb', line 129 def contexts (named? ? [context] : []).to_enum.extend(RDF::Countable) end |
- (Integer) count
Returns the number of RDF statements in this graph.
171 172 173 |
# File 'lib/rdf/model/graph.rb', line 171 def count @data.query(:context => context).count end |
- (Enumerator) each {|statement| ... }
Enumerates each RDF statement in this graph.
194 195 196 |
# File 'lib/rdf/model/graph.rb', line 194 def each(&block) @data.query(:context => context).each(&block) end |
- (Boolean) empty?
Returns true if this graph contains no RDF statements.
154 155 156 |
# File 'lib/rdf/model/graph.rb', line 154 def empty? @data.empty? end |
- (Boolean) graph?
Returns true to indicate that this is a graph.
105 106 107 |
# File 'lib/rdf/model/graph.rb', line 105 def graph? true end |
- (Boolean) has_statement?(statement)
Returns true if this graph contains the given RDF statement.
181 182 183 184 185 |
# File 'lib/rdf/model/graph.rb', line 181 def has_statement?(statement) statement = statement.dup statement.context = context @data.has_statement?(statement) end |
- load!(*args)
This method returns an undefined value.
93 94 95 96 97 98 99 |
# File 'lib/rdf/model/graph.rb', line 93 def load!(*args) case when args.empty? load(context.to_s, context ? {:base_uri => context}.merge(@options) : @options) else super end end |
- (Boolean) named?
Returns true if this is a named graph.
113 114 115 |
# File 'lib/rdf/model/graph.rb', line 113 def named? !unnamed? end |
- (String) to_s
Returns a string representation of this graph.
145 146 147 |
# File 'lib/rdf/model/graph.rb', line 145 def to_s named? ? context.to_s : "<>" end |
- (RDF::URI) to_uri
Returns the URI representation of this graph.
137 138 139 |
# File 'lib/rdf/model/graph.rb', line 137 def to_uri context end |
- (Boolean) unnamed?
Returns true if this is a unnamed graph.
121 122 123 |
# File 'lib/rdf/model/graph.rb', line 121 def unnamed? context.nil? end |