MCPcopy
hub / github.com/sphinx-doc/sphinx / get_ratio

Function get_ratio

sphinx/versioning.py:116–126  ·  view source on GitHub ↗

Return a "similarity ratio" (in percent) representing the similarity between the two strings where 0 is equal and anything above less than equal.

(old: str, new: str)

Source from the content-addressed store, hash-verified

114
115
116def get_ratio(old: str, new: str) -> float:
117 """Return a "similarity ratio" (in percent) representing the similarity
118 between the two strings where 0 is equal and anything above less than equal.
119 """
120 if not all([old, new]):
121 return VERSIONING_RATIO
122
123 if IS_SPEEDUP:
124 return Levenshtein.distance(old, new) / (len(old) / 100.0)
125 else:
126 return levenshtein_distance(old, new) / (len(old) / 100.0)
127
128
129def levenshtein_distance(a: str, b: str) -> int:

Callers 2

test_get_ratioFunction · 0.90
merge_doctreesFunction · 0.85

Calls 1

levenshtein_distanceFunction · 0.85

Tested by 1

test_get_ratioFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…