]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Flow/Utils.hs
[ngrams by context] fix subquery to limit only to current corpus
[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 (Map)
17 import Data.HashMap.Strict (HashMap)
18 import Gargantext.Database.Admin.Types.Node
19 import Gargantext.Database.Prelude (Cmd)
20 import Gargantext.Database.Query.Table.ContextNodeNgrams
21 import Gargantext.Database.Schema.Ngrams
22 import Gargantext.Database.Types
23 import Gargantext.Prelude
24 import Control.Lens ((^.))
25 import qualified Data.Map as DM
26 import qualified Data.HashMap.Strict as HashMap
27
28
29 data DocumentIdWithNgrams a b =
30 DocumentIdWithNgrams
31 { documentWithId :: Indexed NodeId a
32 , documentNgrams :: HashMap b (Map NgramsType Int)
33 } deriving (Show)
34
35 insertDocNgrams :: ListId
36 -> HashMap (Indexed NgramsId Ngrams) (Map NgramsType (Map DocId Int))
37 -> Cmd err Int
38 insertDocNgrams lId m = insertContextNodeNgrams ns
39 where
40 ns = [ ContextNodeNgrams docId lId (ng^.index)
41 (ngramsTypeId t)
42 (fromIntegral i)
43 | (ng, t2n2i) <- HashMap.toList m
44 , (t, n2i) <- DM.toList t2n2i
45 , (docId, i) <- DM.toList n2i
46 ]
47
48
49
50
51
52