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)
26 module Gargantext.Text.Corpus.Parsers.GrandDebat
29 import Data.Aeson (ToJSON, FromJSON)
30 import qualified Data.ByteString.Lazy as DBL
31 import qualified Data.JsonStream.Parser as P
32 import Data.Maybe (Maybe())
33 import Data.Text (Text)
34 import qualified Data.Text as Text
35 import GHC.Generics (Generic)
37 import Gargantext.Core (Lang(..))
38 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..), ToHyperdataDocument, toHyperdataDocument)
39 import Gargantext.Prelude
40 import Gargantext.Prelude.Utils
43 data GrandDebatReference = GrandDebatReference
45 , reference :: !(Maybe Text)
46 , title :: !(Maybe Text)
48 , createdAt :: !(Maybe Text)
49 , publishedAt :: !(Maybe Text)
50 , updatedAt :: !(Maybe Text)
52 , trashed :: !(Maybe Bool)
53 , trashedStatus :: !(Maybe Text)
55 , authorId :: !(Maybe Text)
56 , authorType :: !(Maybe Text)
57 , authorZipCode :: !(Maybe Text)
59 , responses :: !(Maybe [GrandDebatResponse])
61 deriving (Show, Generic)
64 data GrandDebatResponse = GrandDebatResponse
65 { questionId :: !(Maybe Text)
66 , questionTitle :: !(Maybe Text)
67 , value :: !(Maybe Text)
68 , formattedValue :: !(Maybe Text)
70 deriving (Show, Generic)
72 instance FromJSON GrandDebatResponse
73 instance FromJSON GrandDebatReference
75 instance ToJSON GrandDebatResponse
76 instance ToJSON GrandDebatReference
79 instance ToHyperdataDocument GrandDebatReference
81 toHyperdataDocument (GrandDebatReference id' _ref title'
82 _createdAt' publishedAt' _updatedAt
83 _trashed _trashedStatus
84 _authorId authorType' authorZipCode'
86 HyperdataDocument (Just "GrandDebat") id'
87 Nothing Nothing Nothing Nothing
88 title' authorType' authorType' authorZipCode'
89 (toAbstract <$> responses')
91 Nothing Nothing Nothing Nothing Nothing Nothing
92 (Just $ Text.pack $ show FR)
94 toAbstract = (Text.intercalate " . ") . ((filter (/= "")) . (map toSentence))
95 toSentence (GrandDebatResponse _id _qtitle _qvalue r) = case r of
97 Just r' -> case Text.length r' > 10 of
101 instance ReadFile [GrandDebatReference]
103 -- | read json: 3 version below are working but with increased optimization
104 --readFile fp = maybe [] identity <$> decode <$> DBL.readFile fp
105 --readFile fp = either (panic . Text.pack) identity <$> P.eitherDecode <$> DBL.readFile fp
106 readFile' fp = P.parseLazyByteString (P.arrayOf P.value) <$> DBL.readFile fp