Commit d017571f authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FlowCont] improving Type (to prepare group terms)

parent b2cedb8f
Pipeline #1238 failed with stage
...@@ -19,6 +19,7 @@ module Gargantext.Core.Text.List ...@@ -19,6 +19,7 @@ module Gargantext.Core.Text.List
import Control.Lens ((^.), set, over) import Control.Lens ((^.), set, over)
import Data.Map (Map) import Data.Map (Map)
import Data.Maybe (catMaybes) import Data.Maybe (catMaybes)
import Data.Monoid (mempty)
import Data.Ord (Down(..)) import Data.Ord (Down(..))
import Data.Set (Set) import Data.Set (Set)
import Data.Text (Text) import Data.Text (Text)
...@@ -87,7 +88,11 @@ buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do ...@@ -87,7 +88,11 @@ buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do
ngs' :: Map Text (Set NodeId) <- getNodesByNgramsUser uCid nt ngs' :: Map Text (Set NodeId) <- getNodesByNgramsUser uCid nt
socialLists' :: FlowCont Text FlowListScores socialLists' :: FlowCont Text FlowListScores
<- flowSocialList' MySelfFirst user nt (FlowCont Map.empty $ Set.fromList $ Map.keys ngs') <- flowSocialList' MySelfFirst user nt ( FlowCont Map.empty
$ Map.fromList
$ List.zip (Map.keys ngs')
(List.cycle [mempty])
)
-- PrivateFirst for first developments since Public NodeMode is not implemented yet -- PrivateFirst for first developments since Public NodeMode is not implemented yet
{- {-
......
...@@ -13,7 +13,6 @@ Portability : POSIX ...@@ -13,7 +13,6 @@ Portability : POSIX
{-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE InstanceSigs #-}
module Gargantext.Core.Text.List.Group.Prelude module Gargantext.Core.Text.List.Group.Prelude
where where
...@@ -33,9 +32,9 @@ import qualified Data.Map as Map ...@@ -33,9 +32,9 @@ import qualified Data.Map as Map
import qualified Data.List as List import qualified Data.List as List
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Group With Scores Main Types -- | Main Types to group With Scores but preserving Tree dependencies
-- Tree of GroupedTextScores -- Therefore there is a need of Tree of GroupedTextScores
-- Target : type FlowCont Text GroupedTextScores' -- to target continuation type for the flow (FlowCont Text GroupedTreeScores)
data GroupedTreeScores score = data GroupedTreeScores score =
GroupedTreeScores { _gts'_listType :: !(Maybe ListType) GroupedTreeScores { _gts'_listType :: !(Maybe ListType)
, _gts'_children :: !(Map Text (GroupedTreeScores score)) , _gts'_children :: !(Map Text (GroupedTreeScores score))
...@@ -51,11 +50,12 @@ instance (Semigroup a, Ord a) => Semigroup (GroupedTreeScores a) where ...@@ -51,11 +50,12 @@ instance (Semigroup a, Ord a) => Semigroup (GroupedTreeScores a) where
instance (Ord score, Monoid score) instance (Ord score, Monoid score)
=> Monoid (GroupedTreeScores score) where => Monoid (GroupedTreeScores score) where
mempty = GroupedTreeScores Nothing Map.empty mempty mempty = GroupedTreeScores mempty mempty mempty
makeLenses 'GroupedTreeScores makeLenses 'GroupedTreeScores
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Main Classes
class ViewListType a where class ViewListType a where
viewListType :: a -> Maybe ListType viewListType :: a -> Maybe ListType
...@@ -69,6 +69,7 @@ class ToNgramsElement a where ...@@ -69,6 +69,7 @@ class ToNgramsElement a where
toNgramsElement :: a -> [NgramsElement] toNgramsElement :: a -> [NgramsElement]
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Instances declartion for (GroupedTreeScores a)
instance ViewListType (GroupedTreeScores a) where instance ViewListType (GroupedTreeScores a) where
viewListType = view gts'_listType viewListType = view gts'_listType
...@@ -108,8 +109,6 @@ instance ToNgramsElement (Text, GroupedTreeScores a) where ...@@ -108,8 +109,6 @@ instance ToNgramsElement (Text, GroupedTreeScores a) where
$ Map.keys $ Map.keys
$ view gts'_children gts' $ view gts'_children gts'
) )
children' = List.concat children' = List.concat
$ map (childrenWith root (NgramsTerm t') ) $ map (childrenWith root (NgramsTerm t') )
$ Map.toList $ Map.toList
...@@ -122,7 +121,6 @@ instance ToNgramsElement (Text, GroupedTreeScores a) where ...@@ -122,7 +121,6 @@ instance ToNgramsElement (Text, GroupedTreeScores a) where
-- 8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<-- -- 8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--
-- TODO to remove below -- TODO to remove below
data GroupedWithListScores = data GroupedWithListScores =
......
...@@ -26,8 +26,9 @@ import Gargantext.Database.Admin.Types.Node (NodeId) ...@@ -26,8 +26,9 @@ import Gargantext.Database.Admin.Types.Node (NodeId)
import Gargantext.Core.Text.List.Social.Prelude import Gargantext.Core.Text.List.Social.Prelude
import Gargantext.Core.Text.List.Group.Prelude import Gargantext.Core.Text.List.Group.Prelude
import Gargantext.Prelude import Gargantext.Prelude
import qualified Data.Set as Set import qualified Data.List as List
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.Set as Set
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -44,13 +45,17 @@ groupWithScores' flc scores = FlowCont groups orphans ...@@ -44,13 +45,17 @@ groupWithScores' flc scores = FlowCont groups orphans
$ view flc_scores flc $ view flc_scores flc
-- orphans have been filtered already -- orphans have been filtered already
orphans = (view flc_cont flc) orphans = toGroupedTree
$ toMapMaybeParent scores
$ (view flc_cont flc)
------------------------------------------------------------------------ ------------------------------------------------------------------------
toMapMaybeParent :: (Text -> Set NodeId) toMapMaybeParent :: (Text -> Set NodeId)
-> Map Text FlowListScores -> Map Text FlowListScores
-> Map (Maybe Parent) (Map Text (GroupedTreeScores (Set NodeId))) -> Map (Maybe Parent) (Map Text (GroupedTreeScores (Set NodeId)))
toMapMaybeParent f = Map.fromListWith (<>) . (map (fromScores'' f)) . Map.toList toMapMaybeParent f = Map.fromListWith (<>)
. (map (fromScores'' f))
. Map.toList
fromScores'' :: (Text -> Set NodeId) fromScores'' :: (Text -> Set NodeId)
-> (Text, FlowListScores) -> (Text, FlowListScores)
...@@ -78,11 +83,12 @@ toGroupedTree' m notEmpty ...@@ -78,11 +83,12 @@ toGroupedTree' m notEmpty
| otherwise = Map.mapWithKey (addGroup m) notEmpty | otherwise = Map.mapWithKey (addGroup m) notEmpty
where where
addGroup m' k v = over gts'_children ( (toGroupedTree' m') addGroup m' k v = over gts'_children ( (toGroupedTree' m')
. (Map.union (fromMaybe Map.empty . (Map.union ( fromMaybe Map.empty
$ Map.lookup (Just k) m' $ Map.lookup (Just k) m'
) )
) )
) v )
v
......
...@@ -40,9 +40,9 @@ data StopSize = StopSize {unStopSize :: !Int} ...@@ -40,9 +40,9 @@ data StopSize = StopSize {unStopSize :: !Int}
-- discussed. Main purpose of this is offering -- discussed. Main purpose of this is offering
-- a first grouping option to user and get some -- a first grouping option to user and get some
-- enriched data to better learn and improve that algo -- enriched data to better learn and improve that algo
data GroupParams = GroupParams { unGroupParams_lang :: !Lang data GroupParams = GroupParams { unGroupParams_lang :: !Lang
, unGroupParams_len :: !Int , unGroupParams_len :: !Int
, unGroupParams_limit :: !Int , unGroupParams_limit :: !Int
, unGroupParams_stopSize :: !StopSize , unGroupParams_stopSize :: !StopSize
} }
| GroupIdentity | GroupIdentity
......
...@@ -37,18 +37,18 @@ type Parent = Text ...@@ -37,18 +37,18 @@ type Parent = Text
-- | DataType inspired by continuation Monad (but simpler) -- | DataType inspired by continuation Monad (but simpler)
data FlowCont a b = data FlowCont a b =
FlowCont { _flc_scores :: Map a b FlowCont { _flc_scores :: Map a b
, _flc_cont :: Set a , _flc_cont :: Map a b
} }
instance Ord a => Monoid (FlowCont a b) where instance (Ord a, Eq b) => Monoid (FlowCont a b) where
mempty = FlowCont Map.empty Set.empty mempty = FlowCont mempty mempty
instance (Eq a, Ord a) => Semigroup (FlowCont a b) where instance (Eq a, Ord a, Eq b) => Semigroup (FlowCont a b) where
(<>) (FlowCont m1 s1) (<>) (FlowCont m1 s1)
(FlowCont m2 s2) (FlowCont m2 s2)
| s1 == Set.empty = FlowCont m s2 | s1 == mempty = FlowCont m s2
| s2 == Set.empty = FlowCont m s1 | s2 == mempty = FlowCont m s1
| otherwise = FlowCont m (Set.intersection s1 s2) | otherwise = FlowCont m (Map.intersection s1 s2)
where where
m = Map.union m1 m2 m = Map.union m1 m2
...@@ -60,7 +60,7 @@ data FlowListScores = ...@@ -60,7 +60,7 @@ data FlowListScores =
-- You can add any score by incrementing this type -- You can add any score by incrementing this type
-- , _flc_score :: Map Score Int -- , _flc_score :: Map Score Int
} }
deriving (Show, Generic) deriving (Show, Generic, Eq)
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
...@@ -47,7 +47,7 @@ toFlowListScores k flc_origin = foldl' (toFlowListScores_Level1 k flc_origin) me ...@@ -47,7 +47,7 @@ toFlowListScores k flc_origin = foldl' (toFlowListScores_Level1 k flc_origin) me
toFlowListScores_Level1 k' flc_origin' flc_dest ngramsRepo = toFlowListScores_Level1 k' flc_origin' flc_dest ngramsRepo =
Set.foldl' (toFlowListScores_Level2 k' ngramsRepo flc_origin') Set.foldl' (toFlowListScores_Level2 k' ngramsRepo flc_origin')
flc_dest flc_dest
(view flc_cont flc_origin') (Set.fromList $ Map.keys $ view flc_cont flc_origin')
toFlowListScores_Level2 :: KeepAllParents toFlowListScores_Level2 :: KeepAllParents
...@@ -58,9 +58,9 @@ toFlowListScores k flc_origin = foldl' (toFlowListScores_Level1 k flc_origin) me ...@@ -58,9 +58,9 @@ toFlowListScores k flc_origin = foldl' (toFlowListScores_Level1 k flc_origin) me
-> FlowCont Text FlowListScores -> FlowCont Text FlowListScores
toFlowListScores_Level2 k'' ngramsRepo flc_origin'' flc_dest' t = toFlowListScores_Level2 k'' ngramsRepo flc_origin'' flc_dest' t =
case Map.lookup t ngramsRepo of case Map.lookup t ngramsRepo of
Nothing -> over flc_cont (Set.insert t) flc_dest' Nothing -> over flc_cont (Map.insert t mempty) flc_dest'
Just nre -> over flc_scores Just nre -> over flc_scores
( (Map.alter (addParent k'' nre (view flc_cont flc_origin'')) t) ( (Map.alter (addParent k'' nre (Set.fromList $ Map.keys $ view flc_cont flc_origin'')) t)
. (Map.alter (addList $ _nre_list nre) t) . (Map.alter (addList $ _nre_list nre) t)
) flc_dest' ) flc_dest'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment