|
654 | 654 | "result": {"@id": "mf:result", "@type": "xsd:boolean"} |
655 | 655 | }, |
656 | 656 | "@graph": [{ |
657 | | - "@id": "_:b0", |
658 | 657 | "@type": "mf:Manifest", |
659 | 658 | "comment": "Positive processor tests", |
660 | 659 | "entries": [{ |
661 | | - "@id": "_:b1", |
662 | 660 | "@type": "mf:ManifestEntry", |
663 | 661 | "action": { |
664 | | - "@id": "_:b2", |
665 | 662 | "@type": "mq:QueryTest", |
666 | 663 | "data": "http://www.w3.org/TR/microdata-rdf/tests/0001.html", |
667 | 664 | "query": "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl" |
|
1135 | 1132 | "@graph": [{ |
1136 | 1133 | "@id": "urn:id-1", |
1137 | 1134 | "@type": "Class", |
1138 | | - "preserve": { |
1139 | | - "@id": "_:b0" |
1140 | | - } |
| 1135 | + "preserve": {} |
1141 | 1136 | }] |
1142 | 1137 | }) |
1143 | 1138 | }, |
|
1260 | 1255 | "term": "foo" |
1261 | 1256 | }, |
1262 | 1257 | "preserve": { |
1263 | | - "@id": "_:b0", |
1264 | 1258 | "deep": { |
1265 | | - "@id": "_:b1", |
1266 | 1259 | "@graph": [{ |
1267 | 1260 | "@id": "urn:id-3", |
1268 | 1261 | "term": "bar" |
|
1338 | 1331 | end |
1339 | 1332 | end |
1340 | 1333 |
|
| 1334 | + describe "pruneBlankNodeIdentifiers" do |
| 1335 | + it "preserves single-use bnode identifiers if option set to false" do |
| 1336 | + do_frame( |
| 1337 | + input: %({ |
| 1338 | + "@context": { |
| 1339 | + "dc0": "http://purl.org/dc/terms/", |
| 1340 | + "dc:creator": { |
| 1341 | + "@type": "@id" |
| 1342 | + }, |
| 1343 | + "foaf": "http://xmlns.com/foaf/0.1/", |
| 1344 | + "ps": "http://purl.org/payswarm#" |
| 1345 | + }, |
| 1346 | + "@id": "http://example.com/asset", |
| 1347 | + "@type": "ps:Asset", |
| 1348 | + "dc:creator": { |
| 1349 | + "foaf:name": "John Doe" |
| 1350 | + } |
| 1351 | + }), |
| 1352 | + frame: %({ |
| 1353 | + "@context": { |
| 1354 | + "dc": "http://purl.org/dc/terms/", |
| 1355 | + "dc:creator": { |
| 1356 | + "@type": "@id" |
| 1357 | + }, |
| 1358 | + "foaf": "http://xmlns.com/foaf/0.1/", |
| 1359 | + "ps": "http://purl.org/payswarm#" |
| 1360 | + }, |
| 1361 | + "@id": "http://example.com/asset", |
| 1362 | + "@type": "ps:Asset", |
| 1363 | + "dc:creator": {} |
| 1364 | + }), |
| 1365 | + output: %({ |
| 1366 | + "@context": { |
| 1367 | + "dc": "http://purl.org/dc/terms/", |
| 1368 | + "dc:creator": { |
| 1369 | + "@type": "@id" |
| 1370 | + }, |
| 1371 | + "foaf": "http://xmlns.com/foaf/0.1/", |
| 1372 | + "ps": "http://purl.org/payswarm#" |
| 1373 | + }, |
| 1374 | + "@graph": [ |
| 1375 | + { |
| 1376 | + "@id": "http://example.com/asset", |
| 1377 | + "@type": "ps:Asset", |
| 1378 | + "dc:creator": { |
| 1379 | + "@id": "_:b0", |
| 1380 | + "foaf:name": "John Doe" |
| 1381 | + } |
| 1382 | + } |
| 1383 | + ] |
| 1384 | + }), |
| 1385 | + prune: false |
| 1386 | + ) |
| 1387 | + end |
| 1388 | + end |
| 1389 | + |
1341 | 1390 | context "problem cases" do |
1342 | 1391 | it "pr #20" do |
1343 | | - expanded = [ |
| 1392 | + expanded = %([ |
1344 | 1393 | { |
1345 | | - "@id"=>"_:gregg", |
1346 | | - "@type"=>"http://xmlns.com/foaf/0.1/Person", |
1347 | | - "http://xmlns.com/foaf/0.1/name" => "Gregg Kellogg" |
| 1394 | + "@id": "_:gregg", |
| 1395 | + "@type": "http://xmlns.com/foaf/0.1/Person", |
| 1396 | + "http://xmlns.com/foaf/0.1/name": "Gregg Kellogg" |
1348 | 1397 | }, { |
1349 | | - "@id"=>"http://manu.sporny.org/#me", |
1350 | | - "@type"=> "http://xmlns.com/foaf/0.1/Person", |
1351 | | - "http://xmlns.com/foaf/0.1/knows"=> {"@id"=>"_:gregg"}, |
1352 | | - "http://xmlns.com/foaf/0.1/name"=>"Manu Sporny" |
| 1398 | + "@id": "http://manu.sporny.org/#me", |
| 1399 | + "@type": "http://xmlns.com/foaf/0.1/Person", |
| 1400 | + "http://xmlns.com/foaf/0.1/knows": {"@id": "_:gregg"}, |
| 1401 | + "http://xmlns.com/foaf/0.1/name": "Manu Sporny" |
1353 | 1402 | } |
1354 | | - ] |
1355 | | - framed = JSON::LD::API.frame(expanded, {}) |
1356 | | - data = framed["@graph"].first |
1357 | | - expect(data["mising_value"]).to be_nil |
| 1403 | + ]) |
| 1404 | + expected = %({ |
| 1405 | + "@graph": [ |
| 1406 | + { |
| 1407 | + "@id": "_:b0", |
| 1408 | + "@type": "http://xmlns.com/foaf/0.1/Person", |
| 1409 | + "http://xmlns.com/foaf/0.1/name": "Gregg Kellogg" |
| 1410 | + }, |
| 1411 | + { |
| 1412 | + "@id": "http://manu.sporny.org/#me", |
| 1413 | + "@type": "http://xmlns.com/foaf/0.1/Person", |
| 1414 | + "http://xmlns.com/foaf/0.1/knows": { |
| 1415 | + "@id": "_:b0", |
| 1416 | + "@type": "http://xmlns.com/foaf/0.1/Person", |
| 1417 | + "http://xmlns.com/foaf/0.1/name": "Gregg Kellogg" |
| 1418 | + }, |
| 1419 | + "http://xmlns.com/foaf/0.1/name": "Manu Sporny" |
| 1420 | + } |
| 1421 | + ] |
| 1422 | + }) |
| 1423 | + do_frame(input: expanded, frame: {}, output: expected) |
1358 | 1424 | end |
1359 | 1425 |
|
1360 | 1426 | it "issue #28" do |
|
1417 | 1483 |
|
1418 | 1484 | def do_frame(params) |
1419 | 1485 | begin |
1420 | | - input, frame, output = params[:input], params[:frame], params[:output] |
| 1486 | + input, frame, output, prune = params[:input], params[:frame], params[:output], params.fetch(:prune, true) |
1421 | 1487 | input = ::JSON.parse(input) if input.is_a?(String) |
1422 | 1488 | frame = ::JSON.parse(frame) if frame.is_a?(String) |
1423 | 1489 | output = ::JSON.parse(output) if output.is_a?(String) |
1424 | | - jld = JSON::LD::API.frame(input, frame, logger: logger) |
| 1490 | + jld = JSON::LD::API.frame(input, frame, logger: logger, pruneBlankNodeIdentifiers: prune) |
1425 | 1491 | expect(jld).to produce(output, logger) |
1426 | 1492 | rescue JSON::LD::JsonLdError => e |
1427 | 1493 | fail("#{e.class}: #{e.message}\n" + |
|
0 commit comments