rdf 1.1.17.1 → 1.99.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,19 +4,19 @@ module RDF
4
4
  #
5
5
  # @example Creating an RDF statement
6
6
  # s = RDF::URI.new("http://rubygems.org/gems/rdf")
7
- # p = RDF::DC.creator
7
+ # p = RDF::Vocab::DC.creator
8
8
  # o = RDF::URI.new("http://ar.to/#self")
9
9
  # RDF::Statement(s, p, o)
10
10
  #
11
- # @example Creating an RDF statement with a context
11
+ # @example Creating an RDF statement with a graph_name
12
12
  # uri = RDF::URI("http://example/")
13
- # RDF::Statement(s, p, o, :context => uri)
13
+ # RDF::Statement(s, p, o, graph_name: uri)
14
14
  #
15
15
  # @example Creating an RDF statement from a `Hash`
16
16
  # RDF::Statement({
17
- # :subject => RDF::URI.new("http://rubygems.org/gems/rdf"),
18
- # :predicate => RDF::DC.creator,
19
- # :object => RDF::URI.new("http://ar.to/#self"),
17
+ # subject: RDF::URI.new("http://rubygems.org/gems/rdf"),
18
+ # predicate: RDF::Vocab::DC.creator,
19
+ # object: RDF::URI.new("http://ar.to/#self"),
20
20
  # })
21
21
  #
22
22
  # @example Creating an RDF statement with interned nodes
@@ -34,8 +34,8 @@ module RDF
34
34
  def self.from(statement, options = {})
35
35
  case statement
36
36
  when Array, Query::Pattern
37
- context = statement[3] == false ? nil : statement[3]
38
- self.new(statement[0], statement[1], statement[2], options.merge(:context => context))
37
+ graph_name = statement[3] == false ? nil : statement[3]
38
+ self.new(statement[0], statement[1], statement[2], options.merge(graph_name: graph_name))
39
39
  when Statement then statement
40
40
  when Hash then self.new(options.merge(statement))
41
41
  else raise ArgumentError, "expected RDF::Statement, Hash, or Array, but got #{statement.inspect}"
@@ -46,7 +46,29 @@ module RDF
46
46
  attr_accessor :id
47
47
 
48
48
  # @return [RDF::Resource]
49
- attr_accessor :context
49
+ attr_accessor :graph_name
50
+
51
+ ##
52
+ # Name of this graph, if it is part of an {RDF::Repository}
53
+ # @!attribute [rw] graph_name
54
+ # @return [RDF::Resource]
55
+ # @since 1.1.0
56
+ # @deprecated Use {#graph_name} instead.
57
+ def context
58
+ warn "[DEPRECATION] Statement#context is being replaced with Statement@graph_name in RDF.rb 2.0. Called from #{Gem.location_of_caller.join(':')}"
59
+ graph_name
60
+ end
61
+
62
+ ##
63
+ # Name of this graph, if it is part of an {RDF::Repository}
64
+ # @!attribute [rw] graph_name
65
+ # @return [RDF::Resource]
66
+ # @since 1.1.0
67
+ # @deprecated Use {#graph_name=} instead.
68
+ def context=(value)
69
+ warn "[DEPRECATION] Statement#context= is being replaced with Statement@graph_name= in RDF.rb 2.0. Called from #{Gem.location_of_caller.join(':')}"
70
+ self.graph_name = value
71
+ end
50
72
 
51
73
  # @return [RDF::Resource]
52
74
  attr_accessor :subject
@@ -66,7 +88,9 @@ module RDF
66
88
  # @option options [RDF::Resource] :object (nil)
67
89
  # if not a {Resource}, it is coerced to {Literal} or {Node} depending on if it is a symbol or something other than a {Term}.
68
90
  # @option options [RDF::Term] :context (nil)
69
- # Note, in RDF 1.1, a context MUST be an {Resource}.
91
+ # Alias for :graph_name, :context is deprecated in RDF.rb.
92
+ # @option options [RDF::Term] :graph_name (nil)
93
+ # Note, in RDF 1.1, a graph name MUST be an {Resource}.
70
94
  # @return [RDF::Statement]
