rdf 1.99.1 → 2.0.0.beta1

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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/{README → README.md} +9 -44
  3. data/VERSION +1 -1
  4. data/bin/rdf +1 -1
  5. data/lib/rdf.rb +40 -49
  6. data/lib/rdf/changeset.rb +161 -0
  7. data/lib/rdf/cli.rb +195 -33
  8. data/lib/rdf/cli/vocab-loader.rb +13 -3
  9. data/lib/rdf/format.rb +44 -26
  10. data/lib/rdf/mixin/enumerable.rb +133 -97
  11. data/lib/rdf/mixin/enumerator.rb +8 -0
  12. data/lib/rdf/mixin/indexable.rb +1 -1
  13. data/lib/rdf/mixin/mutable.rb +101 -22
  14. data/lib/rdf/mixin/queryable.rb +21 -32
  15. data/lib/rdf/mixin/transactable.rb +94 -0
  16. data/lib/rdf/mixin/writable.rb +12 -3
  17. data/lib/rdf/model/dataset.rb +48 -0
  18. data/lib/rdf/model/graph.rb +73 -43
  19. data/lib/rdf/model/list.rb +61 -33
  20. data/lib/rdf/model/literal.rb +20 -19
  21. data/lib/rdf/model/literal/double.rb +20 -4
  22. data/lib/rdf/model/literal/numeric.rb +15 -13
  23. data/lib/rdf/model/node.rb +15 -16
  24. data/lib/rdf/model/statement.rb +1 -43
  25. data/lib/rdf/model/term.rb +10 -8
  26. data/lib/rdf/model/uri.rb +35 -34
  27. data/lib/rdf/model/value.rb +1 -1
  28. data/lib/rdf/nquads.rb +2 -11
  29. data/lib/rdf/ntriples.rb +1 -1
  30. data/lib/rdf/ntriples/reader.rb +33 -46
  31. data/lib/rdf/ntriples/writer.rb +42 -5
  32. data/lib/rdf/query.rb +6 -40
  33. data/lib/rdf/query/pattern.rb +4 -17
  34. data/lib/rdf/query/solutions.rb +6 -6
  35. data/lib/rdf/reader.rb +65 -14
  36. data/lib/rdf/repository.rb +365 -229
  37. data/lib/rdf/transaction.rb +211 -84
  38. data/lib/rdf/util.rb +1 -0
  39. data/lib/rdf/util/cache.rb +5 -5
  40. data/lib/rdf/util/file.rb +12 -9
  41. data/lib/rdf/util/logger.rb +272 -0
  42. data/lib/rdf/version.rb +2 -2
  43. data/lib/rdf/vocab/owl.rb +82 -77
  44. data/lib/rdf/vocab/rdfs.rb +22 -17
  45. data/lib/rdf/vocab/xsd.rb +5 -0
  46. data/lib/rdf/vocabulary.rb +50 -56
  47. data/lib/rdf/writer.rb +104 -52
  48. metadata +45 -90
  49. data/lib/rdf/mixin/inferable.rb +0 -5
  50. data/lib/rdf/vocab/cc.rb +0 -128
  51. data/lib/rdf/vocab/cert.rb +0 -245
  52. data/lib/rdf/vocab/dc.rb +0 -948
  53. data/lib/rdf/vocab/dc11.rb +0 -167
  54. data/lib/rdf/vocab/dcat.rb +0 -214
  55. data/lib/rdf/vocab/doap.rb +0 -337
  56. data/lib/rdf/vocab/exif.rb +0 -941
  57. data/lib/rdf/vocab/foaf.rb +0 -614
  58. data/lib/rdf/vocab/geo.rb +0 -157
  59. data/lib/rdf/vocab/gr.rb +0 -1501
  60. data/lib/rdf/vocab/ht.rb +0 -236
  61. data/lib/rdf/vocab/ical.rb +0 -528
  62. data/lib/rdf/vocab/ma.rb +0 -513
  63. data/lib/rdf/vocab/mo.rb +0 -2412
  64. data/lib/rdf/vocab/og.rb +0 -222
  65. data/lib/rdf/vocab/ogc.rb +0 -58
  66. data/lib/rdf/vocab/prov.rb +0 -1550
  67. data/lib/rdf/vocab/rsa.rb +0 -72
  68. data/lib/rdf/vocab/rss.rb +0 -66
  69. data/lib/rdf/vocab/schema.rb +0 -10569
  70. data/lib/rdf/vocab/sioc.rb +0 -669
  71. data/lib/rdf/vocab/skos.rb +0 -238
  72. data/lib/rdf/vocab/skosxl.rb +0 -57
  73. data/lib/rdf/vocab/v.rb +0 -383
  74. data/lib/rdf/vocab/vcard.rb +0 -841
  75. data/lib/rdf/vocab/vmd.rb +0 -383
  76. data/lib/rdf/vocab/void.rb +0 -186
  77. data/lib/rdf/vocab/vs.rb +0 -28
  78. data/lib/rdf/vocab/wdrs.rb +0 -134
  79. data/lib/rdf/vocab/wot.rb +0 -167
  80. data/lib/rdf/vocab/xhtml.rb +0 -8
  81. data/lib/rdf/vocab/xhv.rb +0 -505
