ratio function

double ratio(
  1. String s1,
  2. String s2, {
  3. double scoreCutoff = 0.0,
})

Calculates a simple ratio between two strings Matches the behavior of RapidFuzz's ratio implementation

Implementation

double ratio(String s1, String s2, {double scoreCutoff = 0.0}) {
  // Following the original RapidFuzz implementation
  if (s1 == s2) return 100.0;

  // In RapidFuzz, empty strings give a score of 0
  if (s1.isEmpty || s2.isEmpty) return 0.0;

  // The original implementation uses indel_normalized_similarity * 100
  return indelNormalizedSimilarity(s1, s2, scoreCutoff: scoreCutoff / 100) *
      100;
}