rdf 3.1.0 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AUTHORS +1 -1
- data/README.md +43 -9
- data/VERSION +1 -1
- data/bin/rdf +2 -2
- data/etc/doap.nt +74 -80
- data/lib/rdf.rb +16 -11
- data/lib/rdf/changeset.rb +86 -18
- data/lib/rdf/cli.rb +11 -3
- data/lib/rdf/mixin/enumerable.rb +1 -0
- data/lib/rdf/mixin/mutable.rb +3 -13
- data/lib/rdf/mixin/queryable.rb +8 -0
- data/lib/rdf/mixin/writable.rb +9 -14
- data/lib/rdf/model/dataset.rb +1 -1
- data/lib/rdf/model/graph.rb +3 -0
- data/lib/rdf/model/statement.rb +30 -7
- data/lib/rdf/model/uri.rb +10 -10
- data/lib/rdf/nquads.rb +2 -2
- data/lib/rdf/ntriples.rb +6 -4
- data/lib/rdf/ntriples/reader.rb +28 -3
- data/lib/rdf/ntriples/writer.rb +9 -0
- data/lib/rdf/query.rb +4 -1
- data/lib/rdf/query/hash_pattern_normalizer.rb +9 -8
- data/lib/rdf/query/pattern.rb +49 -16
- data/lib/rdf/query/solution.rb +20 -1
- data/lib/rdf/query/solutions.rb +15 -5
- data/lib/rdf/query/variable.rb +17 -5
- data/lib/rdf/reader.rb +65 -20
- data/lib/rdf/repository.rb +27 -13
- data/lib/rdf/util.rb +6 -5
- data/lib/rdf/util/cache.rb +2 -2
- data/lib/rdf/util/coercions.rb +60 -0
- data/lib/rdf/util/file.rb +3 -3
- data/lib/rdf/util/logger.rb +1 -1
- data/lib/rdf/vocab/owl.rb +401 -86
- data/lib/rdf/vocab/rdfs.rb +81 -18
- data/lib/rdf/vocab/rdfv.rb +122 -1
- data/lib/rdf/vocab/writer.rb +43 -4
- data/lib/rdf/vocab/xsd.rb +203 -2
- data/lib/rdf/vocabulary.rb +105 -11
- data/lib/rdf/writer.rb +21 -5
- metadata +9 -8
data/lib/rdf/vocabulary.rb
CHANGED
@@ -58,6 +58,9 @@ module RDF
|
|
58
58
|
class Vocabulary
|
59
59
|
extend ::Enumerable
|
60
60
|
|
61
|
+
autoload :Format, 'rdf/vocab/writer'
|
62
|
+
autoload :Writer, 'rdf/vocab/writer'
|
63
|
+
|
61
64
|
class << self
|
62
65
|
##
|
63
66
|
# Enumerates known RDF vocabulary classes.
|
@@ -67,16 +70,103 @@ module RDF
|
|
67
70
|
# @return [Enumerator]
|
68
71
|
def each(&block)
|
69
72
|
if self.equal?(Vocabulary)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
if @vocabs
|
74
|
+
@vocabs.select(&:name).each(&block)
|
75
|
+
else
|
76
|
+
# This is needed since all vocabulary classes are defined using
|
77
|
+
# Ruby's autoloading facility, meaning that `@@subclasses` will be
|
78
|
+
# empty until each subclass has been touched or require'd.
|
79
|
+
RDF::VOCABS.each { |v, p| RDF.const_get(p[:class_name].to_sym) unless v == :rdf }
|
80
|
+
@@subclasses.select(&:name).each(&block)
|
81
|
+
end
|
75
82
|
else
|
76
83
|
__properties__.each(&block)
|
77
84
|
end
|
78
85
|
end
|
79
86
|
|
87
|
+
##
|
88
|
+
# A hash of all vocabularies by prefix showing relevant URI and
|
89
|
+
# associated vocabulary Class Name
|
90
|
+
#
|
91
|
+
# @return [Hash{Symbol => Hash{Symbol => String}}]
|
92
|
+
def vocab_map
|
93
|
+
# Create an initial duplicate of RDF::VOCABS. We want to
|
94
|
+
# ensure the hash itself is modifiable but the values are
|
95
|
+
# frozen.
|
96
|
+
@vocab_map ||= RDF::VOCABS.transform_values(&:freeze)
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# Return the vocabulary based on it's class_name symbol
|
101
|
+
#
|
102
|
+
# @param [Symbol] sym
|
103
|
+
# @return [RDF::Vocabulary]
|
104
|
+
def from_sym(sym)
|
105
|
+
RDF.const_get(sym.to_sym)
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# Register a vocabulary for internal prefix lookups. Parameters
|
110
|
+
# of interest include `:uri`, `:class_name`, `:source`, and `:skip`.
|
111
|
+
#
|
112
|
+
# @param prefix [Symbol] the prefix to use
|
113
|
+
# @param vocab [String, Class] either the URI or the vocab class
|
114
|
+
# @param params [Hash{Symbol => String}] Relevant parameters
|
115
|
+
# @return [Hash] The parameter hash, but frozen
|
116
|
+
def register(prefix, vocab, **params)
|
117
|
+
# check the input
|
118
|
+
raise ArgumentError, "#{prefix} must be symbol-able" unless
|
119
|
+
[String, Symbol].any? { |c| prefix.is_a? c }
|
120
|
+
|
121
|
+
# note an explicit uri: param overrides
|
122
|
+
case vocab
|
123
|
+
when String then params[:uri] ||= vocab
|
124
|
+
when Class
|
125
|
+
raise ArgumentError, 'vocab must be an RDF::(Strict)Vocabulary' unless
|
126
|
+
vocab.ancestors.include? RDF::Vocabulary
|
127
|
+
params[:class] = vocab
|
128
|
+
params[:uri] ||= vocab.to_uri.to_s
|
129
|
+
end
|
130
|
+
|
131
|
+
# fill in the class name
|
132
|
+
params[:class_name] ||= prefix.to_s.upcase
|
133
|
+
|
134
|
+
# now freeze and assign
|
135
|
+
vocab_map[prefix.to_s.to_sym] = params.freeze
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Limits iteration over vocabularies to just those selected
|
140
|
+
#
|
141
|
+
# @example limit to set of vocabularies by symbol
|
142
|
+
# RDF::Vocabulary.limit_vocabs(:rdf, :rdfs
|
143
|
+
# RDF::Vocabulary.find_term('http://www.w3.org/2000/01/rdf-schema#Resource').pname
|
144
|
+
# # => 'rdfs:Resource'
|
145
|
+
#
|
146
|
+
# @example limit to set of vocabularies by class name
|
147
|
+
# RDF::Vocabulary.limit_vocabs(RDF::RDFV, RDF::RDFS)
|
148
|
+
# RDF::Vocabulary.find_term('http://www.w3.org/2000/01/rdf-schema#Resource').pname
|
149
|
+
# # => 'rdfs:Resource'
|
150
|
+
#
|
151
|
+
# @param [Array<symbol, RDF::Vocabulary>] vocabs
|
152
|
+
# A list of vocabularies (symbols or classes) which may
|
153
|
+
# be returned by {Vocabulary.each}. Also limits
|
154
|
+
# vocabularies that will be inspeced for other methods.
|
155
|
+
# Set to nil, or an empty array to reset.
|
156
|
+
# @return [Array<RDF::Vocabulary>]
|
157
|
+
def limit_vocabs(*vocabs)
|
158
|
+
@vocabs = if Array(vocabs).empty?
|
159
|
+
nil
|
160
|
+
else
|
161
|
+
vocabs.map do |vocab|
|
162
|
+
vocab = :rdfv if vocab == :rdf
|
163
|
+
vocab.is_a?(Symbol) && RDF::VOCABS.key?(vocab) ?
|
164
|
+
RDF.const_get(RDF::VOCABS[vocab][:class_name].to_sym) :
|
165
|
+
vocab
|
166
|
+
end.compact
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
80
170
|
##
|
81
171
|
# Is this a strict vocabulary, or a liberal vocabulary allowing arbitrary properties?
|
82
172
|
def strict?; false; end
|
@@ -291,7 +381,9 @@ module RDF
|
|
291
381
|
prefix, suffix = pname.to_s.split(":", 2)
|
292
382
|
if prefix == "rdf"
|
293
383
|
RDF[suffix]
|
294
|
-
elsif
|
384
|
+
elsif vocab_detail = RDF::Vocabulary.vocab_map[prefix.to_sym]
|
385
|
+
vocab = vocab_detail[:class] ||
|
386
|
+
RDF::Vocabulary.from_sym(vocab_detail[:class_name])
|
295
387
|
suffix.to_s.empty? ? vocab.to_uri : vocab[suffix]
|
296
388
|
else
|
297
389
|
(RDF::Vocabulary.find_term(pname) rescue nil) || RDF::URI(pname, validate: true)
|
@@ -817,11 +909,10 @@ module RDF
|
|
817
909
|
# @return [RDF::Vocabulary]
|
818
910
|
attr_reader :vocab
|
819
911
|
|
820
|
-
#
|
821
|
-
#
|
912
|
+
# Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF.
|
913
|
+
# @return [Hash{Symbol,Resource => Term, #to_s}]
|
822
914
|
attr_reader :attributes
|
823
915
|
|
824
|
-
|
825
916
|
##
|
826
917
|
# @overload new(uri, attributes:, **options)
|
827
918
|
# @param [URI, String, #to_s] uri
|
@@ -882,7 +973,10 @@ module RDF
|
|
882
973
|
#
|
883
974
|
# @return [RDF::URI]
|
884
975
|
def dup
|
885
|
-
|
976
|
+
term = super.extend(Term)
|
977
|
+
term.instance_variable_set(:@vocab, vocab)
|
978
|
+
term.instance_variable_set(:@attributes, attributes)
|
979
|
+
term
|
886
980
|
end
|
887
981
|
|
888
982
|
##
|
@@ -943,7 +1037,7 @@ module RDF
|
|
943
1037
|
##
|
944
1038
|
# Values of an attributes as {RDF::Value}
|
945
1039
|
#
|
946
|
-
# @
|
1040
|
+
# @param [Symbol] prop
|
947
1041
|
# @return [RDF::Value, Array<RDF::Value>]
|
948
1042
|
def attribute_value(prop)
|
949
1043
|
values = attributes[prop]
|
data/lib/rdf/writer.rb
CHANGED
@@ -511,11 +511,12 @@ module RDF
|
|
511
511
|
# @since 0.3.0
|
512
512
|
def format_term(term, **options)
|
513
513
|
case term
|
514
|
-
when String
|
515
|
-
when RDF::List
|
516
|
-
when RDF::Literal
|
517
|
-
when RDF::URI
|
518
|
-
when RDF::Node
|
514
|
+
when String then format_literal(RDF::Literal(term, **options), **options)
|
515
|
+
when RDF::List then format_list(term, **options)
|
516
|
+
when RDF::Literal then format_literal(term, **options)
|
517
|
+
when RDF::URI then format_uri(term, **options)
|
518
|
+
when RDF::Node then format_node(term, **options)
|
519
|
+
when RDF::Statement then format_rdfstar(term, **options)
|
519
520
|
else nil
|
520
521
|
end
|
521
522
|
end
|
@@ -562,6 +563,21 @@ module RDF
|
|
562
563
|
format_term(value.subject, **options)
|
563
564
|
end
|
564
565
|
|
566
|
+
##
|
567
|
+
# Formats a referenced triple.
|
568
|
+
#
|
569
|
+
# @example
|
570
|
+
# <<<s> <p> <o>>> <p> <o> .
|
571
|
+
#
|
572
|
+
# @param [RDF::Statement] value
|
573
|
+
# @param [Hash{Symbol => Object}] options = ({})
|
574
|
+
# @return [String]
|
575
|
+
# @raise [NotImplementedError] unless implemented in subclass
|
576
|
+
# @abstract
|
577
|
+
def format_rdfstar(value, **options)
|
578
|
+
raise NotImplementedError.new("#{self.class}#format_statement") # override in subclasses
|
579
|
+
end
|
580
|
+
|
565
581
|
protected
|
566
582
|
|
567
583
|
##
|
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.
|
4
|
+
version: 3.1.5
|
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:
|
13
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: link_header
|
@@ -80,28 +80,28 @@ dependencies:
|
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '3.
|
83
|
+
version: '3.1'
|
84
84
|
type: :development
|
85
85
|
prerelease: false
|
86
86
|
version_requirements: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: '3.
|
90
|
+
version: '3.1'
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rdf-xsd
|
93
93
|
requirement: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: '3.
|
97
|
+
version: '3.1'
|
98
98
|
type: :development
|
99
99
|
prerelease: false
|
100
100
|
version_requirements: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '3.
|
104
|
+
version: '3.1'
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: rest-client
|
107
107
|
requirement: !ruby/object:Gem::Requirement
|
@@ -267,6 +267,7 @@ files:
|
|
267
267
|
- lib/rdf/util.rb
|
268
268
|
- lib/rdf/util/aliasing.rb
|
269
269
|
- lib/rdf/util/cache.rb
|
270
|
+
- lib/rdf/util/coercions.rb
|
270
271
|
- lib/rdf/util/file.rb
|
271
272
|
- lib/rdf/util/logger.rb
|
272
273
|
- lib/rdf/util/uuid.rb
|
@@ -278,7 +279,7 @@ files:
|
|
278
279
|
- lib/rdf/vocab/xsd.rb
|
279
280
|
- lib/rdf/vocabulary.rb
|
280
281
|
- lib/rdf/writer.rb
|
281
|
-
homepage: https://
|
282
|
+
homepage: https://github.com/ruby-rdf/rdf
|
282
283
|
licenses:
|
283
284
|
- Unlicense
|
284
285
|
metadata:
|
@@ -302,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
302
303
|
- !ruby/object:Gem::Version
|
303
304
|
version: '0'
|
304
305
|
requirements: []
|
305
|
-
rubygems_version: 3.
|
306
|
+
rubygems_version: 3.1.3
|
306
307
|
signing_key:
|
307
308
|
specification_version: 4
|
308
309
|
summary: A Ruby library for working with Resource Description Framework (RDF) data.
|