-}
-{-# LANGUAGE FlexibleContexts #-}
-{-# LANGUAGE NoImplicitPrelude #-}
-{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE RankNTypes #-}
module Gargantext.Database.Action.Flow.Utils
where
import Data.Map (Map)
import qualified Data.Map as DM
-import Gargantext.Prelude
+
+import Gargantext.Database.Admin.Types.Node
+import Gargantext.Database.Admin.Types.Hyperdata (Hyperdata)
+import Gargantext.Database.Prelude (Cmd)
+import Gargantext.Database.Query.Table.NodeNodeNgrams
import Gargantext.Database.Schema.Ngrams
-import Gargantext.Database.Types.Node (NodeId, Node, NodePoly(..), Hyperdata)
-import Gargantext.Database.Utils (Cmd)
-import Gargantext.Database.Schema.NodeNodeNgrams
-import Gargantext.Database.Types.Node
+import Gargantext.Database.Schema.Node
+import Gargantext.Prelude
+
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)