lib/json/ld/api.rb in json-ld-0.1.2 vs lib/json/ld/api.rb in json-ld-0.1.3

- old
+ new

@@ -115,11 +115,10 @@ # @param [Hash{Symbol => Object}] options # Other options passed to {#expand} # @option options [Boolean] :optimize (false) # Perform further optimmization of the compacted output. # (Presently, this is a noop). - # @param [Hash{Symbol => Object}] options # @yield jsonld # @yieldparam [Hash] jsonld # The compacted JSON-LD document # @return [Hash] # The compacted JSON-LD document @@ -128,19 +127,14 @@ def self.compact(input, context, callback = nil, options = {}) expanded = result = nil # 1) Perform the Expansion Algorithm on the JSON-LD input. # This removes any existing context to allow the given context to be cleanly applied. - API.new(input, nil, options) do - expanded = expand(value, nil, self.context) - debug(".compact") {"expanded input: #{value.to_json(JSON_STATE)}"} + expanded = API.expand(input, nil, nil, options) - # x) If no context provided, use context from input document - context ||= value.fetch('@context', nil) - end - API.new(expanded, context, options) do + debug(".compact") {"expanded input: #{expanded.to_json(JSON_STATE)}"} result = compact(value, nil) # xxx) Add the given context to the output result = case result when Hash then self.context.serialize.merge(result) @@ -263,11 +257,10 @@ # An external context to use additionally to the context embedded in input when expanding the input. # @param [Proc] callback (&block) # Alternative to using block, with same parameteres. # @param [{Symbol,String => Object}] options # Options passed to {#expand} - # @param [Hash{Symbol => Object}] options # @raise [InvalidContext] # @yield statement # @yieldparam [RDF::Statement] statement def self.toRDF(input, context = nil, callback = nil, options = {}) # 1) Perform the Expansion Algorithm on the JSON-LD input. @@ -293,19 +286,20 @@ # # @param [Array<RDF::Statement>] input # @param [Proc] callback (&block) # Alternative to using block, with same parameteres. # @param [Hash{Symbol => Object}] options + # @option options [Boolean] :notType don't use @type for rdf:type # @yield jsonld # @yieldparam [Hash] jsonld # The JSON-LD document in expanded form # @return [Array<Hash>] # The JSON-LD document in expanded form def self.fromRDF(input, callback = nil, options = {}) result = nil API.new(nil, nil, options) do |api| - result = api.from_statements(input, BlankNodeNamer.new("t")) + result = api.from_statements(input) end callback.call(result) if callback yield result if block_given? result