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 GHC.IO (FilePath)
23 import Data.Aeson (ToJSON, FromJSON)
24 import qualified Data.JsonStream.Parser as P
25 --import Data.Either (either)
26 import Data.Maybe (Maybe())
27 import Data.Text (Text)
28 import qualified Data.Text as Text
29 import qualified Data.ByteString.Lazy as DBL
30 import GHC.Generics (Generic)
31 import Gargantext.Prelude
32 import Gargantext.Database.Types.Node
33 import Gargantext.Core (Lang(..))
36 data GrandDebatReference = GrandDebatReference
38 , reference :: !(Maybe Text)
39 , title :: !(Maybe Text)
41 , createdAt :: !(Maybe Text)
42 , publishedAt :: !(Maybe Text)
43 , updatedAt :: !(Maybe Text)
45 , trashed :: !(Maybe Bool)
46 , trashedStatus :: !(Maybe Text)
48 , authorId :: !(Maybe Text)
49 , authorType :: !(Maybe Text)
50 , authorZipCode :: !(Maybe Text)
52 , responses :: !(Maybe [GrandDebatResponse])
54 deriving (Show, Generic)
57 data GrandDebatResponse = GrandDebatResponse
58 { questionId :: !(Maybe Text)
59 , questionTitle :: !(Maybe Text)
60 , value :: !(Maybe Text)
61 , formattedValue :: !(Maybe Text)
63 deriving (Show, Generic)
65 instance FromJSON GrandDebatResponse
66 instance FromJSON GrandDebatReference
68 instance ToJSON GrandDebatResponse
69 instance ToJSON GrandDebatReference
72 instance ToHyperdataDocument GrandDebatReference
74 toHyperdataDocument (GrandDebatReference id' _ref title'
75 _createdAt' publishedAt' _updatedAt
76 _trashed _trashedStatus
77 _authorId authorType' authorZipCode'
79 HyperdataDocument (Just "GrandDebat") id'
80 Nothing Nothing Nothing Nothing
81 title' authorType' authorType' authorZipCode'
82 (toAbstract <$> responses')
84 Nothing Nothing Nothing Nothing Nothing Nothing
85 (Just $ Text.pack $ show FR)
87 toAbstract = (Text.intercalate " . ") . ((filter (/= "")) . (map toSentence))
88 toSentence (GrandDebatResponse _id _qtitle _qvalue r) = case r of
90 Just r' -> case Text.length r' > 10 of
96 readFile :: FilePath -> IO a
98 instance ReadFile [GrandDebatReference]
100 -- | read json: 3 version below are working but with increased optimization
101 --readFile fp = maybe [] identity <$> decode <$> DBL.readFile fp
102 --readFile fp = either (panic . Text.pack) identity <$> P.eitherDecode <$> DBL.readFile fp
103 readFile fp = P.parseLazyByteString (P.arrayOf P.value) <$> DBL.readFile fp