Skip to content

Commit

Permalink
Fix resources in JSON-LD snippets with relative @ids not being dete…
Browse files Browse the repository at this point in the history
…cted
  • Loading branch information
fbacall committed Dec 7, 2023
1 parent 5508540 commit c596004
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/bioschemas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run_test
if body
begin
ingestor = Ingestors::BioschemasIngestor.new
@output = ingestor.read_content(StringIO.new(body), url: params[:url])
@output = ingestor.read_content(StringIO.new(body), url: params[:url] || 'https://example.com')
rescue RDF::ReaderError
flash[:error] = 'A parsing error occurred. Please check your document contains valid JSON-LD or HTML.'
format.html { render :test, status: :unprocessable_entity }
Expand Down
13 changes: 13 additions & 0 deletions test/controllers/bioschemas_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ class BioschemasControllerTest < ActionController::TestCase
assert_redirected_to new_user_session_path
end

test 'should detect resources in JSON-LD snippet with relative IDs' do
sign_in users(:regular_user)

post :run_test, params: { snippet: fixture_file('ols_relative_id.json').read }

assert_response :success

output = assigns(:output)
assert_equal 1, output[:totals]['LearningResources']
assert_equal 1, output[:resources][:materials].count
assert_equal "https://test.url", output[:resources][:materials].first[:url]
end

private

def fixture_file(filename)
Expand Down
59 changes: 59 additions & 0 deletions test/fixtures/files/ingestion/ols_relative_id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"@context": "https://schema.org",
"@type": "LearningResource",
"@id": "some%20id",
"url": "https://test.url",
"dct:conformsTo": {
"https://purl.org/dc/terms/conformsTo": {
"@id": "https://bioschemas.org/profiles/TrainingMaterial/1.0-RELEASE",
"@type": "CreativeWork"
}
},
"description": "Video from the talk 'Welcome to OLS!', by Emmy Tsang, on March 07, 2022, in Open Seeds ols-5 cohort",
"keywords": ["Open Science", "Open Life Science", "OLS Introduction"],
"name": "Recording of the talk 'Welcome to OLS!', by Emmy Tsang, on March 07, 2022",
"educationalLevel": "Beginner",
"inLanguage": "en-US",
"learningResourceType": "video",
"license": "https://creativecommons.org/licenses/by-sa/4.0/",
"contributor": [
{
"@type": "Organization",
"name": "Open Life Science",
"email": "team@we-are-ols.org",
"url": "https://openlifesci.org/"
},{
"@type": "Person",
"name": "Emmy Tsang",
"url": "https://openlifesci.org//people#emmyft"
}],
"dateCreated": "2022-03-07",
"hasPart": {
"@type": "CreativeWork",
"url": "https://docs.google.com/presentation/d/1B-TiVAHx6OVririv88-H59_BlPwniS5xDnhZtoDU280/edit#slide=id.g6e457e6ac5_0_69",
"name": "Slides for the talk 'Welcome to OLS!', by Emmy Tsang, on March 07, 2022"
},
"isPartOf": {
"@context": "https://schema.org",
"@type": "Course",
"@id": "https://openlifesci.org//ols-5",
"dct:conformsTo": {
"https://purl.org/dc/terms/conformsTo": {
"@id": "https://bioschemas.org/profiles/Course/1.0-RELEASE",
"@type": "CreativeWork"
}
},
"description": "OLS is a mentoring mentoring & training program for Open Science ambassadors. It runs cohorts with calls every 1-2 weeks.",
"keywords": "Open Science",
"name": "Open Seeds ols-5 cohort",
"url": "https://openlifesci.org//openseeds/ols-5",
"educationalLevel": "Beginner",
"inLanguage": "en-US",
"provider": [{
"@type": "Organization",
"name": "Open Life Science",
"email": "team@we-are-ols.org",
"url": "https://openlifesci.org/"
}]
}
}

0 comments on commit c596004

Please sign in to comment.