rdf-kv 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/.yardopts +7 -0
- data/lib/rdf/kv/version.rb +1 -1
- data/lib/rdf/kv.rb +33 -26
- data/lib/rdf-kv.rb +1 -0
- data/rdf-kv.gemspec +4 -4
- metadata +17 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ace8319f10ea7f736fc8881d6546b19c908284189e5a40f1d0e08659bad5b19
|
4
|
+
data.tar.gz: f38dd9a9e778c037aad1199d6fc753bf6c037ba00acf0d6ee6e437e81efc0034
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efc28fc50193b33e5b461e053eff1e2eed46da55e29dd569b0546b0ef606f05b71dc36430eefed20031b35c25d5a2f455edcebda07f7fe327de7d43cf9373a68
|
7
|
+
data.tar.gz: 053f381f9cf6d907183103f50e47ffd2e5a3f5f85c86b7017dfca0d7733b993cc5994e37feb4890183a8c9f3bbfe7dd5c63829fb9e0b39ccc63b25747c5bc3c4
|
data/.gitignore
CHANGED
data/.yardopts
ADDED
data/lib/rdf/kv/version.rb
CHANGED
data/lib/rdf/kv.rb
CHANGED
@@ -35,7 +35,7 @@ class RDF::KV
|
|
35
35
|
|
36
36
|
GRAMMAR = /#{PARTIAL_STMT}/o
|
37
37
|
MAP = %i[modifier term1 term2 designator term1 designator graph
|
38
|
-
term1 term2 designator graph deref]
|
38
|
+
term1 term2 designator graph deref].freeze
|
39
39
|
|
40
40
|
# these should be instance_exec'd
|
41
41
|
SPECIALS = {
|
@@ -47,10 +47,10 @@ class RDF::KV
|
|
47
47
|
val.each do |v, _|
|
48
48
|
next unless m = /^\s*(#{NCNAME}):\s+(.*)$/o.match(v)
|
49
49
|
prefix, uri = m.captures
|
50
|
-
@
|
50
|
+
@prefixes[prefix.to_sym] = RDF::Vocabulary.new uri
|
51
51
|
end
|
52
52
|
},
|
53
|
-
}
|
53
|
+
}.freeze
|
54
54
|
|
55
55
|
# macros are initially represented as a pair: the macro value and a
|
56
56
|
# flag denoting whether or not the macro itself contains macros and to
|
@@ -60,7 +60,7 @@ class RDF::KV
|
|
60
60
|
NEW_UUID_URN: [[-> { UUIDTools::UUID.random_create.to_uri }, false]],
|
61
61
|
NEW_BNODE: [[-> { "_:#{UUID::NCName.to_ncname_64(
|
62
62
|
UUIDTools::UUID.random_create.to_s, version: 1) }" }, false]],
|
63
|
-
}
|
63
|
+
}.freeze
|
64
64
|
|
65
65
|
# just the classics
|
66
66
|
DEFAULT_NS = {
|
@@ -70,15 +70,14 @@ class RDF::KV
|
|
70
70
|
xsd: RDF::XSD,
|
71
71
|
}.freeze
|
72
72
|
|
73
|
+
# Given a (massaged) set of macros, dereference the given array of
|
74
|
+
# strings and return it.
|
73
75
|
def deref_content strings, macros
|
74
76
|
strings = [strings] unless strings.is_a? Array
|
75
77
|
# bail out early if there is nothing to do
|
76
78
|
return strings unless strings.any? { |s| /#{MACRO}/o.match s }
|
77
79
|
out = []
|
78
80
|
strings.each do |s|
|
79
|
-
# sometimes these are arrays of arrays
|
80
|
-
#s = s.first if s.is_a? Array
|
81
|
-
|
82
81
|
# chunks are parallel output; each element is a value
|
83
82
|
chunks = []
|
84
83
|
s.scan(/\G#{MACROS}/o) do |m|
|
@@ -125,6 +124,10 @@ class RDF::KV
|
|
125
124
|
out
|
126
125
|
end
|
127
126
|
|
127
|
+
# Given the structure of macro declarations, dereference any
|
128
|
+
# recursively-defined macros, and return a new structure with a key
|
129
|
+
# and array of _values_, rather than an array of `[value, deref]`
|
130
|
+
# pairs.
|
128
131
|
def massage_macros macros
|
129
132
|
seen = {}
|
130
133
|
done = GENERATED.transform_values { |v| v.map { |w| w.first } }
|
@@ -147,9 +150,7 @@ class RDF::KV
|
|
147
150
|
next unless deref
|
148
151
|
|
149
152
|
if deref.is_a? Array
|
150
|
-
deref.each
|
151
|
-
done[m] ? dm[m] = true : pm[m] = true
|
152
|
-
end
|
153
|
+
deref.each { |m| done[m] ? dm[m] = true : pm[m] = true }
|
153
154
|
else
|
154
155
|
m = {}
|
155
156
|
val.scan(/#{MACRO}/o).compact.each do |x|
|
@@ -161,7 +162,8 @@ class RDF::KV
|
|
161
162
|
|
162
163
|
done[m] ? dm[m] = true : pm[m] = true
|
163
164
|
end
|
164
|
-
|
165
|
+
|
166
|
+
# replace the deref flag with the elements to deref with
|
165
167
|
pair[1] = m.empty? ? false : m.keys.sort
|
166
168
|
end
|
167
169
|
end
|
@@ -174,6 +176,7 @@ class RDF::KV
|
|
174
176
|
q << m
|
175
177
|
end
|
176
178
|
|
179
|
+
# put the current key back on the queue but put the dependencies first
|
177
180
|
queue = q + [k] + queue
|
178
181
|
next
|
179
182
|
end
|
@@ -205,7 +208,7 @@ class RDF::KV
|
|
205
208
|
# ugh now we gotta do urls
|
206
209
|
if m = /^(#{NCNAME}):(\S*)$/o.match(term)
|
207
210
|
prefix, slug = m.captures
|
208
|
-
if !slug.start_with?(?/) and vocab =
|
211
|
+
if !slug.start_with?(?/) and vocab = prefixes[prefix.to_sym]
|
209
212
|
return vocab[slug]
|
210
213
|
end
|
211
214
|
end
|
@@ -238,37 +241,39 @@ class RDF::KV
|
|
238
241
|
|
239
242
|
# call the callback if we have one
|
240
243
|
term = callback.call term if callback
|
241
|
-
|
244
|
+
|
242
245
|
term
|
243
246
|
end
|
244
247
|
|
245
248
|
public
|
246
249
|
|
247
|
-
attr_reader :subject, :graph, :
|
250
|
+
attr_reader :subject, :graph, :prefixes, :callback
|
251
|
+
# why is this :target, :source
|
252
|
+
alias_method :namespaces, :prefixes
|
248
253
|
|
249
254
|
# Initialize the processor.
|
250
255
|
#
|
251
|
-
# @param subject
|
252
|
-
# @param graph
|
253
|
-
# @param
|
254
|
-
# @param callback
|
256
|
+
# @param subject [RDF::URI] The default subject. Required.
|
257
|
+
# @param graph [RDF::URI] The default context. Optional.
|
258
|
+
# @param prefixes [Hash] Namespace/prefix mappings. Optional.
|
259
|
+
# @param callback [#call] A callback that expects and returns a term.
|
255
260
|
# Optional.
|
256
261
|
#
|
257
|
-
def initialize subject: nil, graph: nil,
|
262
|
+
def initialize subject: nil, graph: nil, prefixes: {}, callback: nil
|
258
263
|
# look at all of our pretty assertions
|
259
264
|
raise ArgumentError, 'subject must be an RDF::Resource' unless
|
260
265
|
subject.is_a? RDF::Resource
|
261
266
|
raise ArgumentError, 'graph must be an RDF::Resource' unless
|
262
267
|
graph.nil? or graph.is_a? RDF::Resource
|
263
|
-
raise ArgumentError, '
|
264
|
-
|
268
|
+
raise ArgumentError, 'prefixes must be hashable' unless
|
269
|
+
prefixes.respond_to? :to_h
|
265
270
|
rase ArgumentError, 'callback must be callable' unless
|
266
271
|
callback.nil? or callback.respond_to? :call
|
267
272
|
|
268
|
-
@subject
|
269
|
-
@graph
|
270
|
-
@callback
|
271
|
-
@
|
273
|
+
@subject = subject
|
274
|
+
@graph = graph
|
275
|
+
@callback = callback
|
276
|
+
@prefixes = DEFAULT_NS.merge(prefixes.to_h.map do |k, v|
|
272
277
|
k = k.to_s.to_sym unless k.is_a? Symbol
|
273
278
|
# coerce to uri
|
274
279
|
v = RDF::URI(v.to_s) unless v.is_a? RDF::Resource
|
@@ -327,7 +332,7 @@ class RDF::KV
|
|
327
332
|
end
|
328
333
|
rescue Exception => e
|
329
334
|
# again this should be nicer
|
330
|
-
raise e
|
335
|
+
raise Error.new e
|
331
336
|
end
|
332
337
|
|
333
338
|
# this will be our output
|
@@ -418,4 +423,6 @@ class RDF::KV
|
|
418
423
|
|
419
424
|
patch
|
420
425
|
end
|
426
|
+
|
427
|
+
class Error < RuntimeError; end
|
421
428
|
end
|
data/lib/rdf-kv.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rdf/kv'
|
data/rdf-kv.gemspec
CHANGED
@@ -29,16 +29,16 @@ RDF::Changeset.
|
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ['lib']
|
31
31
|
|
32
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
32
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7')
|
33
33
|
# dev/test dependencies
|
34
34
|
spec.add_development_dependency 'bundler', '~> 2'
|
35
|
-
spec.add_development_dependency 'rdf-vocab', '~> 3
|
35
|
+
spec.add_development_dependency 'rdf-vocab', '~> 3'
|
36
36
|
|
37
37
|
# stuff we use
|
38
|
-
spec.add_runtime_dependency 'rdf', '
|
38
|
+
spec.add_runtime_dependency 'rdf', '~> 3' # include my changes
|
39
39
|
spec.add_runtime_dependency 'uuidtools', '~> 2'
|
40
40
|
|
41
41
|
# stuff i wrote
|
42
|
-
spec.add_runtime_dependency 'uuid-ncname', '>= 0.
|
42
|
+
spec.add_runtime_dependency 'uuid-ncname', '>= 0.4'
|
43
43
|
|
44
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-kv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Taylor
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3
|
33
|
+
version: '3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3
|
40
|
+
version: '3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rdf
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3
|
47
|
+
version: '3'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3
|
54
|
+
version: '3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: uuidtools
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: '0.4'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: '0.4'
|
83
83
|
description: |
|
84
84
|
This module implements https://doriantaylor.com/rdf-kv, taking
|
85
85
|
key-value input (e.g. from a Web form) and converting it into an
|
@@ -93,12 +93,14 @@ files:
|
|
93
93
|
- ".gitignore"
|
94
94
|
- ".rspec"
|
95
95
|
- ".travis.yml"
|
96
|
+
- ".yardopts"
|
96
97
|
- Gemfile
|
97
98
|
- LICENSE
|
98
99
|
- README.md
|
99
100
|
- Rakefile
|
100
101
|
- bin/console
|
101
102
|
- bin/setup
|
103
|
+
- lib/rdf-kv.rb
|
102
104
|
- lib/rdf/kv.rb
|
103
105
|
- lib/rdf/kv/version.rb
|
104
106
|
- rdf-kv.gemspec
|
@@ -107,7 +109,7 @@ licenses:
|
|
107
109
|
- Apache-2.0
|
108
110
|
metadata:
|
109
111
|
homepage_uri: https://github.com/doriantaylor/rb-rdf-kv
|
110
|
-
post_install_message:
|
112
|
+
post_install_message:
|
111
113
|
rdoc_options: []
|
112
114
|
require_paths:
|
113
115
|
- lib
|
@@ -115,15 +117,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
117
|
requirements:
|
116
118
|
- - ">="
|
117
119
|
- !ruby/object:Gem::Version
|
118
|
-
version: 2.
|
120
|
+
version: '2.7'
|
119
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
122
|
requirements:
|
121
123
|
- - ">="
|
122
124
|
- !ruby/object:Gem::Version
|
123
125
|
version: '0'
|
124
126
|
requirements: []
|
125
|
-
rubygems_version: 3.
|
126
|
-
signing_key:
|
127
|
+
rubygems_version: 3.3.15
|
128
|
+
signing_key:
|
127
129
|
specification_version: 4
|
128
130
|
summary: Ruby implementation of the RDF-KV protocol
|
129
131
|
test_files: []
|