buck rules for regenerating classifiers + support dir prefix

Summary: as title

Reviewed By: kamaljoshi

Differential Revision: D61641528

fbshipit-source-id: 8628dae4d62688bae38b038c00754ec0325f0e3b
This commit is contained in:
Julien Odent 2024-08-22 12:19:56 -07:00 committed by Facebook GitHub Bot
parent 99b8c69b08
commit 6f9bff5a5f

View File

@ -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