Skip to content

Commit 226e05d

Browse files
committed
Set default for omitGraph based on processingMode.
1 parent 5b86c7b commit 226e05d

File tree

3 files changed

+72
-87
lines changed

3 files changed

+72
-87
lines changed

lib/json/ld/api.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class API
8686
# @yieldparam [API]
8787
# @raise [JsonLdError]
8888
def initialize(input, context, rename_bnodes: true, unique_bnodes: false, **options, &block)
89-
#require 'byebug'; byebug
9089
@options = {
9190
compactArrays: true,
9291
documentLoader: self.class.method(:documentLoader)
@@ -340,7 +339,6 @@ def self.frame(input, frame, expanded: false, **options)
340339
explicit: false,
341340
requireAll: true,
342341
omitDefault: false,
343-
omitGraph: false,
344342
documentLoader: method(:documentLoader)
345343
}.merge(options)
346344

@@ -377,6 +375,11 @@ def self.frame(input, frame, expanded: false, **options)
377375
log_debug(".frame") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
378376
log_debug(".frame") {"expanded frame: #{expanded_frame.to_json(JSON_STATE) rescue 'malformed json'}"}
379377

378+
# Set omitGraph option, if not present, based on processingMode
379+
unless options.has_key?(:omitGraph)
380+
options[:omitGraph] = @options[:processingMode] != 'json-ld-1.0'
381+
end
382+
380383
# Get framing nodes from expanded input, replacing Blank Node identifiers as necessary
381384
create_node_map(value, framing_state[:graphMap], active_graph: '@default')
382385

spec/frame_spec.rb

