Commit 6857a2f6 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] Patches to scores (WIP)

parent 812ce833
Pipeline #1294 failed with stage
...@@ -188,6 +188,7 @@ library: ...@@ -188,6 +188,7 @@ library:
- product-profunctors - product-profunctors
- profunctors - profunctors
- protolude - protolude
- pretty-simple
- pureMD5 - pureMD5
- quickcheck-instances - quickcheck-instances
- rake - rake
......
...@@ -11,11 +11,14 @@ Portability : POSIX ...@@ -11,11 +11,14 @@ Portability : POSIX
module Gargantext.Core.Text.List.Social module Gargantext.Core.Text.List.Social
where where
import Data.Map (Map)
import Data.Monoid (mconcat) import Data.Monoid (mconcat)
import Data.Text (Text) import Data.Text (Text)
import Gargantext.API.Ngrams.Tools import Gargantext.API.Ngrams.Tools
import Gargantext.API.Ngrams.Types import Gargantext.API.Ngrams.Types
import Gargantext.Core.Text.List.Social.Find import Gargantext.Core.Text.List.Social.Find
import Gargantext.Core.Text.List.Social.History
import Gargantext.Core.Text.List.Social.Patch
import Gargantext.Core.Text.List.Social.Prelude import Gargantext.Core.Text.List.Social.Prelude
import Gargantext.Core.Text.List.Social.Scores import Gargantext.Core.Text.List.Social.Scores
import Gargantext.Core.Types.Individu import Gargantext.Core.Types.Individu
...@@ -81,9 +84,41 @@ flowSocialList flowPriority user nt flc = ...@@ -81,9 +84,41 @@ flowSocialList flowPriority user nt flc =
) )
=> NgramsType => NgramsType
-> FlowCont Text FlowListScores -> FlowCont Text FlowListScores
-> [NodeId] -> [ListId]
-> m (FlowCont Text FlowListScores) -> m (FlowCont Text FlowListScores)
flowSocialListByModeWith nt'' flc'' ns = flowSocialListByModeWith nt'' flc'' ns =
mapM (\l -> getListNgrams [l] nt'') ns mapM (\l -> getListNgrams [l] nt'') ns
>>= pure >>= pure
. toFlowListScores (keepAllParents nt'') flc'' . toFlowListScores (keepAllParents nt'') flc''
-----------------------------------------------------------------
getHistory :: ( RepoCmdM env err m
, CmdM env err m
, HasNodeError err
, HasTreeError err
)
=> History
-> NgramsType
-> [ListId]
-> m (Map NgramsType (Map ListId [Map NgramsTerm NgramsPatch]))
getHistory hist nt listes =
history hist [nt] listes <$> getRepo
getHistoryScores :: ( RepoCmdM env err m
, CmdM env err m
, HasNodeError err
, HasTreeError err
)
=> History
-> NgramsType
-> FlowCont Text FlowListScores
-> [ListId]
-> m (FlowCont Text FlowListScores)
getHistoryScores hist nt fl listes =
addScorePatches nt listes fl <$> getHistory hist nt listes
...@@ -21,13 +21,18 @@ import Gargantext.Prelude ...@@ -21,13 +21,18 @@ import Gargantext.Prelude
import qualified Data.List as List import qualified Data.List as List
import qualified Data.Map.Strict as Map import qualified Data.Map.Strict as Map
-- TODO put this in Prelude maybe
cons :: a -> [a] cons :: a -> [a]
cons a = [a] cons a = [a]
------------------------------------------------------------------------
-- | History control
data History = User data History = User
| NotUser | NotUser
| AllHistory | AllHistory
------------------------------------------------------------------------
-- | Main Function
history :: History history :: History
-> [NgramsType] -> [NgramsType]
-> [ListId] -> [ListId]
...@@ -44,6 +49,7 @@ history NotUser t l = clean . (history' t l) ...@@ -44,6 +49,7 @@ history NotUser t l = clean . (history' t l)
history AllHistory t l = history' t l history AllHistory t l = history' t l
------------------------------------------------------------------------
history' :: [NgramsType] history' :: [NgramsType]
-> [ListId] -> [ListId]
......
...@@ -26,23 +26,20 @@ import qualified Data.List as List ...@@ -26,23 +26,20 @@ import qualified Data.List as List
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.Patch.Class as Patch (Replace(..)) import qualified Data.Patch.Class as Patch (Replace(..))
{-
fromList [(NgramsTerms,fromList [(NodeId 189,
-}
addScorePaches :: NgramsType -> [ListId] addScorePatches :: NgramsType -> [ListId]
-> Map NgramsType (Map ListId [Map NgramsTerm NgramsPatch])
-> FlowCont Text FlowListScores -> FlowCont Text FlowListScores
-> Map NgramsType (Map ListId [Map NgramsTerm NgramsPatch])
-> FlowCont Text FlowListScores -> FlowCont Text FlowListScores
addScorePaches nt listes repo fl = foldl' (addScorePachesList nt repo) fl listes addScorePatches nt listes fl repo = foldl' (addScorePatchesList nt repo) fl listes
addScorePachesList :: NgramsType addScorePatchesList :: NgramsType
-> Map NgramsType (Map ListId [Map NgramsTerm NgramsPatch]) -> Map NgramsType (Map ListId [Map NgramsTerm NgramsPatch])
-> FlowCont Text FlowListScores -> FlowCont Text FlowListScores
-> ListId -> ListId
-> FlowCont Text FlowListScores -> FlowCont Text FlowListScores
addScorePachesList nt repo fl lid = foldl' addScorePatch fl patches addScorePatchesList nt repo fl lid = foldl' addScorePatch fl patches
where where
patches = maybe [] (List.concat . (map Map.toList)) patches' patches = maybe [] (List.concat . (map Map.toList)) patches'
...@@ -77,6 +74,17 @@ addScorePatch fl (NgramsTerm t, (NgramsPatch _children (Patch.Replace old_list n ...@@ -77,6 +74,17 @@ addScorePatch fl (NgramsTerm t, (NgramsPatch _children (Patch.Replace old_list n
{- {-
[fromList [(NgramsTerm {unNgramsTerm = "approach"},NgramsPatch {_patch_children = PatchMSet (PatchMap (fromList [(NgramsTerm {unNgramsTerm = "order"},Replace {_old = Just (), _new = Nothing})])), _patch_list = Keep})] [fromList [(NgramsTerm {unNgramsTerm = "approach"},NgramsPatch {_patch_children = PatchMSet (PatchMap (fromList [(NgramsTerm {unNgramsTerm = "order"},Replace {_old = Just (), _new = Nothing})])), _patch_list = Keep})]
,fromList [(NgramsTerm {unNgramsTerm = "approach"},NgramsPatch {_patch_children = PatchMSet (PatchMap (fromList [(NgramsTerm {unNgramsTerm = "order"},Replace {_old = Nothing, _new = Just ()})])), _patch_list = Keep})] ,fromList [(NgramsTerm {unNgramsTerm = "approach"},NgramsPatch {_patch_children = PatchMSet (PatchMap (fromList [(NgramsTerm {unNgramsTerm = "order"},Replace {_old = Nothing, _new = Just ()})])), _patch_list = Keep})]
fromList [(NgramsTerm {unNgramsTerm = "Journals"}
,NgramsReplace { _patch_old = Nothing
, _patch_new = Just (NgramsRepoElement { _nre_size = 1
, _nre_list = MapTerm
, _nre_root = Nothing
, _nre_parent = Nothing, _nre_children = MSet (fromList [(NgramsTerm {unNgramsTerm = "European Journal of Operational Research"},()),(NgramsTerm {unNgramsTerm = "Physical Review C"},())])})})]
,fromList [(NgramsTerm {unNgramsTerm = "NOT FOUND"},NgramsPatch {_patch_children = PatchMSet (PatchMap (fromList [])), _patch_list = Replace {_old = MapTerm, _new = StopTerm}})]])])]
-} -}
addScorePatch fl (NgramsTerm t, NgramsPatch children Patch.Keep) = foldl' add fl $ toList children addScorePatch fl (NgramsTerm t, NgramsPatch children Patch.Keep) = foldl' add fl $ toList children
where where
...@@ -107,5 +115,3 @@ score field list n m = (Just mempty <> m) ...@@ -107,5 +115,3 @@ score field list n m = (Just mempty <> m)
. field . field
. at list . at list
%~ (<> Just n) %~ (<> Just n)
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