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 Data.Maybe (Maybe(..))
28 import Gargantext.Core.Types (NodePoly(..))
29 import Gargantext.Prelude
30 import Gargantext.Database.Bashql (runCmd', del)
31 import Gargantext.Database.Node (getRoot, mkRoot, mkCorpus)
32 import Gargantext.Database.User (getUser, UserLight(..), Username)
33 import Gargantext.Database.Node.Document.Insert (insertDocuments, ReturnId(reId))
34 import Gargantext.Database.Node.Document.Add (add)
35 import Gargantext.Text.Parsers (parseDocs, FileFormat(WOS))
41 subFlow :: Username -> IO (UserId, RootId, CorpusId)
43 maybeUserId <- runCmd' (getUser username)
45 let userId = case maybeUserId of
46 Nothing -> panic "Error: User does not exist (yet)" -- mk NodeUser gargantua_id "Node Gargantua"
47 Just user -> userLight_id user
49 rootId' <- map _node_id <$> runCmd' (getRoot userId)
51 rootId'' <- case rootId' of
52 [] -> runCmd' (mkRoot userId)
53 un -> case length un >= 2 of
54 True -> panic "Error: more than 1 userNode / user"
56 let rootId = maybe (panic "error rootId") identity (head rootId'')
58 corpusId' <- runCmd' $ mkCorpus (Just "Corpus WOS") Nothing rootId userId
59 let corpusId = maybe (panic "error corpusId") identity (head corpusId')
61 printDebug "(username, userId, rootId, corpusId"
62 (username, userId, rootId, corpusId)
63 pure (userId, rootId, corpusId)
66 flow :: FilePath -> IO Int
69 (masterUserId, _, corpusId) <- subFlow "gargantua"
71 docs <- parseDocs WOS fp
72 ids <- runCmd' $ insertDocuments masterUserId corpusId docs
73 printDebug "Docs IDs : " ids
75 idsRepeat <- runCmd' $ insertDocuments masterUserId corpusId docs
76 printDebug "Docs IDs : " idsRepeat
78 (_, _, corpusId2) <- subFlow "alexandre"
80 inserted <- runCmd' $ add corpusId2 (map reId ids)
81 printDebug "Inserted : " inserted
83 runCmd' (del [corpusId2, corpusId])