71
95
  #
72
96
  # @overload initialize(subject, predicate, object, options = {})
@@ -77,6 +101,9 @@ module RDF
77
101
  # if not a {Resource}, it is coerced to {Literal} or {Node} depending on if it is a symbol or something other than a {Term}.
78
102
  # @param [Hash{Symbol => Object}] options
79
103
  # @option options [RDF::Term] :context (nil)
104
+ # Alias for :graph_name, :context is deprecated in RDF.rb.
105
+ # @option options [RDF::Term] :graph_name (nil)
106
+ # Note, in RDF 1.1, a graph name MUST be an {Resource}.
80
107
  # @return [RDF::Statement]
81
108
  def initialize(subject = nil, predicate = nil, object = nil, options = {})
82
109
  if subject.is_a?(Hash)
@@ -90,15 +117,19 @@ module RDF
90
117
  @predicate = predicate
91
118
  @object = object
92
119
  end
93
- @id = @options.delete(:id) if @options.has_key?(:id)
94
- @context = @options.delete(:context)
120
+ if @options.has_key?(:context)
121
+ 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(':')}"
122
+ @options[:graph_name] ||= @options.delete(:context)
123
+ end
124
+ @id = @options.delete(:id) if @options.has_key?(:id)
125
+ @graph_name = @options.delete(:graph_name)
95
126
  initialize!
96
127
  end
97
128
 
98
129
  ##
99
130
  # @private
100
131
  def initialize!
101
- @context = Node.intern(@context) if @context.is_a?(Symbol)
132
+ @graph_name = Node.intern(@graph_name) if @graph_name.is_a?(Symbol)
102
133
  @subject = if @subject.is_a?(Value)
103
134
  @subject.to_term
104
135
  elsif @subject.is_a?(Symbol)
@@ -137,7 +168,7 @@ module RDF
137
168
  !(has_subject? && subject.resource? &&
138
169
  has_predicate? && predicate.resource? &&
139
170
  has_object? && (object.resource? || object.literal?) &&
140
- (has_context? ? context.resource? : true ))
171
+ (has_graph? ? graph_name.resource? : true ))
141
172
  end
142
173
 
143
174
  ##
@@ -152,7 +183,7 @@ module RDF
152
183
  has_subject? && subject.resource? && subject.valid? &&
153
184
  has_predicate? && predicate.uri? && predicate.valid? &&
154
185
  has_object? && object.term? && object.valid? &&
155
- (has_context? ? context.resource? && context.valid? : true )
186
+ (has_graph? ? graph_name.resource? && graph_name.valid? : true )
156
187
  end
157
188
 
158
189
  ##
@@ -173,16 +204,37 @@ module RDF
173
204
  false
174
205
  end
175
206
 
207
+ ##
208
+ # Determines if the statement is incomplete, vs. invalid. An incomplete statement is one in which any of `subject`, `predicate`, or `object`, are nil.
209
+ #
210
+ # @return [Boolean]
211
+ # @since 3.0
212
+ def incomplete?
213
+ to_triple.any?(&:nil?)
214
+ end
215
+
216
+ ##
217
+ # Determines if the statement is complete, vs. invalid. A complete statement is one in which none of `subject`, `predicate`, or `object`, are nil.
218
+ #
219
+ # @return [Boolean]
220
+ # @since 3.0
221
+ def complete?
222
+ !incomplete?
223
+ end
224
+
176
225
  ##
177
226
  # @return [Boolean]
178
227
  def has_graph?
179
- has_context?
228
+ !!graph_name
180
229
  end
230
+ alias_method :has_name?, :has_graph?
181
231
 
182
232
  ##
183
233
  # @return [Boolean]
234
+ # @deprecated Use {#has_graph?} instead.
184
235
  def has_context?
185
- !!context
236
+ warn "[DEPRECATION] Statement#has_context? is being replaced with Statement#has_grap in RDF.rb 2.0. Called from #{Gem.location_of_caller.join(':')}"
237
+ !!context
186
238
  end
