import Data.Map (Map)
import qualified Data.Map as DM
-import Gargantext.Core.Types.Individu (User(..))
import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Admin.Types.Hyperdata (Hyperdata)
import Gargantext.Database.Prelude (Cmd)
-import Gargantext.Database.Query.Table.Node
-import Gargantext.Database.Query.Table.User
-import Gargantext.Database.Query.Table.Node.Error
import Gargantext.Database.Query.Table.NodeNodeNgrams
import Gargantext.Database.Schema.Ngrams
import Gargantext.Database.Schema.Node
import Gargantext.Prelude
-getUserId :: HasNodeError err
- => User
- -> Cmd err UserId
-getUserId (UserDBId uid) = pure uid
-getUserId (RootId rid) = do
- n <- getNode rid
- pure $ _node_userId n
-getUserId (UserName u ) = do
- muser <- getUser u
- case muser of
- Just user -> pure $ userLight_id user
- Nothing -> nodeError NoUserFound
-getUserId UserPublic = nodeError NoUserFound
-
toMaps :: Hyperdata a
=> (a -> Map (NgramsT Ngrams) Int)
-> Map (NgramsT Ngrams) (Map NodeId Int)
toMaps fun ns = mapNodeIdNgrams $ documentIdWithNgrams fun ns'
where
- ns' = map (\(Node nId _ _ _ _ _ json) -> DocumentWithId nId json) ns
+ ns' = map (\(Node nId _ _ _ _ _ _ json) -> DocumentWithId nId json) ns
mapNodeIdNgrams :: Hyperdata a
=> [DocumentIdWithNgrams a]
mapNodeIdNgrams ds = DM.map (DM.fromListWith (+)) $ DM.fromListWith (<>) xs
where
xs = [(ng, [(nId, i)]) | (nId, n2i') <- n2i ds, (ng, i) <- DM.toList n2i']
- n2i = map (\d -> ((documentId . documentWithId) d, document_ngrams d))
+ n2i = map (\d -> ((documentId . documentWithId) d, documentNgrams d))
documentIdWithNgrams :: Hyperdata a
data DocumentIdWithNgrams a =
DocumentIdWithNgrams
{ documentWithId :: DocumentWithId a
- , document_ngrams :: Map (NgramsT Ngrams) Int
+ , documentNgrams :: Map (NgramsT Ngrams) Int
} deriving (Show)