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

[OPTIM] MVar for Graph Clustering.

parent 531317c8
...@@ -164,7 +164,7 @@ makeDevMiddleware = do ...@@ -164,7 +164,7 @@ makeDevMiddleware = do
-- True -> app req resp -- True -> app req resp
-- False -> resp ( responseLBS status401 [] -- False -> resp ( responseLBS status401 []
-- "Invalid Origin or Host header") -- "Invalid Origin or Host header")
-- --
let corsMiddleware = cors $ \_ -> Just CorsResourcePolicy let corsMiddleware = cors $ \_ -> Just CorsResourcePolicy
-- { corsOrigins = Just ([env^.settings.allowedOrigin], False) -- { corsOrigins = Just ([env^.settings.allowedOrigin], False)
{ corsOrigins = Nothing -- == /* { corsOrigins = Nothing -- == /*
...@@ -180,7 +180,7 @@ makeDevMiddleware = do ...@@ -180,7 +180,7 @@ makeDevMiddleware = do
--let warpS = Warp.setPort (8008 :: Int) -- (env^.settings.appPort) --let warpS = Warp.setPort (8008 :: Int) -- (env^.settings.appPort)
-- $ Warp.defaultSettings -- $ Warp.defaultSettings
--pure (warpS, logWare . checkOriginAndHost . corsMiddleware) --pure (warpS, logWare . checkOriginAndHost . corsMiddleware)
pure $ logStdoutDev . corsMiddleware pure $ logStdoutDev . corsMiddleware
...@@ -234,58 +234,60 @@ type GargPrivateAPI' = ...@@ -234,58 +234,60 @@ type GargPrivateAPI' =
GargAdminAPI GargAdminAPI
-- Node endpoint -- Node endpoint
:<|> "node" :> Summary "Node endpoint" :<|> "node" :> Summary "Node endpoint"
:> Capture "node_id" NodeId :> Capture "node_id" NodeId
:> NodeAPI HyperdataAny :> NodeAPI HyperdataAny
-- Corpus endpoints -- Corpus endpoints
:<|> "corpus":> Summary "Corpus endpoint" :<|> "corpus" :> Summary "Corpus endpoint"
:> Capture "corpus_id" CorpusId :> Capture "corpus_id" CorpusId
:> NodeAPI HyperdataCorpus :> NodeAPI HyperdataCorpus
:<|> "corpus":> Summary "Corpus endpoint" :<|> "corpus" :> Summary "Corpus endpoint"
:> Capture "node1_id" NodeId :> Capture "node1_id" NodeId
:> "document" :> "document"
:> Capture "node2_id" NodeId :> Capture "node2_id" NodeId
:> NodeNodeAPI HyperdataAny :> NodeNodeAPI HyperdataAny
:<|> "corpus" :> Capture "node_id" CorpusId :<|> "corpus" :> Capture "node_id" CorpusId
:> Export.API :> Export.API
-- Annuaire endpoint -- Annuaire endpoint
:<|> "annuaire":> Summary "Annuaire endpoint" :<|> "annuaire" :> Summary "Annuaire endpoint"
:> Capture "annuaire_id" AnnuaireId :> Capture "annuaire_id" AnnuaireId
:> NodeAPI HyperdataAnnuaire :> NodeAPI HyperdataAnnuaire
:<|> "annuaire" :> Summary "Contact endpoint" :<|> "annuaire" :> Summary "Contact endpoint"
:> Capture "annuaire_id" NodeId :> Capture "annuaire_id" NodeId
:> "contact" :> Capture "contact_id" NodeId :> "contact"
:> Capture "contact_id" NodeId
:> NodeNodeAPI HyperdataContact :> NodeNodeAPI HyperdataContact
-- Document endpoint -- Document endpoint
:<|> "document":> Summary "Document endpoint" :<|> "document" :> Summary "Document endpoint"
:> Capture "doc_id" DocId :> Capture "doc_id" DocId
:> "ngrams" :> TableNgramsApi :> "ngrams" :> TableNgramsApi
-- :<|> "counts" :> Stream GET NewLineFraming '[JSON] Count :> CountAPI -- :<|> "counts" :> Stream GET NewLineFraming '[JSON] Count :> CountAPI
-- TODO-SECURITY -- TODO-SECURITY
:<|> "count" :> Summary "Count endpoint" :<|> "count" :> Summary "Count endpoint"
:> ReqBody '[JSON] Query :> CountAPI :> ReqBody '[JSON] Query
:> CountAPI
-- Corpus endpoint --> TODO rename s/search/filter/g -- Corpus endpoint --> TODO rename s/search/filter/g
:<|> "search":> Capture "corpus" NodeId :<|> "search" :> Capture "corpus" NodeId
:> SearchPairsAPI :> SearchPairsAPI
-- TODO move to NodeAPI? -- TODO move to NodeAPI?
:<|> "graph" :> Summary "Graph endpoint" :<|> "graph" :> Summary "Graph endpoint"
:> Capture "graph_id" NodeId :> Capture "graph_id" NodeId
:> GraphAPI :> GraphAPI
-- TODO move to NodeAPI? -- TODO move to NodeAPI?
-- Tree endpoint -- Tree endpoint
:<|> "tree" :> Summary "Tree endpoint" :<|> "tree" :> Summary "Tree endpoint"
:> Capture "tree_id" NodeId :> Capture "tree_id" NodeId
:> TreeAPI :> TreeAPI
-- :<|> New.Upload -- :<|> New.Upload
:<|> New.AddWithForm :<|> New.AddWithForm
...@@ -296,13 +298,13 @@ type GargPrivateAPI' = ...@@ -296,13 +298,13 @@ type GargPrivateAPI' =
-- :<|> "scraper" :> WithCallbacks ScraperAPI -- :<|> "scraper" :> WithCallbacks ScraperAPI
-- :<|> "new" :> New.Api -- :<|> "new" :> New.Api
:<|> "lists" :> Summary "List export API" :<|> "lists" :> Summary "List export API"
:> Capture "listId" ListId :> Capture "listId" ListId
:> List.API :> List.API
:<|> "wait" :> Summary "Wait test" :<|> "wait" :> Summary "Wait test"
:> Capture "x" Int :> Capture "x" Int
:> WaitAPI -- Get '[JSON] Int :> WaitAPI -- Get '[JSON] Int
-- /mv/<id>/<id> -- /mv/<id>/<id>
-- /merge/<id>/<id> -- /merge/<id>/<id>
...@@ -470,7 +472,7 @@ type Desc t n = Description (AppendSymbol (TypeName t) (AppendSymbol " | " n)) ...@@ -470,7 +472,7 @@ type Desc t n = Description (AppendSymbol (TypeName t) (AppendSymbol " | " n))
swaggerDoc :: Swagger swaggerDoc :: Swagger
swaggerDoc = toSwagger (Proxy :: Proxy GargAPI) swaggerDoc = toSwagger (Proxy :: Proxy GargAPI)
& info.title .~ "Gargantext" & info.title .~ "Gargantext"
& info.version .~ "4.0.2" -- TODO same version as Gargantext & info.version .~ "0.0.1.3.1" -- TODO same version as Gargantext
-- & info.base_url ?~ (URL "http://gargantext.org/") -- & info.base_url ?~ (URL "http://gargantext.org/")
& info.description ?~ "REST API specifications" & info.description ?~ "REST API specifications"
-- & tags .~ Set.fromList [Tag "Garg" (Just "Main perations") Nothing] -- & tags .~ Set.fromList [Tag "Garg" (Just "Main perations") Nothing]
......
...@@ -78,10 +78,15 @@ instance Arbitrary Query where ...@@ -78,10 +78,15 @@ instance Arbitrary Query where
instance ToSchema Query where instance ToSchema Query where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "query_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "query_")
type Api = Summary "New Corpus endpoint" ------------------------------------------------------------------------
:> ReqBody '[JSON] Query
:> Post '[JSON] CorpusId type Api = PostApi
:<|> Get '[JSON] ApiInfo :<|> GetApi
type PostApi = Summary "New Corpus endpoint"
:> ReqBody '[JSON] Query
:> Post '[JSON] CorpusId
type GetApi = Get '[JSON] ApiInfo
-- | TODO manage several apis -- | TODO manage several apis
-- TODO-ACCESS -- TODO-ACCESS
......
...@@ -171,14 +171,14 @@ instance FromHttpApiData TabType ...@@ -171,14 +171,14 @@ instance FromHttpApiData TabType
parseUrlPiece "Trash" = pure Trash parseUrlPiece "Trash" = pure Trash
parseUrlPiece "MoreFav" = pure MoreFav parseUrlPiece "MoreFav" = pure MoreFav
parseUrlPiece "MoreTrash" = pure MoreTrash parseUrlPiece "MoreTrash" = pure MoreTrash
parseUrlPiece "Terms" = pure Terms parseUrlPiece "Terms" = pure Terms
parseUrlPiece "Sources" = pure Sources parseUrlPiece "Sources" = pure Sources
parseUrlPiece "Institutes" = pure Institutes parseUrlPiece "Institutes" = pure Institutes
parseUrlPiece "Authors" = pure Authors parseUrlPiece "Authors" = pure Authors
parseUrlPiece "Contacts" = pure Contacts parseUrlPiece "Contacts" = pure Contacts
parseUrlPiece _ = Left "Unexpected value of TabType" parseUrlPiece _ = Left "Unexpected value of TabType"
instance ToParamSchema TabType instance ToParamSchema TabType
......
...@@ -15,6 +15,8 @@ Portability : POSIX ...@@ -15,6 +15,8 @@ Portability : POSIX
module Gargantext.Viz.Graph.Tools module Gargantext.Viz.Graph.Tools
where where
import Control.Monad.IO.Class (liftIO)
import Control.Concurrent (newEmptyMVar, takeMVar, putMVar, forkIO)
import Debug.Trace (trace) import Debug.Trace (trace)
import Data.Graph.Clustering.Louvain.CplusPlus (LouvainNode(..)) import Data.Graph.Clustering.Louvain.CplusPlus (LouvainNode(..))
import Data.Graph.Clustering.Louvain.CplusPlus (cLouvain) import Data.Graph.Clustering.Louvain.CplusPlus (cLouvain)
...@@ -68,11 +70,14 @@ cooc2graph threshold myCooc = do ...@@ -68,11 +70,14 @@ cooc2graph threshold myCooc = do
n' = Set.size $ Set.fromList $ as <> bs n' = Set.size $ Set.fromList $ as <> bs
ClustersParams rivers level = {-trace ("nodesApprox: " <> show nodesApprox) $-} clustersParams nodesApprox ClustersParams rivers level = {-trace ("nodesApprox: " <> show nodesApprox) $-} clustersParams nodesApprox
partitionsV <- liftIO newEmptyMVar
partitions <- case Map.size distanceMap > 0 of partitions' <- case Map.size distanceMap > 0 of
True -> trace ("level" <> show level) $ cLouvain level distanceMap True -> trace ("level" <> show level) $ cLouvain level distanceMap
False -> panic "Text.Flow: DistanceMap is empty" False -> panic "Text.Flow: DistanceMap is empty"
_ <- liftIO $ forkIO $ putMVar partitionsV partitions'
partitions <- liftIO $ takeMVar partitionsV
let bridgeness' = {-trace ("rivers: " <> show rivers) $-} let bridgeness' = {-trace ("rivers: " <> show rivers) $-}
bridgeness rivers partitions distanceMap bridgeness rivers partitions distanceMap
......
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