@@ -154,7 +154,7 @@ module RDF
154
154
  # @raise [ArgumentError] if the value is invalid
155
155
  # @since 0.3.9
156
156
  def validate!
157
- raise ArgumentError if invalid?
157
+ raise ArgumentError, "#{self.inspect} is not valid" if invalid?
158
158
  self
159
159
  end
160
160
  alias_method :validate, :validate!
@@ -43,7 +43,7 @@ module RDF
43
43
  \s*
44
44
  (?:(?:<[^>]*>) | (?:_:\w+) | (?:"[^"\n]*"(?:^^|@\S+)?)) # Object
45
45
  \s*
46
- (?:\s*(?:<[^>]*>) | (?:_:\w+)) # Context
46
+ (?:\s*(?:<[^>]*>) | (?:_:\w+)) # Graph Name
47
47
  \s*\.
48
48
  )x) && !(
49
49
  sample.match(%r(@(base|prefix|keywords)|\{)) || # Not Turtle/N3/TriG
@@ -74,7 +74,7 @@ module RDF
74
74
  object = read_uriref || read_node || read_literal || fail_object
75
75
  graph_name = read_uriref || read_node
76
76
  if validate? && !read_eos
77
- raise RDF::ReaderError.new("ERROR [line #{lineno}] Expected end of statement (found: #{current_line.inspect})")
77
+ log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
78
78
  end
79
79
  return [subject, predicate, object, {graph_name: graph_name}]
80
80
  end
@@ -88,15 +88,6 @@ module RDF
88
88
  end # Reader
89
89
 
90
90
  class Writer < NTriples::Writer
91
- ##
92
- # @param [RDF::Statement] statement
93
- # @return [void] `self`
94
- def write_statement(statement)
95
- write_quad(*statement.to_quad)
96
- self
97
- end
98
- alias_method :insert_statement, :write_statement # support the RDF::Writable interface
99
-
100
91
  ##
101
92
  # Outputs the N-Quads representation of a statement.
102
93
  #
@@ -62,7 +62,7 @@ module RDF
62
62
  # @see RDF::NTriples::Writer.serialize
63
63
  # @since 0.1.5
64
64
  def self.serialize(value)
65
- Writer.serialize(value)
65
+ Writer.for(:ntriples).serialize(value)
66
66
  end
67
67
 
68
68
  ##
@@ -28,16 +28,14 @@ module RDF::NTriples
28
28
  # @see http://www.w3.org/TR/rdf-testcases/#ntriples
29
29
  # @see http://www.w3.org/TR/n-triples/
30
30
  class Reader < RDF::Reader
31
+ include RDF::Util::Logger
31
32
  format RDF::NTriples::Format
32
33
 
33
34
  # @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
34
- ESCAPE_CHARS = ["\b", "\f", "\t", "\n", "\r", "\"", "\\"].freeze
35
- ESCAPE_CHAR4 = /\\u([0-9A-Fa-f]{4,4})/.freeze
36
- ESCAPE_CHAR8 = /\\U([0-9A-Fa-f]{8,8})/.freeze
37
- ESCAPE_CHAR = Regexp.union(ESCAPE_CHAR4, ESCAPE_CHAR8).freeze
38
- ESCAPE_SURROGATE = /\\u([0-9A-Fa-f]{4,4})\\u([0-9A-Fa-f]{4,4})/.freeze
39
- ESCAPE_SURROGATE1 = (0xD800..0xDBFF).freeze
40
- ESCAPE_SURROGATE2 = (0xDC00..0xDFFF).freeze
35
+ ESCAPE_CHARS = ["\b", "\f", "\t", "\n", "\r", "\"", "\\"].freeze
36
+ UCHAR4 = /\\u([0-9A-Fa-f]{4,4})/.freeze
37
+ UCHAR8 = /\\U([0-9A-Fa-f]{8,8})/.freeze
38
+ UCHAR = Regexp.union(UCHAR4, UCHAR8).freeze
41
39
 
42
40
 
43
41
  # Terminals from rdf-turtle.
@@ -53,7 +51,7 @@ module RDF::NTriples
53
51
  [\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]|[\\u{10000}-\\u{EFFFF}]
54
52
  EOS
55
53
  U_CHARS2 = Regexp.compile("\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040]").freeze
56
- IRI_RANGE = Regexp.compile("[[^<>\"{}|^`\\\\]&&[^\\x00-\\x20]]").freeze
54
+ IRI_RANGE = Regexp.compile("[[^<>\"{}\|\^`\\\\]&&[^\\x00-\\x20]]").freeze
57
55
 
58
56
  # 163s
59
57
  PN_CHARS_BASE = /[A-Z]|[a-z]|#{U_CHARS1}/.freeze
@@ -64,13 +62,13 @@ module RDF::NTriples
64
62
  # 159s
65
63
  ECHAR = /\\[tbnrf\\"]/.freeze
66
64
  # 18
67
- IRIREF = /<((?:#{IRI_RANGE}|#{ESCAPE_CHAR})*)>/.freeze
65
+ IRIREF = /<((?:#{IRI_RANGE}|#{UCHAR})*)>/.freeze
68
66
  # 141s
69
67
  BLANK_NODE_LABEL = /_:((?:[0-9]|#{PN_CHARS_U})(?:(?:#{PN_CHARS}|\.)*#{PN_CHARS})?)/.freeze
70
68
  # 144s
71
69
  LANGTAG = /@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)/.freeze
72
70
  # 22
73
- STRING_LITERAL_QUOTE = /"((?:[^\"\\\n\r]|#{ECHAR}|#{ESCAPE_CHAR})*)"/.freeze
71
+ STRING_LITERAL_QUOTE = /"((?:[^\"\\\n\r]|#{ECHAR}|#{UCHAR})*)"/.freeze
74
72
 
75
73
  # @see http://www.w3.org/TR/rdf-testcases/#ntrip_grammar
76
74
  COMMENT = /^#\s*(.*)$/.freeze
@@ -91,57 +89,59 @@ module RDF::NTriples
91
89
  # representation.
92
90
  #
93
91
  # @param [String] input
92
+ # @param [{Symbol => Object}] options
93
+ # From {RDF::Reader#initialize}
94
94
  # @return [RDF::Term]
95
- def self.unserialize(input)
95
+ def self.unserialize(input, options = {})
96
96
  case input
97
97
  when nil then nil
98
- else self.new(input).read_value
98
+ else self.new(input, {logger: []}.merge(options)).read_value
99
99
  end
100
100
  end
101
101
 
102
102
  ##
103
- # @param [String] input
103
+ # (see unserialize)
104
104
  # @return [RDF::Resource]
105
- def self.parse_subject(input)
106
- parse_uri(input) || parse_node(input)
105
+ def self.parse_subject(input, options = {})
106
+ parse_uri(input, options) || parse_node(input, options)
107
107
  end
108
108
 
109
109
  ##
110
- # @param [String] input
110
+ # (see unserialize)
111
111
  # @return [RDF::URI]
112
- def self.parse_predicate(input)
112
+ def self.parse_predicate(input, options = {})
113
113
  parse_uri(input, intern: true)
114
114
  end
115
115
 
116
116
  ##
117
- # @param [String] input
118
- # @return [RDF::Term]
119
- def self.parse_object(input)
120
- parse_uri(input) || parse_node(input) || parse_literal(input)
117
+ # (see unserialize)
118
+ def self.parse_object(input, options = {})
119
+ parse_uri(input, options) || parse_node(input, options) || parse_literal(input, options)
121
120
  end
122
121
 
123
122
  ##
124
- # @param [String] input
123
+ # (see unserialize)
125
124
  # @return [RDF::Node]
126
- def self.parse_node(input)
125
+ def self.parse_node(input, options = {})
127
126
  if input =~ NODEID
128
127
  RDF::Node.new($1)
129
128
  end
130
129
  end
131
130
 
132
131
  ##
133
- # @param [String] input
132
+ # (see unserialize)
134
133
  # @return [RDF::URI]
135
134
  def self.parse_uri(input, options = {})
136
135
  if input =~ URIREF
137
- RDF::URI.send(options[:intern] ? :intern : :new, $1)
136
+ uri_str = unescape($1)
137
+ RDF::URI.send(options[:intern] ? :intern : :new, unescape($1))
138
138
  end
139
139
  end
140
140
 
141
141
  ##
142
- # @param [String] input
142
+ # (see unserialize)
143
143
  # @return [RDF::Literal]
144
- def self.parse_literal(input)
144
+ def self.parse_literal(input, options = {})
145
145
  case input
146
146
  when LITERAL_WITH_LANGUAGE
147
147
  RDF::Literal.new(unescape($1), language: $4)
@@ -164,22 +164,8 @@ module RDF::NTriples
164
164
  # Decode \t|\n|\r|\"|\\ character escapes:
165
165
  ESCAPE_CHARS.each { |escape| string.gsub!(escape.inspect[1...-1], escape) }
166
166
 
167
- # Decode \uXXXX\uXXXX surrogate pairs:
168
- # XXX: This block should be removed in RDF.rb 2.0
169
- while
170
- (string.sub!(ESCAPE_SURROGATE) do
171
- if ESCAPE_SURROGATE1.include?($1.hex) && ESCAPE_SURROGATE2.include?($2.hex)
172
- warn "[DEPRECATION] Surrogate pairs support deprecated. Support will be removed in RDF.rb 2.0. Called from #{Gem.location_of_caller.join(':')}"
173
- s = [$1, $2].pack('H*H*')
174
- s.force_encoding(Encoding::UTF_16BE).encode!(Encoding::UTF_8)
175
- else
176
- [$1.hex].pack('U*') << '\u' << $2
177
- end
178
- end)
179
- end
180
-
181
167
  # Decode \uXXXX and \UXXXXXXXX code points:
182
- string.gsub!(ESCAPE_CHAR) do
168
+ string.gsub!(UCHAR) do
183
169
  [($1 || $2).hex].pack('U*')
184
170
  end
185
171
 
@@ -192,7 +178,9 @@ module RDF::NTriples
192
178
  begin
193
179
  read_statement
194
180
  rescue RDF::ReaderError
195
- read_uriref || read_node || read_literal
181
+ value = read_uriref || read_node || read_literal
182
+ log_recover
183
+ value
196
184
  end
197
185
  end
198
186
 
@@ -211,8 +199,7 @@ module RDF::NTriples
211
199
  object = read_uriref || read_node || read_literal || fail_object
212
200
 
213
201
  if validate? && !read_eos
214
- raise RDF::ReaderError.new("ERROR [line #{lineno}] Expected end of statement (found: #{current_line.inspect})",
215
- lineno: lineno)
202
+ log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
216
203
  end
217
204
  return [subject, predicate, object]
218
205
  end
@@ -242,7 +229,7 @@ module RDF::NTriples
242
229
  uri
243
230
  end
244
231
  rescue ArgumentError => e
245
- raise RDF::ReaderError.new("ERROR [line #{lineno}] Invalid URI (found: \"<#{uri_str}>\")", lineno: lineno, token: "<#{uri_str}>")
232
+ log_error("Invalid URI (found: \"<#{uri_str}>\")", lineno: lineno, token: "<#{uri_str}>", exception: RDF::ReaderError)
246
233
  end
247
234
 
248
235
  ##
@@ -38,11 +38,12 @@ module RDF::NTriples
38
38
  # @see http://www.w3.org/TR/rdf-testcases/#ntriples
39
39
  # @see http://www.w3.org/TR/n-triples/
40
40
  class Writer < RDF::Writer
41
+ include RDF::Util::Logger
41
42
  format RDF::NTriples::Format
42
43
 
43
44
  # @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
44
45
  ESCAPE_PLAIN = /\A[\x20-\x21\x23-#{Regexp.escape '['}#{Regexp.escape ']'}-\x7E]*\z/m.freeze
45
- ESCAPE_ASCII = /\A[\x00-\x7F]*\z/m.freeze
46
+ ESCAPE_PLAIN_U = /\A(?:#{Reader::IRI_RANGE}|#{Reader::UCHAR})*\z/.freeze
46
47
 
47
48
  ##
48
49
  # Escape Literal and URI content. If encoding is ASCII, all unicode
@@ -63,7 +64,7 @@ module RDF::NTriples
63
64
  string.each_byte { |u| buffer << escape_ascii(u, encoding) }
64
65
  buffer.string
65
66
  end
66
- when string.respond_to?(:each_char) && encoding && encoding != Encoding::ASCII
67
+ when encoding && encoding != Encoding::ASCII
67
68
  # Not encoding UTF-8 characters
68
69
  StringIO.open do |buffer|
69
70
  buffer.set_encoding(encoding)
@@ -95,6 +96,7 @@ module RDF::NTriples
95
96
  # @param [Integer, #ord] u
96
97
  # @param [Encoding] encoding
97
98
  # @return [String]
99
+ # @raise [ArgumentError] if `u` is not a valid Unicode codepoint
98
100
  # @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
99
101
  def self.escape_unicode(u, encoding)
100
102
  case (u = u.ord)
@@ -116,6 +118,7 @@ module RDF::NTriples
116
118
  #
117
119
  # @param [Integer, #ord] u
118
120
  # @return [String]
121
+ # @raise [ArgumentError] if `u` is not a valid Unicode codepoint
119
122
  # @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
120
123
  # @see http://www.w3.org/TR/n-triples/
121
124
  def self.escape_ascii(u, encoding)
@@ -242,17 +245,51 @@ module RDF::NTriples
242
245
  # Serialize node using unique identifier, rather than any used to create the node.
243
246
  # @return [String]
244
247
  def format_node(node, options = {})
245
- options[:unique_bnodes] ? node.to_unique_base : node.to_base
248
+ options[:unique_bnodes] ? node.to_unique_base : node.to_s
246
249
  end
247
250
 
248
251
  ##
249
- # Returns the N-Triples representation of a URI reference.
252
+ # Returns the N-Triples representation of a URI reference using write encoding.
250
253
  #
251
254
  # @param [RDF::URI] uri
252
255
  # @param [Hash{Symbol => Object}] options = ({})
253
256
  # @return [String]
254
257
  def format_uri(uri, options = {})
255
- uri.to_base
258
+ string = uri.to_s
259
+ iriref = case
260
+ when string =~ ESCAPE_PLAIN_U # a shortcut for the simple case
261
+ string
262
+ when string.ascii_only? || (encoding && encoding != Encoding::ASCII)
263
+ StringIO.open do |buffer|
264
+ buffer.set_encoding(encoding)
265
+ string.each_char do |u|
266
+ buffer << case u.ord
267
+ when (0x00..0x20) then self.class.escape_utf16(u)
268
+ when 0x22, 0x3c, 0x3e, 0x5c, 0x5e, 0x60, 0x7b, 0x7c, 0x7d # <>"{}|`\
269
+ self.class.escape_utf16(u)
270
+ else u
271
+ end
272
+ end
273
+ buffer.string
274
+ end
275
+ else
276
+ # Encode ASCII && UTF-8/16 characters
277
+ StringIO.open do |buffer|
278
+ buffer.set_encoding(Encoding::ASCII)
279
+ string.each_byte do |u|
280
+ buffer << case u
281
+ when (0x00..0x20) then self.class.escape_utf16(u)
282
+ when 0x22, 0x3c, 0x3e, 0x5c, 0x5e, 0x60, 0x7b, 0x7c, 0x7d # <>"{}|`\
283
+ self.class.escape_utf16(u)
284
+ when (0x80..0xFFFF) then self.class.escape_utf16(u)
285
+ when (0x10000..0x10FFFF) then self.class.escape_utf32(u)
286
+ else u
287
+ end
288
+ end
289
+ buffer.string
290
+ end
291
+ end
292
+ encoding ? "<#{iriref}>".encode(encoding) : "<#{iriref}>"
256
293
  end
257
294
 
258
295
  ##
@@ -109,8 +109,10 @@ module RDF
109
109
  # @param [Array<Solution>] args
110
110
  # @return [Solutions] returns new solutions including the arguments, which must each be a {Solution}
111
111
  def self.Solutions(*args)
112
- return args.first if args.length == 1 && args.first.is_a?(Solutions)
113
- args = args.first if args.first.is_a?(Array) && args.length == 1
112
+ if args.length == 1
113
+ return args[0] if args[0].is_a?(Solutions)
114
+ args = args[0] if args[0].is_a?(Array)
115
+ end
114
116
  return Solutions.new(args)
115
117
  end
116
118
 
@@ -154,8 +156,6 @@ module RDF
154
156
  # Names that are against unbound variables match either default
155
157
  # or named graphs.
156
158
  # The name of `false` will only match against the default graph.
157
- # @option options [RDF::Resource, RDF::Query::Variable, false] :context (nil)
158
- # Alias for `:graph_name`. The :context option is deprecated in RDF.rb 2.0.
159
159
  # @option options [RDF::Resource, RDF::Query::Variable, false] :name (nil)
160
160
  # Alias for `:graph_name`.
161
161
  # @yield [query]
@@ -175,8 +175,6 @@ module RDF
175
175
  # Names that are against unbound variables match either default
176
176
  # or named graphs.
177
177
  # The name of `false` will only match against the default graph.
178
- # @option options [RDF::Resource, RDF::Query::Variable, false] :context (nil)
179
- # Alias for `:graph_name`. The :context option is deprecated in RDF.rb 2.0.
180
178
  # @option options [RDF::Resource, RDF::Query::Variable, false] :name (nil)
181
179
  # Alias for `:graph_name`.
182
180
  # @yield [query]
@@ -184,10 +182,6 @@ module RDF
184
182
  # @yieldreturn [void] ignored
185
183
  def initialize(*patterns, &block)
186
184
  @options = patterns.last.is_a?(Hash) ? patterns.pop.dup : {}
187
- if @options.has_key?(:context)
188
- warn "[DEPRECATION] the :contexts option to Query#initialize is deprecated in RDF.rb 2.0, use :graph_name instead. Called from #{Gem.location_of_caller.join(':')}"
189
- @options[:graph_name] ||= options.delete(:context)
190
- end
191
185
  patterns << @options if patterns.empty?
192
186
  @variables = {}
193
187
  @solutions = Query::Solutions(@options.delete(:solutions))
@@ -276,14 +270,14 @@ module RDF
276
270
  # If the query nas no patterns, it returns a single empty solution as
277
271
  # per SPARQL 1.1 _Empty Group Pattern_.
278
272
  #
273
+ # @note solutions could be an Iterator, but this algorithm cycles over solutions, which requires them to be an array internally.
274
+ #
279
275
  # @param [RDF::Queryable] queryable
280
276
  # the graph or repository to query
281
277
  # @param [Hash{Symbol => Object}] options
282
278
  # any additional keyword options
283
279
  # @option options [Hash{Symbol => RDF::Term}] bindings
284
280
  # optional variable bindings to use
285
- # @option options [RDF::Resource, RDF::Query::Variable, false] context (nil)
286
- # Alias for `:graph_name`. The :context option is deprecated in RDF.rb 2.0.
287
281
  # @option options [RDF::Resource, RDF::Query::Variable, false] graph_name (nil)
288
282
  # Specific graph name for matching against queryable;
289
283
  # overrides default graph defined on query.
@@ -302,10 +296,6 @@ module RDF
302
296
  def execute(queryable, options = {}, &block)
303
297
  validate!
304
298
  options = options.dup
305
- if options.has_key?(:context)
306
- warn "[DEPRECATION] the :contexts option to Query#execute is deprecated in RDF.rb 2.0, use :graph_name instead. Called from #{Gem.location_of_caller.join(':')}"
307
- options[:graph_name] ||= options.delete(:context)
308
- end
309
299
 
310
300
  # just so we can call #keys below without worrying
311
301
  options[:bindings] ||= {}
@@ -433,15 +423,6 @@ module RDF
433
423
  options[:graph_name].nil?
434
424
  end
435
425
 
436
- # Scope the query to named graphs matching value
437
- # @param [RDF::IRI, RDF::Query::Variable] value
438
- # @return [RDF::IRI, RDF::Query::Variable]
439
- # @deprecated Use {#graph_name=} instead.
440
- def context=(value)
441
- warn "[DEPRECATION] Query#context= is deprecated in RDF.rb 2.0, use Query#graph_name= instead. Called from #{Gem.location_of_caller.join(':')}"
442
- self.graph_name = value
443
- end
444
-
445
426
  # Scope the query to named graphs matching value
446
427
  # @param [RDF::IRI, RDF::Query::Variable] value
447
428
  # @return [RDF::IRI, RDF::Query::Variable]
@@ -449,27 +430,12 @@ module RDF
449
430
  options[:graph_name] = value
450
431
  end
451
432
 
452
- # Scope of this query, if any
453
- # @return [RDF::IRI, RDF::Query::Variable]
454
- # @deprecated Use {#graph_name} instead.
455
- def context
456
- warn "[DEPRECATION] Query#context is deprecated in RDF.rb 2.0, use Query#graph_name instead. Called from #{Gem.location_of_caller.join(':')}"
457
- graph_name
458
- end
459
-
460
433
  # Scope of this query, if any
461
434
  # @return [RDF::IRI, RDF::Query::Variable]
462
435
  def graph_name
463
436
  options[:graph_name]
464
437
  end
465
438
 
466
- # Apply the context specified (or configured) to all patterns that have no context
467
- # @param [RDF::IRI, RDF::Query::Variable] context (self.context)
468
- def apply_context(context = options[:context])
469
- warn "[DEPRECATION] Query#apply_context is deprecated in RDF.rb 2.0, use Query#apply_graph_name instead. Called from #{Gem.location_of_caller.join(':')}"
470
- apply_graph_name(context)
471
- end
472
-
473
439
  # Apply the graph name specified (or configured) to all patterns that have no graph name
474
440
  # @param [RDF::IRI, RDF::Query::Variable] graph_name (self.graph_name)
475
441
  def apply_graph_name(graph_name = options[:graph_name])
@@ -6,10 +6,6 @@ module RDF; class Query
6
6
  # @private
7
7
  # @since 0.2.2
8
8
  def self.from(pattern, options = {})
9
- if options.has_key?(:context)
10
- warn "[DEPRECATION] the :contexts option to Pattern.from is deprecated in RDF.rb 2.0, use :graph_name instead. Called from #{Gem.location_of_caller.join(':')}"
11
- options[:graph_name] ||= options.delete(:context)
12
- end
13
9
  case pattern
14
10
  when Pattern then pattern
15
11
  when Array, Statement
@@ -25,9 +21,6 @@ module RDF; class Query
25
21
  # @option options [Variable, Resource, Symbol, nil] :subject (nil)
26
22
  # @option options [Variable, URI, Symbol, nil] :predicate (nil)
27
23
  # @option options [Variable, Term, Symbol, nil] :object (nil)
28
- # @option options [Variable, Resource, Symbol, nil, false] :context (nil)
29
- # A context of nil matches any context, a context of false, matches only the default context.
30
- # The :context option is deprecated in RDF.rb 2.0. Use :graph_name instead.
31
24
  # @option options [Variable, Resource, Symbol, nil, false] :graph_name (nil)
32
25
  # A graph_name of nil matches any graph, a graph_name of false, matches only the default graph.
33
26
  # @option options [Boolean] :optional (false)
@@ -37,19 +30,12 @@ module RDF; class Query
37
30
  # @param [Variable, URI, Symbol, nil] predicate
38
31
  # @param [Variable, Termm, Symbol, nil] object
39
32
  # @param [Hash{Symbol => Object}] options
40
- # @option options [Variable, Resource, Symbol, nil, false] :context (nil)
41
- # A context of nil matches any context, a context of false, matches only the default context.
42
- # The :context option is deprecated in RDF.rb 2.0. Use :graph_name instead.
43
33
  # @option options [Variable, Resource, Symbol, nil, false] :graph_name (nil)
44
34
  # A graph_name of nil matches any graph, a graph_name of false, matches only the default graph.
45
35
  # @option options [Boolean] :optional (false)
46
36
  #
47
37
  # @note {Statement} treats symbols as interned {Node} instances, in a {Pattern}, they are treated as {Variable}.
48
38
  def initialize(subject = nil, predicate = nil, object = nil, options = {})
49
- if options.has_key?(:context)
50
- warn "[DEPRECATION] the :contexts option to Pattern#initialize is deprecated in RDF.rb 2.0, use :graph_name instead. Called from #{Gem.location_of_caller.join(':')}"
51
- options[:graph_name] ||= options.delete(:context)
52
- end
53
39
  super
54
40
  end
55
41
 
@@ -170,12 +156,13 @@ module RDF; class Query
170
156
  terms = variable_terms(name)
171
157
  break terms if terms.size > 1
172
158
  end
173
- queryable.query(query) do |statement|
159
+ queryable.query(query).select do |statement|
174
160
  # Only yield those matching statements where the variable
175
161
  # constraint is also satisfied:
176
162
  # FIXME: `Array#uniq` uses `#eql?` and `#hash`, not `#==`
177
- if matches = terms.map { |term| statement.send(term) }.uniq.size.equal?(1)
178
- block.call(statement)
163
+ if terms.map { |term| statement.send(term) }.uniq.size.equal?(1)
164
+ yield statement if block_given?
165
+ true
179
166
  end
180
167
  end
181
168
  end