187
239
 
188
240
  ##
@@ -207,15 +259,17 @@ module RDF
207
259
  # Returns `true` if any resource of this statement is a blank node.
208
260
  #
209
261
  # @return [Boolean]
210
- def has_blank_nodes?
262
+ # @since 2.0
263
+ def node?
211
264
  to_quad.compact.any?(&:node?)
212
265
  end
266
+ alias_method :has_blank_nodes?, :node?
213
267
 
214
268
  ##
215
269
  # @param [Statement] other
216
270
  # @return [Boolean]
217
271
  def eql?(other)
218
- other.is_a?(Statement) && self == other && (self.context || false) == (other.context || false)
272
+ other.is_a?(Statement) && self == other && (self.graph_name || false) == (other.graph_name || false)
219
273
  end
220
274
 
221
275
  ##
@@ -229,10 +283,10 @@ module RDF
229
283
  # @param [Statement] other
230
284
  # @return [Boolean]
231
285
  def ===(other)
232
- return false if has_context? && !context.eql?(other.context)
233
- return false if has_subject? && !subject.eql?(other.subject)
234
- return false if has_predicate? && !predicate.eql?(other.predicate)
235
286
  return false if has_object? && !object.eql?(other.object)
287
+ return false if has_predicate? && !predicate.eql?(other.predicate)
288
+ return false if has_subject? && !subject.eql?(other.subject)
289
+ return false if has_graph? && !graph_name.eql?(other.graph_name)
236
290
  return true
237
291
  end
238
292
 
@@ -244,7 +298,7 @@ module RDF
244
298
  when 0 then self.subject
245
299
  when 1 then self.predicate
246
300
  when 2 then self.object
247
- when 3 then self.context
301
+ when 3 then self.graph_name
248
302
  else nil
249
303
  end
250
304
  end
@@ -258,7 +312,7 @@ module RDF
258
312
  when 0 then self.subject = value
259
313
  when 1 then self.predicate = value
260
314
  when 2 then self.object = value
261
- when 3 then self.context = value
315
+ when 3 then self.graph_name = value
262
316
  else nil
263
317
  end
264
318
  end
@@ -266,7 +320,7 @@ module RDF
266
320
  ##
267
321
  # @return [Array(RDF::Term)]
268
322
  def to_quad
269
- [subject, predicate, object, context]
323
+ [subject, predicate, object, graph_name]
270
324
  end
271
325
 
272
326
  ##
@@ -288,7 +342,7 @@ module RDF
288
342
  self.subject.canonicalize! if has_subject? && !self.subject.frozen?
289
343
  self.predicate.canonicalize! if has_predicate? && !self.predicate.frozen?
290
344
  self.object.canonicalize! if has_object? && !self.object.frozen?
291
- self.context.canonicalize! if has_context? && !self.context.frozen?
345
+ self.graph_name.canonicalize! if has_graph? && !self.graph_name.frozen?
292
346
  self.validate!
293
347
  self
294
348
  end
@@ -311,8 +365,8 @@ module RDF
311
365
  # @param [Symbol] predicate_key
312
366
  # @param [Symbol] object_key
313
367
  # @return [Hash{Symbol => RDF::Term}]
314
- def to_hash(subject_key = :subject, predicate_key = :predicate, object_key = :object, context_key = :context)
315
- {subject_key => subject, predicate_key => predicate, object_key => object, context_key => context}
368
+ def to_hash(subject_key = :subject, predicate_key = :predicate, object_key = :object, graph_key = :graph_name)
369
+ {subject_key => subject, predicate_key => predicate, object_key => object, graph_key => graph_name}
316
370
  end
317
371
 
318
372
  ##
@@ -320,7 +374,7 @@ module RDF
320
374
  #
321
375
  # @return [String]
322
376
  def to_s
323
- (context ? to_quad : to_triple).map do |term|
377
+ (graph_name ? to_quad : to_triple).map do |term|
324
378
  term.respond_to?(:to_base) ? term.to_base : term.inspect
