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.Maybe (isJust, isNothing, fromMaybe)
<lang haskell>import Data.Char (toUpper)
import Data.List (sortBy, groupBy)
import Data.Char (toUpper)
import Data.Function (on)
import Data.Function (on)
import Data.List (groupBy, sortBy)
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) $ zip (map toKeyString wordList) wordList ]
filter (isJust . fst) $
groupedList = groupBy ((==) `on` fst) $ sortBy (compare `on` fst) keyedList
zip (map toKeyString wordList) wordList
]
groupedList =
groupBy ((==) `on` fst) $
sortBy (compare `on` fst) keyedList
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
src ++ " which can be represented by the digit key mapping."
++ " which can be represented by the digit key mapping.",
, "They require " ++
"They require "
show (length groupedList) ++ " digit combinations to represent them."
++ show (length groupedList)
, show (length textonymList) ++ " digit combinations represent Textonyms."
++ " digit combinations to represent them.",
, ""
show (length textonymList) ++ " digit combinations represent Textonyms.",
, "Top 5 in ambiguity:"
] ++
"",
"Top 5 in ambiguity:"
fmap showTextonym (take 5 $ sortBy (flip compare `on` length) textonymList) ++
]
["", "Top 5 in length:"] ++
fmap
++ fmap
''Italic text'' showTextonym
showTextonym
( take 5 $
(take 5 $ sortBy (flip compare `on` (length . fst . head)) textonymList)</lang>
sortBy (flip compare `on` length) textonymList
)
++ ["", "Top 5 in length:"]
++ 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.