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 _flowCorpusDebat :: FlowCmdM env err m
11 => User -> Either CorpusName [CorpusId]
14 _flowCorpusDebat u n l fp = do
15 docs <- liftBase ( splitEvery 500
18 :: IO [[GD.GrandDebatReference ]]
20 flowCorpus u n (Multi FR) (map (map toHyperdataDocument) docs)
25 {-# LANGUAGE NoImplicitPrelude #-}
26 {-# LANGUAGE OverloadedStrings #-}
27 {-# LANGUAGE DeriveGeneric #-}
28 {-# LANGUAGE FlexibleInstances #-}
30 module Gargantext.Text.Corpus.Parsers.GrandDebat
33 import Data.Aeson (ToJSON, FromJSON)
34 import Data.Maybe (Maybe())
35 import Data.Text (Text)
36 import GHC.Generics (Generic)
37 import Gargantext.Core (Lang(..))
38 import Gargantext.Database.Admin.Types.Node
39 import Gargantext.Prelude
40 import Gargantext.Prelude.Utils
41 import qualified Data.ByteString.Lazy as DBL
42 import qualified Data.JsonStream.Parser as P
43 import qualified Data.Text as Text
46 data GrandDebatReference = GrandDebatReference
48 , reference :: !(Maybe Text)
49 , title :: !(Maybe Text)
51 , createdAt :: !(Maybe Text)
52 , publishedAt :: !(Maybe Text)
53 , updatedAt :: !(Maybe Text)
55 , trashed :: !(Maybe Bool)
56 , trashedStatus :: !(Maybe Text)
58 , authorId :: !(Maybe Text)
59 , authorType :: !(Maybe Text)
60 , authorZipCode :: !(Maybe Text)
62 , responses :: !(Maybe [GrandDebatResponse])
64 deriving (Show, Generic)
67 data GrandDebatResponse = GrandDebatResponse
68 { questionId :: !(Maybe Text)
69 , questionTitle :: !(Maybe Text)
70 , value :: !(Maybe Text)
71 , formattedValue :: !(Maybe Text)
73 deriving (Show, Generic)
75 instance FromJSON GrandDebatResponse
76 instance FromJSON GrandDebatReference
78 instance ToJSON GrandDebatResponse
79 instance ToJSON GrandDebatReference
82 instance ToHyperdataDocument GrandDebatReference
84 toHyperdataDocument (GrandDebatReference id' _ref title'
85 _createdAt' publishedAt' _updatedAt
86 _trashed _trashedStatus
87 _authorId authorType' authorZipCode'
89 HyperdataDocument (Just "GrandDebat") id'
90 Nothing Nothing Nothing Nothing
91 title' authorType' authorType' authorZipCode'
92 (toAbstract <$> responses')
94 Nothing Nothing Nothing Nothing Nothing Nothing
95 (Just $ Text.pack $ show FR)
97 toAbstract = (Text.intercalate " . ") . ((filter (/= "")) . (map toSentence))
98 toSentence (GrandDebatResponse _id _qtitle _qvalue r) = case r of
100 Just r' -> case Text.length r' > 10 of
104 instance ReadFile [GrandDebatReference]
106 -- | read json: 3 version below are working but with increased optimization
107 --readFile fp = maybe [] identity <$> decode <$> DBL.readFile fp
108 --readFile fp = either (panic . Text.pack) identity <$> P.eitherDecode <$> DBL.readFile fp
109 readFile' fp = P.parseLazyByteString (P.arrayOf P.value) <$> DBL.readFile fp