API
ArguMend.@argumend
— Macro@argumend [n_suggestions=3] [cutoff=0.6] funcdef
This macro lets you automatically suggest similarly-spelled keywords:
@argumend function f(a, b; niterations=10, kw2=2)
a + b - niterations + kw2
end
This results in a nicer mechanism for MethodErrors:
julia> f(1, 2; iterations=1)
ERROR: SuggestiveMethodError: in call to `f`, found unsupported
keyword argument: `iterations`, perhaps you meant `niterations`
This function computes closeness between the mistyped keyword argument by counting the maximum number of matching subsequences with all the other keyword arguments.
You can customize the number of suggestions by specifying it in the macro. You can also control the closeness threshold with cutoff
.
ArguMend.extract_close_matches
— Functionextract_close_matches(key, candidates; n=3, cutoff=0.6)
Finds and returns up to n
close matches from candidates
for a given key
based on a similarity ratio. The similarity ratio is calculated using the similarity_ratio
function, which compares matching subsequences.
Arguments
key
: The string or sequence for which close matches are sought.candidates
: An array of strings or sequences against which thekey
is compared.
Optional keywords
n
: The maximum number of close matches to return (default is 3).cutoff
: The minimum similarity ratio required for a candidate to be considered a close match (default is 0.6).
Returns
- An array of up to
n
candidates that have a similarity ratio above thecutoff
.
Examples
julia> mistyped_kw = "iterations";
julia> candidate_kws = ["niterations", "ncycles_per_iteration", "niterations_per_cycle", "abcdef", "iter"];
julia> extract_close_matches(mistyped_kw, candidate_kws)
["niterations", "niterations_per_cycle"]