introduce GEvalSpecification
This commit is contained in:
parent
33f4af1c38
commit
6290250125
@ -6,5 +6,5 @@ import System.Environment
|
||||
main :: IO ()
|
||||
main = do
|
||||
[expectedFilePath, outFilePath] <- getArgs
|
||||
result <- geval expectedFilePath outFilePath
|
||||
result <- gevalCore MSE expectedFilePath outFilePath
|
||||
print $ result
|
||||
|
@ -20,6 +20,7 @@ library
|
||||
, conduit
|
||||
, conduit-combinators
|
||||
, conduit-extra
|
||||
, filepath
|
||||
, resourcet
|
||||
, text
|
||||
default-language: Haskell2010
|
||||
|
50
src/GEval.hs
50
src/GEval.hs
@ -1,5 +1,9 @@
|
||||
module GEval
|
||||
( geval
|
||||
( geval,
|
||||
gevalCore,
|
||||
Metric(..),
|
||||
GEvalSpecification(..),
|
||||
defaultGEvalSpecification
|
||||
) where
|
||||
|
||||
import Data.Conduit
|
||||
@ -12,8 +16,48 @@ import Data.Text
|
||||
import Data.Text.Read as TR
|
||||
import Control.Applicative
|
||||
|
||||
geval :: String -> String -> IO (Double)
|
||||
geval expectedFilePath outFilePath = do
|
||||
import System.FilePath
|
||||
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 $
|
||||
(getZipSource $ (,)
|
||||
<$> ZipSource (items expectedFilePath)
|
||||
|
@ -2,4 +2,4 @@ flags: {}
|
||||
packages:
|
||||
- '.'
|
||||
extra-deps: []
|
||||
resolver: lts-2.19
|
||||
resolver: nightly-2015-08-06
|
||||
|
@ -7,7 +7,7 @@ main :: IO ()
|
||||
main = hspec $ do
|
||||
describe "mean square error" $ 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
|
||||
(=~) :: a -> a -> Bool
|
||||
|
Loading…
Reference in New Issue
Block a user