Class: RDF::MergeGraph
- Inherits:
-
Object
- Object
- RDF::MergeGraph
- Includes:
- Countable, Enumerable, Queryable, Value
- Defined in:
- lib/rdf/aggregate_repo/merge_graph.rb
Overview
A Merged graph.
Implements a merged graph, containing statements from one or more source graphs. This is done through lazy evaluation of the sources, so that a copy of each source isn’t required.
This class can also be used to change the context (graph name) of triples from the name used in the source.
Instance Attribute Summary collapse
-
#graph_name ⇒ Array<RDF::URI, false>
readonly
Name of this graph, used for setting the context on returned ‘Statements`.
-
#sources ⇒ Array<Array<(RDF::Queryable, RDF::Resource)>>
readonly
The set of aggregated ‘queryable` instances included in this aggregate.
Instance Method Summary collapse
- #count ⇒ Object
- #durable? ⇒ Boolean
- #each(&block) ⇒ Object
-
#each_graph(&block) ⇒ Object
Iterate over each graph, in order, finding named graphs from the most recently added ‘source`.
- #empty? ⇒ Boolean
-
#graph? ⇒ Boolean
Returns ‘true` to indicate that this is a graph.
- #has_graph?(value) ⇒ Boolean
- #has_statement?(statement) ⇒ Boolean
-
#initialize(queryable = [], options = {}) {|self| ... } ⇒ MergeGraph
constructor
Create a new aggregation instance.
-
#name(name) ⇒ RDF::MergeGraph
Set the graph_name for statements in this graph.
-
#named? ⇒ Boolean
Returns ‘true` if this is a named graph.
-
#source(queryable, graph_name) ⇒ RDF::MergeGraph
(also: #add)
Add a queryable to the set of constituent queryable instances.
-
#unnamed? ⇒ Boolean
Returns ‘true` if this is a unnamed graph.
-
#writable? ⇒ Boolean
MergeGraph is writable if any source is writable.
Constructor Details
#initialize(queryable = [], options = {}) {|self| ... } ⇒ MergeGraph
Create a new aggregation instance.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 50 def initialize( = {}, &block) @sources = [] @graph_name = [:graph_name] || [:name] if block_given? case block.arity when 1 then block.call(self) else instance_eval(&block) end end end |
Instance Attribute Details
#graph_name ⇒ Array<RDF::URI, false> (readonly)
Name of this graph, used for setting the context on returned ‘Statements`.
38 39 40 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 38 def graph_name @graph_name end |
#sources ⇒ Array<Array<(RDF::Queryable, RDF::Resource)>> (readonly)
The set of aggregated ‘queryable` instances included in this aggregate
32 33 34 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 32 def sources @sources end |
Instance Method Details
#count ⇒ Object
138 139 140 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 138 def count each_statement.to_a.length end |
#durable? ⇒ Boolean
124 125 126 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 124 def durable? sources.all? {|(source, ctx)| source.durable?} end |
#each(&block) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 155 def each(&block) return enum_for(:each) unless block_given? # Add everything to a new graph for de-duplication tmp = RDF::Graph.new(graph_name: @graph_name, data: RDF::Repository.new) sources.each do |(source, gn)| tmp << RDF::Graph.new(graph_name: gn || nil, data: source) end tmp.each(&block) end |
#each_graph(&block) ⇒ Object
Iterate over each graph, in order, finding named graphs from the most recently added ‘source`.
177 178 179 180 181 182 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 177 def each_graph(&block) if block_given? yield self end enum_graph end |
#empty? ⇒ Boolean
131 132 133 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 131 def empty? count == 0 end |
#graph? ⇒ Boolean
Returns ‘true` to indicate that this is a graph.
67 68 69 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 67 def graph? true end |
#has_graph?(value) ⇒ Boolean
169 170 171 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 169 def has_graph?(value) @graph_name == value end |
#has_statement?(statement) ⇒ Boolean
145 146 147 148 149 150 151 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 145 def has_statement?(statement) sources.any? do |(source, ctx)| statement = statement.dup statement.graph_name = ctx source.has_statement?(statement) end end |
#name(name) ⇒ RDF::MergeGraph
Set the graph_name for statements in this graph
114 115 116 117 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 114 def name(name) @graph_name = name self end |
#named? ⇒ Boolean
The next release, graphs will not be named, this will return false
Returns ‘true` if this is a named graph.
76 77 78 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 76 def named? !unnamed? end |
#source(queryable, graph_name) ⇒ RDF::MergeGraph Also known as: add
Add a queryable to the set of constituent queryable instances
103 104 105 106 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 103 def source(queryable, graph_name) @sources << [queryable, graph_name] self end |
#unnamed? ⇒ Boolean
The next release, graphs will not be named, this will return true
Returns ‘true` if this is a unnamed graph.
85 86 87 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 85 def unnamed? @graph_name.nil? end |
#writable? ⇒ Boolean
MergeGraph is writable if any source is writable. Updates go to the last writable source.
93 94 95 |
# File 'lib/rdf/aggregate_repo/merge_graph.rb', line 93 def writable? sources.any? {|(source, ctx)| source.writable?} end |