Textonyms: Difference between revisions
→{{header|Haskell}}: Removed an apparent editing artefact which impeded compilation
(→{{header|Haskell}}: Removed an apparent editing artefact which impeded compilation) |
|||
Line 1,119:
=={{header|Haskell}}==
<lang haskell>import Data.
import Data.List (sortBy, groupBy)▼
import Data.Function (on)
import Data.Maybe (fromMaybe, isJust, isNothing)
toKey :: Char -> Maybe Char
Line 1,146:
showTextonym :: [(String, String)] -> String
showTextonym ts =
fst (head ts)
++ " => "
++ concat
[ w ++ " "
| (_, w) <- ts
main :: IO ()
Line 1,159 ⟶ 1,160:
keyedList =
[ (key, word)
| (Just key, word) <-
filter (isJust . fst) $
]
groupedList =
groupBy ((==) `on` fst) $
textonymList = filter ((> 1) . length) groupedList
mapM_ putStrLn $
[ "There are "
++ show (length keyedList)
++ " words in "
++ src
show (length groupedList) ++ " digit combinations to represent them."▼
++ show (length groupedList)
▲ , ""
, "Top 5 in ambiguity:"▼
fmap showTextonym (take 5 $ sortBy (flip compare `on` length) textonymList) ++▼
]
["", "Top 5 in length:"] ++▼
++ fmap
( take 5 $
▲ (take 5 $ sortBy (flip compare `on` (length . fst . head)) textonymList)</lang>
)
++ fmap
showTextonym
(take 5 $ sortBy (flip compare `on` (length . fst . head)) textonymList)</lang>
{{out}}
<pre style="font-size:80%">There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
|