2 Module : Gargantext.Core.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.Core.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.Text (Text)
33 import qualified Data.Text as Text
34 import GHC.Generics (Generic)
36 import Gargantext.Core (Lang(..))
37 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..), ToHyperdataDocument, toHyperdataDocument)
38 import Gargantext.Prelude
39 import Gargantext.Prelude.Utils
42 data GrandDebatReference = GrandDebatReference
44 , reference :: !(Maybe Text)
45 , title :: !(Maybe Text)
47 , createdAt :: !(Maybe Text)
48 , publishedAt :: !(Maybe Text)
49 , updatedAt :: !(Maybe Text)
51 , trashed :: !(Maybe Bool)
52 , trashedStatus :: !(Maybe Text)
54 , authorId :: !(Maybe Text)
55 , authorType :: !(Maybe Text)
56 , authorZipCode :: !(Maybe Text)
58 , responses :: !(Maybe [GrandDebatResponse])
60 deriving (Show, Generic)
63 data GrandDebatResponse = GrandDebatResponse
64 { questionId :: !(Maybe Text)
65 , questionTitle :: !(Maybe Text)
66 , value :: !(Maybe Text)
67 , formattedValue :: !(Maybe Text)
69 deriving (Show, Generic)
71 instance FromJSON GrandDebatResponse
72 instance FromJSON GrandDebatReference
74 instance ToJSON GrandDebatResponse
75 instance ToJSON GrandDebatReference
78 instance ToHyperdataDocument GrandDebatReference
80 toHyperdataDocument (GrandDebatReference id' _ref title'
81 _createdAt' publishedAt' _updatedAt
82 _trashed _trashedStatus
83 _authorId authorType' authorZipCode'
85 HyperdataDocument (Just "GrandDebat") id'
86 Nothing Nothing Nothing Nothing
87 title' authorType' authorType' authorZipCode'
88 (toAbstract <$> responses')
90 Nothing Nothing Nothing Nothing Nothing Nothing
91 (Just $ Text.pack $ show FR)
93 toAbstract = (Text.intercalate " . ") . ((filter (/= "")) . (map toSentence))
94 toSentence (GrandDebatResponse _id _qtitle _qvalue r) = case r of
96 Just r' -> case Text.length r' > 10 of
100 instance ReadFile [GrandDebatReference]
102 -- | read json: 3 version below are working but with increased optimization
103 --readFile fp = maybe [] identity <$> decode <$> DBL.readFile fp
104 --readFile fp = either (panic . Text.pack) identity <$> P.eitherDecode <$> DBL.readFile fp
105 readFile' fp = P.parseLazyByteString (P.arrayOf P.value) <$> DBL.readFile fp