]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/API/Hal.hs
[refactoring] add some default extensions to package.yaml
[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 import Gargantext.Core (Lang(..))
19 import Gargantext.Database.Admin.Types.Node (HyperdataDocument(..))
20 import Gargantext.Prelude
21 import qualified Gargantext.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
25
26 get :: Lang -> Text -> Maybe Integer -> IO [HyperdataDocument]
27 get la q ml = do
28 docs <- HAL.getMetadataWith q (fromIntegral <$> ml)
29 either (panic . pack . show) (\d -> mapM (toDoc' la) $ HAL._docs d) docs
30
31 toDoc' :: Lang -> HAL.Corpus -> IO HyperdataDocument
32 toDoc' la (HAL.Corpus i t ab d s aus affs) = 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)
36 Nothing
37 Nothing
38 Nothing
39 Nothing
40 (Just $ intercalate " " t)
41 (Just $ foldl (\x y -> x <> ", " <> y) "" aus)
42 (Just $ foldl (\x y -> x <> ", " <> y) "" affs)
43 (Just $ maybe "Nothing" identity s)
44 (Just $ intercalate " " ab)
45 (fmap (pack . show) utctime)
46 pub_year
47 pub_month
48 pub_day
49 Nothing
50 Nothing
51 Nothing
52 (Just $ (pack . show) la)
53