2 Module : Gargantext.Core.Text.List.Group
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE TemplateHaskell #-}
13 {-# LANGUAGE ConstraintKinds #-}
14 {-# LANGUAGE TypeFamilies #-}
15 {-# LANGUAGE FunctionalDependencies #-}
16 {-# LANGUAGE InstanceSigs #-}
18 module Gargantext.Core.Text.List.Group
21 import Control.Lens (set, view)
24 import Data.Maybe (fromMaybe)
25 import Data.Monoid (mempty)
26 import Data.Text (Text)
27 import Gargantext.Core.Types (ListType(..))
28 import Gargantext.Database.Admin.Types.Node (NodeId)
29 import Gargantext.Core.Text.List.Social.Prelude
30 import Gargantext.Core.Text.List.Group.Prelude
31 import Gargantext.Core.Text.List.Group.WithStem
32 import Gargantext.Core.Text.List.Group.WithScores
33 import Gargantext.Prelude
34 import qualified Data.Set as Set
35 import qualified Data.Map as Map
36 import qualified Data.List as List
38 ------------------------------------------------------------------------
39 -- | TODO add group with stemming
41 class ToGroupedTree a b | a -> b where
42 toGroupedTree :: GroupParams
43 -> FlowCont Text FlowListScores
45 -> FlowCont Text (GroupedTreeScores b)
47 instance ToGroupedTree (Map Text (Set NodeId)) (Set NodeId)
49 toGroupedTree :: GroupParams
50 -> FlowCont Text FlowListScores
51 -> Map Text (Set NodeId)
52 -- -> Map Text (GroupedTreeScores (Set NodeId))
53 -> FlowCont Text (GroupedTreeScores (Set NodeId))
54 toGroupedTree groupParams flc scores = {-view flc_scores-} flow2
56 flow1 = groupWithScores' flc scoring
57 scoring t = fromMaybe Set.empty $ Map.lookup t scores
59 flow2 = case (view flc_cont flow1) == Map.empty of
61 False -> groupWithStem' groupParams flow1
63 instance ToGroupedTree (Map Text Double) Double
65 toGroupedTree :: GroupParams
66 -> FlowCont Text FlowListScores
68 -- -> Map Text (GroupedTreeScores (Set NodeId))
69 -> FlowCont Text (GroupedTreeScores Double)
70 toGroupedTree groupParams flc scores = {-view flc_scores-} flow2
72 flow1 = groupWithScores' flc scoring
73 scoring t = fromMaybe mempty $ Map.lookup t scores
75 flow2 = case (view flc_cont flow1) == Map.empty of
77 False -> groupWithStem' groupParams flow1
79 ------------------------------------------------------------------------
80 ------------------------------------------------------------------------
81 -- 8<-- 8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--
82 -- | TODO To be removed
83 toGroupedText :: GroupedTextParams a b
84 -> Map Text FlowListScores
85 -> Map Text (Set NodeId)
86 -> Map Stem (GroupedText Int)
87 toGroupedText groupParams scores =
88 (groupWithStem groupParams) . (groupWithScores scores)
91 addListType :: Map Text ListType -> GroupedText a -> GroupedText a
92 addListType m g = set gt_listType (hasListType m g) g
94 hasListType :: Map Text ListType -> GroupedText a -> Maybe ListType
95 hasListType m' (GroupedText _ label _ g' _ _ _) =
96 List.foldl' (<>) Nothing
97 $ map (\t -> Map.lookup t m')