Skip to content

Commit 42dba0e

Browse files
committed
Serialize more Bioschemas properties for materials
1 parent fe4d337 commit 42dba0e

2 files changed

Lines changed: 69 additions & 3 deletions

File tree

lib/bioschemas/generator.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,58 @@ def self.address(event)
101101
'longitude' => event.longitude
102102
}.compact
103103
end
104+
105+
# Reverse the process used by TeSS_RDF_Extractors to turn a list of values into a markdown list.
106+
# If the input doesn't look listy, falls back to just returning a list containing the input value as a single element.
107+
# Note that this could lose some data in the case that the input markdown starts with a list and then has some
108+
# non-list content afterwards.
109+
def self.markdown_to_array(markdown)
110+
return nil if markdown.blank?
111+
a = []
112+
113+
if markdown.start_with?(' * ')
114+
matches = markdown.scan(/ \* (.+)\n/)
115+
if matches.any?
116+
a += matches.flatten
117+
else
118+
a << markdown
119+
end
120+
else
121+
a << markdown
122+
end
123+
124+
a.any? ? a : nil
125+
end
126+
127+
def self.external_resources(resource)
128+
resource.external_resources.map do |ext_res|
129+
{
130+
'@type' => 'Thing',
131+
'name' => ext_res.title,
132+
'url' => ext_res.url
133+
}
134+
end
135+
end
136+
137+
def self.provider(resource)
138+
p = []
139+
if resource.content_provider
140+
p << {
141+
'@type' => 'Organization',
142+
'name' => resource.content_provider.title,
143+
'url' => resource.content_provider.url
144+
}
145+
end
146+
147+
resource.nodes.each do |node|
148+
p << {
149+
'@type' => 'Organization',
150+
'name' => node.full_title,
151+
'url' => node.url
152+
}
153+
end
154+
155+
p.any? ? p : nil
156+
end
104157
end
105158
end

lib/bioschemas/learning_resource_generator.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ def self.bioschemas_profile
99
end
1010

1111
property :name, :title
12+
property :learningResourceType, :resource_type
1213
property :url, :url
14+
property :identifier, :doi
15+
property :verison, :version
1316
property :description, :description
1417
property :keywords, :keywords
1518
property :author, -> (material) { material.authors.map { |p| person(p) } }
@@ -20,14 +23,24 @@ def self.bioschemas_profile
2023
property :about, -> (material) {
2124
material.scientific_topics.map { |t| term(t) }
2225
}
23-
property :dateCreated, :remote_created_date
24-
property :dateModified, :remote_updated_date
26+
property :dateCreated, :date_created
27+
property :dateModified, :date_modified
28+
property :datePublished, :date_published
29+
property :creativeWorkStatus, :status
2530
property :license, -> (material) {
2631
LicenceDictionary.instance.lookup_value(material.licence, 'reference') ||
2732
LicenceDictionary.instance.lookup_value(material.licence, 'url') ||
2833
material.licence
2934
}
3035
property :educationalLevel, :difficulty_level,
31-
condition: -> (event) { event.difficulty_level != 'notspecified' }
36+
condition: -> (material) { material.difficulty_level != 'notspecified' }
37+
property :competencyRequired, -> (material) {
38+
markdown_to_array(material.prerequisites)
39+
}
40+
property :teaches, -> (material) {
41+
markdown_to_array(material.learning_objectives)
42+
}
43+
property :mentions, -> (material) { external_resources(material) }
44+
property :provider, -> (material) { provider(material) }
3245
end
3346
end

0 commit comments

Comments
 (0)