2 Module : Gargantext.Text.Parsers.RIS.Presse
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Presse RIS format parser en enricher.
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
17 module Gargantext.Text.Parsers.RIS.Presse (presseEnrich) where
19 import Data.Either (either)
20 import Data.Tuple.Extra (first)
21 import Data.Attoparsec.ByteString (parseOnly)
22 import Data.ByteString (ByteString)
23 import Gargantext.Prelude hiding (takeWhile, take)
24 import Gargantext.Text.Parsers.RIS (withField)
25 import qualified Gargantext.Text.Parsers.Date.Attoparsec as Date
26 -------------------------------------------------------------
27 -------------------------------------------------------------
28 presseEnrich :: [(ByteString, ByteString)] -> [(ByteString, ByteString)]
29 presseEnrich = (withField "DA" presseDate)
30 . (withField "LA" presseLang)
31 . (map (first presseFields))
33 presseDate :: ByteString -> [(ByteString, ByteString)]
34 presseDate str = either (const []) identity $ parseOnly (Date.parserWith "/") str
36 presseLang :: ByteString -> [(ByteString, ByteString)]
37 presseLang "Français" = [("language", "FR")]
38 presseLang "English" = [("language", "EN")]
39 presseLang x = [("language", x)]
41 presseFields :: ByteString -> ByteString
43 | champs == "AU" = "authors"
44 | champs == "TI" = "title"
45 | champs == "JF" = "source"
46 | champs == "DI" = "doi"
47 | champs == "UR" = "url"
48 | champs == "N2" = "abstract"
52 fixTitle :: [(ByteString, ByteString)] -> [(ByteString, ByteString)]
53 fixTitle ns = ns <> [ti, ab]