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.Either (Either)
19 import Data.Text (Text)
20 import qualified Data.Text as Text
21 import Servant.Client (ClientError)
23 import Gargantext.Prelude
24 import Gargantext.Core (Lang(..))
25 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
27 import qualified PUBMED as PubMed
28 import qualified PUBMED.Parser as PubMedDoc
32 type Limit = PubMed.Limit
35 -- | TODO put default pubmed query in gargantext.ini
36 -- by default: 10K docs
37 get :: Query -> Maybe Limit -> IO (Either ClientError (Maybe Integer, ConduitT () HyperdataDocument IO ()))
39 eRes <- PubMed.getMetadataWithC q l
40 pure $ (\(len, docsC) -> (len, docsC .| mapC (toDoc EN))) <$> eRes
41 --either (\e -> panic $ "CRAWL: PubMed" <> e) (map (toDoc EN))
42 -- <$> PubMed.getMetadataWithC q l
44 toDoc :: Lang -> PubMedDoc.PubMed -> HyperdataDocument
45 toDoc l (PubMedDoc.PubMed { pubmed_id
46 , pubmed_article = PubMedDoc.PubMedArticle t j as aus
47 , pubmed_date = PubMedDoc.PubMedDate a y m d }
48 ) = HyperdataDocument { _hd_bdd = Just "PubMed"
51 , _hd_uniqId = Just $ Text.pack $ show pubmed_id
52 , _hd_uniqIdBdd = Nothing
55 , _hd_authors = authors aus
56 , _hd_institutes = institutes aus
58 , _hd_abstract = abstract as
59 , _hd_publication_date = Just $ Text.pack $ show a
60 , _hd_publication_year = Just $ fromIntegral y
61 , _hd_publication_month = Just m
62 , _hd_publication_day = Just d
63 , _hd_publication_hour = Nothing
64 , _hd_publication_minute = Nothing
65 , _hd_publication_second = Nothing
66 , _hd_language_iso2 = Just $ (Text.pack . show) l }
68 authors :: [PubMedDoc.Author] -> Maybe Text
70 authors au = Just $ (Text.intercalate ", ")
72 $ map (\n -> PubMedDoc.foreName n <> Just " " <> PubMedDoc.lastName n) au
74 institutes :: [PubMedDoc.Author] -> Maybe Text
75 institutes [] = Nothing
76 institutes au = Just $ (Text.intercalate ", ")
77 $ (map (Text.replace ", " " - "))
79 $ map PubMedDoc.affiliation au
82 abstract :: [Text] -> Maybe Text
84 abstract as' = Just $ Text.intercalate ", " as'