json-ld 3.1.6 → 3.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -7
- data/VERSION +1 -1
- data/bin/jsonld +13 -11
- data/lib/json/ld/api.rb +34 -17
- data/lib/json/ld/compact.rb +14 -6
- data/lib/json/ld/context.rb +63 -57
- data/lib/json/ld/expand.rb +57 -19
- data/lib/json/ld/extensions.rb +4 -4
- data/lib/json/ld/flatten.rb +137 -9
- data/lib/json/ld/format.rb +8 -1
- data/lib/json/ld/frame.rb +8 -8
- data/lib/json/ld/from_rdf.rb +14 -8
- data/lib/json/ld/html/nokogiri.rb +3 -4
- 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/lib/json/ld.rb +3 -1
- data/spec/api_spec.rb +1 -1
- data/spec/compact_spec.rb +277 -3
- data/spec/context_spec.rb +8 -3
- data/spec/expand_spec.rb +385 -2
- data/spec/flatten_spec.rb +517 -1
- data/spec/frame_spec.rb +93 -3
- data/spec/from_rdf_spec.rb +1 -1
- data/spec/rdfstar_spec.rb +25 -0
- data/spec/spec_helper.rb +40 -2
- 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/suite_to_rdf_spec.rb +1 -1
- data/spec/to_rdf_spec.rb +4 -4
- data/spec/writer_spec.rb +193 -0
- metadata +6 -4
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
|
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
|
-
"
|
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
|