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 qualified Data.ByteString.Lazy as DBL
35 import qualified Data.JsonStream.Parser as P
36 import Data.Maybe (Maybe())
37 import Data.Text (Text)
38 import qualified Data.Text as Text
39 import GHC.Generics (Generic)
41 import Gargantext.Core (Lang(..))
42 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..), ToHyperdataDocument, toHyperdataDocument)
43 import Gargantext.Prelude
44 import Gargantext.Prelude.Utils
47 data GrandDebatReference = GrandDebatReference
49 , reference :: !(Maybe Text)
50 , title :: !(Maybe Text)
52 , createdAt :: !(Maybe Text)
53 , publishedAt :: !(Maybe Text)
54 , updatedAt :: !(Maybe Text)
56 , trashed :: !(Maybe Bool)
57 , trashedStatus :: !(Maybe Text)
59 , authorId :: !(Maybe Text)
60 , authorType :: !(Maybe Text)
61 , authorZipCode :: !(Maybe Text)
63 , responses :: !(Maybe [GrandDebatResponse])
65 deriving (Show, Generic)
68 data GrandDebatResponse = GrandDebatResponse
69 { questionId :: !(Maybe Text)
70 , questionTitle :: !(Maybe Text)
71 , value :: !(Maybe Text)
72 , formattedValue :: !(Maybe Text)
74 deriving (Show, Generic)
76 instance FromJSON GrandDebatResponse
77 instance FromJSON GrandDebatReference
79 instance ToJSON GrandDebatResponse
80 instance ToJSON GrandDebatReference
83 instance ToHyperdataDocument GrandDebatReference
85 toHyperdataDocument (GrandDebatReference id' _ref title'
86 _createdAt' publishedAt' _updatedAt
87 _trashed _trashedStatus
88 _authorId authorType' authorZipCode'
90 HyperdataDocument (Just "GrandDebat") id'
91 Nothing Nothing Nothing Nothing
92 title' authorType' authorType' authorZipCode'
93 (toAbstract <$> responses')
95 Nothing Nothing Nothing Nothing Nothing Nothing
96 (Just $ Text.pack $ show FR)
98 toAbstract = (Text.intercalate " . ") . ((filter (/= "")) . (map toSentence))
99 toSentence (GrandDebatResponse _id _qtitle _qvalue r) = case r of
101 Just r' -> case Text.length r' > 10 of
105 instance ReadFile [GrandDebatReference]
107 -- | read json: 3 version below are working but with increased optimization
108 --readFile fp = maybe [] identity <$> decode <$> DBL.readFile fp
109 --readFile fp = either (panic . Text.pack) identity <$> P.eitherDecode <$> DBL.readFile fp
110 readFile' fp = P.parseLazyByteString (P.arrayOf P.value) <$> DBL.readFile fp