2 Module
: Gargantext.Core.Text.Ngrams.List.Management
3 Description
: Tools to manage lists
4 Copyright
: (c
) CNRS
, 2017-Present
5 License
: AGPL
+ CECILL v3
6 Maintainer
: team@gargantext.org
7 Stability
: experimental
12 {-# LANGUAGE ScopedTypeVariables #-}
13 {-# LANGUAGE TemplateHaskell #-}
15 module Gargantext.Core.Text.List.Management
19 import Data.HashMap.Strict
(HashMap
)
21 import Gargantext.API.Ngrams
22 import Gargantext.API.Ngrams.Types
(NgramsElement
, NgramsTerm
(..
))
23 import Gargantext.Database.Action.Flow.Types
24 import Gargantext.API.Ngrams.Tools
(getListNgrams
)
25 import Gargantext.Core.NodeStory
26 import Gargantext.Core.Text
(size
)
27 import Gargantext.Core.Text.List.Group
28 import Gargantext.Core.Text.List.Group.Prelude
29 import Gargantext.Core.Text.List.Group.WithStem
30 import Gargantext.Core.Text.List.Social
31 import Gargantext.Core.Text.List.Social.Prelude
32 import Gargantext.Core.Text.Metrics
(scored
', Scored(..), scored_speExc, scored_genInc, normalizeGlobal, normalizeLocal, scored_terms)
33 import Gargantext.Core.Types (ListType(..), CorpusId, ListId)
34 import Gargantext.Core.Types.Individu (User(..))
35 import Gargantext.Database.Action.Metrics.NgramsByContext (getContextsByNgramsUser, getContextsByNgramsOnlyUser)
36 import Gargantext.Database.Action.Metrics.TFICF (getTficf_withSample)
37 import Gargantext.Database.Admin.Types.Node (NodeId)
38 import Gargantext.Database.Prelude (CmdM)
39 import Gargantext.Database.Query.Table.Ngrams (text2ngrams)
40 import Gargantext.Database.Query.Table.NgramsPostag (selectLems)
41 import Gargantext.Database.Query.Table.Node (defaultList, getClosestParentIdByType)
42 import Gargantext.Database.Query.Table.Node.Error (HasNodeError())
43 import Gargantext.Database.Query.Tree.Error (HasTreeError)
44 import Gargantext.Database.Action.Metrics.NgramsByContext (getOccByNgramsOnlyFast')
45 import Gargantext.Database.Schema.Ngrams
(NgramsType
(..
), Ngrams
(..
))
46 import Gargantext.Prelude
47 import qualified Data.HashMap.Strict as HashMap
48 import qualified Data.HashSet as HashSet
49 import qualified Data.List as List
50 import qualified Data.Map as Map
51 import qualified Data.Set as Set
52 import qualified Gargantext.Data.HashMap.Strict.Utils as HashMap
59 (HasNodeStory env err m
, FlowCmdM env err m
)
64 -> Int
-- ^ number of ngram pairs to keep
66 restrictListSize corpusId listId ngramsType listType size
= do
67 ngrams
<- getListNgrams
[listId
] ngramsType
68 -- corpus_id
<- getClosestParentIdByType
69 occurrences
<- getOccByNgramsOnlyFast
' corpusId
74 ngrams' <- filterWith listType size occurrences ngrams
76 _
<- setListNgrams listId ngramsType ngrams
'
79 where filterWith :: ListType -> Int -> HashMap NgramsTerm Int
80 -> HashMap NgramsTerm NgramsRepoElement
81 -> m (Map NgramsTerm NgramsRepoElement)
82 filterWith listType' size occs ngrams
=
83 HashMap.filter with ngrams
85 with nre
= case (&&) <$
> Just
(nre^.nre_list
== listType
)
86 <*> ( HashMap.lookup
(nre^.nre_root
) occs