MCPcopy Index your code
hub / github.com/clips/pattern / similarity

Function similarity

pattern/metrics.py:288–295  ·  view source on GitHub ↗

Returns the similarity of string1 and string2 as a number between 0.0 and 1.0, using LEVENSHTEIN edit distance or DICE coefficient.

(string1, string2, metric=LEVENSHTEIN)

Source from the content-addressed store, hash-verified

286
287LEVENSHTEIN, DICE = "levenshtein", "dice"
288def similarity(string1, string2, metric=LEVENSHTEIN):
289 """ Returns the similarity of string1 and string2 as a number between 0.0 and 1.0,
290 using LEVENSHTEIN edit distance or DICE coefficient.
291 """
292 if metric == LEVENSHTEIN:
293 return levenshtein_similarity(string1, string2)
294 if metric == DICE:
295 return dice_coefficient(string1, string2)
296
297#--- STRING READABILITY ----------------------------------------------------------------------------
298# 0.9-1.0 = easily understandable by 11-year old.

Callers

nothing calls this directly

Calls 2

levenshtein_similarityFunction · 0.85
dice_coefficientFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…