]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/API/Istex.hs
Merge branch 'patch-1' of ssh://gitlab.iscpif.fr:20022/gargantext/haskell-gargantext...
[gargantext.git] / src / Gargantext / Text / Corpus / API / Istex.hs
1 {-|
2 Module : Gargantext.Text.Corpus.API.Istex
3 Description : Pubmed API connection
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
15 module Gargantext.Text.Corpus.API.Istex
16 where
17
18 import Data.Either (either)
19 import Data.Maybe
20 import Data.List (concat)
21 import Data.Maybe (catMaybes)
22 import Data.Text (Text, pack)
23 import Gargantext.Prelude
24 import Gargantext.Core (Lang(..))
25 import qualified Gargantext.Text.Corpus.Parsers.Date as Date
26 import Gargantext.Database.Types.Node (HyperdataDocument(..))
27
28 import qualified ISTEX as ISTEX
29 import qualified ISTEX.Client as ISTEX
30
31 get :: Lang -> Text -> Maybe Integer -> IO [HyperdataDocument]
32 get la q ml = do
33 docs <- ISTEX.getMetadataWith q (fromIntegral <$> ml)
34 either (panic . pack . show) (toDoc' la) docs
35
36 toDoc' :: Lang -> ISTEX.Documents -> IO [HyperdataDocument]
37 toDoc' la docs' = do
38 --printDebug "ISTEX" (ISTEX._documents_total docs')
39 mapM (toDoc la) (ISTEX._documents_hits docs')
40
41 -- | TODO remove dateSplit here
42 -- TODO current year as default
43 toDoc :: Lang -> ISTEX.Document -> IO HyperdataDocument
44 toDoc la (ISTEX.Document i t a ab d s) = do
45 (utctime, (pub_year, pub_month, pub_day)) <- Date.dateSplit la (maybe (Just "2019") (Just . pack . show) d)
46 pure $ HyperdataDocument (Just "Istex")
47 (Just i)
48 Nothing
49 Nothing
50 Nothing
51 Nothing
52 t
53 (Just $ foldl (\x y -> x <> ", " <> y) "" (map ISTEX._author_name a))
54 (Just $ foldl (\x y -> x <> ", " <> y) "" (concat $ (map ISTEX._author_affiliations) a))
55 (Just $ foldl (\x y -> x <> ", " <> y) "" (catMaybes $ map ISTEX._source_title s))
56 ab
57 (fmap (pack . show) utctime)
58 pub_year
59 pub_month
60 pub_day
61 Nothing
62 Nothing
63 Nothing
64 (Just $ (pack . show) la)