diff --git a/exe/Duckling/Ranking/Generate.hs b/exe/Duckling/Ranking/Generate.hs index 16e0d46f..d7b61fa4 100644 --- a/exe/Duckling/Ranking/Generate.hs +++ b/exe/Duckling/Ranking/Generate.hs @@ -17,6 +17,7 @@ module Duckling.Ranking.Generate import Data.HashSet (HashSet) import Language.Haskell.Exts as F import Prelude +import System.Environment (getArgs) import qualified Data.HashMap.Strict as HashMap import qualified Data.HashSet as HashSet import qualified Data.Text as Text @@ -87,9 +88,19 @@ regenLangClassifiers lang = do mapM_ (regenClassifiers . makeLocale lang . Just) $ HashMap.lookupDefault HashSet.empty lang allLocales +getPath :: String -> IO (String) +getPath moduleName = do + args <- getArgs + let + prefix = case args of + [] -> "" + (x:_) -> (x :: String) + return $ prefix ++ "Duckling/Ranking/Classifiers/" ++ moduleName ++ ".hs" + -- | Run this function to overwrite the file with Classifiers data regenClassifiers :: Locale -> IO () regenClassifiers locale = do + filepath <- getPath moduleName putStrLn $ "Regenerating " ++ filepath ++ "..." writeFile filepath $ (headerComment ++) $ @@ -98,8 +109,6 @@ regenClassifiers locale = do where moduleName = show locale - filepath = "Duckling/Ranking/Classifiers/" ++ moduleName ++ ".hs" - rules = rulesFor locale . HashSet.singleton $ Seal Time -- | The trained classifier to write out