2 Module : Gargantext.Core.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 module Gargantext.Core.Text.Corpus.API.Hal
16 import Data.Text (Text, pack, intercalate)
18 import Gargantext.Core (Lang(..))
19 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
20 import Gargantext.Prelude
21 import qualified Gargantext.Core.Text.Corpus.Parsers.Date as Date
22 import qualified HAL as HAL
23 import qualified HAL.Client as HAL
24 import qualified HAL.Doc.Corpus as HAL
26 get :: Lang -> Text -> Maybe Integer -> IO [HyperdataDocument]
28 docs <- HAL.getMetadataWith q (Just 0) (fromIntegral <$> ml)
29 either (panic . pack . show) (\d -> mapM (toDoc' la) $ HAL._docs d) docs
31 toDoc' :: Lang -> HAL.Corpus -> IO HyperdataDocument
32 toDoc' la (HAL.Corpus i t ab d s aus affs struct_id) = do
33 (utctime, (pub_year, pub_month, pub_day)) <- Date.dateSplit la (maybe (Just "2019") Just d)
34 pure $ HyperdataDocument (Just "Hal")
35 (Just $ pack $ show i)
40 (Just $ intercalate " " t)
41 (Just $ foldl (\x y -> x <> ", " <> y) "" aus)
42 (Just $ foldl (\x y -> x <> ", " <> y) "" $ affs <> map (cs . show) struct_id)
43 (Just $ maybe "Nothing" identity s)
44 (Just $ intercalate " " ab)
45 (fmap (pack . show) utctime)
52 (Just $ (pack . show) la)