Commit 7782c515 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] enabling FlowSocialList With preferences

parent 4e134509
...@@ -47,10 +47,10 @@ main = do ...@@ -47,10 +47,10 @@ main = do
tt = (Multi EN) tt = (Multi EN)
format = CsvGargV3 -- CsvHal --WOS format = CsvGargV3 -- CsvHal --WOS
corpus :: forall m. FlowCmdM DevEnv GargError m => m CorpusId corpus :: forall m. FlowCmdM DevEnv GargError m => m CorpusId
corpus = flowCorpusFile (UserName $ cs user) (Left (cs name :: Text)) (read limit :: Int) tt format corpusPath corpus = flowCorpusFile (UserName $ cs user) (Left (cs name :: Text)) (read limit :: Int) tt format corpusPath Nothing
corpusCsvHal :: forall m. FlowCmdM DevEnv GargError m => m CorpusId corpusCsvHal :: forall m. FlowCmdM DevEnv GargError m => m CorpusId
corpusCsvHal = flowCorpusFile (UserName $ cs user) (Left (cs name :: Text)) (read limit :: Int) tt CsvHal corpusPath corpusCsvHal = flowCorpusFile (UserName $ cs user) (Left (cs name :: Text)) (read limit :: Int) tt CsvHal corpusPath Nothing
annuaire :: forall m. FlowCmdM DevEnv GargError m => m CorpusId annuaire :: forall m. FlowCmdM DevEnv GargError m => m CorpusId
annuaire = flowAnnuaire (UserName $ cs user) (Left "Annuaire") (Multi EN) corpusPath annuaire = flowAnnuaire (UserName $ cs user) (Left "Annuaire") (Multi EN) corpusPath
......
...@@ -92,7 +92,7 @@ addContact u nId (AddContactParams fn ln) logStatus = do ...@@ -92,7 +92,7 @@ addContact u nId (AddContactParams fn ln) logStatus = do
, _scst_remaining = Just 1 , _scst_remaining = Just 1
, _scst_events = Just [] , _scst_events = Just []
} }
_ <- flow (Nothing :: Maybe HyperdataAnnuaire) u (Right [nId]) (Multi EN) [[hyperdataContact fn ln]] _ <- flow (Nothing :: Maybe HyperdataAnnuaire) u (Right [nId]) (Multi EN) Nothing [[hyperdataContact fn ln]]
pure JobLog { _scst_succeeded = Just 2 pure JobLog { _scst_succeeded = Just 2
, _scst_failed = Just 0 , _scst_failed = Just 0
......
...@@ -137,6 +137,7 @@ data WithQuery = WithQuery ...@@ -137,6 +137,7 @@ data WithQuery = WithQuery
, _wq_datafield :: !Datafield , _wq_datafield :: !Datafield
, _wq_lang :: !Lang , _wq_lang :: !Lang
, _wq_node_id :: !Int , _wq_node_id :: !Int
-- , _wq_flowListWith :: !FlowSocialListWith
} }
deriving Generic deriving Generic
...@@ -213,7 +214,7 @@ addToCorpusWithQuery user cid (WithQuery q dbs datafield l _nid) maybeLimit logS ...@@ -213,7 +214,7 @@ addToCorpusWithQuery user cid (WithQuery q dbs datafield l _nid) maybeLimit logS
, _scst_events = Just [] , _scst_events = Just []
} }
cids <- mapM (\txt -> flowDataText user txt (Multi l) cid) txts cids <- mapM (\txt -> flowDataText user txt (Multi l) cid Nothing) txts
printDebug "corpus id" cids printDebug "corpus id" cids
printDebug "sending email" ("xxxxxxxxxxxxxxxxxxxxx" :: Text) printDebug "sending email" ("xxxxxxxxxxxxxxxxxxxxx" :: Text)
sendMail user sendMail user
...@@ -265,6 +266,7 @@ addToCorpusWithForm user cid (NewWithForm ft d l _n) logStatus jobLog = do ...@@ -265,6 +266,7 @@ addToCorpusWithForm user cid (NewWithForm ft d l _n) logStatus jobLog = do
_cid' <- flowCorpus user _cid' <- flowCorpus user
(Right [cid]) (Right [cid])
(Multi $ fromMaybe EN l) (Multi $ fromMaybe EN l)
Nothing
(map (map toHyperdataDocument) docs) (map (map toHyperdataDocument) docs)
printDebug "Extraction finished : " cid printDebug "Extraction finished : " cid
......
...@@ -66,7 +66,7 @@ api nId (SearchQuery q SearchContact) o l order = do ...@@ -66,7 +66,7 @@ api nId (SearchQuery q SearchContact) o l order = do
<$> SearchResultContact <$> SearchResultContact
<$> map (toRow aId) <$> map (toRow aId)
<$> searchInCorpusWithContacts nId aId q o l order <$> searchInCorpusWithContacts nId aId q o l order
api _ _ _ _ _ = undefined api _ _ _ _ _ = panic "[G.A.Search.api] undefined"
----------------------------------------------------------------------- -----------------------------------------------------------------------
----------------------------------------------------------------------- -----------------------------------------------------------------------
......
...@@ -67,14 +67,15 @@ buildNgramsLists :: ( HasNodeStory env err m ...@@ -67,14 +67,15 @@ buildNgramsLists :: ( HasNodeStory env err m
, HasTreeError err , HasTreeError err
, HasNodeError err , HasNodeError err
) )
=> GroupParams => User
-> User
-> UserCorpusId -> UserCorpusId
-> MasterCorpusId -> MasterCorpusId
-> Maybe FlowSocialListWith
-> GroupParams
-> m (Map NgramsType [NgramsElement]) -> m (Map NgramsType [NgramsElement])
buildNgramsLists gp user uCid mCid = do buildNgramsLists user uCid mCid mfslw gp = do
ngTerms <- buildNgramsTermsList user uCid mCid gp (NgramsTerms, MapListSize 350) ngTerms <- buildNgramsTermsList user uCid mCid mfslw gp (NgramsTerms, MapListSize 350)
othersTerms <- mapM (buildNgramsOthersList user uCid GroupIdentity) othersTerms <- mapM (buildNgramsOthersList user uCid mfslw GroupIdentity)
[ (Authors , MapListSize 9) [ (Authors , MapListSize 9)
, (Sources , MapListSize 9) , (Sources , MapListSize 9)
, (Institutes, MapListSize 9) , (Institutes, MapListSize 9)
...@@ -92,15 +93,16 @@ buildNgramsOthersList ::( HasNodeError err ...@@ -92,15 +93,16 @@ buildNgramsOthersList ::( HasNodeError err
) )
=> User => User
-> UserCorpusId -> UserCorpusId
-> Maybe FlowSocialListWith
-> GroupParams -> GroupParams
-> (NgramsType, MapListSize) -> (NgramsType, MapListSize)
-> m (Map NgramsType [NgramsElement]) -> m (Map NgramsType [NgramsElement])
buildNgramsOthersList user uCid _groupParams (nt, MapListSize mapListSize) = do buildNgramsOthersList user uCid mfslw _groupParams (nt, MapListSize mapListSize) = do
allTerms :: HashMap NgramsTerm (Set NodeId) <- getNodesByNgramsUser uCid nt allTerms :: HashMap NgramsTerm (Set NodeId) <- getNodesByNgramsUser uCid nt
-- PrivateFirst for first developments since Public NodeMode is not implemented yet -- PrivateFirst for first developments since Public NodeMode is not implemented yet
socialLists :: FlowCont NgramsTerm FlowListScores socialLists :: FlowCont NgramsTerm FlowListScores
<- flowSocialList MySelfFirst user nt ( FlowCont HashMap.empty <- flowSocialList mfslw user nt ( FlowCont HashMap.empty
$ HashMap.fromList $ HashMap.fromList
$ List.zip (HashMap.keys allTerms) $ List.zip (HashMap.keys allTerms)
(List.cycle [mempty]) (List.cycle [mempty])
...@@ -149,10 +151,11 @@ buildNgramsTermsList :: ( HasNodeError err ...@@ -149,10 +151,11 @@ buildNgramsTermsList :: ( HasNodeError err
=> User => User
-> UserCorpusId -> UserCorpusId
-> MasterCorpusId -> MasterCorpusId
-> Maybe FlowSocialListWith
-> GroupParams -> GroupParams
-> (NgramsType, MapListSize) -> (NgramsType, MapListSize)
-> m (Map NgramsType [NgramsElement]) -> m (Map NgramsType [NgramsElement])
buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do buildNgramsTermsList user uCid mCid mfslw groupParams (nt, _mapListSize)= do
-- Filter 0 With Double -- Filter 0 With Double
-- Computing global speGen score -- Computing global speGen score
...@@ -163,7 +166,7 @@ buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do ...@@ -163,7 +166,7 @@ buildNgramsTermsList user uCid mCid groupParams (nt, _mapListSize)= do
printDebug "[buldNgramsTermsList: Flow Social List / start]" nt printDebug "[buldNgramsTermsList: Flow Social List / start]" nt
-- PrivateFirst for first developments since Public NodeMode is not implemented yet -- PrivateFirst for first developments since Public NodeMode is not implemented yet
socialLists :: FlowCont NgramsTerm FlowListScores socialLists :: FlowCont NgramsTerm FlowListScores
<- flowSocialList MySelfFirst user nt ( FlowCont HashMap.empty <- flowSocialList mfslw user nt ( FlowCont HashMap.empty
$ HashMap.fromList $ HashMap.fromList
$ List.zip (HashMap.keys allTerms) $ List.zip (HashMap.keys allTerms)
(List.cycle [mempty]) (List.cycle [mempty])
......
...@@ -36,8 +36,12 @@ import Gargantext.Prelude ...@@ -36,8 +36,12 @@ import Gargantext.Prelude
-- | FlowSocialListPriority -- | FlowSocialListPriority
-- Sociological assumption: either private or others (public) first -- Sociological assumption: either private or others (public) first
-- This parameter depends on the user choice -- This parameter depends on the user choice
data FlowSocialListPriority = MySelfFirst | OthersFirst
data FlowSocialListWith = FlowSocialListWithPriority { fslw_priority :: FlowSocialListPriority }
| FlowSocialListWithLists { fslw_lists :: [ListId] }
data FlowSocialListPriority = MySelfFirst | OthersFirst
flowSocialListPriority :: FlowSocialListPriority -> [NodeMode] flowSocialListPriority :: FlowSocialListPriority -> [NodeMode]
flowSocialListPriority MySelfFirst = [Private{-, Shared, Public -}] flowSocialListPriority MySelfFirst = [Private{-, Shared, Public -}]
flowSocialListPriority OthersFirst = reverse $ flowSocialListPriority MySelfFirst flowSocialListPriority OthersFirst = reverse $ flowSocialListPriority MySelfFirst
...@@ -55,11 +59,25 @@ flowSocialList :: ( HasNodeStory env err m ...@@ -55,11 +59,25 @@ flowSocialList :: ( HasNodeStory env err m
, HasNodeError err , HasNodeError err
, HasTreeError err , HasTreeError err
) )
=> Maybe FlowSocialListWith
-> User
-> NgramsType
-> FlowCont NgramsTerm FlowListScores
-> m (FlowCont NgramsTerm FlowListScores)
flowSocialList Nothing u = flowSocialList' MySelfFirst u
flowSocialList (Just (FlowSocialListWithPriority p)) u = flowSocialList' p u
flowSocialList (Just (FlowSocialListWithLists ls)) _ = getHistoryScores ls History_User
flowSocialList' :: ( HasNodeStory env err m
, CmdM env err m
, HasNodeError err
, HasTreeError err
)
=> FlowSocialListPriority => FlowSocialListPriority
-> User -> NgramsType -> User -> NgramsType
-> FlowCont NgramsTerm FlowListScores -> FlowCont NgramsTerm FlowListScores
-> m (FlowCont NgramsTerm FlowListScores) -> m (FlowCont NgramsTerm 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
...@@ -88,25 +106,22 @@ flowSocialList flowPriority user nt flc = ...@@ -88,25 +106,22 @@ flowSocialList flowPriority user nt flc =
-> [ListId] -> [ListId]
-> m (FlowCont NgramsTerm FlowListScores) -> m (FlowCont NgramsTerm FlowListScores)
flowSocialListByModeWith nt'' flc'' listes = flowSocialListByModeWith nt'' flc'' listes =
getHistoryScores History_User nt'' flc'' listes getHistoryScores listes History_User nt'' flc''
{-
mapM (\l -> getListNgrams [l] nt'') listes
>>= pure
. toFlowListScores (keepAllParents nt'') flc''
-}
----------------------------------------------------------------- -----------------------------------------------------------------
getHistoryScores :: ( HasNodeStory env err m getHistoryScores :: ( HasNodeStory env err m
, CmdM env err m , CmdM env err m
, HasNodeError err , HasNodeError err
, HasTreeError err , HasTreeError err
) )
=> History => [ListId]
-> History
-> NgramsType -> NgramsType
-> FlowCont NgramsTerm FlowListScores -> FlowCont NgramsTerm FlowListScores
-> [ListId]
-> m (FlowCont NgramsTerm FlowListScores) -> m (FlowCont NgramsTerm FlowListScores)
getHistoryScores hist nt fl listes = getHistoryScores lists hist nt fl =
addScorePatches nt listes fl <$> getHistory hist nt listes addScorePatches nt lists fl <$> getHistory hist nt lists
getHistory :: ( HasNodeStory env err m getHistory :: ( HasNodeStory env err m
, CmdM env err m , CmdM env err m
......
...@@ -36,7 +36,9 @@ import Gargantext.Prelude ...@@ -36,7 +36,9 @@ import Gargantext.Prelude
import qualified Gargantext.Database.GargDB as GargDB import qualified Gargantext.Database.GargDB as GargDB
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- TODO
-- Delete Corpus children accoring its types
-- Delete NodeList (NodeStory + cbor file)
deleteNode :: (HasConfig env, HasConnectionPool env, HasNodeError err) deleteNode :: (HasConfig env, HasConnectionPool env, HasNodeError err)
=> User => User
-> NodeId -> NodeId
...@@ -44,7 +46,7 @@ deleteNode :: (HasConfig env, HasConnectionPool env, HasNodeError err) ...@@ -44,7 +46,7 @@ deleteNode :: (HasConfig env, HasConnectionPool env, HasNodeError err)
deleteNode u nodeId = do deleteNode u nodeId = do
node' <- N.getNode nodeId node' <- N.getNode nodeId
case (view node_typename node') of case (view node_typename node') of
nt | nt == toDBid NodeUser -> panic "Not allowed to delete NodeUser (yet)" nt | nt == toDBid NodeUser -> panic "[G.D.A.D.deleteNode] Not allowed to delete NodeUser (yet)"
nt | nt == toDBid NodeTeam -> do nt | nt == toDBid NodeTeam -> do
uId <- getUserId u uId <- getUserId u
if _node_user_id node' == uId if _node_user_id node' == uId
......
...@@ -72,6 +72,7 @@ import Gargantext.Core.Text ...@@ -72,6 +72,7 @@ import Gargantext.Core.Text
import Gargantext.Core.Text.List.Group.WithStem ({-StopSize(..),-} GroupParams(..)) import Gargantext.Core.Text.List.Group.WithStem ({-StopSize(..),-} GroupParams(..))
import Gargantext.Core.Text.Corpus.Parsers (parseFile, FileFormat) import Gargantext.Core.Text.Corpus.Parsers (parseFile, FileFormat)
import Gargantext.Core.Text.List (buildNgramsLists) import Gargantext.Core.Text.List (buildNgramsLists)
import Gargantext.Core.Text.List.Social (FlowSocialListWith)
import Gargantext.Core.Text.Terms import Gargantext.Core.Text.Terms
import Gargantext.Core.Text.Terms.Mono.Stem.En (stemIt) import Gargantext.Core.Text.Terms.Mono.Stem.En (stemIt)
import Gargantext.Core.Types (POS(NP)) import Gargantext.Core.Types (POS(NP))
...@@ -151,11 +152,12 @@ flowDataText :: ( FlowCmdM env err m ...@@ -151,11 +152,12 @@ flowDataText :: ( FlowCmdM env err m
-> DataText -> DataText
-> TermType Lang -> TermType Lang
-> CorpusId -> CorpusId
-> Maybe FlowSocialListWith
-> m CorpusId -> m CorpusId
flowDataText u (DataOld ids) tt cid = flowCorpusUser (_tt_lang tt) u (Right [cid]) corpusType ids flowDataText u (DataOld ids) tt cid mfslw = flowCorpusUser (_tt_lang tt) u (Right [cid]) corpusType ids mfslw
where where
corpusType = (Nothing :: Maybe HyperdataCorpus) corpusType = (Nothing :: Maybe HyperdataCorpus)
flowDataText u (DataNew txt) tt cid = flowCorpus u (Right [cid]) tt txt flowDataText u (DataNew txt) tt cid mfslw = flowCorpus u (Right [cid]) tt mfslw txt
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- TODO use proxy -- TODO use proxy
...@@ -167,7 +169,7 @@ flowAnnuaire :: (FlowCmdM env err m) ...@@ -167,7 +169,7 @@ flowAnnuaire :: (FlowCmdM env err m)
-> m AnnuaireId -> m AnnuaireId
flowAnnuaire u n l filePath = do flowAnnuaire u n l filePath = do
docs <- liftBase $ (( splitEvery 500 <$> readFile_Annuaire filePath) :: IO [[HyperdataContact]]) docs <- liftBase $ (( splitEvery 500 <$> readFile_Annuaire filePath) :: IO [[HyperdataContact]])
flow (Nothing :: Maybe HyperdataAnnuaire) u n l docs flow (Nothing :: Maybe HyperdataAnnuaire) u n l Nothing docs
------------------------------------------------------------------------ ------------------------------------------------------------------------
flowCorpusFile :: (FlowCmdM env err m) flowCorpusFile :: (FlowCmdM env err m)
...@@ -175,13 +177,14 @@ flowCorpusFile :: (FlowCmdM env err m) ...@@ -175,13 +177,14 @@ flowCorpusFile :: (FlowCmdM env err m)
-> Either CorpusName [CorpusId] -> Either CorpusName [CorpusId]
-> Limit -- Limit the number of docs (for dev purpose) -> Limit -- Limit the number of docs (for dev purpose)
-> TermType Lang -> FileFormat -> FilePath -> TermType Lang -> FileFormat -> FilePath
-> Maybe FlowSocialListWith
-> m CorpusId -> m CorpusId
flowCorpusFile u n l la ff fp = do flowCorpusFile u n l la ff fp mfslw = do
eParsed <- liftBase $ parseFile ff fp eParsed <- liftBase $ parseFile ff fp
case eParsed of case eParsed of
Right parsed -> do Right parsed -> do
let docs = splitEvery 500 $ take l parsed let docs = splitEvery 500 $ take l parsed
flowCorpus u n la (map (map toHyperdataDocument) docs) flowCorpus u n la mfslw (map (map toHyperdataDocument) docs)
Left e -> panic $ "Error: " <> (T.pack e) Left e -> panic $ "Error: " <> (T.pack e)
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -191,6 +194,7 @@ flowCorpus :: (FlowCmdM env err m, FlowCorpus a) ...@@ -191,6 +194,7 @@ flowCorpus :: (FlowCmdM env err m, FlowCorpus a)
=> User => User
-> Either CorpusName [CorpusId] -> Either CorpusName [CorpusId]
-> TermType Lang -> TermType Lang
-> Maybe FlowSocialListWith
-> [[a]] -> [[a]]
-> m CorpusId -> m CorpusId
flowCorpus = flow (Nothing :: Maybe HyperdataCorpus) flowCorpus = flow (Nothing :: Maybe HyperdataCorpus)
...@@ -204,12 +208,13 @@ flow :: ( FlowCmdM env err m ...@@ -204,12 +208,13 @@ flow :: ( FlowCmdM env err m
-> User -> User
-> Either CorpusName [CorpusId] -> Either CorpusName [CorpusId]
-> TermType Lang -> TermType Lang
-> Maybe FlowSocialListWith
-> [[a]] -> [[a]]
-> m CorpusId -> m CorpusId
flow c u cn la docs = do flow c u cn la mfslw docs = do
-- TODO if public insertMasterDocs else insertUserDocs -- TODO if public insertMasterDocs else insertUserDocs
ids <- traverse (insertMasterDocs c la) docs ids <- traverse (insertMasterDocs c la) docs
flowCorpusUser (la ^. tt_lang) u cn c (concat ids) flowCorpusUser (la ^. tt_lang) u cn c (concat ids) mfslw
------------------------------------------------------------------------ ------------------------------------------------------------------------
flowCorpusUser :: ( FlowCmdM env err m flowCorpusUser :: ( FlowCmdM env err m
...@@ -220,8 +225,9 @@ flowCorpusUser :: ( FlowCmdM env err m ...@@ -220,8 +225,9 @@ flowCorpusUser :: ( FlowCmdM env err m
-> Either CorpusName [CorpusId] -> Either CorpusName [CorpusId]
-> Maybe c -> Maybe c
-> [NodeId] -> [NodeId]
-> Maybe FlowSocialListWith
-> m CorpusId -> m CorpusId
flowCorpusUser l user corpusName ctype ids = do flowCorpusUser l user corpusName ctype ids mfslw = do
-- User Flow -- User Flow
(userId, _rootId, userCorpusId) <- getOrMk_RootWithCorpus user corpusName ctype (userId, _rootId, userCorpusId) <- getOrMk_RootWithCorpus user corpusName ctype
-- NodeTexts is first -- NodeTexts is first
...@@ -242,7 +248,7 @@ flowCorpusUser l user corpusName ctype ids = do ...@@ -242,7 +248,7 @@ flowCorpusUser l user corpusName ctype ids = do
--let gp = (GroupParams l 2 3 (StopSize 3)) --let gp = (GroupParams l 2 3 (StopSize 3))
let gp = GroupWithPosTag l CoreNLP HashMap.empty let gp = GroupWithPosTag l CoreNLP HashMap.empty
ngs <- buildNgramsLists gp user userCorpusId masterCorpusId ngs <- buildNgramsLists user userCorpusId masterCorpusId mfslw gp
_userListId <- flowList_DbRepo listId ngs _userListId <- flowList_DbRepo listId ngs
_mastListId <- getOrMkList masterCorpusId masterUserId _mastListId <- getOrMkList masterCorpusId masterUserId
......
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