]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core/Text/Corpus/API.hs
[conduit] some work towards migrating file parser to conduit (does not compile)
[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.Hal as HAL
29 import qualified Gargantext.Core.Text.Corpus.API.Isidore as ISIDORE
30 import qualified Gargantext.Core.Text.Corpus.API.Istex as ISTEX
31 import qualified Gargantext.Core.Text.Corpus.API.Pubmed as PUBMED
32 import Servant.Client (ClientError)
33
34 -- | TODO put in gargantext.init
35 default_limit :: Maybe Integer
36 default_limit = Just 10000
37
38 -- | Get External API metadata main function
39 get :: ExternalAPIs
40 -> Lang
41 -> Query
42 -> Maybe Limit
43 -- -> IO [HyperdataDocument]
44 -> IO (Either ClientError (Maybe Integer, ConduitT () HyperdataDocument IO ()))
45 get PubMed _la q _l = PUBMED.get q Nothing
46 --docs <- PUBMED.get q default_limit -- EN only by default
47 --pure (Just $ fromIntegral $ length docs, yieldMany docs)
48 get HAL la q _l = HAL.getC la q Nothing
49 get IsTex la q _l = do
50 docs <- ISTEX.get la q default_limit
51 pure $ Right (Just $ fromIntegral $ length docs, yieldMany docs)
52 get Isidore la q _l = do
53 docs <- ISIDORE.get la (fromIntegral <$> default_limit) (Just q) Nothing
54 pure $ Right (Just $ fromIntegral $ length docs, yieldMany docs)
55 get _ _ _ _ = undefined
56
57 -- | Some Sugar for the documentation
58 type Query = PUBMED.Query
59 type Limit = PUBMED.Limit