2 Module : Gargantext.Core.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
13 module Gargantext.Core.Text.Corpus.API.Pubmed
17 import Data.Text (Text)
18 import qualified Data.Text as Text
20 import Gargantext.Prelude
21 import Gargantext.Core (Lang(..))
22 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
24 import qualified PUBMED as PubMed
25 import qualified PUBMED.Parser as PubMedDoc
29 type Limit = PubMed.Limit
32 -- | TODO put default pubmed query in gargantext.ini
33 -- by default: 10K docs
34 get :: Query -> Maybe Limit -> IO [HyperdataDocument]
35 get q l = either (\e -> panic $ "CRAWL: PubMed" <> e) (map (toDoc EN))
36 <$> PubMed.getMetadataWith q l
38 toDoc :: Lang -> PubMedDoc.PubMed -> HyperdataDocument
39 toDoc l (PubMedDoc.PubMed (PubMedDoc.PubMedArticle t j as aus)
40 (PubMedDoc.PubMedDate a y m d)
41 ) = HyperdataDocument (Just "PubMed")
52 (Just $ Text.pack $ show a)
53 (Just $ fromIntegral y)
59 (Just $ (Text.pack . show) l)
61 authors :: Maybe [PubMedDoc.Author] -> Maybe Text
62 authors aus' = case aus' of
64 Just au -> Just $ (Text.intercalate ", ")
66 $ map (\n -> PubMedDoc.foreName n <> Just " " <> PubMedDoc.lastName n) au
68 institutes :: Maybe [PubMedDoc.Author] -> Maybe Text
69 institutes aus' = case aus' of
71 Just au -> Just $ (Text.intercalate ", ")
72 $ (map (Text.replace ", " " - "))
74 $ map PubMedDoc.affiliation au
77 abstract :: Maybe [Text] -> Maybe Text
78 abstract as' = fmap (Text.intercalate ", ") as'