introduce GEvalSpecification
This commit is contained in:
parent
33f4af1c38
commit
6290250125
@ -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
|
||||||
|
@ -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
|
||||||
|
50
src/GEval.hs
50
src/GEval.hs
@ -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)
|
||||||
|
@ -2,4 +2,4 @@ flags: {}
|
|||||||
packages:
|
packages:
|
||||||
- '.'
|
- '.'
|
||||||
extra-deps: []
|
extra-deps: []
|
||||||
resolver: lts-2.19
|
resolver: nightly-2015-08-06
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user