rdf 3.1.9 → 3.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bef3d8a6e581bbf440091f39f73f61504a942ea38ec97d5a4885030d93400d6
4
- data.tar.gz: 83fc1c5544b286a7e859e98f0674fc48dec07fd3756371e00677393358a3d6ca
3
+ metadata.gz: 5de713395026fd70491ac47ef4c5c89e63681bccf27d8b9e39fe21fcf63c1344
4
+ data.tar.gz: a2bc97b12d11858f4089fba2915f358ba28db0bb4704ce70e668f17c80e9a739
5
5
  SHA512:
6
- metadata.gz: 0bfe6c39d8f96cddd544b908e43fb1481ad6ef4fd32b4eefaf2a38f590ffa226f86150adc655cc34a411737956ee9f2c403352ff88056026d1f422b4db5f2a84
7
- data.tar.gz: 02142d3d36e4cce7a65d71d287a0748de0b716f0cbf25647092c65ba662bc4c78736403cc57e53deafc41ed37b36dc55fc602703b1a21ccaf543a1a084ab7363
6
+ metadata.gz: 334cf936abb27e4c0a8fe225c4bd309b455ab96fcf1e79369abe3a763b28e922172b5d477a9a2112677f3ae21d8b3a0fdb9696d6d89bb6ce85bf49831464f611
7
+ data.tar.gz: 76d46e91f93f70e021f482b089fb4a5afebb955e835d89965e270688a46fb938a5b1e334d2c0e5d9992a149de97bb84c5f14e8f4da62019aaa7bec7fcb7f582e
data/README.md CHANGED
@@ -7,7 +7,7 @@ This is a pure-Ruby library for working with [Resource Description Framework
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/rdf.png)](https://badge.fury.io/rb/rdf)
9
9
  [![Build Status](https://github.com/ruby-rdf/rdf/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf/actions?query=workflow%3ACI)
10
- [![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/github/ruby-rdf/rdf)
10
+ [![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg?branch=develop)](https://coveralls.io/github/ruby-rdf/rdf?branch=develop)
11
11
  [![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
12
12
 
13
13
  ## Features
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.9
1
+ 3.1.10
data/lib/rdf/cli.rb CHANGED
@@ -333,7 +333,7 @@ module RDF
333
333
 
334
334
  # Add format-specific reader options
335
335
  reader.options.each do |cli_opt|
336
- next if options.options.has_key?(cli_opt.symbol)
336
+ next if options.options.key?(cli_opt.symbol)
337
337
  on_args = cli_opt.on || []
338
338
  on_args << cli_opt.description if cli_opt.description
339
339
  options.on(*on_args) do |opt_arg|
@@ -355,7 +355,7 @@ module RDF
355
355
 
356
356
  # Add format-specific writer options
357
357
  writer.options.each do |cli_opt|
358
- next if options.options.has_key?(cli_opt.symbol)
358
+ next if options.options.key?(cli_opt.symbol)
359
359
  on_args = cli_opt.on || []
360
360
  on_args << cli_opt.description if cli_opt.description
361
361
  options.on(*on_args) do |opt_arg|
@@ -419,7 +419,7 @@ module RDF
419
419
  end
420
420
 
421
421
  cli_opts.each do |cli_opt|
422
- next if opts.has_key?(cli_opt.symbol)
422
+ next if opts.key?(cli_opt.symbol)
423
423
  on_args = cli_opt.on || []
424
424
  on_args << cli_opt.description if cli_opt.description
425
425
  options.on(*on_args) do |arg|
@@ -12,15 +12,15 @@ module RDF
12
12
  # enumerable.count
13
13
  #
14
14
  # @example Checking whether a specific statement exists
15
- # enumerable.has_statement?(RDF::Statement(subject, predicate, object))
16
- # enumerable.has_triple?([subject, predicate, object])
17
- # enumerable.has_quad?([subject, predicate, object, graph_name])
15
+ # enumerable.statement?(RDF::Statement(subject, predicate, object))
16
+ # enumerable.triple?([subject, predicate, object])
17
+ # enumerable.quad?([subject, predicate, object, graph_name])
18
18
  #
19
19
  # @example Checking whether a specific value exists
20
- # enumerable.has_subject?(RDF::URI("https://rubygems.org/gems/rdf"))
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"))
20
+ # enumerable.subject?(RDF::URI("https://rubygems.org/gems/rdf"))
21
+ # enumerable.predicate?(RDF::RDFS.label)
22
+ # enumerable.object?(RDF::Literal("A Ruby library for working with Resource Description Framework (RDF) data.", language: :en))
23
+ # enumerable.graph?(RDF::URI("http://ar.to/#self"))
24
24
  #
25
25
  # @example Enumerating all statements
26
26
  # enumerable.each_statement do |statement|
@@ -127,14 +127,20 @@ module RDF
127
127
  end
128
128
 
129
129
  ##
130
- # Returns `true` if `self` contains the given RDF statement.
130
+ # @overload statement?
131
+ # Returns `false` indicating this is not an RDF::Statemenet.
132
+ # @return [Boolean]
133
+ # @see RDF::Value#statement?
134
+ # @overload statement?(statement)
135
+ # Returns `true` if `self` contains the given RDF statement.
131
136
  #
132
- # @param [RDF::Statement] statement
133
- # @return [Boolean]
134
- def has_statement?(statement)
135
- !enum_statement.find { |s| s.eql?(statement) }.nil?
137
+ # @param [RDF::Statement] statement
138
+ # @return [Boolean]
139
+ def statement?(statement = nil)
140
+ statement && !enum_statement.find { |s| s.eql?(statement) }.nil?
136
141
  end
137
- alias_method :include?, :has_statement?
142
+ alias_method :has_statement?, :statement?
143
+ alias_method :include?, :statement?
138
144
 
139
145
  ##
140
146
  # Iterates the given block for each RDF statement.
@@ -194,9 +200,10 @@ module RDF
194
200
  #
195
201
  # @param [Array(RDF::Resource, RDF::URI, RDF::Term)] triple
196
202
  # @return [Boolean]
197
- def has_triple?(triple)
203
+ def triple?(triple)
198
204
  triples.include?(triple)
199
205
  end
206
+ alias_method :has_triple?, :triple?
200
207
 
201
208
  ##
202
209
  # Iterates the given block for each RDF triple.
@@ -255,9 +262,10 @@ module RDF
255
262
  #
256
263
  # @param [Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)] quad
257
264
  # @return [Boolean]
258
- def has_quad?(quad)
265
+ def quad?(quad)
259
266
  quads.include?(quad)
260
267
  end
268
+ alias_method :has_quad?, :quad?
261
269
 
262
270
  ##
263
271
  # Iterates the given block for each RDF quad.
@@ -321,9 +329,10 @@ module RDF
321
329
  #
322
330
  # @param [RDF::Resource] value
323
331
  # @return [Boolean]
324
- def has_subject?(value)
332
+ def subject?(value)
325
333
  enum_subject.include?(value)
326
334
  end
335
+ alias_method :has_subject?, :subject?
327
336
 
328
337
  ##
329
338
  # Iterates the given block for each unique RDF subject term.
@@ -386,9 +395,10 @@ module RDF
386
395
  #
387
396
  # @param [RDF::URI] value
388
397
  # @return [Boolean]
389
- def has_predicate?(value)
398
+ def predicate?(value)
390
399
  enum_predicate.include?(value)
391
400
  end
401
+ alias_method :has_predicate?, :predicate?
392
402
 
393
403
  ##
394
404
  # Iterates the given block for each unique RDF predicate term.
@@ -451,9 +461,10 @@ module RDF
451
461
  #
452
462
  # @param [RDF::Term] value
453
463
  # @return [Boolean]
454
- def has_object?(value)
464
+ def object?(value)
455
465
  enum_object.include?(value)
456
466
  end
467
+ alias_method :has_object?, :object?
457
468
 
458
469
  ##
459
470
  # Iterates the given block for each unique RDF object term.
@@ -511,7 +522,7 @@ module RDF
511
522
  def terms(unique: true)
512
523
  unless unique
513
524
  enum_statement.
514
- map(&:to_quad).
525
+ map(&:terms).
515
526
  flatten.
516
527
  compact
517
528
  else
@@ -520,14 +531,20 @@ module RDF
520
531
  end
521
532
 
522
533
  ##
523
- # Returns `true` if `self` contains the given RDF subject term.
534
+ # @overload term?
535
+ # Returns `false` indicating this is not an RDF::Statemenet.
536
+ # @see RDF::Value#statement?
537
+ # @return [Boolean]
538
+ # @overload term?(value)
539
+ # Returns `true` if `self` contains the given RDF subject term.
524
540
  #
525
- # @param [RDF::Resource] value
526
- # @return [Boolean]
527
- # @since 2.0
528
- def has_term?(value)
529
- enum_term.include?(value)
541
+ # @param [RDF::Resource] value
542
+ # @return [Boolean]
543
+ # @since 2.0
544
+ def term?(value = nil)
545
+ value && enum_term.include?(value)
530
546
  end
547
+ alias_method :has_term?, :term?
531
548
 
532
549
  ##
533
550
  # Iterates the given block for each unique RDF term (subject, predicate, object, or graph_name).
@@ -551,8 +568,8 @@ module RDF
551
568
  if block_given?
552
569
  values = {}
553
570
  each_statement do |statement|
554
- statement.to_quad.each do |value|
555
- unless value.nil? || values.include?(value.hash)
571
+ statement.terms.each do |value|
572
+ unless values.include?(value.hash)
556
573
  values[value.hash] = true
557
574
  yield value
558
575
  end
@@ -595,9 +612,10 @@ module RDF
595
612
  # @param [RDF::Resource, false] graph_name
596
613
  # Use value `false` to query for the default graph_name
597
614
  # @return [Boolean]
598
- def has_graph?(graph_name)
615
+ def graph?(graph_name)
599
616
  enum_statement.any? {|s| s.graph_name == graph_name}
600
617
  end
618
+ alias_method :has_graph?, :graph?
601
619
 
602
620
  ##
603
621
  # Limits statements to be from a specific graph.
@@ -122,7 +122,7 @@ module RDF
122
122
 
123
123
  statements.each do |statement|
124
124
  if (statement = Statement.from(statement))
125
- if statement.has_object?
125
+ if statement.object?
126
126
  delete_insert([[statement.subject, statement.predicate, nil]], [statement])
127
127
  else
128
128
  delete([statement.subject, statement.predicate, nil])
@@ -104,7 +104,7 @@ module RDF
104
104
  # @private
105
105
  # @see RDF::Enumerable#supports?
106
106
  def supports?(feature)
107
- return true if [:graph_name, :rdfstar].include?(feature)
107
+ return true if %i(graph_name rdfstar).include?(feature)
108
108
  super
109
109
  end
110
110
 
@@ -215,18 +215,25 @@ module RDF
215
215
  end
216
216
 
217
217
  ##
218
- # Returns `true` if this graph contains the given RDF statement.
218
+ # @overload statement?
219
+ # Returns `false` indicating this is not an RDF::Statemenet.
220
+ # @see RDF::Value#statement?
221
+ # @return [Boolean]
222
+ # @overload statement?(statement)
223
+ # Returns `true` if this graph contains the given RDF statement.
219
224
  #
220
- # A statement is in a graph if the statement if it has the same triples without regard to graph_name.
225
+ # A statement is in a graph if the statement if it has the same triples without regard to graph_name.
221
226
  #
222
- # @param [Statement] statement
223
- # @return [Boolean]
224
- # @see RDF::Enumerable#has_statement?
225
- def has_statement?(statement)
227
+ # @param [Statement] statement
228
+ # @return [Boolean]
229
+ # @see RDF::Enumerable#statement?
230
+ def statement?(statement = nil)
231
+ return false if statement.nil?
226
232
  statement = statement.dup
227
233
  statement.graph_name = graph_name
228
- @data.has_statement?(statement)
234
+ @data.statement?(statement)
229
235
  end
236
+ alias_method :has_statement?, :statement?
230
237
 
231
238
  ##
232
239
  # Enumerates each RDF statement in this graph.
@@ -25,7 +25,7 @@ module RDF
25
25
  #
26
26
  # @example Creating a language-tagged literal (1)
27
27
  # value = RDF::Literal.new("Hello!", language: :en)
28
- # value.has_language? #=> true
28
+ # value.language? #=> true
29
29
  # value.language #=> :en
30
30
  #
31
31
  # @example Creating a language-tagged literal (2)
@@ -35,12 +35,12 @@ module RDF
35
35
  #
36
36
  # @example Creating an explicitly datatyped literal
37
37
  # value = RDF::Literal.new("2009-12-31", datatype: RDF::XSD.date)
38
- # value.has_datatype? #=> true
38
+ # value.datatype? #=> true
39
39
  # value.datatype #=> RDF::XSD.date
40
40
  #
41
41
  # @example Creating an implicitly datatyped literal
42
42
  # value = RDF::Literal.new(Date.today)
43
- # value.has_datatype? #=> true
43
+ # value.datatype? #=> true
44
44
  # value.datatype #=> RDF::XSD.date
45
45
  #
46
46
  # @example Creating implicitly datatyped literals
@@ -225,7 +225,7 @@ module RDF
225
225
  # * The arguments are simple literals or literals typed as xsd:string
226
226
  # * The arguments are plain literals with identical language tags
227
227
  # * The first argument is a plain literal with language tag and the second argument is a simple literal or literal typed as xsd:string
228
- has_language? ?
228
+ language? ?
229
229
  (language == other.language || other.datatype == RDF::URI("http://www.w3.org/2001/XMLSchema#string")) :
230
230
  other.datatype == RDF::URI("http://www.w3.org/2001/XMLSchema#string")
231
231
  end
@@ -289,7 +289,7 @@ module RDF
289
289
  case
290
290
  when self.eql?(other)
291
291
  true
292
- when self.has_language? && self.language.to_s == other.language.to_s
292
+ when self.language? && self.language.to_s == other.language.to_s
293
293
  # Literals with languages can compare if languages are identical
294
294
  self.value_hash == other.value_hash && self.value == other.value
295
295
  when self.simple? && other.simple?
@@ -335,10 +335,10 @@ module RDF
335
335
  #
336
336
  # @return [Boolean] `true` or `false`
337
337
  # @see http://www.w3.org/TR/rdf-concepts/#dfn-plain-literal
338
- def has_language?
338
+ def language?
339
339
  datatype == RDF.langString
340
340
  end
341
- alias_method :language?, :has_language?
341
+ alias_method :has_language?, :language?
342
342
 
343
343
  ##
344
344
  # Returns `true` if this is a datatyped literal.
@@ -347,12 +347,12 @@ module RDF
347
347
  #
348
348
  # @return [Boolean] `true` or `false`
349
349
  # @see http://www.w3.org/TR/rdf-concepts/#dfn-typed-literal
350
- def has_datatype?
350
+ def datatype?
351
351
  !plain? && !language?
352
352
  end
353
- alias_method :datatype?, :has_datatype?
354
- alias_method :typed?, :has_datatype?
355
- alias_method :datatyped?, :has_datatype?
353
+ alias_method :has_datatype?, :datatype?
354
+ alias_method :typed?, :datatype?
355
+ alias_method :datatyped?, :datatype?
356
356
 
357
357
  ##
358
358
  # Returns `true` if the value adheres to the defined grammar of the
@@ -386,16 +386,16 @@ module RDF
386
386
  # This behavior is intuited from SPARQL data-r2/expr-equal/eq-2-2
387
387
  # @return [Boolean]
388
388
  def comperable_datatype?(other)
389
- return false unless self.plain? || self.has_language?
389
+ return false unless self.plain? || self.language?
390
390
 
391
391
  case other
392
392
  when RDF::Literal::Numeric, RDF::Literal::Boolean,
393
393
  RDF::Literal::Date, RDF::Literal::Time, RDF::Literal::DateTime
394
394
  # Invald types can be compared without raising a TypeError if literal has a language (open-eq-08)
395
- !other.valid? && self.has_language?
395
+ !other.valid? && self.language?
396
396
  else
397
397
  # An unknown datatype may not be used for comparison, unless it has a language? (open-eq-8)
398
- self.has_language?
398
+ self.language?
399
399
  end
400
400
  end
401
401
 
@@ -51,11 +51,13 @@ module RDF; class Literal
51
51
  #
52
52
  # @return [Boolean]
53
53
  # @since 1.1.6
54
- def has_timezone?
54
+ def timezone?
55
55
  md = self.to_s.match(GRAMMAR)
56
56
  md && !!md[2]
57
57
  end
58
- alias_method :has_tz?, :has_timezone?
58
+ alias_method :tz?, :timezone?
59
+ alias_method :has_tz?, :timezone?
60
+ alias_method :has_timezone?, :timezone?
59
61
 
60
62
  ##
61
63
  # Returns the value as a string.
@@ -72,7 +74,7 @@ module RDF; class Literal
72
74
  # @since 1.1.6
73
75
  def humanize(lang = :en)
74
76
  d = object.strftime("%A, %d %B %Y")
75
- if has_timezone?
77
+ if timezone?
76
78
  d += if self.tz == 'Z'
77
79
  " UTC"
78
80
  else
@@ -30,7 +30,7 @@ module RDF; class Literal
30
30
  # @see http://www.w3.org/TR/xmlschema11-2/#dateTime
31
31
  def canonicalize!
32
32
  if self.valid?
33
- @string = if has_timezone?
33
+ @string = if timezone?
34
34
  @object.new_offset.new_offset.strftime(FORMAT[0..-4] + 'Z').sub('.000', '')
35
35
  else
36
36
  @object.strftime(FORMAT[0..-4]).sub('.000', '')
@@ -45,7 +45,7 @@ module RDF; class Literal
45
45
  # @return [RDF::Literal]
46
46
  # @see http://www.w3.org/TR/sparql11-query/#func-tz
47
47
  def tz
48
- zone = has_timezone? ? object.zone : ""
48
+ zone = timezone? ? object.zone : ""
49
49
  zone = "Z" if zone == "+00:00"
50
50
  RDF::Literal(zone)
51
51
  end
@@ -85,21 +85,25 @@ module RDF; class Literal
85
85
  #
86
86
  # @return [Boolean]
87
87
  # @since 1.1.6
88
- def has_milliseconds?
88
+ def milliseconds?
89
89
  self.format("%L").to_i > 0
90
90
  end
91
- alias_method :has_ms?, :has_milliseconds?
91
+ alias_method :has_milliseconds?, :milliseconds?
92
+ alias_method :has_ms?, :milliseconds?
93
+ alias_method :ms?, :milliseconds?
92
94
 
93
95
  ##
94
96
  # Does the literal representation include a timezone? Note that this is only possible if initialized using a string, or `:lexical` option.
95
97
  #
96
98
  # @return [Boolean]
97
99
  # @since 1.1.6
98
- def has_timezone?
100
+ def timezone?
99
101
  md = self.to_s.match(GRAMMAR)
100
102
  md && !!md[2]
101
103
  end
102
- alias_method :has_tz?, :has_timezone?
104
+ alias_method :tz?, :timezone?
105
+ alias_method :has_tz?, :timezone?
106
+ alias_method :has_timezone?, :timezone?
103
107
 
104
108
  ##
105
109
  # Returns the `timezone` of the literal. If the
@@ -118,7 +122,7 @@ module RDF; class Literal
118
122
  # @since 1.1.6
119
123
  def humanize(lang = :en)
120
124
  d = object.strftime("%r on %A, %d %B %Y")
121
- if has_timezone?
125
+ if timezone?
122
126
  zone = if self.tz == 'Z'
123
127
  "UTC"
124
128
  else
@@ -42,7 +42,7 @@ module RDF; class Literal
42
42
  # @see http://www.w3.org/TR/xmlschema11-2/#time
43
43
  def canonicalize!
44
44
  if self.valid?
45
- @string = if has_timezone?
45
+ @string = if timezone?
46
46
  @object.new_offset.new_offset.strftime(FORMAT[0..-4] + 'Z').sub('.000', '')
47
47
  else
48
48
  @object.strftime(FORMAT[0..-4]).sub('.000', '')
@@ -57,7 +57,7 @@ module RDF; class Literal
57
57
  # @return [RDF::Literal]
58
58
  # @see http://www.w3.org/TR/sparql11-query/#func-tz
59
59
  def tz
60
- zone = has_timezone? ? object.zone : ""
60
+ zone = timezone? ? object.zone : ""
61
61
  zone = "Z" if zone == "+00:00"
62
62
  RDF::Literal(zone)
63
63
  end
@@ -79,11 +79,13 @@ module RDF; class Literal
79
79
  #
80
80
  # @return [Boolean]
81
81
  # @since 1.1.6
82
- def has_timezone?
82
+ def timezone?
83
83
  md = self.to_s.match(GRAMMAR)
84
84
  md && !!md[2]
85
85
  end
86
- alias_method :has_tz?, :has_timezone?
86
+ alias_method :tz?, :timezone?
87
+ alias_method :has_tz?, :timezone?
88
+ alias_method :has_timezone?, :timezone?
87
89
 
88
90
  ##
89
91
  # Returns the value as a string.
@@ -101,7 +103,7 @@ module RDF; class Literal
101
103
  # @since 1.1.6
102
104
  def humanize(lang = :en)
103
105
  t = object.strftime("%r")
104
- if has_timezone?
106
+ if timezone?
105
107
  t += if self.tz == 'Z'
106
108
  " UTC"
107
109
  else
@@ -96,7 +96,7 @@ module RDF
96
96
  @predicate = predicate
97
97
  @object = object
98
98
  end
99
- @id = @options.delete(:id) if @options.has_key?(:id)
99
+ @id = @options.delete(:id) if @options.key?(:id)
100
100
  @graph_name = @options.delete(:graph_name)
101
101
  initialize!
102
102
  end
@@ -149,10 +149,10 @@ module RDF
149
149
  #
150
150
  # @return [Boolean]
151
151
  def variable?
152
- !(has_subject? && subject.constant? &&
153
- has_predicate? && predicate.constant? &&
154
- has_object? && object.constant? &&
155
- (has_graph? ? graph_name.constant? : true))
152
+ !(subject? && subject.constant? &&
153
+ predicate? && predicate.constant? &&
154
+ object? && object.constant? &&
155
+ (graph? ? graph_name.constant? : true))
156
156
  end
157
157
 
158
158
  ##
@@ -172,10 +172,10 @@ module RDF
172
172
  ##
173
173
  # @return [Boolean]
174
174
  def valid?
175
- has_subject? && subject.resource? && subject.valid? &&
176
- has_predicate? && predicate.uri? && predicate.valid? &&
177
- has_object? && object.term? && object.valid? &&
178
- (has_graph? ? (graph_name.resource? && graph_name.valid?) : true)
175
+ subject? && subject.resource? && subject.valid? &&
176
+ predicate? && predicate.uri? && predicate.valid? &&
177
+ object? && object.term? && object.valid? &&
178
+ (graph? ? (graph_name.resource? && graph_name.valid?) : true)
179
179
  end
180
180
 
181
181
  ##
@@ -216,31 +216,37 @@ module RDF
216
216
 
217
217
  ##
218
218
  # @return [Boolean]
219
- def has_graph?
219
+ def graph?
220
220
  !!graph_name
221
221
  end
222
- alias_method :has_name?, :has_graph?
222
+ alias_method :name?, :graph?
223
+ alias_method :has_graph?, :graph?
224
+ alias_method :has_name?, :graph?
223
225
 
224
226
  ##
225
227
  # @return [Boolean]
226
- def has_subject?
228
+ def subject?
227
229
  !!subject
228
230
  end
231
+ alias_method :has_subject?, :subject?
229
232
 
230
233
  ##
231
234
  # @return [Boolean]
232
- def has_predicate?
235
+ def predicate?
233
236
  !!predicate
234
237
  end
238
+ alias_method :has_predicate?, :predicate?
235
239
 
236
240
  ##
237
241
  # @return [Boolean]
238
- def has_object?
242
+ def object?
239
243
  !!object
240
244
  end
245
+ alias_method :has_object?, :object?
241
246
 
242
247
  ##
243
- # Returns `true` if any resource of this statement is a blank node.
248
+ # Returns `true` if any resource of this statement is a blank node
249
+ # or has an embedded statement including a blank node.
244
250
  #
245
251
  # @return [Boolean]
246
252
  # @since 2.0
@@ -312,10 +318,10 @@ module RDF
312
318
  # @see RDF::Literal#eql?
313
319
  # @see RDF::Query::Variable#eql?
314
320
  def ===(other)
315
- return false if has_object? && !object.eql?(other.object)
316
- return false if has_predicate? && !predicate.eql?(other.predicate)
317
- return false if has_subject? && !subject.eql?(other.subject)
318
- return false if has_graph? && !graph_name.eql?(other.graph_name)
321
+ return false if object? && !object.eql?(other.object)
322
+ return false if predicate? && !predicate.eql?(other.predicate)
323
+ return false if subject? && !subject.eql?(other.subject)
324
+ return false if graph? && !graph_name.eql?(other.graph_name)
319
325
  return true
320
326
  end
321
327
 
@@ -359,6 +365,13 @@ module RDF
359
365
  end
360
366
  alias_method :to_a, :to_triple
361
367
 
368
+ ##
369
+ # Returns an array of all the non-nil non-statement terms.
370
+ # @return [Array(RDF::Term)]
371
+ def terms
372
+ to_quad.map {|t| t.respond_to?(:terms) ? t.terms : t}.flatten.compact
373
+ end
374
+
362
375
  ##
363
376
  # Canonicalizes each unfrozen term in the statement
364
377
  #
@@ -366,10 +379,10 @@ module RDF
366
379
  # @since 1.0.8
367
380
  # @raise [ArgumentError] if any element cannot be canonicalized.
368
381
  def canonicalize!
369
- self.subject.canonicalize! if has_subject? && !self.subject.frozen?
370
- self.predicate.canonicalize! if has_predicate? && !self.predicate.frozen?
371
- self.object.canonicalize! if has_object? && !self.object.frozen?
372
- self.graph_name.canonicalize! if has_graph? && !self.graph_name.frozen?
382
+ self.subject.canonicalize! if subject? && !self.subject.frozen?
383
+ self.predicate.canonicalize! if predicate? && !self.predicate.frozen?
384
+ self.object.canonicalize! if object? && !self.object.frozen?
385
+ self.graph_name.canonicalize! if graph? && !self.graph_name.frozen?
373
386
  self.validate!
374
387
  @hash = nil
375
388
  self
@@ -72,6 +72,14 @@ module RDF
72
72
  self
73
73
  end
74
74
 
75
+ ##
76
+ # Returns an array including just itself.
77
+ #
78
+ # @return [Array<RDF::Value>]
79
+ def terms
80
+ [self]
81
+ end
82
+
75
83
  ##
76
84
  # Returns the base representation of this term.
77
85
  #
data/lib/rdf/model/uri.rb CHANGED
@@ -226,13 +226,13 @@ module RDF
226
226
  @value.dup.force_encoding(Encoding::UTF_8) if @value.encoding != Encoding::UTF_8
227
227
  @value.freeze
228
228
  else
229
- %w(
229
+ %i(
230
230
  scheme
231
231
  user password userinfo
232
232
  host port authority
233
233
  path query fragment
234
- ).map(&:to_sym).each do |meth|
235
- if options.has_key?(meth)
234
+ ).each do |meth|
235
+ if options.key?(meth)
236
236
  self.send("#{meth}=".to_sym, options[meth])
237
237
  else
238
238
  self.send(meth)
@@ -416,7 +416,7 @@ module RDF
416
416
  # @see http://tools.ietf.org/html/rfc3986#section-5.2.2
417
417
  # @see http://tools.ietf.org/html/rfc3986#section-5.2.3
418
418
  def join(*uris)
419
- joined_parts = object.dup.delete_if {|k, v| [:user, :password, :host, :port].include?(k)}
419
+ joined_parts = object.dup.delete_if {|k, v| %i(user password host port).include?(k)}
420
420
 
421
421
  uris.each do |uri|
422
422
  uri = RDF::URI.new(uri) unless uri.is_a?(RDF::URI)
@@ -580,7 +580,7 @@ module RDF
580
580
  else
581
581
  RDF::URI.new(
582
582
  **object.merge(path: '/').
583
- keep_if {|k, v| [:scheme, :authority, :path].include?(k)})
583
+ keep_if {|k, v| %i(scheme authority path).include?(k)})
584
584
  end
585
585
  end
586
586
 
@@ -588,13 +588,14 @@ module RDF
588
588
  # Returns `true` if this URI is hierarchical and it's path component isn't equal to `/`.
589
589
  #
590
590
  # @example
591
- # RDF::URI('http://example.org/').has_parent? #=> false
592
- # RDF::URI('http://example.org/path/').has_parent? #=> true
591
+ # RDF::URI('http://example.org/').parent? #=> false
592
+ # RDF::URI('http://example.org/path/').parent? #=> true
593
593
  #
594
594
  # @return [Boolean] `true` or `false`
595
- def has_parent?
595
+ def parent?
596
596
  !root?
597
597
  end
598
+ alias_method :has_parent?, :parent?
598
599
 
599
600
  ##
600
601
  # Returns a copy of this URI with the path component ascended to the
@@ -1122,7 +1123,7 @@ module RDF
1122
1123
  # @param [String, #to_s] value
1123
1124
  # @return [RDF::URI] self
1124
1125
  def authority=(value)
1125
- object.delete_if {|k, v| [:user, :password, :host, :port, :userinfo].include?(k)}
1126
+ object.delete_if {|k, v| %i(user password host port userinfo).include?(k)}
1126
1127
  object[:authority] = (value.to_s.dup.force_encoding(Encoding::UTF_8) if value)
1127
1128
  user; password; userinfo; host; port
1128
1129
  @value = nil
@@ -1152,7 +1153,7 @@ module RDF
1152
1153
  # @param [String, #to_s] value
1153
1154
  # @return [RDF::URI] self
1154
1155
  def userinfo=(value)
1155
- object.delete_if {|k, v| [:user, :password, :authority].include?(k)}
1156
+ object.delete_if {|k, v| %i(user password authority).include?(k)}
1156
1157
  object[:userinfo] = (value.to_s.dup.force_encoding(Encoding::UTF_8) if value)
1157
1158
  user; password; authority
1158
1159
  @value = nil
@@ -309,8 +309,8 @@ module RDF::NTriples
309
309
  when RDF::Literal
310
310
  # Note, escaping here is more robust than in Term
311
311
  text = quoted(escaped(literal.value))
312
- text << "@#{literal.language}" if literal.has_language?
313
- text << "^^<#{uri_for(literal.datatype)}>" if literal.has_datatype?
312
+ text << "@#{literal.language}" if literal.language?
313
+ text << "^^<#{uri_for(literal.datatype)}>" if literal.datatype?
314
314
  text
315
315
  else
316
316
  quoted(escaped(literal.to_s))
@@ -85,13 +85,13 @@ module RDF; class Query
85
85
  #
86
86
  # @return [Boolean] `true` or `false`
87
87
  # @since 0.3.0
88
- def has_variables?
88
+ def variables?
89
89
  subject && subject.variable? ||
90
90
  predicate && predicate.variable? ||
91
91
  object && object.variable? ||
92
92
  graph_name && graph_name.variable?
93
93
  end
94
- alias_method :variables?, :has_variables?
94
+ alias_method :has_variables?, :variables?
95
95
 
96
96
  ##
97
97
  # Returns `true` if this is an optional pattern.
@@ -111,10 +111,10 @@ module RDF; class Query
111
111
  #
112
112
  # @return [Boolean] `true` or `false`
113
113
  def valid?
114
- (has_subject? ? (subject.resource? || subject.variable?) && subject.valid? : true) &&
115
- (has_predicate? ? (predicate.uri? || predicate.variable?) && predicate.valid? : true) &&
116
- (has_object? ? (object.term? || object.variable?) && object.valid? : true) &&
117
- (has_graph? ? (graph_name.resource? || graph_name.variable?) && graph_name.valid? : true)
114
+ (subject? ? (subject.resource? || subject.variable?) && subject.valid? : true) &&
115
+ (predicate? ? (predicate.uri? || predicate.variable?) && predicate.valid? : true) &&
116
+ (object? ? (object.term? || object.variable?) && object.valid? : true) &&
117
+ (graph? ? (graph_name.resource? || graph_name.variable?) && graph_name.valid? : true)
118
118
  rescue NoMethodError
119
119
  false
120
120
  end
@@ -248,7 +248,7 @@ module RDF; class Query
248
248
  # @param [RDF::Statement] statement
249
249
  # @return [Array<RDF::Term>]
250
250
  def var_values(var, statement)
251
- [:subject, :predicate, :object, :graph_name].map do |position|
251
+ %i(subject predicate object graph_name).map do |position|
252
252
  po = self.send(position)
253
253
  so = statement.send(position)
254
254
  po.var_values(var, so) if po.respond_to?(:var_values)
@@ -121,9 +121,11 @@ class RDF::Query
121
121
  # an array of variables to check
122
122
  # @return [Boolean] `true` or `false`
123
123
  # @since 0.3.0
124
- def has_variables?(variables)
124
+ def variable?(variables)
125
125
  variables.any? { |variable| bound?(variable) }
126
126
  end
127
+ alias_method :variables?, :variable?
128
+ alias_method :has_variables?, :variable?
127
129
 
128
130
  ##
129
131
  # Enumerates over every variable in this solution.
@@ -253,7 +255,7 @@ class RDF::Query
253
255
  # @see http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#defn_algCompatibleMapping
254
256
  def compatible?(other)
255
257
  @bindings.all? do |k, v|
256
- !other.to_h.has_key?(k) || other[k].eql?(v)
258
+ !other.to_h.key?(k) || other[k].eql?(v)
257
259
  end
258
260
  end
259
261
 
@@ -267,7 +269,7 @@ class RDF::Query
267
269
  # @see http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#defn_algMinus
268
270
  def disjoint?(other)
269
271
  @bindings.none? do |k, v|
270
- v && other.to_h.has_key?(k) && other[k].eql?(v)
272
+ v && other.to_h.key?(k) && other[k].eql?(v)
271
273
  end
272
274
  end
273
275
 
@@ -281,7 +283,7 @@ class RDF::Query
281
283
  # @return [Boolean]
282
284
  def isomorphic_with?(other)
283
285
  @bindings.all? do |k, v|
284
- !other.to_h.has_key?(k) || other[k].eql?(v)
286
+ !other.to_h.key?(k) || other[k].eql?(v)
285
287
  end
286
288
  end
287
289
 
@@ -332,7 +334,7 @@ class RDF::Query
332
334
  # @param [Symbol] name
333
335
  # @return [RDF::Term]
334
336
  def method_missing(name, *args, &block)
335
- if args.empty? && @bindings.has_key?(name.to_sym)
337
+ if args.empty? && @bindings.key?(name.to_sym)
336
338
  @bindings[name.to_sym]
337
339
  else
338
340
  super # raises NoMethodError
@@ -342,7 +344,7 @@ class RDF::Query
342
344
  ##
343
345
  # @return [Boolean]
344
346
  def respond_to_missing?(name, include_private = false)
345
- @bindings.has_key?(name.to_sym) || super
347
+ @bindings.key?(name.to_sym) || super
346
348
  end
347
349
 
348
350
  ##
@@ -84,11 +84,13 @@ module RDF; class Query
84
84
  # @param [Array<Symbol, #to_sym>] variables
85
85
  # an array of variables to check
86
86
  # @return [Boolean] `true` or `false`
87
- # @see RDF::Query::Solution#has_variables?
87
+ # @see RDF::Query::Solution#variable?
88
88
  # @see RDF::Query#execute
89
- def have_variables?(variables)
90
- self.any? { |solution| solution.has_variables?(variables) }
89
+ def variable?(variables)
90
+ self.any? { |solution| solution.variables?(variables) }
91
91
  end
92
+ alias_method :variables?, :variable?
93
+ alias_method :have_variables?, :variable?
92
94
  alias_method :has_variables?, :have_variables?
93
95
 
94
96
  ##
@@ -20,7 +20,7 @@ module RDF
20
20
  # repository.count
21
21
  #
22
22
  # @example Checking whether a repository contains a specific statement
23
- # repository.has_statement?(statement)
23
+ # repository.statement?(statement)
24
24
  #
25
25
  # @example Enumerating statements in a repository
26
26
  # repository.each_statement { |statement| statement.inspect! }
@@ -69,7 +69,7 @@ module RDF
69
69
  #
70
70
  # @example Transational read from a repository
71
71
  # repository.transaction do |tx|
72
- # tx.has_statement?(statement)
72
+ # tx.statement?(statement)
73
73
  # tx.query([:s, :p, :o])
74
74
  # end
75
75
  #
@@ -288,10 +288,11 @@ module RDF
288
288
 
289
289
  ##
290
290
  # @private
291
- # @see RDF::Enumerable#has_graph?
292
- def has_graph?(graph)
293
- @data.has_key?(graph)
291
+ # @see RDF::Enumerable#graph?
292
+ def graph?(graph)
293
+ @data.key?(graph)
294
294
  end
295
+ alias_method :has_graph?, :graph?
295
296
 
296
297
  ##
297
298
  # @private
@@ -312,12 +313,19 @@ module RDF
312
313
  enum_graph
313
314
  end
314
315
 
316
+
315
317
  ##
316
- # @private
317
- # @see RDF::Enumerable#has_statement?
318
- def has_statement?(statement)
319
- has_statement_in?(@data, statement)
318
+ # @overload statement?
319
+ # Returns `false` indicating this is not an RDF::Statemenet.
320
+ # @return [Boolean]
321
+ # @see RDF::Value#statement?
322
+ # @overload statement?(statement)
323
+ # @private
324
+ # @see RDF::Enumerable#statement?
325
+ def statement?(statement = nil)
326
+ statement && statement_in?(@data, statement)
320
327
  end
328
+ alias_method :has_statement?, :statement?
321
329
 
322
330
  ##
323
331
  # @private
@@ -389,7 +397,7 @@ module RDF
389
397
  predicate = pattern.predicate
390
398
  object = pattern.object
391
399
 
392
- cs = snapshot.has_key?(graph_name) ? { graph_name => snapshot[graph_name] } : snapshot
400
+ cs = snapshot.key?(graph_name) ? { graph_name => snapshot[graph_name] } : snapshot
393
401
 
394
402
  cs.each do |c, ss|
395
403
  next unless graph_name.nil? ||
@@ -403,7 +411,7 @@ module RDF
403
411
  ss.keys.select {|s| s.statement? && subject.eql?(s)}.inject({}) do |memo, st|
404
412
  memo.merge(st => ss[st])
405
413
  end
406
- elsif ss.has_key?(subject)
414
+ elsif ss.key?(subject)
407
415
  { subject => ss[subject] }
408
416
  else
409
417
  []
@@ -411,7 +419,7 @@ module RDF
411
419
  ss.each do |s, ps|
412
420
  ps = if predicate.nil? || predicate.is_a?(RDF::Query::Variable)
413
421
  ps
414
- elsif ps.has_key?(predicate)
422
+ elsif ps.key?(predicate)
415
423
  { predicate => ps[predicate] }
416
424
  else
417
425
  []
@@ -468,16 +476,17 @@ module RDF
468
476
 
469
477
  ##
470
478
  # @private
471
- # @see #has_statement
472
- def has_statement_in?(data, statement)
479
+ # @see #statement?
480
+ def statement_in?(data, statement)
473
481
  s, p, o, g = statement.to_quad
474
482
  g ||= DEFAULT_GRAPH
475
483
 
476
- data.has_key?(g) &&
477
- data[g].has_key?(s) &&
478
- data[g][s].has_key?(p) &&
479
- data[g][s][p].has_key?(o)
484
+ data.key?(g) &&
485
+ data[g].key?(s) &&
486
+ data[g][s].key?(p) &&
487
+ data[g][s][p].key?(o)
480
488
  end
489
+ alias_method :has_statement_in?, :statement_in?
481
490
 
482
491
  ##
483
492
  # @private
@@ -485,7 +494,7 @@ module RDF
485
494
  def insert_to(data, statement)
486
495
  raise ArgumentError, "Statement #{statement.inspect} is incomplete" if statement.incomplete?
487
496
 
488
- unless has_statement_in?(data, statement)
497
+ unless statement_in?(data, statement)
489
498
  s, p, o, c = statement.to_quad
490
499
  c ||= DEFAULT_GRAPH
491
500
 
@@ -504,7 +513,7 @@ module RDF
504
513
  # @private
505
514
  # @return [Hamster::Hash] a new, updated hamster hash
506
515
  def delete_from(data, statement)
507
- if has_statement_in?(data, statement)
516
+ if statement_in?(data, statement)
508
517
  s, p, o, g = statement.to_quad
509
518
  g = DEFAULT_GRAPH unless supports?(:graph_name)
510
519
  g ||= DEFAULT_GRAPH
@@ -207,10 +207,16 @@ module RDF
207
207
  end
208
208
 
209
209
  ##
210
- # @see RDF::Enumerable#has_statement?
211
- def has_statement?(statement)
212
- read_target.has_statement?(statement)
210
+ # @overload statement?
211
+ # Returns `false` indicating this is not an RDF::Statemenet.
212
+ # @return [Boolean]
213
+ # @see RDF::Value#statement?
214
+ # @overload statement?(statement)
215
+ # @see RDF::Enumerable#statement?
216
+ def statement?(statement = nil)
217
+ statement && read_target.has_statement?(statement)
213
218
  end
219
+ alias_method :has_statement?, :statement?
214
220
 
215
221
  ##
216
222
  # Returns a developer-friendly representation of this transaction.
@@ -53,9 +53,10 @@ module RDF; module Util
53
53
 
54
54
  ##
55
55
  # @return [Boolean]
56
- def has_capacity?
56
+ def capacity?
57
57
  @capacity.equal?(-1) || @capacity > @cache.size
58
58
  end
59
+ alias_method :has_capacity?, :capacity?
59
60
 
60
61
  ##
61
62
  # This implementation relies on `ObjectSpace#_id2ref` and performs
@@ -80,7 +81,7 @@ module RDF; module Util
80
81
  # @param [Object] value
81
82
  # @return [Object]
82
83
  def []=(key, value)
83
- if has_capacity?
84
+ if capacity?
84
85
  id = value.__id__
85
86
  @cache[key] = id
86
87
  @index[id] = key
@@ -133,7 +134,7 @@ module RDF; module Util
133
134
  # @param [Object] value
134
135
  # @return [Object]
135
136
  def []=(key, value)
136
- if has_capacity?
137
+ if capacity?
137
138
  @cache[key] = WeakRef.new(value)
138
139
  end
139
140
  value
@@ -285,7 +285,7 @@ module RDF; module Util
285
285
 
286
286
  def respond_to_missing?(name, include_private = false)
287
287
  return true if
288
- [:fatal, :error, :warn, :info, :debug, :level, :sev_threshold]
288
+ %i(fatal error warn info debug level sev_threshold)
289
289
  .include?(name.to_sym)
290
290
  super
291
291
  end
@@ -430,7 +430,7 @@ module RDF
430
430
  # @param [#to_s] property
431
431
  # @return [RDF::URI]
432
432
  def [](property)
433
- if props.has_key?(property.to_sym)
433
+ if props.key?(property.to_sym)
434
434
  props[property.to_sym]
435
435
  else
436
436
  Term.intern([to_s, property.to_s].join(''), vocab: self, attributes: {})
@@ -508,7 +508,7 @@ module RDF
508
508
  #
509
509
  # @return [String]
510
510
  def to_s
511
- @@uris.has_key?(self) ? @@uris[self].to_s : super
511
+ @@uris.key?(self) ? @@uris[self].to_s : super
512
512
  end
513
513
 
514
514
  ##
@@ -1153,7 +1153,7 @@ module RDF
1153
1153
  :onProperty, :someValuesFrom
1154
1154
  self.restriction?
1155
1155
  when :broader, :exactMatch, :hasTopConcept, :inScheme, :member, :narrower, :related
1156
- @attributes.has_key?(method)
1156
+ @attributes.key?(method)
1157
1157
  else
1158
1158
  super
1159
1159
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.9
4
+ version: 3.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-01-03 00:00:00.000000000 Z
13
+ date: 2021-02-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: link_header
@@ -303,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
303
  - !ruby/object:Gem::Version
304
304
  version: '0'
305
305
  requirements: []
306
- rubygems_version: 3.1.4
306
+ rubygems_version: 3.2.3
307
307
  signing_key:
308
308
  specification_version: 4
309
309
  summary: A Ruby library for working with Resource Description Framework (RDF) data.