rdf 3.1.10 → 3.1.15

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: 5de713395026fd70491ac47ef4c5c89e63681bccf27d8b9e39fe21fcf63c1344
4
- data.tar.gz: a2bc97b12d11858f4089fba2915f358ba28db0bb4704ce70e668f17c80e9a739
3
+ metadata.gz: 8747674533ca06af62b3ee536ea4342be3c8bedc8831b1a1838e244d927263cb
4
+ data.tar.gz: fbc0593916678f9f696d4c461b29df01549da5af7d436b700d66735f5350054d
5
5
  SHA512:
6
- metadata.gz: 334cf936abb27e4c0a8fe225c4bd309b455ab96fcf1e79369abe3a763b28e922172b5d477a9a2112677f3ae21d8b3a0fdb9696d6d89bb6ce85bf49831464f611
7
- data.tar.gz: 76d46e91f93f70e021f482b089fb4a5afebb955e835d89965e270688a46fb938a5b1e334d2c0e5d9992a149de97bb84c5f14e8f4da62019aaa7bec7fcb7f582e
6
+ metadata.gz: fb56f5b72af92421afb2216ca5d1dec10907860a2f1ad069e4d69e37ee3126219dfb0c60fab256c1088424b9a8dcc42f6637e98b1c52258cc88163b394e06fc5
7
+ data.tar.gz: dcd897b9313decf48df3a89d4e8885ac74da1b966d194c28faa56a2edff2f4b123d093322655985ae1c0c059c6e8e49be9f18bbc9b1ef9c87634394d9090064b
data/README.md CHANGED
@@ -10,6 +10,26 @@ This is a pure-Ruby library for working with [Resource Description Framework
10
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
+ ## Table of contents
14
+
15
+ 1. [Features](#features)
16
+ 2. [Differences between RDF 1.0 and RDF 1.1](#differences-between-rdf-1-0-and-rdf-1-1)
17
+ 3. [Tutorials](#tutorials)
18
+ 4. [Command Line](#command-line)
19
+ 5. [Examples](#examples)
20
+ 6. [Reader/Writer convenience methods](#reader/writer-convenience-methods)
21
+ 7. [RDF* (RDFStar)](#rdf*-(rdfstar))
22
+ 8. [Documentation](#documentation)
23
+ 9. [Dependencies](#dependencies)
24
+ 10. [Installation](#installation)
25
+ 11. [Download](#download)
26
+ 12. [Resources](#resources)
27
+ 13. [Mailing List](#mailing-list)
28
+ 14. [Authors](#authors)
29
+ 15. [Contributors](#contributors)
30
+ 16. [Contributing](#contributing)
31
+ 17. [License](#license)
32
+
13
33
  ## Features
14
34
 
15
35
  * 100% pure Ruby with minimal dependencies and no bloat.
@@ -41,7 +61,7 @@ middleware.
41
61
 
42
62
  See {RDF::Util::File} for configuring other mechanisms for retrieving resources.
43
63
 
44
- ### Term caching and configuration.
64
+ ### Term caching and configuration
45
65
 
46
66
  RDF.rb uses a weak-reference cache for storing internalized versions of URIs and Nodes. This is particularly useful for Nodes as two nodes are equivalent only if they're the same node.
47
67
 
@@ -76,7 +96,7 @@ the 1.1 release of RDF.rb:
76
96
  * {RDF::Util::File.open\_file} now performs redirects and manages `base_uri` based on W3C recommendations:
77
97
  * `base_uri` is set to the original URI if a status 303 is provided, otherwise any other redirect will set `base_uri` to the redirected location.
78
98
  * `base_uri` is set to the content of the `Location` header if status is _success_.
79
- * Additionally, {RDF::Util::File.open\_file} sets the result encoding from `charset` if provided, defaulting to `UTF-8`. Other access methods include `last_modified` and `content_type`,
99
+ * Additionally, {RDF::Util::File.open\_file} sets the result encoding from `charset` if provided, defaulting to `UTF-8`. Other access methods include `last_modified` and `content_type`,
80
100
  * {RDF::StrictVocabulary} added with an easy way to keep vocabulary definitions up to date based on their OWL or RDFS definitions. Most vocabularies are now StrictVocabularies meaning that an attempt to resolve a particular term in that vocabulary will error if the term is not defined in the vocabulary.
81
101
  * New vocabulary definitions have been added for [ICal](http://www.w3.org/2002/12/cal/icaltzd#), [Media Annotations (MA)](http://www.w3.org/ns/ma-ont#), [Facebook OpenGraph (OG)](http://ogp.me/ns#), [PROV](http://www.w3.org/ns/prov#), [SKOS-XL (SKOSXL)](http://www.w3.org/2008/05/skos-xl#), [Data Vocabulary (V)](http://rdf.data-vocabulary.org/), [VCard](http://www.w3.org/2006/vcard/ns#), [VOID](http://rdfs.org/ns/void#http://rdfs.org/ns/void#), [Powder-S (WDRS)](http://www.w3.org/2007/05/powder-s#), and [XHV](http://www.w3.org/1999/xhtml/vocab#).
82
102
 
@@ -89,6 +109,7 @@ Notably, {RDF::Queryable#query} and {RDF::Query#execute} are now completely symm
89
109
  * [Getting started with RDF and SPARQL using 4store and RDF.rb](https://www.jenitennison.com/blog/node/152)
90
110
 
91
111
  ## Command Line
112
+
92
113
  When installed, RDF.rb includes a `rdf` shell script which acts as a wrapper to perform a number of different
93
114
  operations on RDF files using available readers and writers.
94
115
 
@@ -112,7 +133,7 @@ Different RDF gems will augment the `rdf` script with more capabilities, which m
112
133
  require 'rdf/ntriples'
113
134
  graph = RDF::Graph.new << [:hello, RDF::RDFS.label, "Hello, world!"]
114
135
  graph.dump(:ntriples)
115
-
136
+
116
137
  or
117
138
 
118
139
  RDF::Writer.open("hello.nt") { |writer| writer << graph }
@@ -121,7 +142,7 @@ or
121
142
 
122
143
  require 'rdf/ntriples'
123
144
  graph = RDF::Graph.load("https://ruby-rdf.github.com/rdf/etc/doap.nt")
124
-
145
+
125
146
  or
126
147
 
127
148
  RDF::Reader.open("https://ruby-rdf.github.com/rdf/etc/doap.nt") do |reader|
@@ -131,19 +152,20 @@ or
131
152
  end
132
153
 
133
154
  ### Reading RDF data in other formats
155
+
134
156
  {RDF::Reader.open} and {RDF::Repository.load} use a number of mechanisms to determine the appropriate reader
135
157
  to use when loading a file. The specific format to use can be forced using, e.g. `format: :ntriples`
136
158
  option where the specific format symbol is determined by the available readers. Both also use
137
159
  MimeType or file extension, where available.
138
160
 
139
161
  require 'rdf/nquads'
140
-
162
+
141
163
  graph = RDF::Graph.load("https://ruby-rdf.github.com/rdf/etc/doap.nq", format: :nquads)
142
164
 
143
165
  A specific sub-type of Reader can also be invoked directly:
144
166
 
145
167
  require 'rdf/nquads'
146
-
168
+
147
169
  RDF::NQuads::Reader.open("https://ruby-rdf.github.com/rdf/etc/doap.nq") do |reader|
148
170
  reader.each_statement do |statement|
149
171
  puts statement.inspect
@@ -157,6 +179,7 @@ be detected from filename or other options, or that more than one format is iden
157
179
  match will be used to read the input.
158
180
 
159
181
  ### Writing RDF data using other formats
182
+
160
183
  {RDF::Writer.open}, {RDF::Enumerable#dump}, {RDF::Writer.dump} take similar options to {RDF::Reader.open} to determine the
161
184
  appropriate writer to use.
162
185
 
@@ -176,6 +199,7 @@ A specific sub-type of Writer can also be invoked directly:
176
199
  File.open("hello.nq", "w") {|f| f << repo.dump(:nquads)}
177
200
 
178
201
  ## Reader/Writer convenience methods
202
+
179
203
  {RDF::Enumerable} implements `to_{format}` for each available instance of {RDF::Reader}.
180
204
  For example, if `rdf/turtle` is loaded, this allows the following:
181
205
 
@@ -195,7 +219,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
195
219
  ### Querying RDF data using basic graph patterns (BGPs)
196
220
 
197
221
  require 'rdf/ntriples'
198
-
222
+
199
223
  graph = RDF::Graph.load("https://ruby-rdf.github.com/rdf/etc/doap.nt")
200
224
  query = RDF::Query.new({
201
225
  person: {
@@ -204,7 +228,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
204
228
  FOAF.mbox => :email,
205
229
  }
206
230
  }, **{})
207
-
231
+
208
232
  query.execute(graph) do |solution|
209
233
  puts "name=#{solution.name} email=#{solution.email}"
210
234
  end
@@ -451,7 +475,6 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
451
475
  which you will be asked to agree to on the first commit to a repo within the organization.
452
476
  Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
453
477
 
454
-
455
478
  ## License
456
479
 
457
480
  This is free and unencumbered public domain software. For more information,
@@ -492,4 +515,4 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
492
515
  [JSON::LD]: https://ruby-rdf.github.com/json-ld
493
516
  [RestClient]: https://rubygems.org/gems/rest-client
494
517
  [RestClient Components]: https://rubygems.org/gems/rest-client-components
495
- [Rack::Cache]: https://rtomayko.github.io/rack-cache/
518
+ [Rack::Cache]: https://rtomayko.github.io/rack-cache/
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.10
1
+ 3.1.15
data/lib/rdf/cli.rb CHANGED
@@ -256,8 +256,7 @@ module RDF
256
256
  lambda: ->(argv, opts) do
257
257
  writer_class = RDF::Writer.for(opts[:output_format]) || RDF::NTriples::Writer
258
258
  out = opts[:output]
259
- opts = opts.merge(prefixes: {})
260
- writer_opts = opts.merge(standard_prefixes: true)
259
+ writer_opts = {prefixes: {}, standard_prefixes: true}.merge(opts)
261
260
  writer_class.new(out, **writer_opts) do |writer|
262
261
  writer << repository
263
262
  end
@@ -536,6 +535,8 @@ module RDF
536
535
  count = 0
537
536
  self.parse(args, **options) do |reader|
538
537
  reader.each_statement {|st| @repository << st}
538
+ # Remember prefixes from reading
539
+ options[:prefixes] ||= reader.prefixes
539
540
  end
540
541
  secs = Time.new - start
541
542
  options[:logger].info "Parsed #{repository.count} statements with #{@readers.join(', ')} in #{secs} seconds @ #{count/secs} statements/second."
@@ -136,8 +136,13 @@ module RDF
136
136
  #
137
137
  # @param [RDF::Statement] statement
138
138
  # @return [Boolean]
139
- def statement?(statement = nil)
140
- statement && !enum_statement.find { |s| s.eql?(statement) }.nil?
139
+ def statement?(*args)
140
+ case args.length
141
+ when 0 then false
142
+ when 1
143
+ args.first && !enum_statement.find { |s| s.eql?(args.first) }.nil?
144
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
145
+ end
141
146
  end
142
147
  alias_method :has_statement?, :statement?
143
148
  alias_method :include?, :statement?
@@ -541,8 +546,12 @@ module RDF
541
546
  # @param [RDF::Resource] value
542
547
  # @return [Boolean]
543
548
  # @since 2.0
544
- def term?(value = nil)
545
- value && enum_term.include?(value)
549
+ def term?(*args)
550
+ case args.length
551
+ when 0 then super
552
+ when 1 then args.first && enum_term.include?(args.first)
553
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
554
+ end
546
555
  end
547
556
  alias_method :has_term?, :term?
548
557
 
@@ -138,11 +138,22 @@ module RDF
138
138
  end
139
139
 
140
140
  ##
141
- # Returns `true` to indicate that this is a graph.
141
+ # @overload graph?
142
+ # Returns `true` to indicate that this is a graph.
142
143
  #
143
- # @return [Boolean]
144
- def graph?
145
- true
144
+ # @return [Boolean]
145
+ # @overload graph?(name)
146
+ # Returns `true` if `self` contains the given RDF graph_name.
147
+ #
148
+ # @param [RDF::Resource, false] graph_name
149
+ # Use value `false` to query for the default graph_name
150
+ # @return [Boolean]
151
+ def graph?(*args)
152
+ case args.length
153
+ when 0 then true
154
+ when 1 then graph_name == args.first
155
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
156
+ end
146
157
  end
147
158
 
148
159
  ##
@@ -227,11 +238,15 @@ module RDF
227
238
  # @param [Statement] statement
228
239
  # @return [Boolean]
229
240
  # @see RDF::Enumerable#statement?
230
- def statement?(statement = nil)
231
- return false if statement.nil?
232
- statement = statement.dup
233
- statement.graph_name = graph_name
234
- @data.statement?(statement)
241
+ def statement?(*args)
242
+ case args.length
243
+ when 0 then false
244
+ when 1
245
+ statement = args.first.dup
246
+ statement.graph_name = graph_name
247
+ @data.statement?(statement)
248
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
249
+ end
235
250
  end
236
251
  alias_method :has_statement?, :statement?
237
252
 
@@ -308,6 +308,37 @@ module RDF
308
308
  end
309
309
  alias_method :===, :==
310
310
 
311
+ ##
312
+ # Compares `self` to `other` for sorting purposes (with type check).
313
+ #
314
+ # @param [Object] other
315
+ # @return [Integer] `-1`, `0`, or `1`
316
+ def <=>(other)
317
+ case other
318
+ when Literal
319
+ case
320
+ when self.eql?(other)
321
+ 0
322
+ when self.language? && other.language?
323
+ # Literals with languages can compare if languages are identical
324
+ self.to_s <=> other.to_s
325
+ when self.simple? && other.simple?
326
+ self.to_s <=> other.to_s
327
+ when !self.valid?
328
+ type_error("#{self.inspect} is invalid") || 0
329
+ when !other.valid?
330
+ type_error("#{other.inspect} is invalid") || 0
331
+ when self.comperable_datatype2?(other)
332
+ self.object <=> other.object
333
+ else
334
+ type_error("#{self.inspect} and #{other.inspect} are not comperable") || 0
335
+ end
336
+ when String
337
+ self.simple? && self.value <=> other
338
+ else 1
339
+ end
340
+ end
341
+
311
342
  ##
312
343
  # Returns `true` if this is a plain literal. A plain literal
313
344
  # may have a language, but may not have a datatype. For
@@ -399,6 +430,32 @@ module RDF
399
430
  end
400
431
  end
401
432
 
433
+ ##
434
+ # Returns `true` if the literal has a datatype and the comparison should
435
+ # return false instead of raise a type error.
436
+ #
437
+ # Used for <=> operator.
438
+ #
439
+ # This behavior is intuited from SPARQL data-r2/expr-equal/eq-2-2
440
+ # @return [Boolean]
441
+ def comperable_datatype2?(other)
442
+ case self
443
+ when RDF::Literal::Numeric, RDF::Literal::Boolean
444
+ case other
445
+ when RDF::Literal::Numeric, RDF::Literal::Boolean
446
+ true
447
+ else
448
+ self.plain? || other.plain? ||
449
+ self.language? || other.language? ||
450
+ self.datatype == other.datatype
451
+ end
452
+ else
453
+ self.plain? || other.plain? ||
454
+ self.language? || other.language? ||
455
+ self.datatype == other.datatype
456
+ end
457
+ end
458
+
402
459
  ##
403
460
  # Converts this literal into its canonical lexical representation.
404
461
  #
@@ -11,6 +11,9 @@ module RDF; class Literal
11
11
  # @return [Integer] `-1`, `0`, or `1`
12
12
  # @since 0.3.0
13
13
  def <=>(other)
14
+ # If lexically invalid, use regular literal testing
15
+ return super unless self.valid? && (!other.respond_to?(:valid?) || other.valid?)
16
+
14
17
  case other
15
18
  when ::Numeric
16
19
  to_d <=> other
@@ -30,11 +33,10 @@ module RDF; class Literal
30
33
  # @since 0.3.0
31
34
  def ==(other)
32
35
  # If lexically invalid, use regular literal testing
33
- return super unless self.valid?
36
+ return super unless self.valid? && (!other.respond_to?(:valid?) || other.valid?)
34
37
 
35
38
  case other
36
39
  when Literal::Numeric
37
- return super unless other.valid?
38
40
  (cmp = (self <=> other)) ? cmp.zero? : false
39
41
  when RDF::URI, RDF::Node
40
42
  # Interpreting SPARQL data-r2/expr-equal/eq-2-2, numeric can't be compared with other types
@@ -136,23 +136,45 @@ module RDF
136
136
  end
137
137
 
138
138
  ##
139
- # Returns `true` to indicate that this value is a statement.
139
+ # @overload statement?
140
+ # Returns `true` if `self` is a {RDF::Statement}.
140
141
  #
141
- # @return [Boolean]
142
- def statement?
143
- true
142
+ # @return [Boolean]
143
+ # @overload statement?(statement)
144
+ # Returns `true` if `self` contains the given {RDF::Statement}.
145
+ #
146
+ # @param [RDF::Statement] statement
147
+ # @return [Boolean]
148
+ def statement?(*args)
149
+ case args.length
150
+ when 0 then true
151
+ when 1 then self == args.first || subject.statement?(*args) || object.statement?(*args)
152
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
153
+ end
144
154
  end
145
155
 
146
156
  ##
147
- # Returns `true` if any element of the statement is not a
157
+ # @overload variable?
158
+ # Returns `true` if any element of the statement is not a
148
159
  # URI, Node or Literal.
149
160
  #
150
- # @return [Boolean]
151
- def variable?
152
- !(subject? && subject.constant? &&
153
- predicate? && predicate.constant? &&
154
- object? && object.constant? &&
155
- (graph? ? graph_name.constant? : true))
161
+ # @return [Boolean]
162
+ # @overload variable?(variables)
163
+ # Returns `true` if this statement contains any of the variables.
164
+ #
165
+ # @param [Array<Symbol, #to_sym>] variables
166
+ # @return [Boolean]
167
+ def variable?(*args)
168
+ case args.length
169
+ when 0
170
+ !(subject? && subject.constant? &&
171
+ predicate? && predicate.constant? &&
172
+ object? && object.constant? &&
173
+ (graph? ? graph_name.constant? : true))
174
+ when 1
175
+ to_quad.any? {|t| t.respond_to?(:variable?) && t.variable?(*args)}
176
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
177
+ end
156
178
  end
157
179
 
158
180
  ##
@@ -215,9 +237,22 @@ module RDF
215
237
  end
216
238
 
217
239
  ##
218
- # @return [Boolean]
219
- def graph?
220
- !!graph_name
240
+ # @overload graph?
241
+ # Returns `true` if the statement has a graph name.
242
+ #
243
+ # @return [Boolean]
244
+ # @overload graph?(name)
245
+ # Returns `true` if `self` contains the given RDF graph_name.
246
+ #
247
+ # @param [RDF::Resource, false] graph_name
248
+ # Use value `false` to query for the default graph_name
249
+ # @return [Boolean]
250
+ def graph?(*args)
251
+ case args.length
252
+ when 0 then !!graph_name
253
+ when 1 then graph_name == args.first
254
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
255
+ end
221
256
  end
222
257
  alias_method :name?, :graph?
223
258
  alias_method :has_graph?, :graph?
@@ -266,7 +301,7 @@ module RDF
266
301
  # @see RDF::Literal#==
267
302
  # @see RDF::Query::Variable#==
268
303
  def eql?(other)
269
- other.is_a?(Statement) && self == other && (self.graph_name || false) == (other.graph_name || false)
304
+ other.is_a?(Statement) && self.to_a.eql?(other.to_a) && (self.graph_name || false) == (other.graph_name || false)
270
305
  end
271
306
 
272
307
  ##
@@ -57,11 +57,21 @@ module RDF
57
57
  end
58
58
 
59
59
  ##
60
- # Returns `true` if `self` is a {RDF::Term}.
60
+ # @overload term?
61
+ # Returns `true` if `self` is a {RDF::Term}.
61
62
  #
62
- # @return [Boolean]
63
- def term?
64
- true
63
+ # @return [Boolean]
64
+ # @overload term?(name)
65
+ # Returns `true` if `self` contains the given RDF subject term.
66
+ #
67
+ # @param [RDF::Resource] value
68
+ # @return [Boolean]
69
+ def term?(*args)
70
+ case args.length
71
+ when 0 then true
72
+ when 1 then false
73
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
74
+ end
65
75
  end
66
76
 
67
77
  ##