Commit 137f53bd 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 bcb2bf9f
Pipeline #7403 passed with stages
in 75 minutes and 33 seconds
...@@ -63,12 +63,12 @@ updateNode :: (HasNodeStory env err m ...@@ -63,12 +63,12 @@ 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
markProgress 1 jobHandle markProgress 1 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)
......
...@@ -30,7 +30,7 @@ import Data.Map.Strict qualified as Map ...@@ -30,7 +30,7 @@ import Data.Map.Strict qualified as Map
import Data.Set qualified as Set import Data.Set qualified as Set
import Data.Tuple.Extra qualified as Tuple import Data.Tuple.Extra qualified as Tuple
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(..))
---------------------------------------------------------------------- ----------------------------------------------------------------------
...@@ -122,41 +122,3 @@ filterComsAdvanced m = Map.filter (not . null) $ mapWithKey filter' m ...@@ -122,41 +122,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 (Partitions, bridgeness, nodeId2comId, setNodes2clusterNodes) import Gargantext.Core.Viz.Graph.Bridgeness (bridgeness, nodeId2comId, 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 -> MultiPartite
-> Similarity -> Similarity
-> Threshold -> Threshold
-> Strength -> Strength
-> HashMap (NgramsTerm, NgramsTerm) Int -> HashMap (NgramsTerm, NgramsTerm) Int
-> IO Graph -> IO Graph
cooc2graphWith Spinglass = cooc2graphWith' (spinglass 1) cooc2graphWith bridgenessMethod multi similarity threshold strength myCooc = do
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
-> Similarity
-> Threshold
-> Strength
-> HashMap (NgramsTerm, NgramsTerm) Int
-> IO Graph
cooc2graphWith' _doPartitions 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 spinglass' 1 distanceMap then 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"
...@@ -129,7 +102,6 @@ cooc2graphWith' _doPartitions bridgenessMethod multi similarity threshold streng ...@@ -129,7 +102,6 @@ cooc2graphWith' _doPartitions bridgenessMethod multi similarity threshold streng
pure $ data2graph multi ti diag bridgeness' confluence' (setNodes2clusterNodes partitions) pure $ data2graph multi ti diag bridgeness' confluence' (setNodes2clusterNodes partitions)
-- | A converter from the partition type returned by `spinglass'` -- | A converter from the partition type returned by `spinglass'`
-- to the partition type required by `bridgeness` -- to the partition type required by `bridgeness`
partitionsToClusterNodes :: [Set Int] -> [ClusterNode] partitionsToClusterNodes :: [Set Int] -> [ClusterNode]
...@@ -147,7 +119,6 @@ partitionsToClusterNodes setlist = ...@@ -147,7 +119,6 @@ partitionsToClusterNodes setlist =
-- Turn pairs into `ClusterNode`s -- Turn pairs into `ClusterNode`s
fmap (\(clusterId, nodeId) -> ClusterNode nodeId clusterId) fmap (\(clusterId, nodeId) -> ClusterNode nodeId clusterId)
type Reverse = Bool type Reverse = Bool
doSimilarityMap :: Similarity doSimilarityMap :: Similarity
......
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