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
44 -- | Language of a Text
45 -- For simplicity, we suppose text has an homogenous language
46 data Language = EN | FR -- | DE | IT | SP
49 -- > DE == deutch (not implemented yet)
50 -- > IT == italian (not implemented yet)
51 -- > SP == spanish (not implemented yet)
52 -- > ... add your language and help us to implement it (:
55 -- All the Database is structred like a hierarchical Tree
56 data Tree a = NodeT a [Tree a]
57 deriving (Show, Read, Eq)
60 -- data Tree a = NodeT a [Tree a]
65 -- Garg Network is a network of all Garg nodes
66 --gargNetwork = undefined
68 -- | Garg Node is Database Schema Typed as specification
69 -- gargNode gathers all the Nodes of all users on one Node
70 gargNode :: [Tree NodeType]
73 -- | User Tree simplified
74 userTree :: Tree NodeType
75 userTree = NodeT NodeUser [projectTree]
78 projectTree :: Tree NodeType
79 projectTree = NodeT Project [corpusTree]
82 corpusTree :: Tree NodeType
83 corpusTree = NodeT Corpus ( [ leafT Document ]
86 <> [ leafT Classification]
89 -- TODO make instances of Nodes
91 -- * why NodeUser and not just User ?
92 -- * is this supposed to hold data ?
93 data NodeType = NodeUser | Project | Corpus | Document | DocumentCopy
97 deriving (Show, Read, Eq, Generic)
99 instance FromJSON NodeType
100 instance ToJSON NodeType
101 instance FromHttpApiData NodeType where parseUrlPiece = Right . read . unpack
103 data Classification = Favorites | MyClassifcation
105 data Lists = StopList | MainList | MapList | GroupList
107 data Metrics = Occurrences | Cooccurrences | Specclusion | Genclusion | Cvalue
108 | TfidfCorpus | TfidfGlobal | TirankLocal | TirankGlobal
112 -- | NodePoly indicates that Node has a Polymorphism Type
113 type Node json = NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime json -- NodeVector
114 type FacetDoc json = Facet NodeId HyperdataDocument Bool Double
116 -- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json
117 type NodeTypeId = Int
119 type NodeParentId = Int
120 type NodeUserId = Int
122 --type NodeVector = Vector
124 --type NodeUser = Node HyperdataUser
126 -- | Then a Node can be either a Folder or a Corpus or a Document
127 type NodeUser = Node HyperdataUser
128 type Folder = Node HyperdataFolder
129 type Project = Folder -- NP Node HyperdataProject ?
130 type Corpus = Node HyperdataCorpus
131 type Document = Node HyperdataDocument
133 -- | Community Manager Use Case
134 type Annuaire = Corpus
135 type Individu = Document
137 -- | Favorites Node enable Node categorization
138 type Favorites = Node HyperdataFavorites
140 -- | Favorites Node enable Swap Node with some synonyms for clarity
141 type NodeSwap = Node HyperdataResource
143 -- | Then a Node can be a List which has some synonyms
144 type List = Node HyperdataList
148 type GroupList = List
150 -- | Then a Node can be a Score which has some synonyms
151 type Score = Node HyperdataScore
152 type Occurrences = Score
153 type Cooccurrences = Score
154 type Specclusion = Score
155 type Genclusion = Score
158 ---- TODO All these Tfidf* will be replaced with TFICF
159 type TfidfCorpus = Tficf
160 type TfidfGlobal = Tficf
161 type TirankLocal = Tficf
162 type TirankGlobal = Tficf
164 ---- | Then a Node can be either a Graph or a Phylo or a Notebook
165 type Graph = Node HyperdataGraph
166 type Phylo = Node HyperdataPhylo
167 type Notebook = Node HyperdataNotebook
170 nodeTypes :: [(NodeType, NodeTypeId)]
171 nodeTypes = [ (NodeUser , 1)
182 -- , (Occurrences , 10)
183 -- , (Cooccurrences , 9)
185 -- , (Specclusion , 11)
186 -- , (Genclusion , 18)
189 -- , (TfidfCorpus , 13)
190 -- , (TfidfGlobal , 14)
192 -- , (TirankLocal , 16)
193 -- , (TirankGlobal , 17)
196 -- , (Favorites , 15)
200 nodeTypeId :: NodeType -> NodeTypeId
201 nodeTypeId tn = fromMaybe (error $ "Typename " <> show tn <> " does not exist")
202 (lookup tn nodeTypes)
208 -- Temporary types to be removed
209 type Ngrams = (Text, Text, Text)
210 type ErrorMessage = Text