json-ld 3.2.3 → 3.2.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/VERSION +1 -1
- data/lib/json/ld/api.rb +807 -764
- data/lib/json/ld/compact.rb +304 -304
- data/lib/json/ld/conneg.rb +179 -161
- data/lib/json/ld/context.rb +2080 -1945
- data/lib/json/ld/expand.rb +745 -666
- data/lib/json/ld/extensions.rb +14 -13
- data/lib/json/ld/flatten.rb +257 -247
- data/lib/json/ld/format.rb +202 -194
- data/lib/json/ld/frame.rb +525 -502
- data/lib/json/ld/from_rdf.rb +224 -166
- data/lib/json/ld/html/nokogiri.rb +123 -121
- data/lib/json/ld/html/rexml.rb +151 -147
- data/lib/json/ld/reader.rb +107 -100
- data/lib/json/ld/resource.rb +224 -205
- data/lib/json/ld/streaming_reader.rb +574 -507
- data/lib/json/ld/streaming_writer.rb +93 -92
- data/lib/json/ld/to_rdf.rb +171 -167
- data/lib/json/ld/utils.rb +270 -264
- data/lib/json/ld/version.rb +24 -14
- data/lib/json/ld/writer.rb +334 -311
- data/lib/json/ld.rb +103 -96
- metadata +78 -209
- data/spec/api_spec.rb +0 -132
- data/spec/compact_spec.rb +0 -3482
- data/spec/conneg_spec.rb +0 -373
- data/spec/context_spec.rb +0 -2036
- data/spec/expand_spec.rb +0 -4496
- data/spec/flatten_spec.rb +0 -1203
- data/spec/format_spec.rb +0 -115
- data/spec/frame_spec.rb +0 -2498
- data/spec/from_rdf_spec.rb +0 -1005
- data/spec/matchers.rb +0 -20
- data/spec/rdfstar_spec.rb +0 -25
- data/spec/reader_spec.rb +0 -883
- data/spec/resource_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -281
- data/spec/streaming_reader_spec.rb +0 -237
- data/spec/streaming_writer_spec.rb +0 -145
- data/spec/suite_compact_spec.rb +0 -22
- data/spec/suite_expand_spec.rb +0 -36
- data/spec/suite_flatten_spec.rb +0 -34
- data/spec/suite_frame_spec.rb +0 -29
- data/spec/suite_from_rdf_spec.rb +0 -22
- data/spec/suite_helper.rb +0 -411
- data/spec/suite_html_spec.rb +0 -22
- data/spec/suite_http_spec.rb +0 -35
- data/spec/suite_remote_doc_spec.rb +0 -22
- data/spec/suite_to_rdf_spec.rb +0 -30
- data/spec/support/extensions.rb +0 -44
- data/spec/test-files/test-1-compacted.jsonld +0 -10
- data/spec/test-files/test-1-context.jsonld +0 -7
- data/spec/test-files/test-1-expanded.jsonld +0 -5
- data/spec/test-files/test-1-input.jsonld +0 -10
- data/spec/test-files/test-1-rdf.ttl +0 -8
- data/spec/test-files/test-2-compacted.jsonld +0 -20
- data/spec/test-files/test-2-context.jsonld +0 -7
- data/spec/test-files/test-2-expanded.jsonld +0 -16
- data/spec/test-files/test-2-input.jsonld +0 -20
- data/spec/test-files/test-2-rdf.ttl +0 -14
- data/spec/test-files/test-3-compacted.jsonld +0 -11
- data/spec/test-files/test-3-context.jsonld +0 -8
- data/spec/test-files/test-3-expanded.jsonld +0 -10
- data/spec/test-files/test-3-input.jsonld +0 -11
- data/spec/test-files/test-3-rdf.ttl +0 -8
- data/spec/test-files/test-4-compacted.jsonld +0 -10
- data/spec/test-files/test-4-context.jsonld +0 -7
- data/spec/test-files/test-4-expanded.jsonld +0 -6
- data/spec/test-files/test-4-input.jsonld +0 -10
- data/spec/test-files/test-4-rdf.ttl +0 -5
- data/spec/test-files/test-5-compacted.jsonld +0 -13
- data/spec/test-files/test-5-context.jsonld +0 -7
- data/spec/test-files/test-5-expanded.jsonld +0 -9
- data/spec/test-files/test-5-input.jsonld +0 -13
- data/spec/test-files/test-5-rdf.ttl +0 -7
- data/spec/test-files/test-6-compacted.jsonld +0 -10
- data/spec/test-files/test-6-context.jsonld +0 -7
- data/spec/test-files/test-6-expanded.jsonld +0 -10
- data/spec/test-files/test-6-input.jsonld +0 -10
- data/spec/test-files/test-6-rdf.ttl +0 -6
- data/spec/test-files/test-7-compacted.jsonld +0 -23
- data/spec/test-files/test-7-context.jsonld +0 -4
- data/spec/test-files/test-7-expanded.jsonld +0 -20
- data/spec/test-files/test-7-input.jsonld +0 -23
- data/spec/test-files/test-7-rdf.ttl +0 -14
- data/spec/test-files/test-8-compacted.jsonld +0 -34
- data/spec/test-files/test-8-context.jsonld +0 -11
- data/spec/test-files/test-8-expanded.jsonld +0 -24
- data/spec/test-files/test-8-frame.jsonld +0 -18
- data/spec/test-files/test-8-framed.jsonld +0 -25
- data/spec/test-files/test-8-input.jsonld +0 -30
- data/spec/test-files/test-8-rdf.ttl +0 -15
- data/spec/test-files/test-9-compacted.jsonld +0 -20
- data/spec/test-files/test-9-context.jsonld +0 -13
- data/spec/test-files/test-9-expanded.jsonld +0 -14
- data/spec/test-files/test-9-input.jsonld +0 -12
- data/spec/to_rdf_spec.rb +0 -1551
- data/spec/writer_spec.rb +0 -427
data/lib/json/ld/utils.rb
CHANGED
@@ -1,305 +1,311 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
# frozen_string_literal: true
|
3
|
-
module JSON::LD
|
4
|
-
module Utils
|
5
|
-
##
|
6
|
-
# Is value a node? A value is a node if
|
7
|
-
# * it is a Hash
|
8
|
-
# * it is not a @value, @set or @list
|
9
|
-
# * it has more than 1 key or any key is not @id
|
10
|
-
# @param [Object] value
|
11
|
-
# @return [Boolean]
|
12
|
-
def node?(value)
|
13
|
-
value.is_a?(Hash) &&
|
14
|
-
!(value.key?('@value') || value.key?('@list') || value.key?('@set')) &&
|
15
|
-
(value.length > 1 || !value.key?('@id'))
|
16
|
-
end
|
17
2
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
3
|
+
module JSON
|
4
|
+
module LD
|
5
|
+
module Utils
|
6
|
+
##
|
7
|
+
# Is value a node? A value is a node if
|
8
|
+
# * it is a Hash
|
9
|
+
# * it is not a @value, @set or @list
|
10
|
+
# * it has more than 1 key or any key is not @id
|
11
|
+
# @param [Object] value
|
12
|
+
# @return [Boolean]
|
13
|
+
def node?(value)
|
14
|
+
value.is_a?(Hash) &&
|
15
|
+
!(value.key?('@value') || value.key?('@list') || value.key?('@set')) &&
|
16
|
+
(value.length > 1 || !value.key?('@id'))
|
17
|
+
end
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
19
|
+
##
|
20
|
+
# Is value a node reference?
|
21
|
+
# @param [Object] value
|
22
|
+
# @return [Boolean]
|
23
|
+
def node_reference?(value)
|
24
|
+
value.is_a?(Hash) && value.length == 1 && value.key?('@id')
|
25
|
+
end
|
34
26
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
when nil then true
|
43
|
-
when String then value.start_with?('_:')
|
44
|
-
else
|
45
|
-
(node?(value) || node_reference?(value)) && value.fetch('@id', '_:').start_with?('_:')
|
27
|
+
##
|
28
|
+
# Is value a node or a node reference reference?
|
29
|
+
# @param [Object] value
|
30
|
+
# @return [Boolean]
|
31
|
+
def node_or_ref?(value)
|
32
|
+
value.is_a?(Hash) &&
|
33
|
+
!(value.key?('@value') || value.key?('@list') || value.key?('@set'))
|
46
34
|
end
|
47
|
-
end
|
48
35
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
36
|
+
##
|
37
|
+
# Is value a blank node? Value is a blank node
|
38
|
+
#
|
39
|
+
# @param [Object] value
|
40
|
+
# @return [Boolean]
|
41
|
+
def blank_node?(value)
|
42
|
+
case value
|
43
|
+
when nil then true
|
44
|
+
when String then value.start_with?('_:')
|
45
|
+
else
|
46
|
+
(node?(value) || node_reference?(value)) && value.fetch('@id', '_:').start_with?('_:')
|
47
|
+
end
|
48
|
+
end
|
62
49
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
# @return [Boolean]
|
77
|
-
def list?(value)
|
78
|
-
value.is_a?(Hash) && value.key?('@list')
|
79
|
-
end
|
50
|
+
##
|
51
|
+
# Is value an expaned @graph?
|
52
|
+
#
|
53
|
+
# Note: A value is a graph if all of these hold true:
|
54
|
+
# 1. It is an object.
|
55
|
+
# 2. It has an `@graph` key.
|
56
|
+
# 3. It may have '@context', '@id' or '@index'
|
57
|
+
#
|
58
|
+
# @param [Object] value
|
59
|
+
# @return [Boolean]
|
60
|
+
def graph?(value)
|
61
|
+
value.is_a?(Hash) && (value.keys - UTIL_GRAPH_KEYS) == ['@graph']
|
62
|
+
end
|
80
63
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
64
|
+
##
|
65
|
+
# Is value a simple graph (lacking @id)?
|
66
|
+
#
|
67
|
+
# @param [Object] value
|
68
|
+
# @return [Boolean]
|
69
|
+
def simple_graph?(value)
|
70
|
+
graph?(value) && !value.key?('@id')
|
71
|
+
end
|
89
72
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
73
|
+
##
|
74
|
+
# Is value an expaned @list?
|
75
|
+
#
|
76
|
+
# @param [Object] value
|
77
|
+
# @return [Boolean]
|
78
|
+
def list?(value)
|
79
|
+
value.is_a?(Hash) && value.key?('@list')
|
80
|
+
end
|
98
81
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
if id.start_with?('_:')
|
107
|
-
(@nodes[id] ||= RDF::Node.new(namer.get_sym(id)))
|
108
|
-
elsif base
|
109
|
-
base.join(id)
|
110
|
-
else
|
111
|
-
RDF::URI(id)
|
82
|
+
##
|
83
|
+
# Is value annotated?
|
84
|
+
#
|
85
|
+
# @param [Object] value
|
86
|
+
# @return [Boolean]
|
87
|
+
def index?(value)
|
88
|
+
value.is_a?(Hash) && value.key?('@index')
|
112
89
|
end
|
113
|
-
end
|
114
90
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
91
|
+
##
|
92
|
+
# Is value literal?
|
93
|
+
#
|
94
|
+
# @param [Object] value
|
95
|
+
# @return [Boolean]
|
96
|
+
def value?(value)
|
97
|
+
value.is_a?(Hash) && value.key?('@value')
|
98
|
+
end
|
122
99
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
v1 == v2
|
100
|
+
##
|
101
|
+
# Represent an id as an IRI or Blank Node
|
102
|
+
# @param [String] id
|
103
|
+
# @param [RDF::URI] base (nil)
|
104
|
+
# @return [RDF::Resource]
|
105
|
+
def as_resource(id, base = nil)
|
106
|
+
@nodes ||= {} # Re-use BNodes
|
107
|
+
if id.start_with?('_:')
|
108
|
+
(@nodes[id] ||= RDF::Node.new(namer.get_sym(id)))
|
109
|
+
elsif base
|
110
|
+
base.join(id)
|
111
|
+
else
|
112
|
+
RDF::URI(id)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Represent as an array
|
118
|
+
# @param [Object] object
|
119
|
+
# @return [Array<Object>]
|
120
|
+
def as_array(object)
|
121
|
+
object.is_a?(Array) ? object : [object]
|
146
122
|
end
|
147
|
-
end
|
148
123
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
124
|
+
##
|
125
|
+
# Compares two JSON-LD values for equality. Two JSON-LD values will be
|
126
|
+
# considered equal if:
|
127
|
+
#
|
128
|
+
# 1. They are both primitives of the same type and value.
|
129
|
+
# 2. They are both @values with the same @value, @type, @language,
|
130
|
+
# and @index, OR
|
131
|
+
# 3. They both have @ids that are the same.
|
132
|
+
#
|
133
|
+
# @param [Object] v1 the first value.
|
134
|
+
# @param [Object] v2 the second value.
|
135
|
+
#
|
136
|
+
# @return [Boolean] v1 and v2 are considered equal
|
137
|
+
def compare_values(v1, v2)
|
138
|
+
if node_or_ref?(v1) && node_or_ref?(v2)
|
139
|
+
v1['@id'] && v1['@id'] == v2['@id']
|
140
|
+
elsif value?(v1) && value?(v2)
|
141
|
+
v1['@value'] == v2['@value'] &&
|
142
|
+
v1['@type'] == v2['@type'] &&
|
143
|
+
v1['@language'] == v2['@language'] &&
|
144
|
+
v1['@index'] == v2['@index']
|
145
|
+
else
|
146
|
+
v1 == v2
|
170
147
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
148
|
+
end
|
149
|
+
|
150
|
+
# Adds a value to a subject. If the value is an array, all values in the
|
151
|
+
# array will be added.
|
152
|
+
#
|
153
|
+
# @param [Hash] subject the hash to add the value to.
|
154
|
+
# @param [String] property the property that relates the value to the subject.
|
155
|
+
# @param [Object] value the value to add.
|
156
|
+
# @param [Boolean] property_is_array (false)
|
157
|
+
# true if the property is always an array, false if not.
|
158
|
+
# @param [Boolean] value_is_array (false)
|
159
|
+
# true if the value to be added should be preserved as an array (lists)
|
160
|
+
# @param [Boolean] allow_duplicate (true)
|
161
|
+
# true to allow duplicates, false not to (uses
|
162
|
+
# a simple shallow comparison of subject ID or value).
|
163
|
+
def add_value(subject, property, value, property_is_array: false, value_is_array: false, allow_duplicate: true)
|
164
|
+
if value_is_array
|
165
|
+
subject[property] = value
|
166
|
+
elsif value.is_a?(Array)
|
167
|
+
subject[property] = [] if value.empty? && property_is_array
|
168
|
+
value.each do |v|
|
169
|
+
add_value(subject, property, v,
|
170
|
+
property_is_array: property_is_array, allow_duplicate: allow_duplicate)
|
171
|
+
end
|
172
|
+
elsif subject[property]
|
173
|
+
# check if subject already has value if duplicates not allowed
|
174
|
+
_has_value = !allow_duplicate && has_value?(subject, property, value)
|
174
175
|
|
175
|
-
|
176
|
-
|
177
|
-
|
176
|
+
# make property an array if value not present or always an array
|
177
|
+
if !subject[property].is_a?(Array) && (!_has_value || property_is_array)
|
178
|
+
subject[property] =
|
179
|
+
[subject[property]]
|
180
|
+
end
|
181
|
+
subject[property] << value unless _has_value
|
182
|
+
else
|
183
|
+
subject[property] = property_is_array ? [value] : value
|
178
184
|
end
|
179
|
-
subject[property] << value unless _has_value
|
180
|
-
else
|
181
|
-
subject[property] = property_is_array ? [value] : value
|
182
185
|
end
|
183
|
-
end
|
184
186
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
187
|
+
# Returns True if the given subject has the given property.
|
188
|
+
#
|
189
|
+
# @param subject the subject to check.
|
190
|
+
# @param property the property to look for.
|
191
|
+
#
|
192
|
+
# @return [Boolean] true if the subject has the given property, false if not.
|
193
|
+
def property?(subject, property)
|
194
|
+
return false unless (value = subject[property])
|
195
|
+
|
196
|
+
!value.is_a?(Array) || !value.empty?
|
197
|
+
end
|
195
198
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
199
|
+
# Determines if the given value is a property of the given subject.
|
200
|
+
#
|
201
|
+
# @param [Hash] subject the subject to check.
|
202
|
+
# @param [String] property the property to check.
|
203
|
+
# @param [Object] value the value to check.
|
204
|
+
#
|
205
|
+
# @return [Boolean] true if the value exists, false if not.
|
206
|
+
def has_value?(subject, property, value)
|
207
|
+
if property?(subject, property)
|
208
|
+
val = subject[property]
|
209
|
+
is_list = list?(val)
|
210
|
+
if val.is_a?(Array) || is_list
|
211
|
+
val = val['@list'] if is_list
|
212
|
+
val.any? { |v| compare_values(value, v) }
|
213
|
+
elsif !val.is_a?(Array)
|
214
|
+
compare_values(value, val)
|
215
|
+
else
|
216
|
+
false
|
217
|
+
end
|
212
218
|
else
|
213
219
|
false
|
214
220
|
end
|
215
|
-
else
|
216
|
-
false
|
217
221
|
end
|
218
|
-
end
|
219
222
|
|
220
|
-
|
221
|
-
|
223
|
+
private
|
224
|
+
|
225
|
+
UTIL_GRAPH_KEYS = %w[@context @id @index].freeze
|
226
|
+
|
227
|
+
# Merge the last value into an array based for the specified key if hash is not null and value is not already in that array
|
228
|
+
def merge_value(hash, key, value)
|
229
|
+
return unless hash
|
222
230
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
values
|
229
|
-
|
230
|
-
|
231
|
-
elsif !values.include?(value)
|
232
|
-
values << value
|
231
|
+
values = hash[key] ||= []
|
232
|
+
if key == '@list'
|
233
|
+
values << value
|
234
|
+
elsif list?(value)
|
235
|
+
values << value
|
236
|
+
elsif !values.include?(value)
|
237
|
+
values << value
|
238
|
+
end
|
233
239
|
end
|
234
240
|
end
|
235
|
-
end
|
236
241
|
|
237
|
-
##
|
238
|
-
# Utility class for mapping old blank node identifiers, or unnamed blank
|
239
|
-
# nodes to new identifiers
|
240
|
-
class BlankNodeMapper < Hash
|
241
242
|
##
|
242
|
-
#
|
243
|
-
#
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
old
|
249
|
-
|
243
|
+
# Utility class for mapping old blank node identifiers, or unnamed blank
|
244
|
+
# nodes to new identifiers
|
245
|
+
class BlankNodeMapper < Hash
|
246
|
+
##
|
247
|
+
# Just return a Blank Node based on `old`. Manufactures
|
248
|
+
# a node if `old` is nil or empty
|
249
|
+
# @param [String] old ("")
|
250
|
+
# @return [String]
|
251
|
+
def get_sym(old = "")
|
252
|
+
old = RDF::Node.new.to_s if old.to_s.empty?
|
253
|
+
old.to_s.sub(/_:/, '')
|
254
|
+
end
|
250
255
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
256
|
+
##
|
257
|
+
# Get a new mapped name for `old`
|
258
|
+
#
|
259
|
+
# @param [String] old ("")
|
260
|
+
# @return [String]
|
261
|
+
def get_name(old = "")
|
262
|
+
"_:" + get_sym(old)
|
263
|
+
end
|
258
264
|
end
|
259
|
-
end
|
260
265
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
266
|
+
class BlankNodeUniqer < BlankNodeMapper
|
267
|
+
##
|
268
|
+
# Use the uniquely generated bnodes, rather than a sequence
|
269
|
+
# @param [String] old ("")
|
270
|
+
# @return [String]
|
271
|
+
def get_sym(old = "")
|
272
|
+
old = old.to_s.sub(/_:/, '')
|
273
|
+
if old && key?(old)
|
274
|
+
self[old]
|
275
|
+
elsif !old.empty?
|
276
|
+
self[old] = RDF::Node.new.to_unique_base[2..]
|
277
|
+
else
|
278
|
+
RDF::Node.new.to_unique_base[2..]
|
279
|
+
end
|
274
280
|
end
|
275
281
|
end
|
276
|
-
end
|
277
282
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
283
|
+
class BlankNodeNamer < BlankNodeMapper
|
284
|
+
# @param [String] prefix
|
285
|
+
def initialize(prefix)
|
286
|
+
@prefix = prefix.to_s
|
287
|
+
@num = 0
|
288
|
+
super
|
289
|
+
end
|
285
290
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
291
|
+
##
|
292
|
+
# Get a new symbol mapped from `old`
|
293
|
+
# @param [String] old ("")
|
294
|
+
# @return [String]
|
295
|
+
def get_sym(old = "")
|
296
|
+
old = old.to_s.sub(/_:/, '')
|
297
|
+
if !old.empty? && key?(old)
|
298
|
+
self[old]
|
299
|
+
elsif !old.empty?
|
300
|
+
@num += 1
|
301
|
+
# puts "allocate #{@prefix + (@num - 1).to_s} to #{old.inspect}"
|
302
|
+
self[old] = @prefix + (@num - 1).to_s
|
303
|
+
else
|
304
|
+
# Not referenced, just return a new unique value
|
305
|
+
@num += 1
|
306
|
+
# puts "allocate #{@prefix + (@num - 1).to_s} to #{old.inspect}"
|
307
|
+
@prefix + (@num - 1).to_s
|
308
|
+
end
|
303
309
|
end
|
304
310
|
end
|
305
311
|
end
|
data/lib/json/ld/version.rb
CHANGED
@@ -1,20 +1,30 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
# frozen_string_literal: true
|
3
|
-
module JSON::LD::VERSION
|
4
|
-
VERSION_FILE = File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "VERSION")
|
5
|
-
MAJOR, MINOR, TINY, EXTRA = File.read(VERSION_FILE).chomp.split(".")
|
6
2
|
|
7
|
-
|
3
|
+
module JSON
|
4
|
+
module LD
|
5
|
+
module VERSION
|
6
|
+
VERSION_FILE = File.join(__dir__, "..", "..", "..", "VERSION")
|
7
|
+
MAJOR, MINOR, TINY, EXTRA = File.read(VERSION_FILE).chomp.split(".")
|
8
8
|
|
9
|
-
|
10
|
-
# @return [String]
|
11
|
-
def self.to_s() STRING end
|
9
|
+
STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
##
|
12
|
+
# @return [String]
|
13
|
+
def self.to_s
|
14
|
+
STRING
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
##
|
18
|
+
# @return [String]
|
19
|
+
def self.to_str
|
20
|
+
STRING
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# @return [Array(Integer, Integer, Integer)]
|
25
|
+
def self.to_a
|
26
|
+
STRING.split(".")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
20
30
|
end
|