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 Gargantext.Database.Admin.Types.Node
18 import Gargantext.Database.Prelude (Cmd)
19 import Gargantext.Database.Query.Table.NodeNodeNgrams
20 import Gargantext.Database.Schema.Ngrams
21 import Gargantext.Database.Types
22 import Gargantext.Prelude
23 import qualified Data.Map as DM
25 type DocumentWithId a = Indexed NodeId a
27 data DocumentIdWithNgrams a =
29 { documentWithId :: DocumentWithId a
30 , documentNgrams :: Map Ngrams (Map NgramsType Int)
34 docNgrams2nodeNodeNgrams :: CorpusId
37 docNgrams2nodeNodeNgrams cId (DocNgrams d n nt w) =
38 NodeNodeNgrams cId d n nt w
40 data DocNgrams = DocNgrams { dn_doc_id :: DocId
42 , dn_ngrams_type :: NgramsTypeId
46 insertDocNgramsOn :: CorpusId
49 insertDocNgramsOn cId dn =
51 $ (map (docNgrams2nodeNodeNgrams cId) dn)
53 insertDocNgrams :: CorpusId
54 -> Map (Indexed Int Ngrams) (Map NgramsType (Map NodeId Int))
56 insertDocNgrams cId m =
57 insertDocNgramsOn cId [ DocNgrams n (_index ng) (ngramsTypeId t) (fromIntegral i)
58 | (ng, t2n2i) <- DM.toList m
59 , (t, n2i) <- DM.toList t2n2i
60 , (n, i) <- DM.toList n2i