Commit 48a8c59d authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Async] back (corpus input test) but still needs work.

parent 005d8dcc
...@@ -257,11 +257,11 @@ addToCorpusWithForm cid (WithForm ft d l _n) logStatus = do ...@@ -257,11 +257,11 @@ addToCorpusWithForm cid (WithForm ft d l _n) logStatus = do
PresseRIS -> Parser.parseFormat Parser.RisPresse PresseRIS -> Parser.parseFormat Parser.RisPresse
newDocs <- liftIO newEmptyMVar newDocs <- liftIO newEmptyMVar
docs <- liftIO _ <- liftIO $ forkIO
$ splitEvery 500 <$> putMVar newDocs
<$> splitEvery 500
<$> take 1000000 <$> take 1000000
<$> parse (cs d) <$> parse (cs d)
_ <- liftIO $ forkIO $ putMVar newDocs docs
logStatus ScraperStatus { _scst_succeeded = Just 1 logStatus ScraperStatus { _scst_succeeded = Just 1
, _scst_failed = Just 0 , _scst_failed = Just 0
...@@ -269,13 +269,14 @@ addToCorpusWithForm cid (WithForm ft d l _n) logStatus = do ...@@ -269,13 +269,14 @@ addToCorpusWithForm cid (WithForm ft d l _n) logStatus = do
, _scst_events = Just [] , _scst_events = Just []
} }
docs' <- liftIO $ takeMVar newDocs docs' <- liftIO $ takeMVar newDocs
newCid <- liftIO newEmptyMVar newCid <- liftIO newEmptyMVar
cid' <- flowCorpus "user1" _ <- forkIO <$> putMVar newCid
(Right [cid]) <$> flowCorpus "user1"
(Multi $ fromMaybe EN l) (Right [cid])
(map (map toHyperdataDocument) docs') (Multi $ fromMaybe EN l)
_ <- liftIO $ forkIO $ putMVar newCid cid' (map (map toHyperdataDocument) docs')
cid'' <- liftIO $ takeMVar newCid cid'' <- liftIO $ takeMVar newCid
printDebug "cid'" cid'' printDebug "cid'" cid''
......
...@@ -158,25 +158,37 @@ recomputeGraph uId nId = do ...@@ -158,25 +158,37 @@ recomputeGraph uId nId = do
g <- case graph of g <- case graph of
Nothing -> do Nothing -> do
graph' <- computeGraph cId NgramsTerms repo graph' <- computeGraphAsync cId NgramsTerms repo
_ <- insertGraph cId uId' (HyperdataGraph $ Just graph') _ <- insertGraph cId uId' (HyperdataGraph $ Just graph')
pure $ trace "[recomputeGraph] Graph empty, computing" $ graph' pure $ trace "[recomputeGraph] Graph empty, computing" $ graph'
Just graph' -> if listVersion == Just v Just graph' -> if listVersion == Just v
then pure graph' then pure graph'
else do else do
graph'' <- computeGraph cId NgramsTerms repo graph'' <- computeGraphAsync cId NgramsTerms repo
_ <- updateHyperdata nId (HyperdataGraph $ Just graph'') _ <- updateHyperdata nId (HyperdataGraph $ Just graph'')
pure $ trace "[recomputeGraph] Graph exists, recomputing" $ graph'' pure $ trace "[recomputeGraph] Graph exists, recomputing" $ graph''
newGraph <- liftIO newEmptyMVar pure g
_ <- liftIO $ forkIO $ putMVar newGraph g
g' <- liftIO $ takeMVar newGraph computeGraphAsync :: HasNodeError err
=> CorpusId
-> NgramsType
-> NgramsRepo
-> Cmd err Graph
computeGraphAsync cId nt repo = do
g <- liftIO newEmptyMVar
_ <- forkIO <$> putMVar g <$> computeGraph cId nt repo
g' <- liftIO $ takeMVar g
pure g' pure g'
-- TODO use Database Monad only here ? -- TODO use Database Monad only here ?
computeGraph :: HasNodeError err => CorpusId -> NgramsType -> NgramsRepo -> Cmd err Graph computeGraph :: HasNodeError err
=> CorpusId
-> NgramsType
-> NgramsRepo
-> Cmd err Graph
computeGraph cId nt repo = do computeGraph cId nt repo = do
lId <- defaultList cId lId <- defaultList cId
...@@ -190,12 +202,12 @@ computeGraph cId nt repo = do ...@@ -190,12 +202,12 @@ computeGraph cId nt repo = do
lIds <- selectNodesWithUsername NodeList userMaster lIds <- selectNodesWithUsername NodeList userMaster
let ngs = filterListWithRoot GraphTerm $ mapTermListRoot [lId] nt repo let ngs = filterListWithRoot GraphTerm $ mapTermListRoot [lId] nt repo
myCooc <- inMVarIO $ Map.filter (>1) myCooc <- Map.filter (>1)
<$> getCoocByNgrams (Diagonal False) <$> getCoocByNgrams (Diagonal False)
<$> groupNodesByNgrams ngs <$> groupNodesByNgrams ngs
<$> getNodesByNgramsOnlyUser cId (lIds <> [lId]) nt (Map.keys ngs) <$> getNodesByNgramsOnlyUser cId (lIds <> [lId]) nt (Map.keys ngs)
graph <- liftIO $ inMVar $ cooc2graph 0 myCooc let graph = cooc2graph 0 myCooc
let graph' = set graph_metadata (Just metadata) graph let graph' = set graph_metadata (Just metadata) graph
pure graph' pure graph'
......
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