Filtering works on multiple values

This commit is contained in:
Filip Gralinski 2020-05-20 10:50:01 +02:00
parent 0ed06729ba
commit a00120b1c2
6 changed files with 37 additions and 8 deletions

View File

@ -22,7 +22,9 @@ import Data.Conduit.SmartSource
import Data.Conduit.Header
import GEval.Selector
data Filter = NoFilter | FilterByFeatures (Maybe TabularHeader) String
import qualified Data.Set as S
data Filter = NoFilter | FilterByFeatures (Maybe TabularHeader) (S.Set String)
noFilter :: Filter
noFilter = NoFilter
@ -33,19 +35,19 @@ applyFilter (FilterByFeatures mInHeader featureSpec) tR = applyFeatureFilter mIn
getFilterForScheme :: Maybe TabularHeader -> EvaluationScheme -> Filter
getFilterForScheme mTabHeader (EvaluationScheme _ ops) = case findFilter ops of
Nothing -> NoFilter
Just f -> FilterByFeatures mTabHeader (unpack $ fixIndex f)
[] -> NoFilter
fs -> FilterByFeatures mTabHeader (S.fromList $ Prelude.map (unpack . fixIndex) fs)
fixIndex = replace "[" "<" . replace "]" ">"
findFilter :: [PreprocessingOperation] -> Maybe Text
findFilter [] = Nothing
findFilter ((FeatureFilter f):_) = Just f
findFilter :: [PreprocessingOperation] -> [Text]
findFilter [] = []
findFilter ((FeatureFilter f):ops) = (f:(findFilter ops))
findFilter (_:ops) = findFilter ops
applyFeatureFilter :: Maybe TabularHeader -> String -> TargetRecord -> Bool
applyFeatureFilter mInHeader featureSpec tR = featureSpec `elem` (Prelude.map show fs)
applyFeatureFilter :: Maybe TabularHeader -> S.Set String -> TargetRecord -> Bool
applyFeatureFilter mInHeader featureSpec tR = featureSpec `S.isSubsetOf` (S.fromList $ Prelude.map show fs)
where fs = getFeatures Nothing
BlackBoxDebuggingOptions {
bbdoMinFrequency = 0,

View File

@ -137,6 +137,8 @@ main = hspec $ do
runGEvalTest "accuracy-on-sorted" `shouldReturnAlmost` 0.75
it "with filtering" $
runGEvalTest "accuracy-filtering" `shouldReturnAlmost` 0.6666
it "with filtering 2" $
runGEvalTest "accuracy-multiple-filtering" `shouldReturnAlmost` 0.5
describe "F-measure" $ do
it "simple example" $
runGEvalTest "f-measure-simple" `shouldReturnAlmost` 0.57142857

View File

@ -0,0 +1,8 @@
foo
bar
bar
foo
foo
foo
foo
bar
1 foo
2 bar
3 bar
4 foo
5 foo
6 foo
7 foo
8 bar

View File

@ -0,0 +1 @@
--metric Accuracy:f<in[1]:en>N<xyz>f<in[1]:general>

View File

@ -0,0 +1,8 @@
foo
bar
foo
foo
foo
foo
foo
bar
1 foo
2 bar
3 foo
4 foo
5 foo
6 foo
7 foo
8 bar

View File

@ -0,0 +1,8 @@
general
de specific
general en
general
general
en specific
en general
1 general
2 de specific
3 general en
4 general
5 general
6 en specific
7 en general