Lines changed: 66 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -652,20 +652,18 @@
652652
"query": {"@id": "mq:query", "@type": "@id"},
653653
"result": {"@id": "mf:result", "@type": "xsd:boolean"}
654654
},
655-
"@graph": [{
656-
"@type": "mf:Manifest",
657-
"comment": "Positive processor tests",
658-
"entries": [{
659-
"@type": "mf:ManifestEntry",
660-
"action": {
661-
"@type": "mq:QueryTest",
662-
"data": "http://www.w3.org/TR/microdata-rdf/tests/0001.html",
663-
"query": "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl"
664-
},
665-
"comment": "Item with no itemtype and literal itemprop",
666-
"mf:result": "true",
667-
"name": "Test 0001"
668-
}]
655+
"@type": "mf:Manifest",
656+
"comment": "Positive processor tests",
657+
"entries": [{
658+
"@type": "mf:ManifestEntry",
659+
"action": {
660+
"@type": "mq:QueryTest",
661+
"data": "http://www.w3.org/TR/microdata-rdf/tests/0001.html",
662+
"query": "http://www.w3.org/TR/microdata-rdf/tests/0001.ttl"
663+
},
664+
"comment": "Item with no itemtype and literal itemprop",
665+
"mf:result": "true",
666+
"name": "Test 0001"
669667
}]
670668
}),
671669
processingMode: 'json-ld-1.1'
@@ -1129,11 +1127,9 @@
11291127
}),
11301128
output: %({
11311129
"@context": {"@vocab": "urn:"},
1132-
"@graph": [{
1133-
"@id": "urn:id-1",
1134-
"@type": "Class",
1135-
"preserve": {}
1136-
}]
1130+
"@id": "urn:id-1",
1131+
"@type": "Class",
1132+
"preserve": {}
11371133
}),
11381134
processingMode: 'json-ld-1.1'
11391135
},
@@ -1157,17 +1153,15 @@
11571153
}),
11581154
output: %({
11591155
"@context": {"@vocab": "urn:"},
1160-
"@graph": [{
1161-
"@id": "urn:id-1",
1162-
"@type": "Class",
1163-
"preserve": {
1164-
"@id": "urn:gr-1",
1165-
"@graph": {
1166-
"@id": "urn:id-2",
1167-
"term": "data"
1168-
}
1156+
"@id": "urn:id-1",
1157+
"@type": "Class",
1158+
"preserve": {
1159+
"@id": "urn:gr-1",
1160+
"@graph": {
1161+
"@id": "urn:id-2",
1162+
"term": "data"
11691163
}
1170-
}]
1164+
}
11711165
}),
11721166
processingMode: 'json-ld-1.1'
11731167
},
@@ -1200,21 +1194,19 @@
12001194
}),
12011195
output: %({
12021196
"@context": {"@vocab": "urn:"},
1203-
"@graph": [{
1204-
"@id": "urn:id-1",
1205-
"@type": "Class",
1206-
"merge": {
1207-
"@id": "urn:id-2",
1208-
"term": "foo"
1209-
},
1210-
"preserve": {
1211-
"@id": "urn:graph-1",
1212-
"@graph": {
1213-
"@id": "urn:id-3",
1214-
"term": "bar"
1215-
}
1197+
"@id": "urn:id-1",
1198+
"@type": "Class",
1199+
"merge": {
1200+
"@id": "urn:id-2",
1201+
"term": "foo"
1202+
},
1203+
"preserve": {
1204+
"@id": "urn:graph-1",
1205+
"@graph": {
1206+
"@id": "urn:id-3",
1207+
"term": "bar"
12161208
}
1217-
}]
1209+
}
12181210
}),
12191211
processingMode: 'json-ld-1.1'
12201212
},
@@ -1250,22 +1242,20 @@
12501242
}),
12511243
output: %({
12521244
"@context": {"@vocab": "urn:"},
1253-
"@graph": [{
1254-
"@id": "urn:id-1",
1255-
"@type": "Class",
1256-
"merge": {
1257-
"@id": "urn:id-2",
1258-
"term": "foo"
1259-
},
1260-
"preserve": {
1261-
"deep": {
1262-
"@graph": {
1263-
"@id": "urn:id-3",
1264-
"term": "bar"
1265-
}
1245+
"@id": "urn:id-1",
1246+
"@type": "Class",
1247+
"merge": {
1248+
"@id": "urn:id-2",
1249+
"term": "foo"
1250+
},
1251+
"preserve": {
1252+
"deep": {
1253+
"@graph": {
1254+
"@id": "urn:id-3",
1255+
"term": "bar"
12661256
}
12671257
}
1268-
}]
1258+
}
12691259
}),
12701260
processingMode: 'json-ld-1.1'
12711261
},
@@ -1301,28 +1291,24 @@
13011291
}),
13021292
output: %({
13031293
"@context": {"@vocab": "http://example.org/"},
1304-
"@graph": [
1305-
{
1306-
"@id": "http://example.org/library",
1307-
"@type": "Library",
1308-
"name": "Library",
1294+
"@id": "http://example.org/library",
1295+
"@type": "Library",
1296+
"name": "Library",
1297+
"contains": {
1298+
"@id": "http://example.org/graphs/books",
1299+
"@graph": {
1300+
"@id": "http://example.org/library/the-republic",
1301+
"@type": "Book",
1302+
"creator": "Plato",
1303+
"title": "The Republic",
13091304
"contains": {
1310-
"@id": "http://example.org/graphs/books",
1311-
"@graph": {
1312-
"@id": "http://example.org/library/the-republic",
1313-
"@type": "Book",
1314-
"creator": "Plato",
1315-
"title": "The Republic",
1316-
"contains": {
1317-
"@id": "http://example.org/library/the-republic#introduction",
1318-
"@type": "Chapter",
1319-
"description": "An introductory chapter on The Republic.",
1320-
"title": "The Introduction"
1321-
}
1322-
}
1305+
"@id": "http://example.org/library/the-republic#introduction",
1306+
"@type": "Chapter",
1307+
"description": "An introductory chapter on The Republic.",
1308+
"title": "The Introduction"
13231309
}
13241310
}
1325-
]
1311+
}
13261312
}),
13271313
processingMode: 'json-ld-1.1'
13281314
}
@@ -1523,14 +1509,10 @@
15231509
},
15241510
"id": "@id"
15251511
},
1526-
"@graph": [
1527-
{
1528-
"claim": {
1529-
"id": "ex:1",
1530-
"test": "foo"
1531-
}
1532-
}
1533-
]
1512+
"claim": {
1513+
"id": "ex:1",
1514+
"test": "foo"
1515+
}
15341516
})
15351517
do_frame(input: input, frame: frame, output: expected, processingMode: 'json-ld-1.1')
15361518
end

spec/suite_frame_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::FRAME_SUITE}frame-manifest.jsonld")
88
describe m.name do
99
m.entries.each do |t|
10-
specify "#{t.property('input')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
10+
specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
1111
t.run self
1212
end
1313
end

0 commit comments

Comments
 (0)