]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/API.hs
[FACTO] Type Class and some Instances : Flow Corpus.
[gargantext.git] / src / Gargantext / Text / Corpus / API.hs
1 {-|
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
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE NoImplicitPrelude #-}
13 {-# LANGUAGE OverloadedStrings #-}
14 {-# LANGUAGE DeriveGeneric #-}
15
16 module Gargantext.Text.Corpus.API
17 where
18
19 import GHC.Generics (Generic)
20 import Data.Aeson
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)
28 import Data.Swagger
29
30 import qualified PUBMED as PubMed
31 import qualified PUBMED.Parser as Doc (PubMed)
32 import qualified Gargantext.Text.Corpus.API.Isidore as Isidore
33
34 data ExternalAPIs = All
35 | PubMed
36 | HAL
37 -- | IsTex
38 | IsidoreQuery | IsidoreAuth
39 deriving (Show, Eq, Enum, Bounded, Generic)
40
41 instance FromJSON ExternalAPIs
42 instance ToJSON ExternalAPIs
43
44 externalAPIs :: [ExternalAPIs]
45 externalAPIs = [minBound..maxBound]
46
47 instance Arbitrary ExternalAPIs
48 where
49 arbitrary = elements externalAPIs
50
51 instance ToSchema ExternalAPIs
52
53 type Query = Text
54 type Limit = PubMed.Limit
55
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
58 get _ _ _ = undefined
59
60 toDoc :: FlowCorpus a => Lang -> Doc.PubMed -> a
61 toDoc = undefined
62