Class: PennMARC::Language
- Defined in:
- lib/pennmarc/helpers/language.rb
Overview
Logic for extracting and translating Language values for a record. Penn practice is to verify the value present in the 008 control field as a three letter code. This code is then mapped to a display-friendly value using the a provided mapping hash.
Constant Summary collapse
- UNDETERMINED_CODE =
Used when no value is present in the control field - still mapped
:und
- LANGUAGE_SUBFIELDS =
%w[a b d e g h i j k m n p q r t].freeze
Constants included from Util
Util::TRAILING_PUNCTUATIONS_PATTERNS
Class Method Summary collapse
-
.show(record) ⇒ Array<String>
Get language values for display from the 546 field and related 880.
-
.values(record, iso_639_2_mapping: Mappers.iso_639_2_language, iso_639_3_mapping: Mappers.iso_639_3_language) ⇒ Array<String>
Get language values for searching and faceting of a record.
Methods included from Util
#append_relator, #append_trailing, #datafield_and_linked_alternate, #field_defined?, #field_or_its_linked_alternate?, #join_and_squish, #join_subfields, #linked_alternate, #linked_alternate_not_6_or_8, #no_subfield_value_matches?, #prefixed_subject_and_alternate, #relator, #relator_join_separator, #relator_term_subfield, #remove_paren_value_from_subfield_i, #subfield_defined?, #subfield_in?, #subfield_not_in?, #subfield_undefined?, #subfield_value?, #subfield_value_in?, #subfield_value_not_in?, #subfield_values, #subfield_values_for, #substring_after, #substring_before, #translate_relator, #trim_punctuation, #trim_trailing, #trim_trailing!, #valid_subject_genre_source_code?
Class Method Details
.show(record) ⇒ Array<String>
Get language values for display from the 546 field and related 880.
17 18 19 20 21 22 23 |
# File 'lib/pennmarc/helpers/language.rb', line 17 def show(record) values = record.fields('546').map do |field| join_subfields field, &subfield_not_in?(%w[6 8]) end language_values = values + linked_alternate(record, '546', &subfield_not_in?(%w[6 8])) language_values.uniq end |
.values(record, iso_639_2_mapping: Mappers.iso_639_2_language, iso_639_3_mapping: Mappers.iso_639_3_language) ⇒ Array<String>
In franklin, we extracted the language code from the 008 control field. After engaging cataloging unit representatives, we decided to also extract these values from the 041 field: Includes records for multilingual items, items that involve translation, and items where the medium of communication is a sign language. www.loc.gov/marc/bibliographic/bd041.html
Get language values for searching and faceting of a record. The values are extracted from subfields in the 041 field. Language facet and search values will typically be the same, with the exception of ‘zxx`, when no linguistic content is found.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pennmarc/helpers/language.rb', line 38 def values(record, iso_639_2_mapping: Mappers.iso_639_2_language, iso_639_3_mapping: Mappers.iso_639_3_language) values = record.fields('041').filter_map { |field| mapper = subfield_value?(field, '2', /iso639-3/) ? iso_639_3_mapping : iso_639_2_mapping field.filter_map do |sf| next unless LANGUAGE_SUBFIELDS.include? sf.code mapper[sf.value&.to_sym] end }.flatten control_field = record['008']&.value values << iso_639_2_mapping[control_field[35..37]&.to_sym] if control_field.present? values.empty? ? values << iso_639_2_mapping[UNDETERMINED_CODE] : values.uniq end |