Class: PennMARC::TitleSuggestionWeightService

Inherits:
Object
  • Object
show all
Defined in:
lib/pennmarc/services/title_suggestion_weight_service.rb

Overview

A service to calculate suggestion weights based on a variety of criteria

Constant Summary collapse

BASE_WEIGHT =

Starting score

10
FACTORS =

Array of symbols referring to methods on this object that return a boolean and the scoring factor if the method returns true.

[
  [:targeted_format?,             8],
  [:published_in_last_ten_years?, 5],
  [:electronic_holdings?,         3],
  [:high_encoding_level?,         2],
  [:physical_holdings?,           1],
  [:low_encoding_level?,         -2],
  [:weird_format?,               -5],
  [:no_holdings?,                -10]
].freeze
TARGETED_FORMATS =

Score higher records with these formats

[Format::BOOK, Format::WEBSITE_DATABASE, Format::JOURNAL_PERIODICAL, Format::NEWSPAPER,
Format::SOUND_RECORDING, Format::MUSICAL_SCORE].freeze
WEIRD_FORMATS =

Score lower these formats

[Format::OTHER, Format::THREE_D_OBJECT].freeze
HIGH_ENCODING_SORT_LEVEL =

See #EncodingLevel for more of the logic that determines sort values An encoding sort level of this value is considered good

0
LOW_ENCODING_SORT_LEVEL =

An encoding sort level higher than this is considered poor

4

Class Method Summary collapse

Class Method Details

.electronic_holdings?(record) ⇒ Boolean

Parameters:

  • record (MARC::Record)

Returns:

  • (Boolean)


59
60
61
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 59

def electronic_holdings?(record)
  Inventory.electronic(record)&.any? || false
end

.factorsArray[Array]

Returns:

  • (Array[Array])


45
46
47
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 45

def factors
  FACTORS
end

.high_encoding_level?(record) ⇒ Boolean

Parameters:

  • record (MARC::Record)

Returns:

  • (Boolean)


77
78
79
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 77

def high_encoding_level?(record)
  Encoding.level_sort(record) == HIGH_ENCODING_SORT_LEVEL
end

.low_encoding_level?(record) ⇒ Boolean

Parameters:

  • record (MARC::Record)

Returns:

  • (Boolean)


95
96
97
98
99
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 95

def low_encoding_level?(record)
  return false unless Encoding.level_sort(record).present?

  Encoding.level_sort(record) > LOW_ENCODING_SORT_LEVEL
end

.no_holdings?(record) ⇒ Boolean

Parameters:

  • record (MARC::Record)

Returns:

  • (Boolean)


89
90
91
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 89

def no_holdings?(record)
  !electronic_holdings?(record) && !physical_holdings?(record)
end

.physical_holdings?(record) ⇒ Boolean

Parameters:

  • record (MARC::Record)

Returns:

  • (Boolean)


65
66
67
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 65

def physical_holdings?(record)
  Inventory.physical(record)&.any? || false
end

.published_in_last_ten_years?(record) ⇒ Boolean

Parameters:

  • record (MARC::Record)

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 51

def published_in_last_ten_years?(record)
  return false unless Date.publication(record).present?

  Date.publication(record) > 10.years.ago
end

.targeted_format?(record) ⇒ Boolean

Parameters:

  • record (MARC::Record)

Returns:

  • (Boolean)


71
72
73
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 71

def targeted_format?(record)
  (Format.facet(record) & TARGETED_FORMATS).any?
end

.weight(record) ⇒ Integer

Calculate a weight for use in sorting good title suggestions from bad

Parameters:

  • record (MARC::Record)

Returns:

  • (Integer)


38
39
40
41
42
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 38

def weight(record)
  factors.reduce(BASE_WEIGHT) do |weight, (call, score)|
    weight + (public_send(call, record) ? score : 0)
  end
end

.weird_format?(record) ⇒ Boolean

Parameters:

  • record (MARC::Record)

Returns:

  • (Boolean)


83
84
85
# File 'lib/pennmarc/services/title_suggestion_weight_service.rb', line 83

def weird_format?(record)
  (Format.facet(record) & WEIRD_FORMATS).any?
end