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