rdf 3.1.8 → 3.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -11
- data/VERSION +1 -1
- data/lib/rdf/cli.rb +32 -12
- 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/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/statement.rb +80 -32
- data/lib/rdf/model/term.rb +22 -4
- data/lib/rdf/model/uri.rb +11 -10
- data/lib/rdf/model/value.rb +53 -16
- data/lib/rdf/ntriples/writer.rb +2 -2
- data/lib/rdf/query.rb +15 -4
- data/lib/rdf/query/pattern.rb +7 -7
- data/lib/rdf/query/solution.rb +32 -12
- data/lib/rdf/query/solutions.rb +18 -7
- data/lib/rdf/query/variable.rb +19 -5
- data/lib/rdf/repository.rb +46 -21
- data/lib/rdf/transaction.rb +13 -3
- data/lib/rdf/util/cache.rb +4 -3
- 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
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a8a5a69a203cf83628099c927675bbc4abe122bd8568bb69fa06bae0cbcb94b
|
4
|
+
data.tar.gz: eba5377c635a6b05c25cd2b88107521c494d557dbfde6c0de5dbe52646ee1401
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51af08617cb541333344b88a968c2d5699439baa7a4263154f7ccbdce06b635491b1cb93b9fb0e4dbca8711d9b71926ff22b60ab92f3f0cad9e205f86d1a3177
|
7
|
+
data.tar.gz: 8abc461f8937d46d3e75634764bc8bbaaf6f54ba07e39fa94c1400b62a59f20436ffd07c50a428aea7c2a01e292acbedb8f94bd5d07560e2523a00fef19174d1
|
data/README.md
CHANGED
@@ -7,9 +7,29 @@ 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
|
+
## 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.
|
1
|
+
3.1.13
|
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
|
@@ -239,8 +256,7 @@ module RDF
|
|
239
256
|
lambda: ->(argv, opts) do
|
240
257
|
writer_class = RDF::Writer.for(opts[:output_format]) || RDF::NTriples::Writer
|
241
258
|
out = opts[:output]
|
242
|
-
|
243
|
-
writer_opts = opts.merge(standard_prefixes: true)
|
259
|
+
writer_opts = {prefixes: {}, standard_prefixes: true}.merge(opts)
|
244
260
|
writer_class.new(out, **writer_opts) do |writer|
|
245
261
|
writer << repository
|
246
262
|
end
|
@@ -316,7 +332,7 @@ module RDF
|
|
316
332
|
|
317
333
|
# Add format-specific reader options
|
318
334
|
reader.options.each do |cli_opt|
|
319
|
-
next if options.options.
|
335
|
+
next if options.options.key?(cli_opt.symbol)
|
320
336
|
on_args = cli_opt.on || []
|
321
337
|
on_args << cli_opt.description if cli_opt.description
|
322
338
|
options.on(*on_args) do |opt_arg|
|
@@ -338,7 +354,7 @@ module RDF
|
|
338
354
|
|
339
355
|
# Add format-specific writer options
|
340
356
|
writer.options.each do |cli_opt|
|
341
|
-
next if options.options.
|
357
|
+
next if options.options.key?(cli_opt.symbol)
|
342
358
|
on_args = cli_opt.on || []
|
343
359
|
on_args << cli_opt.description if cli_opt.description
|
344
360
|
options.on(*on_args) do |opt_arg|
|
@@ -402,7 +418,7 @@ module RDF
|
|
402
418
|
end
|
403
419
|
|
404
420
|
cli_opts.each do |cli_opt|
|
405
|
-
next if opts.
|
421
|
+
next if opts.key?(cli_opt.symbol)
|
406
422
|
on_args = cli_opt.on || []
|
407
423
|
on_args << cli_opt.description if cli_opt.description
|
408
424
|
options.on(*on_args) do |arg|
|
@@ -457,7 +473,7 @@ module RDF
|
|
457
473
|
# @param [Array<String>] args
|
458
474
|
# @param [IO] output
|
459
475
|
# @param [OptionParser] option_parser
|
460
|
-
# @param [Hash{Symbol => Hash{Symbol => Array[String]}}] messages used for
|
476
|
+
# @param [Hash{Symbol => Hash{Symbol => Array[String]}}] messages used for conveying non primary-output which is structured.
|
461
477
|
# @param [Hash{Symbol => Object}] options
|
462
478
|
# @return [Boolean]
|
463
479
|
def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options)
|
@@ -506,10 +522,12 @@ module RDF
|
|
506
522
|
options[:output_format] = options[:output_format].to_sym if options[:output_format]
|
507
523
|
|
508
524
|
# Allow repository to be set via option.
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
525
|
+
# If RDF::OrderedRepo is present, use it if the `ordered` option is specified, otherwise extend an Array.
|
526
|
+
@repository = options[:repository] || case
|
527
|
+
when RDF.const_defined?(:OrderedRepo) then RDF::OrderedRepo.new
|
528
|
+
when options[:ordered] then [].extend(RDF::Enumerable, RDF::Queryable)
|
529
|
+
else RDF::Repository.new
|
530
|
+
end
|
513
531
|
|
514
532
|
# Parse input files if any command requires it
|
515
533
|
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
|
@@ -517,6 +535,8 @@ module RDF
|
|
517
535
|
count = 0
|
518
536
|
self.parse(args, **options) do |reader|
|
519
537
|
reader.each_statement {|st| @repository << st}
|
538
|
+
# Remember prefixes from reading
|
539
|
+
options[:prefixes] ||= reader.prefixes
|
520
540
|
end
|
521
541
|
secs = Time.new - start
|
522
542
|
options[:logger].info "Parsed #{repository.count} statements with #{@readers.join(', ')} in #{secs} seconds @ #{count/secs} statements/second."
|
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.
|
data/lib/rdf/mixin/mutable.rb
CHANGED
@@ -122,7 +122,7 @@ module RDF
|
|
122
122
|
|
123
123
|
statements.each do |statement|
|
124
124
|
if (statement = Statement.from(statement))
|
125
|
-
if statement.
|
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])
|
data/lib/rdf/model/dataset.rb
CHANGED