325
379
  end.join(" ") + " ."
326
380
  end
@@ -332,7 +386,11 @@ module RDF
332
386
  # @return [RDF::Graph]
333
387
  # @see http://www.w3.org/TR/rdf-primer/#reification
334
388
  def reified(options = {})
335
- RDF::Graph.new(options[:context]) do |graph|
389
+ if options.has_key?(:context)
390
+ 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(':')}"
391
+ options[:graph_name] ||= options.delete(:context)
392
+ end
393
+ RDF::Graph.new(options[:graph_name]) do |graph|
336
394
  subject = options[:subject] || RDF::Node.new(options[:id])
337
395
  graph << [subject, RDF.type, RDF[:Statement]]
338
396
  graph << [subject, RDF.subject, self.subject]
@@ -2,7 +2,7 @@ module RDF
2
2
  ##
3
3
  # An RDF term.
4
4
  #
5
- # Terms can be used as subjects, predicates, objects, and contexts of
5
+ # Terms can be used as subjects, predicates, objects, and graph names of
6
6
  # statements.
7
7
  #
8
8
  # @since 0.3.0
@@ -80,6 +80,15 @@ module RDF
80
80
  self
81
81
  end
82
82
 
83
+ ##
84
+ # Term compatibility according to SPARQL
85
+ #
86
+ # @see http://www.w3.org/TR/sparql11-query/#func-arg-compatibility
87
+ # @since 2.0
88
+ def compatible?(other)
89
+ false
90
+ end
91
+
83
92
  protected
84
93
  ##
85
94
  # Escape a term using standard character escapes
data/lib/rdf/model/uri.rb CHANGED
@@ -10,7 +10,7 @@ module RDF
10
10
  # uri = RDF::URI.new("http://rubygems.org/gems/rdf")
11
11
  #
12
12
  # @example Creating a URI reference (2)
13
- # uri = RDF::URI.new(:scheme => 'http', host: 'rubygems.org', path: '/rdf')
13
+ # uri = RDF::URI.new(scheme: 'http', host: 'rubygems.org', path: '/rdf')
14
14
  # #=> RDF::URI.new("http://rubygems.org/gems/rdf")
15
15
  #
16
16
  # @example Creating an interned URI reference
@@ -377,11 +377,11 @@ module RDF
377
377
  # @since 0.3.0
378
378
  def canonicalize!
379
379
  @object = {
380
- :scheme => normalized_scheme,
381
- :authority => normalized_authority,
382
- :path => normalized_path.sub(/\/+/, '/'),
383
- :query => normalized_query,
384
- :fragment => normalized_fragment
380
+ scheme: normalized_scheme,
381
+ authority: normalized_authority,
382
+ path: normalized_path.sub(/\/+/, '/'),
383
+ query: normalized_query,
384
+ fragment: normalized_fragment
385
385
  }
386
386
  @value = nil
387
387
  self
@@ -421,7 +421,7 @@ module RDF
421
421
 
422
422
  case
423
423
  when uri.scheme
424
- joined_parts = uri.object.merge(:path => self.class.normalize_path(uri.path))
424
+ joined_parts = uri.object.merge(path: self.class.normalize_path(uri.path))
425
425
  when uri.authority
426
426
  joined_parts[:authority] = uri.authority
427
427
  joined_parts[:path] = self.class.normalize_path(uri.path)
@@ -572,7 +572,7 @@ module RDF
572
572
  self
573
573
  else
574
574
  RDF::URI.new(
575
- object.merge(:path => '/').
575
+ object.merge(path: '/').
576
576
  keep_if {|k, v| [:scheme, :authority, :path].include?(k)})
577
577
  end
578
578
  end
@@ -616,9 +616,9 @@ module RDF
616
616
  # Returns a qualified name (QName) for this URI based on available vocabularies, if possible.
617
617
  #
618
618
  # @example
