rdf-aggregate-repo 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/rdf/aggregate_repo/merge_graph.rb +7 -0
- data/lib/rdf/aggregate_repo.rb +104 -11
- metadata +2 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -190,7 +190,14 @@ module RDF
|
|
190
190
|
protected
|
191
191
|
|
192
192
|
##
|
193
|
+
# @private
|
194
|
+
# @see RDF::Queryable#query_pattern
|
193
195
|
def query_pattern(pattern, &block)
|
196
|
+
pattern = pattern.dup
|
197
|
+
sources.each do |(source, ctx)|
|
198
|
+
pattern.context = ctx
|
199
|
+
source.send(:query_pattern, pattern, &block)
|
200
|
+
end
|
194
201
|
end
|
195
202
|
end
|
196
203
|
end
|
data/lib/rdf/aggregate_repo.rb
CHANGED
@@ -119,35 +119,60 @@ module RDF
|
|
119
119
|
def writable?; false; end
|
120
120
|
|
121
121
|
##
|
122
|
-
#
|
122
|
+
# Returns `true` all constituent graphs are durable.
|
123
|
+
#
|
124
|
+
# @return [Boolean]
|
123
125
|
# @see RDF::Durable#durable?
|
124
126
|
def durable?
|
125
127
|
sources.all?(&:durable?)
|
126
128
|
end
|
127
129
|
|
128
130
|
##
|
129
|
-
#
|
131
|
+
# Returns `true` if all constituent graphs are empty.
|
132
|
+
#
|
133
|
+
# @return [Boolean]
|
130
134
|
# @see RDF::Countable#empty?
|
131
135
|
def empty?
|
132
136
|
count == 0
|
133
137
|
end
|
134
138
|
|
135
139
|
##
|
136
|
-
#
|
140
|
+
# Returns the number of RDF statements in all constituent graphs.
|
141
|
+
#
|
142
|
+
# @return [Integer]
|
137
143
|
# @see RDF::Countable#count
|
138
144
|
def count
|
139
145
|
each_graph.to_a.reduce(0) {|memo, g| memo += g.count}
|
140
146
|
end
|
141
147
|
|
142
148
|
##
|
143
|
-
#
|
149
|
+
# Returns `true` if any constituent graph contains the given RDF statement.
|
150
|
+
#
|
151
|
+
# @param [RDF::Statement] statement
|
152
|
+
# @return [Boolean]
|
144
153
|
# @see RDF::Enumerable#has_statement?
|
145
154
|
def has_statement?(statement)
|
146
155
|
each_graph.to_a.any? {|g| g.has_statement?(statement)}
|
147
156
|
end
|
148
157
|
|
149
158
|
##
|
150
|
-
#
|
159
|
+
# Iterates the given block for each RDF statement.
|
160
|
+
#
|
161
|
+
# If no block was given, returns an enumerator.
|
162
|
+
#
|
163
|
+
# The order in which statements are yielded is undefined.
|
164
|
+
#
|
165
|
+
# @overload each_statement
|
166
|
+
# @yield [statement]
|
167
|
+
# each statement
|
168
|
+
# @yieldparam [RDF::Statement] statement
|
169
|
+
# @yieldreturn [void] ignored
|
170
|
+
# @return [void]
|
171
|
+
#
|
172
|
+
# @overload each_statement
|
173
|
+
# @return [Enumerator]
|
174
|
+
#
|
175
|
+
# @return [void]
|
151
176
|
# @see RDF::Repository#each_statement
|
152
177
|
# @see RDF::Enumerable#each_statement
|
153
178
|
def each_statement(&block)
|
@@ -159,23 +184,46 @@ module RDF
|
|
159
184
|
end
|
160
185
|
|
161
186
|
##
|
162
|
-
#
|
187
|
+
# Enumerates each RDF statement in constituent graphs
|
188
|
+
#
|
189
|
+
# @yield [statement]
|
190
|
+
# @yieldparam [Statement] statement
|
191
|
+
# @return [Enumerator]
|
163
192
|
# @see RDF::Enumerable#each
|
164
193
|
def each(&block)
|
165
|
-
|
166
|
-
|
167
|
-
end
|
194
|
+
return to_enum unless block_given?
|
195
|
+
each_graph {|g| g.each(&block)}
|
168
196
|
end
|
169
197
|
|
170
198
|
##
|
171
|
-
#
|
199
|
+
# Returns `true` if any constituent grahp contains the given RDF context.
|
200
|
+
#
|
201
|
+
# @param [RDF::Resource, false] value
|
202
|
+
# Use value `false` to query for the default context
|
203
|
+
# @return [Boolean]
|
172
204
|
# @see RDF::Enumerable#has_context?
|
173
205
|
def has_context?(value)
|
174
206
|
@contexts.include?(value)
|
175
207
|
end
|
176
208
|
|
177
209
|
##
|
178
|
-
#
|
210
|
+
# Iterates the given block for each unique RDF context, other than the default context.
|
211
|
+
#
|
212
|
+
# If no block was given, returns an enumerator.
|
213
|
+
#
|
214
|
+
# The order in which values are yielded is undefined.
|
215
|
+
#
|
216
|
+
# @overload each_context
|
217
|
+
# @yield [context]
|
218
|
+
# each context term
|
219
|
+
# @yieldparam [RDF::Resource] context
|
220
|
+
# @yieldreturn [void] ignored
|
221
|
+
# @return [void]
|
222
|
+
#
|
223
|
+
# @overload each_context
|
224
|
+
# @return [Enumerator]
|
225
|
+
#
|
226
|
+
# @return [void]
|
179
227
|
# @see RDF::Enumerable#each_context
|
180
228
|
def each_context(&block)
|
181
229
|
if block_given?
|
@@ -188,6 +236,21 @@ module RDF
|
|
188
236
|
##
|
189
237
|
# Iterate over each graph, in order, finding named graphs from the most recently added `source`.
|
190
238
|
#
|
239
|
+
# If no block was given, returns an enumerator.
|
240
|
+
#
|
241
|
+
# The order in which graphs are yielded is undefined.
|
242
|
+
#
|
243
|
+
# @overload each_graph
|
244
|
+
# @yield [graph]
|
245
|
+
# each graph
|
246
|
+
# @yieldparam [RDF::Graph] graph
|
247
|
+
# @yieldreturn [void] ignored
|
248
|
+
# @return [void]
|
249
|
+
#
|
250
|
+
# @overload each_graph
|
251
|
+
# @return [Enumerator]
|
252
|
+
#
|
253
|
+
# @return [void]
|
191
254
|
# @see RDF::Enumerable#each_graph
|
192
255
|
def each_graph(&block)
|
193
256
|
if block_given?
|
@@ -205,7 +268,37 @@ module RDF
|
|
205
268
|
protected
|
206
269
|
|
207
270
|
##
|
271
|
+
# Queries each constituent graph for RDF statements matching the given `pattern`,
|
272
|
+
# yielding each matched statement to the given block.
|
273
|
+
#
|
274
|
+
# @param [RDF::Query::Pattern] pattern
|
275
|
+
# the query pattern to match
|
276
|
+
# @yield [statement]
|
277
|
+
# @yieldparam [RDF::Statement] statement
|
278
|
+
# @yieldreturn [void] ignored
|
279
|
+
# @return [void] ignored
|
280
|
+
# @see RDF::Queryable#query_pattern
|
208
281
|
def query_pattern(pattern, &block)
|
282
|
+
case pattern.context
|
283
|
+
when nil
|
284
|
+
# Query against all graphs
|
285
|
+
each_graph {|graph| graph.send(:query_pattern, pattern, &block)}
|
286
|
+
when FalseClass
|
287
|
+
# Query against default graph only
|
288
|
+
default_graph.send(:query_pattern, pattern, &block)
|
289
|
+
when RDF::Query::Variable
|
290
|
+
# Query against all named graphs
|
291
|
+
each_context do |context|
|
292
|
+
source = sources.reverse.detect {|s| s.has_context?(context)}
|
293
|
+
RDF::Graph.new(context, :data => source).send(:query_pattern, pattern, &block)
|
294
|
+
end
|
295
|
+
else
|
296
|
+
# Query against a specific context
|
297
|
+
if @contexts.include?(pattern.context)
|
298
|
+
source = sources.reverse.detect {|s| s.has_context?(pattern.context)}
|
299
|
+
RDF::Graph.new(pattern.context, :data => source).send(:query_pattern, pattern, &block)
|
300
|
+
end
|
301
|
+
end
|
209
302
|
end
|
210
303
|
|
211
304
|
##
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-aggregate-repo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdf
|
@@ -108,9 +108,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- - ! '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
segments:
|
112
|
-
- 0
|
113
|
-
hash: 2958421905290465049
|
114
111
|
requirements: []
|
115
112
|
rubyforge_project:
|
116
113
|
rubygems_version: 1.8.25
|