]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/Parsers/GrandDebat.hs
[GRAPH] adding type Ordering to sortTficf and others
[gargantext.git] / src / Gargantext / Text / Corpus / Parsers / GrandDebat.hs
1 {-|
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
8 Portability : POSIX
9
10 _flowCorpusDebat :: FlowCmdM env err m
11 => User -> Either CorpusName [CorpusId]
12 -> Limit -> FilePath
13 -> m CorpusId
14 _flowCorpusDebat u n l fp = do
15 docs <- liftBase ( splitEvery 500
16 <$> take l
17 <$> readFile' fp
18 :: IO [[GD.GrandDebatReference ]]
19 )
20 flowCorpus u n (Multi FR) (map (map toHyperdataDocument) docs)
21
22
23 -}
24
25 {-# LANGUAGE NoImplicitPrelude #-}
26 {-# LANGUAGE OverloadedStrings #-}
27 {-# LANGUAGE DeriveGeneric #-}
28 {-# LANGUAGE FlexibleInstances #-}
29
30 module Gargantext.Text.Corpus.Parsers.GrandDebat
31 where
32
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
44
45
46 data GrandDebatReference = GrandDebatReference
47 { id :: !(Maybe Text)
48 , reference :: !(Maybe Text)
49 , title :: !(Maybe Text)
50
51 , createdAt :: !(Maybe Text)
52 , publishedAt :: !(Maybe Text)
53 , updatedAt :: !(Maybe Text)
54
55 , trashed :: !(Maybe Bool)
56 , trashedStatus :: !(Maybe Text)
57
58 , authorId :: !(Maybe Text)
59 , authorType :: !(Maybe Text)
60 , authorZipCode :: !(Maybe Text)
61
62 , responses :: !(Maybe [GrandDebatResponse])
63 }
64 deriving (Show, Generic)
65
66
67 data GrandDebatResponse = GrandDebatResponse
68 { questionId :: !(Maybe Text)
69 , questionTitle :: !(Maybe Text)
70 , value :: !(Maybe Text)
71 , formattedValue :: !(Maybe Text)
72 }
73 deriving (Show, Generic)
74
75 instance FromJSON GrandDebatResponse
76 instance FromJSON GrandDebatReference
77
78 instance ToJSON GrandDebatResponse
79 instance ToJSON GrandDebatReference
80
81
82 instance ToHyperdataDocument GrandDebatReference
83 where
84 toHyperdataDocument (GrandDebatReference id' _ref title'
85 _createdAt' publishedAt' _updatedAt
86 _trashed _trashedStatus
87 _authorId authorType' authorZipCode'
88 responses') =
89 HyperdataDocument (Just "GrandDebat") id'
90 Nothing Nothing Nothing Nothing
91 title' authorType' authorType' authorZipCode'
92 (toAbstract <$> responses')
93 publishedAt'
94 Nothing Nothing Nothing Nothing Nothing Nothing
95 (Just $ Text.pack $ show FR)
96 where
97 toAbstract = (Text.intercalate " . ") . ((filter (/= "")) . (map toSentence))
98 toSentence (GrandDebatResponse _id _qtitle _qvalue r) = case r of
99 Nothing -> ""
100 Just r' -> case Text.length r' > 10 of
101 True -> r'
102 False -> ""
103
104 instance ReadFile [GrandDebatReference]
105 where
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
110
111
112