]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/API/Pubmed.hs
[refactoring] add some default extensions to package.yaml
[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
13 module Gargantext.Text.Corpus.API.Pubmed
14 where
15
16 import Data.Maybe
17 import Data.Text (Text)
18 import Gargantext.Prelude
19 import Gargantext.Core (Lang(..))
20 import Gargantext.Database.Admin.Types.Node (HyperdataDocument(..))
21 import qualified Data.Text as Text
22
23 import qualified PUBMED as PubMed
24 import qualified PUBMED.Parser as PubMedDoc
25
26
27 type Query = Text
28 type Limit = PubMed.Limit
29
30 get :: Query -> Maybe Limit -> IO [HyperdataDocument]
31 get q l = either (\e -> panic $ "CRAWL: PubMed" <> e) (map (toDoc EN)) <$> PubMed.getMetadataWith q l
32
33 toDoc :: Lang -> PubMedDoc.PubMed -> HyperdataDocument
34 toDoc l (PubMedDoc.PubMed (PubMedDoc.PubMedArticle t j as aus)
35 (PubMedDoc.PubMedDate a y m d)
36 ) = HyperdataDocument (Just "PubMed")
37 Nothing
38 Nothing
39 Nothing
40 Nothing
41 Nothing
42 t
43 (authors aus)
44 Nothing
45 j
46 (abstract as)
47 (Just $ Text.pack $ show a)
48 (Just $ fromIntegral y)
49 (Just m)
50 (Just d)
51 Nothing
52 Nothing
53 Nothing
54 (Just $ (Text.pack . show) l)
55 where
56 authors :: Maybe [PubMedDoc.Author] -> Maybe Text
57 authors aus' = case aus' of
58 Nothing -> Nothing
59 Just au -> Just $ (Text.intercalate ", ") $ catMaybes $ map PubMedDoc.foreName au
60
61 abstract :: Maybe [Text] -> Maybe Text
62 abstract as' = fmap (Text.intercalate ", ") as'
63