Commit 41cf1ee9 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FLOW] Instances of HyperdataDocument + Grand Debat imports.

parent 6a45919d
...@@ -59,6 +59,7 @@ library: ...@@ -59,6 +59,7 @@ library:
- Gargantext.Text.Parsers.Date - Gargantext.Text.Parsers.Date
- Gargantext.Text.Parsers.Wikimedia - Gargantext.Text.Parsers.Wikimedia
- Gargantext.Text.Parsers.WOS - Gargantext.Text.Parsers.WOS
- Gargantext.Text.Parsers.GrandDebat
- Gargantext.Text.Search - Gargantext.Text.Search
- Gargantext.Text.Terms - Gargantext.Text.Terms
- Gargantext.Text.Terms.Stop - Gargantext.Text.Terms.Stop
......
...@@ -148,7 +148,7 @@ instance Arbitrary FacetDoc where ...@@ -148,7 +148,7 @@ instance Arbitrary FacetDoc where
| id' <- [1..10] | id' <- [1..10]
, year <- [1990..2000] , year <- [1990..2000]
, t <- ["title", "another title"] , t <- ["title", "another title"]
, hp <- hyperdataDocuments , hp <- arbitraryHyperdataDocuments
, fav <- [True, False] , fav <- [True, False]
, ngramCount <- [3..100] , ngramCount <- [3..100]
] ]
......
...@@ -80,10 +80,10 @@ flowCorpus :: FlowCmdM env ServantErr m ...@@ -80,10 +80,10 @@ flowCorpus :: FlowCmdM env ServantErr m
=> Username -> CorpusName -> TermType Lang -> FileFormat -> FilePath -> m CorpusId => Username -> CorpusName -> TermType Lang -> FileFormat -> FilePath -> m CorpusId
flowCorpus u cn la ff fp = liftIO (parseDocs ff fp) >>= \docs -> flowCorpus' u cn la docs flowCorpus u cn la ff fp = liftIO (parseDocs ff fp) >>= \docs -> flowCorpus' u cn la docs
flowCorpus' :: FlowCmdM env ServantErr m flowCorpus' :: (FlowCmdM env ServantErr m, ToHyperdataDocument a)
=> Username -> CorpusName -> TermType Lang -> [HyperdataDocument] -> m CorpusId => Username -> CorpusName -> TermType Lang -> [a] -> m CorpusId
flowCorpus' u cn la docs = do flowCorpus' u cn la docs = do
ids <- flowCorpusMaster la docs ids <- flowCorpusMaster la (map toHyperdataDocument docs)
flowCorpusUser u cn ids flowCorpusUser u cn ids
......
This diff is collapsed.
{-|
Module : Gargantext.Text.Parsers.GrandDebat
Description : Grand Debat Types
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
TODO: create a separate Lib.
-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
module Gargantext.Text.Parsers.GrandDebat
where
import GHC.IO (FilePath)
import Data.Aeson (ToJSON, FromJSON, decode)
import Data.Maybe (Maybe(), maybe)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.ByteString.Lazy as DBL
import GHC.Generics (Generic)
import Gargantext.Prelude
import Gargantext.Database.Types.Node
import Gargantext.Core (Lang(..))
data GrandDebatReference = GrandDebatReference
{ id :: !(Maybe Text)
, reference :: !(Maybe Text)
, title :: !(Maybe Text)
, createdAt :: !(Maybe Text)
, publishedAt :: !(Maybe Text)
, updatedAt :: !(Maybe Text)
, trashed :: !(Maybe Bool)
, trashedStatus :: !(Maybe Text)
, authorId :: !(Maybe Text)
, authorType :: !(Maybe Text)
, authorZipCode :: !(Maybe Text)
, responses :: !(Maybe [GrandDebatResponse])
}
deriving (Show, Generic)
data GrandDebatResponse = GrandDebatResponse
{ questionId :: !(Maybe Text)
, questionTitle :: !(Maybe Text)
, value :: !(Maybe Text)
, formattedValue :: !(Maybe Text)
}
deriving (Show, Generic)
instance FromJSON GrandDebatResponse
instance FromJSON GrandDebatReference
instance ToJSON GrandDebatResponse
instance ToJSON GrandDebatReference
instance ToHyperdataDocument GrandDebatReference
where
toHyperdataDocument (GrandDebatReference id' _ref title'
_createdAt' publishedAt' _updatedAt
_trashed _trashedStatus
_authorId authorType' authorZipCode'
responses') =
HyperdataDocument (Just "GrandDebat") id'
Nothing Nothing Nothing Nothing
title' authorType' authorZipCode' authorZipCode'
(toAbstract <$> responses')
publishedAt'
Nothing Nothing Nothing Nothing Nothing Nothing
(Just $ Text.pack $ show FR)
where
toAbstract = (Text.intercalate " . ") . (map toSentence)
toSentence (GrandDebatResponse _id _qtitle _qvalue r) = case r of
Nothing -> ""
Just r' -> case Text.length r' > 10 of
True -> r'
False -> ""
class ReadFile a
where
readFile :: FilePath -> IO a
instance ReadFile [GrandDebatReference]
where
readFile fp = maybe [] identity <$> decode <$> DBL.readFile fp
...@@ -31,10 +31,6 @@ import Data.ByteString.Char8 (pack) ...@@ -31,10 +31,6 @@ import Data.ByteString.Char8 (pack)
import Control.Applicative import Control.Applicative
------------------------------------------------------------- -------------------------------------------------------------
-- | wosParser parses ISI format from -- | wosParser parses ISI format from
-- Web Of Science Database -- Web Of Science Database
wosParser :: Parser [[(ByteString, ByteString)]] wosParser :: Parser [[(ByteString, ByteString)]]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment