]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core/Text/Corpus/API/Hal.hs
[API] simplify parsing of date
[gargantext.git] / src / Gargantext / Core / Text / Corpus / API / Hal.hs
1 {-|
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
8 Portability : POSIX
9
10 -}
11
12 module Gargantext.Core.Text.Corpus.API.Hal
13 where
14
15 import Data.Maybe
16 import Data.Text (Text, pack, intercalate)
17
18 import Gargantext.Core (Lang(..))
19 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
20 import qualified Gargantext.Defaults as Defaults
21 import Gargantext.Prelude
22 import qualified Gargantext.Core.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 (Just 0) (fromIntegral <$> ml)
30 pure $ either (panic . pack . show) (\d -> map (toDoc' la) $ HAL._docs d) docs
31
32 toDoc' :: Lang -> HAL.Corpus -> HyperdataDocument
33 toDoc' la (HAL.Corpus i t ab d s aus affs struct_id) = do
34 let (utctime, (pub_year, pub_month, pub_day)) =
35 Date.dateSplit la (maybe (Just $ pack $ show Defaults.year) Just d)
36 HyperdataDocument { _hd_bdd = Just "Hal"
37 , _hd_doi = Just $ pack $ show i
38 , _hd_url = Nothing
39 , _hd_uniqId = Nothing
40 , _hd_uniqIdBdd = Nothing
41 , _hd_page = Nothing
42 , _hd_title = Just $ intercalate " " t
43 , _hd_authors = Just $ foldl (\x y -> x <> ", " <> y) "" aus
44 , _hd_institutes = Just $ foldl (\x y -> x <> ", " <> y) "" $ affs <> map (cs . show) struct_id
45 , _hd_source = Just $ maybe "Nothing" identity s
46 , _hd_abstract = Just $ intercalate " " ab
47 , _hd_publication_date = fmap (pack . show) utctime
48 , _hd_publication_year = pub_year
49 , _hd_publication_month = pub_month
50 , _hd_publication_day = pub_day
51 , _hd_publication_hour = Nothing
52 , _hd_publication_minute = Nothing
53 , _hd_publication_second = Nothing
54 , _hd_language_iso2 = Just $ (pack . show) la }
55