]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core/Text/List/Management.sh
refactoring temporal matching
[gargantext.git] / src / Gargantext / Core / Text / List / Management.sh
1 {-|
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
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE ScopedTypeVariables #-}
13 {-# LANGUAGE TemplateHaskell #-}
14
15 module Gargantext.Core.Text.List.Management
16 where
17
18 {-
19 import Data.HashMap.Strict (HashMap)
20 import Data.Map (Map)
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
53
54
55
56
57 restrictListSize
58 :: forall env err m.
59 (HasNodeStory env err m, FlowCmdM env err m)
60 => CorpusId
61 -> ListId
62 -> NgramsType
63 -> ListType
64 -> Int -- ^ number of ngram pairs to keep
65 -> m ()
66 restrictListSize corpusId listId ngramsType listType size = do
67 ngrams <- getListNgrams [listId] ngramsType
68 -- corpus_id <- getClosestParentIdByType
69 occurrences <- getOccByNgramsOnlyFast' corpusId
70 listId
71 ngramsType
72 (HashMap.keys ngrams)
73
74 ngrams' <- filterWith listType size occurrences ngrams
75
76 _ <- setListNgrams listId ngramsType ngrams'
77 return ()
78
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
84 where
85 with nre = case (&&) <$> Just (nre^.nre_list == listType)
86 <*> ( HashMap.lookup (nre^.nre_root) occs
87 &&
88
89
90
91
92
93
94 -}
95
96