2 Module : .Gargantext.Types.Main
3 Description : Short description
4 Copyright : (c) CNRS, 2017
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
13 {-# LANGUAGE FlexibleInstances #-}
14 {-# LANGUAGE DeriveGeneric #-}
16 module Gargantext.Types.Main where
21 import Data.Monoid ((<>))
22 import Protolude (fromMaybe)
26 import Data.Text (unpack)
27 import Text.Read (read)
28 import Data.Either (Either(Right))
29 --import Data.ByteString (ByteString())
30 import Data.Text (Text)
31 import Data.Time (UTCTime)
32 import Data.List (lookup)
33 import Gargantext.Types.Node ( NodePoly, HyperdataUser
34 , HyperdataFolder , HyperdataCorpus , HyperdataDocument
35 , HyperdataFavorites, HyperdataResource
36 , HyperdataList , HyperdataScore
43 -- | Language of a Text
44 -- For simplicity, we suppose text has an homogenous language
45 data Language = EN | FR -- | DE | IT | SP
48 -- > DE == deutch (not implemented yet)
49 -- > IT == italian (not implemented yet)
50 -- > SP == spanish (not implemented yet)
51 -- > ... add your language and help us to implement it (:
54 -- All the Database is structred like a hierarchical Tree
55 data Tree a = NodeT a [Tree a]
56 deriving (Show, Read, Eq)
59 -- data Tree a = NodeT a [Tree a]
64 -- Garg Network is a network of all Garg nodes
65 --gargNetwork = undefined
67 -- | Garg Node is Database Schema Typed as specification
68 -- gargNode gathers all the Nodes of all users on one Node
69 gargNode :: [Tree NodeType]
72 -- | User Tree simplified
73 userTree :: Tree NodeType
74 userTree = NodeT NodeUser [projectTree]
77 projectTree :: Tree NodeType
78 projectTree = NodeT Project [corpusTree]
81 corpusTree :: Tree NodeType
82 corpusTree = NodeT Corpus ( [ leafT Document ]
85 <> [ leafT Classification]
88 -- TODO make instances of Nodes
90 -- * why NodeUser and not just User ?
91 -- * is this supposed to hold data ?
92 data NodeType = NodeUser | Project | Corpus | Document | DocumentCopy
95 | Metrics | Occurrences
96 deriving (Show, Read, Eq, Generic)
98 instance FromJSON NodeType
99 instance ToJSON NodeType
100 instance FromHttpApiData NodeType where parseUrlPiece = Right . read . unpack
102 data Classification = Favorites | MyClassifcation
104 data Lists = StopList | MainList | MapList | GroupList
106 -- data Metrics = Occurrences | Cooccurrences | Specclusion | Genclusion | Cvalue
107 -- | TfidfCorpus | TfidfGlobal | TirankLocal | TirankGlobal
111 -- | NodePoly indicates that Node has a Polymorphism Type
112 type Node json = NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime json -- NodeVector
114 -- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json
115 type NodeTypeId = Int
117 type NodeParentId = Int
118 type NodeUserId = Int
120 --type NodeVector = Vector
122 --type NodeUser = Node HyperdataUser
124 -- | Then a Node can be either a Folder or a Corpus or a Document
125 type NodeUser = Node HyperdataUser
126 type Folder = Node HyperdataFolder
127 type Project = Folder -- NP Node HyperdataProject ?
128 type Corpus = Node HyperdataCorpus
129 type Document = Node HyperdataDocument
131 -- | Community Manager Use Case
132 type Annuaire = Corpus
133 type Individu = Document
135 -- | Favorites Node enable Node categorization
136 type Favorites = Node HyperdataFavorites
138 -- | Favorites Node enable Swap Node with some synonyms for clarity
139 type NodeSwap = Node HyperdataResource
141 -- | Then a Node can be a List which has some synonyms
142 type List = Node HyperdataList
146 type GroupList = List
148 -- | Then a Node can be a Score which has some synonyms
149 type Score = Node HyperdataScore
150 type Occurrences = Score
151 type Cooccurrences = Score
152 type Specclusion = Score
153 type Genclusion = Score
156 ---- TODO All these Tfidf* will be replaced with TFICF
157 type TfidfCorpus = Tficf
158 type TfidfGlobal = Tficf
159 type TirankLocal = Tficf
160 type TirankGlobal = Tficf
162 ---- | Then a Node can be either a Graph or a Phylo or a Notebook
163 type Graph = Node HyperdataGraph
164 type Phylo = Node HyperdataPhylo
165 type Notebook = Node HyperdataNotebook
168 nodeTypes :: [(NodeType, NodeTypeId)]
169 nodeTypes = [ (NodeUser , 1)
181 -- , (Cooccurrences , 9)
183 -- , (Specclusion , 11)
184 -- , (Genclusion , 18)
187 -- , (TfidfCorpus , 13)
188 -- , (TfidfGlobal , 14)
190 -- , (TirankLocal , 16)
191 -- , (TirankGlobal , 17)
194 -- , (Favorites , 15)
198 nodeTypeId :: NodeType -> NodeTypeId
199 nodeTypeId tn = fromMaybe (error $ "Typename " <> show tn <> " does not exist")
200 (lookup tn nodeTypes)
205 -- Temporary types to be removed
206 type Ngrams = (Text, Text, Text)
207 type ErrorMessage = Text
210 type ParentId = NodeId