From 759c258ecbb83843eb7846ed7c94a188be80017d Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sat, 22 Aug 2015 00:00:46 +0200 Subject: [PATCH] start parsing options --- app/Main.hs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-- geval.cabal | 1 + src/GEval.hs | 14 ++++++++++++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 7a88db3..32584dc 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -3,8 +3,62 @@ module Main where import GEval import System.Environment +import Options.Applicative + +fullOptionsParser = info (helper <*> optionsParser) + (fullDesc + <> progDesc "Run evaluation for tests in Gonito platform" + <> header "geval - stand-alone evaluation tool for tests in Gonito platform") + +optionsParser :: Parser GEvalOptions +optionsParser = GEvalOptions + <$> switch + ( long "init" + <> help "Init a sample Gonito challange rather than run an evaluation" ) + <*> specParser + +specParser :: Parser GEvalSpecification +specParser = GEvalSpecification + <$> strOption + ( long "out-directory" + <> value defaultOutDirectory + <> showDefault + <> metavar "OUT-DIRECTORY" + <> help "Directory with test results to be evaluated" ) + <*> optional (strOption + ( long "expected-directory" + <> metavar "EXPECTED-DIRECTORY" + <> help "Directory with expected test results (if not specified the same as OUT-DIRECTORY)" )) + <*> strOption + ( long "test-name" + <> value defaultTestName + <> showDefault + <> metavar "NAME" + <> help "Test name (i.e. subdirectory with results or expected results)" ) + <*> strOption + ( long "out-file" + <> value defaultOutFile + <> showDefault + <> metavar "OUT" + <> help "The name of the file to be evaluated" ) + <*> strOption + ( long "expected-file" + <> value defaultExpectedFile + <> showDefault + <> metavar "EXPECTED" + <> help "The name of the file with expected results" ) + <*> metricReader + +metricReader :: Parser Metric +metricReader = option auto + ( long "metric" + <> value defaultMetric + <> showDefault + <> metavar "METRIC" + <> help "Metric to be used" ) + main :: IO () main = do - [expectedFilePath, outFilePath] <- getArgs - result <- gevalCore MSE expectedFilePath outFilePath + opts <- execParser fullOptionsParser + result <- geval $ geoSpec opts print $ result diff --git a/geval.cabal b/geval.cabal index 47d1d35..a1655dd 100644 --- a/geval.cabal +++ b/geval.cabal @@ -31,6 +31,7 @@ executable geval-exe ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: base , geval + , optparse-applicative default-language: Haskell2010 test-suite geval-test diff --git a/src/GEval.hs b/src/GEval.hs index 87dc636..e86dcc1 100644 --- a/src/GEval.hs +++ b/src/GEval.hs @@ -3,7 +3,13 @@ module GEval gevalCore, Metric(..), GEvalSpecification(..), - defaultGEvalSpecification + GEvalOptions(..), + defaultGEvalSpecification, + defaultOutDirectory, + defaultTestName, + defaultOutFile, + defaultExpectedFile, + defaultMetric ) where import Data.Conduit @@ -20,6 +26,7 @@ import System.FilePath import Data.Maybe data Metric = MSE | BLEU + deriving (Show, Read) defaultOutDirectory = "." defaultTestName = "test-A" @@ -29,6 +36,7 @@ defaultExpectedFile = "expected.tsv" defaultMetric :: Metric defaultMetric = MSE + data GEvalSpecification = GEvalSpecification { gesOutDirectory :: String, gesExpectedDirectory :: Maybe String, @@ -37,6 +45,10 @@ data GEvalSpecification = GEvalSpecification gesExpectedFile :: String, gesMetric :: Metric } +data GEvalOptions = GEvalOptions + { geoInit :: Bool, + geoSpec :: GEvalSpecification } + defaultGEvalSpecification = GEvalSpecification { gesOutDirectory = defaultOutDirectory,