619
- # RDF::URI('http://purl.org/dc/terms/').qname #=> [:dc, nil]
620
- # RDF::URI('http://purl.org/dc/terms/title').qname #=> [:dc, :title]
621
- # RDF::DC.title.qname #=> [:dc, :title]
619
+ # RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname #=> [:rdfs, nil]
620
+ # RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname #=> [:rdfs, :label]
621
+ # RDF::RDFS.label.qname #=> [:rdfs, :label]
622
622
  #
623
623
  # @return [Array(Symbol, Symbol)] or `nil` if no QName found
624
624
  def qname
@@ -710,9 +710,9 @@ module RDF
710
710
  # Checks whether this URI the same term as `other`.
711
711
  #
712
712
  # @example
713
- # RDF::URI('http://t.co/').eql?(RDF::URI('http://t.co/')) #=> true
714
- # RDF::URI('http://t.co/').eql?('http://t.co/') #=> false
715
- # RDF::URI('http://purl.org/dc/terms/').eql?(RDF::DC) #=> false
713
+ # RDF::URI('http://t.co/').eql?(RDF::URI('http://t.co/')) #=> true
714
+ # RDF::URI('http://t.co/').eql?('http://t.co/') #=> false
715
+ # RDF::URI('http://www.w3.org/2000/01/rdf-schema#').eql?(RDF::RDFS) #=> false
716
716
  #
717
717
  # @param [RDF::URI] other
718
718
  # @return [Boolean] `true` or `false`
@@ -728,7 +728,7 @@ module RDF
728
728
  # @example
729
729
  # RDF::URI('http://t.co/') == RDF::URI('http://t.co/') #=> true
730
730
  # RDF::URI('http://t.co/') == 'http://t.co/' #=> true
731
- # RDF::URI('http://purl.org/dc/terms/') == RDF::DC #=> true
731
+ # RDF::URI('http://www.w3.org/2000/01/rdf-schema#') == RDF::RDFS #=> true
732
732
  #
733
733
  # @param [Object] other
734
734
  # @return [Boolean] `true` or `false`
@@ -752,7 +752,7 @@ module RDF
752
752
  # RDF::URI('http://example.org/') === /foobar/ #=> false
753
753
  # RDF::URI('http://t.co/') === RDF::URI('http://t.co/') #=> true
754
754
  # RDF::URI('http://t.co/') === 'http://t.co/' #=> true
755
- # RDF::URI('http://purl.org/dc/terms/') === RDF::DC #=> true
755
+ # RDF::URI('http://www.w3.org/2000/01/rdf-schema#') === RDF::RDFS #=> true
756
756
  #
757
757
  # @param [Object] other
758
758
  # @return [Boolean] `true` or `false`
@@ -834,7 +834,7 @@ module RDF
834
834
  #
835
835
  # @return [Fixnum]
836
836
  def hash
837
- return @hash ||= (to_s.hash * -1)
837
+ @hash ||= (value.hash * -1)
838
838
  end
839
839
 
840
840
  ##
@@ -842,9 +842,7 @@ module RDF
842
842
  #
843
843
  # @return [Hash{Symbol => String}]
844
844
  def object
845
- @object ||= begin
846
- parse @value
847
- end
845
+ @object ||= parse(@value)
848
846
  end
849
847
  alias_method :to_hash, :object
850
848
 
@@ -1045,18 +1043,19 @@ module RDF
1045
1043
  when authority
1046
1044
  # ipath-abempty
1047
1045
  segments.map {|s| normalize_segment(s, ISEGMENT)}
1048
- when segments.first.nil?
1046
+ when segments[0].nil?
1049
1047
  # ipath-absolute
1050
1048
  res = [nil]
1051
1049
  res << normalize_segment(segments[1], ISEGMENT_NZ) if segments.length > 1
1052
1050
  res += segments[2..-1].map {|s| normalize_segment(s, ISEGMENT)} if segments.length > 2
1053
1051
  res
1054
- when segments.first.to_s.index(':')
1052
+ when segments[0].to_s.index(':')
1055
1053
  # ipath-noscheme
1056
1054
  res = []
