2 Module : Gargantext.Text.Corpus.API.Istex
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.Istex
18 import Data.Either (either)
19 import Data.List (concat)
21 import Data.Maybe (catMaybes)
22 import Data.Text (Text, pack)
23 import Gargantext.Core (Lang(..))
24 import Gargantext.Database.Admin.Types.Node (HyperdataDocument(..))
25 import Gargantext.Prelude
26 import qualified Gargantext.Text.Corpus.Parsers.Date as Date
27 import qualified ISTEX as ISTEX
28 import qualified ISTEX.Client as ISTEX
30 get :: Lang -> Text -> Maybe Integer -> IO [HyperdataDocument]
32 docs <- ISTEX.getMetadataWith q (fromIntegral <$> ml)
33 either (panic . pack . show) (toDoc' la) docs
35 toDoc' :: Lang -> ISTEX.Documents -> IO [HyperdataDocument]
37 --printDebug "ISTEX" (ISTEX._documents_total docs')
38 mapM (toDoc la) (ISTEX._documents_hits docs')
40 -- | TODO remove dateSplit here
41 -- TODO current year as default
42 toDoc :: Lang -> ISTEX.Document -> IO HyperdataDocument
43 toDoc la (ISTEX.Document i t a ab d s) = do
44 (utctime, (pub_year, pub_month, pub_day)) <- Date.dateSplit la (maybe (Just "2019") (Just . pack . show) d)
45 pure $ HyperdataDocument (Just "Istex")
52 (Just $ foldl (\x y -> x <> ", " <> y) "" (map ISTEX._author_name a))
53 (Just $ foldl (\x y -> x <> ", " <> y) "" (concat $ (map ISTEX._author_affiliations) a))
54 (Just $ foldl (\x y -> x <> ", " <> y) "" (catMaybes $ map ISTEX._source_title s))
56 (fmap (pack . show) utctime)
63 (Just $ (pack . show) la)