2 Module : Gargantext.Text.Corpus.API.Pubmed
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.Pubmed
19 import Data.Text (Text)
20 import Gargantext.Prelude
21 import Gargantext.Core (Lang(..))
22 import Gargantext.Database.Admin.Types.Node (HyperdataDocument(..))
23 import qualified Data.Text as Text
25 import qualified PUBMED as PubMed
26 import qualified PUBMED.Parser as PubMedDoc
30 type Limit = PubMed.Limit
32 get :: Query -> Maybe Limit -> IO [HyperdataDocument]
33 get q l = either (\e -> panic $ "CRAWL: PubMed" <> e) (map (toDoc EN)) <$> PubMed.getMetadataWith q l
35 toDoc :: Lang -> PubMedDoc.PubMed -> HyperdataDocument
36 toDoc l (PubMedDoc.PubMed (PubMedDoc.PubMedArticle t j as aus)
37 (PubMedDoc.PubMedDate a y m d)
38 ) = HyperdataDocument (Just "PubMed")
49 (Just $ Text.pack $ show a)
50 (Just $ fromIntegral y)
56 (Just $ (Text.pack . show) l)
58 authors :: Maybe [PubMedDoc.Author] -> Maybe Text
59 authors aus' = case aus' of
61 Just au -> Just $ (Text.intercalate ", ") $ catMaybes $ map PubMedDoc.foreName au
63 abstract :: Maybe [Text] -> Maybe Text
64 abstract as' = fmap (Text.intercalate ", ") as'