Class: RuboCop::StringUtil::JaroWinkler

Inherits:
Jaro
  • Object
show all
Defined in:
lib/rubocop/string_util.rb

Overview

This class computes Jaro-Winkler distance, which adds prefix-matching bonus to Jaro distance.

Constant Summary collapse

DEFAULT_BOOST_THRESHOLD =

Add the prefix bonus only when the Jaro distance is above this value. In other words, if the Jaro distance is less than this value, JaroWinkler.distance returns the raw Jaro distance.

0.7
DEFAULT_SCALING_FACTOR =

How much the prefix bonus is weighted. This should not exceed 0.25.

0.1
MAX_COMMON_PREFIX_LENGTH =

Cutoff the common prefix length to this value if it’s longer than this.

4

Instance Attribute Summary collapse

Attributes inherited from Jaro

#longer, #shorter

Instance Method Summary collapse

Methods inherited from Jaro

distance, #distance

Constructor Details

#initialize(a, b, boost_threshold = nil, scaling_factor = nil) ⇒ JaroWinkler

Returns a new instance of JaroWinkler.



119
120
121
122
123
# File 'lib/rubocop/string_util.rb', line 119

def initialize(a, b, boost_threshold = nil, scaling_factor = nil)
  super(a, b)
  @boost_threshold = boost_threshold || DEFAULT_BOOST_THRESHOLD
  @scaling_factor = scaling_factor || DEFAULT_SCALING_FACTOR
end

Instance Attribute Details

#boost_thresholdObject (readonly)

Returns the value of attribute boost_threshold.



117
118
119
# File 'lib/rubocop/string_util.rb', line 117

def boost_threshold
  @boost_threshold
end

#scaling_factorObject (readonly)

Returns the value of attribute scaling_factor.



117
118
119
# File 'lib/rubocop/string_util.rb', line 117

def scaling_factor
  @scaling_factor
end