2 Module : Gargantext.Core.Text.List.Social
4 Copyright : (c) CNRS, 2018-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
11 module Gargantext.Core.Text.List.Social
14 import Data.HashMap.Strict (HashMap)
16 import Data.Monoid (mconcat)
17 import Gargantext.API.Ngrams.Tools
18 import Gargantext.API.Ngrams.Types
19 import Gargantext.Core.Text.List.Social.Find
20 import Gargantext.Core.Text.List.Social.History
21 import Gargantext.Core.Text.List.Social.Patch
22 import Gargantext.Core.Text.List.Social.Prelude
23 import Gargantext.Core.Types.Individu
24 import Gargantext.Database.Admin.Types.Node
25 import Gargantext.Database.Prelude
26 import Gargantext.Database.Query.Table.Node.Error
27 import Gargantext.Database.Query.Tree
28 import Gargantext.Database.Schema.Ngrams
29 import Gargantext.Prelude
31 ------------------------------------------------------------------------
32 ------------------------------------------------------------------------
35 -- | FlowSocialListPriority
36 -- Sociological assumption: either private or others (public) first
37 -- This parameter depends on the user choice
38 data FlowSocialListPriority = MySelfFirst | OthersFirst
40 flowSocialListPriority :: FlowSocialListPriority -> [NodeMode]
41 flowSocialListPriority MySelfFirst = [Private{-, Shared, Public -}]
42 flowSocialListPriority OthersFirst = reverse $ flowSocialListPriority MySelfFirst
45 -- | We keep the parents for all ngrams but terms
46 keepAllParents :: NgramsType -> KeepAllParents
47 keepAllParents NgramsTerms = KeepAllParents False
48 keepAllParents _ = KeepAllParents True
51 ------------------------------------------------------------------------
52 flowSocialList :: ( RepoCmdM env err m
57 => FlowSocialListPriority
59 -> FlowCont NgramsTerm FlowListScores
60 -> m (FlowCont NgramsTerm FlowListScores)
61 flowSocialList flowPriority user nt flc =
62 mconcat <$> mapM (flowSocialListByMode' user nt flc)
63 (flowSocialListPriority flowPriority)
66 flowSocialListByMode' :: ( RepoCmdM env err m
72 -> FlowCont NgramsTerm FlowListScores
74 -> m (FlowCont NgramsTerm FlowListScores)
75 flowSocialListByMode' user' nt' flc' mode =
76 findListsId user' mode
77 >>= flowSocialListByModeWith nt' flc'
80 flowSocialListByModeWith :: ( RepoCmdM env err m
86 -> FlowCont NgramsTerm FlowListScores
88 -> m (FlowCont NgramsTerm FlowListScores)
89 flowSocialListByModeWith nt'' flc'' listes =
90 getHistoryScores History_User nt'' flc'' listes
92 mapM (\l -> getListNgrams [l] nt'') listes
94 . toFlowListScores (keepAllParents nt'') flc''
96 -----------------------------------------------------------------
97 getHistoryScores :: ( RepoCmdM env err m
104 -> FlowCont NgramsTerm FlowListScores
106 -> m (FlowCont NgramsTerm FlowListScores)
107 getHistoryScores hist nt fl listes =
108 addScorePatches nt listes fl <$> getHistory hist nt listes
110 getHistory :: ( RepoCmdM env err m
118 -> m (Map NgramsType (Map ListId [HashMap NgramsTerm NgramsPatch]))
119 getHistory hist nt listes =
120 history hist [nt] listes <$> getRepo