@@ -280,6 +280,92 @@ class FieldTest < Test::Unit::TestCase
280280 assert_equal 'de' , course_instance_extractor ( json ) . send ( :extract_language )
281281 end
282282
283+ test 'extract authors' do
284+ json = %(
285+ [{
286+ "@context": "https://schema.org/",
287+ "@type": "LearningResource",
288+ "http://purl.org/dc/terms/conformsTo": {
289+ "@id": "https://bioschemas.org/profiles/TrainingMaterial/1.0-RELEASE",
290+ "@type": "CreativeWork"
291+ },
292+ "name": "Dummy Material",
293+ "author": {
294+ "@type": "Person",
295+ "@id": "https://orcid.org/0000-0001-9062-6303",
296+ "name": "Patricia Palagi"
297+ }
298+ }])
299+ authors = learning_resource_extractor ( json ) . send ( :extract_people , RDF ::Vocab ::SCHEMA . author )
300+ assert_equal 1 , authors . length
301+ assert_equal '0000-0001-9062-6303' , authors . first [ :orcid ]
302+ assert_equal 'Patricia Palagi' , authors . first [ :name ]
303+
304+ json = %(
305+ [{
306+ "@context": "https://schema.org/",
307+ "@type": "LearningResource",
308+ "http://purl.org/dc/terms/conformsTo": {
309+ "@id": "https://bioschemas.org/profiles/TrainingMaterial/1.0-RELEASE",
310+ "@type": "CreativeWork"
311+ },
312+ "name": "Dummy Material",
313+ "author": {
314+ "@type": "Person",
315+ "@id": "#aperson",
316+ "name": "Patricia Palagi",
317+ "identifier": "https://orcid.org/0000-0001-9062-6303"
318+ }
319+ }])
320+ authors = learning_resource_extractor ( json ) . send ( :extract_people , RDF ::Vocab ::SCHEMA . author )
321+ assert_equal 1 , authors . length
322+ assert_equal '0000-0001-9062-6303' , authors . first [ :orcid ]
323+ assert_equal 'Patricia Palagi' , authors . first [ :name ]
324+
325+ json = %(
326+ [{
327+ "@context": "https://schema.org/",
328+ "@type": "LearningResource",
329+ "http://purl.org/dc/terms/conformsTo": {
330+ "@id": "https://bioschemas.org/profiles/TrainingMaterial/1.0-RELEASE",
331+ "@type": "CreativeWork"
332+ },
333+ "name": "Dummy Material",
334+ "author": {
335+ "@type": "Person",
336+ "@id": "#aperson",
337+ "name": "Thomas B. Hickey",
338+ "identifier": " 0000-0002-1694-233X "
339+ }
340+ }])
341+ authors = learning_resource_extractor ( json ) . send ( :extract_people , RDF ::Vocab ::SCHEMA . author )
342+ assert_equal 1 , authors . length
343+ assert_equal '0000-0002-1694-233X' , authors . first [ :orcid ]
344+ assert_equal 'Thomas B. Hickey' , authors . first [ :name ]
345+
346+
347+ json = %(
348+ [{
349+ "@context": "https://schema.org/",
350+ "@type": "LearningResource",
351+ "http://purl.org/dc/terms/conformsTo": {
352+ "@id": "https://bioschemas.org/profiles/TrainingMaterial/1.0-RELEASE",
353+ "@type": "CreativeWork"
354+ },
355+ "name": "Dummy Material",
356+ "author": {
357+ "@type": "Person",
358+ "@id": "#aperson",
359+ "name": "Patricia Palagi",
360+ "identifier": "https://something.that.isnt.an.orcid"
361+ }
362+ }])
363+ authors = learning_resource_extractor ( json ) . send ( :extract_people , RDF ::Vocab ::SCHEMA . author )
364+ assert_equal 1 , authors . length
365+ assert_nil authors . first [ :orcid ]
366+ assert_equal 'Patricia Palagi' , authors . first [ :name ]
367+ end
368+
283369 private
284370
285371 def course_extractor ( fixture , format : :jsonld , base_uri : 'https://example.com/my.json' )
0 commit comments