]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/Parsers/GrandDebat.hs
[GRAPH] Type graph version is list version.
[gargantext.git] / src / Gargantext / Text / Corpus / Parsers / GrandDebat.hs
1 {-|
2 Module : Gargantext.Text.Corpus.Parsers.GrandDebat
3 Description : Grand Debat Types
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 TODO: create a separate Lib.
11
12 -}
13
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
16 {-# LANGUAGE DeriveGeneric #-}
17 {-# LANGUAGE FlexibleInstances #-}
18
19 module Gargantext.Text.Corpus.Parsers.GrandDebat
20 where
21
22 import Data.Aeson (ToJSON, FromJSON)
23 import Data.Maybe (Maybe())
24 import Data.Text (Text)
25 import GHC.Generics (Generic)
26 import Gargantext.Core (Lang(..))
27 import Gargantext.Database.Types.Node
28 import Gargantext.Prelude
29 import Gargantext.Prelude.Utils
30 import qualified Data.ByteString.Lazy as DBL
31 import qualified Data.JsonStream.Parser as P
32 import qualified Data.Text as Text
33
34
35 data GrandDebatReference = GrandDebatReference
36 { id :: !(Maybe Text)
37 , reference :: !(Maybe Text)
38 , title :: !(Maybe Text)
39
40 , createdAt :: !(Maybe Text)
41 , publishedAt :: !(Maybe Text)
42 , updatedAt :: !(Maybe Text)
43
44 , trashed :: !(Maybe Bool)
45 , trashedStatus :: !(Maybe Text)
46
47 , authorId :: !(Maybe Text)
48 , authorType :: !(Maybe Text)
49 , authorZipCode :: !(Maybe Text)
50
51 , responses :: !(Maybe [GrandDebatResponse])
52 }
53 deriving (Show, Generic)
54
55
56 data GrandDebatResponse = GrandDebatResponse
57 { questionId :: !(Maybe Text)
58 , questionTitle :: !(Maybe Text)
59 , value :: !(Maybe Text)
60 , formattedValue :: !(Maybe Text)
61 }
62 deriving (Show, Generic)
63
64 instance FromJSON GrandDebatResponse
65 instance FromJSON GrandDebatReference
66
67 instance ToJSON GrandDebatResponse
68 instance ToJSON GrandDebatReference
69
70
71 instance ToHyperdataDocument GrandDebatReference
72 where
73 toHyperdataDocument (GrandDebatReference id' _ref title'
74 _createdAt' publishedAt' _updatedAt
75 _trashed _trashedStatus
76 _authorId authorType' authorZipCode'
77 responses') =
78 HyperdataDocument (Just "GrandDebat") id'
79 Nothing Nothing Nothing Nothing
80 title' authorType' authorType' authorZipCode'
81 (toAbstract <$> responses')
82 publishedAt'
83 Nothing Nothing Nothing Nothing Nothing Nothing
84 (Just $ Text.pack $ show FR)
85 where
86 toAbstract = (Text.intercalate " . ") . ((filter (/= "")) . (map toSentence))
87 toSentence (GrandDebatResponse _id _qtitle _qvalue r) = case r of
88 Nothing -> ""
89 Just r' -> case Text.length r' > 10 of
90 True -> r'
91 False -> ""
92
93 instance ReadFile [GrandDebatReference]
94 where
95 -- | read json: 3 version below are working but with increased optimization
96 --readFile fp = maybe [] identity <$> decode <$> DBL.readFile fp
97 --readFile fp = either (panic . Text.pack) identity <$> P.eitherDecode <$> DBL.readFile fp
98 readFile' fp = P.parseLazyByteString (P.arrayOf P.value) <$> DBL.readFile fp
99
100
101