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
13 {-# OPTIONS_GHC -fno-warn-orphans #-}
15 {-# LANGUAGE RankNTypes #-}
16 {-# LANGUAGE NoImplicitPrelude #-}
17 {-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals
18 {-# LANGUAGE OverloadedLists #-} -- allows to write Map and HashMap as lists
19 {-# LANGUAGE DataKinds #-}
21 module Gargantext.Viz.Graph.API
24 import Control.Monad.IO.Class (liftIO)
25 import Control.Lens (set)
26 --import Servant.Job.Utils (swaggerOptions)
27 import Gargantext.Database.Schema.Ngrams
28 import Gargantext.API.Types
29 import Gargantext.Database.Metrics.NgramsByNode (getNodesByNgramsOnlyUser)
30 import Gargantext.Database.Schema.Node ( getNode)
31 import Gargantext.Database.Types.Node -- (GraphId, ListId, CorpusId, NodeId)
32 import Gargantext.Prelude
33 import Gargantext.API.Ngrams.Tools
34 import Gargantext.Core.Types.Main
35 import Gargantext.Viz.Graph.Tools -- (cooc2graph)
36 import Gargantext.Database.Schema.Node (defaultList)
37 import Gargantext.Viz.Graph
39 import qualified Data.Map as Map
42 getgraph :: GraphId -> GraphView
43 getgraph _GraphId = phyloView
44 --getgraph :: GraphId -> Maybe PhyloQueryView -> PhyloView
45 --getgraph _GraphId _phyloQueryView = phyloView
47 postgraph :: CorpusId -> Maybe ListId -> GraphQueryBuild -> Phylo
50 putgraph :: GraphId -> Maybe ListId -> PhyloQueryBuild -> Phylo
54 type GraphAPI = Get '[JSON] Graph
56 graphAPI :: NodeId -> GargServer GraphAPI
58 nodeGraph <- getNode nId HyperdataGraph
60 let metadata = GraphMetadata "Title" [maybe 0 identity $ _node_parentId nodeGraph]
61 [ LegendField 1 "#FFF" "Cluster"
62 , LegendField 2 "#FFF" "Cluster"
64 -- (map (\n -> LegendField n "#FFFFFF" (pack $ show n)) [1..10])
65 let cId = maybe (panic "no parentId") identity $ _node_parentId nodeGraph
67 lId <- defaultList cId
68 ngs <- filterListWithRoot GraphTerm <$> mapTermListRoot [lId] NgramsTerms
70 myCooc <- Map.filter (>1) <$> getCoocByNgrams (Diagonal False)
71 <$> groupNodesByNgrams ngs
72 <$> getNodesByNgramsOnlyUser cId NgramsTerms (Map.keys ngs)
74 liftIO $ set graph_metadata (Just metadata) <$> cooc2graph myCooc