2 Module : Gargantext.Database.Flow.Utils
3 Description : Database Flow
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
13 module Gargantext.Database.Action.Flow.Utils
17 import Data.HashMap.Strict (HashMap)
18 import Gargantext.Core.Types (TermsCount)
19 import Gargantext.Database.Admin.Types.Node
20 import Gargantext.Database.Prelude (Cmd)
21 import Gargantext.Database.Query.Table.ContextNodeNgrams
22 import Gargantext.Database.Schema.Ngrams
23 import Gargantext.Database.Types
24 import Gargantext.Prelude
25 import Control.Lens ((^.))
26 import qualified Data.Map as DM
27 import qualified Data.HashMap.Strict as HashMap
30 data DocumentIdWithNgrams a b =
32 { documentWithId :: Indexed NodeId a
33 , documentNgrams :: HashMap b (Map NgramsType Int, TermsCount)
36 insertDocNgrams :: ListId
37 -> HashMap (Indexed NgramsId Ngrams) (Map NgramsType (Map DocId (Int, TermsCount)))
39 insertDocNgrams lId m = do
40 printDebug "[insertDocNgrams] ns" ns
41 insertContextNodeNgrams ns
43 ns = [ ContextNodeNgrams docId lId (ng^.index)
47 | (ng, t2n2i) <- HashMap.toList m
48 , (t, n2i) <- DM.toList t2n2i
49 , (docId, (i, cnt)) <- DM.toList n2i
52 -- [(NodeId, {Ngrams: ({NgramsType: Int}, TermsCount)})]
53 -- {Ngrams: {NgramsType: {NodeId: (Int, TermsCount)}}}