Skip to content

Commit

Permalink
Finish 3.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 25, 2020
2 parents 4619258 + 6dc0dc6 commit 65dd9c0
Show file tree
Hide file tree
Showing 5 changed files with 410 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.6
3.1.7
11 changes: 9 additions & 2 deletions lib/json/ld/compact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ def compact(element,
log_debug("", depth: log_depth.to_i) {"#{expanded_property}: #{expanded_value.inspect}"}

if expanded_property == '@id'
compacted_value = Array(expanded_value).map do |expanded_id|
context.compact_iri(expanded_id, base: @options[:base])
compacted_value = as_array(expanded_value).map do |expanded_id|
if node?(expanded_id) && @options[:rdfstar]
# This can only really happen for valid RDF*
compact(expanded_id, base: base,
property: '@id',
log_depth: log_depth.to_i + 1)
else
context.compact_iri(expanded_id, base: @options[:base])
end
end

kw_alias = context.compact_iri('@id', vocab: true)
Expand Down
2 changes: 1 addition & 1 deletion lib/json/ld/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ def find_definition(term)
# @param [Term, #to_s] term in unexpanded form
# @return [Array<'@index', '@language', '@index', '@set', '@type', '@id', '@graph'>]
def container(term)
return [term] if term == '@list'
return Set[term] if term == '@list'
term = find_definition(term)
term ? term.container_mapping : Set.new
end
Expand Down
208 changes: 206 additions & 2 deletions spec/compact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3113,6 +3113,210 @@
end
end

context "JSON-LD*" do
{
"subject-iii": {
input: %([{
"@id": {
"@id": "http://example/s1",
"http://example/p1": [{"@id": "http://example/o1"}]
},
"http://example/p": [{"@id": "http://example/o"}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": {
"@id": "ex:s1",
"ex:p1": {"@id": "ex:o1"}
},
"ex:p": {"@id": "ex:o"}
})
},
"subject-iib": {
input: %([{
"@id": {
"@id": "http://example/s1",
"http://example/p1": [{"@id": "_:o1"}]
},
"http://example/p": [{"@id": "http://example/o"}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": {
"@id": "ex:s1",
"ex:p1": {"@id": "_:o1"}
},
"ex:p": {"@id": "ex:o"}
})
},
"subject-iil": {
input: %([{
"@id": {
"@id": "http://example/s1",
"http://example/p1": [{"@value": "o1"}]
},
"http://example/p": [{"@id": "http://example/o"}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": {
"@id": "ex:s1",
"ex:p1": "o1"
},
"ex:p": {"@id": "ex:o"}
})
},
"subject-bii": {
input: %([{
"@id": {
"@id": "_:s1",
"http://example/p1": [{"@id": "http://example/o1"}]
},
"http://example/p": [{"@id": "http://example/o"}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": {
"@id": "_:s1",
"ex:p1": {"@id": "ex:o1"}
},
"ex:p": {"@id": "ex:o"}
})
},
"subject-bib": {
input: %([{
"@id": {
"@id": "_:s1",
"http://example/p1": [{"@id": "_:o1"}]
},
"http://example/p": [{"@id": "http://example/o"}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": {
"@id": "_:s1",
"ex:p1": {"@id": "_:o1"}
},
"ex:p": {"@id": "ex:o"}
})
},
"subject-bil": {
input: %([{
"@id": {
"@id": "_:s1",
"http://example/p1": [{"@value": "o1"}]
},
"http://example/p": [{"@id": "http://example/o"}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": {
"@id": "_:s1",
"ex:p1": "o1"
},
"ex:p": {"@id": "ex:o"}
})
},
"object-iii": {
input: %([{
"@id": "http://example/s",
"http://example/p": [{
"@id": {
"@id": "http://example/s1",
"http://example/p1": [{"@id": "http://example/o1"}]
}
}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": "ex:s",
"ex:p": {
"@id": {
"@id": "ex:s1",
"ex:p1": {"@id": "ex:o1"}
}
}
})
},
"object-iib": {
input: %([{
"@id": "http://example/s",
"http://example/p": [{
"@id": {
"@id": "http://example/s1",
"http://example/p1": [{"@id": "_:o1"}]
}
}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": "ex:s",
"ex:p": {
"@id": {
"@id": "ex:s1",
"ex:p1": {"@id": "_:o1"}
}
}
})
},
"object-iil": {
input: %([{
"@id": "http://example/s",
"http://example/p": [{
"@id": {
"@id": "http://example/s1",
"http://example/p1": [{"@value": "o1"}]
}
}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": "ex:s",
"ex:p": {
"@id": {
"@id": "ex:s1",
"ex:p1": "o1"
}
}
})
},
"recursive-subject": {
input: %([{
"@id": {
"@id": {
"@id": "http://example/s2",
"http://example/p2": [{"@id": "http://example/o2"}]
},
"http://example/p1": [{"@id": "http://example/o1"}]
},
"http://example/p": [{"@id": "http://example/o"}]
}]),
context: %({"ex": "http://example/"}),
output: %({
"@context": {"ex": "http://example/"},
"@id": {
"@id": {
"@id": "ex:s2",
"ex:p2": {"@id": "ex:o2"}
},
"ex:p1": {"@id": "ex:o1"}
},
"ex:p": {"@id": "ex:o"}
})
},
}.each do |name, params|
it(name) {run_compact(params.merge(rdfstar: true))}
end
end

context "problem cases" do
{
Expand Down Expand Up @@ -3200,8 +3404,8 @@ def run_compact(params)
expect(jld).to produce_jsonld(output, logger)

# Compare expanded jld/output too to make sure list values remain ordered
exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1')
exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1')
exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1', rdfstar: params[:rdfstar])
exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1', rdfstar: params[:rdfstar])
expect(exp_jld).to produce_jsonld(exp_output, logger)
end
end
Expand Down
Loading

0 comments on commit 65dd9c0

Please sign in to comment.