Skip to content

Commit

Permalink
Use string normalization to replace accented letter with ascii letters
Browse files Browse the repository at this point in the history
  • Loading branch information
papey committed Mar 16, 2021
1 parent 92b0166 commit 050b4c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/blindtest/blindtest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ defmodule BlindTest do
[
%GuessEntry{
url: url,
f1s: Enum.map(String.split(f1s, "|"), &String.trim(&1)),
f2s: Enum.map(String.split(f2s, "|"), &String.trim(&1))
f1s: Enum.map(String.split(f1s, "|"), &BlindTest.sanitize_input/1),
f2s: Enum.map(String.split(f2s, "|"), &BlindTest.sanitize_input/1)
}
]}}}

Expand Down Expand Up @@ -230,7 +230,7 @@ defmodule BlindTest do
"abc"
"""
def sanitize_input(input) do
String.trim(input)
String.normalize(input, :nfd)
|> String.replace(~r/[^a-zA-Z0-9 -]/, "")
|> String.replace(~r/\s+/, " ")
|> String.downcase()
Expand All @@ -247,7 +247,7 @@ defmodule BlindTest do
"""
def verify_answer(expected, proposal, threshold \\ 0.2) do
valid? =
&(Levenshtein.distance(sanitize_input(&1), sanitize_input(proposal)) /
&(Levenshtein.distance(&1, sanitize_input(proposal)) /
String.length(Enum.max([expected, proposal])) < threshold)

both_combinations =
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule O2M.MixProject do
def project do
[
app: :o2m,
version: "0.7.5",
version: "0.7.6",
elixir: "~> 1.10",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down

0 comments on commit 050b4c2

Please sign in to comment.