Refactor line-by-line mode
This commit is contained in:
parent
af21031172
commit
b2e3293a12
@ -39,7 +39,8 @@ module GEval.Core
|
|||||||
checkMultipleOuts,
|
checkMultipleOuts,
|
||||||
checkMultipleOutsCore,
|
checkMultipleOutsCore,
|
||||||
gesMainMetric,
|
gesMainMetric,
|
||||||
gesPreprocess
|
gesPreprocess,
|
||||||
|
threeLineSource
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Conduit
|
import Data.Conduit
|
||||||
@ -898,7 +899,11 @@ instance (MonadUnliftIO m, MonadIO m, MonadThrow m) => EvaluationContext (WithIn
|
|||||||
checkStepM _ (_, WrappedParsedRecordWithInput Done Done Done) = return Nothing
|
checkStepM _ (_, WrappedParsedRecordWithInput Done Done Done) = return Nothing
|
||||||
|
|
||||||
|
|
||||||
|
threeLineSource :: (MonadUnliftIO m, MonadIO m, MonadThrow m) => WithInput m Text Text Text -> ConduitT () (WrappedParsedRecord (WithInput m Text Text Text)) (ResourceT m) ()
|
||||||
|
threeLineSource (WithInput inputLineSource expectedLineSource outLineSource) = getZipSource $ (\x (y,z) -> WrappedParsedRecordWithInput x y z)
|
||||||
|
<$> ZipSource (linesAsItems inputLineSource) <*> (ZipSource $ getZipSource $ (,)
|
||||||
|
<$> ZipSource (linesAsItems expectedLineSource)
|
||||||
|
<*> ZipSource (linesAsItems outLineSource))
|
||||||
|
|
||||||
averageC :: MonadResource m => ConduitT Double Void m Double
|
averageC :: MonadResource m => ConduitT Double Void m Double
|
||||||
averageC = getZipSink
|
averageC = getZipSink
|
||||||
@ -906,12 +911,20 @@ averageC = getZipSink
|
|||||||
<$> ZipSink CC.sum
|
<$> ZipSink CC.sum
|
||||||
<*> ZipSink CC.length
|
<*> ZipSink CC.length
|
||||||
|
|
||||||
|
-- | Takes a source of lines and returns a source of lines and returns a conduit of
|
||||||
|
-- items (using a given preprocessor and parser).
|
||||||
items :: MonadResource m => LineSource m -> (Text -> Either String a) -> ConduitT () (SourceItem a) m ()
|
items :: MonadResource m => LineSource m -> (Text -> Either String a) -> ConduitT () (SourceItem a) m ()
|
||||||
items (LineSource lineSource preprocess _ _) parser =
|
items (LineSource lineSource preprocess _ _) parser =
|
||||||
(lineSource .| CL.map (toItem . parser . preprocess)) >> yield Done
|
(lineSource .| CL.map (toItem . parser . preprocess)) >> yield Done
|
||||||
where toItem (Right x) = Got x
|
where toItem (Right x) = Got x
|
||||||
toItem (Left m) = Wrong m
|
toItem (Left m) = Wrong m
|
||||||
|
|
||||||
|
-- | Takes a source of lines and returns a conduit of lines represented as
|
||||||
|
-- items (without preprocessing and parsing!) to be used in line-by-line modes.
|
||||||
|
linesAsItems :: MonadResource m => LineSource m -> ConduitT () (SourceItem Text) m ()
|
||||||
|
linesAsItems (LineSource lineSource _ _ _) =
|
||||||
|
(lineSource .| CL.map Got) >> yield Done
|
||||||
|
|
||||||
itemAbsoluteError :: (Double, Double) -> Double
|
itemAbsoluteError :: (Double, Double) -> Double
|
||||||
itemAbsoluteError (exp, out) = abs (exp-out)
|
itemAbsoluteError (exp, out) = abs (exp-out)
|
||||||
|
|
||||||
|
@ -417,9 +417,9 @@ gevalLineByLineSource :: Metric -> (Text -> Text) -> SourceSpec -> SourceSpec ->
|
|||||||
gevalLineByLineSource metric preprocess inputSource expectedSource outSource =
|
gevalLineByLineSource metric preprocess inputSource expectedSource outSource =
|
||||||
(getZipSource $ (,)
|
(getZipSource $ (,)
|
||||||
<$> ZipSource (CL.sourceList [1..])
|
<$> ZipSource (CL.sourceList [1..])
|
||||||
<*> (ZipSource $ recordSource context parserSpec)) .| CL.mapM (checkStepM evaluateLine) .| CL.catMaybes
|
<*> (ZipSource $ threeLineSource context)) .| CL.mapM (checkStepM evaluateLine) .| CL.catMaybes
|
||||||
where parserSpec = (ParserSpecWithInput (Right . id) (Right . id) (Right . id))
|
where context = (WithInput inputLineSource expectedLineSource outputLineSource)
|
||||||
context = (WithInput inputLineSource expectedLineSource outputLineSource)
|
-- preparing sources, `id` means that no preprocessing is done (to avoid double preprocessing)
|
||||||
inputLineSource = fileAsLineSource inputSource id
|
inputLineSource = fileAsLineSource inputSource id
|
||||||
expectedLineSource = fileAsLineSource expectedSource id
|
expectedLineSource = fileAsLineSource expectedSource id
|
||||||
outputLineSource = fileAsLineSource outSource id
|
outputLineSource = fileAsLineSource outSource id
|
||||||
|
Loading…
Reference in New Issue
Block a user