1 {-# LANGUAGE OverloadedStrings #-}
3 module Data.Gargantext.Parsers.WOS (wosParser) where
5 -- TOFIX : Should import Data.Gargantext.Prelude here
6 import Prelude hiding (takeWhile, take, concat, readFile, lines, concat)
8 import qualified Data.List as DL
10 import Data.Monoid ((<>))
11 import Data.Attoparsec.ByteString (Parser, try, string
14 import Data.Attoparsec.ByteString.Char8 (anyChar, isEndOfLine)
15 import Data.ByteString (ByteString, concat)
16 import Data.ByteString.Char8 (pack)
18 import Control.Applicative
20 --import Data.Gargantext.Types
22 -- | wosParser parses ISI format from
23 -- Web Of Science Database
24 wosParser :: Parser [[(ByteString, ByteString)]]
26 -- TODO Warning if version /= 1.0
27 -- FIXME anyChar (string ..) /= exact string "\nVR 1.0" ?
28 _ <- manyTill anyChar (string $ pack "\nVR 1.0")
29 ns <- many1 notice <* (string $ pack "\nEF" )
32 notice :: Parser [(ByteString, ByteString)]
33 notice = start *> fields <* end
35 start :: Parser ByteString
36 start = "\nPT " *> takeTill isEndOfLine
39 end = manyTill anyChar (string $ pack "\nER\n")
42 fields :: Parser [(ByteString, ByteString)]
45 field :: Parser (ByteString, ByteString)
47 name <- "\n" *> take 2 <* " "
48 txt <- takeTill isEndOfLine
50 let txts' = case DL.length txts > 0 of
53 pure (translate name, concat ([txt] <> txts'))
56 lines :: Parser [ByteString]
59 line :: Parser ByteString
60 line = "\n " *> takeTill isEndOfLine
62 translate :: ByteString -> ByteString
64 | champs == "AU" = "author"
65 | champs == "TI" = "title"
66 | champs == "SO" = "source"
67 | champs == "DI" = "doi"
68 | champs == "PD" = "publication_date"
69 | champs == "AB" = "abstract"