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.NodeStory
20 import Gargantext.Core.Text.List.Social.Find
21 import Gargantext.Core.Text.List.Social.History
22 import Gargantext.Core.Text.List.Social.Patch
23 import Gargantext.Core.Text.List.Social.Prelude
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
40 data FlowSocialListWith = FlowSocialListWithPriority { fslw_priority :: FlowSocialListPriority }
41 | FlowSocialListWithLists { fslw_lists :: [ListId] }
44 data FlowSocialListPriority = MySelfFirst | OthersFirst
45 flowSocialListPriority :: FlowSocialListPriority -> [NodeMode]
46 flowSocialListPriority MySelfFirst = [Private{-, Shared, Public -}]
47 flowSocialListPriority OthersFirst = reverse $ flowSocialListPriority MySelfFirst
50 -- | We keep the parents for all ngrams but terms
51 keepAllParents :: NgramsType -> KeepAllParents
52 keepAllParents NgramsTerms = KeepAllParents False
53 keepAllParents _ = KeepAllParents True
56 ------------------------------------------------------------------------
57 flowSocialList :: ( HasNodeStory env err m
62 => Maybe FlowSocialListWith
65 -> FlowCont NgramsTerm FlowListScores
66 -> m (FlowCont NgramsTerm FlowListScores)
67 flowSocialList Nothing u = flowSocialList' MySelfFirst u
68 flowSocialList (Just (FlowSocialListWithPriority p)) u = flowSocialList' p u
69 flowSocialList (Just (FlowSocialListWithLists ls)) _ = getHistoryScores ls History_User
71 flowSocialList' :: ( HasNodeStory env err m
76 => FlowSocialListPriority
78 -> FlowCont NgramsTerm FlowListScores
79 -> m (FlowCont NgramsTerm FlowListScores)
80 flowSocialList' flowPriority user nt flc =
81 mconcat <$> mapM (flowSocialListByMode' user nt flc)
82 (flowSocialListPriority flowPriority)
85 flowSocialListByMode' :: ( HasNodeStory env err m
91 -> FlowCont NgramsTerm FlowListScores
93 -> m (FlowCont NgramsTerm FlowListScores)
94 flowSocialListByMode' user' nt' flc' mode =
95 findListsId user' mode
96 >>= flowSocialListByModeWith nt' flc'
99 flowSocialListByModeWith :: ( HasNodeStory env err m
105 -> FlowCont NgramsTerm FlowListScores
107 -> m (FlowCont NgramsTerm FlowListScores)
108 flowSocialListByModeWith nt'' flc'' listes =
109 getHistoryScores listes History_User nt'' flc''
112 -----------------------------------------------------------------
113 getHistoryScores :: ( HasNodeStory env err m
121 -> FlowCont NgramsTerm FlowListScores
122 -> m (FlowCont NgramsTerm FlowListScores)
123 getHistoryScores lists hist nt fl =
124 addScorePatches nt lists fl <$> getHistory hist nt lists
126 getHistory :: ( HasNodeStory env err m
134 -> m (Map ListId (Map NgramsType [HashMap NgramsTerm NgramsPatch]))
135 getHistory hist nt listes =
136 history hist [nt] listes <$> getRepo' listes