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)
| 114 | |
| 115 | |
| 116 | def 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 | |
| 129 | def levenshtein_distance(a: str, b: str) -> int: |
searching dependent graphs…