Skip to content

Commit

Permalink
Changes language mapping to use a blank node.
Browse files Browse the repository at this point in the history
closes #316
  • Loading branch information
justinlittman committed Dec 6, 2023
1 parent 970bf3f commit ac0457b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 16 deletions.
16 changes: 15 additions & 1 deletion lib/rdf2marc/rdf2model/mappers/control_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,22 @@ def parse_date(date_literal)
raise BadRequestError, "#{date_literal} is an invalid date."
end

LANGUAGE_PARTS = ['text', 'sung or spoken text'].freeze

def language
language_uri = item.work.query.path_first_uri([BF.language])
language_nodes = item.work.query.path_all([BF.language])
preferred_nodes = language_nodes.select do |node|
LANGUAGE_PARTS.include?(item.work.query.path_first_literal([BF.part], subject_term: node)&.downcase)
end

language_blank_node = preferred_nodes.first || language_nodes.first
return nil if language_blank_node.nil?

language_node = item.work.query.path_first([RDF::RDFS.label], subject_term: language_blank_node)
return nil unless language_node.is_a?(RDF::URI)

language_uri = language_node.value

return nil if language_uri.nil? || !language_uri.start_with?(%r{https?://id.loc.gov/vocabulary/languages/})

language_uri.sub(%r{^https?://id.loc.gov/vocabulary/languages/}, '')
Expand Down
63 changes: 48 additions & 15 deletions spec/rdf2marc/rdf2model/mappers/control_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,58 @@
end

describe 'general info language' do
let(:ttl) do
<<~TTL
<#{work_term}> <http://id.loc.gov/ontologies/bibframe/language> <http://id.loc.gov/vocabulary/languages/ace>.
<http://id.loc.gov/vocabulary/languages/ace> <http://www.w3.org/2000/01/rdf-schema#label> "Achinese".
<> <http://id.loc.gov/ontologies/bibframe/language> <http://id.loc.gov/vocabulary/languages/bug>.
<http://id.loc.gov/vocabulary/languages/bug> <http://www.w3.org/2000/01/rdf-schema#label> "Bugis".
TTL
context 'when language part is text' do
let(:ttl) do
<<~TTL
<#{work_term}> <http://id.loc.gov/ontologies/bibframe/language> _:b29, _:b30.
_:b29 a <http://id.loc.gov/ontologies/bibframe/Language>;
<http://www.w3.org/2000/01/rdf-schema#label> <http://id.loc.gov/vocabulary/languages/eng>;
<http://id.loc.gov/ontologies/bibframe/part> "Original"@en.
<http://id.loc.gov/vocabulary/languages/eng> <http://www.w3.org/2000/01/rdf-schema#label> "English".
_:b30 a <http://id.loc.gov/ontologies/bibframe/Language>;
<http://www.w3.org/2000/01/rdf-schema#label> <http://id.loc.gov/vocabulary/languages/ukr>;
<http://id.loc.gov/ontologies/bibframe/part> "Text"@en.
<http://id.loc.gov/vocabulary/languages/ukr> <http://www.w3.org/2000/01/rdf-schema#label> "Ukrainian".
TTL
end

let(:model) do
{
general_info: {
language: 'ukr',
place: 'xx'
}
}
end

include_examples 'mapper', described_class
end

let(:model) do
{
general_info: {
language: 'ace',
place: 'xx'
context 'when no language part' do
let(:ttl) do
<<~TTL
<#{work_term}> <http://id.loc.gov/ontologies/bibframe/language> _:b29, _:b30.
_:b29 a <http://id.loc.gov/ontologies/bibframe/Language>;
<http://www.w3.org/2000/01/rdf-schema#label> <http://id.loc.gov/vocabulary/languages/eng>;
<http://id.loc.gov/ontologies/bibframe/part> "Original"@en.
<http://id.loc.gov/vocabulary/languages/eng> <http://www.w3.org/2000/01/rdf-schema#label> "English".
_:b30 a <http://id.loc.gov/ontologies/bibframe/Language>;
<http://www.w3.org/2000/01/rdf-schema#label> <http://id.loc.gov/vocabulary/languages/ukr>.
<http://id.loc.gov/vocabulary/languages/ukr> <http://www.w3.org/2000/01/rdf-schema#label> "Ukrainian".
TTL
end

let(:model) do
{
general_info: {
language: 'eng',
place: 'xx'
}
}
}
end
end

include_examples 'mapper', described_class
include_examples 'mapper', described_class
end
end

describe 'general info book illustrative content' do
Expand Down

0 comments on commit ac0457b

Please sign in to comment.