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
15 import Data.Monoid (mconcat)
16 import Data.Text (Text)
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.Text.List.Social.Scores
24 import Gargantext.Core.Types.Individu
25 import Gargantext.Database.Admin.Types.Node
26 import Gargantext.Database.Prelude
27 import Gargantext.Database.Query.Table.Node.Error
28 import Gargantext.Database.Query.Tree
29 import Gargantext.Database.Schema.Ngrams
30 import Gargantext.Prelude
32 ------------------------------------------------------------------------
33 ------------------------------------------------------------------------
36 -- | FlowSocialListPriority
37 -- Sociological assumption: either private or others (public) first
38 -- This parameter depends on the user choice
39 data FlowSocialListPriority = MySelfFirst | OthersFirst
41 flowSocialListPriority :: FlowSocialListPriority -> [NodeMode]
42 flowSocialListPriority MySelfFirst = [Private{-, Shared, Public -}]
43 flowSocialListPriority OthersFirst = reverse $ flowSocialListPriority MySelfFirst
46 -- | We keep the parents for all ngrams but terms
47 keepAllParents :: NgramsType -> KeepAllParents
48 keepAllParents NgramsTerms = KeepAllParents False
49 keepAllParents _ = KeepAllParents True
51 ------------------------------------------------------------------------
52 flowSocialList :: ( RepoCmdM env err m
57 => FlowSocialListPriority
59 -> FlowCont Text FlowListScores
60 -> m (FlowCont Text 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 Text FlowListScores
74 -> m (FlowCont Text FlowListScores)
75 flowSocialListByMode' user' nt' flc' mode =
76 findListsId user' mode
77 >>= flowSocialListByModeWith nt' flc'
80 flowSocialListByModeWith :: ( RepoCmdM env err m
86 -> FlowCont Text FlowListScores
88 -> m (FlowCont Text FlowListScores)
89 flowSocialListByModeWith nt'' flc'' ns =
90 mapM (\l -> getListNgrams [l] nt'') ns
92 . toFlowListScores (keepAllParents nt'') flc''
94 -----------------------------------------------------------------
97 getHistory :: ( RepoCmdM env err m
105 -> m (Map NgramsType (Map ListId [Map NgramsTerm NgramsPatch]))
106 getHistory hist nt listes =
107 history hist [nt] listes <$> getRepo
110 getHistoryScores :: ( RepoCmdM env err m
117 -> FlowCont Text FlowListScores
119 -> m (FlowCont Text FlowListScores)
120 getHistoryScores hist nt fl listes =
121 addScorePatches nt listes fl <$> getHistory hist nt listes