Guest User

Untitled

a guest
Oct 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Usage: ./main -d <dictionary> -w word2check
  2.  
  3. \begin{code}
  4.  
  5. module Main (main) where
  6. import SpellChecker.Core
  7. import System.Environment
  8. import System.Console.GetOpt
  9. import Data.Maybe
  10. import Char
  11. import Control.Applicative
  12. import qualified Data.ByteString.Lazy.Char8 as L
  13. import Debug.Trace
  14.  
  15. data Options = Options {
  16. dictFile :: Maybe String,
  17. wordToCheck :: Maybe String
  18. }
  19.  
  20. defaultOptions :: Options
  21. defaultOptions = Options {
  22. dictFile = Just "big.txt",
  23. wordToCheck = Just "testt"
  24. }
  25.  
  26. options =
  27. [Option ['d'] [] (OptArg (\arg opt -> return opt { dictFile = arg }) "DictionaryFile")
  28. "The dictionary file."
  29. ,Option ['w'] [] (ReqArg (\arg opt -> return opt { wordToCheck = Just arg }) "WordToCheck")
  30. "The word to check."
  31. ]
  32.  
  33. main = do
  34. args <- getArgs
  35. let (actions, nonops, msgs) = getOpt RequireOrder options args
  36. opts <- foldl ( >>= ) (return defaultOptions) actions
  37. let Options { dictFile = dictFile, wordToCheck = wordToCheck } = opts
  38.  
  39. let dictionary = fromJust dictFile
  40. let checkee = fromJust wordToCheck
  41. putTraceMsg $ "Start to load dictionary file " ++ dictionary
  42. content <- L.map toLower <$> (L.readFile dictionary)
  43. putTraceMsg $ "Loaded dictionary file. Now check spelling for " ++ checkee
  44. let sorted_candidates = check content (L.pack checkee)
  45. mapM_ L.putStrLn sorted_candidates
  46.  
  47. \end{code}
Add Comment
Please, Sign In to add comment