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