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

[FIX] SocialList working for others than Ngrams with Hierarchical groups

parent acbb8703
...@@ -16,12 +16,13 @@ module Gargantext.Core.Text.List ...@@ -16,12 +16,13 @@ module Gargantext.Core.Text.List
where where
import Control.Lens ((^.), set, view, over) import Control.Lens ((^.), set, over)
import Data.Map (Map) import Data.Map (Map)
import Data.Maybe (catMaybes) import Data.Maybe (catMaybes)
import Data.Ord (Down(..)) import Data.Ord (Down(..))
import Data.Set (Set) import Data.Set (Set)
import Data.Text (Text) import Data.Text (Text)
import Data.Tuple.Extra (both)
import Gargantext.API.Ngrams.Types (NgramsElement) import Gargantext.API.Ngrams.Types (NgramsElement)
import Gargantext.API.Ngrams.Types (RepoCmdM) import Gargantext.API.Ngrams.Types (RepoCmdM)
import Gargantext.Core.Text.List.Group import Gargantext.Core.Text.List.Group
...@@ -97,7 +98,7 @@ buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do ...@@ -97,7 +98,7 @@ buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do
let let
groupParams = GroupedTextParams groupIt (Set.size . snd) fst snd {-(size . fst)-} groupParams = GroupedTextParams groupIt (Set.size . snd) fst snd {-(size . fst)-}
groupedWithList = toGroupedText groupParams (view flc_scores socialLists') ngs' groupedWithList = toGroupedTreeText groupParams socialLists' ngs'
{- {-
printDebug "groupedWithList" printDebug "groupedWithList"
...@@ -111,9 +112,10 @@ buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do ...@@ -111,9 +112,10 @@ buildNgramsOthersList user uCid groupIt (nt, MapListSize mapListSize) = do
(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)
(mapTerms', candiTerms) = List.splitAt listSize (mapTerms', candiTerms) = both Map.fromList
$ List.sortOn (Down . viewScore) $ List.splitAt listSize
$ Map.elems tailTerms' $ List.sortOn (Down . viewScore . snd)
$ Map.toList tailTerms'
pure $ Map.fromList [( nt, (toNgramsElement stopTerms) pure $ Map.fromList [( nt, (toNgramsElement stopTerms)
<> (toNgramsElement mapTerms ) <> (toNgramsElement mapTerms )
......
...@@ -18,13 +18,14 @@ Portability : POSIX ...@@ -18,13 +18,14 @@ Portability : POSIX
module Gargantext.Core.Text.List.Group module Gargantext.Core.Text.List.Group
where where
import Control.Lens (set) import Control.Lens (set, view)
import Data.Set (Set) import Data.Set (Set)
import Data.Map (Map) import Data.Map (Map)
import Data.Maybe (fromMaybe)
import Data.Text (Text) import Data.Text (Text)
import Gargantext.Core.Types (ListType(..)) import Gargantext.Core.Types (ListType(..))
import Gargantext.Database.Admin.Types.Node (NodeId) import Gargantext.Database.Admin.Types.Node (NodeId)
import Gargantext.Core.Text.List.Social.Prelude (FlowListScores(..)) import Gargantext.Core.Text.List.Social.Prelude
import Gargantext.Core.Text.List.Group.Prelude import Gargantext.Core.Text.List.Group.Prelude
import Gargantext.Core.Text.List.Group.WithStem import Gargantext.Core.Text.List.Group.WithStem
import Gargantext.Core.Text.List.Group.WithScores import Gargantext.Core.Text.List.Group.WithScores
...@@ -41,6 +42,28 @@ toGroupedText :: GroupedTextParams a b ...@@ -41,6 +42,28 @@ toGroupedText :: GroupedTextParams a b
toGroupedText groupParams scores = toGroupedText groupParams scores =
(groupWithStem groupParams) . (groupWithScores scores) (groupWithStem groupParams) . (groupWithScores scores)
-- | TODO add group with stemming
toGroupedTreeText :: GroupedTextParams a b
-> FlowCont Text FlowListScores
-> Map Text (Set NodeId)
-> Map Text (GroupedTreeScores (Set NodeId))
toGroupedTreeText _groupParams flc scores = view flc_scores flow1
where
flow1 = groupWithScores' flc scoring
scoring t = fromMaybe Set.empty $ Map.lookup t scores
{-
flow2 = case flc_cont flow1 == Set.empty of
True -> view flc_scores flow1
False -> groupWithStem' groupParams flow1
groupWithStem' :: GroupedTextParams a b
-> FlowCont Text (GroupedTreeScores (Set NodeId))
-> FlowCont Text (GroupedTreeScores (Set NodeId))
groupWithStem' _groupParams = identity
-}
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | TODO To be removed -- | TODO To be removed
......
...@@ -31,11 +31,11 @@ import Gargantext.Prelude ...@@ -31,11 +31,11 @@ import Gargantext.Prelude
import qualified Data.Set as Set import qualified Data.Set as Set
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.List as List import qualified Data.List as List
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Group With Scores Main Types -- | Group With Scores Main Types
-- Tree of GroupedTextScores -- Tree of GroupedTextScores
-- Target : type FlowCont Text GroupedTextScores' -- Target : type FlowCont Text GroupedTextScores'
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))
...@@ -55,7 +55,7 @@ instance (Ord score, Monoid score) ...@@ -55,7 +55,7 @@ instance (Ord score, Monoid score)
makeLenses 'GroupedTreeScores makeLenses 'GroupedTreeScores
--------------------------------------------- ------------------------------------------------------------------------
class ViewListType a where class ViewListType a where
viewListType :: a -> Maybe ListType viewListType :: a -> Maybe ListType
...@@ -68,21 +68,52 @@ class Ord b => ViewScore a b | a -> b where ...@@ -68,21 +68,52 @@ class Ord b => ViewScore a b | a -> b where
class ToNgramsElement a where class ToNgramsElement a where
toNgramsElement :: a -> [NgramsElement] toNgramsElement :: a -> [NgramsElement]
--------------------------------------------- ------------------------------------------------------------------------
instance ViewListType (GroupedTreeScores a) where instance ViewListType (GroupedTreeScores a) where
viewListType = view gts'_listType viewListType = view gts'_listType
instance SetListType (GroupedTreeScores a) where instance SetListType (GroupedTreeScores a) where
setListType = set gts'_listType setListType = set gts'_listType
instance SetListType (Map Text (GroupedTreeScores a)) where
setListType lt = Map.map (set gts'_listType lt)
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 ToNgramsElement (Map Text (GroupedTreeScores (Set NodeId))) where instance ToNgramsElement (Map Text (GroupedTreeScores a)) where
toNgramsElement = undefined toNgramsElement = List.concat . (map toNgramsElement) . Map.toList
instance ToNgramsElement (Text, GroupedTreeScores a) where
toNgramsElement (t, gts) = parent : children
where
parent = mkNgramsElement (NgramsTerm t)
(fromMaybe CandidateTerm $ viewListType gts)
Nothing
(mSetFromList $ map NgramsTerm
$ Map.keys
$ view gts'_children gts
)
children = List.concat
$ map (childrenWith (NgramsTerm t) (NgramsTerm t) )
$ Map.toList
$ view gts'_children gts
childrenWith root parent' (t', gts') = parent'' : children'
where
parent'' = mkNgramsElement (NgramsTerm t')
(fromMaybe CandidateTerm $ viewListType gts')
(Just $ RootParent root parent')
(mSetFromList $ map NgramsTerm
$ Map.keys
$ view gts'_children gts'
)
children' = List.concat
$ map (childrenWith root (NgramsTerm t') )
$ Map.toList
$ view gts'_children gts'
......
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