]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Flow.hs
Use desc instead of descr and use defaultCorpus
[gargantext.git] / src / Gargantext / Database / Flow.hs
1 {-|
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
8 Portability : POSIX
9
10
11
12 add :: Corpus -> [Documents] -> IO Int
13 if new id -> extractNgrams + extract Authors + extract Sources
14 Map (Ngrams, NodeId)
15 insert Ngrams -> NgramsId
16 Map (NgramsId, NodeId) -> insert
17
18 data NgramsType = Sources | Authors | Terms
19
20 nodes_ngrams : column type, column list
21
22
23 documents
24 sources
25 authors
26
27 -}
28
29 {-# LANGUAGE NoImplicitPrelude #-}
30 {-# LANGUAGE OverloadedStrings #-}
31
32 module Gargantext.Database.Flow
33 (flow)
34 where
35 import System.FilePath (FilePath)
36 import Data.Maybe (Maybe(..))
37 import Gargantext.Core.Types (NodePoly(..))
38 import Gargantext.Prelude
39 import Gargantext.Database.Bashql (runCmd', del)
40 import Gargantext.Database.Node (getRoot, mkRoot, mkCorpus)
41 import Gargantext.Database.User (getUser, UserLight(..))
42 import Gargantext.Database.Node.Document.Import (insertDocuments)
43 import Gargantext.Text.Parsers (parseDocs, FileFormat(WOS))
44
45 flow :: FilePath -> IO ()
46 flow fp = do
47 masterUser <- runCmd' (getUser "gargantua")
48
49 let masterUserId = case masterUser of
50 Nothing -> panic "Error: User does not exist (yet)" -- mk NodeUser gargantua_id "Node Gargantua"
51 Just user -> userLight_id user
52
53 rootId' <- map _node_id <$> runCmd' (getRoot masterUserId)
54
55 rootId'' <- case rootId' of
56 [] -> runCmd' (mkRoot masterUserId)
57 un -> case length un >= 2 of
58 True -> panic "Error: more than 1 userNode / user"
59 False -> pure rootId'
60 let rootId = maybe (panic "error rootId") identity (head rootId'')
61 printDebug "Root ID : " rootId
62
63 corpusId' <- runCmd' $ mkCorpus (Just "Corpus WOS") Nothing rootId masterUserId
64 let corpusId = maybe (panic "error corpusId") identity (head corpusId')
65 printDebug "Corpus ID : " corpusId
66
67 docs <- parseDocs WOS fp
68 ids <- runCmd' $ insertDocuments masterUserId corpusId docs
69 printDebug "Docs IDs : " ids
70
71 idsRepeat <- runCmd' $ insertDocuments masterUserId corpusId docs
72 printDebug "Docs IDs : " idsRepeat
73
74 _ <- runCmd' (del [corpusId])
75 pure ()
76
77 {-
78 --folderId <- mk Folder parentId (Name "Data") (Descr "All corpora DATA here")
79 folderId <- mk Folder rootId "Data"
80 corpusId <- mk Corpus folderId (Name "WOS") (Descr "WOS database description")
81 -}
82
83
84
85 {-
86 docs <- parseDocuments WOS "doc/.."
87 ids <- add (Documents corpusId) docs
88
89 user_id <- runCmd' (get RootUser "alexandre")
90 rootUser_id <- runCmd' (getRootUser $ userLight_id user_id
91 corpusId <- mk Corpus
92 -}
93
94