]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/API/Hal.hs
Merge branch 'dev' into dev-list-charts
[gargantext.git] / src / Gargantext / Text / Corpus / API / Hal.hs
1 {-|
2 Module : Gargantext.Text.Corpus.API.Hal
3 Description : Pubmed API connection
4 Copyright : (c) CNRS, 2017
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12
13 module Gargantext.Text.Corpus.API.Hal
14 where
15
16 import Data.Maybe
17 import Data.Text (Text, pack, intercalate)
18
19 import Gargantext.Core (Lang(..))
20 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
21 import Gargantext.Prelude
22 import qualified Gargantext.Text.Corpus.Parsers.Date as Date
23 import qualified HAL as HAL
24 import qualified HAL.Client as HAL
25 import qualified HAL.Doc.Corpus as HAL
26
27 get :: Lang -> Text -> Maybe Integer -> IO [HyperdataDocument]
28 get la q ml = do
29 docs <- HAL.getMetadataWith q (fromIntegral <$> ml)
30 either (panic . pack . show) (\d -> mapM (toDoc' la) $ HAL._docs d) docs
31
32 toDoc' :: Lang -> HAL.Corpus -> IO HyperdataDocument
33 toDoc' la (HAL.Corpus i t ab d s aus affs) = do
34 (utctime, (pub_year, pub_month, pub_day)) <- Date.dateSplit la (maybe (Just "2019") Just d)
35 pure $ HyperdataDocument (Just "Hal")
36 (Just $ pack $ show i)
37 Nothing
38 Nothing
39 Nothing
40 Nothing
41 (Just $ intercalate " " t)
42 (Just $ foldl (\x y -> x <> ", " <> y) "" aus)
43 (Just $ foldl (\x y -> x <> ", " <> y) "" affs)
44 (Just $ maybe "Nothing" identity s)
45 (Just $ intercalate " " ab)
46 (fmap (pack . show) utctime)
47 pub_year
48 pub_month
49 pub_day
50 Nothing
51 Nothing
52 Nothing
53 (Just $ (pack . show) la)
54