Skip to content

Commit 54ebbdf

Browse files
committed
Remove pruneBlankNodeIdentifiers and just use processingMode.
1 parent 68eccf9 commit 54ebbdf

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

lib/json/ld/api.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ class API
7272
# @option options [Boolean, String, RDF::URI] :flatten
7373
# If set to a value that is not `false`, the JSON-LD processor must modify the output of the Compaction Algorithm or the Expansion Algorithm by coalescing all properties associated with each subject via the Flattening Algorithm. The value of `flatten must` be either an _IRI_ value representing the name of the graph to flatten, or `true`. If the value is `true`, then the first graph encountered in the input document is selected and flattened.
7474
# @option options [String] :processingMode
75-
# Processing mode, json-ld-1.0 or json-ld-1.1. Also can have other values:
76-
#
77-
# * json-ld-1.1-expand-frame – special frame expansion mode.
78-
#
75+
# Processing mode, json-ld-1.0 or json-ld-1.1.
7976
# If `processingMode` is not specified, a mode of `json-ld-1.0` or `json-ld-1.1` is set, the context used for `expansion` or `compaction`.
8077
# @option options [Boolean] :rename_bnodes (true)
8178
# Rename bnodes as part of expansion, or keep them the same.
@@ -321,7 +318,6 @@ def self.flatten(input, context, expanded: false, **options)
321318
# @option options [Boolean] :omitDefault (false)
322319
# a flag specifying that properties that are missing from the JSON-LD input should be omitted from the output.
323320
# @option options [Boolean] :expanded Input is already expanded
324-
# @option options [Boolean] :pruneBlankNodeIdentifiers (true) removes blank node identifiers that are only used once.
325321
# @option options [Boolean] :omitGraph does not use `@graph` at top level unless necessary to describe multiple objects, defaults to `true` if processingMode is 1.1, otherwise `false`.
326322
# @yield jsonld
327323
# @yieldparam [Hash] jsonld
@@ -342,7 +338,6 @@ def self.frame(input, frame, expanded: false, **options)
342338
requireAll: true,
343339
omitDefault: false,
344340
omitGraph: false,
345-
pruneBlankNodeIdentifiers: true,
346341
documentLoader: method(:documentLoader)
347342
}.merge(options)
348343

@@ -399,7 +394,7 @@ def self.frame(input, frame, expanded: false, **options)
399394
frame(framing_state, framing_state[:subjects].keys.sort, (expanded_frame.first || {}), parent: result, **options)
400395

401396
# Count blank node identifiers used in the document, if pruning
402-
if options[:pruneBlankNodeIdentifiers]
397+
unless @options[:processingMode] == 'json-ld-1.0'
403398
bnodes_to_clear = count_blank_node_identifiers(result).collect {|k, v| k if v == 1}.compact
404399
result = prune_bnodes(result, bnodes_to_clear)
405400
end

spec/frame_spec.rb

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@
667667
"name": "Test 0001"
668668
}]
669669
}]
670-
})
670+
}),
671+
processingMode: 'json-ld-1.1'
671672
},
672673
"library" => {
673674
frame: %({
@@ -1133,7 +1134,8 @@
11331134
"@type": "Class",
11341135
"preserve": {}
11351136
}]
1136-
})
1137+
}),
1138+
processingMode: 'json-ld-1.1'
11371139
},
11381140
"Frame default graph if outer @graph is used" => {
11391141
frame: %({
@@ -1166,7 +1168,8 @@
11661168
}
11671169
}
11681170
}]
1169-
})
1171+
}),
1172+
processingMode: 'json-ld-1.1'
11701173
},
11711174
"Merge one graph and preserve another" => {
11721175
frame: %({
@@ -1212,7 +1215,8 @@
12121215
}
12131216
}
12141217
}]
1215-
})
1218+
}),
1219+
processingMode: 'json-ld-1.1'
12161220
},
12171221
"Merge one graph and deep preserve another" => {
12181222
frame: %({
@@ -1262,7 +1266,8 @@
12621266
}
12631267
}
12641268
}]
1265-
})
1269+
}),
1270+
processingMode: 'json-ld-1.1'
12661271
},
12671272
"library" => {
12681273
frame: %({
@@ -1318,7 +1323,8 @@
13181323
}
13191324
}
13201325
]
1321-
})
1326+
}),
1327+
processingMode: 'json-ld-1.1'
13221328
}
13231329
}.each do |title, params|
13241330
it title do
@@ -1328,8 +1334,8 @@
13281334
end
13291335
end
13301336

1331-
describe "pruneBlankNodeIdentifiers" do
1332-
it "preserves single-use bnode identifiers if option set to false" do
1337+
describe "prune blank nodes" do
1338+
it "preserves single-use bnode identifiers if @version 1.0" do
13331339
do_frame(
13341340
input: %({
13351341
"@context": {
@@ -1378,8 +1384,7 @@
13781384
}
13791385
}
13801386
]
1381-
}),
1382-
prune: false
1387+
})
13831388
)
13841389
end
13851390
end
@@ -1477,7 +1482,7 @@
14771482
do_frame(input: input, frame: frame, output: expected)
14781483
end
14791484

1480-
it "framing with @container: @graph assumes pruneBnodeIdentifiers" do
1485+
it "framing with @version: 1.1 prunes identifiers" do
14811486
input = JSON.parse %({
14821487
"@context": {
14831488
"@version": 1.1,
@@ -1527,17 +1532,17 @@
15271532
}
15281533
]
15291534
})
1530-
do_frame(input: input, frame: frame, output: expected)
1535+
do_frame(input: input, frame: frame, output: expected, processingMode: 'json-ld-1.1')
15311536
end
15321537
end
15331538

15341539
def do_frame(params)
15351540
begin
1536-
input, frame, output, prune = params[:input], params[:frame], params[:output], params.fetch(:prune, true)
1541+
input, frame, output, processingMode = params[:input], params[:frame], params[:output], params.fetch(:processingMode, 'json-ld-1.0')
15371542
input = ::JSON.parse(input) if input.is_a?(String)
15381543
frame = ::JSON.parse(frame) if frame.is_a?(String)
15391544
output = ::JSON.parse(output) if output.is_a?(String)
1540-
jld = JSON::LD::API.frame(input, frame, logger: logger, pruneBlankNodeIdentifiers: prune)
1545+
jld = JSON::LD::API.frame(input, frame, logger: logger, processingMode: processingMode)
15411546
expect(jld).to produce(output, logger)
15421547
rescue JSON::LD::JsonLdError => e
15431548
fail("#{e.class}: #{e.message}\n" +

0 commit comments

Comments
 (0)