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 qualified Data.Text as Text
22 import Gargantext.Prelude
23 import Gargantext.Core (Lang(..))
24 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
26 import qualified PUBMED as PubMed
27 import qualified PUBMED.Parser as PubMedDoc
31 type Limit = PubMed.Limit
33 get :: Query -> Maybe Limit -> IO [HyperdataDocument]
34 get q l = either (\e -> panic $ "CRAWL: PubMed" <> e) (map (toDoc EN)) <$> PubMed.getMetadataWith q l
36 toDoc :: Lang -> PubMedDoc.PubMed -> HyperdataDocument
37 toDoc l (PubMedDoc.PubMed (PubMedDoc.PubMedArticle t j as aus)
38 (PubMedDoc.PubMedDate a y m d)
39 ) = HyperdataDocument (Just "PubMed")
50 (Just $ Text.pack $ show a)
51 (Just $ fromIntegral y)
57 (Just $ (Text.pack . show) l)
59 authors :: Maybe [PubMedDoc.Author] -> Maybe Text
60 authors aus' = case aus' of
62 Just au -> Just $ (Text.intercalate ", ") $ catMaybes $ map PubMedDoc.foreName au
64 abstract :: Maybe [Text] -> Maybe Text
65 abstract as' = fmap (Text.intercalate ", ") as'