Class: PennMARC::Title
Overview
This helper contains logic for parsing out Title and Title-related fields.
Constant Summary collapse
- AUX_TITLE_TAGS =
{ main: %w[130 210 222 240 245 246 247 440 490 730 740 830], related: %w[773 774 780 785], entity: %w[700 710 711], note: %w[505] }.freeze
- HOST_BIB_TITLE =
This text is used in Alma to indicate a Bib record is a “Host” record for other bibs (bound-withs)
'Host bibliographic record for boundwith'- NO_TITLE_PROVIDED =
Title to use when no 245 field is present. This “shouldn’t” occur, but it does.
'[No title provided]'
Constants included from Util
Util::TRAILING_PUNCTUATIONS_PATTERNS
Class Method Summary collapse
-
.alternate_show(record) ⇒ String?
Same structure as show, but linked alternate title.
-
.detailed_show(record) ⇒ String
Same as show, but with all subfields included as found - except for subfield c.
-
.former_show(record) ⇒ Array<String>
Former Title for display.
-
.host_bib_record?(record) ⇒ Boolean
Determine if the record is a “Host” bibliographic record for other bib records (“bound-withs”).
-
.journal_search(record) ⇒ Array<String>
Journal Title Search field.
-
.journal_search_aux(record) ⇒ Array<String>
Auxiliary Journal Title Search field.
-
.other_show(record) ⇒ Array<String>
Other Title for display.
-
.search(record) ⇒ Array<String>
Main Title Search field.
-
.search_aux(record) ⇒ Array<String>
Auxiliary Title Search field.
-
.show(record) ⇒ String
Single-valued Title, for use in headings.
-
.sort(record) ⇒ String
Canonical title with non-filing characters relocated to the end.
-
.standardized_show(record) ⇒ Array<String>
Array of standardized titles as strings.
-
.suggest(record) ⇒ Array<String>
Values for title suggester, including only ǂa and ǂb from 245 field.
-
.suggest_weight(record) ⇒ Integer
An integer value used for weighing title suggest values.
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
.alternate_show(record) ⇒ String?
Same structure as show, but linked alternate title.
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/pennmarc/helpers/title.rb', line 142 def alternate_show(record) field = record.fields('880').filter_map { |alternate_field| next unless subfield_value?(alternate_field, '6', /^245/) alternate_field }.first return unless field values = title_values(field, include_subfield_c: true) [format_title(values[:title_or_form]), values[:punctuation], values[:other_info]].compact_blank.join(' ') end |
.detailed_show(record) ⇒ String
Same as show, but with all subfields included as found - except for subfield c.
132 133 134 135 136 137 |
# File 'lib/pennmarc/helpers/title.rb', line 132 def detailed_show(record) field = record.fields('245')&.first return unless field join_subfields(field, &subfield_not_in?(%w[6 8])) end |
.former_show(record) ⇒ Array<String>
what are e and w subfields?
Ported from get_former_title_display. That method returns a hash for constructing a search link. We may need to do something like that eventually.
Former Title for display. These values come from 247.
254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/pennmarc/helpers/title.rb', line 254 def former_show(record) record.fields .filter_map { |field| next unless field.tag == '247' || (field.tag == '880' && subfield_value?(field, '6', /^247/)) # 6 and 8 are not meaningful for display former_title = join_subfields field, &subfield_not_in?(%w[6 8 e w]) former_title_append = join_subfields field, &subfield_in?(%w[e w]) "#{former_title} #{former_title_append}".strip }.uniq end |
.host_bib_record?(record) ⇒ Boolean
Determine if the record is a “Host” bibliographic record for other bib records (“bound-withs”)
269 270 271 272 273 274 |
# File 'lib/pennmarc/helpers/title.rb', line 269 def host_bib_record?(record) record.fields('245').any? do |f| title = join_subfields(f, &subfield_in?(%w[a])) title.include?(HOST_BIB_TITLE) end end |
.journal_search(record) ⇒ Array<String>
Journal Title Search field. Takes from 245 and linked 880. We do not return any values if the MARC leader indicates that the record is not a serial.
92 93 94 95 96 97 98 99 100 |
# File 'lib/pennmarc/helpers/title.rb', line 92 def journal_search(record) return [] if not_a_serial?(record) record.fields(%w[245 880]).filter_map { |field| next if field.tag == '880' && no_subfield_value_matches?(field, '6', /^245/) join_subfields(field, &subfield_not_in?(%w[c 6 8 h])) }.uniq end |
.journal_search_aux(record) ⇒ Array<String>
Auxiliary Journal Title Search field. Takes from many fields defined in AUX_TITLE_TAGS that contain title-like information. Does not return any titles if the MARC leader indicates that the record is not a serial.
107 108 109 110 111 112 113 |
# File 'lib/pennmarc/helpers/title.rb', line 107 def journal_search_aux(record) values = search_aux_values(record: record, title_type: :main, journal: true, &subfield_not_in?(%w[c 6 8])) + search_aux_values(record: record, title_type: :related, journal: true, &subfield_in?(%w[s t])) + search_aux_values(record: record, title_type: :entity, journal: true, &subfield_in?(%w[t])) + search_aux_values(record: record, title_type: :note, journal: true, &subfield_in?(%w[t])) values.uniq end |
.other_show(record) ⇒ Array<String>
Other Title for display
Data comes from 246 (OCLC docs) and 740 (OCLC docs)
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/pennmarc/helpers/title.rb', line 228 def other_show(record) other_titles = record.fields('246').map do |field| join_subfields(field, &subfield_not_in?(%w[6 8])) end other_titles += record.fields('740') .filter_map do |field| next unless field.indicator2.in? ['', ' ', '0', '1', '3'] join_subfields(field, &subfield_not_in?(%w[5 6 8])) end titles = other_titles + record.fields('880').filter_map do |field| next unless subfield_value? field, '6', /^(246|740)/ join_subfields(field, &subfield_not_in?(%w[5 6 8])) end titles.uniq end |
.search(record) ⇒ Array<String>
Ported from get_title_1_search_values.
Main Title Search field. Takes from 245 and linked 880.
67 68 69 70 71 72 73 |
# File 'lib/pennmarc/helpers/title.rb', line 67 def search(record) record.fields(%w[245 880]).filter_map { |field| next if field.tag == '880' && no_subfield_value_matches?(field, '6', /^245/) join_subfields(field, &subfield_not_in?(%w[c 6 8 h])) }.uniq end |
.search_aux(record) ⇒ Array<String>
Auxiliary Title Search field. Takes from many fields defined in AUX_TITLE_TAGS that contain title-like information.
79 80 81 82 83 84 85 |
# File 'lib/pennmarc/helpers/title.rb', line 79 def search_aux(record) values = search_aux_values(record: record, title_type: :main, &subfield_not_in?(%w[c 6 8])) + search_aux_values(record: record, title_type: :related, &subfield_in?(%w[s t])) + search_aux_values(record: record, title_type: :entity, &subfield_in?(%w[t])) + search_aux_values(record: record, title_type: :note, &subfield_in?(%w[t])) values.uniq end |
.show(record) ⇒ String
is punctuation handling still as desired? treatment here is described in spreadsheet from 2011
Single-valued Title, for use in headings. Takes the first 245 value. Special consideration for punctuation practices.
121 122 123 124 125 126 127 |
# File 'lib/pennmarc/helpers/title.rb', line 121 def show(record) field = record.fields('245')&.first return Array.wrap(NO_TITLE_PROVIDED) unless field.present? values = title_values(field) [format_title(values[:title_or_form]), values[:punctuation], values[:other_info]].compact_blank.join(' ') end |
.sort(record) ⇒ String
refactor to reduce complexity
Currently we index two “title sort” fields: title_nssort (ssort type - regex token filter applied) and title_sort_tl (text left justified). It is not yet clear why this distinction is useful. For now, use a properly normalized (leading articles and punctuation removed) single title value here.
Canonical title with non-filing characters relocated to the end.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/pennmarc/helpers/title.rb', line 162 def sort(record) title_field = record.fields('245').first return unless title_field.present? # attempt to get number of non-filing characters present, default to 0 offset = if /^[0-9]$/.match?(title_field.indicator2) title_field.indicator2.to_i else 0 end raw_title = join_subfields(title_field, &subfield_in?(['a'])) # get title from subfield a value = if offset.between?(1, 9) { prefix: raw_title[0..offset - 1]&.strip, filing: raw_title[offset..]&.strip } elsif raw_title.present? handle_bracket_prefix raw_title else # no subfield a, no indicator raw_form = join_subfields(title_field, &subfield_in?(['k'])) handle_bracket_prefix raw_form end value[:filing] = [value[:filing], join_subfields(title_field, &subfield_in?(%w[b n p]))].compact_blank.join(' ') [value[:filing], value[:prefix]].join(' ').strip end |
.standardized_show(record) ⇒ Array<String>
this is simplified from legacy practice as a linking hash is not returned. I believe this only supported title browse and we will not be supporting that at this time
Returns Array of standardized titles as strings.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/pennmarc/helpers/title.rb', line 199 def standardized_show(record) standardized_titles = record.fields(%w[130 240]).map do |field| join_subfields(field, &subfield_not_in?(%w[0 6 8 e w])) end standardized_titles += record.fields('730').filter_map do |field| # skip unless one of the indicators is blank next unless field.indicator1 == '' || field.indicator2 == '' # skip if a subfield i is present next if subfield_defined?(field, 'i') join_subfields(field, &subfield_not_in?(%w[5 6 8 e w])) end titles = standardized_titles + record.fields('880').filter_map do |field| next unless subfield_undefined?(field, 'i') && subfield_value?(field, '6', /^(130|240|730)/) join_subfields field, &subfield_not_in?(%w[5 6 8 e w]) end titles.uniq end |
.suggest(record) ⇒ Array<String>
Values for title suggester, including only ǂa and ǂb from 245 field. Limits the output to 20 words and strips any trailing slashes.
47 48 49 50 51 52 53 54 |
# File 'lib/pennmarc/helpers/title.rb', line 47 def suggest(record) record.fields(%w[245]).filter_map do |field| join_subfields(field, &subfield_in?(%w[a b])) .squish .truncate_words(20) .sub(%r{ /$}, '') end end |
.suggest_weight(record) ⇒ Integer
An integer value used for weighing title suggest values. See PennMARC::TitleSuggestionWeightService for logic.
59 60 61 |
# File 'lib/pennmarc/helpers/title.rb', line 59 def suggest_weight(record) PennMARC::TitleSuggestionWeightService.weight record end |