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)
22 import Data.Text (Text)
23 import Gargantext.Prelude
24 import Gargantext.Core (Lang(..))
25 import Gargantext.Database.Types.Node (HyperdataDocument(..))
26 import Test.QuickCheck.Arbitrary
27 import Test.QuickCheck (elements)
29 import qualified Data.Text as Text
31 import qualified PUBMED as PubMed
32 import qualified PUBMED.Parser as Doc
33 --import qualified Gargantext.Text.Corpus.API.Isidore as Isidore
35 data ExternalAPIs = All
39 | IsidoreQuery | IsidoreAuth
40 deriving (Show, Eq, Enum, Bounded, Generic)
42 instance FromJSON ExternalAPIs
43 instance ToJSON ExternalAPIs
45 externalAPIs :: [ExternalAPIs]
46 externalAPIs = [minBound..maxBound]
48 instance Arbitrary ExternalAPIs
50 arbitrary = elements externalAPIs
52 instance ToSchema ExternalAPIs
55 type Limit = PubMed.Limit
57 get :: ExternalAPIs -> Query -> Maybe Limit -> IO [HyperdataDocument]
58 get PubMed q l = either (\e -> panic $ "CRAWL: PubMed" <> e) (map (toDoc EN)) <$> PubMed.crawler q l
61 toDoc :: Lang -> Doc.PubMed -> HyperdataDocument
62 toDoc l (Doc.PubMed (Doc.PubMedArticle t j as aus)
63 (Doc.PubMedDate a y m d)
64 ) = HyperdataDocument (Just "PubMed")
75 (Just $ Text.pack $ show a)
76 (Just $ fromIntegral y)
82 (Just $ (Text.pack . show) l)
84 authors :: Maybe [Doc.Author] -> Maybe Text
85 authors aus' = case aus' of
87 Just au -> Just $ (Text.intercalate ", ") $ catMaybes $ map Doc.foreName au
89 abstract :: Maybe [Text] -> Maybe Text
90 abstract as' = fmap (Text.intercalate ", ") as'