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.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 qualified Data.Map as DM
25 import qualified Data.HashMap.Strict as HashMap
28 data DocumentIdWithNgrams a b =
30 { documentWithId :: Indexed NodeId a
31 , documentNgrams :: HashMap b (Map NgramsType Int)
34 docNgrams2contextNodeNgrams :: ListId
37 docNgrams2contextNodeNgrams lId (DocNgrams d n nt w) =
38 ContextNodeNgrams d lId n nt w
40 data DocNgrams = DocNgrams { dn_doc_id :: DocId
42 , dn_ngrams_type :: NgramsTypeId
46 insertDocNgramsOn :: ListId
49 insertDocNgramsOn cId dn =
50 insertContextNodeNgrams
51 $ (map (docNgrams2contextNodeNgrams cId) dn)
53 insertDocNgrams :: ListId
54 -> HashMap (Indexed Int Ngrams) (Map NgramsType (Map DocId 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