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
10 TODO: create a separate Lib.
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
16 {-# LANGUAGE DeriveGeneric #-}
17 {-# LANGUAGE FlexibleInstances #-}
19 module Gargantext.Text.Corpus.Parsers.GrandDebat
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
35 data GrandDebatReference = GrandDebatReference
37 , reference :: !(Maybe Text)
38 , title :: !(Maybe Text)
40 , createdAt :: !(Maybe Text)
41 , publishedAt :: !(Maybe Text)
42 , updatedAt :: !(Maybe Text)
44 , trashed :: !(Maybe Bool)
45 , trashedStatus :: !(Maybe Text)
47 , authorId :: !(Maybe Text)
48 , authorType :: !(Maybe Text)
49 , authorZipCode :: !(Maybe Text)
51 , responses :: !(Maybe [GrandDebatResponse])
53 deriving (Show, Generic)
56 data GrandDebatResponse = GrandDebatResponse
57 { questionId :: !(Maybe Text)
58 , questionTitle :: !(Maybe Text)
59 , value :: !(Maybe Text)
60 , formattedValue :: !(Maybe Text)
62 deriving (Show, Generic)
64 instance FromJSON GrandDebatResponse
65 instance FromJSON GrandDebatReference
67 instance ToJSON GrandDebatResponse
68 instance ToJSON GrandDebatReference
71 instance ToHyperdataDocument GrandDebatReference
73 toHyperdataDocument (GrandDebatReference id' _ref title'
74 _createdAt' publishedAt' _updatedAt
75 _trashed _trashedStatus
76 _authorId authorType' authorZipCode'
78 HyperdataDocument (Just "GrandDebat") id'
79 Nothing Nothing Nothing Nothing
80 title' authorType' authorType' authorZipCode'
81 (toAbstract <$> responses')
83 Nothing Nothing Nothing Nothing Nothing Nothing
84 (Just $ Text.pack $ show FR)
86 toAbstract = (Text.intercalate " . ") . ((filter (/= "")) . (map toSentence))
87 toSentence (GrandDebatResponse _id _qtitle _qvalue r) = case r of
89 Just r' -> case Text.length r' > 10 of
93 instance ReadFile [GrandDebatReference]
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