Commit 16f0bfa0 authored by Grégoire Locqueville's avatar Grégoire Locqueville

Cleanup

Removed some dead code, most notably the `Partition` and `PartitionMathod`
types which were not in actual use anywhere.
Also renamed some function arguments from single-/double-letter identifiers
to actual words.
parent 80085576
Pipeline #7308 passed with stages
in 68 minutes and 19 seconds
...@@ -10,7 +10,6 @@ Portability : POSIX ...@@ -10,7 +10,6 @@ Portability : POSIX
-} -}
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Gargantext.API.Node.Update module Gargantext.API.Node.Update
where where
...@@ -64,11 +63,11 @@ updateNode :: (HasNodeStory env err m ...@@ -64,11 +63,11 @@ updateNode :: (HasNodeStory env err m
-> JobHandle m -> JobHandle m
-> m () -> m ()
updateNode nId (UpdateNodeParamsGraph updateNode nId (UpdateNodeParamsGraph
(UpdateNodeConfigGraph metric partitionMethod bridgeMethod strength nt1 nt2)) jobHandle = do (UpdateNodeConfigGraph metric bridgeMethod strength nt1 nt2)) jobHandle = do
markStarted 2 jobHandle markStarted 2 jobHandle
-- printDebug "Computing graph: " method -- printDebug "Computing graph: " method
_ <- recomputeGraph nId partitionMethod bridgeMethod (Just metric) (Just strength) nt1 nt2 True _ <- recomputeGraph nId bridgeMethod (Just metric) (Just strength) nt1 nt2 True
-- printDebug "Graph computed: " method -- printDebug "Graph computed: " method
markComplete jobHandle markComplete jobHandle
......
...@@ -5,7 +5,6 @@ import Data.Aeson ...@@ -5,7 +5,6 @@ import Data.Aeson
import Data.Swagger ( ToSchema ) import Data.Swagger ( ToSchema )
import Gargantext.Core.Methods.Similarities (GraphMetric(..)) import Gargantext.Core.Methods.Similarities (GraphMetric(..))
import Gargantext.Core.Text.Ngrams (NgramsType) import Gargantext.Core.Text.Ngrams (NgramsType)
import Gargantext.Core.Viz.Graph.Tools (PartitionMethod(..))
import Gargantext.Core.Viz.Graph.Types (BridgenessMethod, Strength) import Gargantext.Core.Viz.Graph.Types (BridgenessMethod, Strength)
import Gargantext.Core.Viz.Phylo (PhyloSubConfigAPI(..)) import Gargantext.Core.Viz.Phylo (PhyloSubConfigAPI(..))
import Gargantext.Database.Admin.Types.Node ( NodeId, NodeType ) import Gargantext.Database.Admin.Types.Node ( NodeId, NodeType )
...@@ -46,7 +45,6 @@ data Charts = Sources | Authors | Institutes | Ngrams | All ...@@ -46,7 +45,6 @@ data Charts = Sources | Authors | Institutes | Ngrams | All
------------------------------------------------------------------------ ------------------------------------------------------------------------
data UpdateNodeConfigGraph = UpdateNodeConfigGraph { methodGraphMetric :: !GraphMetric data UpdateNodeConfigGraph = UpdateNodeConfigGraph { methodGraphMetric :: !GraphMetric
, methodGraphClustering :: !PartitionMethod
, methodGraphBridgeness :: !BridgenessMethod , methodGraphBridgeness :: !BridgenessMethod
, methodGraphEdgesStrength :: !Strength , methodGraphEdgesStrength :: !Strength
, methodGraphNodeType1 :: !NgramsType , methodGraphNodeType1 :: !NgramsType
......
...@@ -71,10 +71,9 @@ getGraph nId = do ...@@ -71,10 +71,9 @@ getGraph nId = do
case graph of case graph of
Nothing -> do Nothing -> do
let defaultMetric = Order1 let defaultMetric = Order1
let defaultPartitionMethod = Spinglass
let defaultEdgesStrength = Strong let defaultEdgesStrength = Strong
let defaultBridgenessMethod = BridgenessBasic let defaultBridgenessMethod = BridgenessBasic
graph' <- computeGraph cId defaultPartitionMethod defaultBridgenessMethod (withMetric defaultMetric) defaultEdgesStrength (NgramsTerms, NgramsTerms) repo graph' <- computeGraph cId defaultBridgenessMethod (withMetric defaultMetric) defaultEdgesStrength (NgramsTerms, NgramsTerms) repo
mt <- defaultGraphMetadata cId listId "Title" repo defaultMetric defaultEdgesStrength mt <- defaultGraphMetadata cId listId "Title" repo defaultMetric defaultEdgesStrength
let mt' = set gm_legend (generateLegend graph') mt let mt' = set gm_legend (generateLegend graph') mt
let let
...@@ -91,7 +90,6 @@ getGraph nId = do ...@@ -91,7 +90,6 @@ getGraph nId = do
--recomputeGraph :: UserId -> NodeId -> Maybe GraphMetric -> GargNoServer Graph --recomputeGraph :: UserId -> NodeId -> Maybe GraphMetric -> GargNoServer Graph
recomputeGraph :: HasNodeStory env err m recomputeGraph :: HasNodeStory env err m
=> NodeId => NodeId
-> PartitionMethod
-> BridgenessMethod -> BridgenessMethod
-> Maybe GraphMetric -> Maybe GraphMetric
-> Maybe Strength -> Maybe Strength
...@@ -99,7 +97,7 @@ recomputeGraph :: HasNodeStory env err m ...@@ -99,7 +97,7 @@ recomputeGraph :: HasNodeStory env err m
-> NgramsType -> NgramsType
-> Bool -> Bool
-> m Graph -> m Graph
recomputeGraph nId partitionMethod bridgeMethod maybeSimilarity maybeStrength nt1 nt2 force' = do recomputeGraph nId bridgeMethod maybeSimilarity maybeStrength nt1 nt2 force' = do
nodeGraph <- getNodeWith nId (Proxy :: Proxy HyperdataGraph) nodeGraph <- getNodeWith nId (Proxy :: Proxy HyperdataGraph)
let let
graph = nodeGraph ^. node_hyperdata . hyperdataGraph graph = nodeGraph ^. node_hyperdata . hyperdataGraph
...@@ -127,7 +125,7 @@ recomputeGraph nId partitionMethod bridgeMethod maybeSimilarity maybeStrength nt ...@@ -127,7 +125,7 @@ recomputeGraph nId partitionMethod bridgeMethod maybeSimilarity maybeStrength nt
let v = repo ^. unNodeStory . at listId . _Just . a_version let v = repo ^. unNodeStory . at listId . _Just . a_version
let computeG mt = do let computeG mt = do
!g <- computeGraph cId partitionMethod bridgeMethod similarity strength (nt1,nt2) repo !g <- computeGraph cId bridgeMethod similarity strength (nt1,nt2) repo
let mt' = set gm_legend (generateLegend g) mt let mt' = set gm_legend (generateLegend g) mt
let g' = set graph_metadata (Just mt') g let g' = set graph_metadata (Just mt') g
_nentries <- updateHyperdata nId (HyperdataGraph (Just g') camera) _nentries <- updateHyperdata nId (HyperdataGraph (Just g') camera)
...@@ -154,14 +152,13 @@ recomputeGraph nId partitionMethod bridgeMethod maybeSimilarity maybeStrength nt ...@@ -154,14 +152,13 @@ recomputeGraph nId partitionMethod bridgeMethod maybeSimilarity maybeStrength nt
-- TODO remove repo -- TODO remove repo
computeGraph :: HasNodeError err computeGraph :: HasNodeError err
=> CorpusId => CorpusId
-> PartitionMethod
-> BridgenessMethod -> BridgenessMethod
-> Similarity -> Similarity
-> Strength -> Strength
-> (NgramsType, NgramsType) -> (NgramsType, NgramsType)
-> NodeListStory -> NodeListStory
-> DBCmd err Graph -> DBCmd err Graph
computeGraph corpusId partitionMethod bridgeMethod similarity strength (nt1,nt2) repo = do computeGraph corpusId bridgeMethod similarity strength (nt1,nt2) repo = do
-- Getting the Node parameters -- Getting the Node parameters
lId <- defaultList corpusId lId <- defaultList corpusId
lIds <- selectNodesWithUsername NodeList userMaster lIds <- selectNodesWithUsername NodeList userMaster
...@@ -190,7 +187,7 @@ computeGraph corpusId partitionMethod bridgeMethod similarity strength (nt1,nt2) ...@@ -190,7 +187,7 @@ computeGraph corpusId partitionMethod bridgeMethod similarity strength (nt1,nt2)
-- TODO MultiPartite Here -- TODO MultiPartite Here
liftBase liftBase
$ cooc2graphWith partitionMethod bridgeMethod (MultiPartite (Partite (HashMap.keysSet m1) nt1) $ cooc2graphWith bridgeMethod (MultiPartite (Partite (HashMap.keysSet m1) nt1)
(Partite (HashMap.keysSet m2) nt2) (Partite (HashMap.keysSet m2) nt2)
) )
similarity 0 strength myCooc similarity 0 strength myCooc
...@@ -239,7 +236,7 @@ graphRecompute :: (HasNodeStory env err m, MonadJobStatus m) ...@@ -239,7 +236,7 @@ graphRecompute :: (HasNodeStory env err m, MonadJobStatus m)
-> m () -> m ()
graphRecompute n jobHandle = do graphRecompute n jobHandle = do
markStarted 1 jobHandle markStarted 1 jobHandle
_g <- recomputeGraph n Spinglass BridgenessBasic Nothing Nothing NgramsTerms NgramsTerms False _g <- recomputeGraph n BridgenessBasic Nothing Nothing NgramsTerms NgramsTerms False
markComplete jobHandle markComplete jobHandle
graphVersions :: (HasNodeStory env err m) graphVersions :: (HasNodeStory env err m)
...@@ -274,7 +271,7 @@ graphVersions u nId = do ...@@ -274,7 +271,7 @@ graphVersions u nId = do
recomputeVersions :: HasNodeStory env err m recomputeVersions :: HasNodeStory env err m
=> NodeId => NodeId
-> m Graph -> m Graph
recomputeVersions nId = recomputeGraph nId Spinglass BridgenessBasic Nothing Nothing NgramsTerms NgramsTerms False recomputeVersions nId = recomputeGraph nId BridgenessBasic Nothing Nothing NgramsTerms NgramsTerms False
------------------------------------------------------------ ------------------------------------------------------------
graphClone :: (HasNodeError err) graphClone :: (HasNodeError err)
......
...@@ -20,8 +20,6 @@ TODO use Map LouvainNodeId (Map LouvainNodeId) ...@@ -20,8 +20,6 @@ TODO use Map LouvainNodeId (Map LouvainNodeId)
{-# OPTIONS_GHC -fno-warn-deprecations #-} {-# OPTIONS_GHC -fno-warn-deprecations #-}
{-# LANGUAGE BangPatterns #-}
module Gargantext.Core.Viz.Graph.Bridgeness -- (bridgeness) module Gargantext.Core.Viz.Graph.Bridgeness -- (bridgeness)
where where
...@@ -33,7 +31,7 @@ import Data.Set qualified as Set ...@@ -33,7 +31,7 @@ import Data.Set qualified as Set
import Data.Tuple.Extra qualified as Tuple import Data.Tuple.Extra qualified as Tuple
import Gargantext.Core.Methods.Similarities (Similarity(..)) import Gargantext.Core.Methods.Similarities (Similarity(..))
import Gargantext.Core.Viz.Graph.Types (BridgenessMethod(..)) import Gargantext.Core.Viz.Graph.Types (BridgenessMethod(..))
import Gargantext.Prelude hiding (toList) import Gargantext.Prelude hiding (toList, filter)
import Graph.Types (ClusterNode(..)) import Graph.Types (ClusterNode(..))
---------------------------------------------------------------------- ----------------------------------------------------------------------
...@@ -113,13 +111,20 @@ bridgeness :: [[Set NodeId]] ...@@ -113,13 +111,20 @@ bridgeness :: [[Set NodeId]]
-> Similarity -> Similarity
-> Map (NodeId, NodeId) Double -> Map (NodeId, NodeId) Double
-> Map (NodeId, NodeId) Double -> Map (NodeId, NodeId) Double
bridgeness sn method f sim m = bridgeness partitions method filter similarity m =
Map.unions $ [linksBetween] <> map (\s -> baseBridgeness (setNodes2clusterNodes s) method (if sim == Conditional then pi*f else f) m') sn Map.unions $ [linksBetween] <>
map (\s -> baseBridgeness
(setNodes2clusterNodes s)
method
(if similarity == Conditional then pi*filter
else filter)
m'
) partitions
where where
(linksBetween, m') = Map.partitionWithKey (\(n1,n2) _v -> Map.lookup n1 mapNodeIdClusterId (linksBetween, m') = Map.partitionWithKey (\(n1,n2) _v -> Map.lookup n1 mapNodeIdClusterId
/= Map.lookup n2 mapNodeIdClusterId /= Map.lookup n2 mapNodeIdClusterId
) $ baseBridgeness clusters method f m ) $ baseBridgeness clusters method filter m
clusters = setNodes2clusterNodes (map Set.unions sn) clusters = setNodes2clusterNodes (map Set.unions partitions)
mapNodeIdClusterId = clusterNodes2map clusters mapNodeIdClusterId = clusterNodes2map clusters
baseBridgeness :: [ClusterNode] baseBridgeness :: [ClusterNode]
...@@ -127,14 +132,14 @@ baseBridgeness :: [ClusterNode] ...@@ -127,14 +132,14 @@ baseBridgeness :: [ClusterNode]
-> Double -> Double
-> Map (NodeId, NodeId) Double -> Map (NodeId, NodeId) Double
-> Map (NodeId, NodeId) Double -> Map (NodeId, NodeId) Double
baseBridgeness ns method b m = Map.fromList baseBridgeness partitions method filter m = Map.fromList
$ List.concat $ List.concat
$ Map.elems $ Map.elems
$ (case method of $ (case method of
BridgenessBasic -> filterComs (round b) BridgenessBasic -> filterComs (round filter)
BridgenessAdvanced -> filterComsAdvanced BridgenessAdvanced -> filterComsAdvanced
) )
$ groupEdges (Map.fromList $ map nodeId2comId ns) m $ groupEdges (Map.fromList $ map nodeId2comId partitions) m
groupEdges :: (Ord comId, Ord nodeId) groupEdges :: (Ord comId, Ord nodeId)
...@@ -179,41 +184,3 @@ filterComsAdvanced m = Map.filter (not . null) $ mapWithKey filter' m ...@@ -179,41 +184,3 @@ filterComsAdvanced m = Map.filter (not . null) $ mapWithKey filter' m
filter' (c1,c2) xs filter' (c1,c2) xs
| c1 == c2 = xs | c1 == c2 = xs
| otherwise = List.filter (\(_nn,v) -> v >= threshold) xs | otherwise = List.filter (\(_nn,v) -> v >= threshold) xs
--------------------------------------------------------------
-- Utils
{--
map2intMap :: Map (Int, Int) a -> IntMap (IntMap a)
map2intMap m = IntMap.fromListWith (<>)
$ map (\((k1,k2), v) -> if k1 < k2
then (k1, IntMap.singleton k2 v)
else (k2, IntMap.singleton k1 v)
)
$ Map.toList m
look :: (Int,Int) -> IntMap (IntMap a) -> Maybe a
look (k1,k2) m = if k1 < k2
then case (IntMap.lookup k1 m) of
Just m' -> IntMap.lookup k2 m'
_ -> Nothing
else look (k2,k1) m
{-
Compute the median of a list
From: https://hackage.haskell.org/package/dsp-0.2.5.1/docs/src/Numeric.Statistics.Median.html
Compute the center of the list in a more lazy manner
and thus halves memory requirement.
-}
median :: (Ord a, Fractional a) => [a] -> a
median [] = panic "medianFast: empty list has no median"
median zs =
let recurse (x0:_) (_:[]) = x0
recurse (x0:x1:_) (_:_:[]) = (x0+x1)/2
recurse (_:xs) (_:_:ys) = recurse xs ys
recurse _ _ =
panic "median: this error cannot occur in the way 'recurse' is called"
in recurse zs zs
-}
...@@ -23,17 +23,15 @@ import Data.HashSet qualified as HashSet ...@@ -23,17 +23,15 @@ import Data.HashSet qualified as HashSet
import Data.List qualified as List import Data.List qualified as List
import Data.Map.Strict qualified as Map import Data.Map.Strict qualified as Map
import Data.Set qualified as Set import Data.Set qualified as Set
import Data.Swagger ( ToSchema )
import Data.Text qualified as Text import Data.Text qualified as Text
import Data.Vector.Storable qualified as Vec import Data.Vector.Storable qualified as Vec
import Gargantext.API.Ngrams.Types (NgramsTerm(..)) import Gargantext.API.Ngrams.Types (NgramsTerm(..))
import Gargantext.Core.Methods.Similarities (Similarity(..), measure) import Gargantext.Core.Methods.Similarities (Similarity(..), measure)
import Gargantext.Core.Statistics ( pcaReduceTo, Dimension(Dimension) ) import Gargantext.Core.Statistics ( pcaReduceTo, Dimension(Dimension) )
import Gargantext.Core.Text.Ngrams (NgramsType(..)) import Gargantext.Core.Text.Ngrams (NgramsType(..))
import Gargantext.Core.Viz.Graph.Bridgeness (bridgeness, Partitions, nodeId2comId, {-recursiveClustering,-} recursiveClustering', setNodes2clusterNodes) import Gargantext.Core.Viz.Graph.Bridgeness (bridgeness, nodeId2comId, {-recursiveClustering,-} recursiveClustering', setNodes2clusterNodes)
import Gargantext.Core.Viz.Graph.Index (createIndices, toIndex, map2mat, mat2map, Index, MatrixShape(..)) import Gargantext.Core.Viz.Graph.Index (createIndices, toIndex, map2mat, mat2map, Index, MatrixShape(..))
import Gargantext.Core.Viz.Graph.Tools.IGraph (mkGraphUfromEdges, spinglass, spinglass') import Gargantext.Core.Viz.Graph.Tools.IGraph (mkGraphUfromEdges, spinglass, spinglass')
import Gargantext.Core.Viz.Graph.Tools.Infomap (infomap)
import Gargantext.Core.Viz.Graph.Types (Attributes(..), BridgenessMethod, Edge(..), Graph(..), MultiPartite(..), Node(..), Partite(..), Strength(..), LegendField(..)) import Gargantext.Core.Viz.Graph.Types (Attributes(..), BridgenessMethod, Edge(..), Graph(..), MultiPartite(..), Node(..), Partite(..), Strength(..), LegendField(..))
import Gargantext.Core.Viz.Graph.Utils (edgesFilter, nodesFilter) import Gargantext.Core.Viz.Graph.Utils (edgesFilter, nodesFilter)
import Gargantext.Prelude import Gargantext.Prelude
...@@ -42,16 +40,6 @@ import Graph.Types (ClusterNode) ...@@ -42,16 +40,6 @@ import Graph.Types (ClusterNode)
import IGraph qualified as Igraph import IGraph qualified as Igraph
import IGraph.Algorithms.Layout qualified as Layout import IGraph.Algorithms.Layout qualified as Layout
import IGraph.Random ( Gen ) -- (Gen(..)) import IGraph.Random ( Gen ) -- (Gen(..))
import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary ( Arbitrary(arbitrary) )
data PartitionMethod = Spinglass | Confluence | Infomap
deriving (Generic, Eq, Ord, Enum, Bounded, Show)
instance FromJSON PartitionMethod
instance ToJSON PartitionMethod
instance ToSchema PartitionMethod
instance Arbitrary PartitionMethod where
arbitrary = elements [ minBound .. maxBound ]
------------------------------------------------------------- -------------------------------------------------------------
...@@ -82,33 +70,18 @@ cooc2graph' distance threshold myCooc ...@@ -82,33 +70,18 @@ cooc2graph' distance threshold myCooc
-- coocurrences graph computation -- coocurrences graph computation
cooc2graphWith :: PartitionMethod cooc2graphWith :: BridgenessMethod
-> BridgenessMethod
-> MultiPartite
-> Similarity
-> Threshold
-> Strength
-> HashMap (NgramsTerm, NgramsTerm) Int
-> IO Graph
cooc2graphWith Spinglass = cooc2graphWith' (spinglass 1)
cooc2graphWith Confluence= cooc2graphWith' (\x -> pure $ BAC.defaultClustering x)
cooc2graphWith Infomap = cooc2graphWith' (infomap "-v -N2")
--cooc2graphWith Infomap = cooc2graphWith' (infomap "--silent --two-level -N2")
-- TODO: change these options, or make them configurable in UI?
cooc2graphWith' :: Partitions
-> BridgenessMethod
-> MultiPartite -> MultiPartite
-> Similarity -> Similarity
-> Threshold -> Threshold
-> Strength -> Strength
-> HashMap (NgramsTerm, NgramsTerm) Int -> HashMap (NgramsTerm, NgramsTerm) Int
-> IO Graph -> IO Graph
cooc2graphWith' _doPartitions bridgenessMethod multi similarity threshold strength myCooc = do cooc2graphWith bridgenessMethod multi similarity threshold strength myCooc = do
let (distanceMap, diag, ti) = doSimilarityMap similarity threshold strength myCooc let (distanceMap, diag, ti) = doSimilarityMap similarity threshold strength myCooc
distanceMap `seq` diag `seq` ti `seq` pure () distanceMap `seq` diag `seq` ti `seq` pure ()
partitions <- if (Map.size distanceMap > 0) partitions <- if Map.size distanceMap > 0
then recursiveClustering' (spinglass' 1) distanceMap then recursiveClustering' (spinglass' 1) distanceMap
else panic $ Text.unwords [ "I can not compute the graph you request" else panic $ Text.unwords [ "I can not compute the graph you request"
, "because either the quantity of documents" , "because either the quantity of documents"
...@@ -126,27 +99,6 @@ cooc2graphWith' _doPartitions bridgenessMethod multi similarity threshold streng ...@@ -126,27 +99,6 @@ cooc2graphWith' _doPartitions bridgenessMethod multi similarity threshold streng
pure $ data2graph multi ti diag bridgeness' confluence' (setNodes2clusterNodes $ List.concat partitions) pure $ data2graph multi ti diag bridgeness' confluence' (setNodes2clusterNodes $ List.concat partitions)
{-
cooc2graphWith' _doPartitions _bridgenessMethod multi similarity@Distributional threshold strength myCooc = do
let (distanceMap, diag, ti) = doSimilarityMap similarity threshold strength myCooc
distanceMap `seq` diag `seq` ti `seq` pure ()
partitions <- if (Map.size distanceMap > 0)
then recursiveClustering (spinglass 1) distanceMap
else panic $ Text.unlines [ "[Gargantext.C.V.Graph.Tools] Similarity Matrix is empty"
, "Maybe you should add more Map Terms in your list"
, "Tutorial: TODO"
]
length partitions `seq` pure ()
let
!confluence' = BAC.computeConfluences 3 (Map.keys distanceMap) True
!bridgeness' = bridgeness (Bridgeness_Basic partitions 1.0) distanceMap
pure $ data2graph multi ti diag bridgeness' confluence' partitions
-}
type Reverse = Bool type Reverse = Bool
......
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