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.Maybe (fromMaybe)
16 import Data.Monoid (mconcat)
18 import Data.Text (Text)
19 import Gargantext.API.Ngrams.Tools -- (getListNgrams)
20 import Gargantext.API.Ngrams.Types
21 import Gargantext.Core.Text.List.Social.Find
22 import Gargantext.Core.Text.List.Social.ListType
23 import Gargantext.Core.Text.List.Social.Prelude
24 import Gargantext.Core.Text.List.Social.Scores
25 import Gargantext.Core.Types.Individu
26 import Gargantext.Core.Types.Main
27 import Gargantext.Database.Admin.Types.Node
28 import Gargantext.Database.Prelude
29 import Gargantext.Database.Query.Table.Node.Error
30 import Gargantext.Database.Query.Tree
31 import Gargantext.Database.Schema.Ngrams
32 import Gargantext.Prelude
33 import qualified Data.Map as Map
34 import qualified Data.Set as Set
36 ------------------------------------------------------------------------
37 ------------------------------------------------------------------------
38 ------------------------------------------------------------------------
41 -- | FlowSocialListPriority
42 -- Sociological assumption: either private or others (public) first
43 -- This parameter depends on the user choice
44 data FlowSocialListPriority = MySelfFirst | OthersFirst
46 flowSocialListPriority :: FlowSocialListPriority -> [NodeMode]
47 flowSocialListPriority MySelfFirst = [Private, Shared{-, Public -}]
48 flowSocialListPriority OthersFirst = reverse $ flowSocialListPriority MySelfFirst
51 -- | We keep the parents for all ngrams but terms
52 keepAllParents :: NgramsType -> KeepAllParents
53 keepAllParents NgramsTerms = KeepAllParents False
54 keepAllParents _ = KeepAllParents True
57 ------------------------------------------------------------------------
58 flowSocialList' :: ( RepoCmdM env err m
63 => FlowSocialListPriority
65 -> FlowCont Text FlowListScores
66 -> m (FlowCont Text FlowListScores)
67 flowSocialList' flowPriority user nt flc =
68 mconcat <$> mapM (flowSocialListByMode' user nt flc)
69 (flowSocialListPriority flowPriority)
72 flowSocialListByMode' :: ( RepoCmdM env err m
78 -> FlowCont Text FlowListScores
80 -> m (FlowCont Text FlowListScores)
81 flowSocialListByMode' user' nt' flc' mode =
82 findListsId user' mode
83 >>= flowSocialListByModeWith nt' flc'
86 flowSocialListByModeWith :: ( RepoCmdM env err m
92 -> FlowCont Text FlowListScores
94 -> m (FlowCont Text FlowListScores)
95 flowSocialListByModeWith nt'' flc'' ns =
96 mapM (\l -> getListNgrams [l] nt'') ns
98 . toFlowListScores (keepAllParents nt'') flc''