]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Flow/Utils.hs
[OPTIM] removing long computations for now (TFICF)
[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.NodeNodeNgrams
21 import Gargantext.Database.Schema.Ngrams
22 import Gargantext.Database.Types
23 import Gargantext.Prelude
24 import qualified Data.Map as DM
25 import qualified Data.HashMap.Strict as HashMap
26
27
28 data DocumentIdWithNgrams a b =
29 DocumentIdWithNgrams
30 { documentWithId :: Indexed NodeId a
31 , documentNgrams :: HashMap b (Map NgramsType Int)
32 } deriving (Show)
33
34 docNgrams2nodeNodeNgrams :: CorpusId
35 -> DocNgrams
36 -> NodeNodeNgrams
37 docNgrams2nodeNodeNgrams cId (DocNgrams d n nt w) =
38 NodeNodeNgrams cId d n nt w
39
40 data DocNgrams = DocNgrams { dn_doc_id :: DocId
41 , dn_ngrams_id :: Int
42 , dn_ngrams_type :: NgramsTypeId
43 , dn_weight :: Double
44 }
45
46 insertDocNgramsOn :: CorpusId
47 -> [DocNgrams]
48 -> Cmd err Int
49 insertDocNgramsOn cId dn =
50 insertNodeNodeNgrams
51 $ (map (docNgrams2nodeNodeNgrams cId) dn)
52
53 insertDocNgrams :: CorpusId
54 -> HashMap (Indexed Int Ngrams) (Map NgramsType (Map NodeId Int))
55 -> Cmd err Int
56 insertDocNgrams cId m =
57 insertDocNgramsOn cId [ DocNgrams { dn_doc_id = n
58 , dn_ngrams_id = _index ng
59 , dn_ngrams_type = ngramsTypeId t
60 , dn_weight = fromIntegral i }
61 | (ng, t2n2i) <- HashMap.toList m
62 , (t, n2i) <- DM.toList t2n2i
63 , (n, i) <- DM.toList n2i
64 ]
65