2 Module : Gargantext.Database.Flow
3 Description : Database Flow
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
11 Map (NgramsId, NodeId) -> insert
12 data NgramsType = Sources | Authors | Terms
13 nodes_ngrams : column type, column list
21 {-# LANGUAGE NoImplicitPrelude #-}
22 {-# LANGUAGE OverloadedStrings #-}
24 module Gargantext.Database.Flow
26 import System.FilePath (FilePath)
27 import GHC.Base ((>>))
28 import Data.Maybe (Maybe(..))
29 import Gargantext.Core.Types (NodePoly(..))
30 import Gargantext.Prelude
31 import Gargantext.Database.Bashql (runCmd', del)
32 import Gargantext.Database.Node (Cmd(..), getRoot, mkRoot, mkCorpus, defaultCorpus)
33 import Gargantext.Database.User (getUser, UserLight(..), Username)
34 import Gargantext.Database.Node.Document.Insert (insertDocuments, ReturnId(reId))
35 import Gargantext.Database.Node.Document.Add (add)
36 import Gargantext.Text.Parsers (parseDocs, FileFormat(WOS))
42 subFlow :: Username -> IO (UserId, RootId, CorpusId)
44 maybeUserId <- runCmd' (getUser username)
46 let userId = case maybeUserId of
47 Nothing -> panic "Error: User does not exist (yet)" -- mk NodeUser gargantua_id "Node Gargantua"
48 Just user -> userLight_id user
50 rootId' <- map _node_id <$> runCmd' (getRoot userId)
52 rootId'' <- case rootId' of
53 [] -> runCmd' (mkRoot userId)
54 un -> case length un >= 2 of
55 True -> panic "Error: more than 1 userNode / user"
57 let rootId = maybe (panic "error rootId") identity (head rootId'')
59 corpusId' <- runCmd' $ mkCorpus (Just "Corpus WOS") Nothing rootId userId
60 let corpusId = maybe (panic "error corpusId") identity (head corpusId')
62 printDebug "(username, userId, rootId, corpusId"
63 (username, userId, rootId, corpusId)
64 pure (userId, rootId, corpusId)
67 -- flow :: FilePath -> IO ()
70 (masterUserId, _, corpusId) <- subFlow "gargantua"
72 docs <- parseDocs WOS fp
73 ids <- runCmd' $ insertDocuments masterUserId corpusId docs
74 printDebug "Docs IDs : " ids
76 idsRepeat <- runCmd' $ insertDocuments masterUserId corpusId docs
77 printDebug "Docs IDs : " idsRepeat
79 (userId, rootId, corpusId2) <- subFlow "alexandre"
81 inserted <- runCmd' $ add corpusId2 (map reId ids)
82 printDebug "Inserted : " inserted
84 -- runCmd' (del [corpusId2, corpusId])
87 ids <- add (Documents corpusId) docs
89 user_id <- runCmd' (get RootUser "alexandre")
90 rootUser_id <- runCmd' (getRootUser $ userLight_id user_id