Skip to content

Commit

Permalink
omitGraph set to false. fixes #46
Browse files Browse the repository at this point in the history
  • Loading branch information
saumier committed Jan 3, 2025
1 parent 9de0d50 commit 7d29700
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/utils/artsdata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ def transform(sparql)

def frame(frame_list)
frame_list = [frame_list] unless frame_list.is_a?(Array)
@framed_json = {"@context" => [], "@graph" => []}
@framed_json = {"@context" => {}, "@graph" => []}
options = {:omitGraph => false}
frame_list.each do |frame|
frame = JSON.parse(File.read(frame))
input = JSON.parse(@graph.dump(:jsonld))
framed_json = JSON::LD::API.frame(input, frame)
@framed_json["@context"] = framed_json["@context"]
@framed_json["@graph"] += framed_json["@graph"]
framed_json = JSON::LD::API.frame(input, frame, **options)
@framed_json["@context"] = @framed_json["@context"].merge(framed_json["@context"])
@framed_json["@graph"] += Array(framed_json["@graph"])
end

end
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/expositions.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"@context": "http://schema.org",
"@type": "Event",
"name": "Some Event"
},
{
"@context": "http://schema.org",
"@type": "ExhibitionEvent",
"name": "Big Exhibition"
}
]
9 changes: 8 additions & 1 deletion tests/frame_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ def test_nested_offers_does_not_contain_bad
assert !framed_json["representation"][0]["offers"]["offers"]["bad"]
end


def test_exposition_frame
frame = JSON.parse(File.read('./frame/lavitrine_exposition_frame.jsonld'))
input = JSON.parse(File.read('./tests/fixtures/expositions.jsonld'))
options = {:omitGraph => false}
framed_json = JSON::LD::API.frame(input, frame, **options)
# pp framed_json
assert framed_json["@graph"].class == Array
end


end

0 comments on commit 7d29700

Please sign in to comment.