Commit 0db18836 authored by Grégoire Locqueville's avatar Grégoire Locqueville

Clarification of some functions' role

The `filterNodes` function's name and type signature were confusing, so
they were changed to make it evident that the filtering function for an
antry is applied to its total number of cooccurrences.
parent 612e9aad
......@@ -138,11 +138,11 @@ occurrences = occurrencesOn _terms_stem
-- Note: Compared to `occurences`, this is the more elementary function, maybe
-- it would make more sense to rename this one into `occurences` and the other
-- into something more descriptive
countOccurrences :: (Foldable f, Ord a, Num n)
=> f a -- ^ The collection whose items will be counted
-> Map a n -- ^ A map whose keys are items of the input
-- collection, and whose values are the number of
-- times those items appear in the input collection
countOccurrences :: (Foldable f, Ord a)
=> f a -- ^ The collection whose items will be counted
-> Map a Int -- ^ A map whose keys are items of the input
-- collection, and whose values are the number of
-- times those items appear in the input collection
countOccurrences collection =
foldl' (\occurenceMap item -> insertWith (+) item 1 occurenceMap)
empty
......
......@@ -33,7 +33,7 @@ import Gargantext.Core.Viz.Graph.Bridgeness (bridgeness, nodeId2comId, setNodes2
import Gargantext.Core.Viz.Graph.Index (createIndices, toIndex, map2mat, mat2map, Index, MatrixShape(..))
import Gargantext.Core.Viz.Graph.Tools.IGraph (mkGraphUfromEdges, spinglass)
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, filterNodesByCount)
import Gargantext.Prelude
import Graph.BAC.ProxemyOptim qualified as BAC
import Graph.Types (ClusterNode(..))
......@@ -189,7 +189,7 @@ data2graph multi labels' occurences bridge conf partitions =
]
-- Remove vertices not connected to any other node, i.e. vertices that have
-- zero edge joining them to other vertices
(bridge', toKeep) = nodesFilter (> 0) bridge
(bridge', toKeep) = filterNodesByCount (> 0) bridge
edges = [ Edge { edge_source = show s
, edge_hidden = Nothing
......
......@@ -81,8 +81,17 @@ edgesFilter m = Map.fromList $ catMaybes results
keys = Set.toList $ Set.fromList (x <> y)
(x,y) = unzip $ Map.keys m
nodesFilter :: (Show a, Show b, Ord a, Ord b, Num b) => (b -> Bool) -> Map (a,a) b -> (Map (a,a) b, Set a)
nodesFilter f m = (m', toKeep)
-- | Filter nodes depending on how many times they (co)occur.
-- More specifically, for a given value `x :: a`, this sums all entries in the
-- map that have `x` as a value, and then it filters by applying `f` to the sum.
-- Warning: This counts the value at `(x, x)` twice.
filterNodesByCount :: (Show node, Ord node)
=> (Int -> Bool) -- ^ Filtering function
-> Map (node, node) b -- ^ Input map
-> (Map (node, node) b, Set node)
-- ^ The map without the filtered out nodes, and the set of
-- remaining nodes
filterNodesByCount f m = (m', toKeep)
where
m' = Map.filterWithKey (\(a,b) _ -> Set.member a toKeep && Set.member b toKeep) m
toKeep = Set.fromList
......
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