]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Parsers/RIS/Presse.hs
[PARSERS] refactor, split, organize (TODO: tests parsers).
[gargantext.git] / src / Gargantext / Text / Parsers / RIS / Presse.hs
1 {-|
2 Module : Gargantext.Text.Parsers.RIS.Presse
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Presse RIS format parser en enricher.
11
12 -}
13
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
16
17 module Gargantext.Text.Parsers.RIS.Presse (presseEnrich) where
18
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))
32
33 presseDate :: ByteString -> [(ByteString, ByteString)]
34 presseDate str = either (const []) identity $ parseOnly (Date.parserWith "/") str
35
36 presseLang :: ByteString -> [(ByteString, ByteString)]
37 presseLang "Français" = [("language", "FR")]
38 presseLang "English" = [("language", "EN")]
39 presseLang x = [("language", x)]
40
41 presseFields :: ByteString -> ByteString
42 presseFields champs
43 | champs == "AU" = "authors"
44 | champs == "TI" = "title"
45 | champs == "JF" = "source"
46 | champs == "DI" = "doi"
47 | champs == "UR" = "url"
48 | champs == "N2" = "abstract"
49 | otherwise = champs
50
51 {-
52 fixTitle :: [(ByteString, ByteString)] -> [(ByteString, ByteString)]
53 fixTitle ns = ns <> [ti, ab]
54 where
55 ti = case
56 -}