]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Viz/Phylo/Aggregates/Cluster.hs
hard core refactoring
[gargantext.git] / src / Gargantext / Viz / Phylo / Aggregates / Cluster.hs
1 {-|
2 Module : Gargantext.Viz.Phylo.Tools
3 Description : Phylomemy Tools to build/manage it
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10
11 -}
12
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE OverloadedStrings #-}
16
17 module Gargantext.Viz.Phylo.Aggregates.Cluster
18 where
19
20 import Data.List (last,head,union,concat,null,nub,(++),init,tail,(!!))
21 import Data.Map (Map,elems,adjust,unionWith,intersectionWith)
22 import Data.Set (Set)
23 import Data.Tuple (fst, snd)
24
25 import Gargantext.Prelude hiding (head)
26 import Gargantext.Viz.Phylo
27 import Gargantext.Viz.Phylo.Tools
28 import Gargantext.Viz.Phylo.BranchMaker
29 import Gargantext.Viz.Phylo.Metrics.Proximity
30 import Gargantext.Viz.Phylo.Metrics.Clustering
31
32 import qualified Data.List as List
33 import qualified Data.Map as Map
34 import qualified Data.Set as Set
35
36
37 -- | To apply a Clustering method to a PhyloGraph
38 graphToClusters :: (Clustering,[Double]) -> PhyloGraph -> [[PhyloGroup]]
39 graphToClusters (clust,param) (nodes,edges) = case clust of
40 Louvain -> undefined
41 RelatedComponents -> relatedComp 0 (head nodes) (tail nodes,edges) [] []
42
43
44 -- | To transform a Phylo into Clusters of PhyloGroups at a given level
45 phyloToClusters :: Level -> (Proximity,[Double]) -> (Clustering,[Double]) -> Phylo -> Map (Date,Date) [[PhyloGroup]]
46 phyloToClusters lvl (prox,param) (clus,param') p = Map.fromList
47 $ zip (getPhyloPeriods p)
48 (map (\prd -> let graph = groupsToGraph (prox,param) (getGroupsWithFilters lvl prd p) p
49 in if null (fst graph)
50 then []
51 else graphToClusters (clus,param') graph)
52 (getPhyloPeriods p))