Textonyms: Difference between revisions

Content deleted Content added
Shuisman (talk | contribs)
Hout (talk | contribs)
→‎{{header|Haskell}}: Removed an apparent editing artefact which impeded compilation
Line 1,119:
 
=={{header|Haskell}}==
<lang haskell>import Data.MaybeChar (isJust, isNothing, fromMaybetoUpper)
import Data.List (sortBy, groupBy)
import Data.Char (toUpper)
import Data.Function (on)
import Data.List (sortBygroupBy, groupBysortBy)
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) $ zip (map toKeyString wordList) wordList ]
groupedList = groupBy ((==) `on` fst) $ sortBy zip (comparemap `on`toKeyString fstwordList) keyedListwordList
]
groupedList =
groupBy ((==) `on` fst) $
(take 5 $ sortBy (flip compare `on` (length . fst . head)) textonymList)</lang>keyedList
textonymList = filter ((> 1) . length) groupedList
mapM_ putStrLn $
[ "There are " ++
++ show (length keyedList) ++
++ " words in " ++
++ src
src ++ " which can be represented by the digit key mapping.",
, "They require " ++
show (length groupedList) ++ " digit combinations to represent them."
++ show (length groupedList)
, show (length textonymList) ++ " digit combinations to represent Textonymsthem.",
, ""
show (length groupedListtextonymList) ++ " digit combinations to represent themTextonyms.",
, "Top 5 in ambiguity:"
] ++ "",
, "Top 5 in ambiguity:"
fmap showTextonym (take 5 $ sortBy (flip compare `on` length) textonymList) ++
]
["", "Top 5 in length:"] ++
++ fmap
''Italic text'' showTextonym
( take 5 $
(take 5 $ sortBy (flip compare `on` (length . fst . head)) textonymList)</lang>
fmap showTextonym (take 5 $ sortBy (flip compare `on` length) textonymList) ++
)
++ ["", "Top 5 in length:"] ++
++ 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.