Navigation Menu

Skip to content

Commit

Permalink
Fix bug expanding datatypes with @vocab.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Sep 11, 2012
1 parent 72b6d2f commit 716c60d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/json/ld/evaluation_context.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/json/ld/flatten.rb
Expand Up @@ -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.
Expand Down
68 changes: 68 additions & 0 deletions spec/expand_spec.rb
Expand Up @@ -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" => {
Expand Down

0 comments on commit 716c60d

Please sign in to comment.