]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Viz/Graph/IGraph.hs
Merge branch 'dev' into dev-phylo
[gargantext.git] / src / Gargantext / Viz / Graph / IGraph.hs
1 {-| Module : Gargantext.Viz.Graph.IGraph
2 Description : IGraph main functions used in Garg
3 Copyright : (c) CNRS, 2017-Present
4 License : AGPL + CECILL v3
5 Maintainer : team@gargantext.org
6 Stability : experimental
7 Portability : POSIX
8
9 Main IGraph funs/types to ease portability with FGL.
10
11 -}
12
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE DataKinds #-}
15
16 module Gargantext.Viz.Graph.IGraph where
17
18 import Data.Serialize (Serialize)
19 import Data.Singletons (SingI)
20 import Gargantext.Prelude
21 import IGraph hiding (mkGraph, neighbors, edges, nodes, Node, Graph)
22 import IGraph.Algorithms.Clique as IAC
23 import qualified IGraph as IG
24 import qualified Data.List as List
25
26 ------------------------------------------------------------------
27 -- | Main Types
28 type Graph_Undirected = IG.Graph 'U () ()
29 type Graph_Directed = IG.Graph 'D () ()
30
31 type Node = IG.Node
32 type Graph = IG.Graph
33
34 ------------------------------------------------------------------
35 -- | Main Functions
36
37 mkGraph :: (SingI d, Ord v,
38 Serialize v, Serialize e) =>
39 [v] -> [LEdge e] -> IG.Graph d v e
40 mkGraph = IG.mkGraph
41
42 neighbors :: IG.Graph d v e -> IG.Node -> [Node]
43 neighbors = IG.neighbors
44
45 edges :: IG.Graph d v e -> [Edge]
46 edges = IG.edges
47
48 nodes :: IG.Graph d v e -> [Node]
49 nodes = IG.nodes
50 ------------------------------------------------------------------
51
52 -- | Tools
53 maximalCliques :: IG.Graph d v e -> [[Int]]
54 maximalCliques g = IAC.maximalCliques g (min',max')
55 where
56 min' = 0
57 max' = 0
58
59 ------------------------------------------------------------------
60 -- | Main sugared functions
61 mkGraphUfromEdges :: [(Int, Int)] -> Graph_Undirected
62 mkGraphUfromEdges es = mkGraph (List.replicate n ()) $ zip es $ repeat ()
63 where
64 (a,b) = List.unzip es
65 n = List.length (List.nub $ a <> b)
66
67 mkGraphDfromEdges :: [(Int, Int)] -> Graph_Directed
68 mkGraphDfromEdges = undefined
69
70