]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/API.hs
[FEAT] Learn function to export models
[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.Maybe
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)
28 import Data.Swagger
29 import qualified Data.Text as Text
30
31 import qualified PUBMED as PubMed
32 import qualified PUBMED.Parser as Doc
33 --import qualified Gargantext.Text.Corpus.API.Isidore as Isidore
34
35 data ExternalAPIs = All
36 | PubMed
37 | HAL
38 -- | IsTex
39 | IsidoreQuery | IsidoreAuth
40 deriving (Show, Eq, Enum, Bounded, Generic)
41
42 instance FromJSON ExternalAPIs
43 instance ToJSON ExternalAPIs
44
45 externalAPIs :: [ExternalAPIs]
46 externalAPIs = [minBound..maxBound]
47
48 instance Arbitrary ExternalAPIs
49 where
50 arbitrary = elements externalAPIs
51
52 instance ToSchema ExternalAPIs
53
54 type Query = Text
55 type Limit = PubMed.Limit
56
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
59 get _ _ _ = undefined
60
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")
65 Nothing
66 Nothing
67 Nothing
68 Nothing
69 Nothing
70 t
71 (authors aus)
72 Nothing
73 j
74 (abstract as)
75 (Just $ Text.pack $ show a)
76 (Just $ fromIntegral y)
77 (Just m)
78 (Just d)
79 Nothing
80 Nothing
81 Nothing
82 (Just $ (Text.pack . show) l)
83 where
84 authors :: Maybe [Doc.Author] -> Maybe Text
85 authors aus' = case aus' of
86 Nothing -> Nothing
87 Just au -> Just $ (Text.intercalate ", ") $ catMaybes $ map Doc.foreName au
88
89 abstract :: Maybe [Text] -> Maybe Text
90 abstract as' = fmap (Text.intercalate ", ") as'
91
92
93
94