rdf 3.1.7 → 3.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -22
- data/VERSION +1 -1
- data/lib/rdf.rb +24 -0
- data/lib/rdf/cli.rb +38 -10
- data/lib/rdf/mixin/enumerable.rb +55 -28
- data/lib/rdf/mixin/mutable.rb +1 -1
- data/lib/rdf/model/dataset.rb +1 -1
- data/lib/rdf/model/graph.rb +35 -13
- data/lib/rdf/model/list.rb +29 -4
- data/lib/rdf/model/literal.rb +14 -14
- data/lib/rdf/model/literal/date.rb +5 -3
- data/lib/rdf/model/literal/datetime.rb +11 -7
- data/lib/rdf/model/literal/time.rb +7 -5
- data/lib/rdf/model/node.rb +2 -6
- data/lib/rdf/model/statement.rb +80 -32
- data/lib/rdf/model/term.rb +22 -4
- data/lib/rdf/model/uri.rb +14 -16
- data/lib/rdf/model/value.rb +53 -16
- data/lib/rdf/nquads.rb +2 -2
- data/lib/rdf/ntriples/reader.rb +6 -6
- data/lib/rdf/ntriples/writer.rb +3 -3
- data/lib/rdf/query.rb +16 -5
- data/lib/rdf/query/pattern.rb +7 -7
- data/lib/rdf/query/solution.rb +22 -11
- data/lib/rdf/query/solutions.rb +18 -7
- data/lib/rdf/query/variable.rb +19 -5
- data/lib/rdf/reader.rb +6 -19
- data/lib/rdf/repository.rb +46 -21
- data/lib/rdf/transaction.rb +13 -3
- data/lib/rdf/util/cache.rb +10 -6
- data/lib/rdf/util/logger.rb +1 -1
- data/lib/rdf/vocab/owl.rb +366 -388
- data/lib/rdf/vocab/rdfs.rb +72 -74
- data/lib/rdf/vocab/rdfv.rb +74 -74
- data/lib/rdf/vocab/writer.rb +41 -25
- data/lib/rdf/vocab/xsd.rb +198 -463
- data/lib/rdf/vocabulary.rb +136 -88
- data/lib/rdf/writer.rb +2 -2
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff64fa365f10553262446da5494bf2bb592dffe9c409cda37239e0726a5e1f4d
|
4
|
+
data.tar.gz: 6915405e0bc437cf0be2a88697145757131ea1d054040b9e7823c26c998a8568
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b73a1e41bdb9c53d7dcff97c2b14f785b1f02be8233dcf8ffdd36f9fbc426dcdff5e0af4cb0a31e11fd5edcc76442a2fe6f9d0c1483855a91e340b407ee4753
|
7
|
+
data.tar.gz: d93d42dcd04f9ff35676a43d1a71b3e84c5fe1a94118a3b0dd7e94aa708e23e5bb0310fb136fa98956b192f7098eb48fe25a91d22c0287e66041a7f73a704b15
|
data/README.md
CHANGED
@@ -6,9 +6,29 @@ This is a pure-Ruby library for working with [Resource Description Framework
|
|
6
6
|
* <https://ruby-rdf.github.com/rdf>
|
7
7
|
|
8
8
|
[![Gem Version](https://badge.fury.io/rb/rdf.png)](https://badge.fury.io/rb/rdf)
|
9
|
-
[![Build Status](https://
|
10
|
-
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/
|
11
|
-
[![
|
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?branch=develop)](https://coveralls.io/github/ruby-rdf/rdf?branch=develop)
|
11
|
+
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
|
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)
|
12
32
|
|
13
33
|
## Features
|
14
34
|
|
@@ -39,6 +59,22 @@ resources. Clients may also consider using [RestClient Components][] to enable
|
|
39
59
|
client-side caching of HTTP results using [Rack::Cache][] or other Rack
|
40
60
|
middleware.
|
41
61
|
|
62
|
+
See {RDF::Util::File} for configuring other mechanisms for retrieving resources.
|
63
|
+
|
64
|
+
### Term caching and configuration
|
65
|
+
|
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.
|
67
|
+
|
68
|
+
By default, each cache can grow to an unlimited size, but this can be configured using {RDF.config}, for general limits, along with URI- or Node-specific limits.
|
69
|
+
|
70
|
+
For example, to limit the size of the URI intern cache only:
|
71
|
+
|
72
|
+
RDF.config.uri_cache_size = 10_000
|
73
|
+
|
74
|
+
The default for creating new caches without a specific initialization size can be set using:
|
75
|
+
|
76
|
+
RDF.config.cache_size = 100_000
|
77
|
+
|
42
78
|
## Differences between RDF 1.0 and RDF 1.1
|
43
79
|
|
44
80
|
This version of RDF.rb is fully compatible with [RDF 1.1][], but it creates some
|
@@ -60,7 +96,7 @@ the 1.1 release of RDF.rb:
|
|
60
96
|
* {RDF::Util::File.open\_file} now performs redirects and manages `base_uri` based on W3C recommendations:
|
61
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.
|
62
98
|
* `base_uri` is set to the content of the `Location` header if status is _success_.
|
63
|
-
* 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`,
|
64
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.
|
65
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#).
|
66
102
|
|
@@ -73,6 +109,7 @@ Notably, {RDF::Queryable#query} and {RDF::Query#execute} are now completely symm
|
|
73
109
|
* [Getting started with RDF and SPARQL using 4store and RDF.rb](https://www.jenitennison.com/blog/node/152)
|
74
110
|
|
75
111
|
## Command Line
|
112
|
+
|
76
113
|
When installed, RDF.rb includes a `rdf` shell script which acts as a wrapper to perform a number of different
|
77
114
|
operations on RDF files using available readers and writers.
|
78
115
|
|
@@ -96,7 +133,7 @@ Different RDF gems will augment the `rdf` script with more capabilities, which m
|
|
96
133
|
require 'rdf/ntriples'
|
97
134
|
graph = RDF::Graph.new << [:hello, RDF::RDFS.label, "Hello, world!"]
|
98
135
|
graph.dump(:ntriples)
|
99
|
-
|
136
|
+
|
100
137
|
or
|
101
138
|
|
102
139
|
RDF::Writer.open("hello.nt") { |writer| writer << graph }
|
@@ -105,7 +142,7 @@ or
|
|
105
142
|
|
106
143
|
require 'rdf/ntriples'
|
107
144
|
graph = RDF::Graph.load("https://ruby-rdf.github.com/rdf/etc/doap.nt")
|
108
|
-
|
145
|
+
|
109
146
|
or
|
110
147
|
|
111
148
|
RDF::Reader.open("https://ruby-rdf.github.com/rdf/etc/doap.nt") do |reader|
|
@@ -115,19 +152,20 @@ or
|
|
115
152
|
end
|
116
153
|
|
117
154
|
### Reading RDF data in other formats
|
155
|
+
|
118
156
|
{RDF::Reader.open} and {RDF::Repository.load} use a number of mechanisms to determine the appropriate reader
|
119
157
|
to use when loading a file. The specific format to use can be forced using, e.g. `format: :ntriples`
|
120
158
|
option where the specific format symbol is determined by the available readers. Both also use
|
121
159
|
MimeType or file extension, where available.
|
122
160
|
|
123
161
|
require 'rdf/nquads'
|
124
|
-
|
162
|
+
|
125
163
|
graph = RDF::Graph.load("https://ruby-rdf.github.com/rdf/etc/doap.nq", format: :nquads)
|
126
164
|
|
127
165
|
A specific sub-type of Reader can also be invoked directly:
|
128
166
|
|
129
167
|
require 'rdf/nquads'
|
130
|
-
|
168
|
+
|
131
169
|
RDF::NQuads::Reader.open("https://ruby-rdf.github.com/rdf/etc/doap.nq") do |reader|
|
132
170
|
reader.each_statement do |statement|
|
133
171
|
puts statement.inspect
|
@@ -141,6 +179,7 @@ be detected from filename or other options, or that more than one format is iden
|
|
141
179
|
match will be used to read the input.
|
142
180
|
|
143
181
|
### Writing RDF data using other formats
|
182
|
+
|
144
183
|
{RDF::Writer.open}, {RDF::Enumerable#dump}, {RDF::Writer.dump} take similar options to {RDF::Reader.open} to determine the
|
145
184
|
appropriate writer to use.
|
146
185
|
|
@@ -160,6 +199,7 @@ A specific sub-type of Writer can also be invoked directly:
|
|
160
199
|
File.open("hello.nq", "w") {|f| f << repo.dump(:nquads)}
|
161
200
|
|
162
201
|
## Reader/Writer convenience methods
|
202
|
+
|
163
203
|
{RDF::Enumerable} implements `to_{format}` for each available instance of {RDF::Reader}.
|
164
204
|
For example, if `rdf/turtle` is loaded, this allows the following:
|
165
205
|
|
@@ -179,7 +219,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
|
|
179
219
|
### Querying RDF data using basic graph patterns (BGPs)
|
180
220
|
|
181
221
|
require 'rdf/ntriples'
|
182
|
-
|
222
|
+
|
183
223
|
graph = RDF::Graph.load("https://ruby-rdf.github.com/rdf/etc/doap.nt")
|
184
224
|
query = RDF::Query.new({
|
185
225
|
person: {
|
@@ -188,7 +228,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
|
|
188
228
|
FOAF.mbox => :email,
|
189
229
|
}
|
190
230
|
}, **{})
|
191
|
-
|
231
|
+
|
192
232
|
query.execute(graph) do |solution|
|
193
233
|
puts "name=#{solution.name} email=#{solution.email}"
|
194
234
|
end
|
@@ -246,17 +286,10 @@ By default, the N-Triples reader will reject a document containing a subject res
|
|
246
286
|
end
|
247
287
|
# => RDF::ReaderError
|
248
288
|
|
249
|
-
Readers support a `rdfstar` option
|
289
|
+
Readers support a boolean valued `rdfstar` option.
|
250
290
|
|
251
291
|
graph = RDF::Graph.new do |graph|
|
252
|
-
RDF::NTriples::Reader.new(nt, rdfstar:
|
253
|
-
end
|
254
|
-
graph.count #=> 2
|
255
|
-
|
256
|
-
When using the `:SA` mode, only one statement is asserted, although the reified statement is contained within the graph.
|
257
|
-
|
258
|
-
graph = RDF::Graph.new do |graph|
|
259
|
-
RDF::NTriples::Reader.new(nt, rdfstar: :SA) {|reader| graph << reader}
|
292
|
+
RDF::NTriples::Reader.new(nt, rdfstar: true) {|reader| graph << reader}
|
260
293
|
end
|
261
294
|
graph.count #=> 1
|
262
295
|
|
@@ -442,7 +475,6 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
|
|
442
475
|
which you will be asked to agree to on the first commit to a repo within the organization.
|
443
476
|
Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
|
444
477
|
|
445
|
-
|
446
478
|
## License
|
447
479
|
|
448
480
|
This is free and unencumbered public domain software. For more information,
|
@@ -478,9 +510,9 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
|
478
510
|
[RDF::TriX]: https://ruby-rdf.github.com/rdf-trix
|
479
511
|
[RDF::Turtle]: https://ruby-rdf.github.com/rdf-turtle
|
480
512
|
[RDF::Raptor]: https://ruby-rdf.github.com/rdf-raptor
|
481
|
-
[RDF*]: https://
|
513
|
+
[RDF*]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html
|
482
514
|
[LinkedData]: https://ruby-rdf.github.com/linkeddata
|
483
515
|
[JSON::LD]: https://ruby-rdf.github.com/json-ld
|
484
516
|
[RestClient]: https://rubygems.org/gems/rest-client
|
485
517
|
[RestClient Components]: https://rubygems.org/gems/rest-client-components
|
486
|
-
[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.
|
1
|
+
3.1.12
|
data/lib/rdf.rb
CHANGED
@@ -2,6 +2,7 @@ require 'stringio'
|
|
2
2
|
require 'bigdecimal'
|
3
3
|
require 'date'
|
4
4
|
require 'time'
|
5
|
+
require "ostruct"
|
5
6
|
|
6
7
|
require 'rdf/version'
|
7
8
|
require 'rdf/extensions'
|
@@ -79,6 +80,29 @@ module RDF
|
|
79
80
|
# CLI
|
80
81
|
autoload :CLI, 'rdf/cli'
|
81
82
|
|
83
|
+
##
|
84
|
+
# Configuration, used open for configuring constants used within the codebase.
|
85
|
+
#
|
86
|
+
# @example set default cache size to be at most 10,000 entries
|
87
|
+
#
|
88
|
+
# RDF.config.cache_size = 10_000
|
89
|
+
#
|
90
|
+
# @example set cache size for interned URIs to 5,000 entries
|
91
|
+
#
|
92
|
+
# RDF.config.uri_cache_size = 5_000
|
93
|
+
#
|
94
|
+
# Defaults:
|
95
|
+
# * `cache_size`: -1
|
96
|
+
# * `uri_cache_size`: `cache_size`
|
97
|
+
# * `node_cache_size`: `cache_size`
|
98
|
+
#
|
99
|
+
# @note cache configurations must be set before initial use, when the caches are allocated.
|
100
|
+
# @see RDF::Util::Cache.new
|
101
|
+
# @return [Object]
|
102
|
+
def self.config
|
103
|
+
@config ||= OpenStruct.new(cache_size: -1, uri_cache_size: nil, node_cache_size: nil)
|
104
|
+
end
|
105
|
+
|
82
106
|
##
|
83
107
|
# Alias for `RDF::Resource.new`.
|
84
108
|
#
|
data/lib/rdf/cli.rb
CHANGED
@@ -8,9 +8,26 @@ begin
|
|
8
8
|
require 'linkeddata'
|
9
9
|
rescue LoadError
|
10
10
|
# Silently load without linkeddata, but try some others
|
11
|
-
%w(
|
11
|
+
%w(
|
12
|
+
json/ld
|
13
|
+
ld/patch
|
14
|
+
rdf/microdata
|
15
|
+
rdf/n3
|
16
|
+
rdf/ordered_repo
|
17
|
+
rdf/rdfa
|
18
|
+
rdf/rdfxml
|
19
|
+
rdf/reasoner
|
20
|
+
rdf/tabular
|
21
|
+
rdf/trig
|
22
|
+
rdf/trix
|
23
|
+
rdf/turtle
|
24
|
+
rdf/vocab
|
25
|
+
rdf/xsd
|
26
|
+
shacl
|
27
|
+
shex
|
28
|
+
).each do |ser|
|
12
29
|
begin
|
13
|
-
require ser
|
30
|
+
require ser
|
14
31
|
rescue LoadError
|
15
32
|
end
|
16
33
|
end
|
@@ -162,6 +179,7 @@ module RDF
|
|
162
179
|
# * `lambda` code run to execute command.
|
163
180
|
# * `filter` Option values that must match for command to be used
|
164
181
|
# * `control` Used to indicate how (if) command is displayed
|
182
|
+
# * `repository` Use this repository, if set
|
165
183
|
# * `options` an optional array of `RDF::CLI::Option` describing command-specific options.
|
166
184
|
# * `option_use`: A hash of option symbol to option usage, used for overriding the default status of an option for this command.
|
167
185
|
# @return [Hash{Symbol => Hash{Symbol => Object}}]
|
@@ -315,7 +333,7 @@ module RDF
|
|
315
333
|
|
316
334
|
# Add format-specific reader options
|
317
335
|
reader.options.each do |cli_opt|
|
318
|
-
next if options.options.
|
336
|
+
next if options.options.key?(cli_opt.symbol)
|
319
337
|
on_args = cli_opt.on || []
|
320
338
|
on_args << cli_opt.description if cli_opt.description
|
321
339
|
options.on(*on_args) do |opt_arg|
|
@@ -337,7 +355,7 @@ module RDF
|
|
337
355
|
|
338
356
|
# Add format-specific writer options
|
339
357
|
writer.options.each do |cli_opt|
|
340
|
-
next if options.options.
|
358
|
+
next if options.options.key?(cli_opt.symbol)
|
341
359
|
on_args = cli_opt.on || []
|
342
360
|
on_args << cli_opt.description if cli_opt.description
|
343
361
|
options.on(*on_args) do |opt_arg|
|
@@ -401,7 +419,7 @@ module RDF
|
|
401
419
|
end
|
402
420
|
|
403
421
|
cli_opts.each do |cli_opt|
|
404
|
-
next if opts.
|
422
|
+
next if opts.key?(cli_opt.symbol)
|
405
423
|
on_args = cli_opt.on || []
|
406
424
|
on_args << cli_opt.description if cli_opt.description
|
407
425
|
options.on(*on_args) do |arg|
|
@@ -456,7 +474,7 @@ module RDF
|
|
456
474
|
# @param [Array<String>] args
|
457
475
|
# @param [IO] output
|
458
476
|
# @param [OptionParser] option_parser
|
459
|
-
# @param [Hash{Symbol => Hash{Symbol => Array[String]}}] messages used for
|
477
|
+
# @param [Hash{Symbol => Hash{Symbol => Array[String]}}] messages used for conveying non primary-output which is structured.
|
460
478
|
# @param [Hash{Symbol => Object}] options
|
461
479
|
# @return [Boolean]
|
462
480
|
def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options)
|
@@ -493,6 +511,9 @@ module RDF
|
|
493
511
|
raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
|
494
512
|
end
|
495
513
|
end
|
514
|
+
|
515
|
+
# The command may specify a repository instance to use
|
516
|
+
options[:repository] ||= COMMANDS[c.to_sym][:repository]
|
496
517
|
end
|
497
518
|
|
498
519
|
# Hacks for specific options
|
@@ -501,9 +522,13 @@ module RDF
|
|
501
522
|
options[:format] = options[:format].to_sym if options[:format]
|
502
523
|
options[:output_format] = options[:output_format].to_sym if options[:output_format]
|
503
524
|
|
504
|
-
|
505
|
-
|
506
|
-
|
525
|
+
# Allow repository to be set via option.
|
526
|
+
# If RDF::OrderedRepo is present, use it if the `ordered` option is specified, otherwise extend an Array.
|
527
|
+
@repository = options[:repository] || case
|
528
|
+
when RDF.const_defined?(:OrderedRepo) then RDF::OrderedRepo.new
|
529
|
+
when options[:ordered] then [].extend(RDF::Enumerable, RDF::Queryable)
|
530
|
+
else RDF::Repository.new
|
531
|
+
end
|
507
532
|
|
508
533
|
# Parse input files if any command requires it
|
509
534
|
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
|
@@ -518,7 +543,10 @@ module RDF
|
|
518
543
|
|
519
544
|
# Run each command in sequence
|
520
545
|
cmds.each do |command|
|
521
|
-
COMMANDS[command.to_sym][:lambda].call(args,
|
546
|
+
COMMANDS[command.to_sym][:lambda].call(args,
|
547
|
+
output: output,
|
548
|
+
messages: messages,
|
549
|
+
**options.merge(repository: repository))
|
522
550
|
end
|
523
551
|
|
524
552
|
# Normalize messages
|
data/lib/rdf/mixin/enumerable.rb
CHANGED
@@ -12,15 +12,15 @@ module RDF
|
|
12
12
|
# enumerable.count
|
13
13
|
#
|
14
14
|
# @example Checking whether a specific statement exists
|
15
|
-
# enumerable.
|
16
|
-
# enumerable.
|
17
|
-
# enumerable.
|
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.
|
21
|
-
# enumerable.
|
22
|
-
# enumerable.
|
23
|
-
# enumerable.
|
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,25 @@ module RDF
|
|
127
127
|
end
|
128
128
|
|
129
129
|
##
|
130
|
-
#
|
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
|
-
#
|
133
|
-
#
|
134
|
-
def
|
135
|
-
|
137
|
+
# @param [RDF::Statement] statement
|
138
|
+
# @return [Boolean]
|
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
|
136
146
|
end
|
137
|
-
alias_method :
|
147
|
+
alias_method :has_statement?, :statement?
|
148
|
+
alias_method :include?, :statement?
|
138
149
|
|
139
150
|
##
|
140
151
|
# Iterates the given block for each RDF statement.
|
@@ -194,9 +205,10 @@ module RDF
|
|
194
205
|
#
|
195
206
|
# @param [Array(RDF::Resource, RDF::URI, RDF::Term)] triple
|
196
207
|
# @return [Boolean]
|
197
|
-
def
|
208
|
+
def triple?(triple)
|
198
209
|
triples.include?(triple)
|
199
210
|
end
|
211
|
+
alias_method :has_triple?, :triple?
|
200
212
|
|
201
213
|
##
|
202
214
|
# Iterates the given block for each RDF triple.
|
@@ -255,9 +267,10 @@ module RDF
|
|
255
267
|
#
|
256
268
|
# @param [Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)] quad
|
257
269
|
# @return [Boolean]
|
258
|
-
def
|
270
|
+
def quad?(quad)
|
259
271
|
quads.include?(quad)
|
260
272
|
end
|
273
|
+
alias_method :has_quad?, :quad?
|
261
274
|
|
262
275
|
##
|
263
276
|
# Iterates the given block for each RDF quad.
|
@@ -321,9 +334,10 @@ module RDF
|
|
321
334
|
#
|
322
335
|
# @param [RDF::Resource] value
|
323
336
|
# @return [Boolean]
|
324
|
-
def
|
337
|
+
def subject?(value)
|
325
338
|
enum_subject.include?(value)
|
326
339
|
end
|
340
|
+
alias_method :has_subject?, :subject?
|
327
341
|
|
328
342
|
##
|
329
343
|
# Iterates the given block for each unique RDF subject term.
|
@@ -386,9 +400,10 @@ module RDF
|
|
386
400
|
#
|
387
401
|
# @param [RDF::URI] value
|
388
402
|
# @return [Boolean]
|
389
|
-
def
|
403
|
+
def predicate?(value)
|
390
404
|
enum_predicate.include?(value)
|
391
405
|
end
|
406
|
+
alias_method :has_predicate?, :predicate?
|
392
407
|
|
393
408
|
##
|
394
409
|
# Iterates the given block for each unique RDF predicate term.
|
@@ -451,9 +466,10 @@ module RDF
|
|
451
466
|
#
|
452
467
|
# @param [RDF::Term] value
|
453
468
|
# @return [Boolean]
|
454
|
-
def
|
469
|
+
def object?(value)
|
455
470
|
enum_object.include?(value)
|
456
471
|
end
|
472
|
+
alias_method :has_object?, :object?
|
457
473
|
|
458
474
|
##
|
459
475
|
# Iterates the given block for each unique RDF object term.
|
@@ -511,7 +527,7 @@ module RDF
|
|
511
527
|
def terms(unique: true)
|
512
528
|
unless unique
|
513
529
|
enum_statement.
|
514
|
-
map(&:
|
530
|
+
map(&:terms).
|
515
531
|
flatten.
|
516
532
|
compact
|
517
533
|
else
|
@@ -520,14 +536,24 @@ module RDF
|
|
520
536
|
end
|
521
537
|
|
522
538
|
##
|
523
|
-
#
|
539
|
+
# @overload term?
|
540
|
+
# Returns `false` indicating this is not an RDF::Statemenet.
|
541
|
+
# @see RDF::Value#statement?
|
542
|
+
# @return [Boolean]
|
543
|
+
# @overload term?(value)
|
544
|
+
# Returns `true` if `self` contains the given RDF subject term.
|
524
545
|
#
|
525
|
-
#
|
526
|
-
#
|
527
|
-
#
|
528
|
-
def
|
529
|
-
|
546
|
+
# @param [RDF::Resource] value
|
547
|
+
# @return [Boolean]
|
548
|
+
# @since 2.0
|
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
|
530
555
|
end
|
556
|
+
alias_method :has_term?, :term?
|
531
557
|
|
532
558
|
##
|
533
559
|
# Iterates the given block for each unique RDF term (subject, predicate, object, or graph_name).
|
@@ -551,8 +577,8 @@ module RDF
|
|
551
577
|
if block_given?
|
552
578
|
values = {}
|
553
579
|
each_statement do |statement|
|
554
|
-
statement.
|
555
|
-
unless
|
580
|
+
statement.terms.each do |value|
|
581
|
+
unless values.include?(value.hash)
|
556
582
|
values[value.hash] = true
|
557
583
|
yield value
|
558
584
|
end
|
@@ -595,9 +621,10 @@ module RDF
|
|
595
621
|
# @param [RDF::Resource, false] graph_name
|
596
622
|
# Use value `false` to query for the default graph_name
|
597
623
|
# @return [Boolean]
|
598
|
-
def
|
624
|
+
def graph?(graph_name)
|
599
625
|
enum_statement.any? {|s| s.graph_name == graph_name}
|
600
626
|
end
|
627
|
+
alias_method :has_graph?, :graph?
|
601
628
|
|
602
629
|
##
|
603
630
|
# Limits statements to be from a specific graph.
|