Skip to content

Commit 2c7d988

Browse files
committedJan 24, 2021
Minor correction on annotation expansion.
1 parent 15adaca commit 2c7d988

File tree

4 files changed

+138
-2
lines changed

4 files changed

+138
-2
lines changed
 

‎.coveralls.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
repo_token: EUv9wY2KnN7lYmiGWUFhEKH73Ndwtok1A

‎Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source "https://rubygems.org"
2-
gem "nokogiri", '~> 1.8'
2+
gem "nokogiri", '~> 1.10'
33
gem "nokogumbo", platforms: :mri
44

55
gemspec

‎lib/json/ld/expand.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def expand_object(input, active_property, context, output_object,
297297
[{}]
298298
elsif @options[:rdfstar]
299299
# Result must have just a single statement
300-
rei_node = expand(value, active_property, context, log_depth: log_depth.to_i + 1)
300+
rei_node = expand(value, nil, context, log_depth: log_depth.to_i + 1)
301301
statements = to_enum(:item_to_rdf, rei_node)
302302
raise JsonLdError::InvalidEmbeddedNode,
303303
"Embedded node with #{statements.size} statements" unless

‎spec/expand_spec.rb

+135
Original file line numberDiff line numberDiff line change
@@ -3840,6 +3840,141 @@
38403840
}]
38413841
}])
38423842
},
3843+
"embedded node with reverse relationship": {
3844+
input: %({
3845+
"@context": {
3846+
"rel": {"@reverse": "ex:rel"}
3847+
},
3848+
"@id": {
3849+
"@id": "ex:rei",
3850+
"rel": {"@id": "ex:value"}
3851+
},
3852+
"ex:prop": "value2"
3853+
}),
3854+
output: %([{
3855+
"@id": {
3856+
"@id": "ex:rei",
3857+
"@reverse": {
3858+
"ex:rel": [{"@id": "ex:value"}]
3859+
}
3860+
},
3861+
"ex:prop": [{"@value": "value2"}]
3862+
}])
3863+
},
3864+
"embedded node with expanded reverse relationship": {
3865+
input: %({
3866+
"@id": {
3867+
"@id": "ex:rei",
3868+
"@reverse": {
3869+
"ex:rel": {"@id": "ex:value"}
3870+
}
3871+
},
3872+
"ex:prop": "value2"
3873+
}),
3874+
output: %([{
3875+
"@id": {
3876+
"@id": "ex:rei",
3877+
"@reverse": {
3878+
"ex:rel": [{"@id": "ex:value"}]
3879+
}
3880+
},
3881+
"ex:prop": [{"@value": "value2"}]
3882+
}])
3883+
},
3884+
"embedded node used as subject in reverse relationship": {
3885+
input: %({
3886+
"@context": {
3887+
"rel": {"@reverse": "ex:rel"}
3888+
},
3889+
"@id": {
3890+
"@id": "ex:rei",
3891+
"ex:prop": {"@id": "ex:value"}
3892+
},
3893+
"rel": {"@id": "ex:value2"}
3894+
}),
3895+
output: %([{
3896+
"@id": {
3897+
"@id": "ex:rei",
3898+
"ex:prop": [{"@id": "ex:value"}]
3899+
},
3900+
"@reverse": {
3901+
"ex:rel": [{"@id": "ex:value2"}]
3902+
}
3903+
}])
3904+
},
3905+
"embedded node used as object in reverse relationship": {
3906+
input: %({
3907+
"@context": {
3908+
"rel": {"@reverse": "ex:rel"}
3909+
},
3910+
"@id": "ex:subj",
3911+
"rel": {
3912+
"@id": "ex:rei",
3913+
"ex:prop": {"@id": "ex:value"}
3914+
}
3915+
}),
3916+
output: %([{
3917+
"@id": "ex:subj",
3918+
"@reverse": {
3919+
"ex:rel": [{
3920+
"@id": "ex:rei",
3921+
"ex:prop": [{"@id": "ex:value"}]
3922+
}]
3923+
}
3924+
}])
3925+
},
3926+
"node with @annotation property on node object with reverse relationship": {
3927+
input: %({
3928+
"@context": {
3929+
"knownBy": {"@reverse": "ex:knows"}
3930+
},
3931+
"@id": "ex:bob",
3932+
"ex:name": "Bob",
3933+
"knownBy": {
3934+
"@id": "ex:fred",
3935+
"ex:name": "Fred",
3936+
"@annotation": {"ex:certainty": 0.8}
3937+
}
3938+
}),
3939+
output: %([{
3940+
"@id": "ex:bob",
3941+
"ex:name": [{"@value": "Bob"}],
3942+
"@reverse": {
3943+
"ex:knows": [{
3944+
"@id": "ex:fred",
3945+
"ex:name": [{"@value": "Fred"}],
3946+
"@annotation": [{"ex:certainty": [{"@value": 0.8}]}]
3947+
}]
3948+
}
3949+
}])
3950+
},
3951+
"reverse relationship inside annotation": {
3952+
input: %({
3953+
"@context": {
3954+
"claims": {"@reverse": "ex:claims", "@type": "@id"}
3955+
},
3956+
"@id": "ex:bob",
3957+
"ex:knows": {
3958+
"@id": "ex:jane",
3959+
"@annotation": {
3960+
"ex:certainty": 0.8,
3961+
"claims": "ex:sue"
3962+
}
3963+
}
3964+
}),
3965+
output: %([{
3966+
"@id": "ex:bob",
3967+
"ex:knows": [{
3968+
"@id": "ex:jane",
3969+
"@annotation": [{
3970+
"ex:certainty": [{"@value": 0.8}],
3971+
"@reverse": {
3972+
"ex:claims": [{"@id": "ex:sue"}]
3973+
}
3974+
}]
3975+
}]
3976+
}])
3977+
},
38433978
}.each do |title, params|
38443979
it(title) {run_expand params.merge(rdfstar: true)}
38453980
end

0 commit comments

Comments
 (0)
Please sign in to comment.