]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Types/Main.hs
[TEXT] String to Text in Servant file.
[gargantext.git] / src / Gargantext / Types / Main.hs
1 {-|
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
8 Portability : POSIX
9
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
12 -}
13 {-# LANGUAGE FlexibleInstances #-}
14
15 module Gargantext.Types.Main where
16
17 import Prelude
18
19 import Data.Eq (Eq())
20 import Data.Monoid ((<>))
21 import Protolude (fromMaybe)
22
23 --import Data.ByteString (ByteString())
24 import Data.Text (Text)
25 import Data.Time (UTCTime)
26 import Data.List (lookup)
27 import Gargantext.Types.Node ( NodePoly, HyperdataUser
28 , HyperdataFolder , HyperdataCorpus , HyperdataDocument
29 , HyperdataFavorites, HyperdataResource
30 , HyperdataList , HyperdataScore
31 , HyperdataGraph
32 , HyperdataPhylo
33 , HyperdataNotebook
34 )
35
36
37 -- | Language of a Text
38 -- For simplicity, we suppose text has an homogenous language
39 data Language = EN | FR -- | DE | IT | SP
40 -- > EN == english
41 -- > FR == french
42 -- > DE == deutch (not implemented yet)
43 -- > IT == italian (not implemented yet)
44 -- > SP == spanish (not implemented yet)
45 -- > ... add your language and help us to implement it (:
46
47
48 -- All the Database is structred like a hierarchical Tree
49 data Tree a = NodeT a [Tree a]
50 deriving (Show, Read, Eq)
51
52
53 -- data Tree a = NodeT a [Tree a]
54 -- same as Data.Tree
55 leafT :: a -> Tree a
56 leafT x = NodeT x []
57
58 -- Garg Network is a network of all Garg nodes
59 --gargNetwork = undefined
60
61 -- | Garg Node is Database Schema Typed as specification
62 -- gargNode gathers all the Nodes of all users on one Node
63 gargNode :: [Tree NodeType]
64 gargNode = [userTree]
65
66 -- | User Tree simplified
67 userTree :: Tree NodeType
68 userTree = NodeT NodeUser [projectTree]
69
70 -- | Project Tree
71 projectTree :: Tree NodeType
72 projectTree = NodeT Project [corpusTree]
73
74 -- | Corpus Tree
75 corpusTree :: Tree NodeType
76 corpusTree = NodeT Corpus ( [ leafT Document ]
77 <> [ leafT Lists ]
78 <> [ leafT Metrics ]
79 <> [ leafT Classification]
80 )
81
82 -- TODO make instances of Nodes
83 -- NP
84 -- * why NodeUser and not just User ?
85 -- * is this supposed to hold data ?
86 data NodeType = NodeUser | Project | Corpus | Document | DocumentCopy
87 | Classification
88 | Lists
89 | Metrics
90 deriving (Show, Read, Eq)
91
92 data Classification = Favorites | MyClassifcation
93
94 data Lists = StopList | MainList | MapList | GroupList
95
96 data Metrics = Occurrences | Cooccurrences | Specclusion | Genclusion | Cvalue
97 | TfidfCorpus | TfidfGlobal | TirankLocal | TirankGlobal
98
99
100
101 -- | NodePoly indicates that Node has a Polymorphism Type
102 type Node json = NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime json -- NodeVector
103 -- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json
104 type NodeTypeId = Int
105 type NodeId = Int
106 type NodeParentId = Int
107 type NodeUserId = Int
108 type NodeName = Text
109 --type NodeVector = Vector
110
111 --type NodeUser = Node HyperdataUser
112
113 -- | Then a Node can be either a Folder or a Corpus or a Document
114 type NodeUser = Node HyperdataUser
115 type Folder = Node HyperdataFolder
116 type Project = Folder -- NP Node HyperdataProject ?
117 type Corpus = Node HyperdataCorpus
118 type Document = Node HyperdataDocument
119
120 -- | Community Manager Use Case
121 type Annuaire = Corpus
122 type Individu = Document
123
124 -- | Favorites Node enable Node categorization
125 type Favorites = Node HyperdataFavorites
126
127 -- | Favorites Node enable Swap Node with some synonyms for clarity
128 type NodeSwap = Node HyperdataResource
129
130 -- | Then a Node can be a List which has some synonyms
131 type List = Node HyperdataList
132 type StopList = List
133 type MainList = List
134 type MapList = List
135 type GroupList = List
136
137 -- | Then a Node can be a Score which has some synonyms
138 type Score = Node HyperdataScore
139 type Occurrences = Score
140 type Cooccurrences = Score
141 type Specclusion = Score
142 type Genclusion = Score
143 type Cvalue = Score
144 type Tficf = Score
145 ---- TODO All these Tfidf* will be replaced with TFICF
146 type TfidfCorpus = Tficf
147 type TfidfGlobal = Tficf
148 type TirankLocal = Tficf
149 type TirankGlobal = Tficf
150 --
151 ---- | Then a Node can be either a Graph or a Phylo or a Notebook
152 type Graph = Node HyperdataGraph
153 type Phylo = Node HyperdataPhylo
154 type Notebook = Node HyperdataNotebook
155
156
157 nodeTypes :: [(NodeType, NodeTypeId)]
158 nodeTypes = [ (NodeUser , 1)
159 , (Project , 2)
160 , (Corpus , 3)
161 , (Document , 4)
162 --, (NodeSwap , 19)
163 ------ Lists
164 -- , (StopList , 5)
165 -- , (GroupList , 6)
166 -- , (MainList , 7)
167 -- , (MapList ,  8)
168 ---- Scores
169 -- , (Occurrences , 10)
170 -- , (Cooccurrences , 9)
171 --
172 -- , (Specclusion , 11)
173 -- , (Genclusion , 18)
174 -- , (Cvalue , 12)
175 --
176 -- , (TfidfCorpus , 13)
177 -- , (TfidfGlobal , 14)
178 --
179 -- , (TirankLocal , 16)
180 -- , (TirankGlobal , 17)
181 --
182 ---- Node management
183 -- , (Favorites , 15)
184 --
185 ]
186 --
187 nodeTypeId :: NodeType -> NodeTypeId
188 nodeTypeId tn = fromMaybe (error $ "Typename " <> show tn <> " does not exist")
189 (lookup tn nodeTypes)
190
191
192
193 -- Temporary types to be removed
194 type Ngrams = (Text, Text, Text)
195 type ErrorMessage = Text
196
197
198
199