2 Module : Gargantext.Types.Nodes
3 Description : Main Types of Nodes
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE DeriveGeneric #-}
13 {-# LANGUAGE TemplateHaskell #-}
14 {-# LANGUAGE OverloadedStrings #-}
15 {-# LANGUAGE FlexibleInstances #-}
16 -- {-# LANGUAGE DuplicateRecordFields #-}
18 module Gargantext.Types.Node where
20 import GHC.Generics (Generic)
23 import Data.Aeson (Value(),toJSON)
24 import Data.Aeson.TH (deriveJSON)
27 import Data.Text (Text, unpack)
28 import Data.Time (UTCTime)
29 import Data.Time.Segment (jour)
31 import Data.Maybe (fromJust)
33 import Text.Read (read)
34 import Text.Show (Show())
38 import Test.QuickCheck.Arbitrary
39 import Test.QuickCheck (elements)
41 import Gargantext.Prelude
42 import Gargantext.Utils.Prefix (unPrefix)
44 ------------------------------------------------------------------------
45 data Status = Status { status_date :: Maybe UTCTime
46 , status_error :: Maybe Text
47 , status_action :: Maybe Text
48 , status_complete :: Maybe Bool
49 , status_progress :: Maybe Int
50 } deriving (Show, Generic)
51 $(deriveJSON (unPrefix "status_") ''Status)
53 instance Arbitrary Status where
54 arbitrary = elements [Status Nothing Nothing Nothing Nothing Nothing]
57 ------------------------------------------------------------------------
58 data HyperdataDocument = HyperdataDocument { hyperdataDocument_bdd :: Maybe Text
59 , hyperdataDocument_doi :: Maybe Text
60 , hyperdataDocument_url :: Maybe Text
61 , hyperdataDocument_page :: Maybe Int
62 , hyperdataDocument_title :: Maybe Text
63 , hyperdataDocument_authors :: Maybe Text
64 , hyperdataDocument_abstract :: Maybe Text
65 , hyperdataDocument_statuses :: Maybe [Status]
66 , hyperdataDocument_publication_date :: Maybe Text
67 , hyperdataDocument_publication_year :: Maybe Double
68 , hyperdataDocument_publication_month :: Maybe Double
69 , hyperdataDocument_publication_hour :: Maybe Double
70 , hyperdataDocument_publication_minute :: Maybe Double
71 , hyperdataDocument_publication_second :: Maybe Double
72 , hyperdataDocument_languageIso2 :: Maybe Text
73 } deriving (Show, Generic)
74 $(deriveJSON (unPrefix "hyperdataDocument_") ''HyperdataDocument)
76 hyperdataDocuments :: [HyperdataDocument]
77 hyperdataDocuments = [HyperdataDocument Nothing Nothing Nothing Nothing (Just "Title")
78 Nothing (Just "Abstract") Nothing Nothing
79 Nothing Nothing Nothing Nothing Nothing Nothing
83 instance Arbitrary HyperdataDocument where
84 arbitrary = elements hyperdataDocuments
86 ------------------------------------------------------------------------
87 data LanguageNodes = LanguageNodes { languageNodes___unknown__ :: [Int]}
88 deriving (Show, Generic)
89 $(deriveJSON (unPrefix "languageNodes_") ''LanguageNodes)
92 ------------------------------------------------------------------------
94 data Resource = Resource { resource_Url :: Maybe Text
95 , resource_Path :: Maybe Text
96 , resource_Type :: Maybe Int
97 , resource_Extracted :: Maybe Bool
98 } deriving (Show, Generic)
99 $(deriveJSON (unPrefix "resource_") ''Resource)
101 instance Arbitrary Resource where
102 arbitrary = elements [Resource Nothing Nothing Nothing Nothing]
104 data HyperdataCorpus = HyperdataCorpus { hyperdataCorpus_Action :: Maybe Text
105 , hyperdataCorpus_Statuses :: Maybe [Status]
106 , hyperdataCorpus_Languages :: Maybe LanguageNodes
107 , hyperdataCorpus_Resources :: Maybe [Resource]
108 , hyperdataCorpus_Language_id :: Maybe Text
109 , hyperdataCorpus_Skipped_docs :: Maybe [Int]
110 } deriving (Show, Generic)
111 $(deriveJSON (unPrefix "hyperdataCorpus_") ''HyperdataCorpus)
114 data HyperdataUser = HyperdataUser { hyperdataUser_language :: Maybe Text
115 } deriving (Show, Generic)
116 $(deriveJSON (unPrefix "hyperdataUser_") ''HyperdataUser)
120 data HyperdataFolder = HyperdataFolder { hyperdataFolder_Preferences :: Maybe Text
121 } deriving (Show, Generic)
122 $(deriveJSON (unPrefix "hyperdataFolder_") ''HyperdataFolder)
125 data HyperdataProject = HyperdataProject { hyperdataProject_Preferences :: Maybe Text
126 } deriving (Show, Generic)
127 $(deriveJSON (unPrefix "hyperdataProject_") ''HyperdataProject)
131 data HyperdataList = HyperdataList { hyperdataList_Preferences :: Maybe Text
132 } deriving (Show, Generic)
133 $(deriveJSON (unPrefix "hyperdataList_") ''HyperdataList)
135 data HyperdataScore = HyperdataScore { hyperdataScore_Preferences :: Maybe Text
136 } deriving (Show, Generic)
137 $(deriveJSON (unPrefix "hyperdataScore_") ''HyperdataScore)
141 data HyperdataFavorites = HyperdataFavorites { hyperdataFavorites_Preferences :: Maybe Text
142 } deriving (Show, Generic)
143 $(deriveJSON (unPrefix "hyperdataFavorites_") ''HyperdataFavorites)
145 data HyperdataResource = HyperdataResource { hyperdataResource_Preferences :: Maybe Text
146 } deriving (Show, Generic)
147 $(deriveJSON (unPrefix "hyperdataResource_") ''HyperdataResource)
151 -- TODO add the Graph Structure here
152 data HyperdataGraph = HyperdataGraph { hyperdataGraph_Preferences :: Maybe Text
153 } deriving (Show, Generic)
154 $(deriveJSON (unPrefix "hyperdataGraph_") ''HyperdataGraph)
157 -- TODO add the Graph Structure here
158 data HyperdataPhylo = HyperdataPhylo { hyperdataPhylo_Preferences :: Maybe Text
159 } deriving (Show, Generic)
160 $(deriveJSON (unPrefix "hyperdataPhylo_") ''HyperdataPhylo)
162 -- | TODO FEATURE: Notebook saved in the node (to work with Python or Haskell)
163 data HyperdataNotebook = HyperdataNotebook { hyperdataNotebook_Preferences :: Maybe Text
164 } deriving (Show, Generic)
165 $(deriveJSON (unPrefix "hyperdataNotebook_") ''HyperdataNotebook)
169 -- | NodePoly indicates that Node has a Polymorphism Type
170 type Node json = NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime json -- NodeVector
172 -- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json
173 type NodeTypeId = Int
175 type NodeParentId = Int
176 type NodeUserId = Int
178 --type NodeVector = Vector
180 --type NodeUser = Node HyperdataUser
182 -- | Then a Node can be either a Folder or a Corpus or a Document
183 type NodeUser = Node HyperdataUser
184 type Folder = Node HyperdataFolder
185 type Project = Folder -- NP Node HyperdataProject ?
186 type Corpus = Node HyperdataCorpus
187 type Document = Node HyperdataDocument
189 ------------------------------------------------------------------------
190 data NodeType = NodeUser | Project | Corpus | Document | DocumentCopy
193 | Metrics | Occurrences
194 deriving (Show, Read, Eq, Generic)
196 instance FromJSON NodeType
197 instance ToJSON NodeType
199 instance FromHttpApiData NodeType
201 parseUrlPiece = Right . read . unpack
203 instance ToParamSchema NodeType
204 instance ToSchema NodeType
206 ------------------------------------------------------------------------
207 data NodePoly id typename userId parentId name date hyperdata = Node { node_id :: id
208 , node_typename :: typename
209 , node_userId :: userId
210 -- , nodeHashId :: hashId
211 , node_parentId :: parentId
214 , node_hyperdata :: hyperdata
215 -- , node_titleAbstract :: titleAbstract
216 } deriving (Show, Generic)
217 $(deriveJSON (unPrefix "node_") ''NodePoly)
219 instance Arbitrary (NodePoly NodeId NodeTypeId (Maybe NodeUserId) NodeParentId NodeName UTCTime Value) where
220 arbitrary = elements [Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (toJSON ("{}"::Text))]
223 instance Arbitrary (NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime Value) where
224 arbitrary = elements [Node 1 1 1 (Just 1) "name" (jour 2018 01 01) (toJSON ("{}"::Text))]
226 instance Arbitrary (NodePoly NodeId NodeTypeId (Maybe NodeUserId) NodeParentId NodeName UTCTime HyperdataDocument) where
227 arbitrary = elements [Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) ((hyperdataDocument))]
230 instance Arbitrary (NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime HyperdataDocument) where
231 arbitrary = elements [Node 1 1 1 (Just 1) "name" (jour 2018 01 01) hyperdataDocument]
233 hyperdataDocument :: HyperdataDocument
234 hyperdataDocument = fromJust $ decode "{\"publication_day\":6,\"language_iso2\":\"en\",\"publication_minute\":0,\"publication_month\":7,\"language_iso3\":\"eng\",\"publication_second\":0,\"authors\":\"Nils Hovdenak, Kjell Haram\",\"publication_year\":2012,\"publication_date\":\"2012-07-06 00:00:00+00:00\",\"language_name\":\"English\",\"statuses\":[],\"realdate_full_\":\"2012 01 12\",\"source\":\"European journal of obstetrics, gynecology, and reproductive biology\",\"abstract\":\"The literature was searched for publications on minerals and vitamins during pregnancy and the possible influence of supplements on pregnancy outcome.\",\"title\":\"Influence of mineral and vitamin supplements on pregnancy outcome.\",\"publication_hour\":0}"
237 instance ToSchema HyperdataDocument where
238 declareNamedSchema = genericDeclareNamedSchemaUnrestricted defaultSchemaOptions
240 instance ToSchema (NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime HyperdataDocument)
241 instance ToSchema (NodePoly NodeId NodeTypeId (Maybe NodeUserId) NodeParentId NodeName UTCTime HyperdataDocument)
243 instance ToSchema Status