]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Flow/Utils.hs
[FEAT] Graph O2 bridgeness improvement and FrameWrite Extraction
[gargantext.git] / src / Gargantext / Database / Action / Flow / Utils.hs
1 {-|
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
8 Portability : POSIX
9
10 -}
11
12
13 module Gargantext.Database.Action.Flow.Utils
14 where
15
16 import Data.Map.Strict (Map)
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.Strict as DM
27 import qualified Data.HashMap.Strict as HashMap
28
29
30 data DocumentIdWithNgrams a b =
31 DocumentIdWithNgrams
32 { documentWithId :: Indexed NodeId a
33 , documentNgrams :: HashMap b (Map NgramsType Int, TermsCount)
34 } deriving (Show)
35
36 insertDocNgrams :: ListId
37 -> HashMap (Indexed NgramsId Ngrams) (Map NgramsType (Map DocId (Int, TermsCount)))
38 -> Cmd err Int
39 insertDocNgrams lId m = do
40 -- printDebug "[insertDocNgrams] ns" ns
41 insertContextNodeNgrams ns
42 where
43 ns = [ ContextNodeNgrams docId lId (ng^.index)
44 (ngramsTypeId t)
45 (fromIntegral i)
46 cnt
47 | (ng, t2n2i) <- HashMap.toList m
48 , (t, n2i) <- DM.toList t2n2i
49 , (docId, (i, cnt)) <- DM.toList n2i
50 ]
51
52 -- [(NodeId, {Ngrams: ({NgramsType: Int}, TermsCount)})]
53 -- {Ngrams: {NgramsType: {NodeId: (Int, TermsCount)}}}