json-ld 3.1.6 → 3.1.10

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,6 +3183,210 @@ describe JSON::LD::API do
3113
3183
  end
3114
3184
  end
3115
3185
 
3186
+ context "JSON-LD-star" do
3187
+ {
3188
+ "subject-iii": {
3189
+ input: %([{
3190
+ "@id": {
3191
+ "@id": "http://example/s1",
3192
+ "http://example/p1": [{"@id": "http://example/o1"}]
3193
+ },
3194
+ "http://example/p": [{"@id": "http://example/o"}]
3195
+ }]),
3196
+ context: %({"ex": "http://example/"}),
3197
+ output: %({
3198
+ "@context": {"ex": "http://example/"},
3199
+ "@id": {
3200
+ "@id": "ex:s1",
3201
+ "ex:p1": {"@id": "ex:o1"}
3202
+ },
3203
+ "ex:p": {"@id": "ex:o"}
3204
+ })
3205
+ },
3206
+ "subject-iib": {
3207
+ input: %([{
3208
+ "@id": {
3209
+ "@id": "http://example/s1",
3210
+ "http://example/p1": [{"@id": "_:o1"}]
3211
+ },
3212
+ "http://example/p": [{"@id": "http://example/o"}]
3213
+ }]),
3214
+ context: %({"ex": "http://example/"}),
3215
+ output: %({
3216
+ "@context": {"ex": "http://example/"},
3217
+ "@id": {
3218
+ "@id": "ex:s1",
3219
+ "ex:p1": {"@id": "_:o1"}
3220
+ },
3221
+ "ex:p": {"@id": "ex:o"}
3222
+ })
3223
+ },
3224
+ "subject-iil": {
3225
+ input: %([{
3226
+ "@id": {
3227
+ "@id": "http://example/s1",
3228
+ "http://example/p1": [{"@value": "o1"}]
3229
+ },
3230
+ "http://example/p": [{"@id": "http://example/o"}]
3231
+ }]),
3232
+ context: %({"ex": "http://example/"}),
3233
+ output: %({
3234
+ "@context": {"ex": "http://example/"},
3235
+ "@id": {
3236
+ "@id": "ex:s1",
3237
+ "ex:p1": "o1"
3238
+ },
3239
+ "ex:p": {"@id": "ex:o"}
3240
+ })
3241
+ },
3242
+ "subject-bii": {
3243
+ input: %([{
3244
+ "@id": {
3245
+ "@id": "_:s1",
3246
+ "http://example/p1": [{"@id": "http://example/o1"}]
3247
+ },
3248
+ "http://example/p": [{"@id": "http://example/o"}]
3249
+ }]),
3250
+ context: %({"ex": "http://example/"}),
3251
+ output: %({
3252
+ "@context": {"ex": "http://example/"},
3253
+ "@id": {
3254
+ "@id": "_:s1",
3255
+ "ex:p1": {"@id": "ex:o1"}
3256
+ },
3257
+ "ex:p": {"@id": "ex:o"}
3258
+ })
3259
+ },
3260
+ "subject-bib": {
3261
+ input: %([{
3262
+ "@id": {
3263
+ "@id": "_:s1",
3264
+ "http://example/p1": [{"@id": "_:o1"}]
3265
+ },
3266
+ "http://example/p": [{"@id": "http://example/o"}]
3267
+ }]),
3268
+ context: %({"ex": "http://example/"}),
3269
+ output: %({
3270
+ "@context": {"ex": "http://example/"},
3271
+ "@id": {
3272
+ "@id": "_:s1",
3273
+ "ex:p1": {"@id": "_:o1"}
3274
+ },
3275
+ "ex:p": {"@id": "ex:o"}
3276
+ })
3277
+ },
3278
+ "subject-bil": {
3279
+ input: %([{
3280
+ "@id": {
3281
+ "@id": "_:s1",
3282
+ "http://example/p1": [{"@value": "o1"}]
3283
+ },
3284
+ "http://example/p": [{"@id": "http://example/o"}]
3285
+ }]),
3286
+ context: %({"ex": "http://example/"}),
3287
+ output: %({
3288
+ "@context": {"ex": "http://example/"},
3289
+ "@id": {
3290
+ "@id": "_:s1",
3291
+ "ex:p1": "o1"
3292
+ },
3293
+ "ex:p": {"@id": "ex:o"}
3294
+ })
3295
+ },
3296
+ "object-iii": {
3297
+ input: %([{
3298
+ "@id": "http://example/s",
3299
+ "http://example/p": [{
3300
+ "@id": {
3301
+ "@id": "http://example/s1",
3302
+ "http://example/p1": [{"@id": "http://example/o1"}]
3303
+ }
3304
+ }]
3305
+ }]),
3306
+ context: %({"ex": "http://example/"}),
3307
+ output: %({
3308
+ "@context": {"ex": "http://example/"},
3309
+ "@id": "ex:s",
3310
+ "ex:p": {
3311
+ "@id": {
3312
+ "@id": "ex:s1",
3313
+ "ex:p1": {"@id": "ex:o1"}
3314
+ }
3315
+ }
3316
+ })
3317
+ },
3318
+ "object-iib": {
3319
+ input: %([{
3320
+ "@id": "http://example/s",
3321
+ "http://example/p": [{
3322
+ "@id": {
3323
+ "@id": "http://example/s1",
3324
+ "http://example/p1": [{"@id": "_:o1"}]
3325
+ }
3326
+ }]
3327
+ }]),
3328
+ context: %({"ex": "http://example/"}),
3329
+ output: %({
3330
+ "@context": {"ex": "http://example/"},
3331
+ "@id": "ex:s",
3332
+ "ex:p": {
3333
+ "@id": {
3334
+ "@id": "ex:s1",
3335
+ "ex:p1": {"@id": "_:o1"}
3336
+ }
3337
+ }
3338
+ })
3339
+ },
3340
+ "object-iil": {
3341
+ input: %([{
3342
+ "@id": "http://example/s",
3343
+ "http://example/p": [{
3344
+ "@id": {
3345
+ "@id": "http://example/s1",
3346
+ "http://example/p1": [{"@value": "o1"}]
3347
+ }
3348
+ }]
3349
+ }]),
3350
+ context: %({"ex": "http://example/"}),
3351
+ output: %({
3352
+ "@context": {"ex": "http://example/"},
3353
+ "@id": "ex:s",
3354
+ "ex:p": {
3355
+ "@id": {
3356
+ "@id": "ex:s1",
3357
+ "ex:p1": "o1"
3358
+ }
3359
+ }
3360
+ })
3361
+ },
3362
+ "recursive-subject": {
3363
+ input: %([{
3364
+ "@id": {
3365
+ "@id": {
3366
+ "@id": "http://example/s2",
3367
+ "http://example/p2": [{"@id": "http://example/o2"}]
3368
+ },
3369
+ "http://example/p1": [{"@id": "http://example/o1"}]
3370
+ },
3371
+ "http://example/p": [{"@id": "http://example/o"}]
3372
+ }]),
3373
+ context: %({"ex": "http://example/"}),
3374
+ output: %({
3375
+ "@context": {"ex": "http://example/"},
3376
+ "@id": {
3377
+ "@id": {
3378
+ "@id": "ex:s2",
3379
+ "ex:p2": {"@id": "ex:o2"}
3380
+ },
3381
+ "ex:p1": {"@id": "ex:o1"}
3382
+ },
3383
+ "ex:p": {"@id": "ex:o"}
3384
+ })
3385
+ },
3386
+ }.each do |name, params|
3387
+ it(name) {run_compact(params.merge(rdfstar: true))}
3388
+ end
3389
+ end
3116
3390
 
