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