1057
- res << normalize_segment(segments[1], ISEGMENT_NZ_NC)
1055
+ res << normalize_segment(segments[0], ISEGMENT_NZ_NC)
1058
1056
  res += segments[1..-1].map {|s| normalize_segment(s, ISEGMENT)} if segments.length > 1
1059
- when segments.first
1057
+ res
1058
+ when segments[0]
1060
1059
  # ipath-rootless
1061
1060
  # ipath-noscheme
1062
1061
  res = []
@@ -1218,7 +1217,7 @@ module RDF
1218
1217
  # An empty Hash or Array will result in an empty query string.
1219
1218
  #
1220
1219
  # @example
1221
- # uri.query_values = {:a => "a", :b => ["c", "d", "e"]}
1220
+ # uri.query_values = {a: "a", b: ["c", "d", "e"]}
1222
1221
  # uri.query
1223
1222
  # # => "a=a&b=c&b=d&b=e"
1224
1223
  # uri.query_values = [['a', 'a'], ['b', 'c'], ['b', 'd'], ['b', 'e']]
data/lib/rdf/nquads.rb CHANGED
@@ -13,15 +13,14 @@ module RDF
13
13
  # @example Obtaining an NQuads format class
14
14
  # RDF::Format.for(:nquads) #=> RDF::NQuads::Format
15
15
  # RDF::Format.for("etc/doap.nq")
16
- # RDF::Format.for(:file_name => "etc/doap.nq")
17
- # RDF::Format.for(:file_extension => "nq")
18
- # RDF::Format.for(:content_type => "application/n-quads")
19
- # RDF::Format.for(:content_type => "text/x-nquads")
16
+ # RDF::Format.for(file_name: "etc/doap.nq")
17
+ # RDF::Format.for(file_extension: "nq")
18
+ # RDF::Format.for(content_type: "application/n-quads")
20
19
  #
21
20
  # @see http://www.w3.org/TR/n-quads/
22
21
  # @since 0.4.0
23
22
  class Format < RDF::Format
24
- content_type 'application/n-quads', :extension => :nq, :alias => ['text/x-nquads']
23
+ content_type 'application/n-quads', extension: :nq, alias: ['text/x-nquads']
25
24
  content_encoding 'utf-8'
26
25
 
27
26
  reader { RDF::NQuads::Reader }
@@ -58,15 +57,7 @@ module RDF
58
57
 
59
58
  class Reader < NTriples::Reader
60
59
  ##
61
- # @param [String] input
62
- # @return [RDF::Term]
63
- # @since 0.4.0
64
- def self.parse_context(input)
65
- parse_uri(input) || parse_node(input) || parse_literal(input)
66
- end
67
-
68
- ##
69
- # Read a Quad, where the context is optional
60
+ # Read a Quad, where the graph_name is optional
70
61
  #
71
62
  # @return [Array]
72
63
  # @see http://sw.deri.org/2008/07/n-quads/#grammar
@@ -79,13 +70,13 @@ module RDF
79
70
  begin
80
71
  unless blank? || read_comment
81
72
  subject = read_uriref || read_node || fail_subject
82
- predicate = read_uriref(:intern => true) || fail_predicate
73
+ predicate = read_uriref(intern: true) || fail_predicate
83
74
  object = read_uriref || read_node || read_literal || fail_object
84
- context = read_uriref || read_node
75
+ graph_name = read_uriref || read_node
85
76
  if validate? && !read_eos
86
77
  raise RDF::ReaderError.new("ERROR [line #{lineno}] Expected end of statement (found: #{current_line.inspect})")
87
78
  end
88
- return [subject, predicate, object, {:context => context}]
79
+ return [subject, predicate, object, {graph_name: graph_name}]
89
80
  end
90
81
  rescue RDF::ReaderError => e
91
82
  @line = line # this allows #read_value to work
@@ -113,8 +104,8 @@ module RDF
113
104
  # @param [RDF::URI] predicate
114
105
  # @param [RDF::Term] object
115
106
  # @return [void]
