Textonyms: Difference between revisions

m
Line 1,209:
------------------------ TEXTONYMS -----------------------
 
digitEncoded :: M.Map Char Char -> [String] -> [(String, String)]
M.Map Char Char ->
[String] ->
[(String, String)]
digitEncoded dict =
mapMaybe $
Line 1,238 ⟶ 1,241:
s <- readFile fp
let encodings = digitEncoded charDict $ lines s
codeGroups = groupBy (on (==) snd) . sortOn snd $ encodings
groupBy
(on (==) snd)
. sortOn snd
$ encodings
textonyms = filter ((1 <) . length) codeGroups
mapM_
Line 1,246 ⟶ 1,253:
<> " words in "
<> fp
<> " which can be represented by the digit key mapping.\n",
<> "Theyby the digit requirekey mapping.",
"\nThey require "
<> show (length codeGroups)
<> " digit combinations to represent them.",
show (length textonyms) <> " digit combinations represent textonyms.",
<> " digit combinations represent textonyms.",
""
]
let codeLength = length . snd . head
[ambiguous, longer] = definedSamples 5 textonyms [length, codeLength]
definedSamples
[wa, wl] = maximum . fmap codeLength <$> [ambiguous, longer]
5
textonyms
[length, codeLength]
[wa, wl] =
[wa, wl] = maximum . fmap codeLength <$> [ambiguous, longer]
<$> [ambiguous, longer]
mapM_ putStrLn $
"Five most ambiguous:" :
fmap (showTextonym wa) ambiguous
<> ("" : "Five longest:" : fmap (showTextonym wl) longer)
"Five longest:" :
fmap
(showTextonym wl)
longer
)
 
------------------------- DISPLAY ------------------------
showTextonym :: Int -> [(String, String)] -> String
showTextonym w ts =
concat
concat [ rjust w ' ' (snd (head ts)), " -> ", unwords $ fmap fst ts]
" -> ",
unwords $ fmap fst ts
]
where
rjust n c = (drop . length) <*> (replicate n c <>)</lang>
{{Out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
by the digit key mapping.
 
They require 22903 digit combinations to represent them.
1473 digit combinations represent textonyms.
 
5Five most ambiguous:
269 -> amy any bmw bow box boy cow cox coy
729 -> paw pax pay paz raw ray saw sax say
Line 1,279 ⟶ 1,305:
426 -> gam gao ham han ian ibm ibn
 
5Five longest:
25287876746242 -> claustrophobia claustrophobic
7244967473642 -> schizophrenia schizophrenic
9,659

edits