-- TODO-EVENTS: InsertedNodes
-}
-{-# OPTIONS_GHC -fno-warn-orphans #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ConstrainedClassMethods #-}
, flowCorpusFile
, flowCorpus
, flowAnnuaire
+ , insertMasterDocs
, getOrMkRoot
, getOrMk_RootWithCorpus
import System.FilePath (FilePath)
import Gargantext.Core (Lang(..))
+import Gargantext.Core.Ext.IMT (toSchoolName)
+import Gargantext.Core.Ext.IMTUser (deserialiseImtUsersFromFile)
import Gargantext.Core.Flow.Types
+import Gargantext.Core.Text
+import Gargantext.Core.Text.List.Group.WithStem (StopSize(..), GroupParams(..))
+import Gargantext.Core.Text.Corpus.Parsers (parseFile, FileFormat)
+import Gargantext.Core.Text.List (buildNgramsLists)
+import Gargantext.Core.Text.Terms
+import Gargantext.Core.Text.Terms.Mono.Stem.En (stemIt)
import Gargantext.Core.Types (Terms(..))
import Gargantext.Core.Types.Individu (User(..))
import Gargantext.Core.Types.Main
+import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger)
import Gargantext.Database.Action.Flow.List
import Gargantext.Database.Action.Flow.Types
import Gargantext.Database.Action.Flow.Utils (insertDocNgrams)
-import Gargantext.Database.Query.Table.Node
-import Gargantext.Database.Query.Table.Node.Document.Insert -- (insertDocuments, ReturnId(..), addUniqIdsDoc, addUniqIdsContact, ToDbData(..))
-import Gargantext.Database.Query.Tree.Root (getOrMkRoot, getOrMk_RootWithCorpus)
import Gargantext.Database.Action.Search (searchDocInDatabase)
import Gargantext.Database.Admin.Config (userMaster, corpusMasterName)
-import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..))
import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Admin.Types.Node -- (HyperdataDocument(..), NodeType(..), NodeId, UserId, ListId, CorpusId, RootId, MasterCorpusId, MasterUserId)
import Gargantext.Database.Prelude
import Gargantext.Database.Query.Table.Ngrams
+import Gargantext.Database.Query.Table.Node
+import Gargantext.Database.Query.Table.Node.Document.Insert -- (insertDocuments, ReturnId(..), addUniqIdsDoc, addUniqIdsContact, ToDbData(..))
+import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..))
import Gargantext.Database.Query.Table.NodeNgrams (listInsertDb , getCgramsId)
import Gargantext.Database.Query.Table.NodeNodeNgrams2
+import Gargantext.Database.Query.Tree.Root (getOrMkRoot, getOrMk_RootWithCorpus)
import Gargantext.Database.Schema.Node (NodePoly(..))
-import Gargantext.Core.Ext.IMT (toSchoolName)
-import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger)
-import Gargantext.Core.Ext.IMTUser (deserialiseImtUsersFromFile)
-import Gargantext.Core.Text
import Gargantext.Prelude
import Gargantext.Prelude.Crypto.Hash (Hash)
-import Gargantext.Core.Text.Corpus.Parsers (parseFile, FileFormat)
-import Gargantext.Core.Text.List (buildNgramsLists,StopSize(..))
-import Gargantext.Core.Text.Terms.Mono.Stem.En (stemIt)
-import Gargantext.Core.Text.Terms
-import qualified Gargantext.Database.Query.Table.Node.Document.Add as Doc (add)
import qualified Gargantext.Core.Text.Corpus.API as API
+import qualified Gargantext.Database.Query.Table.Node.Document.Add as Doc (add)
------------------------------------------------------------------------
-- TODO use internal with API name (could be old data)
getDataText (ExternalOrigin api) la q li = liftBase $ DataNew
<$> splitEvery 500
<$> API.get api (_tt_lang la) q li
+
getDataText (InternalOrigin _) _la q _li = do
(_masterUserId, _masterRootId, cId) <- getOrMk_RootWithCorpus
(UserName userMaster)
pure $ DataOld ids
-------------------------------------------------------------------------------
-flowDataText :: FlowCmdM env err m
- => User
- -> DataText
- -> TermType Lang
- -> CorpusId
- -> m CorpusId
+flowDataText :: ( FlowCmdM env err m
+ )
+ => User
+ -> DataText
+ -> TermType Lang
+ -> CorpusId
+ -> m CorpusId
flowDataText u (DataOld ids) tt cid = flowCorpusUser (_tt_lang tt) u (Right [cid]) corpusType ids
where
corpusType = (Nothing :: Maybe HyperdataCorpus)
------------------------------------------------------------------------
-- TODO use proxy
-flowAnnuaire :: FlowCmdM env err m
+flowAnnuaire :: (FlowCmdM env err m)
=> User
-> Either CorpusName [CorpusId]
-> (TermType Lang)
flow (Nothing :: Maybe HyperdataAnnuaire) u n l docs
------------------------------------------------------------------------
-flowCorpusFile :: FlowCmdM env err m
+flowCorpusFile :: (FlowCmdM env err m)
=> User
-> Either CorpusName [CorpusId]
-> Limit -- Limit the number of docs (for dev purpose)
flowCorpus = flow (Nothing :: Maybe HyperdataCorpus)
-flow :: (FlowCmdM env err m, FlowCorpus a, MkCorpus c)
- => Maybe c
- -> User
- -> Either CorpusName [CorpusId]
- -> TermType Lang
- -> [[a]]
- -> m CorpusId
+flow :: ( FlowCmdM env err m
+ , FlowCorpus a
+ , MkCorpus c
+ )
+ => Maybe c
+ -> User
+ -> Either CorpusName [CorpusId]
+ -> TermType Lang
+ -> [[a]]
+ -> m CorpusId
flow c u cn la docs = do
-- TODO if public insertMasterDocs else insertUserDocs
ids <- traverse (insertMasterDocs c la) docs
flowCorpusUser (la ^. tt_lang) u cn c (concat ids)
------------------------------------------------------------------------
-flowCorpusUser :: (FlowCmdM env err m, MkCorpus c)
+flowCorpusUser :: ( FlowCmdM env err m
+ , MkCorpus c
+ )
=> Lang
-> User
-> Either CorpusName [CorpusId]
flowCorpusUser l user corpusName ctype ids = do
-- User Flow
(userId, _rootId, userCorpusId) <- getOrMk_RootWithCorpus user corpusName ctype
+ -- NodeTexts is first
+ _tId <- insertDefaultNode NodeTexts userCorpusId userId
+ -- printDebug "NodeTexts: " tId
+
+ -- NodeList is second
listId <- getOrMkList userCorpusId userId
-- _cooc <- insertDefaultNode NodeListCooc listId userId
-- TODO: check if present already, ignore
_ <- Doc.add userCorpusId ids
- _tId <- insertDefaultNode NodeTexts userCorpusId userId
-- printDebug "Node Text Ids:" tId
-- User List Flow
(masterUserId, _masterRootId, masterCorpusId) <- getOrMk_RootWithCorpus (UserName userMaster) (Left "") ctype
- ngs <- buildNgramsLists l 2 3 (StopSize 3) userCorpusId masterCorpusId
+ ngs <- buildNgramsLists user (GroupParams l 2 3 (StopSize 3)) userCorpusId masterCorpusId
_userListId <- flowList_DbRepo listId ngs
_mastListId <- getOrMkList masterCorpusId masterUserId
-- _ <- insertOccsUpdates userCorpusId mastListId
-- _ <- mkAnnuaire rootUserId userId
pure userCorpusId
--- TODO Type NodeDocumentUnicised
-insertDocs :: ( FlowCmdM env err m
- -- , FlowCorpus a
- , FlowInsertDB a
- )
- => UserId
- -> CorpusId
- -> [a]
- -> m ([DocId], [DocumentWithId a])
-insertDocs uId cId hs = do
- let docs = map addUniqId hs
- newIds <- insertDb uId cId docs
- -- printDebug "newIds" newIds
- let
- newIds' = map reId newIds
- documentsWithId = mergeData (toInserted newIds) (Map.fromList $ map viewUniqId' docs)
- _ <- Doc.add cId newIds'
- pure (newIds', documentsWithId)
-
insertMasterDocs :: ( FlowCmdM env err m
, FlowCorpus a
pure ids'
------------------------------------------------------------------------
+-- TODO Type NodeDocumentUnicised
+insertDocs :: ( FlowCmdM env err m
+ -- , FlowCorpus a
+ , FlowInsertDB a
+ )
+ => UserId
+ -> CorpusId
+ -> [a]
+ -> m ([DocId], [DocumentWithId a])
+insertDocs uId cId hs = do
+ let docs = map addUniqId hs
+ newIds <- insertDb uId cId docs
+ -- printDebug "newIds" newIds
+ let
+ newIds' = map reId newIds
+ documentsWithId = mergeData (toInserted newIds) (Map.fromList $ map viewUniqId' docs)
+ _ <- Doc.add cId newIds'
+ pure (newIds', documentsWithId)
+
+
+
------------------------------------------------------------------------
viewUniqId' :: UniqId a
=> a