json-ld 3.1.7 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/VERSION +1 -1
- data/bin/jsonld +3 -3
- data/lib/json/ld.rb +3 -1
- data/lib/json/ld/api.rb +22 -14
- data/lib/json/ld/compact.rb +3 -3
- data/lib/json/ld/context.rb +44 -44
- data/lib/json/ld/expand.rb +46 -8
- data/lib/json/ld/extensions.rb +4 -4
- data/lib/json/ld/flatten.rb +92 -9
- data/lib/json/ld/format.rb +1 -1
- data/lib/json/ld/frame.rb +8 -8
- data/lib/json/ld/from_rdf.rb +2 -2
- data/lib/json/ld/reader.rb +1 -0
- data/lib/json/ld/streaming_reader.rb +5 -5
- data/lib/json/ld/streaming_writer.rb +4 -4
- data/lib/json/ld/to_rdf.rb +2 -2
- data/lib/json/ld/utils.rb +13 -13
- data/lib/json/ld/writer.rb +2 -2
- data/spec/api_spec.rb +1 -1
- data/spec/compact_spec.rb +1 -1
- data/spec/expand_spec.rb +384 -1
- data/spec/flatten_spec.rb +517 -1
- data/spec/rdfstar_spec.rb +25 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/suite_flatten_spec.rb +4 -0
- data/spec/suite_frame_spec.rb +7 -0
- data/spec/suite_helper.rb +13 -7
- data/spec/to_rdf_spec.rb +3 -3
- metadata +63 -61
@@ -64,8 +64,8 @@ module JSON::LD
|
|
64
64
|
{"@value" => MultiJson.load(statement.object.to_s), "@type" => "@json"}
|
65
65
|
else
|
66
66
|
lit = {"@value" => statement.object.to_s}
|
67
|
-
lit["@type"] = statement.object.datatype.to_s if statement.object.
|
68
|
-
lit["@language"] = statement.object.language.to_s if statement.object.
|
67
|
+
lit["@type"] = statement.object.datatype.to_s if statement.object.datatype?
|
68
|
+
lit["@language"] = statement.object.language.to_s if statement.object.language?
|
69
69
|
lit
|
70
70
|
end
|
71
71
|
end
|
@@ -91,7 +91,7 @@ module JSON::LD
|
|
91
91
|
def start_graph(resource)
|
92
92
|
#log_debug("start_graph") {"state: #{@state.inspect}, resource: #{resource}"}
|
93
93
|
if resource
|
94
|
-
@output.puts(",") if
|
94
|
+
@output.puts(",") if %i(wrote_node wrote_graph).include?(@state)
|
95
95
|
@output.puts %({"@id": "#{resource}", "@graph": [)
|
96
96
|
@state = :in_graph
|
97
97
|
end
|
@@ -109,7 +109,7 @@ module JSON::LD
|
|
109
109
|
|
110
110
|
def end_node
|
111
111
|
#log_debug("end_node") {"state: #{@state.inspect}, node: #{@current_node_def.to_json}"}
|
112
|
-
@output.puts(",") if
|
112
|
+
@output.puts(",") if %i(wrote_node wrote_graph).include?(@state)
|
113
113
|
if @current_node_def
|
114
114
|
node_def = if context
|
115
115
|
compacted = JSON::LD::API.compact(@current_node_def, context, rename_bnodes: false, **@options)
|
data/lib/json/ld/to_rdf.rb
CHANGED
@@ -48,7 +48,7 @@ module JSON::LD
|
|
48
48
|
# Only valid for rdf:JSON
|
49
49
|
value = value.to_json_c14n
|
50
50
|
else
|
51
|
-
if item.
|
51
|
+
if item.key?('@direction') && @options[:rdfDirection]
|
52
52
|
# Either serialize using a datatype, or a compound-literal
|
53
53
|
case @options[:rdfDirection]
|
54
54
|
when 'i18n-datatype'
|
@@ -63,7 +63,7 @@ module JSON::LD
|
|
63
63
|
end
|
64
64
|
|
65
65
|
# Otherwise, if datatype is null, set it to xsd:string or xsd:langString, depending on if item has a @language key.
|
66
|
-
datatype ||= item.
|
66
|
+
datatype ||= item.key?('@language') ? RDF.langString : RDF::XSD.string
|
67
67
|
if datatype == RDF::URI(RDF.to_uri + "JSON")
|
68
68
|
value = value.to_json_c14n
|
69
69
|
end
|
data/lib/json/ld/utils.rb
CHANGED
@@ -11,8 +11,8 @@ module JSON::LD
|
|
11
11
|
# @return [Boolean]
|
12
12
|
def node?(value)
|
13
13
|
value.is_a?(Hash) &&
|
14
|
-
!(value.
|
15
|
-
(value.length > 1 || !value.
|
14
|
+
!(value.key?('@value') || value.key?('@list') || value.key?('@set')) &&
|
15
|
+
(value.length > 1 || !value.key?('@id'))
|
16
16
|
end
|
17
17
|
|
18
18
|
##
|
@@ -29,7 +29,7 @@ module JSON::LD
|
|
29
29
|
# @return [Boolean]
|
30
30
|
def node_or_ref?(value)
|
31
31
|
value.is_a?(Hash) &&
|
32
|
-
!(value.
|
32
|
+
!(value.key?('@value') || value.key?('@list') || value.key?('@set'))
|
33
33
|
end
|
34
34
|
|
35
35
|
##
|
@@ -66,7 +66,7 @@ module JSON::LD
|
|
66
66
|
# @param [Object] value
|
67
67
|
# @return [Boolean]
|
68
68
|
def simple_graph?(value)
|
69
|
-
graph?(value) && !value.
|
69
|
+
graph?(value) && !value.key?('@id')
|
70
70
|
end
|
71
71
|
|
72
72
|
##
|
@@ -75,7 +75,7 @@ module JSON::LD
|
|
75
75
|
# @param [Object] value
|
76
76
|
# @return [Boolean]
|
77
77
|
def list?(value)
|
78
|
-
value.is_a?(Hash) && value.
|
78
|
+
value.is_a?(Hash) && value.key?('@list')
|
79
79
|
end
|
80
80
|
|
81
81
|
##
|
@@ -84,7 +84,7 @@ module JSON::LD
|
|
84
84
|
# @param [Object] value
|
85
85
|
# @return [Boolean]
|
86
86
|
def index?(value)
|
87
|
-
value.is_a?(Hash) && value.
|
87
|
+
value.is_a?(Hash) && value.key?('@index')
|
88
88
|
end
|
89
89
|
|
90
90
|
##
|
@@ -93,7 +93,7 @@ module JSON::LD
|
|
93
93
|
# @param [Object] value
|
94
94
|
# @return [Boolean]
|
95
95
|
def value?(value)
|
96
|
-
value.is_a?(Hash) && value.
|
96
|
+
value.is_a?(Hash) && value.key?('@value')
|
97
97
|
end
|
98
98
|
|
99
99
|
##
|
@@ -170,7 +170,7 @@ module JSON::LD
|
|
170
170
|
end
|
171
171
|
elsif subject[property]
|
172
172
|
# check if subject already has value if duplicates not allowed
|
173
|
-
_has_value = !allow_duplicate && has_value(subject, property, value)
|
173
|
+
_has_value = !allow_duplicate && has_value?(subject, property, value)
|
174
174
|
|
175
175
|
# make property an array if value not present or always an array
|
176
176
|
if !subject[property].is_a?(Array) && (!_has_value || property_is_array)
|
@@ -188,7 +188,7 @@ module JSON::LD
|
|
188
188
|
# @param property the property to look for.
|
189
189
|
#
|
190
190
|
# @return [Boolean] true if the subject has the given property, false if not.
|
191
|
-
def
|
191
|
+
def property?(subject, property)
|
192
192
|
return false unless value = subject[property]
|
193
193
|
!value.is_a?(Array) || !value.empty?
|
194
194
|
end
|
@@ -200,8 +200,8 @@ module JSON::LD
|
|
200
200
|
# @param [Object] value the value to check.
|
201
201
|
#
|
202
202
|
# @return [Boolean] true if the value exists, false if not.
|
203
|
-
def has_value(subject, property, value)
|
204
|
-
if
|
203
|
+
def has_value?(subject, property, value)
|
204
|
+
if property?(subject, property)
|
205
205
|
val = subject[property]
|
206
206
|
is_list = list?(val)
|
207
207
|
if val.is_a?(Array) || is_list
|
@@ -265,7 +265,7 @@ module JSON::LD
|
|
265
265
|
# @return [String]
|
266
266
|
def get_sym(old = "")
|
267
267
|
old = old.to_s.sub(/_:/, '')
|
268
|
-
if old && self.
|
268
|
+
if old && self.key?(old)
|
269
269
|
self[old]
|
270
270
|
elsif !old.empty?
|
271
271
|
self[old] = RDF::Node.new.to_unique_base[2..-1]
|
@@ -289,7 +289,7 @@ module JSON::LD
|
|
289
289
|
# @return [String]
|
290
290
|
def get_sym(old = "")
|
291
291
|
old = old.to_s.sub(/_:/, '')
|
292
|
-
if !old.empty? && self.
|
292
|
+
if !old.empty? && self.key?(old)
|
293
293
|
self[old]
|
294
294
|
elsif !old.empty?
|
295
295
|
@num += 1
|
data/lib/json/ld/writer.rb
CHANGED
@@ -237,8 +237,8 @@ module JSON::LD
|
|
237
237
|
# @yield [writer]
|
238
238
|
# @yieldparam [RDF::Writer] writer
|
239
239
|
def initialize(output = $stdout, **options, &block)
|
240
|
-
options[:base_uri] ||= options[:base] if options.
|
241
|
-
options[:base] ||= options[:base_uri] if options.
|
240
|
+
options[:base_uri] ||= options[:base] if options.key?(:base)
|
241
|
+
options[:base] ||= options[:base_uri] if options.key?(:base_uri)
|
242
242
|
super do
|
243
243
|
@repo = RDF::Repository.new
|
244
244
|
|
data/spec/api_spec.rb
CHANGED
@@ -44,7 +44,7 @@ describe JSON::LD::API do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
context "Test Files" do
|
47
|
-
%
|
47
|
+
%i(oj json_gem ok_json yajl).each do |adapter|
|
48
48
|
context "with MultiJson adapter #{adapter.inspect}" do
|
49
49
|
Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), 'test-files/*-input.*'))) do |filename|
|
50
50
|
test = File.basename(filename).sub(/-input\..*$/, '')
|
data/spec/compact_spec.rb
CHANGED
@@ -3389,7 +3389,7 @@ describe JSON::LD::API do
|
|
3389
3389
|
input = ::JSON.parse(input) if input.is_a?(String)
|
3390
3390
|
output = ::JSON.parse(output) if output.is_a?(String)
|
3391
3391
|
context = ::JSON.parse(context) if context.is_a?(String)
|
3392
|
-
context = context['@context'] if context.
|
3392
|
+
context = context['@context'] if context.key?('@context')
|
3393
3393
|
pending params.fetch(:pending, "test implementation") unless input
|
3394
3394
|
if params[:exception]
|
3395
3395
|
expect {JSON::LD::API.compact(input, context, logger: logger, **params)}.to raise_error(params[:exception])
|
data/spec/expand_spec.rb
CHANGED
@@ -3371,6 +3371,43 @@ describe JSON::LD::API do
|
|
3371
3371
|
}),
|
3372
3372
|
exception: JSON::LD::JsonLdError::InvalidReversePropertyMap,
|
3373
3373
|
},
|
3374
|
+
"Explicit and implicit @reverse in same object": {
|
3375
|
+
input: %({
|
3376
|
+
"@context": {
|
3377
|
+
"fooOf": {"@reverse": "ex:foo", "@type": "@id"}
|
3378
|
+
},
|
3379
|
+
"@id": "ex:s",
|
3380
|
+
"fooOf": "ex:o1",
|
3381
|
+
"@reverse": {
|
3382
|
+
"ex:bar": {"@id": "ex:o2"}
|
3383
|
+
}
|
3384
|
+
}),
|
3385
|
+
output: %([{
|
3386
|
+
"@id": "ex:s",
|
3387
|
+
"@reverse": {
|
3388
|
+
"ex:bar": [{"@id": "ex:o2"}],
|
3389
|
+
"ex:foo": [{"@id": "ex:o1"}]
|
3390
|
+
}
|
3391
|
+
}])
|
3392
|
+
},
|
3393
|
+
"Two properties both with @reverse": {
|
3394
|
+
input: %({
|
3395
|
+
"@context": {
|
3396
|
+
"fooOf": {"@reverse": "ex:foo", "@type": "@id"},
|
3397
|
+
"barOf": {"@reverse": "ex:bar", "@type": "@id"}
|
3398
|
+
},
|
3399
|
+
"@id": "ex:s",
|
3400
|
+
"fooOf": "ex:o1",
|
3401
|
+
"barOf": "ex:o2"
|
3402
|
+
}),
|
3403
|
+
output: %([{
|
3404
|
+
"@id": "ex:s",
|
3405
|
+
"@reverse": {
|
3406
|
+
"ex:bar": [{"@id": "ex:o2"}],
|
3407
|
+
"ex:foo": [{"@id": "ex:o1"}]
|
3408
|
+
}
|
3409
|
+
}])
|
3410
|
+
},
|
3374
3411
|
}.each do |title, params|
|
3375
3412
|
it(title) {run_expand params}
|
3376
3413
|
end
|
@@ -3388,6 +3425,36 @@ describe JSON::LD::API do
|
|
3388
3425
|
}),
|
3389
3426
|
exception: JSON::LD::JsonLdError::InvalidIdValue
|
3390
3427
|
},
|
3428
|
+
"node object with @annotation property is ignored without rdfstar option": {
|
3429
|
+
input: %({
|
3430
|
+
"@id": "ex:bob",
|
3431
|
+
"ex:knows": {
|
3432
|
+
"@id": "ex:fred",
|
3433
|
+
"@annotation": {
|
3434
|
+
"ex:certainty": 0.8
|
3435
|
+
}
|
3436
|
+
}
|
3437
|
+
}),
|
3438
|
+
output: %([{
|
3439
|
+
"@id": "ex:bob",
|
3440
|
+
"ex:knows": [{"@id": "ex:fred"}]
|
3441
|
+
}])
|
3442
|
+
},
|
3443
|
+
"value object with @annotation property is ignored without rdfstar option": {
|
3444
|
+
input: %({
|
3445
|
+
"@id": "ex:bob",
|
3446
|
+
"ex:age": {
|
3447
|
+
"@value": 23,
|
3448
|
+
"@annotation": {
|
3449
|
+
"ex:certainty": 0.8
|
3450
|
+
}
|
3451
|
+
}
|
3452
|
+
}),
|
3453
|
+
output: %([{
|
3454
|
+
"@id": "ex:bob",
|
3455
|
+
"ex:age": [{"@value": 23}]
|
3456
|
+
}])
|
3457
|
+
},
|
3391
3458
|
}.each do |title, params|
|
3392
3459
|
it(title) {run_expand params}
|
3393
3460
|
end
|
@@ -3569,7 +3636,7 @@ describe JSON::LD::API do
|
|
3569
3636
|
}]
|
3570
3637
|
}])
|
3571
3638
|
},
|
3572
|
-
"
|
3639
|
+
"node with embedded object having properties": {
|
3573
3640
|
input: %({
|
3574
3641
|
"@id": "ex:subj",
|
3575
3642
|
"ex:value": {
|
@@ -3619,6 +3686,322 @@ describe JSON::LD::API do
|
|
3619
3686
|
}]
|
3620
3687
|
}])
|
3621
3688
|
},
|
3689
|
+
"node with @annotation property on value object": {
|
3690
|
+
input: %({
|
3691
|
+
"@id": "ex:bob",
|
3692
|
+
"ex:age": {
|
3693
|
+
"@value": 23,
|
3694
|
+
"@annotation": {"ex:certainty": 0.8}
|
3695
|
+
}
|
3696
|
+
}),
|
3697
|
+
output: %([{
|
3698
|
+
"@id": "ex:bob",
|
3699
|
+
"ex:age": [{
|
3700
|
+
"@value": 23,
|
3701
|
+
"@annotation": [{"ex:certainty": [{"@value": 0.8}]}]
|
3702
|
+
}]
|
3703
|
+
}])
|
3704
|
+
},
|
3705
|
+
"node with @annotation property on node object": {
|
3706
|
+
input: %({
|
3707
|
+
"@id": "ex:bob",
|
3708
|
+
"ex:name": "Bob",
|
3709
|
+
"ex:knows": {
|
3710
|
+
"@id": "ex:fred",
|
3711
|
+
"ex:name": "Fred",
|
3712
|
+
"@annotation": {"ex:certainty": 0.8}
|
3713
|
+
}
|
3714
|
+
}),
|
3715
|
+
output: %([{
|
3716
|
+
"@id": "ex:bob",
|
3717
|
+
"ex:name": [{"@value": "Bob"}],
|
3718
|
+
"ex:knows": [{
|
3719
|
+
"@id": "ex:fred",
|
3720
|
+
"ex:name": [{"@value": "Fred"}],
|
3721
|
+
"@annotation": [{"ex:certainty": [{"@value": 0.8}]}]
|
3722
|
+
}]
|
3723
|
+
}])
|
3724
|
+
},
|
3725
|
+
"node with @annotation property multiple values": {
|
3726
|
+
input: %({
|
3727
|
+
"@id": "ex:bob",
|
3728
|
+
"ex:name": "Bob",
|
3729
|
+
"ex:knows": {
|
3730
|
+
"@id": "ex:fred",
|
3731
|
+
"ex:name": "Fred",
|
3732
|
+
"@annotation": [{
|
3733
|
+
"ex:certainty": 0.8
|
3734
|
+
}, {
|
3735
|
+
"ex:source": {"@id": "http://example.org/"}
|
3736
|
+
}]
|
3737
|
+
}
|
3738
|
+
}),
|
3739
|
+
output: %([{
|
3740
|
+
"@id": "ex:bob",
|
3741
|
+
"ex:name": [{"@value": "Bob"}],
|
3742
|
+
"ex:knows": [{
|
3743
|
+
"@id": "ex:fred",
|
3744
|
+
"ex:name": [{"@value": "Fred"}],
|
3745
|
+
"@annotation": [{
|
3746
|
+
"ex:certainty": [{"@value": 0.8}]
|
3747
|
+
}, {
|
3748
|
+
"ex:source": [{"@id": "http://example.org/"}]
|
3749
|
+
}]
|
3750
|
+
}]
|
3751
|
+
}])
|
3752
|
+
},
|
3753
|
+
"node with @annotation property that is on the top-level is invalid": {
|
3754
|
+
input: %({
|
3755
|
+
"@id": "ex:bob",
|
3756
|
+
"ex:name": "Bob",
|
3757
|
+
"@annotation": {"ex:prop": "value2"}
|
3758
|
+
}),
|
3759
|
+
exception: JSON::LD::JsonLdError::InvalidAnnotation
|
3760
|
+
},
|
3761
|
+
"node with @annotation property on a top-level graph node is invalid": {
|
3762
|
+
input: %({
|
3763
|
+
"@id": "ex:bob",
|
3764
|
+
"ex:name": "Bob",
|
3765
|
+
"@graph": {
|
3766
|
+
"@id": "ex:fred",
|
3767
|
+
"ex:name": "Fred",
|
3768
|
+
"@annotation": {"ex:prop": "value2"}
|
3769
|
+
}
|
3770
|
+
}),
|
3771
|
+
exception: JSON::LD::JsonLdError::InvalidAnnotation
|
3772
|
+
},
|
3773
|
+
"node with @annotation property having @id is invalid": {
|
3774
|
+
input: %({
|
3775
|
+
"@id": "ex:bob",
|
3776
|
+
"ex:knows": {
|
3777
|
+
"@id": "ex:fred",
|
3778
|
+
"@annotation": {
|
3779
|
+
"@id": "ex:invalid-ann-id",
|
3780
|
+
"ex:prop": "value2"
|
3781
|
+
}
|
3782
|
+
}
|
3783
|
+
}),
|
3784
|
+
exception: JSON::LD::JsonLdError::InvalidAnnotation
|
3785
|
+
},
|
3786
|
+
"node with @annotation property with value object value is invalid": {
|
3787
|
+
input: %({
|
3788
|
+
"@id": "ex:bob",
|
3789
|
+
"ex:knows": {
|
3790
|
+
"@id": "fred",
|
3791
|
+
"@annotation": "value2"
|
3792
|
+
}
|
3793
|
+
}),
|
3794
|
+
exception: JSON::LD::JsonLdError::InvalidAnnotation
|
3795
|
+
},
|
3796
|
+
"node with @annotation on a list": {
|
3797
|
+
input: %({
|
3798
|
+
"@id": "ex:bob",
|
3799
|
+
"ex:knows": {
|
3800
|
+
"@list": [{"@id": "ex:fred"}],
|
3801
|
+
"@annotation": {"ex:prop": "value2"}
|
3802
|
+
}
|
3803
|
+
}),
|
3804
|
+
exception: JSON::LD::JsonLdError::InvalidSetOrListObject
|
3805
|
+
},
|
3806
|
+
"node with @annotation on a list value": {
|
3807
|
+
input: %({
|
3808
|
+
"@id": "ex:bob",
|
3809
|
+
"ex:knows": {
|
3810
|
+
"@list": [
|
3811
|
+
{
|
3812
|
+
"@id": "ex:fred",
|
3813
|
+
"@annotation": {"ex:prop": "value2"}
|
3814
|
+
}
|
3815
|
+
]
|
3816
|
+
}
|
3817
|
+
}),
|
3818
|
+
exception: JSON::LD::JsonLdError::InvalidAnnotation
|
3819
|
+
},
|
3820
|
+
"node with @annotation property on a top-level @included node is invalid": {
|
3821
|
+
input: %({
|
3822
|
+
"@id": "ex:bob",
|
3823
|
+
"ex:name": "Bob",
|
3824
|
+
"@included": [{
|
3825
|
+
"@id": "ex:fred",
|
3826
|
+
"ex:name": "Fred",
|
3827
|
+
"@annotation": {"ex:prop": "value2"}
|
3828
|
+
}]
|
3829
|
+
}),
|
3830
|
+
exception: JSON::LD::JsonLdError::InvalidAnnotation
|
3831
|
+
},
|
3832
|
+
"node with @annotation property on embedded subject": {
|
3833
|
+
input: %({
|
3834
|
+
"@id": {
|
3835
|
+
"@id": "ex:rei",
|
3836
|
+
"ex:prop": {"@id": "_:value"}
|
3837
|
+
},
|
3838
|
+
"ex:prop": {
|
3839
|
+
"@value": "value2",
|
3840
|
+
"@annotation": {"ex:certainty": 0.8}
|
3841
|
+
}
|
3842
|
+
}),
|
3843
|
+
output: %([{
|
3844
|
+
"@id": {
|
3845
|
+
"@id": "ex:rei",
|
3846
|
+
"ex:prop": [{"@id": "_:value"}]
|
3847
|
+
},
|
3848
|
+
"ex:prop": [{
|
3849
|
+
"@value": "value2",
|
3850
|
+
"@annotation": [{
|
3851
|
+
"ex:certainty": [{"@value": 0.8}]
|
3852
|
+
}]
|
3853
|
+
}]
|
3854
|
+
}])
|
3855
|
+
},
|
3856
|
+
"node with @annotation property on embedded object": {
|
3857
|
+
input: %({
|
3858
|
+
"@id": "ex:subj",
|
3859
|
+
"ex:value": {
|
3860
|
+
"@id": {
|
3861
|
+
"@id": "ex:rei",
|
3862
|
+
"ex:prop": "value"
|
3863
|
+
},
|
3864
|
+
"@annotation": {"ex:certainty": 0.8}
|
3865
|
+
}
|
3866
|
+
}),
|
3867
|
+
output: %([{
|
3868
|
+
"@id": "ex:subj",
|
3869
|
+
"ex:value": [{
|
3870
|
+
"@id": {
|
3871
|
+
"@id": "ex:rei",
|
3872
|
+
"ex:prop": [{"@value": "value"}]
|
3873
|
+
},
|
3874
|
+
"@annotation": [{
|
3875
|
+
"ex:certainty": [{"@value": 0.8}]
|
3876
|
+
}]
|
3877
|
+
}]
|
3878
|
+
}])
|
3879
|
+
},
|
3880
|
+
"embedded node with reverse relationship": {
|
3881
|
+
input: %({
|
3882
|
+
"@context": {
|
3883
|
+
"rel": {"@reverse": "ex:rel"}
|
3884
|
+
},
|
3885
|
+
"@id": {
|
3886
|
+
"@id": "ex:rei",
|
3887
|
+
"rel": {"@id": "ex:value"}
|
3888
|
+
},
|
3889
|
+
"ex:prop": "value2"
|
3890
|
+
}),
|
3891
|
+
exception: JSON::LD::JsonLdError::InvalidEmbeddedNode
|
3892
|
+
},
|
3893
|
+
"embedded node with expanded reverse relationship": {
|
3894
|
+
input: %({
|
3895
|
+
"@id": {
|
3896
|
+
"@id": "ex:rei",
|
3897
|
+
"@reverse": {
|
3898
|
+
"ex:rel": {"@id": "ex:value"}
|
3899
|
+
}
|
3900
|
+
},
|
3901
|
+
"ex:prop": "value2"
|
3902
|
+
}),
|
3903
|
+
exception: JSON::LD::JsonLdError::InvalidEmbeddedNode
|
3904
|
+
},
|
3905
|
+
"embedded node used as subject in reverse relationship": {
|
3906
|
+
input: %({
|
3907
|
+
"@context": {
|
3908
|
+
"rel": {"@reverse": "ex:rel"}
|
3909
|
+
},
|
3910
|
+
"@id": {
|
3911
|
+
"@id": "ex:rei",
|
3912
|
+
"ex:prop": {"@id": "ex:value"}
|
3913
|
+
},
|
3914
|
+
"rel": {"@id": "ex:value2"}
|
3915
|
+
}),
|
3916
|
+
output: %([{
|
3917
|
+
"@id": {
|
3918
|
+
"@id": "ex:rei",
|
3919
|
+
"ex:prop": [{"@id": "ex:value"}]
|
3920
|
+
},
|
3921
|
+
"@reverse": {
|
3922
|
+
"ex:rel": [{"@id": "ex:value2"}]
|
3923
|
+
}
|
3924
|
+
}])
|
3925
|
+
},
|
3926
|
+
"embedded node used as object in reverse relationship": {
|
3927
|
+
input: %({
|
3928
|
+
"@context": {
|
3929
|
+
"rel": {"@reverse": "ex:rel"}
|
3930
|
+
},
|
3931
|
+
"@id": "ex:subj",
|
3932
|
+
"rel": {
|
3933
|
+
"@id": {
|
3934
|
+
"@id": "ex:rei",
|
3935
|
+
"ex:prop": {"@id": "ex:value"}
|
3936
|
+
},
|
3937
|
+
"ex:prop": {"@id": "ex:value2"}
|
3938
|
+
}
|
3939
|
+
}),
|
3940
|
+
output: %([{
|
3941
|
+
"@id": "ex:subj",
|
3942
|
+
"@reverse": {
|
3943
|
+
"ex:rel": [{
|
3944
|
+
"@id": {
|
3945
|
+
"@id": "ex:rei",
|
3946
|
+
"ex:prop": [{"@id": "ex:value"}]
|
3947
|
+
},
|
3948
|
+
"ex:prop": [{"@id": "ex:value2"}]
|
3949
|
+
}]
|
3950
|
+
}
|
3951
|
+
}])
|
3952
|
+
},
|
3953
|
+
"node with @annotation property on node object with reverse relationship": {
|
3954
|
+
input: %({
|
3955
|
+
"@context": {
|
3956
|
+
"knownBy": {"@reverse": "ex:knows"}
|
3957
|
+
},
|
3958
|
+
"@id": "ex:bob",
|
3959
|
+
"ex:name": "Bob",
|
3960
|
+
"knownBy": {
|
3961
|
+
"@id": "ex:fred",
|
3962
|
+
"ex:name": "Fred",
|
3963
|
+
"@annotation": {"ex:certainty": 0.8}
|
3964
|
+
}
|
3965
|
+
}),
|
3966
|
+
output: %([{
|
3967
|
+
"@id": "ex:bob",
|
3968
|
+
"ex:name": [{"@value": "Bob"}],
|
3969
|
+
"@reverse": {
|
3970
|
+
"ex:knows": [{
|
3971
|
+
"@id": "ex:fred",
|
3972
|
+
"ex:name": [{"@value": "Fred"}],
|
3973
|
+
"@annotation": [{"ex:certainty": [{"@value": 0.8}]}]
|
3974
|
+
}]
|
3975
|
+
}
|
3976
|
+
}])
|
3977
|
+
},
|
3978
|
+
"reverse relationship inside annotation": {
|
3979
|
+
input: %({
|
3980
|
+
"@context": {
|
3981
|
+
"claims": {"@reverse": "ex:claims", "@type": "@id"}
|
3982
|
+
},
|
3983
|
+
"@id": "ex:bob",
|
3984
|
+
"ex:knows": {
|
3985
|
+
"@id": "ex:jane",
|
3986
|
+
"@annotation": {
|
3987
|
+
"ex:certainty": 0.8,
|
3988
|
+
"claims": "ex:sue"
|
3989
|
+
}
|
3990
|
+
}
|
3991
|
+
}),
|
3992
|
+
output: %([{
|
3993
|
+
"@id": "ex:bob",
|
3994
|
+
"ex:knows": [{
|
3995
|
+
"@id": "ex:jane",
|
3996
|
+
"@annotation": [{
|
3997
|
+
"ex:certainty": [{"@value": 0.8}],
|
3998
|
+
"@reverse": {
|
3999
|
+
"ex:claims": [{"@id": "ex:sue"}]
|
4000
|
+
}
|
4001
|
+
}]
|
4002
|
+
}]
|
4003
|
+
}])
|
4004
|
+
},
|
3622
4005
|
}.each do |title, params|
|
3623
4006
|
it(title) {run_expand params.merge(rdfstar: true)}
|
3624
4007
|
end
|