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
Methods included from Value
#inspect, #inspect!, #iri?, #literal?, #node?, #resource?, #statement?, #to_ntriples, #to_rdf, #uri?, #variable?
Constructor Details
- (Graph) initialize(context = nil, options = {}) {|graph| ... }
A new instance of Graph
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rdf/model/graph.rb', line 72 def initialize(context = nil, = {}, &block) @context = case context when nil then nil when RDF::Resource then context else RDF::URI.new(context) end = .dup @data = .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 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.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rdf/model/graph.rb', line 54 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.
161 162 163 |
# File 'lib/rdf/model/graph.rb', line 161 def anonymous? context.nil? ? false : context.anonymous? end |
- (Enumerator<RDF::Resource>) contexts
Returns all unique RDF contexts for this graph.
128 129 130 |
# File 'lib/rdf/model/graph.rb', line 128 def contexts (named? ? [context] : []).to_enum.extend(RDF::Countable) end |
- (Integer) count
Returns the number of RDF statements in this graph.
170 171 172 |
# File 'lib/rdf/model/graph.rb', line 170 def count @data.query(:context => context).count end |
- (Enumerator) each {|statement| ... }
Enumerates each RDF statement in this graph.
193 194 195 |
# File 'lib/rdf/model/graph.rb', line 193 def each(&block) @data.query(:context => context).each(&block) end |
- (Boolean) empty?
Returns true if this graph contains no RDF statements.
153 154 155 |
# File 'lib/rdf/model/graph.rb', line 153 def empty? @data.empty? end |
- (Boolean) graph?
Returns true to indicate that this is a graph.
104 105 106 |
# File 'lib/rdf/model/graph.rb', line 104 def graph? true end |
- (Boolean) has_statement?(statement)
Returns true if this graph contains the given RDF statement.
180 181 182 183 184 |
# File 'lib/rdf/model/graph.rb', line 180 def has_statement?(statement) statement = statement.dup statement.context = context @data.has_statement?(statement) end |
- load!(*args)
This method returns an undefined value.
92 93 94 95 96 97 98 |
# File 'lib/rdf/model/graph.rb', line 92 def load!(*args) case when args.empty? load(context.to_s, context ? {:base_uri => context}.merge() : ) else super end end |
- (Boolean) named?
Returns true if this is a named graph.
112 113 114 |
# File 'lib/rdf/model/graph.rb', line 112 def named? !unnamed? end |
- (String) to_s
Returns a string representation of this graph.
144 145 146 |
# File 'lib/rdf/model/graph.rb', line 144 def to_s named? ? context.to_s : "<>" end |
- (RDF::URI) to_uri
Returns the URI representation of this graph.
136 137 138 |
# File 'lib/rdf/model/graph.rb', line 136 def to_uri context end |
- (Boolean) unnamed?
Returns true if this is a unnamed graph.
120 121 122 |
# File 'lib/rdf/model/graph.rb', line 120 def unnamed? context.nil? end |