Config.hs 1.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
{-|
Module      : Gargantext.Database
Description : Tools for Database
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

Target: just import this module and nothing else to work with
Gargantext's database.

13
TODO: configure nodes table in Haskell (Config typenames etc.)
14 15 16 17 18 19 20
-}

{-# LANGUAGE NoImplicitPrelude #-}

module Gargantext.Database.Config
    where

21 22 23 24 25

import Data.Text        (pack)
import Data.Tuple.Extra (swap)
import Data.Maybe       (fromMaybe)
import Data.List        (lookup)
26 27 28 29

import Gargantext.Database.Types.Node
import Gargantext.Prelude

30 31 32
nodeTypeId :: NodeType -> NodeTypeId
nodeTypeId n =
  case n of
33 34 35 36 37 38 39
    NodeUser      -> 1
    NodeFolder    -> 2
    NodeCorpusV3  -> 3
    NodeCorpus    -> 30
    NodeAnnuaire  -> 31
    NodeDocument  -> 4
    NodeContact   -> 41
40 41 42
  --NodeSwap   -> 19

----  Lists
43
    NodeList    -> 5
44

45
----  Scores
46
--    NodeOccurrences -> 10
47 48 49
    NodeGraph       -> 9
    NodeDashboard   -> 5
    NodeChart       -> 51
50 51

--  Cooccurrences -> 9
52
--
53 54 55
--  Specclusion  -> 11
--  Genclusion   -> 18
--  Cvalue       -> 12
56
--
57 58
--  TfidfCorpus  -> 13
--  TfidfGlobal  -> 14
59
--
60 61 62
--  TirankLocal  -> 16
--  TirankGlobal -> 17

63 64
--  Node management
--  NodeFavorites    -> 15
65 66


67
--
68
-- | Nodes are typed in the database according to a specific ID
69
--
70 71
nodeTypeInv :: [(NodeTypeId, NodeType)]
nodeTypeInv = map swap nodeTypes
72

73 74
nodeTypes :: [(NodeType, NodeTypeId)]
nodeTypes = [ (n, nodeTypeId n) | n <- allNodeTypes ]
75

76 77 78
typeId2node :: NodeTypeId -> NodeType
typeId2node tId = fromMaybe (panic $ pack $ "Type Id " <> show tId <> " does not exist")
                            (lookup tId nodeTypeInv)