Is there a method in Ruby similar to Python's difflib.get_close_matches("<target_string>", "[<array_of_strings>]")
method?
CodePudding user response:
An approach would be
$ gem install amatch
ruby> require 'amatch'
==> true
ruby> "a bee sat on my knee".damerau_levenshtein_similar("a bee sat on my knee")
==> 1.0
ruby> "a bee sat on my knee".damerau_levenshtein_similar("a fly sat on my knee")
==> 0.85
ruby> "a bee sat on my knee".damerau_levenshtein_similar("a BEE sat on my knee")
==> 0.85
ruby> "a bee sat on my knee".damerau_levenshtein_similar("a BEE sat on my knee".downcase)
==> 1.0
ruby> "snow".damerau_levenshtein_similar(["flow", "snowmobile", "sonw"])
==> [0.5, 0.4, 0.75]
Also available:
:hamming_similar
:pair_distance_similar
:longest_subsequence_similar
:levenshtein_similar
:longest_substring_similar
:jaro_similar
:jarowinkler_similar