Textonyms: Difference between revisions

m
(→‎{{header|C++}}: minor modifications)
Line 1,124:
Or, in terms of ''Data.Map'' and ''traverse'':
 
<lang haskell>import Data.ListFunction (groupBy, maximum, sortBy, sortOnon)
import Data.List (groupBy, maximum, sortBy, sortOn)
import qualified Data.Map as M
import Data.Maybe (mapMaybe)
import Data.Ord (comparing)
 
import Data.Function (on)
------------------------ TEXTONYMS -----------------------
 
digitEncoded :: M.Map Char Char -> [String] -> [(String, String)]
digitEncoded dict = mapMaybe $ ((>>=) . traverse (`M.lookup` dict)) <*> curry Just
mapMaybe $
((>>=) . traverse (`M.lookup` dict))
<*> curry Just
 
charDict :: M.Map Char Char
charDict =
M.fromList $
concat $
zipWith
(fmap . flip (,))
(head . show <$> [2 ..])
(words "abc def ghi jkl mno pqrs tuv wxyz")
 
definedSamples ::
:: Int ->
-> [[(String, String)]] ->
-> [[(String, String)] -> Int] ->
-> [[[(String, String)]]]
definedSamples n xs fs =
[take n . flip sortBy xs] <*> (flip . comparing <$> fs)
 
--------------------------- TEST ---------------------------
main :: IO ()
main = do
Line 1,160 ⟶ 1,165:
mapM_
putStrLn
[ "There are " ++
<> show (length encodings) ++
<> " words in " ++
<> fp
fp ++ <> " which can be represented by the digit key mapping.",
, "They require " ++
show (length codeGroups) ++ " digit combinations to represent them."
, <> show (length textonymscodeGroups) ++ " digit combinations represent textonyms."
<> " digit combinations to represent them.",
, ""
show (length codeGroupstextonyms) ++<> " digit combinations to represent themtextonyms.",
, ""
]
let codeLength = length . snd . head
Line 1,174 ⟶ 1,181:
mapM_ putStrLn $
"Five most ambiguous:" :
fmap (showTextonym wa) ambiguous ++
<> ("" : "Five longest:" : fmap (showTextonym wl) longer)
 
------------------------- DISPLAY --------------------------
showTextonym :: Int -> [(String, String)] -> String
showTextonym w ts =
concat [rjust w ' ' (snd (head ts)), " -> ", unwords $ fmap fst ts]
where
rjust n c = (drop . length) <*> (replicate n c ++<>)</lang>
{{Out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
9,659

edits