zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

suggestion.ex (580B)


      1 defmodule Absinthe.Utils.Suggestion do
      2   @jaro_threshold 0.70
      3 
      4   @doc """
      5   Sort a list of suggestions by Jaro distance to a target string,
      6   supporting a cut-off threshold.
      7   """
      8   @spec sort_list([String.t()], String.t(), float) :: [String.t()]
      9   def sort_list(suggestions, target, threshold \\ @jaro_threshold)
     10 
     11   def sort_list(suggestions, target, threshold) do
     12     Enum.map(suggestions, fn s -> {s, String.jaro_distance(s, target)} end)
     13     |> Enum.filter(fn {_, x} -> x >= threshold end)
     14     |> Enum.sort_by(fn {_, x} -> x end)
     15     |> Enum.map(fn {s, _} -> s end)
     16   end
     17 end