diff --git a/src/GEval/LineByLine.hs b/src/GEval/LineByLine.hs index d44e9d4..b2ee4b3 100644 --- a/src/GEval/LineByLine.hs +++ b/src/GEval/LineByLine.hs @@ -9,7 +9,9 @@ module GEval.LineByLine (runLineByLine, - runDiff + runLineByLineGeneralized, + runDiff, + runDiffGeneralized ) where import GEval.Core @@ -31,11 +33,8 @@ data LineRecord = LineRecord Text Text Text Word32 MetricValue deriving (Eq, Show) runLineByLine :: GEvalSpecification -> IO () -runLineByLine spec = do - (inputFilePath, expectedFilePath, outFilePath) <- checkAndGetFiles spec - gevalLineByLineCore metric inputFilePath expectedFilePath outFilePath consum - where metric = gesMetric spec - consum :: ConduitT LineRecord Void (ResourceT IO) () +runLineByLine spec = runLineByLineGeneralized spec consum + where consum :: ConduitT LineRecord Void (ResourceT IO) () consum = (CL.map (encodeUtf8 . formatOutput) .| CC.unlinesAscii .| CC.stdout) formatOutput (LineRecord inp exp out _ score) = Data.Text.intercalate "\t" [ formatScore score, @@ -45,18 +44,15 @@ runLineByLine spec = do formatScore :: MetricValue -> Text formatScore = Data.Text.pack . printf "%f" -runDiff :: FilePath -> GEvalSpecification -> IO () -runDiff otherOut spec = do - let otherOutFilePath = getOutFile spec otherOut +runLineByLineGeneralized :: GEvalSpecification -> ConduitT LineRecord Void (ResourceT IO) a -> IO a +runLineByLineGeneralized spec consum = do (inputFilePath, expectedFilePath, outFilePath) <- checkAndGetFiles spec - let sourceA = gevalLineByLineSource metric inputFilePath expectedFilePath outFilePath - let sourceB = gevalLineByLineSource metric inputFilePath expectedFilePath otherOutFilePath - runResourceT $ runConduit $ - ((getZipSource $ (,) - <$> ZipSource sourceA - <*> ZipSource sourceB) .| consum) + gevalLineByLineCore metric inputFilePath expectedFilePath outFilePath consum where metric = gesMetric spec - consum :: ConduitT (LineRecord, LineRecord) Void (ResourceT IO) () + +runDiff :: FilePath -> GEvalSpecification -> IO () +runDiff otherOut spec = runDiffGeneralized otherOut spec consum + where consum :: ConduitT (LineRecord, LineRecord) Void (ResourceT IO) () consum = (CL.filter shouldBeShown .| CL.map (encodeUtf8 . formatOutput) .| CC.unlinesAscii .| CC.stdout) shouldBeShown (LineRecord _ _ outA _ scoreA, LineRecord _ _ outB _ scoreB) = outA /= outB && scoreA /= scoreB @@ -69,10 +65,22 @@ runDiff otherOut spec = do formatScoreDiff :: Double -> Text formatScoreDiff = Data.Text.pack . printf "%f" +runDiffGeneralized :: FilePath -> GEvalSpecification -> ConduitT (LineRecord, LineRecord) Void (ResourceT IO) a -> IO a +runDiffGeneralized otherOut spec consum = do + let otherOutFilePath = getOutFile spec otherOut + (inputFilePath, expectedFilePath, outFilePath) <- checkAndGetFiles spec + let sourceA = gevalLineByLineSource metric inputFilePath expectedFilePath outFilePath + let sourceB = gevalLineByLineSource metric inputFilePath expectedFilePath otherOutFilePath + runResourceT $ runConduit $ + ((getZipSource $ (,) + <$> ZipSource sourceA + <*> ZipSource sourceB) .| consum) + where metric = gesMetric spec + escapeTabs :: Text -> Text escapeTabs = Data.Text.replace "\t" "" -gevalLineByLineCore :: Metric -> FilePath -> FilePath -> FilePath -> ConduitT LineRecord Void (ResourceT IO) () -> IO () +gevalLineByLineCore :: Metric -> FilePath -> FilePath -> FilePath -> ConduitT LineRecord Void (ResourceT IO) a -> IO a gevalLineByLineCore metric inputFilePath expectedFilePath outFilePath consum = runResourceT $ runConduit $ ((gevalLineByLineSource metric inputFilePath expectedFilePath outFilePath) .| consum)