Commit 7173c1d5 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] bug in FlowCont Semigroup instance (intersection for cont)

parent 86473b50
...@@ -16,7 +16,7 @@ module Gargantext.Core.Text.List ...@@ -16,7 +16,7 @@ module Gargantext.Core.Text.List
where where
import Control.Lens ((^.), set, over) import Control.Lens ((^.), view, set, over)
import Data.Map (Map) import Data.Map (Map)
import Data.Maybe (catMaybes) import Data.Maybe (catMaybes)
import Data.Monoid (mempty) import Data.Monoid (mempty)
...@@ -87,32 +87,29 @@ buildNgramsOthersList ::( HasNodeError err ...@@ -87,32 +87,29 @@ buildNgramsOthersList ::( HasNodeError err
buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do
ngs' :: Map Text (Set NodeId) <- getNodesByNgramsUser uCid nt ngs' :: Map Text (Set NodeId) <- getNodesByNgramsUser uCid nt
-- | PrivateFirst for first developments since Public NodeMode is not implemented yet
socialLists' :: FlowCont Text FlowListScores socialLists' :: FlowCont Text FlowListScores
<- flowSocialList' MySelfFirst user nt ( FlowCont Map.empty <- flowSocialList' MySelfFirst user nt ( FlowCont Map.empty
$ Map.fromList $ Map.fromList
$ List.zip (Map.keys ngs') $ List.zip (Map.keys ngs')
(List.cycle [mempty]) (List.cycle [mempty])
) )
-- PrivateFirst for first developments since Public NodeMode is not implemented yet
{- {-
printDebug "flowSocialList'" printDebug "flowSocialList'"
$ Map.filter (not . ((==) Map.empty) . view fls_parents) $ Map.filter (not . ((==) Map.empty) . (view fls_parents))
$ view flc_scores socialLists' $ view flc_scores socialLists'
-} -}
let let
groupedWithList = toGroupedTreeText groupIt socialLists' ngs' groupedWithList = toGroupedTreeText groupIt socialLists' ngs'
{- {-
printDebug "groupedWithList" printDebug "groupedWithList"
$ Map.map (\v -> (view gt_label v, view gt_children v)) $ view flc_scores groupedWithList
$ Map.filter (\v -> (Set.size $ view gt_children v) > 0)
$ groupedWithList
-} -}
let let
(stopTerms, tailTerms) = Map.partition ((== Just StopTerm) . viewListType) groupedWithList (stopTerms, tailTerms) = Map.partition ((== Just StopTerm) . viewListType) $ view flc_scores groupedWithList
(mapTerms, tailTerms') = Map.partition ((== Just MapTerm) . viewListType) tailTerms (mapTerms, tailTerms') = Map.partition ((== Just MapTerm) . viewListType) tailTerms
listSize = mapListSize - (List.length mapTerms) listSize = mapListSize - (List.length mapTerms)
...@@ -178,6 +175,7 @@ buildNgramsTermsList user uCid mCid groupParams = do ...@@ -178,6 +175,7 @@ buildNgramsTermsList user uCid mCid groupParams = do
let let
-- Get Local Scores now for selected grouped ngrams -- Get Local Scores now for selected grouped ngrams
-- TODO HasTerms
selectedTerms = Set.toList $ List.foldl' selectedTerms = Set.toList $ List.foldl'
(\set' (GroupedText _ l' _ g _ _ _ ) -> Set.union set' (\set' (GroupedText _ l' _ g _ _ _ ) -> Set.union set'
$ Set.insert l' g $ Set.insert l' g
......
...@@ -39,10 +39,11 @@ import qualified Data.List as List ...@@ -39,10 +39,11 @@ import qualified Data.List as List
toGroupedTreeText :: GroupParams toGroupedTreeText :: GroupParams
-> FlowCont Text FlowListScores -> FlowCont Text FlowListScores
-> Map Text (Set NodeId) -> Map Text (Set NodeId)
-> Map Text (GroupedTreeScores (Set NodeId)) -- -> Map Text (GroupedTreeScores (Set NodeId))
toGroupedTreeText groupParams flc scores = view flc_scores flow2 -> FlowCont Text (GroupedTreeScores (Set NodeId))
toGroupedTreeText groupParams flc scores = {-view flc_scores-} flow2
where where
flow1 = groupWithScores' flc scoring flow1 = groupWithScores' flc scoring
scoring t = fromMaybe Set.empty $ Map.lookup t scores scoring t = fromMaybe Set.empty $ Map.lookup t scores
flow2 = case (view flc_cont flow1) == Map.empty of flow2 = case (view flc_cont flow1) == Map.empty of
......
...@@ -38,7 +38,7 @@ import qualified Data.List as List ...@@ -38,7 +38,7 @@ import qualified Data.List as List
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))
, _gts'_score :: score , _gts'_score :: !score
} deriving (Show, Ord, Eq) } deriving (Show, Ord, Eq)
instance (Semigroup a, Ord a) => Semigroup (GroupedTreeScores a) where instance (Semigroup a, Ord a) => Semigroup (GroupedTreeScores a) where
...@@ -68,6 +68,9 @@ class Ord b => ViewScore a b | a -> b where ...@@ -68,6 +68,9 @@ class Ord b => ViewScore a b | a -> b where
class ToNgramsElement a where class ToNgramsElement a where
toNgramsElement :: a -> [NgramsElement] toNgramsElement :: a -> [NgramsElement]
class HasTerms a where
hasTerms :: a -> Set Text
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Instances declartion for (GroupedTreeScores a) -- | Instances declartion for (GroupedTreeScores a)
instance ViewListType (GroupedTreeScores a) where instance ViewListType (GroupedTreeScores a) where
...@@ -82,6 +85,10 @@ instance SetListType (Map Text (GroupedTreeScores a)) where ...@@ -82,6 +85,10 @@ instance SetListType (Map Text (GroupedTreeScores a)) where
instance ViewScore (GroupedTreeScores (Set NodeId)) Int where instance ViewScore (GroupedTreeScores (Set NodeId)) Int where
viewScore = Set.size . (view gts'_score) viewScore = Set.size . (view gts'_score)
instance HasTerms (Map Text (GroupedTreeScores a)) where
hasTerms = undefined
instance ToNgramsElement (Map Text (GroupedTreeScores a)) where instance ToNgramsElement (Map Text (GroupedTreeScores a)) where
toNgramsElement = List.concat . (map toNgramsElement) . Map.toList toNgramsElement = List.concat . (map toNgramsElement) . Map.toList
......
...@@ -26,7 +26,6 @@ import Gargantext.Database.Admin.Types.Node (NodeId) ...@@ -26,7 +26,6 @@ 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.List as List
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.Set as Set import qualified Data.Set as Set
...@@ -44,11 +43,10 @@ groupWithScores' flc scores = FlowCont groups orphans ...@@ -44,11 +43,10 @@ groupWithScores' flc scores = FlowCont groups orphans
$ toMapMaybeParent scores $ toMapMaybeParent scores
$ view flc_scores flc $ view flc_scores flc
-- orphans have been filtered already -- orphans should be filtered already
orphans = toGroupedTree orphans = toGroupedTree
$ toMapMaybeParent scores $ toMapMaybeParent scores
$ (view flc_cont flc) $ view flc_cont flc
------------------------------------------------------------------------ ------------------------------------------------------------------------
toMapMaybeParent :: (Text -> Set NodeId) toMapMaybeParent :: (Text -> Set NodeId)
-> Map Text FlowListScores -> Map Text FlowListScores
...@@ -92,6 +90,9 @@ toGroupedTree' m notEmpty ...@@ -92,6 +90,9 @@ toGroupedTree' m notEmpty
--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 BE REMOVED -- TODO TO BE REMOVED
data GroupedTextScores score = data GroupedTextScores score =
......
...@@ -20,6 +20,7 @@ module Gargantext.Core.Text.List.Group.WithStem ...@@ -20,6 +20,7 @@ module Gargantext.Core.Text.List.Group.WithStem
import Control.Lens (makeLenses, view, over) import Control.Lens (makeLenses, view, over)
import Data.Set (Set) import Data.Set (Set)
import Data.Map (Map) import Data.Map (Map)
import Data.Monoid (mempty)
import Data.Text (Text) import Data.Text (Text)
import Gargantext.Core (Lang(..)) import Gargantext.Core (Lang(..))
import Gargantext.Core.Text (size) import Gargantext.Core.Text (size)
...@@ -36,6 +37,7 @@ import qualified Data.Text as Text ...@@ -36,6 +37,7 @@ import qualified Data.Text as Text
-- | Main Types -- | Main Types
data StopSize = StopSize {unStopSize :: !Int} data StopSize = StopSize {unStopSize :: !Int}
deriving (Eq)
-- | TODO: group with 2 terms only can be -- | TODO: group with 2 terms only can be
-- discussed. Main purpose of this is offering -- discussed. Main purpose of this is offering
...@@ -47,13 +49,18 @@ data GroupParams = GroupParams { unGroupParams_lang :: !Lang ...@@ -47,13 +49,18 @@ data GroupParams = GroupParams { unGroupParams_lang :: !Lang
, unGroupParams_stopSize :: !StopSize , unGroupParams_stopSize :: !StopSize
} }
| GroupIdentity | GroupIdentity
deriving (Eq)
------------------------------------------------------------------------ ------------------------------------------------------------------------
groupWithStem' :: GroupParams groupWithStem' :: GroupParams
-> FlowCont Text (GroupedTreeScores (Set NodeId)) -> FlowCont Text (GroupedTreeScores (Set NodeId))
-> FlowCont Text (GroupedTreeScores (Set NodeId)) -> FlowCont Text (GroupedTreeScores (Set NodeId))
groupWithStem' = mergeWith . groupWith groupWithStem' g flc
| g == GroupIdentity = FlowCont ( (<>)
(view flc_scores flc)
(view flc_cont flc)
) Map.empty
| otherwise = mergeWith (groupWith g) flc
-- | MergeWith : with stem, we always have an answer -- | MergeWith : with stem, we always have an answer
-- if Maybe lems then we should add it to continuation -- if Maybe lems then we should add it to continuation
...@@ -69,7 +76,7 @@ mergeWith fun flc = FlowCont scores Map.empty ...@@ -69,7 +76,7 @@ mergeWith fun flc = FlowCont scores Map.empty
scores' = view flc_scores flc scores' = view flc_scores flc
cont' = Map.toList $ view flc_cont flc cont' = Map.toList $ view flc_cont flc
-- TODO inserti at the right place in group hierarchy -- TODO insert at the right place in group hierarchy
-- adding as child of the parent for now -- adding as child of the parent for now
alter :: Map Stem Text alter :: Map Stem Text
-> Map Text (GroupedTreeScores (Set NodeId)) -> Map Text (GroupedTreeScores (Set NodeId))
......
...@@ -65,7 +65,7 @@ flowSocialList' :: ( RepoCmdM env err m ...@@ -65,7 +65,7 @@ flowSocialList' :: ( RepoCmdM env err m
-> FlowCont Text FlowListScores -> FlowCont Text FlowListScores
-> m (FlowCont Text FlowListScores) -> m (FlowCont Text FlowListScores)
flowSocialList' flowPriority user nt flc = flowSocialList' flowPriority user nt flc =
mconcat <$> mapM (flowSocialListByMode' user nt flc) mconcat <$> mapM (flowSocialListByMode' user nt flc)
(flowSocialListPriority flowPriority) (flowSocialListPriority flowPriority)
where where
......
...@@ -46,12 +46,12 @@ instance (Ord a, Eq b) => Monoid (FlowCont a b) where ...@@ -46,12 +46,12 @@ instance (Ord a, Eq b) => Monoid (FlowCont a b) where
instance (Eq a, Ord a, Eq b) => 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 == mempty = FlowCont m s2 = FlowCont m s
| s2 == mempty = FlowCont m s1 where
| otherwise = FlowCont m (Map.intersection s1 s2) m = Map.union m1 m2
where s = Map.intersection s1 s2
m = Map.union m1 m2
makeLenses ''FlowCont
-- | Datatype definition -- | Datatype definition
data FlowListScores = data FlowListScores =
...@@ -62,9 +62,6 @@ data FlowListScores = ...@@ -62,9 +62,6 @@ data FlowListScores =
} }
deriving (Show, Generic, Eq) deriving (Show, Generic, Eq)
------------------------------------------------------------------------
makeLenses ''FlowCont
makeLenses ''FlowListScores makeLenses ''FlowListScores
-- | Rules to compose 2 datatype FlowListScores -- | Rules to compose 2 datatype FlowListScores
......
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