Commit 233fb199 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[refactoring] add default-extensions to packages, some refactoring

parent a9d8e08a
{-# LANGUAGE OverloadedStrings #-}
module Main where
import PUBMED (getMetadataWith)
......
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.31.2.
-- This file has been generated from package.yaml by hpack version 0.34.4.
--
-- see: https://github.com/sol/hpack
--
-- hash: 4bb73f43a66d509480c9a672fe457ad8be7cb2d27c8b0892e234b8ac088a2a44
name: crawlerPubMed
version: 0.1.0.0
......@@ -30,10 +28,16 @@ library
PUBMED
PUBMED.Client
PUBMED.Parser
PUBMED.Test
other-modules:
Paths_crawlerPubMed
hs-source-dirs:
src
default-extensions:
DataKinds
MultiParamTypeClasses
OverloadedStrings
TypeOperators
build-depends:
attoparsec
, base >=4.7 && <5
......@@ -56,10 +60,13 @@ library
executable crawlerPubMed-exe
main-is: Main.hs
other-modules:
Paths_crawlerPubMed
hs-source-dirs:
app
default-extensions:
DataKinds
MultiParamTypeClasses
OverloadedStrings
TypeOperators
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
attoparsec
......@@ -89,6 +96,11 @@ test-suite crawlerPubMed-test
Paths_crawlerPubMed
hs-source-dirs:
test
default-extensions:
DataKinds
MultiParamTypeClasses
OverloadedStrings
TypeOperators
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
attoparsec
......
......@@ -14,6 +14,12 @@ extra-source-files:
# synopsis: Short description of your package
# category: Web
default-extensions:
- DataKinds
- MultiParamTypeClasses
- OverloadedStrings
- TypeOperators
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
......@@ -51,6 +57,10 @@ executables:
- -with-rtsopts=-N
dependencies:
- crawlerPubMed
# https://stackoverflow.com/questions/67519851/multiple-files-use-the-same-module-name
when:
- condition: false
other-modules: Paths_crawlerPubMed
tests:
crawlerPubMed-test:
......@@ -62,3 +72,4 @@ tests:
- -with-rtsopts=-N
dependencies:
- crawlerPubMed
{-# LANGUAGE OverloadedStrings #-}
module PUBMED where
import Prelude hiding (takeWhile)
......@@ -26,6 +24,17 @@ import qualified Data.ByteString as DB
import qualified Data.Text as T
import qualified Data.List as List
pmHost :: String
pmHost = "eutils.ncbi.nlm.nih.gov"
pmSearchPath :: String
pmSearchPath = "entrez/eutils"
pmPort :: Int
pmPort = 443
defaultEnv = do
manager' <- newManager tlsManagerSettings
pure $ mkClientEnv manager' $ BaseUrl Https pmHost pmPort pmSearchPath
-- | API main function
getMetadataWith :: Text -> Maybe Limit -> IO (Either Text [PubMed])
getMetadataWith = runSimpleFindPubmedAbstractRequest
......@@ -72,10 +81,10 @@ runSimpleFetchPubmedAbstractRequest ::
[Integer]
-> IO (Either Text [PubMed])
runSimpleFetchPubmedAbstractRequest ids = do
manager' <- newManager tlsManagerSettings
env <- defaultEnv
res <- runClientM
(fetch (Just "pubmed") (Just "abstract") ids)
(mkClientEnv manager' $ BaseUrl Https "eutils.ncbi.nlm.nih.gov" 443 "entrez/eutils")
env
case res of
(Left err) -> pure (Left . T.pack $ show err)
(Right (BsXml abs)) ->
......@@ -89,13 +98,18 @@ runSimpleFetchPubmedAbstractRequest ids = do
runSimpleFindPubmedAbstractRequest :: Text -> Maybe Limit -> IO (Either Text [PubMed])
runSimpleFindPubmedAbstractRequest query limit = do
manager' <- newManager tlsManagerSettings
eDocIds <- searchDocIds query limit
case eDocIds of
Left err -> pure $ Left err
Right docIds -> runMultipleFPAR docIds
searchDocIds :: Text -> Maybe Limit -> IO (Either Text [Integer])
searchDocIds query limit = do
env <- defaultEnv
res <- runClientM
(search (Just query) limit)
(mkClientEnv manager' $ BaseUrl Https "eutils.ncbi.nlm.nih.gov" 443 "entrez/eutils")
env
case res of
(Left err) -> pure (Left $ T.pack $ show err)
(Right (BsXml docs)) -> do
let docIds = runParser parseDocId docs
runMultipleFPAR docIds
pure $ Right $ runParser parseDocId docs
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module PUBMED.Client where
import Servant.API
......
{-# LANGUAGE OverloadedStrings #-}
module PUBMED.Parser where
import Text.XML.Stream.Parse
......
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