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
12 {-# LANGUAGE NoImplicitPrelude #-}
13 {-# LANGUAGE OverloadedStrings #-}
15 module Gargantext.Text.Corpus.API.Hal
19 import Data.Text (Text, pack, intercalate)
20 import Gargantext.Core (Lang(..))
21 import Gargantext.Database.Admin.Types.Node (HyperdataDocument(..))
22 import Gargantext.Prelude
23 import qualified Gargantext.Text.Corpus.Parsers.Date as Date
24 import qualified HAL as HAL
25 import qualified HAL.Client as HAL
26 import qualified HAL.Doc.Corpus as HAL
28 get :: Lang -> Text -> Maybe Integer -> IO [HyperdataDocument]
30 docs <- HAL.getMetadataWith q (fromIntegral <$> ml)
31 either (panic . pack . show) (\d -> mapM (toDoc' la) $ HAL._docs d) docs
33 toDoc' :: Lang -> HAL.Corpus -> IO HyperdataDocument
34 toDoc' la (HAL.Corpus i t ab d s aus affs) = do
35 (utctime, (pub_year, pub_month, pub_day)) <- Date.dateSplit la (maybe (Just "2019") Just d)
36 pure $ HyperdataDocument (Just "Hal")
37 (Just $ pack $ show i)
42 (Just $ intercalate " " t)
43 (Just $ foldl (\x y -> x <> ", " <> y) "" aus)
44 (Just $ foldl (\x y -> x <> ", " <> y) "" affs)
45 (Just $ maybe "Nothing" identity s)
46 (Just $ intercalate " " ab)
47 (fmap (pack . show) utctime)
54 (Just $ (pack . show) la)