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.Monoid (mconcat)
15 import Data.Text (Text)
16 import Gargantext.API.Ngrams.Tools -- (getListNgrams)
17 import Gargantext.API.Ngrams.Types
18 import Gargantext.Core.Text.List.Social.Find
19 import Gargantext.Core.Text.List.Social.Prelude
20 import Gargantext.Core.Text.List.Social.Scores
21 import Gargantext.Core.Types.Individu
22 import Gargantext.Database.Admin.Types.Node
23 import Gargantext.Database.Prelude
24 import Gargantext.Database.Query.Table.Node.Error
25 import Gargantext.Database.Query.Tree
26 import Gargantext.Database.Schema.Ngrams
27 import Gargantext.Prelude
29 ------------------------------------------------------------------------
30 ------------------------------------------------------------------------
31 ------------------------------------------------------------------------
34 -- | FlowSocialListPriority
35 -- Sociological assumption: either private or others (public) first
36 -- This parameter depends on the user choice
37 data FlowSocialListPriority = MySelfFirst | OthersFirst
39 flowSocialListPriority :: FlowSocialListPriority -> [NodeMode]
40 flowSocialListPriority MySelfFirst = [Private, Shared{-, Public -}]
41 flowSocialListPriority OthersFirst = reverse $ flowSocialListPriority MySelfFirst
44 -- | We keep the parents for all ngrams but terms
45 keepAllParents :: NgramsType -> KeepAllParents
46 keepAllParents NgramsTerms = KeepAllParents False
47 keepAllParents _ = KeepAllParents True
50 ------------------------------------------------------------------------
51 flowSocialList' :: ( RepoCmdM env err m
56 => FlowSocialListPriority
58 -> FlowCont Text FlowListScores
59 -> m (FlowCont Text FlowListScores)
60 flowSocialList' flowPriority user nt flc =
61 mconcat <$> mapM (flowSocialListByMode' user nt flc)
62 (flowSocialListPriority flowPriority)
65 flowSocialListByMode' :: ( RepoCmdM env err m
71 -> FlowCont Text FlowListScores
73 -> m (FlowCont Text FlowListScores)
74 flowSocialListByMode' user' nt' flc' mode =
75 findListsId user' mode
76 >>= flowSocialListByModeWith nt' flc'
79 flowSocialListByModeWith :: ( RepoCmdM env err m
85 -> FlowCont Text FlowListScores
87 -> m (FlowCont Text FlowListScores)
88 flowSocialListByModeWith nt'' flc'' ns =
89 mapM (\l -> getListNgrams [l] nt'') ns
91 . toFlowListScores (keepAllParents nt'') flc''