Textonyms: Difference between revisions
m
→{{header|Haskell}}: hlint, hindent – minor tidying
m (C code modified to use GLib I/O functions to load the dictionary) |
m (→{{header|Haskell}}: hlint, hindent – minor tidying) |
||
Line 821:
=={{header|Haskell}}==
<lang haskell>import Data.Maybe (isJust, isNothing, fromMaybe)
import Data.List (sortBy, groupBy)▼
import Data.Char (toUpper)
▲import Data.List (sortBy, groupBy)
import Data.Function (on)
toKey :: Char -> Maybe Char
toKey ch
toKeyString :: String -> Maybe String
toKeyString st
| any
where
▲ else Just $ map (fromMaybe '!') mch
mch = map (toKey . toUpper) st
showTextonym :: [(String, String)] ->
showTextonym ts =
" => " ++
concat
| (_, w) <- ts ]
main :: IO ()
main = do
keyedList =
▲ let wordList = lines contents
[ (key, word)
| (Just key, word) <-
groupedList = groupBy ((==) `on` fst) $ sortBy (compare `on` fst) keyedList▼
textonymList = filter ((> 1) . length) groupedList
putStrLn $ "There are " ++ show (length keyedList) ++ " words in " ++ src ++ " which can be represented by the digit key mapping."▼
mapM_ putStrLn $
putStrLn $ "They require " ++ show (length groupedList) ++ " digit combinations to represent them."▼
[ "There are " ++
putStrLn $ show (length textonymList) ++ " digit combinations represent Textonyms."▼
show (length keyedList) ++
▲ putStrLn ""
▲
mapM_ showTextonym $ take 5 $ sortBy (flip compare `on` length) textonymList▼
▲
putStrLn "Top 5 in length:"▼
mapM_ showTextonym $ take 5 $ sortBy (flip compare `on` (length.fst.head)) textonymList </lang>▼
, ""
, "Top 5 in ambiguity:"
] ++
fmap
showTextonym
▲
{{out}}
<pre style="font-size:80%">There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
|