Given a requested command and an iterable of possible options returns the most similar (if any is similar). :param requested_command: The command entered by the user :param options: The list of available commands to search for the most similar :param similarity_function_to_use: An optio
(
requested_command: str, options: Iterable[str], similarity_function_to_use: Callable[[str, str], float] | None = None
)
| 783 | |
| 784 | |
| 785 | def suggest_similar( |
| 786 | requested_command: str, options: Iterable[str], similarity_function_to_use: Callable[[str, str], float] | None = None |
| 787 | ) -> str | None: |
| 788 | """Given a requested command and an iterable of possible options returns the most similar (if any is similar). |
| 789 | |
| 790 | :param requested_command: The command entered by the user |
| 791 | :param options: The list of available commands to search for the most similar |
| 792 | :param similarity_function_to_use: An optional callable to use to compare commands |
| 793 | :return: The most similar command or None if no one is similar |
| 794 | """ |
| 795 | proposed_command = None |
| 796 | best_simil = MIN_SIMIL_TO_CONSIDER |
| 797 | requested_command_to_compare = requested_command.lower() |
| 798 | similarity_function_to_use = similarity_function_to_use or similarity_function |
| 799 | for each in options: |
| 800 | simil = similarity_function_to_use(each.lower(), requested_command_to_compare) |
| 801 | if best_simil < simil: |
| 802 | best_simil = simil |
| 803 | proposed_command = each |
| 804 | return proposed_command |
| 805 | |
| 806 | |
| 807 | def get_types(func_or_method: Callable[..., Any]) -> tuple[dict[str, Any], Any]: |
no outgoing calls
no test coverage detected
searching dependent graphs…