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

[parser] add pubmed_id

parent 6495eb7a
......@@ -36,9 +36,10 @@ parseDocCount :: TL.Text -> Maybe Integer
parseDocCount txt = TR.readMaybe $ T.unpack $ txt ^. TTL.html . TTL.allNamed (only "eSearchResult") . namedEl "Count" . TTL.contents
data PubMed =
PubMed { pubmed_article :: PubMedArticle
, pubmed_date :: PubMedDate
} deriving Show
PubMed { pubmed_id :: Int
, pubmed_article :: PubMedArticle
, pubmed_date :: PubMedDate
} deriving Show
data PubMedArticle =
PubMedArticle { pubmed_title :: Maybe T.Text
......@@ -71,11 +72,17 @@ parsePubMed :: TL.Text -> [PubMed]
parsePubMed txt = catMaybes $ txt ^.. pubmedArticle . to pubMed
where
pubmedArticle = TTL.html . TTL.allNamed (only "PubmedArticleSet") . TTL.allNamed (only "PubmedArticle")
pubMed el = PubMed <$> el ^? article . to pubMedArticle
pubMed el = PubMed <$> el ^? articleId . to pubMedId
<*> el ^? article . to pubMedArticle
<*> el ^? pubDate . to pubMedDate
where
article = namedEl "MedlineCitation" . namedEl "Article"
medline = namedEl "MedlineCitation"
article = medline . namedEl "Article"
articleId = medline . namedEl "PMID"
pubDate = namedEl "PubmedData" . namedEl "History" . namedEl "PubMedPubDate" . TTL.attributed (ix "PubStatus" . only "pubmed")
pubMedId el = case (TR.readMaybe $ T.unpack $ el ^. TTL.contents) of
Nothing -> panic $ "Cannot parse id: " <> (T.unpack $ el ^. TTL.contents)
Just id -> id
pubMedDate el = PubMedDate { pubmedDate_date = jour y m d
, pubmedDate_year = y
, pubmedDate_month = m
......
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