Commit 9cdba642 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[parser] fix abstract/authors type (no Maybe for lists)

Also, use deepContent to get article title and abstracts' contents.
parent bbaddaba
......@@ -20,6 +20,8 @@ contentWithChildren :: Prism' Node T.Text
contentWithChildren = prism' NodeContent $ \case { NodeContent c -> Just c
; NodeElement e -> Just $ e ^. TTL.children . traverse . contentWithChildren }
deepContent = TTL.children . traverse . contentWithChildren
parseDocIds :: TL.Text -> [Integer]
parseDocIds txt = map (\s -> read (T.unpack s) :: Integer) parsed
where
......@@ -33,8 +35,8 @@ data PubMed =
data PubMedArticle =
PubMedArticle { pubmed_title :: Maybe T.Text
, pubmed_journal :: Maybe T.Text
, pubmed_abstract :: Maybe [T.Text] -- TODO No Maybe?
, pubmed_authors :: Maybe [Author] -- TODO No Maybe?
, pubmed_abstract :: [T.Text]
, pubmed_authors :: [Author]
}
deriving (Show)
......@@ -76,12 +78,14 @@ parsePubMed txt = catMaybes $ txt ^.. pubmedArticle . to pubMed
d = read $ T.unpack $ el ^. namedEl "Day" . TTL.contents
pubMedArticle el = PubMedArticle { pubmed_title = Just $ el ^. title
, pubmed_journal = el ^? journalTitle
, pubmed_abstract = Just $ el ^.. abstract
, pubmed_authors = Just $ el ^.. authors . to author }
, pubmed_abstract = el ^.. abstract
, pubmed_authors = el ^.. authors . to author }
where
journalTitle = namedEl "Journal" . namedEl "Title" . TTL.contents
title = namedEl "ArticleTitle" . TTL.children . traverse . contentWithChildren
abstract = namedEl "Abstract" . namedEl "AbstractText" . TTL.contents
title = namedEl "ArticleTitle" . deepContent
abstract = namedEl "Abstract" . TTL.allNamed (only "AbstractText") . to abstractContent
where
abstractContent el = el ^. deepContent
authors = namedEl "AuthorList" . TTL.allNamed (only "Author")
author el = Author { lastName = el ^? lastName
, foreName = el ^? firstName
......
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