Method: JSON::LD::API.toRDF
- Defined in:
- lib/json/ld/api.rb
.toRDF(input, context = nil, options = {}) {|statement| ... } ⇒ Array<RDF::Statement>
Processes the input according to the RDF Conversion Algorithm, calling the provided callback for each triple generated.
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/json/ld/api.rb', line 348 def self.toRDF(input, context = nil, = {}, &block) results = [] results.extend(RDF::Enumerable) # Expand input to simplify processing = API.(input, context, ) API.new(, context, ) do # 1) Perform the Expansion Algorithm on the JSON-LD input. # This removes any existing context to allow the given context to be cleanly applied. debug(".toRDF") {"expanded input: #{.to_json(JSON_STATE)}"} # Generate _nodeMap_ node_map = Hash.ordered node_map['@default'] = Hash.ordered generate_node_map(, node_map) debug(".toRDF") {"node map: #{node_map.to_json(JSON_STATE)}"} # Start generating statements node_map.each do |graph_name, graph| context = as_resource(graph_name) unless graph_name == '@default' debug(".toRDF") {"context: #{context ? context.to_ntriples : 'null'}"} graph_to_rdf(graph).each do |statement| next if statement.predicate.node? && ![:produceGeneralizedRDF] statement.context = context if context if block_given? yield statement else results << statement end end end end results end |