introduce GEvalSpecification

This commit is contained in:
Filip Gralinski 2015-08-21 22:56:32 +02:00 committed by Filip Gralinski
parent 33f4af1c38
commit 6290250125
5 changed files with 51 additions and 6 deletions

View File

@ -6,5 +6,5 @@ import System.Environment
main :: IO () main :: IO ()
main = do main = do
[expectedFilePath, outFilePath] <- getArgs [expectedFilePath, outFilePath] <- getArgs
result <- geval expectedFilePath outFilePath result <- gevalCore MSE expectedFilePath outFilePath
print $ result print $ result

View File

@ -20,6 +20,7 @@ library
, conduit , conduit
, conduit-combinators , conduit-combinators
, conduit-extra , conduit-extra
, filepath
, resourcet , resourcet
, text , text
default-language: Haskell2010 default-language: Haskell2010

View File

@ -1,5 +1,9 @@
module GEval module GEval
( geval ( geval,
gevalCore,
Metric(..),
GEvalSpecification(..),
defaultGEvalSpecification
) where ) where
import Data.Conduit import Data.Conduit
@ -12,8 +16,48 @@ import Data.Text
import Data.Text.Read as TR import Data.Text.Read as TR
import Control.Applicative import Control.Applicative
geval :: String -> String -> IO (Double) import System.FilePath
geval expectedFilePath outFilePath = do import Data.Maybe
data Metric = MSE | BLEU
defaultOutDirectory = "."
defaultTestName = "test-A"
defaultOutFile = "out.tsv"
defaultExpectedFile = "expected.tsv"
defaultMetric :: Metric
defaultMetric = MSE
data GEvalSpecification = GEvalSpecification
{ gesOutDirectory :: String,
gesExpectedDirectory :: Maybe String,
gesTestName :: String,
gesOutFile :: String,
gesExpectedFile :: String,
gesMetric :: Metric }
defaultGEvalSpecification = GEvalSpecification {
gesOutDirectory = defaultOutDirectory,
gesExpectedDirectory = Nothing,
gesTestName = defaultTestName,
gesOutFile = defaultOutFile,
gesExpectedFile = defaultExpectedFile,
gesMetric = defaultMetric }
geval :: GEvalSpecification -> IO (Double)
geval gevalSpec = gevalCore metric expectedFilePath outFilePath
where expectedFilePath = expectedDirectory </> testName </> (gesExpectedFile gevalSpec)
outFilePath = outDirectory </> testName </> (gesOutFile gevalSpec)
expectedDirectory = fromMaybe outDirectory $ gesExpectedDirectory gevalSpec
outDirectory = gesOutDirectory gevalSpec
testName = gesTestName gevalSpec
metric = gesMetric gevalSpec
gevalCore :: Metric -> String -> String -> IO (Double)
gevalCore MSE expectedFilePath outFilePath = do
mse <- runResourceT $ mse <- runResourceT $
(getZipSource $ (,) (getZipSource $ (,)
<$> ZipSource (items expectedFilePath) <$> ZipSource (items expectedFilePath)

View File

@ -2,4 +2,4 @@ flags: {}
packages: packages:
- '.' - '.'
extra-deps: [] extra-deps: []
resolver: lts-2.19 resolver: nightly-2015-08-06

View File

@ -7,7 +7,7 @@ main :: IO ()
main = hspec $ do main = hspec $ do
describe "mean square error" $ do describe "mean square error" $ do
it "simple test" $ do it "simple test" $ do
geval "test/mse-simple/mse-simple/test-A/expected.tsv" "test/mse-simple/mse-simple-solution/test-A/out.tsv" `shouldReturnAlmost` 0.64549722436790 geval (defaultGEvalSpecification {gesExpectedDirectory=Just "test/mse-simple/mse-simple", gesOutDirectory="test/mse-simple/mse-simple-solution"}) `shouldReturnAlmost` 0.64549722436790
class AEq a where class AEq a where
(=~) :: a -> a -> Bool (=~) :: a -> a -> Bool