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


62
63
64
# File 'lib/pennmarc/helpers/classification.rb', line 62

def call_number_search(record)
  values(record, loc_only: false)
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:


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

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

.sort(record) ⇒ String?

Note:

this could be made more efficient by just returning the first value, but in the future we may want to be more discerning about which call number we return (longest?)

Return a normalized Call Number value for sorting purposes. This uses the Lcsort gem normalization logic, which returns nil for non-LC call numbers. For now, this returns only the call number values from the enrichment inventory fields.

Parameters:

  • record (MARC::Record)

Returns:

  • (String, nil)

    a normalized call number


54
55
56
# File 'lib/pennmarc/helpers/classification.rb', line 54

def sort(record)
  values(record, loc_only: true).filter_map { |val| Lcsort.normalize(val) }.first
end

.values(record, loc_only:) ⇒ Array<String>

Return raw call number values from inventory fields

Parameters:

  • record (MARC::Record)
  • loc_only (Boolean)

    whether or not to explicitly return only LOC call numbers from ITM & AVA inventory

Returns:

  • (Array<String>)

70
71
72
73
74
75
76
77
78
79
# File 'lib/pennmarc/helpers/classification.rb', line 70

def values(record, loc_only:)
  call_nums = record.fields(TAGS).filter_map do |field|
    next if loc_only && !loc_call_number_type?(subfield_values(field, call_number_type_sf(field))&.first)

    subfield_values(field, call_number_sf(field))
  end

  call_nums += hld_field_call_nums(record)
  call_nums.flatten.uniq
end