Use DataSource in LineByLine
This commit is contained in:
parent
454f60812c
commit
2f348dd616
@ -26,6 +26,7 @@ module GEval.LineByLine
|
|||||||
|
|
||||||
import GEval.Core
|
import GEval.Core
|
||||||
import GEval.Common
|
import GEval.Common
|
||||||
|
import GEval.DataSource
|
||||||
import GEval.EvaluationScheme
|
import GEval.EvaluationScheme
|
||||||
import Text.Tokenizer
|
import Text.Tokenizer
|
||||||
|
|
||||||
@ -463,7 +464,10 @@ lessByMetric reversed metric = lessByMetric' reversed (getMetricOrdering metric)
|
|||||||
(\(LineRecord _ _ _ _ scoreA) (LineRecord _ _ _ _ scoreB) ->
|
(\(LineRecord _ _ _ _ scoreA) (LineRecord _ _ _ _ scoreB) ->
|
||||||
scoreA < scoreB)
|
scoreA < scoreB)
|
||||||
|
|
||||||
runLineByLineGeneralized :: ResultOrdering -> GEvalSpecification -> (Maybe References -> ConduitT LineRecord Void (ResourceT IO) a) -> IO a
|
runLineByLineGeneralized :: ResultOrdering
|
||||||
|
-> GEvalSpecification
|
||||||
|
-> (Maybe References -> ConduitT LineRecord Void (ResourceT IO) a)
|
||||||
|
-> IO a
|
||||||
runLineByLineGeneralized ordering spec consum = do
|
runLineByLineGeneralized ordering spec consum = do
|
||||||
mReferences <- case gesReferences spec of
|
mReferences <- case gesReferences spec of
|
||||||
Just referencesFp -> do
|
Just referencesFp -> do
|
||||||
@ -474,7 +478,18 @@ runLineByLineGeneralized ordering spec consum = do
|
|||||||
mInHeader <- readHeaderFileWrapper $ getInHeader spec
|
mInHeader <- readHeaderFileWrapper $ getInHeader spec
|
||||||
mOutHeader <- readHeaderFileWrapper $ getOutHeader spec
|
mOutHeader <- readHeaderFileWrapper $ getOutHeader spec
|
||||||
let mOutHeader = Nothing
|
let mOutHeader = Nothing
|
||||||
gevalLineByLineCore metric mSelector preprocess mInHeader mOutHeader inputFilePath expectedFilePath outFilePath (sorter ordering .| consum mReferences)
|
let chDataSource = ChallengeDataSource {
|
||||||
|
challengeDataSourceInput = inputFilePath,
|
||||||
|
challengeDataSourceExpected = expectedFilePath,
|
||||||
|
challengeDataSourceSelector = mSelector,
|
||||||
|
challengeDataSourcePreprocess = preprocess,
|
||||||
|
challengeDataSourceFilter = Nothing,
|
||||||
|
challengeDataSourceInHeader = mInHeader,
|
||||||
|
challengeDataSourceOutHeader = mOutHeader }
|
||||||
|
let dataSource = DataSource {
|
||||||
|
dataSourceChallengeData = chDataSource,
|
||||||
|
dataSourceOut = outFilePath }
|
||||||
|
gevalLineByLineCore metric dataSource (sorter ordering .| consum mReferences)
|
||||||
where metric = gesMainMetric spec
|
where metric = gesMainMetric spec
|
||||||
scheme = gesMainScheme spec
|
scheme = gesMainScheme spec
|
||||||
mSelector = gesSelector spec
|
mSelector = gesSelector spec
|
||||||
@ -532,7 +547,17 @@ runMultiOutputGeneralized spec consum = do
|
|||||||
let sourceSpecs = (outSource:altSourceSpecs)
|
let sourceSpecs = (outSource:altSourceSpecs)
|
||||||
mInHeader <- readHeaderFileWrapper $ getInHeader spec
|
mInHeader <- readHeaderFileWrapper $ getInHeader spec
|
||||||
mOutHeader <- readHeaderFileWrapper $ getOutHeader spec
|
mOutHeader <- readHeaderFileWrapper $ getOutHeader spec
|
||||||
let sources = Prelude.map (gevalLineByLineSource metric mSelector preprocess mInHeader mOutHeader inputSource expectedSource) sourceSpecs
|
let chDataSource = ChallengeDataSource {
|
||||||
|
challengeDataSourceInput = inputSource,
|
||||||
|
challengeDataSourceExpected = expectedSource,
|
||||||
|
challengeDataSourceSelector = mSelector,
|
||||||
|
challengeDataSourcePreprocess = preprocess,
|
||||||
|
challengeDataSourceFilter = Nothing,
|
||||||
|
challengeDataSourceInHeader = mInHeader,
|
||||||
|
challengeDataSourceOutHeader = mOutHeader }
|
||||||
|
let sources = Prelude.map (\s -> gevalLineByLineSource metric DataSource {
|
||||||
|
dataSourceChallengeData = chDataSource,
|
||||||
|
dataSourceOut = s}) sourceSpecs
|
||||||
runResourceT $ runConduit $
|
runResourceT $ runConduit $
|
||||||
(sequenceSources sources .| consum)
|
(sequenceSources sources .| consum)
|
||||||
where metric = gesMainMetric spec
|
where metric = gesMainMetric spec
|
||||||
@ -569,8 +594,22 @@ runDiffGeneralized ordering otherOut spec consum = do
|
|||||||
Left (NoFile fp) -> throwM $ NoOutFile fp
|
Left (NoFile fp) -> throwM $ NoOutFile fp
|
||||||
Left (NoDirectory d) -> throwM $ NoOutFile otherOut
|
Left (NoDirectory d) -> throwM $ NoOutFile otherOut
|
||||||
Right otherOutSource -> do
|
Right otherOutSource -> do
|
||||||
let sourceA = gevalLineByLineSource metric mSelector preprocess mInHeader mOutHeader inputSource expectedSource otherOutSource
|
let chDataSource = ChallengeDataSource {
|
||||||
let sourceB = gevalLineByLineSource metric mSelector preprocess mInHeader mOutHeader inputSource expectedSource outSource
|
challengeDataSourceInput = inputSource,
|
||||||
|
challengeDataSourceExpected = expectedSource,
|
||||||
|
challengeDataSourceSelector = mSelector,
|
||||||
|
challengeDataSourcePreprocess = preprocess,
|
||||||
|
challengeDataSourceFilter = Nothing,
|
||||||
|
challengeDataSourceInHeader = mInHeader,
|
||||||
|
challengeDataSourceOutHeader = mOutHeader }
|
||||||
|
let dataSourceA = DataSource {
|
||||||
|
dataSourceChallengeData = chDataSource,
|
||||||
|
dataSourceOut = otherOutSource}
|
||||||
|
let dataSourceB = DataSource {
|
||||||
|
dataSourceChallengeData = chDataSource,
|
||||||
|
dataSourceOut = outSource}
|
||||||
|
let sourceA = gevalLineByLineSource metric dataSourceA
|
||||||
|
let sourceB = gevalLineByLineSource metric dataSourceB
|
||||||
runResourceT $ runConduit $
|
runResourceT $ runConduit $
|
||||||
((getZipSource $ (,)
|
((getZipSource $ (,)
|
||||||
<$> ZipSource sourceA
|
<$> ZipSource sourceA
|
||||||
@ -592,21 +631,18 @@ runDiffGeneralized ordering otherOut spec consum = do
|
|||||||
escapeTabs :: Text -> Text
|
escapeTabs :: Text -> Text
|
||||||
escapeTabs = Data.Text.replace "\t" "<tab>"
|
escapeTabs = Data.Text.replace "\t" "<tab>"
|
||||||
|
|
||||||
gevalLineByLineCore :: Metric -> Maybe Selector -> (Text -> Text) -> (Maybe TabularHeader) -> (Maybe TabularHeader) -> SourceSpec -> SourceSpec -> SourceSpec -> ConduitT LineRecord Void (ResourceT IO) a -> IO a
|
gevalLineByLineCore :: Metric
|
||||||
gevalLineByLineCore metric mSelector preprocess mInHeader mOutHeader inputSource expectedSource outSource consum =
|
-> DataSource
|
||||||
|
-> ConduitT LineRecord Void (ResourceT IO) a
|
||||||
|
-> IO a
|
||||||
|
gevalLineByLineCore metric dataSource consum =
|
||||||
runResourceT $ runConduit $
|
runResourceT $ runConduit $
|
||||||
((gevalLineByLineSource metric mSelector preprocess mInHeader mOutHeader inputSource expectedSource outSource) .| consum)
|
((gevalLineByLineSource metric dataSource) .| consum)
|
||||||
|
|
||||||
gevalLineByLineSource :: Metric
|
gevalLineByLineSource :: Metric
|
||||||
-> Maybe Selector
|
-> DataSource
|
||||||
-> (Text -> Text)
|
|
||||||
-> (Maybe TabularHeader)
|
|
||||||
-> (Maybe TabularHeader)
|
|
||||||
-> SourceSpec
|
|
||||||
-> SourceSpec
|
|
||||||
-> SourceSpec
|
|
||||||
-> ConduitT () LineRecord (ResourceT IO) ()
|
-> ConduitT () LineRecord (ResourceT IO) ()
|
||||||
gevalLineByLineSource metric mSelector preprocess mInHeader mOutHeader inputSource expectedSource outSource =
|
gevalLineByLineSource metric dataSource =
|
||||||
(getZipSource $ (,)
|
(getZipSource $ (,)
|
||||||
<$> ZipSource (CL.sourceList [1..])
|
<$> ZipSource (CL.sourceList [1..])
|
||||||
<*> (ZipSource $ threeLineSource context)) .| CL.mapM (checkStepM evaluateLine) .| CL.catMaybes
|
<*> (ZipSource $ threeLineSource context)) .| CL.mapM (checkStepM evaluateLine) .| CL.catMaybes
|
||||||
@ -629,6 +665,14 @@ gevalLineByLineSource metric mSelector preprocess mInHeader mOutHeader inputSour
|
|||||||
fileProcessingOptionsSelector = mSelector,
|
fileProcessingOptionsSelector = mSelector,
|
||||||
fileProcessingOptionsPreprocess = id,
|
fileProcessingOptionsPreprocess = id,
|
||||||
fileProcessingOptionsHeader = mInHeader }
|
fileProcessingOptionsHeader = mInHeader }
|
||||||
|
challengeDataSource = dataSourceChallengeData dataSource
|
||||||
|
mSelector = challengeDataSourceSelector challengeDataSource
|
||||||
|
preprocess = challengeDataSourcePreprocess challengeDataSource
|
||||||
|
mInHeader = challengeDataSourceInHeader challengeDataSource
|
||||||
|
mOutHeader = challengeDataSourceOutHeader challengeDataSource
|
||||||
|
inputSource = challengeDataSourceInput challengeDataSource
|
||||||
|
expectedSource = challengeDataSourceExpected challengeDataSource
|
||||||
|
outSource = dataSourceOut dataSource
|
||||||
|
|
||||||
|
|
||||||
justTokenize :: Maybe Tokenizer -> IO ()
|
justTokenize :: Maybe Tokenizer -> IO ()
|
||||||
|
Loading…
Reference in New Issue
Block a user