33import math
44
55from dataclasses import dataclass
6+ from difflib import SequenceMatcher
67from html .parser import HTMLParser
78
8- from rapidfuzz .distance import Levenshtein
9-
109
1110class TagStripper (HTMLParser ):
1211 def __init__ (self ) -> None :
@@ -51,12 +50,12 @@ def find_similar_names(name: str, names: list[str]) -> list[str]:
5150 """
5251 Finds names similar to a given command name.
5352 """
54- threshold = 1e3
53+ threshold = 0.4
5554 distance_by_name = {}
56-
55+ if " " in name :
56+ names = [name for name in names if " " in name ]
5757 for actual_name in names :
58- # Get Levenshtein distance between the input and each command name
59- distance = Levenshtein .distance (name , actual_name )
58+ distance = SequenceMatcher (None , actual_name , name ).ratio ()
6059
6160 is_similar = distance <= len (name ) / 3
6261 substring_index = actual_name .find (name )
@@ -70,9 +69,7 @@ def find_similar_names(name: str, names: list[str]) -> list[str]:
7069
7170 # Only keep results with a distance below the threshold
7271 distance_by_name = {
73- key : value
74- for key , value in distance_by_name .items ()
75- if value [0 ] < 2 * threshold
72+ key : value for key , value in distance_by_name .items () if value [0 ] > threshold
7673 }
7774 # Display results with shortest distance first
7875 return sorted (distance_by_name , key = lambda key : distance_by_name [key ])
0 commit comments