]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core/Text/Corpus/API.hs
Merge remote-tracking branch 'origin/121-dev-arxiv' into dev-merge
[gargantext.git] / src / Gargantext / Core / Text / Corpus / API.hs
1 {-|
2 Module : Gargantext.Core.Text.Corpus.API
3 Description : All crawlers of Gargantext in one file.
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 module Gargantext.Core.Text.Corpus.API
13 ( ExternalAPIs(..)
14 , Query
15 , Limit
16 , get
17 , externalAPIs
18 )
19 where
20
21 import Conduit
22 import Data.Either (Either(..))
23 import Data.Maybe
24 import Gargantext.API.Admin.Orchestrator.Types (ExternalAPIs(..), externalAPIs)
25 import Gargantext.Core (Lang(..))
26 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
27 import Gargantext.Prelude
28 import qualified Gargantext.Core.Text.Corpus.API.Arxiv as Arxiv
29 import qualified Gargantext.Core.Text.Corpus.API.Hal as HAL
30 import qualified Gargantext.Core.Text.Corpus.API.Isidore as ISIDORE
31 import qualified Gargantext.Core.Text.Corpus.API.Istex as ISTEX
32 import qualified Gargantext.Core.Text.Corpus.API.Pubmed as PUBMED
33 import Servant.Client (ClientError)
34
35 -- | Get External API metadata main function
36 get :: ExternalAPIs
37 -> Lang
38 -> Query
39 -> Maybe Limit
40 -- -> IO [HyperdataDocument]
41 -> IO (Either ClientError (Maybe Integer, ConduitT () HyperdataDocument IO ()))
42 get PubMed _la q limit = PUBMED.get q limit
43 --docs <- PUBMED.get q default_limit -- EN only by default
44 --pure (Just $ fromIntegral $ length docs, yieldMany docs)
45 get Arxiv la q limit = Arxiv.get la q (fromIntegral <$> limit)
46 get HAL la q limit = HAL.getC la q limit
47 get IsTex la q limit = do
48 docs <- ISTEX.get la q limit
49 pure $ Right (Just $ fromIntegral $ length docs, yieldMany docs)
50 get Isidore la q limit = do
51 docs <- ISIDORE.get la (fromIntegral <$> limit) (Just q) Nothing
52 pure $ Right (Just $ fromIntegral $ length docs, yieldMany docs)
53 get _ _ _ _ = undefined
54
55 -- | Some Sugar for the documentation
56 type Query = PUBMED.Query
57 type Limit = PUBMED.Limit