]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/API/Pubmed.hs
[DB|WIP] fix Tree RootId
[gargantext.git] / src / Gargantext / Text / Corpus / API / Pubmed.hs
1 {-|
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
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE NoImplicitPrelude #-}
13 {-# LANGUAGE OverloadedStrings #-}
14
15 module Gargantext.Text.Corpus.API.Pubmed
16 where
17
18 import Data.Maybe
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
24
25 import qualified PUBMED as PubMed
26 import qualified PUBMED.Parser as PubMedDoc
27
28
29 type Query = Text
30 type Limit = PubMed.Limit
31
32 get :: Query -> Maybe Limit -> IO [HyperdataDocument]
33 get q l = either (\e -> panic $ "CRAWL: PubMed" <> e) (map (toDoc EN)) <$> PubMed.getMetadataWith q l
34
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")
39 Nothing
40 Nothing
41 Nothing
42 Nothing
43 Nothing
44 t
45 (authors aus)
46 Nothing
47 j
48 (abstract as)
49 (Just $ Text.pack $ show a)
50 (Just $ fromIntegral y)
51 (Just m)
52 (Just d)
53 Nothing
54 Nothing
55 Nothing
56 (Just $ (Text.pack . show) l)
57 where
58 authors :: Maybe [PubMedDoc.Author] -> Maybe Text
59 authors aus' = case aus' of
60 Nothing -> Nothing
61 Just au -> Just $ (Text.intercalate ", ") $ catMaybes $ map PubMedDoc.foreName au
62
63 abstract :: Maybe [Text] -> Maybe Text
64 abstract as' = fmap (Text.intercalate ", ") as'
65