rdf 1.1.17.1 → 1.99.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.
- checksums.yaml +4 -4
- data/README +9 -9
- data/VERSION +1 -1
- data/lib/rdf/cli.rb +10 -10
- data/lib/rdf/format.rb +9 -9
- data/lib/rdf/mixin/enumerable.rb +66 -38
- data/lib/rdf/mixin/mutable.rb +11 -5
- data/lib/rdf/mixin/queryable.rb +2 -2
- data/lib/rdf/model/graph.rb +60 -40
- data/lib/rdf/model/list.rb +9 -9
- data/lib/rdf/model/literal/boolean.rb +1 -1
- data/lib/rdf/model/literal/date.rb +1 -1
- data/lib/rdf/model/literal/datetime.rb +5 -5
- data/lib/rdf/model/literal/decimal.rb +1 -1
- data/lib/rdf/model/literal/double.rb +3 -1
- data/lib/rdf/model/literal/integer.rb +1 -1
- data/lib/rdf/model/literal/time.rb +5 -5
- data/lib/rdf/model/literal/token.rb +1 -1
- data/lib/rdf/model/literal.rb +40 -6
- data/lib/rdf/model/node.rb +1 -1
- data/lib/rdf/model/statement.rb +88 -30
- data/lib/rdf/model/term.rb +10 -1
- data/lib/rdf/model/uri.rb +24 -25
- data/lib/rdf/nquads.rb +13 -22
- data/lib/rdf/ntriples/format.rb +4 -5
- data/lib/rdf/ntriples/reader.rb +10 -10
- data/lib/rdf/ntriples/writer.rb +6 -6
- data/lib/rdf/query/pattern.rb +49 -35
- data/lib/rdf/query/solution.rb +1 -1
- data/lib/rdf/query/solutions.rb +4 -4
- data/lib/rdf/query.rb +81 -40
- data/lib/rdf/reader.rb +22 -5
- data/lib/rdf/repository.rb +86 -37
- data/lib/rdf/transaction.rb +41 -20
- data/lib/rdf/util/file.rb +35 -18
- data/lib/rdf/vocab/schema.rb +5129 -5127
- data/lib/rdf/vocabulary.rb +43 -60
- data/lib/rdf/writer.rb +22 -12
- data/lib/rdf.rb +19 -4
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5459870c2250fc3eb1ce868c6707b2fd20664ee4
|
4
|
+
data.tar.gz: be34a5df00dff4f60336ad287e50cf2d480bf5a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed6a295b07e4fce0204a18ba1fe9d544f1a49af2baae95c5dea6da944db6d2eeae0176b479f279ebfac0874b1bcbda27b52438c0dc2d147aabfe12549f9ef920
|
7
|
+
data.tar.gz: d20fcf6cd98b1928afbc149223b49f6dee9c35f6aa38e325808fdd69f2b1b546f22675ad7cec880871c8cd4a19157db691659bcd80b0847d3b51868dfb54cbd6
|
data/README
CHANGED
@@ -92,7 +92,7 @@ operations on RDF files using available readers and writers.
|
|
92
92
|
### Writing RDF data using the [N-Triples][] format
|
93
93
|
|
94
94
|
require 'rdf/ntriples'
|
95
|
-
graph = RDF::Graph.new << [:hello, RDF::
|
95
|
+
graph = RDF::Graph.new << [:hello, RDF::RDFS.label, "Hello, world!"]
|
96
96
|
graph.dump(:ntriples)
|
97
97
|
|
98
98
|
or
|
@@ -114,13 +114,13 @@ or
|
|
114
114
|
|
115
115
|
### Reading RDF data in other formats
|
116
116
|
{RDF::Reader.open} and {RDF::Repository.load} use a number of mechanisms to determine the appropriate reader
|
117
|
-
to use when loading a file. The specific format to use can be forced using, e.g.
|
117
|
+
to use when loading a file. The specific format to use can be forced using, e.g. `format: :ntriples`
|
118
118
|
option where the specific format symbol is determined by the available readers. Both also use
|
119
119
|
MimeType or file extension, where available.
|
120
120
|
|
121
121
|
require 'rdf/nquads'
|
122
122
|
|
123
|
-
graph = RDF::Graph.load("http://ruby-rdf.github.com/rdf/etc/doap.nq", :
|
123
|
+
graph = RDF::Graph.load("http://ruby-rdf.github.com/rdf/etc/doap.nq", format: :nquads)
|
124
124
|
|
125
125
|
A specific sub-type of Reader can also be invoked directly:
|
126
126
|
|
@@ -144,9 +144,9 @@ appropriate writer to use.
|
|
144
144
|
|
145
145
|
require 'linkeddata'
|
146
146
|
|
147
|
-
RDF::Writer.open("hello.nq", :
|
147
|
+
RDF::Writer.open("hello.nq", format: :nquads) do |writer|
|
148
148
|
writer << RDF::Repository.new do |repo|
|
149
|
-
repo << RDF::Statement.new(:hello, RDF::
|
149
|
+
repo << RDF::Statement.new(:hello, RDF::RDFS.label, "Hello, world!", context: RDF::URI("context"))
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -154,14 +154,14 @@ A specific sub-type of Writer can also be invoked directly:
|
|
154
154
|
|
155
155
|
require 'rdf/nquads'
|
156
156
|
|
157
|
-
repo = RDF::Repository.new << RDF::Statement.new(:hello, RDF::
|
157
|
+
repo = RDF::Repository.new << RDF::Statement.new(:hello, RDF::RDFS.label, "Hello, world!", context: RDF::URI("context"))
|
158
158
|
File.open("hello.nq", "w") {|f| f << repo.dump(:nquads)}
|
159
159
|
|
160
160
|
## Reader/Writer convenience methods
|
161
161
|
{RDF::Enumerable} implements `to_{format}` for each available instance of {RDF::Reader}.
|
162
162
|
For example, if `rdf/turtle` is loaded, this allows the following:
|
163
163
|
|
164
|
-
graph = RDF::Graph.new << [:hello, RDF::
|
164
|
+
graph = RDF::Graph.new << [:hello, RDF::RDFS.label, "Hello, world!"]
|
165
165
|
graph.to_ttl
|
166
166
|
|
167
167
|
Similarly, {RDF::Mutable} implements `from_{format}` for each available instance
|
@@ -172,7 +172,7 @@ of {RDF::Writer}. For example:
|
|
172
172
|
|
173
173
|
Note that no prefixes are loaded automatically, however they can be provided as arguments:
|
174
174
|
|
175
|
-
graph.from_ttl("[ a rdf:Resource]", :
|
175
|
+
graph.from_ttl("[ a rdf:Resource]", prefixes: {rdf: RDF.to_uri})
|
176
176
|
|
177
177
|
### Querying RDF data using basic graph patterns (BGPs)
|
178
178
|
|
@@ -180,7 +180,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
|
|
180
180
|
|
181
181
|
graph = RDF::Graph.load("http://ruby-rdf.github.com/rdf/etc/doap.nt")
|
182
182
|
query = RDF::Query.new({
|
183
|
-
:
|
183
|
+
person: {
|
184
184
|
RDF.type => FOAF.Person,
|
185
185
|
FOAF.name => :name,
|
186
186
|
FOAF.mbox => :email,
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.99.0
|
data/lib/rdf/cli.rb
CHANGED
@@ -62,8 +62,8 @@ module RDF
|
|
62
62
|
writer_class = RDF::Writer.for(opts[:output_format]) || RDF::NTriples::Writer
|
63
63
|
out = opts[:output] || $stdout
|
64
64
|
out.set_encoding(Encoding::UTF_8) if out.respond_to?(:set_encoding) && RUBY_PLATFORM == "java"
|
65
|
-
opts = opts.merge(:
|
66
|
-
writer_opts = opts.merge(:
|
65
|
+
opts = opts.merge(prefixes: {})
|
66
|
+
writer_opts = opts.merge(standard_prefixes: true)
|
67
67
|
self.parse(argv, opts) do |reader|
|
68
68
|
writer_class.new(out, writer_opts) do |writer|
|
69
69
|
writer << reader
|
@@ -91,14 +91,14 @@ module RDF
|
|
91
91
|
def self.options(&block)
|
92
92
|
options = OptionParser.new
|
93
93
|
opts = options.options = {
|
94
|
-
:
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
98
|
-
:
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
94
|
+
base_uri: nil,
|
95
|
+
canonicalize: false,
|
96
|
+
debug: false,
|
97
|
+
evaluate: nil,
|
98
|
+
format: nil,
|
99
|
+
output: $stdout,
|
100
|
+
output_format: :ntriples,
|
101
|
+
validate: false,
|
102
102
|
}
|
103
103
|
|
104
104
|
# Command-specific options
|
data/lib/rdf/format.rb
CHANGED
@@ -11,19 +11,19 @@ module RDF
|
|
11
11
|
# @example Getting a serialization format class
|
12
12
|
# RDF::Format.for(:ntriples) #=> RDF::NTriples::Format
|
13
13
|
# RDF::Format.for("etc/doap.nt")
|
14
|
-
# RDF::Format.for(:
|
15
|
-
# RDF::Format.for(:
|
16
|
-
# RDF::Format.for(:
|
14
|
+
# RDF::Format.for(file_name: "etc/doap.nt")
|
15
|
+
# RDF::Format.for(file_extension: "nt")
|
16
|
+
# RDF::Format.for(content_type: "application/n-triples")
|
17
17
|
#
|
18
18
|
# @example Obtaining serialization format MIME types
|
19
19
|
# RDF::Format.content_types #=> {"application/n-triples" => [RDF::NTriples::Format]}
|
20
20
|
#
|
21
21
|
# @example Obtaining serialization format file extension mappings
|
22
|
-
# RDF::Format.file_extensions #=> {:
|
22
|
+
# RDF::Format.file_extensions #=> {nt: [RDF::NTriples::Format]}
|
23
23
|
#
|
24
24
|
# @example Defining a new RDF serialization format class
|
25
25
|
# class RDF::NTriples::Format < RDF::Format
|
26
|
-
# content_type 'application/n-triples', :
|
26
|
+
# content_type 'application/n-triples', extension: :nt
|
27
27
|
# content_encoding 'utf-8'
|
28
28
|
#
|
29
29
|
# reader RDF::NTriples::Reader
|
@@ -95,7 +95,7 @@ module RDF
|
|
95
95
|
format = case options
|
96
96
|
when String
|
97
97
|
# Find a format based on the file name
|
98
|
-
self.for(:
|
98
|
+
self.for(file_name: options) { yield if block_given? }
|
99
99
|
|
100
100
|
when Hash
|
101
101
|
case
|
@@ -112,7 +112,7 @@ module RDF
|
|
112
112
|
content_types[mime_type] unless mime_type == 'text/plain' && (options[:sample] || block_given?)
|
113
113
|
# Find a format based on the file name:
|
114
114
|
when file_name = options[:file_name]
|
115
|
-
self.for(:
|
115
|
+
self.for(file_extension: File.extname(file_name.to_s)[1..-1]) { yield if block_given? }
|
116
116
|
# Find a format based on the file extension:
|
117
117
|
when file_ext = options[:file_extension]
|
118
118
|
file_extensions[file_ext.to_sym]
|
@@ -201,7 +201,7 @@ module RDF
|
|
201
201
|
# @example
|
202
202
|
#
|
203
203
|
# content_types = RDF::Format.reader_types
|
204
|
-
# format = RDF::Format.for(:
|
204
|
+
# format = RDF::Format.for(content_type: content_types.first)
|
205
205
|
#
|
206
206
|
# @return [Array<String>]
|
207
207
|
def self.reader_types
|
@@ -227,7 +227,7 @@ module RDF
|
|
227
227
|
# @example
|
228
228
|
#
|
229
229
|
# content_types = RDF::Format.writer_types
|
230
|
-
# format = RDF::Format.for(:
|
230
|
+
# format = RDF::Format.for(content_type: content_types.first)
|
231
231
|
#
|
232
232
|
# @return [Array<String>]
|
233
233
|
def self.writer_types
|
data/lib/rdf/mixin/enumerable.rb
CHANGED
@@ -14,13 +14,13 @@ module RDF
|
|
14
14
|
# @example Checking whether a specific statement exists
|
15
15
|
# enumerable.has_statement?(RDF::Statement(subject, predicate, object))
|
16
16
|
# enumerable.has_triple?([subject, predicate, object])
|
17
|
-
# enumerable.has_quad?([subject, predicate, object,
|
17
|
+
# enumerable.has_quad?([subject, predicate, object, graph_name])
|
18
18
|
#
|
19
19
|
# @example Checking whether a specific value exists
|
20
20
|
# enumerable.has_subject?(RDF::URI("http://rubygems.org/gems/rdf"))
|
21
|
-
# enumerable.has_predicate?(RDF::
|
22
|
-
# enumerable.has_object?(RDF::Literal("A Ruby library for working with Resource Description Framework (RDF) data.", :
|
23
|
-
# enumerable.
|
21
|
+
# enumerable.has_predicate?(RDF::RDFS.label)
|
22
|
+
# enumerable.has_object?(RDF::Literal("A Ruby library for working with Resource Description Framework (RDF) data.", language: :en))
|
23
|
+
# enumerable.has_graph?(RDF::URI("http://ar.to/#self"))
|
24
24
|
#
|
25
25
|
# @example Enumerating all statements
|
26
26
|
# enumerable.each_statement do |statement|
|
@@ -33,26 +33,25 @@ module RDF
|
|
33
33
|
# end
|
34
34
|
#
|
35
35
|
# @example Enumerating all statements in the form of quads
|
36
|
-
# enumerable.each_quad do |subject, predicate, object,
|
37
|
-
# puts [subject, predicate, object,
|
36
|
+
# enumerable.each_quad do |subject, predicate, object, graph_name|
|
37
|
+
# puts [subject, predicate, object, graph_name].inspect
|
38
38
|
# end
|
39
39
|
#
|
40
40
|
# @example Enumerating all terms
|
41
41
|
# enumerable.each_subject { |term| puts term.inspect }
|
42
42
|
# enumerable.each_predicate { |term| puts term.inspect }
|
43
43
|
# enumerable.each_object { |term| puts term.inspect }
|
44
|
-
# enumerable.each_context { |term| puts term.inspect }
|
45
44
|
#
|
46
45
|
# @example Obtaining all statements
|
47
46
|
# enumerable.statements #=> [RDF::Statement(subject1, predicate1, object1), ...]
|
48
47
|
# enumerable.triples #=> [[subject1, predicate1, object1], ...]
|
49
|
-
# enumerable.quads #=> [[subject1, predicate1, object1,
|
48
|
+
# enumerable.quads #=> [[subject1, predicate1, object1, graph_name1], ...]
|
50
49
|
#
|
51
50
|
# @example Obtaining all unique values
|
52
|
-
# enumerable.subjects #=> [subject1, subject2, subject3, ...]
|
53
|
-
# enumerable.predicates #=> [predicate1, predicate2, predicate3, ...]
|
54
|
-
# enumerable.objects #=> [object1, object2, object3, ...]
|
55
|
-
# enumerable.
|
51
|
+
# enumerable.subjects(unique: true) #=> [subject1, subject2, subject3, ...]
|
52
|
+
# enumerable.predicates(unique: true) #=> [predicate1, predicate2, predicate3, ...]
|
53
|
+
# enumerable.objects(unique: true) #=> [object1, object2, object3, ...]
|
54
|
+
# enumerable.graph_names(unique: true) #=> [graph_name1, graph_name2, graph_name3, ...]
|
56
55
|
#
|
57
56
|
# @see RDF::Graph
|
58
57
|
# @see RDF::Repository
|
@@ -66,7 +65,8 @@ module RDF
|
|
66
65
|
# Returns `true` if this repository supports the given `feature`.
|
67
66
|
#
|
68
67
|
# Supported features include:
|
69
|
-
# * `:
|
68
|
+
# * `:graph_name` supports statements with a graph_name, allowing multiple named graphs
|
69
|
+
# * `:context` supports statements with a context, allowing multiple contexts (DEPRECATED, use graph_name. `context` will be removed in RDF.rb 2.0)
|
70
70
|
# * `:inference` supports RDFS inferrence of queryable contents.
|
71
71
|
# * `:validity` allows a concrete Enumerable implementation to indicate that it does or does not support valididty checking. By default implementations are assumed to support validity checking.
|
72
72
|
# * `:skolemize` supports [Skolemization](https://www.w3.org/wiki/BnodeSkolemization) of an `Enumerable`. Implementations supporting this feature must implement a `#skolemize` method, taking a base URI used for minting URIs for BNodes as stable identifiers and a `#deskolemize` method, also taking a base URI used for turning URIs having that prefix back into the same BNodes which were originally skolemized.
|
@@ -267,19 +267,18 @@ module RDF
|
|
267
267
|
# The order in which quads are yielded is undefined.
|
268
268
|
#
|
269
269
|
# @overload each_quad
|
270
|
-
# @yield [subject, predicate, object,
|
270
|
+
# @yield [subject, predicate, object, graph_name]
|
271
271
|
# each quad
|
272
272
|
# @yieldparam [RDF::Resource] subject
|
273
273
|
# @yieldparam [RDF::URI] predicate
|
274
274
|
# @yieldparam [RDF::Term] object
|
275
|
-
# @yieldparam [RDF::Resource]
|
275
|
+
# @yieldparam [RDF::Resource] graph_name
|
276
276
|
# @yieldreturn [void] ignored
|
277
277
|
# @return [void]
|
278
278
|
#
|
279
279
|
# @overload each_quad
|
280
|
-
# @return [Enumerator]
|
280
|
+
# @return [Enumerator<Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)>]
|
281
281
|
#
|
282
|
-
# @return [void]
|
283
282
|
# @see #enum_quad
|
284
283
|
def each_quad
|
285
284
|
if block_given?
|
@@ -342,9 +341,7 @@ module RDF
|
|
342
341
|
# @return [void]
|
343
342
|
#
|
344
343
|
# @overload each_subject
|
345
|
-
# @return [Enumerator]
|
346
|
-
#
|
347
|
-
# @return [void]
|
344
|
+
# @return [Enumerator<RDF::Resource>]
|
348
345
|
# @see #enum_subject
|
349
346
|
def each_subject
|
350
347
|
if block_given?
|
@@ -363,7 +360,7 @@ module RDF
|
|
363
360
|
##
|
364
361
|
# Returns an enumerator for {RDF::Enumerable#each_subject}.
|
365
362
|
#
|
366
|
-
# @return [Enumerator]
|
363
|
+
# @return [Enumerator<RDF::Resource>]
|
367
364
|
# @see #each_subject
|
368
365
|
def enum_subject
|
369
366
|
enum_for(:each_subject)
|
@@ -375,7 +372,7 @@ module RDF
|
|
375
372
|
#
|
376
373
|
# @param [Hash{Symbol => Boolean}] options
|
377
374
|
# @option options [Boolean] :unique (true)
|
378
|
-
# @return [
|
375
|
+
# @return [Array<RDF::URI>]
|
379
376
|
# @see #each_predicate
|
380
377
|
# @see #enum_predicate
|
381
378
|
def predicates(options = {})
|
@@ -410,9 +407,7 @@ module RDF
|
|
410
407
|
# @return [void]
|
411
408
|
#
|
412
409
|
# @overload each_predicate
|
413
|
-
# @return [Enumerator]
|
414
|
-
#
|
415
|
-
# @return [void]
|
410
|
+
# @return [Enumerator<RDF::URI>]
|
416
411
|
# @see #enum_predicate
|
417
412
|
def each_predicate
|
418
413
|
if block_given?
|
@@ -431,7 +426,7 @@ module RDF
|
|
431
426
|
##
|
432
427
|
# Returns an enumerator for {RDF::Enumerable#each_predicate}.
|
433
428
|
#
|
434
|
-
# @return [Enumerator]
|
429
|
+
# @return [Enumerator<RDF::URI>]
|
435
430
|
# @see #each_predicate
|
436
431
|
def enum_predicate
|
437
432
|
enum_for(:each_predicate)
|
@@ -478,9 +473,8 @@ module RDF
|
|
478
473
|
# @return [void]
|
479
474
|
#
|
480
475
|
# @overload each_object
|
481
|
-
# @return [Enumerator]
|
476
|
+
# @return [Enumerator<RDF::Term>]
|
482
477
|
#
|
483
|
-
# @return [void]
|
484
478
|
# @see #enum_object
|
485
479
|
def each_object # FIXME: deduplication
|
486
480
|
if block_given?
|
@@ -499,7 +493,7 @@ module RDF
|
|
499
493
|
##
|
500
494
|
# Returns an enumerator for {RDF::Enumerable#each_object}.
|
501
495
|
#
|
502
|
-
# @return [Enumerator]
|
496
|
+
# @return [Enumerator<RDF::Term>]
|
503
497
|
# @see #each_object
|
504
498
|
def enum_object
|
505
499
|
enum_for(:each_object)
|
@@ -514,7 +508,9 @@ module RDF
|
|
514
508
|
# @return [Enumerator<RDF::Resource>]
|
515
509
|
# @see #each_context
|
516
510
|
# @see #enum_context
|
511
|
+
# @deprecated use {#graph_names} instead.
|
517
512
|
def contexts(options = {})
|
513
|
+
warn "[DEPRECATION] Enumerable#contexts is being replaced with Enumerable#graph_names in RDF.rb 2.0. Called from #{Gem.location_of_caller.join(':')}"
|
518
514
|
if options[:unique] == false
|
519
515
|
enum_statement.map(&:context).compact.to_enum # TODO: optimize
|
520
516
|
else
|
@@ -522,14 +518,33 @@ module RDF
|
|
522
518
|
end
|
523
519
|
end
|
524
520
|
|
521
|
+
##
|
522
|
+
# Returns all unique RDF graph names, other than the default graph.
|
523
|
+
#
|
524
|
+
# @param [Hash{Symbol => Boolean}] options
|
525
|
+
# @option options [Boolean] :unique (true)
|
526
|
+
# @return [Array<RDF::Resource>]
|
527
|
+
# @see #each_graph
|
528
|
+
# @see #enum_graph
|
529
|
+
# @since 2.0
|
530
|
+
def graph_names(options = {})
|
531
|
+
if options[:unique] == false
|
532
|
+
enum_statement.map(&:graph_name).compact # TODO: optimize
|
533
|
+
else
|
534
|
+
enum_graph.map(&:graph_name).compact
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
525
538
|
##
|
526
539
|
# Returns `true` if `self` contains the given RDF context.
|
527
540
|
#
|
528
541
|
# @param [RDF::Resource, false] value
|
529
542
|
# Use value `false` to query for the default context
|
530
543
|
# @return [Boolean]
|
544
|
+
# @deprecated Use {#has_graph?} instead.
|
531
545
|
def has_context?(value)
|
532
|
-
|
546
|
+
warn "[DEPRECATION] Enumerable#has_context? is being replaced with Enumerable#has_graph? in RDF.rb 2.0. Called from #{Gem.location_of_caller.join(':')}"
|
547
|
+
has_graph?(value)
|
533
548
|
end
|
534
549
|
|
535
550
|
##
|
@@ -549,9 +564,10 @@ module RDF
|
|
549
564
|
# @overload each_context
|
550
565
|
# @return [Enumerator]
|
551
566
|
#
|
552
|
-
# @return [void]
|
553
567
|
# @see #enum_context
|
568
|
+
# @deprecated Use {#each_graph} instead.
|
554
569
|
def each_context
|
570
|
+
warn "[DEPRECATION] Enumerable#each_context is being replaced with Enumerable#each_graph in RDF.rb 2.0. Called from #{Gem.location_of_caller.join(':')}"
|
555
571
|
if block_given?
|
556
572
|
values = {}
|
557
573
|
each_statement do |statement|
|
@@ -570,11 +586,23 @@ module RDF
|
|
570
586
|
#
|
571
587
|
# @return [Enumerator]
|
572
588
|
# @see #each_context
|
589
|
+
# @deprecated Use {#enum_graph} instead.
|
573
590
|
def enum_context
|
591
|
+
warn "[DEPRECATION] Enumerable#enum_context is being replaced with Enumerable#enum_graph in RDF.rb 2.0. Called from #{Gem.location_of_caller.join(':')}"
|
574
592
|
enum_for(:each_context)
|
575
593
|
end
|
576
594
|
alias_method :enum_contexts, :enum_context
|
577
595
|
|
596
|
+
##
|
597
|
+
# Returns `true` if `self` contains the given RDF graph_name.
|
598
|
+
#
|
599
|
+
# @param [RDF::Resource, false] graph_name
|
600
|
+
# Use value `false` to query for the default graph_name
|
601
|
+
# @return [Boolean]
|
602
|
+
def has_graph?(graph_name)
|
603
|
+
enum_statement.any? {|s| s.graph_name == graph_name}
|
604
|
+
end
|
605
|
+
|
578
606
|
##
|
579
607
|
# Iterates the given block for each RDF graph in `self`.
|
580
608
|
#
|
@@ -590,16 +618,16 @@ module RDF
|
|
590
618
|
# @return [void]
|
591
619
|
#
|
592
620
|
# @overload each_graph
|
593
|
-
# @return [Enumerator]
|
621
|
+
# @return [Enumerator<RDF::Graph>]
|
594
622
|
#
|
595
|
-
# @return [void]
|
596
623
|
# @see #enum_graph
|
597
624
|
# @since 0.1.9
|
598
625
|
def each_graph
|
599
626
|
if block_given?
|
600
|
-
yield RDF::Graph.new(nil, :
|
601
|
-
|
602
|
-
|
627
|
+
yield RDF::Graph.new(nil, data: self)
|
628
|
+
# FIXME: brute force, repositories should override behavior
|
629
|
+
enum_statement.map(&:graph_name).uniq.compact do |graph_name|
|
630
|
+
yield RDF::Graph.new(graph_name, data: self)
|
603
631
|
end
|
604
632
|
end
|
605
633
|
enum_graph
|
@@ -608,7 +636,7 @@ module RDF
|
|
608
636
|
##
|
609
637
|
# Returns an enumerator for {RDF::Enumerable#each_graph}.
|
610
638
|
#
|
611
|
-
# @return [Enumerator]
|
639
|
+
# @return [Enumerator<RDF::Graph>]
|
612
640
|
# @see #each_graph
|
613
641
|
# @since 0.1.9
|
614
642
|
def enum_graph
|
@@ -691,7 +719,7 @@ module RDF
|
|
691
719
|
def method_missing(meth, *args)
|
692
720
|
writer = RDF::Writer.for(meth.to_s[3..-1].to_sym) if meth.to_s[0,3] == "to_"
|
693
721
|
if writer
|
694
|
-
writer.buffer(:
|
722
|
+
writer.buffer(standard_prefixes: true) {|w| w << self}
|
695
723
|
else
|
696
724
|
super
|
697
725
|
end
|
data/lib/rdf/mixin/mutable.rb
CHANGED
@@ -35,16 +35,22 @@ module RDF
|
|
35
35
|
# @param [Hash{Symbol => Object}] options
|
36
36
|
# Options from {RDF::Reader.open}
|
37
37
|
# @option options [RDF::Resource] :context
|
38
|
-
# Set set context of each loaded statement
|
38
|
+
# Set set context of each loaded statement. This option is deprecated in RDF.rb 2.0.
|
39
|
+
# @option options [RDF::Resource] :graph_name
|
40
|
+
# Set set graph name of each loaded statement
|
39
41
|
# @return [void]
|
40
42
|
def load(filename, options = {})
|
43
|
+
if options.has_key?(:context)
|
44
|
+
warn "[DEPRECATION] the :contexts option to Mutable#load is deprecated in RDF.rb 2.0, use :graph_name instead. Called from #{Gem.location_of_caller.join(':')}"
|
45
|
+
options[:graph_name] ||= options.delete(:context)
|
46
|
+
end
|
41
47
|
raise TypeError.new("#{self} is immutable") if immutable?
|
42
48
|
|
43
|
-
Reader.open(filename, {:
|
44
|
-
if options[:
|
49
|
+
Reader.open(filename, {base_uri: filename}.merge(options)) do |reader|
|
50
|
+
if options[:graph_name]
|
45
51
|
statements = []
|
46
52
|
reader.each_statement do |statement|
|
47
|
-
statement.
|
53
|
+
statement.graph_name = options[:graph_name]
|
48
54
|
statements << statement
|
49
55
|
end
|
50
56
|
insert_statements(statements)
|
@@ -147,7 +153,7 @@ module RDF
|
|
147
153
|
def clear
|
148
154
|
raise TypeError.new("#{self} is immutable") if immutable?
|
149
155
|
|
150
|
-
if respond_to?(:clear_statements)
|
156
|
+
if respond_to?(:clear_statements, true)
|
151
157
|
clear_statements
|
152
158
|
else
|
153
159
|
delete_statements(self)
|
data/lib/rdf/mixin/queryable.rb
CHANGED
@@ -19,8 +19,8 @@ module RDF
|
|
19
19
|
# actual lower-level query pattern matching implementation.
|
20
20
|
#
|
21
21
|
# @example Querying for statements having a given predicate
|
22
|
-
# queryable.query([nil, RDF::DOAP.developer, nil])
|
23
|
-
# queryable.query(:
|
22
|
+
# queryable.query([nil, RDF::Vocab::DOAP.developer, nil])
|
23
|
+
# queryable.query(predicate: RDF::Vocab::DOAP.developer) do |statement|
|
24
24
|
# puts statement.inspect
|
25
25
|
# end
|
26
26
|
#
|