json-ld 3.1.7 → 3.2.0

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.
data/spec/compact_spec.rb CHANGED
@@ -954,6 +954,76 @@ describe JSON::LD::API do
954
954
  }),
955
955
  processingMode: 'json-ld-1.1'
956
956
  },
957
+ "issue-514": {
958
+ input: %({
959
+ "http://example.org/ns/prop": [{
960
+ "@id": "http://example.org/ns/bar",
961
+ "http://example.org/ns/name": "bar"
962
+ }, {
963
+ "@id": "http://example.org/ns/foo",
964
+ "http://example.org/ns/name": "foo"
965
+ }]
966
+ }),
967
+ context: %({
968
+ "@context": {
969
+ "ex": "http://example.org/ns/",
970
+ "prop": {
971
+ "@id": "ex:prop",
972
+ "@container": "@index",
973
+ "@index": "ex:name"
974
+ }
975
+ }
976
+ }),
977
+ output: %({
978
+ "@context": {
979
+ "ex": "http://example.org/ns/",
980
+ "prop": {
981
+ "@id": "ex:prop",
982
+ "@container": "@index",
983
+ "@index": "ex:name"
984
+ }
985
+ },
986
+ "prop": {
987
+ "foo": { "@id": "ex:foo"},
988
+ "bar": { "@id": "ex:bar"}
989
+ }
990
+ })
991
+ },
992
+ "issue-514b": {
993
+ input: %({
994
+ "http://example.org/ns/prop": [{
995
+ "@id": "http://example.org/ns/bar",
996
+ "http://example.org/ns/name": "bar"
997
+ }, {
998
+ "@id": "http://example.org/ns/foo",
999
+ "http://example.org/ns/name": "foo"
1000
+ }]
1001
+ }),
1002
+ context: %({
1003
+ "@context": {
1004
+ "ex": "http://example.org/ns/",
1005
+ "prop": {
1006
+ "@id": "ex:prop",
1007
+ "@container": "@index",
1008
+ "@index": "http://example.org/ns/name"
1009
+ }
1010
+ }
1011
+ }),
1012
+ output: %({
1013
+ "@context": {
1014
+ "ex": "http://example.org/ns/",
1015
+ "prop": {
1016
+ "@id": "ex:prop",
1017
+ "@container": "@index",
1018
+ "@index": "http://example.org/ns/name"
1019
+ }
1020
+ },
1021
+ "prop": {
1022
+ "foo": { "@id": "ex:foo"},
1023
+ "bar": { "@id": "ex:bar"}
1024
+ }
1025
+ })
1026
+ },
957
1027
  }.each_pair do |title, params|
958
1028
  it(title) {run_compact(params)}
959
1029
  end
@@ -3113,7 +3183,7 @@ describe JSON::LD::API do
3113
3183
  end
3114
3184
  end
3115
3185
 
3116
- context "JSON-LD*" do
3186
+ context "JSON-LD-star" do
3117
3187
  {
3118
3188
  "subject-iii": {
3119
3189
  input: %([{
@@ -3389,7 +3459,7 @@ describe JSON::LD::API do
3389
3459
  input = ::JSON.parse(input) if input.is_a?(String)
3390
3460
  output = ::JSON.parse(output) if output.is_a?(String)
3391
3461
  context = ::JSON.parse(context) if context.is_a?(String)
3392
- context = context['@context'] if context.has_key?('@context')
3462
+ context = context['@context'] if context.key?('@context')
3393
3463
  pending params.fetch(:pending, "test implementation") unless input
3394
3464
  if params[:exception]
3395
3465
  expect {JSON::LD::API.compact(input, context, logger: logger, **params)}.to raise_error(params[:exception])
data/spec/context_spec.rb CHANGED
@@ -181,7 +181,14 @@ describe JSON::LD::Context do
181
181
  before {JSON::LD::Context.instance_variable_set(:@cache, nil)}
182
182
  it "retrieves and parses a remote context document" do
183
183
  expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
184
- subject.parse(ctx)
184
+ ec = subject.parse(ctx)
185
+ expect(ec.send(:mappings)).to produce({
186
+ "xsd" => "http://www.w3.org/2001/XMLSchema#",
187
+ "name" => "http://xmlns.com/foaf/0.1/name",
188
+ "homepage" => "http://xmlns.com/foaf/0.1/homepage",
189
+ "avatar" => "http://xmlns.com/foaf/0.1/avatar",
190
+ "integer" => "http://www.w3.org/2001/XMLSchema#integer"
191
+ }, logger)
185
192
  end
186
193
  end
187
194
 
@@ -1148,7 +1155,6 @@ describe JSON::LD::Context do
1148
1155
  "nil" => [nil, nil],
1149
1156
  "absolute IRI" => ["http://example.com/", "http://example.com/"],
1150
1157
  "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1151
- "keyword" => ["@type", "@type"],
1152
1158
  "unmapped" => ["foo", "foo"],
1153
1159
  "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1154
1160
  "relative" => ["foo/bar", "http://base/foo/bar"],
@@ -1338,7 +1344,6 @@ describe JSON::LD::Context do
1338
1344
  "nil" => [nil, nil],
1339
1345
  "absolute IRI" => ["http://example.com/", "http://example.com/"],
1340
1346
  "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1341
- "keyword" => ["@type", "@type"],
1342
1347
  "unmapped" => ["foo", "foo"],
1343
1348
  "bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
1344
1349
  "relative" => ["foo/bar", "http://base/foo/bar"],
data/spec/expand_spec.rb CHANGED
@@ -3371,12 +3371,49 @@ 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
3377
3414
  end
3378
3415
 
3379
- context "JSON-LD*" do
3416
+ context "JSON-LD-star" do
3380
3417
  {
3381
3418
  "node with embedded subject without rdfstar option": {
3382
3419
  input: %({
@@ -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
- "illegal node with embedded object having properties": {
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