3117
3391
  context "problem cases" do
3118
3392
  {
@@ -3185,7 +3459,7 @@ describe JSON::LD::API do
3185
3459
  input = ::JSON.parse(input) if input.is_a?(String)
3186
3460
  output = ::JSON.parse(output) if output.is_a?(String)
3187
3461
  context = ::JSON.parse(context) if context.is_a?(String)
3188
- context = context['@context'] if context.has_key?('@context')
3462
+ context = context['@context'] if context.key?('@context')
3189
3463
  pending params.fetch(:pending, "test implementation") unless input
3190
3464
  if params[:exception]
3191
3465
  expect {JSON::LD::API.compact(input, context, logger: logger, **params)}.to raise_error(params[:exception])
@@ -3200,8 +3474,8 @@ describe JSON::LD::API do
3200
3474
  expect(jld).to produce_jsonld(output, logger)
3201
3475
 
3202
3476
  # Compare expanded jld/output too to make sure list values remain ordered
3203
- exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1')
3204
- exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1')
3477
+ exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1', rdfstar: params[:rdfstar])
3478
+ exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1', rdfstar: params[:rdfstar])
3205
3479
  expect(exp_jld).to produce_jsonld(exp_output, logger)
3206
3480
  end
3207
3481
  end
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"],