116
- def write_quad(subject, predicate, object, context)
117
- puts format_quad(subject, predicate, object, context, @options)
107
+ def write_quad(subject, predicate, object, graph_name)
108
+ puts format_quad(subject, predicate, object, graph_name, @options)
118
109
  end
119
110
 
120
111
  ##
@@ -134,12 +125,12 @@ module RDF
134
125
  # @param [RDF::Resource] subject
135
126
  # @param [RDF::URI] predicate
136
127
  # @param [RDF::Term] object
137
- # @param [RDF::Term] context
128
+ # @param [RDF::Term] graph_name
138
129
  # @param [Hash{Symbol => Object}] options = ({})
139
130
  # @return [String]
140
- def format_quad(subject, predicate, object, context, options = {})
131
+ def format_quad(subject, predicate, object, graph_name, options = {})
141
132
  s = "%s %s %s " % [subject, predicate, object].map { |value| format_term(value, options) }
142
- s += format_term(context, options) + " " if context
133
+ s += format_term(graph_name, options) + " " if graph_name
143
134
  s + "."
144
135
  end
145
136
  end # Writer
@@ -9,15 +9,14 @@ module RDF::NTriples
9
9
  # @example Obtaining an NTriples format class
10
10
  # RDF::Format.for(:ntriples) #=> RDF::NTriples::Format
11
11
  # RDF::Format.for("etc/doap.nt")
12
- # RDF::Format.for(:file_name => "etc/doap.nt")
13
- # RDF::Format.for(:file_extension => "nt")
14
- # RDF::Format.for(:content_type => "application/n-triples")
15
- # RDF::Format.for(:content_type => "text/plain")
12
+ # RDF::Format.for(file_name: "etc/doap.nt")
13
+ # RDF::Format.for(file_extension: "nt")
14
+ # RDF::Format.for(content_type: "application/n-triples")
16
15
  #
17
16
  # @see http://www.w3.org/TR/rdf-testcases/#ntriples
18
17
  # @see http://www.w3.org/TR/n-triples/
19
18
  class Format < RDF::Format
20
- content_type 'application/n-triples', :extension => :nt, :alias => ['text/plain']
19
+ content_type 'application/n-triples', extension: :nt, alias: ['text/plain']
21
20
  content_encoding 'utf-8'
22
21
 
23
22
  reader { RDF::NTriples::Reader }
@@ -6,9 +6,9 @@ module RDF::NTriples
6
6
  # @example Obtaining an NTriples reader class
7
7
  # RDF::Reader.for(:ntriples) #=> RDF::NTriples::Reader
8
8
  # RDF::Reader.for("etc/doap.nt")
9
- # RDF::Reader.for(:file_name => "etc/doap.nt")
10
- # RDF::Reader.for(:file_extension => "nt")
11
- # RDF::Reader.for(:content_type => "text/plain")
9
+ # RDF::Reader.for(file_name: "etc/doap.nt")
10
+ # RDF::Reader.for(file_extension: "nt")
11
+ # RDF::Reader.for(content_type: "application/n-triples")
12
12
  #
13
13
  # @example Parsing RDF statements from an NTriples file
14
14
  # RDF::NTriples::Reader.open("etc/doap.nt") do |reader|
@@ -110,7 +110,7 @@ module RDF::NTriples
110
110
  # @param [String] input
111
111
  # @return [RDF::URI]
112
112
  def self.parse_predicate(input)
113
- parse_uri(input, :intern => true)
113
+ parse_uri(input, intern: true)
114
114
  end
115
115
 
116
116
  ##
@@ -144,9 +144,9 @@ module RDF::NTriples
144
144
  def self.parse_literal(input)
145
145
  case input
146
146
  when LITERAL_WITH_LANGUAGE
147
- RDF::Literal.new(unescape($1), :language => $2)
147
+ RDF::Literal.new(unescape($1), language: $4)
148
148
  when LITERAL_WITH_DATATYPE
149
- RDF::Literal.new(unescape($1), :datatype => $2)
149
+ RDF::Literal.new(unescape($1), datatype: $4)
150
150
  when LITERAL_PLAIN
