2 Module : Gargantext.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
12 {-# LANGUAGE NoImplicitPrelude #-}
13 {-# LANGUAGE OverloadedStrings #-}
14 {-# LANGUAGE DeriveGeneric #-}
16 module Gargantext.Text.Corpus.API
19 import GHC.Generics (Generic)
21 import Data.Text (Text)
22 import Gargantext.Prelude
23 import Gargantext.Core (Lang(..))
24 import Gargantext.Core.Flow (FlowCorpus)
25 import Gargantext.Database.Types.Node (HyperdataDocument)
26 import Test.QuickCheck.Arbitrary
27 import Test.QuickCheck (elements)
30 import qualified PUBMED as PubMed
31 import qualified PUBMED.Parser as Doc (PubMed)
32 import qualified Gargantext.Text.Corpus.API.Isidore as Isidore
34 data ExternalAPIs = All
38 | IsidoreQuery | IsidoreAuth
39 deriving (Show, Eq, Enum, Bounded, Generic)
41 instance FromJSON ExternalAPIs
42 instance ToJSON ExternalAPIs
44 externalAPIs :: [ExternalAPIs]
45 externalAPIs = [minBound..maxBound]
47 instance Arbitrary ExternalAPIs
49 arbitrary = elements externalAPIs
51 instance ToSchema ExternalAPIs
54 type Limit = PubMed.Limit
56 get :: FlowCorpus a => ExternalAPIs -> Query -> Maybe Limit -> IO [a]
57 get PubMed q l = either (\e -> panic $ "CRAWL: PubMed" <> e) (map (toDoc EN)) <$> PubMed.crawler q l
60 toDoc :: FlowCorpus a => Lang -> Doc.PubMed -> a