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 (view)
23 import Data.Maybe (fromMaybe)
24 import Data.Monoid (Monoid, mempty)
25 import Data.Text (Text)
26 import Gargantext.Core.Text.List.Social.Prelude
27 import Gargantext.Core.Text.List.Group.Prelude
28 import Gargantext.Core.Text.List.Group.WithStem
29 import Gargantext.Core.Text.List.Group.WithScores
30 import Gargantext.Prelude
31 import qualified Data.Map as Map
33 ------------------------------------------------------------------------
34 -- | TODO add group with stemming
35 toGroupedTree :: (Ord a, Monoid a, GroupWithStem a)
37 -> FlowCont Text FlowListScores
39 -- -> Map Text (GroupedTreeScores (Set NodeId))
40 -> FlowCont Text (GroupedTreeScores a)
41 toGroupedTree groupParams flc scores = {-view flc_scores-} flow2
43 flow1 = groupWithScores' flc scoring
44 scoring t = fromMaybe mempty $ Map.lookup t scores
46 flow2 = case (view flc_cont flow1) == Map.empty of
48 False -> groupWithStem' groupParams flow1
52 ------------------------------------------------------------------------
53 setScoresWithMap :: (Ord a, Ord b, Monoid b) => Map Text b
54 -> Map Text (GroupedTreeScores a)
55 -> Map Text (GroupedTreeScores b)
56 setScoresWithMap m = setScoresWith (score m)
58 score m' t = case Map.lookup t m' of
62 setScoresWith :: (Ord a, Ord b)
64 -> Map Text (GroupedTreeScores a)
65 -> Map Text (GroupedTreeScores b)
67 -- | This Type level lenses solution does not work
68 setScoresWith f = Map.mapWithKey (\k v -> over gts'_children (setScoresWith f)
69 $ set gts'_score (f k) v
72 setScoresWith f = Map.mapWithKey (\k v -> v { _gts'_score = f k
73 , _gts'_children = setScoresWith f
74 $ view gts'_children v
79 ------------------------------------------------------------------------