Handle escaping spaces in configuration files
This commit is contained in:
parent
819fbecedc
commit
40d5ac602e
@ -40,6 +40,9 @@ import GEval.Model
|
|||||||
import GEval.ModelTraining
|
import GEval.ModelTraining
|
||||||
|
|
||||||
import Data.List (find, intercalate)
|
import Data.List (find, intercalate)
|
||||||
|
import Data.List.Utils (split)
|
||||||
|
|
||||||
|
import Data.Char (isSpace)
|
||||||
|
|
||||||
import Data.Conduit.SmartSource
|
import Data.Conduit.SmartSource
|
||||||
import Data.CartesianStrings
|
import Data.CartesianStrings
|
||||||
@ -352,7 +355,26 @@ readOptsFromConfigFile :: [String] -> FilePath -> IO (Either (ParserResult GEval
|
|||||||
readOptsFromConfigFile args configFilePath = do
|
readOptsFromConfigFile args configFilePath = do
|
||||||
configH <- openFile configFilePath ReadMode
|
configH <- openFile configFilePath ReadMode
|
||||||
contents <- hGetContents configH
|
contents <- hGetContents configH
|
||||||
getOptions' False ((words contents) ++ args)
|
getOptions' False ((parseConfigFileContents contents) ++ args)
|
||||||
|
|
||||||
|
data ConfigFileSymbol = Literal Char | Separator
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
-- very simplistic handling of backslash escaping
|
||||||
|
-- even "\\" is treated as double backslashes...
|
||||||
|
parseConfigFileContents :: String -> [String]
|
||||||
|
parseConfigFileContents contents =
|
||||||
|
filter (not . null)
|
||||||
|
$ map (map (\(Literal c) -> c))
|
||||||
|
$ split [Separator]
|
||||||
|
$ parseSymbols contents
|
||||||
|
where parseSymbols ('\\':c:t)
|
||||||
|
| isSpace c = (Literal c) : parseSymbols t
|
||||||
|
| otherwise = (Literal '\\'): (Literal c) :parseSymbols t
|
||||||
|
parseSymbols (c:t)
|
||||||
|
| isSpace c = Separator : parseSymbols t
|
||||||
|
| otherwise = (Literal c) : parseSymbols t
|
||||||
|
parseSymbols [] = []
|
||||||
|
|
||||||
attemptToReadOptsFromConfigFile :: [String] -> GEvalOptions -> IO (Either (ParserResult GEvalOptions) GEvalOptions)
|
attemptToReadOptsFromConfigFile :: [String] -> GEvalOptions -> IO (Either (ParserResult GEvalOptions) GEvalOptions)
|
||||||
attemptToReadOptsFromConfigFile args opts = do
|
attemptToReadOptsFromConfigFile args opts = do
|
||||||
|
@ -131,9 +131,10 @@ main = hspec $ do
|
|||||||
describe "CER" $ do
|
describe "CER" $ do
|
||||||
it "simple example" $
|
it "simple example" $
|
||||||
runGEvalTest "cer-simple" `shouldReturnAlmost` 0.28947368421
|
runGEvalTest "cer-simple" `shouldReturnAlmost` 0.28947368421
|
||||||
describe "CER" $ do
|
|
||||||
it "simple example (Mean/CER)" $
|
it "simple example (Mean/CER)" $
|
||||||
runGEvalTest "cer-mean-simple" `shouldReturnAlmost` 0.277777777777778
|
runGEvalTest "cer-mean-simple" `shouldReturnAlmost` 0.277777777777778
|
||||||
|
it "space escaping" $
|
||||||
|
runGEvalTest "cer-space-escaping" `shouldReturnAlmost` 0.0555555
|
||||||
describe "Accuracy" $ do
|
describe "Accuracy" $ do
|
||||||
it "simple example" $
|
it "simple example" $
|
||||||
runGEvalTest "accuracy-simple" `shouldReturnAlmost` 0.6
|
runGEvalTest "accuracy-simple" `shouldReturnAlmost` 0.6
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
foo bar
|
||||||
|
aaa bxb ccc
|
|
1
test/cer-space-escaping/cer-space-escaping/config.txt
Normal file
1
test/cer-space-escaping/cer-space-escaping/config.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
--metric CER:s<\ +><\ >
|
@ -0,0 +1,2 @@
|
|||||||
|
foo bar
|
||||||
|
aaa bbb ccc
|
|
Loading…
Reference in New Issue
Block a user