Skip to content

Commit 65dd9c0

Browse files
committed
Finish 3.1.7
2 parents 4619258 + 6dc0dc6 commit 65dd9c0

File tree

5 files changed

+410
-6
lines changed

5 files changed

+410
-6
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.6
1+
3.1.7

lib/json/ld/compact.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ def compact(element,
9898
log_debug("", depth: log_depth.to_i) {"#{expanded_property}: #{expanded_value.inspect}"}
9999

100100
if expanded_property == '@id'
101-
compacted_value = Array(expanded_value).map do |expanded_id|
102-
context.compact_iri(expanded_id, base: @options[:base])
101+
compacted_value = as_array(expanded_value).map do |expanded_id|
102+
if node?(expanded_id) && @options[:rdfstar]
103+
# This can only really happen for valid RDF*
104+
compact(expanded_id, base: base,
105+
property: '@id',
106+
log_depth: log_depth.to_i + 1)
107+
else
108+
context.compact_iri(expanded_id, base: @options[:base])
109+
end
103110
end
104111

105112
kw_alias = context.compact_iri('@id', vocab: true)

lib/json/ld/context.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ def find_definition(term)
10381038
# @param [Term, #to_s] term in unexpanded form
10391039
# @return [Array<'@index', '@language', '@index', '@set', '@type', '@id', '@graph'>]
10401040
def container(term)
1041-
return [term] if term == '@list'
1041+
return Set[term] if term == '@list'
10421042
term = find_definition(term)
10431043
term ? term.container_mapping : Set.new
10441044
end

spec/compact_spec.rb

+206-2
Original file line numberDiff line numberDiff line change
@@ -3113,6 +3113,210 @@
31133113
end
31143114
end
31153115

3116+
context "JSON-LD*" do
3117+
{
3118+
"subject-iii": {
3119+
input: %([{
3120+
"@id": {
3121+
"@id": "http://example/s1",
3122+
"http://example/p1": [{"@id": "http://example/o1"}]
3123+
},
3124+
"http://example/p": [{"@id": "http://example/o"}]
3125+
}]),
3126+
context: %({"ex": "http://example/"}),
3127+
output: %({
3128+
"@context": {"ex": "http://example/"},
3129+
"@id": {
3130+
"@id": "ex:s1",
3131+
"ex:p1": {"@id": "ex:o1"}
3132+
},
3133+
"ex:p": {"@id": "ex:o"}
3134+
})
3135+
},
3136+
"subject-iib": {
3137+
input: %([{
3138+
"@id": {
3139+
"@id": "http://example/s1",
3140+
"http://example/p1": [{"@id": "_:o1"}]
3141+
},
3142+
"http://example/p": [{"@id": "http://example/o"}]
3143+
}]),
3144+
context: %({"ex": "http://example/"}),
3145+
output: %({
3146+
"@context": {"ex": "http://example/"},
3147+
"@id": {
3148+
"@id": "ex:s1",
3149+
"ex:p1": {"@id": "_:o1"}
3150+
},
3151+
"ex:p": {"@id": "ex:o"}
3152+
})
3153+
},
3154+
"subject-iil": {
3155+
input: %([{
3156+
"@id": {
3157+
"@id": "http://example/s1",
3158+
"http://example/p1": [{"@value": "o1"}]
3159+
},
3160+
"http://example/p": [{"@id": "http://example/o"}]
3161+
}]),
3162+
context: %({"ex": "http://example/"}),
3163+
output: %({
3164+
"@context": {"ex": "http://example/"},
3165+
"@id": {
3166+
"@id": "ex:s1",
3167+
"ex:p1": "o1"
3168+
},
3169+
"ex:p": {"@id": "ex:o"}
3170+
})
3171+
},
3172+
"subject-bii": {
3173+
input: %([{
3174+
"@id": {
3175+
"@id": "_:s1",
3176+
"http://example/p1": [{"@id": "http://example/o1"}]
3177+
},
3178+
"http://example/p": [{"@id": "http://example/o"}]
3179+
}]),
3180+
context: %({"ex": "http://example/"}),
3181+
output: %({
3182+
"@context": {"ex": "http://example/"},
3183+
"@id": {
3184+
"@id": "_:s1",
3185+
"ex:p1": {"@id": "ex:o1"}
3186+
},
3187+
"ex:p": {"@id": "ex:o"}
3188+
})
3189+
},
3190+
"subject-bib": {
3191+
input: %([{
3192+
"@id": {
3193+
"@id": "_:s1",
3194+
"http://example/p1": [{"@id": "_:o1"}]
3195+
},
3196+
"http://example/p": [{"@id": "http://example/o"}]
3197+
}]),
3198+
context: %({"ex": "http://example/"}),
3199+
output: %({
3200+
"@context": {"ex": "http://example/"},
3201+
"@id": {
3202+
"@id": "_:s1",
3203+
"ex:p1": {"@id": "_:o1"}
3204+
},
3205+
"ex:p": {"@id": "ex:o"}
3206+
})
3207+
},
3208+
"subject-bil": {
3209+
input: %([{
3210+
"@id": {
3211+
"@id": "_:s1",
3212+
"http://example/p1": [{"@value": "o1"}]
3213+
},
3214+
"http://example/p": [{"@id": "http://example/o"}]
3215+
}]),
3216+
context: %({"ex": "http://example/"}),
3217+
output: %({
3218+
"@context": {"ex": "http://example/"},
3219+
"@id": {
3220+
"@id": "_:s1",
3221+
"ex:p1": "o1"
3222+
},
3223+
"ex:p": {"@id": "ex:o"}
3224+
})
3225+
},
3226+
"object-iii": {
3227+
input: %([{
3228+
"@id": "http://example/s",
3229+
"http://example/p": [{
3230+
"@id": {
3231+
"@id": "http://example/s1",
3232+
"http://example/p1": [{"@id": "http://example/o1"}]
3233+
}
3234+
}]
3235+
}]),
3236+
context: %({"ex": "http://example/"}),
3237+
output: %({
3238+
"@context": {"ex": "http://example/"},
3239+
"@id": "ex:s",
3240+
"ex:p": {
3241+
"@id": {
3242+
"@id": "ex:s1",
3243+
"ex:p1": {"@id": "ex:o1"}
3244+
}
3245+
}
3246+
})
3247+
},
3248+
"object-iib": {
3249+
input: %([{
3250+
"@id": "http://example/s",
3251+
"http://example/p": [{
3252+
"@id": {
3253+
"@id": "http://example/s1",
3254+
"http://example/p1": [{"@id": "_:o1"}]
3255+
}
3256+
}]
3257+
}]),
3258+
context: %({"ex": "http://example/"}),
3259+
output: %({
3260+
"@context": {"ex": "http://example/"},
3261+
"@id": "ex:s",
3262+
"ex:p": {
3263+
"@id": {
3264+
"@id": "ex:s1",
3265+
"ex:p1": {"@id": "_:o1"}
3266+
}
3267+
}
3268+
})
3269+
},
3270+
"object-iil": {
3271+
input: %([{
3272+
"@id": "http://example/s",
3273+
"http://example/p": [{
3274+
"@id": {
3275+
"@id": "http://example/s1",
3276+
"http://example/p1": [{"@value": "o1"}]
3277+
}
3278+
}]
3279+
}]),
3280+
context: %({"ex": "http://example/"}),
3281+
output: %({
3282+
"@context": {"ex": "http://example/"},
3283+
"@id": "ex:s",
3284+
"ex:p": {
3285+
"@id": {
3286+
"@id": "ex:s1",
3287+
"ex:p1": "o1"
3288+
}
3289+
}
3290+
})
3291+
},
3292+
"recursive-subject": {
3293+
input: %([{
3294+
"@id": {
3295+
"@id": {
3296+
"@id": "http://example/s2",
3297+
"http://example/p2": [{"@id": "http://example/o2"}]
3298+
},
3299+
"http://example/p1": [{"@id": "http://example/o1"}]
3300+
},
3301+
"http://example/p": [{"@id": "http://example/o"}]
3302+
}]),
3303+
context: %({"ex": "http://example/"}),
3304+
output: %({
3305+
"@context": {"ex": "http://example/"},
3306+
"@id": {
3307+
"@id": {
3308+
"@id": "ex:s2",
3309+
"ex:p2": {"@id": "ex:o2"}
3310+
},
3311+
"ex:p1": {"@id": "ex:o1"}
3312+
},
3313+
"ex:p": {"@id": "ex:o"}
3314+
})
3315+
},
3316+
}.each do |name, params|
3317+
it(name) {run_compact(params.merge(rdfstar: true))}
3318+
end
3319+
end
31163320

31173321
context "problem cases" do
31183322
{
@@ -3200,8 +3404,8 @@ def run_compact(params)
32003404
expect(jld).to produce_jsonld(output, logger)
32013405

32023406
# Compare expanded jld/output too to make sure list values remain ordered
3203-
exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1')
3204-
exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1')
3407+
exp_jld = JSON::LD::API.expand(jld, processingMode: 'json-ld-1.1', rdfstar: params[:rdfstar])
3408+
exp_output = JSON::LD::API.expand(output, processingMode: 'json-ld-1.1', rdfstar: params[:rdfstar])
32053409
expect(exp_jld).to produce_jsonld(exp_output, logger)
32063410
end
32073411
end

0 commit comments

Comments
 (0)