Class: PennMARC::Classification

Inherits:
Helper
  • Object
show all
Defined in:
lib/pennmarc/helpers/classification.rb

Overview

Generates library of congress and dewey classifications using call number data.

Constant Summary collapse

LOC_CALL_NUMBER_TYPE =

Subfield value that identifies Library of Congress call number

'0'
DEWEY_CALL_NUMBER_TYPE =

Subfield value that identifies Dewey call number

'1'
CLASSIFICATION_MAPS =

Hash that maps call number type to the appropriate mapper

{
  LOC_CALL_NUMBER_TYPE => Mappers.loc_classification,
  DEWEY_CALL_NUMBER_TYPE => Mappers.dewey_classification
}.freeze
TAGS =

Enriched MARC tags that hold classification data

[Enriched::Pub::ITEM_TAG, Enriched::Api::PHYS_INVENTORY_TAG].freeze

Constants included from Util

Util::TRAILING_PUNCTUATIONS_PATTERNS

Class Method Summary collapse

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

.call_number_search(record) ⇒ Array<String>

Parse call number values from inventory fields, including both hld and itm fields from publishing enrichment. Return only unique values.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)

    array of call numbers from inventory fields



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pennmarc/helpers/classification.rb', line 49

def call_number_search(record)
  call_nums = record.fields(TAGS).filter_map do |field|
    subfield_values(field, call_number_sf(field))
  end

  # Ensure we get call numbers for records with no `itm` tags by also checking `hld` and de-duping
  call_nums += record.fields([Enriched::Pub::PHYS_INVENTORY_TAG]).filter_map do |field|
    first = subfield_values(field, Enriched::Pub::HOLDING_CLASSIFICATION_PART)&.first
    last = subfield_values(field, Enriched::Pub::HOLDING_ITEM_PART)&.first
    "#{first} #{last}".squish.presence
  end
  call_nums.flatten.uniq
end

.facet(record) ⇒ Array<String>

Parse classification values for faceting. We retrieve classification values from enriched MARC fields ‘itm’ or ‘AVA’ originating respectively from the Alma publishing process or from the Alma Api. We return the highest level LOC or Dewey classifications from each available call number, joining the class code with its title in a single string. See Enriched and Enriched::Api for more information on the enriched MARC fields.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)

    array of classifications

See Also:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pennmarc/helpers/classification.rb', line 30

def facet(record)
  record.fields(TAGS).flat_map { |field|
    call_number_type = subfield_values(field, call_number_type_sf(field))&.first
    call_numbers = subfield_values(field, call_number_sf(field))

    call_numbers.filter_map do |call_number|
      class_code = call_number[0]
      title = translate_classification(class_code, call_number_type)
      next if title.blank?

      format_facet(class_code, call_number_type, title)
    end
  }.uniq
end