diff --git a/lib/json/ld/evaluation_context.rb b/lib/json/ld/evaluation_context.rb index 0128cbbb..7c424ceb 100644 --- a/lib/json/ld/evaluation_context.rb +++ b/lib/json/ld/evaluation_context.rb @@ -476,7 +476,7 @@ def expand_iri(iri, options = {}) prefix, suffix = iri.split(':', 2) return mapping(iri) if mapping(iri) # If it's an exact match debug("expand_iri") {"prefix: #{prefix.inspect}, suffix: #{suffix.inspect}, vocab: #{vocab.inspect}"} unless options[:quiet] - base = self.base unless [:predicate, :datatype].include?(options[:position]) + base = [:subject, :object].include?(options[:position]) ? self.base : nil prefix = prefix.to_s case when prefix == '_' && suffix then bnode(suffix) diff --git a/lib/json/ld/flatten.rb b/lib/json/ld/flatten.rb index 12079ca4..586370ea 100644 --- a/lib/json/ld/flatten.rb +++ b/lib/json/ld/flatten.rb @@ -71,7 +71,7 @@ def generate_node_map(element, node_map, graph, list, namer, id = nil) # If one does not already exist, add a node reference for v into node for property. node[prop] ||= [] node[prop] << {'@id' => name} unless node[prop].any? {|n| - node_ref?(n) && n['@id'] == name + node_reference?(n) && n['@id'] == name } # Recursively call this algorithm passing v for value, nodeMap, graph, and nil for list. diff --git a/spec/expand_spec.rb b/spec/expand_spec.rb index d9704442..95fb27e1 100644 --- a/spec/expand_spec.rb +++ b/spec/expand_spec.rb @@ -416,6 +416,74 @@ end end + context "default vocabulary" do + { + "property" => { + :input => { + "@context" => {"@vocab" => "http://example.com/"}, + "verb" => {"@value" => "foo"} + }, + :output => [{ + "http://example.com/verb" => [{"@value" => "foo"}] + }] + }, + "datatype" => { + :input => { + "@context" => {"@vocab" => "http://example.com/"}, + "http://example.org/verb" => {"@value" => "foo", "@type" => "string"} + }, + :output => [ + "http://example.org/verb" => [{"@value" => "foo", "@type" => "http://example.com/string"}] + ] + }, + "expand-0028" => { + :input => { + "@context" => { + "@vocab" => "http://example.org/vocab#", + "date" => { "@type" => "dateTime" } + }, + "@id" => "example1", + "@type" => "test", + "date" => "2011-01-25T00:00:00Z", + "embed" => { + "@id" => "example2", + "expandedDate" => { "@value" => "2012-08-01T00:00:00Z", "@type" => "dateTime" } + } + }, + :output => [ + { + "@id" => "http://foo/bar/example1", + "@type" => ["http://example.org/vocab#test"], + "http://example.org/vocab#date" => [ + { + "@value" => "2011-01-25T00:00:00Z", + "@type" => "http://example.org/vocab#dateTime" + } + ], + "http://example.org/vocab#embed" => [ + { + "@id" => "http://foo/bar/example2", + "http://example.org/vocab#expandedDate" => [ + { + "@value" => "2012-08-01T00:00:00Z", + "@type" => "http://example.org/vocab#dateTime" + } + ] + } + ] + } + ] + } + }.each do |title, params| + it title do + jld = JSON::LD::API.expand(params[:input], nil, nil, + :base => "http://foo/bar/", + :debug => @debug) + jld.should produce(params[:output], @debug) + end + end + end + context "unmapped properties" do { "unmapped key" => {