module Main ( main ) where import Control.Monad.Trans.State import Data.Map (Map) import qualified Data.Map as Map import Lib import System.Environment (getArgs, getProgName) import System.Exit (die) import System.IO import System.Random (getStdGen) import UnescapingPrint (ushow) saveDictionary :: FilePath -> Map String [String] -> IO () saveDictionary filePath dict = withFile filePath WriteMode $ \h -> mapM_ (\(k, v) -> hPutStrLn h $ ushow k ++ ": " ++ ushow v) (Map.toList dict) main :: IO () main = getArgs >>= \args -> getStdGen >>= \gen -> case args of (dict1Path:initial:dict2Path:nstr:[]) -> readFile dict1Path >>= \text1 -> readFile dict2Path >>= \text2 -> let dict1 = buildDictionary (processText text1) dict2 = buildDictionary (processText text2) n = read nstr :: Int in saveDictionary "./tmp/dict1.txt" dict1 >> saveDictionary "./tmp/dict2.txt" dict2 >> mapM_ putStrLn (execLogStdGen gen $ twoModelDialog dict1 dict2 initial n) (dictPath:initial:[]) -> readFile dictPath >>= \text -> let dict = buildDictionary (processText text) in saveDictionary "./tmp/dict.txt" dict >> case evalState (processInput dict initial) gen of Just s -> putStrLn s Nothing -> die $ "There is no \"" ++ initial ++ "\" in the constructed dictionary!" _ -> getProgName >>= \arg0 -> die $ "Usage: " ++ arg0 ++ " DICT1 INITIAL [DICT2 N]"