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