add function for evaluating single lines
This commit is contained in:
parent
8d87ee4c4b
commit
a2814f2d12
@ -8,6 +8,8 @@
|
||||
module GEval.Core
|
||||
( geval,
|
||||
gevalCore,
|
||||
gevalCoreOnSingleLines,
|
||||
LineInFile(..),
|
||||
Metric(..),
|
||||
MetricOrdering(..),
|
||||
getMetricOrdering,
|
||||
@ -231,6 +233,16 @@ fileAsLineSource :: FilePath -> LineSource (ResourceT IO)
|
||||
fileAsLineSource filePath =
|
||||
LineSource (CB.sourceFile filePath $= CT.decodeUtf8Lenient =$= CT.lines) filePath 1
|
||||
|
||||
gevalCoreOnSingleLines :: Metric -> LineInFile -> LineInFile -> LineInFile -> IO (MetricValue)
|
||||
gevalCoreOnSingleLines metric inpLine expLine outLine =
|
||||
gevalCoreOnSources metric (singleLineAsLineSource inpLine)
|
||||
(singleLineAsLineSource expLine)
|
||||
(singleLineAsLineSource outLine)
|
||||
|
||||
singleLineAsLineSource :: LineInFile -> LineSource (ResourceT IO)
|
||||
singleLineAsLineSource (LineInFile filePath lineNo line) =
|
||||
LineSource (CL.sourceList [line]) filePath lineNo
|
||||
|
||||
gevalCore :: Metric -> String -> String -> String -> IO (MetricValue)
|
||||
gevalCore metric inputFilePath expectedFilePath outFilePath = do
|
||||
unlessM (D.doesFileExist expectedFilePath) $ throwM $ NoExpectedFile expectedFilePath
|
||||
@ -253,6 +265,8 @@ gevalCoreOnSources RMSE inputLineSource expectedLineSource outLineSource = do
|
||||
gevalCoreOnSources metric inputLineSource expectedLineSource outLineSource = do
|
||||
gevalCore' metric inputLineSource expectedLineSource outLineSource
|
||||
|
||||
data LineInFile = LineInFile FilePath Int Text
|
||||
|
||||
gevalCore' :: (MonadIO m, MonadThrow m, MonadBaseControl IO m) => Metric -> LineSource (ResourceT m) -> LineSource (ResourceT m) -> LineSource (ResourceT m) -> m (MetricValue)
|
||||
gevalCore' MSE _ = gevalCoreWithoutInput outParser outParser itemError averageC id
|
||||
where outParser = getValue . TR.double
|
||||
|
@ -175,6 +175,12 @@ main = hspec $ do
|
||||
["one", "one"]) `shouldBeAlmost` 0.5
|
||||
it "simple test" $ do
|
||||
runGEvalTest "map-simple" `shouldReturnAlmost` 0.444444444
|
||||
describe "evaluating single lines" $ do
|
||||
it "RMSE" $ do
|
||||
gevalCoreOnSingleLines RMSE (LineInFile "stub1" 1 "blabla")
|
||||
(LineInFile "stub2" 1 "3.4")
|
||||
(LineInFile "stub3" 1 "2.6") `shouldReturnAlmost` 0.8
|
||||
|
||||
|
||||
neverMatch :: Char -> Int -> Bool
|
||||
neverMatch _ _ = False
|
||||
|
Loading…
Reference in New Issue
Block a user