Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes language mapping to use a blank node. #322

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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