I tried to improove a function I wrote to modify "castellano" the proper name for spanish to coherent (so that there's no exception rules to phonetics). I made this with StringReplace with a long list of rules.
euzk[cad_] :=
StringReplace[
cad, {"á" -> "a", "é" -> "e", "í" -> "i", "ó" -> "o", "ú" -> "u",
"ca" -> "ka", "ce" -> "ze", "ci" -> "zi", "co" -> "ko",
"cu" -> "ku", "ch" -> "c", "cl" -> "kl", "cr" -> "kr",
"cc" -> "kz", "cg" -> "kg", "cn" -> "kn", "cp" -> "kp",
"ct" -> "kt", "ge" -> "je", "gi" -> "ji", "gue" -> "ge",
"gui" -> "gi", "h" -> "", "qu" -> "k", "v" -> "b", "w" -> "u",
"y" -> "i"}]
As I read about Dispatch and how can make functions run faster I made
eusk = {"á" -> "a", "é" -> "e", "í" -> "i", "ó" -> "o", "ú" -> "u",
"ca" -> "ka", "ce" -> "ze", "ci" -> "zi", "co" -> "ko",
"cu" -> "ku", "ch" -> "c", "cl" -> "kl", "cr" -> "kr",
"cc" -> "kz", "cg" -> "kg", "cn" -> "kn", "cp" -> "kp",
"ct" -> "kt", "ge" -> "je", "gi" -> "ji", "gue" -> "ge",
"gui" -> "gi", "h" -> "", "qu" -> "k", "v" -> "b", "w" -> "u",
"y" -> "i"};
then
deusk = Dispatch[eusk]
and finally
euzk[cad_] := StringReplace[cad, deusk]
But when try to use it... receive
StringReplace::srep: Dispatch[Length: 27] is not a valid string replacement rule.
I can of course leave the function as list of rules, but Dispatch looks like so efficient. Can I use it otherwise? Some advice ?
StringReplacecompiles toRegularExpressiongenerally, makingDispatchis unnecessary. – b3m2a1 Jan 16 '18 at 09:58RegularExpressionsometimes can give you a performance gain (and sometimes opposite). – Alexey Popkov Jan 16 '18 at 10:21