]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/API/Hal.hs
[ELEVE] mainEleve' with a witness corpus
[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 {-# LANGUAGE NoImplicitPrelude #-}
13 {-# LANGUAGE OverloadedStrings #-}
14
15 module Gargantext.Text.Corpus.API.Hal
16 where
17
18 import Data.Maybe
19 import Data.Text (Text, pack, intercalate)
20 import Gargantext.Prelude
21 import Gargantext.Core (Lang(..))
22 import qualified Gargantext.Text.Corpus.Parsers.Date as Date
23 import Gargantext.Database.Types.Node (HyperdataDocument(..))
24
25 import qualified HAL as HAL
26 import qualified HAL.Doc.Corpus as HAL
27 import qualified HAL.Client as HAL
28
29 get :: Lang -> Text -> Maybe Integer -> IO [HyperdataDocument]
30 get la q ml = do
31 docs <- HAL.getMetadataWith q (fromIntegral <$> ml)
32 either (panic . pack . show) (\d -> mapM (toDoc' la) $ HAL._docs d) docs
33
34 toDoc' :: Lang -> HAL.Corpus -> IO HyperdataDocument
35 toDoc' la (HAL.Corpus i t ab d s aus affs) = do
36 (utctime, (pub_year, pub_month, pub_day)) <- Date.dateSplit la (maybe (Just "2019") Just d)
37 pure $ HyperdataDocument (Just "Hal")
38 (Just $ pack $ show i)
39 Nothing
40 Nothing
41 Nothing
42 Nothing
43 (Just $ intercalate " " t)
44 (Just $ foldl (\x y -> x <> ", " <> y) "" aus)
45 (Just $ foldl (\x y -> x <> ", " <> y) "" affs)
46 (Just $ maybe "Nothing" identity s)
47 (Just $ intercalate " " ab)
48 (fmap (pack . show) utctime)
49 pub_year
50 pub_month
51 pub_day
52 Nothing
53 Nothing
54 Nothing
55 (Just $ (pack . show) la)
56