ClippEU passes tests
This commit is contained in:
parent
fcc52d6c3a
commit
67f73f420e
@ -54,7 +54,7 @@ clippingSpecParser = do
|
|||||||
rectangle <- rectangleParser
|
rectangle <- rectangleParser
|
||||||
char '/'
|
char '/'
|
||||||
margin <- decimal
|
margin <- decimal
|
||||||
return $ ClippingSpec pageNo rectangle (extendedRectangle margin rectangle)
|
return $ ClippingSpec pageNo (smallerRectangle margin rectangle) (extendedRectangle margin rectangle)
|
||||||
|
|
||||||
possibleWhitespace = many' (satisfy isHorizontalSpace)
|
possibleWhitespace = many' (satisfy isHorizontalSpace)
|
||||||
|
|
||||||
@ -65,6 +65,13 @@ extendedRectangle margin (Rectangle (Point x0 y0) (Point x1 y1)) =
|
|||||||
Rectangle (Point (x0 `nonNegativeDiff` margin) (y0 `nonNegativeDiff` margin))
|
Rectangle (Point (x0 `nonNegativeDiff` margin) (y0 `nonNegativeDiff` margin))
|
||||||
(Point (x1 + margin) (y1 + margin))
|
(Point (x1 + margin) (y1 + margin))
|
||||||
|
|
||||||
|
smallerRectangle :: Int -> Rectangle -> Rectangle
|
||||||
|
smallerRectangle margin (Rectangle (Point x0 y0) (Point x1 y1)) =
|
||||||
|
Rectangle (Point (x0 + margin) (y0 + margin))
|
||||||
|
(Point (x1 `nonNegativeDiff` margin) (y1 `nonNegativeDiff` margin))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
nonNegativeDiff x y
|
nonNegativeDiff x y
|
||||||
| x < y = 0
|
| x < y = 0
|
||||||
| otherwise = x - y
|
| otherwise = x - y
|
||||||
|
@ -35,12 +35,16 @@ import System.FilePath
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import qualified Data.List.Split as DLS
|
import qualified Data.List.Split as DLS
|
||||||
|
|
||||||
|
import Data.Attoparsec.Text (parseOnly)
|
||||||
|
|
||||||
import GEval.BLEU
|
import GEval.BLEU
|
||||||
import GEval.Common
|
import GEval.Common
|
||||||
|
import GEval.ClippEU
|
||||||
|
import GEval.PrecisionRecall
|
||||||
|
|
||||||
type MetricValue = Double
|
type MetricValue = Double
|
||||||
|
|
||||||
data Metric = RMSE | MSE | BLEU | Accuracy
|
data Metric = RMSE | MSE | BLEU | Accuracy | ClippEU
|
||||||
deriving (Show, Read, Eq)
|
deriving (Show, Read, Eq)
|
||||||
|
|
||||||
data MetricOrdering = TheLowerTheBetter | TheHigherTheBetter
|
data MetricOrdering = TheLowerTheBetter | TheHigherTheBetter
|
||||||
@ -50,6 +54,7 @@ getMetricOrdering RMSE = TheLowerTheBetter
|
|||||||
getMetricOrdering MSE = TheLowerTheBetter
|
getMetricOrdering MSE = TheLowerTheBetter
|
||||||
getMetricOrdering BLEU = TheHigherTheBetter
|
getMetricOrdering BLEU = TheHigherTheBetter
|
||||||
getMetricOrdering Accuracy = TheHigherTheBetter
|
getMetricOrdering Accuracy = TheHigherTheBetter
|
||||||
|
getMetricOrdering ClippEU = TheHigherTheBetter
|
||||||
|
|
||||||
defaultOutDirectory = "."
|
defaultOutDirectory = "."
|
||||||
defaultTestName = "test-A"
|
defaultTestName = "test-A"
|
||||||
@ -168,6 +173,17 @@ gevalCore' BLEU = gevalCore'' (Prelude.map Prelude.words . DLS.splitOn "\t" . un
|
|||||||
gevalCore' Accuracy = gevalCore'' strip strip hitOrMiss averageC id
|
gevalCore' Accuracy = gevalCore'' strip strip hitOrMiss averageC id
|
||||||
where hitOrMiss (x,y) = if x == y then 1.0 else 0.0
|
where hitOrMiss (x,y) = if x == y then 1.0 else 0.0
|
||||||
|
|
||||||
|
gevalCore' ClippEU = gevalCore'' parseClippingSpecs parseClippings matchStep clippeuAgg finalStep
|
||||||
|
where
|
||||||
|
parseClippings = controlledParse lineClippingsParser
|
||||||
|
parseClippingSpecs = controlledParse lineClippingSpecsParser
|
||||||
|
matchStep (clippingSpecs, clippings) = (maxMatch matchClippingToSpec clippingSpecs clippings,
|
||||||
|
Prelude.length clippingSpecs,
|
||||||
|
Prelude.length clippings)
|
||||||
|
clippeuAgg = CC.foldl clippeuFuse (0, 0, 0)
|
||||||
|
clippeuFuse (a1, a2, a3) (b1, b2, b3) = (a1+b1, a2+b2, a3+b3)
|
||||||
|
finalStep counts = f2MeasureOnCounts counts
|
||||||
|
|
||||||
data SourceItem a = Got a | Done
|
data SourceItem a = Got a | Done
|
||||||
|
|
||||||
gevalCore'' :: (Text -> a) -> (Text -> b) -> ((a, b) -> c) -> (Sink c (ResourceT IO) d) -> (d -> Double) -> String -> String -> IO (MetricValue)
|
gevalCore'' :: (Text -> a) -> (Text -> b) -> ((a, b) -> c) -> (Sink c (ResourceT IO) d) -> (d -> Double) -> String -> String -> IO (MetricValue)
|
||||||
@ -210,3 +226,8 @@ getValue (Right (x, reminder)) =
|
|||||||
then x
|
then x
|
||||||
else throw $ UnexpectedData "number expected"
|
else throw $ UnexpectedData "number expected"
|
||||||
getValue (Left s) = throw $ UnexpectedData s
|
getValue (Left s) = throw $ UnexpectedData s
|
||||||
|
|
||||||
|
controlledParse parser t =
|
||||||
|
case parseOnly parser t of
|
||||||
|
(Right v) -> v
|
||||||
|
(Left _) -> throw $ UnexpectedData "cannot parse line"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
module GEval.PrecisionRecall(fMeasure, f1Measure, f2Measure, precision, recall,
|
module GEval.PrecisionRecall(fMeasure, f1Measure, f2Measure, precision, recall,
|
||||||
fMeasureOnCounts, f1MeasureOnCounts, f2MeasureOnCounts,
|
fMeasureOnCounts, f1MeasureOnCounts, f2MeasureOnCounts,
|
||||||
precisionAndRecall, precisionAndRecallFromCounts)
|
precisionAndRecall, precisionAndRecallFromCounts, maxMatch)
|
||||||
where
|
where
|
||||||
|
|
||||||
import GEval.Common
|
import GEval.Common
|
||||||
|
@ -84,11 +84,12 @@ main = hspec $ do
|
|||||||
r `shouldBe` []
|
r `shouldBe` []
|
||||||
it "parsing specs" $ do
|
it "parsing specs" $ do
|
||||||
let (Right r) = parseOnly lineClippingSpecsParser " 2/0,0,2,3/5 10/20,30,40,50/10"
|
let (Right r) = parseOnly lineClippingSpecsParser " 2/0,0,2,3/5 10/20,30,40,50/10"
|
||||||
r `shouldBe` [ClippingSpec (PageNumber 2) (Rectangle (Point 0 0) (Point 2 3))
|
r `shouldBe` [ClippingSpec (PageNumber 2) (Rectangle (Point 5 5) (Point 0 0))
|
||||||
(Rectangle (Point 0 0) (Point 7 8)),
|
(Rectangle (Point 0 0) (Point 7 8)),
|
||||||
ClippingSpec (PageNumber 10) (Rectangle (Point 20 30) (Point 40 50))
|
ClippingSpec (PageNumber 10) (Rectangle (Point 30 40) (Point 30 40))
|
||||||
(Rectangle (Point 10 20) (Point 50 60))]
|
(Rectangle (Point 10 20) (Point 50 60))]
|
||||||
|
it "full test" $ do
|
||||||
|
runGEvalTest "clippeu-simple" `shouldReturnAlmost` 0.399999999999
|
||||||
|
|
||||||
neverMatch :: Char -> Int -> Bool
|
neverMatch :: Char -> Int -> Bool
|
||||||
neverMatch _ _ = False
|
neverMatch _ _ = False
|
||||||
|
Loading…
Reference in New Issue
Block a user