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