bpod_core.misc.suggest_similar

bpod_core.misc.suggest_similar(invalid_string, valid_strings, format_string=" - did you mean '{}'?", cutoff=0.6) str

Suggest a similar valid string based on the given invalid string.

This function uses a similarity matching algorithm to find the closest match from a list of valid strings. If a match is found above the specified cutoff, it returns a formatted suggestion string.

Parameters:
  • invalid_string (str) – The string that is invalid or misspelled.

  • valid_strings (list[str]) – A list of valid strings to compare against.

  • format_string (str, optional) – The format string for the suggestion. Defaults to “ - did you mean ‘{}’?”.

  • cutoff (float, optional) – The similarity threshold for considering a match. Defaults to 0.6.

Returns:

A formatted suggestion string if a match is found, otherwise an empty string.

Return type:

str