Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Usage: ./main -d <dictionary> -w word2check
- \begin{code}
- module Main (main) where
- import SpellChecker.Core
- import System.Environment
- import System.Console.GetOpt
- import Data.Maybe
- import Char
- import Control.Applicative
- import qualified Data.ByteString.Lazy.Char8 as L
- import Debug.Trace
- data Options = Options {
- dictFile :: Maybe String,
- wordToCheck :: Maybe String
- }
- defaultOptions :: Options
- defaultOptions = Options {
- dictFile = Just "big.txt",
- wordToCheck = Just "testt"
- }
- options =
- [Option ['d'] [] (OptArg (\arg opt -> return opt { dictFile = arg }) "DictionaryFile")
- "The dictionary file."
- ,Option ['w'] [] (ReqArg (\arg opt -> return opt { wordToCheck = Just arg }) "WordToCheck")
- "The word to check."
- ]
- main = do
- args <- getArgs
- let (actions, nonops, msgs) = getOpt RequireOrder options args
- opts <- foldl ( >>= ) (return defaultOptions) actions
- let Options { dictFile = dictFile, wordToCheck = wordToCheck } = opts
- let dictionary = fromJust dictFile
- let checkee = fromJust wordToCheck
- putTraceMsg $ "Start to load dictionary file " ++ dictionary
- content <- L.map toLower <$> (L.readFile dictionary)
- putTraceMsg $ "Loaded dictionary file. Now check spelling for " ++ checkee
- let sorted_candidates = check content (L.pack checkee)
- mapM_ L.putStrLn sorted_candidates
- \end{code}
Add Comment
Please, Sign In to add comment