3 Description : Gargantext Import Corpus
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Import a corpus binary.
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
16 {-# LANGUAGE FlexibleContexts #-}
17 {-# LANGUAGE RankNTypes #-}
18 {-# LANGUAGE Strict #-}
24 import Control.Exception (finally)
25 import Gargantext.Prelude
26 import Gargantext.Database.Flow (FlowCmdM, flowCorpusFile)
27 import Gargantext.Text.Corpus.Parsers (FileFormat(..))
28 import Gargantext.Database.Utils (Cmd, )
29 import Gargantext.Database.Types.Node (CorpusId, toHyperdataDocument)
30 import Gargantext.Database.Schema.User (insertUsersDemo)
31 import Gargantext.Text.Terms (TermType(..))
32 import Gargantext.Core (Lang(..))
33 import Gargantext.API.Types (GargError)
34 import Gargantext.API.Node () -- instances
35 import Gargantext.API.Settings (withDevEnv, runCmdDev, DevEnv)
36 import System.Environment (getArgs)
37 --import Gargantext.Text.Corpus.Parsers.GrandDebat (readFile, GrandDebatReference(..))
38 import Data.Text (Text)
39 import qualified Data.Text as Text
40 import Control.Monad.IO.Class (liftIO)
44 [userCreate, user, name, iniPath, limit, corpusPath] <- getArgs
47 let createUsers :: Cmd GargError Int64
48 createUsers = insertUsersDemo
51 --tt = (Unsupervised EN 6 0 Nothing)
53 format = CsvGargV3 -- CsvHalFormat --WOS
54 cmd :: forall m. FlowCmdM DevEnv GargError m => m CorpusId
55 cmd = flowCorpusFile (cs user) (Left (cs name :: Text)) (read limit :: Int) tt format corpusPath
57 let debatCorpus :: forall m. FlowCmdM DevEnv GargError m => m CorpusId
59 docs <- liftIO ( splitEvery 500
60 <$> take (read limit :: Int)
61 <$> readFile corpusPath
62 :: IO [[GrandDebatReference ]]
64 flowCorpus (Text.pack user) (Text.pack name) (Multi FR) (map (map toHyperdataDocument) docs)
68 withDevEnv iniPath $ \env -> do
69 _ <- if userCreate == "true"
70 then runCmdDev env createUsers
71 else pure 0 --(cs "false")
73 _ <- runCmdDev env cmd
75 _ <- if corpusType == "csv"
76 then runCmdDev env csvCorpus
77 else if corpusType == "debat"
78 then runCmdDev env debatCorpus
79 else panic "corpusType unknown: try \"csv\" or \"debat\""