@@ -80,7 +80,6 @@ def initialize(input, context, options = {}, &block)
8080 @options [ :documentLoader ] ||= self . class . method ( :documentLoader )
8181 options [ :rename_bnodes ] ||= true
8282 @namer = options [ :rename_bnodes ] ? BlankNodeNamer . new ( "b" ) : BlankNodeMapper . new
83- content_type = nil
8483 @value = case input
8584 when Array , Hash then input . dup
8685 when IO , StringIO
@@ -219,8 +218,7 @@ def self.flatten(input, context, options = {})
219218 debug ( ".flatten" ) { "expanded input: #{ value . to_json ( JSON_STATE ) } " }
220219
221220 # Initialize node map to a JSON object consisting of a single member whose key is @default and whose value is an empty JSON object.
222- node_map = Hash . ordered
223- node_map [ '@default' ] = Hash . ordered
221+ node_map = { '@default' => { } }
224222 self . generate_node_map ( value , node_map )
225223
226224 default_graph = node_map [ '@default' ]
@@ -281,7 +279,6 @@ def self.flatten(input, context, options = {})
281279 # @see http://json-ld.org/spec/latest/json-ld-api/#framing-algorithm
282280 def self . frame ( input , frame , options = { } )
283281 result = nil
284- match_limit = 0
285282 framing_state = {
286283 :embed => true ,
287284 :explicit => false ,
@@ -319,7 +316,7 @@ def self.frame(input, frame, options = {})
319316 debug ( ".frame" ) { "expanded input: #{ value . to_json ( JSON_STATE ) } " }
320317
321318 # Get framing nodes from expanded input, replacing Blank Node identifiers as necessary
322- all_nodes = Hash . ordered
319+ all_nodes = { }
323320 old_dbg , @options [ :debug ] = @options [ :debug ] , nil
324321 depth do
325322 generate_node_map ( value , all_nodes )
@@ -360,24 +357,28 @@ def self.frame(input, frame, options = {})
360357 # @option options [Boolean] :produceGeneralizedRdf (false)
361358 # If true, output will include statements having blank node predicates, otherwise they are dropped.
362359 # @raise [JsonLdError]
363- # @return [Array<RDF::Statement>] if no block given
364360 # @yield statement
365361 # @yieldparam [RDF::Statement] statement
366362 def self . toRdf ( input , options = { } , &block )
367- results = [ ]
368- results . extend ( RDF ::Enumerable )
363+ unless block_given?
364+ results = [ ]
365+ results . extend ( RDF ::Enumerable )
366+ self . toRdf ( input , options ) do |stmt |
367+ results << stmt
368+ end
369+ return results
370+ end
369371
370372 # Expand input to simplify processing
371- expanded_input = API . expand ( input , options )
373+ expanded_input = API . expand ( input , options . merge ( :ordered => false ) )
372374
373375 API . new ( expanded_input , nil , options ) do
374376 # 1) Perform the Expansion Algorithm on the JSON-LD input.
375377 # This removes any existing context to allow the given context to be cleanly applied.
376378 debug ( ".toRdf" ) { "expanded input: #{ expanded_input . to_json ( JSON_STATE ) } " }
377379
378380 # Generate _nodeMap_
379- node_map = Hash . ordered
380- node_map [ '@default' ] = Hash . ordered
381+ node_map = { '@default' => { } }
381382 generate_node_map ( expanded_input , node_map )
382383 debug ( ".toRdf" ) { "node map: #{ node_map . to_json ( JSON_STATE ) } " }
383384
@@ -390,7 +391,7 @@ def self.toRdf(input, options = {}, &block)
390391 debug ( ".toRdf" ) { "drop relative graph_name: #{ statement . to_ntriples } " }
391392 next
392393 end
393- graph_to_rdf ( graph ) . each do |statement |
394+ graph_to_rdf ( graph ) do |statement |
394395 next if statement . predicate . node? && !options [ :produceGeneralizedRdf ]
395396 # Drop results with relative IRIs
396397 relative = statement . to_a . any? do |r |
0 commit comments