151
151
  RDF::Literal.new(unescape($1))
152
152
  end
@@ -169,7 +169,7 @@ module RDF::NTriples
169
169
  while
170
170
  (string.sub!(ESCAPE_SURROGATE) do
171
171
  if ESCAPE_SURROGATE1.include?($1.hex) && ESCAPE_SURROGATE2.include?($2.hex)
172
- warn "[DEPRECATION] Surrogate pairs support deprecated. Support will be removed in a future release."
172
+ warn "[DEPRECATION] Surrogate pairs support deprecated. Support will be removed in RDF.rb 2.0. Called from #{Gem.location_of_caller.join(':')}"
173
173
  s = [$1, $2].pack('H*H*')
174
174
  s.force_encoding(Encoding::UTF_16BE).encode!(Encoding::UTF_8)
175
175
  else
@@ -207,7 +207,7 @@ module RDF::NTriples
207
207
  begin
208
208
  unless blank? || read_comment
209
209
  subject = read_uriref || read_node || fail_subject
210
- predicate = read_uriref(:intern => true) || fail_predicate
210
+ predicate = read_uriref(intern: true) || fail_predicate
211
211
  object = read_uriref || read_node || read_literal || fail_object
212
212
 
213
213
  if validate? && !read_eos
@@ -263,9 +263,9 @@ module RDF::NTriples
263
263
  literal_str = self.class.unescape(literal_str)
264
264
  literal = case
265
265
  when language = match(LANGTAG)
266
- RDF::Literal.new(literal_str, :language => language)
266
+ RDF::Literal.new(literal_str, language: language)
267
267
  when datatype = match(/^(\^\^)/) # FIXME
268
- RDF::Literal.new(literal_str, :datatype => read_uriref || fail_object)
268
+ RDF::Literal.new(literal_str, datatype: read_uriref || fail_object)
269
269
  else
270
270
  RDF::Literal.new(literal_str) # plain string literal
271
271
  end
@@ -4,15 +4,15 @@ module RDF::NTriples
4
4
  # N-Triples serializer.
5
5
  #
6
6
  # Output is serialized for UTF-8, to serialize as ASCII
7
- # (with) unicode escapes, set :encoding => Encoding::ASCII as
7
+ # (with) unicode escapes, set encoding: Encoding::ASCII as
8
8
  # an option to {RDF::NTriples::Writer#initialize}.
9
9
  #
10
10
  # @example Obtaining an NTriples writer class
11
11
  # RDF::Writer.for(:ntriples) #=> RDF::NTriples::Writer
12
12
  # RDF::Writer.for("etc/test.nt")
13
- # RDF::Writer.for(:file_name => "etc/test.nt")
14
- # RDF::Writer.for(:file_extension => "nt")
15
- # RDF::Writer.for(:content_type => "text/plain")
13
+ # RDF::Writer.for(file_name: "etc/test.nt")
14
+ # RDF::Writer.for(file_extension: "nt")
15
+ # RDF::Writer.for(content_type: "application/n-triples")
16
16
  #
17
17
  # @example Serializing RDF statements into an NTriples file
18
18
  # RDF::NTriples::Writer.open("etc/test.nt") do |writer|
@@ -29,7 +29,7 @@ module RDF::NTriples
29
29
  # end
30
30
  #
31
31
  # @example Serializing RDF statements into an NTriples string with escaped UTF-8
32
- # RDF::NTriples::Writer.buffer(:encoding => Encoding::ASCII) do |writer|
32
+ # RDF::NTriples::Writer.buffer(encoding: Encoding::ASCII) do |writer|
33
33
  # graph.each_statement do |statement|
34
34
  # writer << statement
35
35
  # end
@@ -187,7 +187,7 @@ module RDF::NTriples
187
187
  # @yieldparam [RDF::Writer] writer
188
188
  # @yieldreturn [void]
189
189
  def initialize(output = $stdout, options = {}, &block)
190
- options = {:validate => true}.merge(options)
190
+ options = {validate: true}.merge(options)
191
191
  super
192
192
  end
193
193