Commit 27fab5b6 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[search] parse dates correctly

parent ceffe8d3
Pipeline #1932 failed with stage
in 81 minutes and 55 seconds
......@@ -176,7 +176,6 @@ library:
- pandoc
- parallel
- parsec
- parsec3-numbers
- patches-class
- patches-map
- path
......
......@@ -108,8 +108,14 @@ hyperdataDocumentFromFrameWrite (HyperdataFrame { _hf_base, _hf_frame_id }, cont
case parseLines contents of
Left _ -> Left "Error parsing node"
Right (Parsed { authors, contents = c, date, source, title = t }) ->
let authorJoinSingle (Author { firstName, lastName }) = T.concat [ lastName, ", ", firstName ] in
let authors' = T.concat $ authorJoinSingle <$> authors in
let authorJoinSingle (Author { firstName, lastName }) = T.concat [ lastName, ", ", firstName ]
authors' = T.concat $ authorJoinSingle <$> authors
date' = (\(Date { year, month, day }) -> T.concat [ T.pack $ show year, "-"
, T.pack $ show month, "-"
, T.pack $ show day ]) <$> date
year' = fromIntegral $ maybe 2021 (\(Date { year }) -> year) date
month' = fromIntegral $ maybe 10 (\(Date { month }) -> month) date
day' = fromIntegral $ maybe 4 (\(Date { day }) -> day) date in
Right HyperdataDocument { _hd_bdd = Just "FrameWrite"
, _hd_doi = Nothing
, _hd_url = Nothing
......@@ -121,10 +127,10 @@ hyperdataDocumentFromFrameWrite (HyperdataFrame { _hf_base, _hf_frame_id }, cont
, _hd_institutes = Nothing
, _hd_source = source
, _hd_abstract = Just c
, _hd_publication_date = date
, _hd_publication_year = Just 2021 -- TODO
, _hd_publication_month = Just 10 -- TODO
, _hd_publication_day = Just 4 -- TODO
, _hd_publication_date = date'
, _hd_publication_year = Just year'
, _hd_publication_month = Just month'
, _hd_publication_day = Just day'
, _hd_publication_hour = Nothing
, _hd_publication_minute = Nothing
, _hd_publication_second = Nothing
......
......@@ -6,9 +6,8 @@ import Data.Either
import Data.Maybe
import Data.Text hiding (foldl)
import Gargantext.Prelude
import Prelude ((++))
import Prelude ((++), read)
import Text.Parsec hiding (Line)
import Text.Parsec.Number (number)
import Text.Parsec.String
......@@ -58,14 +57,14 @@ parseLinesSampleUnordered = parseLines sampleUnordered
data Author =
Author { firstName :: Text
, lastName :: Text }
, lastName :: Text }
deriving (Show)
data Parsed =
Parsed { title :: Text
, authors :: [Author]
, date :: Maybe Text
, source :: Maybe Text
Parsed { title :: Text
, authors :: [Author]
, date :: Maybe Date
, source :: Maybe Text
, contents :: Text }
deriving (Show)
......@@ -78,9 +77,9 @@ emptyParsed =
, contents = "" }
data Date =
Date { year :: Int
, month :: Int
, day :: Int }
Date { year :: Integer
, month :: Integer
, day :: Integer }
deriving (Show)
data Line =
......@@ -176,18 +175,23 @@ datePrefixP :: Parser [Char]
datePrefixP = do
_ <- string "^@@date:"
many (char ' ')
dateP :: Parser [Char]
dateP :: Parser Date
dateP = try datePrefixP
*> many (noneOf "\n")
*> dateISOP
-- *> many (noneOf "\n")
dateISOP :: Parser Date
dateISOP = do
year <- number
year <- rd <$> number
_ <- char '-'
month <- number
month <- rd <$> number
_ <- char '-'
day <- number
day <- rd <$> number
_ <- many (noneOf "\n" )
pure $ Date { year, month, day }
where
rd = read :: [Char] -> Integer
number = many1 digit
sourcePrefixP :: Parser [Char]
sourcePrefixP = do
......
......@@ -99,7 +99,6 @@ extra-deps:
- logging-effect-1.3.12@sha256:72d168dd09887649ba9501627219b6027cbec2d5541931555b7885b133785ce3,1679
- MissingH-1.4.3.0@sha256:32f9892ec98cd21df4f4d3ed8d95a3831ae74287ea0641d6f09b2dc6ef061d39,4859
- monoid-extras-0.5.1@sha256:438dbfd7b4dce47d8f0ca577f56caf94bd1e21391afa545cad09fe7cf2e5793d,2333
- parsec-numbers-0.1@sha256:60fa05b1c16050dffd0e28cecb682a021eeec1be6f34dc9d901a38c90182f289,727
- rake-0.0.1@sha256:3380f6567fb17505d1095b7f32222c0b631fa04126ad39726c84262da99c08b3,2025
- servant-cassava-0.10.1@sha256:07e7b6ca67cf57dcb4a0041a399a25d058844505837c6479e01d62be59d01fdf,1665
- servant-flatten-0.2@sha256:276896f7c5cdec5b8f8493f6205fded0cc602d050b58fdb09a6d7c85c3bb0837,1234
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment