Skip to content

Commit 476b6c4

Browse files
committed
Extract language
1 parent c89fcad commit 476b6c4

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lib/tess/rdf/event_extractor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def extract_params
3636
params[:prerequisites] = extract_course_prerequisites
3737
params[:learning_objectives] = markdownify_list extract_names_or_values(RDF::Vocab::SCHEMA.teaches)
3838
params[:target_audience] = extract_audience
39+
params[:language] = extract_names_or_values(RDF::Vocab::SCHEMA.inLanguage).first
3940

4041
remove_blanks(params)
4142
end

lib/tess/rdf/extraction.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ def extract_mentions(subject: resource)
255255
[:mention, RDF::Vocab::SCHEMA.url, :url, { optional: true }]).map { |a| { title: a[:name], url: a[:url] } }.compact
256256
end
257257

258+
def extract_language(subject: resource)
259+
query(
260+
[subject, RDF::Vocab::SCHEMA.inLanguage, :language],
261+
[:language, RDF::Vocab::SCHEMA.name, :language, { optional: true }])
262+
end
263+
258264
def extract_names_or_ids(predicate, subject: resource)
259265
query([subject, predicate, :thing],
260266
[:thing, RDF::Vocab::SCHEMA.name, :name, { optional: true }],

test/field_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,30 @@ class FieldTest < Test::Unit::TestCase
256256
assert_equal 'Patricia Palagi (https://orcid.org/0000-0001-9062-6303), SIB Swiss Institute of Bioinformatics (https://www.sib.swiss/), Someone, https://cool.guys',
257257
course_instance_extractor(json).send(:extract_names_or_ids, RDF::Vocab::SCHEMA.organizer).join(', ')
258258
end
259+
260+
test 'extract language' do
261+
json = %(
262+
[{
263+
"@context": "https://schema.org/",
264+
"@type": "CourseInstance",
265+
"name": "Dummy Course",
266+
"inLanguage": "en"
267+
}])
268+
assert_equal 'en', course_instance_extractor(json).extract_params[:language]
269+
270+
json = %(
271+
[{
272+
"@context": "https://schema.org/",
273+
"@type": "CourseInstance",
274+
"name": "Dummy Course",
275+
"inLanguage": {
276+
"@type": "Language",
277+
"name" : "de"
278+
}
279+
}])
280+
assert_equal 'de', course_instance_extractor(json).extract_params[:language]
281+
end
282+
259283
private
260284

261285
def course_extractor(fixture, format: :jsonld, base_uri: 'https://example.com/my.json')

0 commit comments

Comments
 (0)