json-ld 3.1.2 → 3.1.7
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/README.md +124 -48
- data/VERSION +1 -1
- data/bin/jsonld +27 -30
- data/lib/json/ld.rb +6 -2
- data/lib/json/ld/api.rb +33 -24
- data/lib/json/ld/compact.rb +65 -37
- data/lib/json/ld/conneg.rb +1 -1
- data/lib/json/ld/context.rb +612 -539
- data/lib/json/ld/expand.rb +158 -77
- data/lib/json/ld/format.rb +20 -7
- data/lib/json/ld/from_rdf.rb +40 -17
- data/lib/json/ld/reader.rb +20 -11
- data/lib/json/ld/streaming_reader.rb +578 -0
- data/lib/json/ld/to_rdf.rb +9 -5
- data/lib/json/ld/writer.rb +10 -3
- data/spec/compact_spec.rb +207 -2
- data/spec/context_spec.rb +13 -60
- data/spec/expand_spec.rb +248 -0
- data/spec/from_rdf_spec.rb +181 -0
- data/spec/matchers.rb +1 -1
- data/spec/reader_spec.rb +33 -34
- data/spec/streaming_reader_spec.rb +237 -0
- data/spec/suite_helper.rb +14 -8
- data/spec/suite_to_rdf_spec.rb +1 -0
- data/spec/to_rdf_spec.rb +206 -0
- data/spec/writer_spec.rb +193 -0
- metadata +9 -6
data/spec/expand_spec.rb
CHANGED
@@ -3376,6 +3376,254 @@ describe JSON::LD::API do
|
|
3376
3376
|
end
|
3377
3377
|
end
|
3378
3378
|
|
3379
|
+
context "JSON-LD*" do
|
3380
|
+
{
|
3381
|
+
"node with embedded subject without rdfstar option": {
|
3382
|
+
input: %({
|
3383
|
+
"@id": {
|
3384
|
+
"@id": "ex:rei",
|
3385
|
+
"ex:prop": "value"
|
3386
|
+
},
|
3387
|
+
"ex:prop": "value2"
|
3388
|
+
}),
|
3389
|
+
exception: JSON::LD::JsonLdError::InvalidIdValue
|
3390
|
+
},
|
3391
|
+
}.each do |title, params|
|
3392
|
+
it(title) {run_expand params}
|
3393
|
+
end
|
3394
|
+
|
3395
|
+
{
|
3396
|
+
"node with embedded subject having no @id": {
|
3397
|
+
input: %({
|
3398
|
+
"@id": {
|
3399
|
+
"ex:prop": "value"
|
3400
|
+
},
|
3401
|
+
"ex:prop": "value2"
|
3402
|
+
}),
|
3403
|
+
output: %([{
|
3404
|
+
"@id": {
|
3405
|
+
"ex:prop": [{"@value": "value"}]
|
3406
|
+
},
|
3407
|
+
"ex:prop": [{"@value": "value2"}]
|
3408
|
+
}])
|
3409
|
+
},
|
3410
|
+
"node with embedded subject having IRI @id": {
|
3411
|
+
input: %({
|
3412
|
+
"@id": {
|
3413
|
+
"@id": "ex:rei",
|
3414
|
+
"ex:prop": "value"
|
3415
|
+
},
|
3416
|
+
"ex:prop": "value2"
|
3417
|
+
}),
|
3418
|
+
output: %([{
|
3419
|
+
"@id": {
|
3420
|
+
"@id": "ex:rei",
|
3421
|
+
"ex:prop": [{"@value": "value"}]
|
3422
|
+
},
|
3423
|
+
"ex:prop": [{"@value": "value2"}]
|
3424
|
+
}])
|
3425
|
+
},
|
3426
|
+
"node with embedded subject having BNode @id": {
|
3427
|
+
input: %({
|
3428
|
+
"@id": {
|
3429
|
+
"@id": "_:rei",
|
3430
|
+
"ex:prop": "value"
|
3431
|
+
},
|
3432
|
+
"ex:prop": "value2"
|
3433
|
+
}),
|
3434
|
+
output: %([{
|
3435
|
+
"@id": {
|
3436
|
+
"@id": "_:rei",
|
3437
|
+
"ex:prop": [{"@value": "value"}]
|
3438
|
+
},
|
3439
|
+
"ex:prop": [{"@value": "value2"}]
|
3440
|
+
}])
|
3441
|
+
},
|
3442
|
+
"node with embedded subject having a type": {
|
3443
|
+
input: %({
|
3444
|
+
"@id": {
|
3445
|
+
"@id": "ex:rei",
|
3446
|
+
"@type": "ex:Type"
|
3447
|
+
},
|
3448
|
+
"ex:prop": "value2"
|
3449
|
+
}),
|
3450
|
+
output: %([{
|
3451
|
+
"@id": {
|
3452
|
+
"@id": "ex:rei",
|
3453
|
+
"@type": ["ex:Type"]
|
3454
|
+
},
|
3455
|
+
"ex:prop": [{"@value": "value2"}]
|
3456
|
+
}])
|
3457
|
+
},
|
3458
|
+
"node with embedded subject having an IRI value": {
|
3459
|
+
input: %({
|
3460
|
+
"@id": {
|
3461
|
+
"@id": "ex:rei",
|
3462
|
+
"ex:prop": {"@id": "ex:value"}
|
3463
|
+
},
|
3464
|
+
"ex:prop": "value2"
|
3465
|
+
}),
|
3466
|
+
output: %([{
|
3467
|
+
"@id": {
|
3468
|
+
"@id": "ex:rei",
|
3469
|
+
"ex:prop": [{"@id": "ex:value"}]
|
3470
|
+
},
|
3471
|
+
"ex:prop": [{"@value": "value2"}]
|
3472
|
+
}])
|
3473
|
+
},
|
3474
|
+
"node with embedded subject having an BNode value": {
|
3475
|
+
input: %({
|
3476
|
+
"@id": {
|
3477
|
+
"@id": "ex:rei",
|
3478
|
+
"ex:prop": {"@id": "_:value"}
|
3479
|
+
},
|
3480
|
+
"ex:prop": "value2"
|
3481
|
+
}),
|
3482
|
+
output: %([{
|
3483
|
+
"@id": {
|
3484
|
+
"@id": "ex:rei",
|
3485
|
+
"ex:prop": [{"@id": "_:value"}]
|
3486
|
+
},
|
3487
|
+
"ex:prop": [{"@value": "value2"}]
|
3488
|
+
}])
|
3489
|
+
},
|
3490
|
+
"node with recursive embedded subject": {
|
3491
|
+
input: %({
|
3492
|
+
"@id": {
|
3493
|
+
"@id": {
|
3494
|
+
"@id": "ex:rei",
|
3495
|
+
"ex:prop": "value3"
|
3496
|
+
},
|
3497
|
+
"ex:prop": "value"
|
3498
|
+
},
|
3499
|
+
"ex:prop": "value2"
|
3500
|
+
}),
|
3501
|
+
output: %([{
|
3502
|
+
"@id": {
|
3503
|
+
"@id": {
|
3504
|
+
"@id": "ex:rei",
|
3505
|
+
"ex:prop": [{"@value": "value3"}]
|
3506
|
+
},
|
3507
|
+
"ex:prop": [{"@value": "value"}]
|
3508
|
+
},
|
3509
|
+
"ex:prop": [{"@value": "value2"}]
|
3510
|
+
}])
|
3511
|
+
},
|
3512
|
+
"illegal node with subject having no property": {
|
3513
|
+
input: %({
|
3514
|
+
"@id": {
|
3515
|
+
"@id": "ex:rei"
|
3516
|
+
},
|
3517
|
+
"ex:prop": "value3"
|
3518
|
+
}),
|
3519
|
+
exception: JSON::LD::JsonLdError::InvalidEmbeddedNode
|
3520
|
+
},
|
3521
|
+
"illegal node with subject having multiple properties": {
|
3522
|
+
input: %({
|
3523
|
+
"@id": {
|
3524
|
+
"@id": "ex:rei",
|
3525
|
+
"ex:prop": ["value1", "value2"]
|
3526
|
+
},
|
3527
|
+
"ex:prop": "value3"
|
3528
|
+
}),
|
3529
|
+
exception: JSON::LD::JsonLdError::InvalidEmbeddedNode
|
3530
|
+
},
|
3531
|
+
"illegal node with subject having multiple types": {
|
3532
|
+
input: %({
|
3533
|
+
"@id": {
|
3534
|
+
"@id": "ex:rei",
|
3535
|
+
"@type": ["ex:Type1", "ex:Type2"]
|
3536
|
+
},
|
3537
|
+
"ex:prop": "value3"
|
3538
|
+
}),
|
3539
|
+
exception: JSON::LD::JsonLdError::InvalidEmbeddedNode
|
3540
|
+
},
|
3541
|
+
"illegal node with subject having type and property": {
|
3542
|
+
input: %({
|
3543
|
+
"@id": {
|
3544
|
+
"@id": "ex:rei",
|
3545
|
+
"@type": "ex:Type",
|
3546
|
+
"ex:prop": "value"
|
3547
|
+
},
|
3548
|
+
"ex:prop": "value2"
|
3549
|
+
}),
|
3550
|
+
exception: JSON::LD::JsonLdError::InvalidEmbeddedNode
|
3551
|
+
},
|
3552
|
+
"node with embedded object": {
|
3553
|
+
input: %({
|
3554
|
+
"@id": "ex:subj",
|
3555
|
+
"ex:value": {
|
3556
|
+
"@id": {
|
3557
|
+
"@id": "ex:rei",
|
3558
|
+
"ex:prop": "value"
|
3559
|
+
}
|
3560
|
+
}
|
3561
|
+
}),
|
3562
|
+
output: %([{
|
3563
|
+
"@id": "ex:subj",
|
3564
|
+
"ex:value": [{
|
3565
|
+
"@id": {
|
3566
|
+
"@id": "ex:rei",
|
3567
|
+
"ex:prop": [{"@value": "value"}]
|
3568
|
+
}
|
3569
|
+
}]
|
3570
|
+
}])
|
3571
|
+
},
|
3572
|
+
"illegal node with embedded object having properties": {
|
3573
|
+
input: %({
|
3574
|
+
"@id": "ex:subj",
|
3575
|
+
"ex:value": {
|
3576
|
+
"@id": {
|
3577
|
+
"@id": "ex:rei",
|
3578
|
+
"ex:prop": "value"
|
3579
|
+
},
|
3580
|
+
"ex:prop": "value2"
|
3581
|
+
}
|
3582
|
+
}),
|
3583
|
+
output: %([{
|
3584
|
+
"@id": "ex:subj",
|
3585
|
+
"ex:value": [{
|
3586
|
+
"@id": {
|
3587
|
+
"@id": "ex:rei",
|
3588
|
+
"ex:prop": [{"@value": "value"}]
|
3589
|
+
},
|
3590
|
+
"ex:prop": [{"@value": "value2"}]
|
3591
|
+
}]
|
3592
|
+
}])
|
3593
|
+
},
|
3594
|
+
"node with recursive embedded object": {
|
3595
|
+
input: %({
|
3596
|
+
"@id": "ex:subj",
|
3597
|
+
"ex:value": {
|
3598
|
+
"@id": {
|
3599
|
+
"@id": {
|
3600
|
+
"@id": "ex:rei",
|
3601
|
+
"ex:prop": "value3"
|
3602
|
+
},
|
3603
|
+
"ex:prop": "value"
|
3604
|
+
},
|
3605
|
+
"ex:prop": "value2"
|
3606
|
+
}
|
3607
|
+
}),
|
3608
|
+
output: %([{
|
3609
|
+
"@id": "ex:subj",
|
3610
|
+
"ex:value": [{
|
3611
|
+
"@id": {
|
3612
|
+
"@id": {
|
3613
|
+
"@id": "ex:rei",
|
3614
|
+
"ex:prop": [{"@value": "value3"}]
|
3615
|
+
},
|
3616
|
+
"ex:prop":[{"@value": "value"}]
|
3617
|
+
},
|
3618
|
+
"ex:prop": [{"@value": "value2"}]
|
3619
|
+
}]
|
3620
|
+
}])
|
3621
|
+
},
|
3622
|
+
}.each do |title, params|
|
3623
|
+
it(title) {run_expand params.merge(rdfstar: true)}
|
3624
|
+
end
|
3625
|
+
end
|
3626
|
+
|
3379
3627
|
begin
|
3380
3628
|
require 'nokogiri'
|
3381
3629
|
rescue LoadError
|
data/spec/from_rdf_spec.rb
CHANGED
@@ -766,6 +766,187 @@ describe JSON::LD::API do
|
|
766
766
|
end
|
767
767
|
end
|
768
768
|
|
769
|
+
context "RDF*" do
|
770
|
+
{
|
771
|
+
"subject-iii": {
|
772
|
+
input: RDF::Statement(
|
773
|
+
RDF::Statement(
|
774
|
+
RDF::URI('http://example/s1'),
|
775
|
+
RDF::URI('http://example/p1'),
|
776
|
+
RDF::URI('http://example/o1')),
|
777
|
+
RDF::URI('http://example/p'),
|
778
|
+
RDF::URI('http://example/o')),
|
779
|
+
output: %([{
|
780
|
+
"@id": {
|
781
|
+
"@id": "http://example/s1",
|
782
|
+
"http://example/p1": [{"@id": "http://example/o1"}]
|
783
|
+
},
|
784
|
+
"http://example/p": [{"@id": "http://example/o"}]
|
785
|
+
}])
|
786
|
+
},
|
787
|
+
"subject-iib": {
|
788
|
+
input: RDF::Statement(
|
789
|
+
RDF::Statement(
|
790
|
+
RDF::URI('http://example/s1'),
|
791
|
+
RDF::URI('http://example/p1'),
|
792
|
+
RDF::Node.new('o1')),
|
793
|
+
RDF::URI('http://example/p'),
|
794
|
+
RDF::URI('http://example/o')),
|
795
|
+
output: %([{
|
796
|
+
"@id": {
|
797
|
+
"@id": "http://example/s1",
|
798
|
+
"http://example/p1": [{"@id": "_:o1"}]
|
799
|
+
},
|
800
|
+
"http://example/p": [{"@id": "http://example/o"}]
|
801
|
+
}])
|
802
|
+
},
|
803
|
+
"subject-iil": {
|
804
|
+
input: RDF::Statement(
|
805
|
+
RDF::Statement(
|
806
|
+
RDF::URI('http://example/s1'),
|
807
|
+
RDF::URI('http://example/p1'),
|
808
|
+
RDF::Literal('o1')),
|
809
|
+
RDF::URI('http://example/p'),
|
810
|
+
RDF::URI('http://example/o')),
|
811
|
+
output: %([{
|
812
|
+
"@id": {
|
813
|
+
"@id": "http://example/s1",
|
814
|
+
"http://example/p1": [{"@value": "o1"}]
|
815
|
+
},
|
816
|
+
"http://example/p": [{"@id": "http://example/o"}]
|
817
|
+
}])
|
818
|
+
},
|
819
|
+
"subject-bii": {
|
820
|
+
input: RDF::Statement(
|
821
|
+
RDF::Statement(
|
822
|
+
RDF::Node('s1'),
|
823
|
+
RDF::URI('http://example/p1'),
|
824
|
+
RDF::URI('http://example/o1')),
|
825
|
+
RDF::URI('http://example/p'),
|
826
|
+
RDF::URI('http://example/o')),
|
827
|
+
output: %([{
|
828
|
+
"@id": {
|
829
|
+
"@id": "_:s1",
|
830
|
+
"http://example/p1": [{"@id": "http://example/o1"}]
|
831
|
+
},
|
832
|
+
"http://example/p": [{"@id": "http://example/o"}]
|
833
|
+
}])
|
834
|
+
},
|
835
|
+
"subject-bib": {
|
836
|
+
input: RDF::Statement(
|
837
|
+
RDF::Statement(
|
838
|
+
RDF::Node('s1'),
|
839
|
+
RDF::URI('http://example/p1'),
|
840
|
+
RDF::Node.new('o1')),
|
841
|
+
RDF::URI('http://example/p'), RDF::URI('http://example/o')),
|
842
|
+
output: %([{
|
843
|
+
"@id": {
|
844
|
+
"@id": "_:s1",
|
845
|
+
"http://example/p1": [{"@id": "_:o1"}]
|
846
|
+
},
|
847
|
+
"http://example/p": [{"@id": "http://example/o"}]
|
848
|
+
}])
|
849
|
+
},
|
850
|
+
"subject-bil": {
|
851
|
+
input: RDF::Statement(
|
852
|
+
RDF::Statement(
|
853
|
+
RDF::Node('s1'),
|
854
|
+
RDF::URI('http://example/p1'),
|
855
|
+
RDF::Literal('o1')),
|
856
|
+
RDF::URI('http://example/p'),
|
857
|
+
RDF::URI('http://example/o')),
|
858
|
+
output: %([{
|
859
|
+
"@id": {
|
860
|
+
"@id": "_:s1",
|
861
|
+
"http://example/p1": [{"@value": "o1"}]
|
862
|
+
},
|
863
|
+
"http://example/p": [{"@id": "http://example/o"}]
|
864
|
+
}])
|
865
|
+
},
|
866
|
+
"object-iii": {
|
867
|
+
input: RDF::Statement(
|
868
|
+
RDF::URI('http://example/s'),
|
869
|
+
RDF::URI('http://example/p'),
|
870
|
+
RDF::Statement(
|
871
|
+
RDF::URI('http://example/s1'),
|
872
|
+
RDF::URI('http://example/p1'),
|
873
|
+
RDF::URI('http://example/o1'))),
|
874
|
+
output: %([{
|
875
|
+
"@id": "http://example/s",
|
876
|
+
"http://example/p": [{
|
877
|
+
"@id": {
|
878
|
+
"@id": "http://example/s1",
|
879
|
+
"http://example/p1": [{"@id": "http://example/o1"}]
|
880
|
+
}
|
881
|
+
}]
|
882
|
+
}])
|
883
|
+
},
|
884
|
+
"object-iib": {
|
885
|
+
input: RDF::Statement(
|
886
|
+
RDF::URI('http://example/s'),
|
887
|
+
RDF::URI('http://example/p'),
|
888
|
+
RDF::Statement(
|
889
|
+
RDF::URI('http://example/s1'),
|
890
|
+
RDF::URI('http://example/p1'),
|
891
|
+
RDF::Node.new('o1'))),
|
892
|
+
output: %([{
|
893
|
+
"@id": "http://example/s",
|
894
|
+
"http://example/p": [{
|
895
|
+
"@id": {
|
896
|
+
"@id": "http://example/s1",
|
897
|
+
"http://example/p1": [{"@id": "_:o1"}]
|
898
|
+
}
|
899
|
+
}]
|
900
|
+
}])
|
901
|
+
},
|
902
|
+
"object-iil": {
|
903
|
+
input: RDF::Statement(
|
904
|
+
RDF::URI('http://example/s'),
|
905
|
+
RDF::URI('http://example/p'),
|
906
|
+
RDF::Statement(
|
907
|
+
RDF::URI('http://example/s1'),
|
908
|
+
RDF::URI('http://example/p1'),
|
909
|
+
RDF::Literal('o1'))),
|
910
|
+
output: %([{
|
911
|
+
"@id": "http://example/s",
|
912
|
+
"http://example/p": [{
|
913
|
+
"@id": {
|
914
|
+
"@id": "http://example/s1",
|
915
|
+
"http://example/p1": [{"@value": "o1"}]
|
916
|
+
}
|
917
|
+
}]
|
918
|
+
}])
|
919
|
+
},
|
920
|
+
"recursive-subject": {
|
921
|
+
input: RDF::Statement(
|
922
|
+
RDF::Statement(
|
923
|
+
RDF::Statement(
|
924
|
+
RDF::URI('http://example/s2'),
|
925
|
+
RDF::URI('http://example/p2'),
|
926
|
+
RDF::URI('http://example/o2')),
|
927
|
+
RDF::URI('http://example/p1'),
|
928
|
+
RDF::URI('http://example/o1')),
|
929
|
+
RDF::URI('http://example/p'),
|
930
|
+
RDF::URI('http://example/o')),
|
931
|
+
output: %([{
|
932
|
+
"@id": {
|
933
|
+
"@id": {
|
934
|
+
"@id": "http://example/s2",
|
935
|
+
"http://example/p2": [{"@id": "http://example/o2"}]
|
936
|
+
},
|
937
|
+
"http://example/p1": [{"@id": "http://example/o1"}]
|
938
|
+
},
|
939
|
+
"http://example/p": [{"@id": "http://example/o"}]
|
940
|
+
}])
|
941
|
+
},
|
942
|
+
}.each do |name, params|
|
943
|
+
it name do
|
944
|
+
graph = RDF::Graph.new {|g| g << params[:input]}
|
945
|
+
do_fromRdf(params.merge(input: graph, prefixes: {ex: 'http://example/'}))
|
946
|
+
end
|
947
|
+
end
|
948
|
+
end
|
949
|
+
|
769
950
|
context "problems" do
|
770
951
|
{
|
771
952
|
"xsd:boolean as value" => {
|
data/spec/matchers.rb
CHANGED
data/spec/reader_spec.rb
CHANGED
@@ -43,40 +43,39 @@ describe JSON::LD::Reader do
|
|
43
43
|
{
|
44
44
|
plain: %q({
|
45
45
|
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
</script>),
|
46
|
+
"@id": "_:bnode1",
|
47
|
+
"@type": "foaf:Person",
|
48
|
+
"foaf:homepage": "http://example.com/bob/",
|
49
|
+
"foaf:name": "Bob"
|
50
|
+
}),
|
51
|
+
leading_comment: %q(
|
52
|
+
// A comment before content
|
53
|
+
{
|
54
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
55
|
+
"@id": "_:bnode1",
|
56
|
+
"@type": "foaf:Person",
|
57
|
+
"foaf:homepage": "http://example.com/bob/",
|
58
|
+
"foaf:name": "Bob"
|
59
|
+
}),
|
60
|
+
script: %q(<script type="application/ld+json">
|
61
|
+
{
|
62
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
63
|
+
"@id": "_:bnode1",
|
64
|
+
"@type": "foaf:Person",
|
65
|
+
"foaf:homepage": "http://example.com/bob/",
|
66
|
+
"foaf:name": "Bob"
|
67
|
+
}
|
68
|
+
</script>),
|
69
|
+
script_comments: %q(<script type="application/ld+json">
|
70
|
+
// A comment before content
|
71
|
+
{
|
72
|
+
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
|
73
|
+
"@id": "_:bnode1",
|
74
|
+
"@type": "foaf:Person",
|
75
|
+
"foaf:homepage": "http://example.com/bob/",
|
76
|
+
"foaf:name": "Bob"
|
77
|
+
}
|
78
|
+
</script>),
|
80
79
|
}.each do |variant, src|
|
81
80
|
context variant do
|
82
81
|
subject {src}
|