Class: RDF::AggregateRepo
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb
Overview
Allow graph names to reassigned with queryable
An aggregated RDF datset.
Aggregates the default and named graphs from one or more instances implementing RDF::Queryable. By default, the aggregate projects no default or named graphs, which must be added explicitly.
Adding the existing default graph (identified with the name false
)
adds the merge of all default graphs from the specified queryable
instances.
Adding a named graph, adds the last graph found having that name
from the specified queryable
instances.
Updating a previously non-existing named graph, appends to the last source. Updating the default graph updates to the merge of the graphs.
Defined Under Namespace
Modules: VERSION
Constant Summary
Constants inherited from Dataset
Dataset::DEFAULT_GRAPH, Dataset::ISOLATION_LEVELS
Instance Attribute Summary collapse
-
#defaults ⇒ Array<RDF::URI, false>
readonly
Names of the named graphs making up the default graph, or false, if it is made up from the merger of all default graphs.
-
#sources ⇒ Array<RDF::Queryable>
readonly
The set of aggregated
queryable
instances included in this aggregate.
Attributes included from Enumerable
Instance Method Summary collapse
-
#count ⇒ Integer
Returns the number of RDF statements in all constituent graphs.
-
#default(*names) ⇒ RDF::AggregateRepo
Set the default graph based on zero or more named graphs, or the merge of all default graphs if
false
. -
#default_graph ⇒ RDF::Graph
Default graph of this aggregate, either a projection of the source default graph (if
false
), a particular named graph from the last source in which it appears, or a MergeGraph composed of the graphs which compose it. -
#durable? ⇒ Boolean
Returns
true
all constituent graphs are durable. -
#each {|statement| ... } ⇒ Enumerator
Enumerates each RDF statement in constituent graphs.
-
#each_graph(&block) ⇒ Object
Iterate over each graph, in order, finding named graphs from the most recently added
source
. -
#each_statement(&block)
Iterates the given block for each RDF statement.
-
#empty? ⇒ Boolean
Returns
true
if all constituent graphs are empty. -
#has_graph?(value) ⇒ Boolean
Returns
true
if any constituent grahp contains the given RDF graph. -
#has_statement?(statement) ⇒ Boolean
Returns
true
if any constituent graph contains the given RDF statement. -
#initialize(queryable = [], **options) {|aggregation| ... } ⇒ AggregateRepo
constructor
Create a new aggregation instance.
-
#named(name) ⇒ RDF::AggregateRepo
Add a named graph projection.
-
#query_pattern(pattern, **options) {|statement| ... }
protected
Queries each constituent graph for RDF statements matching the given
pattern
, yielding each matched statement to the given block. -
#source(queryable) ⇒ RDF::AggregateRepo
(also: #add)
Add a queryable to the set of constituent queryable instances.
-
#writable? ⇒ false
Not writable.
Methods inherited from Dataset
#inspect, #inspect!, #isolation_level
Methods included from Queryable
#concise_bounded_description, #first, #first_literal, #first_object, #first_predicate, #first_subject, #first_value, #lint, #query, #query_execute, #query_without_sparql, #to_sparql
Methods included from Durable
Methods included from Util::Aliasing::LateBound
Methods included from Enumerable
add_entailment, #canonicalize, #canonicalize!, #dump, #each_object, #each_predicate, #each_quad, #each_subject, #each_term, #each_triple, #entail, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph?, #graph_names, #invalid?, #method_missing, #object?, #objects, #predicate?, #predicates, #project_graph, #quad?, #quads, #respond_to_missing?, #statement?, #statements, #subject?, #subjects, #term?, #terms, #to_a, #to_h, #to_set, #triple?, #triples, #valid?, #validate!
Methods included from Isomorphic
#bijection_to, #isomorphic_with?
Constructor Details
#initialize(queryable = [], **options) {|aggregation| ... } ⇒ AggregateRepo
Create a new aggregation instance.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 61 def initialize(*queryable, &block) @options = queryable.last.is_a?(Hash) ? queryable.pop.dup : {} @sources = queryable @defaults = [] @named_graphs = [] 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::Enumerable
Instance Attribute Details
#defaults ⇒ Array<RDF::URI, false> (readonly)
Names of the named graphs making up the default graph, or false, if it is made up from the merger of all default graphs
50 51 52 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 50 def defaults @defaults end |
#sources ⇒ Array<RDF::Queryable> (readonly)
The set of aggregated queryable
instances included in this aggregate
42 43 44 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 42 def sources @sources end |
Instance Method Details
#count ⇒ Integer
Returns the number of RDF statements in all constituent graphs.
156 157 158 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 156 def count each_graph.to_a.reduce(0) {|memo, g| memo += g.count} end |
#default(*names) ⇒ RDF::AggregateRepo
Set the default graph based on zero or more
named graphs, or the merge of all default graphs if false
93 94 95 96 97 98 99 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 93 def default(*names) if names.any? {|n| n == false} && names.length > 1 raise ArgumentError, "If using merge of default graphs, there can be only one" end @default_graph = nil @defaults = names end |
#default_graph ⇒ RDF::Graph
Default graph of this aggregate, either a projection of the source
default graph (if false
), a particular named graph from the
last source in which it appears, or a MergeGraph composed of the
graphs which compose it.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 259 def default_graph @default_graph ||= begin case when sources.length == 0 || defaults.length == 0 RDF::Graph.new when defaults == [false] && sources.length == 1 # Trivial case RDF::Graph.new(data: sources.first) else # Otherwise, create a MergeGraph from the set of pairs of source and graph_name RDF::MergeGraph.new(name: nil) do |graph| if defaults == [false] sources.each do |s| # Add default graph from each source graph.source s, false end else defaults.each do |graph_name| # add the named graph graph.source sources.reverse.detect {|s| s.has_graph?(graph_name)}, graph_name end end end end end end |
#durable? ⇒ Boolean
Returns true
all constituent graphs are durable.
138 139 140 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 138 def durable? sources.all?(&:durable?) end |
#each {|statement| ... } ⇒ Enumerator
Enumerates each RDF statement in constituent graphs
205 206 207 208 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 205 def each(&block) return to_enum unless block_given? each_graph {|g| g.each(&block)} end |
#each_graph {|graph| ... } #each_graph ⇒ Enumerator<RDF::Graph>
Iterate over each graph, in order, finding named graphs from the most recently added source
.
If no block was given, returns an enumerator.
The order in which graphs are yielded is undefined.
239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 239 def each_graph(&block) if block_given? yield default_graph # Send graph from appropriate source @named_graphs.each do |graph_name| source = sources.reverse.detect {|s| s.has_graph?(graph_name)} block.call(RDF::Graph.new(graph_name: graph_name, data: source)) end end enum_graph end |
#each_statement {|statement| ... } #each_statement ⇒ Enumerator
This method returns an undefined value.
Iterates the given block for each RDF statement.
If no block was given, returns an enumerator.
The order in which statements are yielded is undefined.
190 191 192 193 194 195 196 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 190 def each_statement(&block) if block_given? # Invoke {#each} in the containing class: each(&block) end enum_statement end |
#empty? ⇒ Boolean
Returns true
if all constituent graphs are empty.
147 148 149 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 147 def empty? count == 0 end |
#has_graph?(value) ⇒ Boolean
Returns true
if any constituent grahp contains the given RDF graph.
217 218 219 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 217 def has_graph?(value) @named_graphs.include?(value) end |
#has_statement?(statement) ⇒ Boolean
Returns true
if any constituent graph contains the given RDF statement.
166 167 168 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 166 def has_statement?(statement) each_graph.any? {|g| g.has_statement?(statement) && statement.graph_name == g.graph_name} end |
#named(name) ⇒ RDF::AggregateRepo
Add a named graph projection. Dynamically binds to the
last queryable
having a matching graph.
107 108 109 110 111 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 107 def named(name) raise ArgumentError, "name must be an RDF::Resource: #{name.inspect}" unless name.is_a?(RDF::Resource) raise ArgumentError, "name does not exist in loaded sources" unless sources.any?{|s| s.has_graph?(name)} @named_graphs << name end |
#query_pattern(pattern, **options) {|statement| ... } (protected)
This method returns an undefined value.
Queries each constituent graph for RDF statements matching the given pattern
, yielding each matched statement to the given block.
If called without a block, returns an enumerator
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 300 def query_pattern(pattern, **, &block) return enum_for(:query_pattern, pattern, **) unless block_given? case pattern.graph_name when nil # Query against all graphs each_graph {|graph| graph.send(:query_pattern, pattern, **, &block)} when FalseClass # Query against default graph only default_graph.send(:query_pattern, pattern, **, &block) when RDF::Query::Variable # Query against all named graphs each_graph do |graph| source = sources.reverse.detect {|s| s.has_graph?(graph.graph_name)} RDF::Graph.new(graph_name: graph.graph_name, data: source).send(:query_pattern, pattern, **, &block) end else # Query against a specific graph if @named_graphs.include?(pattern.graph_name) source = sources.reverse.detect {|s| s.has_graph?(pattern.graph_name)} RDF::Graph.new(graph_name: pattern.graph_name, data: source).send(:query_pattern, pattern, **, &block) end end end |
#source(queryable) ⇒ RDF::AggregateRepo Also known as: add
Add a queryable to the set of constituent queryable instances
80 81 82 83 84 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 80 def source(queryable) @sources << queryable @default_graph = nil self end |
#writable? ⇒ false
Not writable
131 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-aggregate-repo-cb93fb3485bc/lib/rdf/aggregate_repo.rb', line 131 def writable?; false; end |