document parsing works now

parent 72a4c71e
# Open Alex Database API Crawler for GarganText # Open Alex Database API Crawler for GarganText
## Compilation
For non-GHC stuff, use Nix.
For GHC, use ghcup and use GHC 8.10.7.
## Running ## Running
``` shell ``` shell
......
...@@ -16,6 +16,10 @@ main = do ...@@ -16,6 +16,10 @@ main = do
"Fetch OpenAlex concepts (https://docs.openalex.org/api-entities/concepts/concept-object)" "Fetch OpenAlex concepts (https://docs.openalex.org/api-entities/concepts/concept-object)"
(const fetchConcepts) (const fetchConcepts)
(pure ()) (pure ())
addCommand "works"
"Fetch OpenAlex works (https://docs.openalex.org/api-entities/works/work-object)"
(const fetchWorks)
(pure ())
runCmd () runCmd ()
...@@ -27,5 +31,13 @@ fetchConcepts _ = do ...@@ -27,5 +31,13 @@ fetchConcepts _ = do
case ec of case ec of
Left err -> putText $ "error: " <> show err Left err -> putText $ "error: " <> show err
Right c -> do Right c -> do
putText "c"
putText $ show c putText $ show c
fetchWorks :: () -> IO ()
fetchWorks _ = do
-- ec <- OA.fetchConcepts (Just 1) (Just 1) Nothing
ew <- OA.fetchWorks (Just 1) (Just 1) (Just "*")
case ew of
Left err -> putText $ "error: " <> show err
Right w -> do
putText $ show w
...@@ -14,6 +14,7 @@ rec { ...@@ -14,6 +14,7 @@ rec {
ps.tqdm ps.tqdm
]); ]);
nonhsBuildInputs = with pkgs; [ nonhsBuildInputs = with pkgs; [
gmp
jupyter jupyter
pythonEnv pythonEnv
zlib zlib
...@@ -21,6 +22,6 @@ rec { ...@@ -21,6 +22,6 @@ rec {
#libPaths = pkgs.lib.makeLibraryPath nonhsBuildInputs; #libPaths = pkgs.lib.makeLibraryPath nonhsBuildInputs;
shell = pkgs.mkShell { shell = pkgs.mkShell {
name = "openalex"; name = "openalex";
buildInputs = hsBuildInputs ++ nonhsBuildInputs; buildInputs = nonhsBuildInputs;
}; };
} }
...@@ -14,7 +14,9 @@ module OpenAlex ...@@ -14,7 +14,9 @@ module OpenAlex
( module OpenAlex.Client ( module OpenAlex.Client
, module OpenAlex.Types , module OpenAlex.Types
-- , fetchConcepts' -- , fetchConcepts'
, fetchConcepts ) , fetchConcepts
, fetchWorks
)
where where
-- import Data.Aeson -- import Data.Aeson
...@@ -27,7 +29,7 @@ import Network.HTTP.Client.TLS (tlsManagerSettings) ...@@ -27,7 +29,7 @@ import Network.HTTP.Client.TLS (tlsManagerSettings)
import Protolude import Protolude
import OpenAlex.Client import OpenAlex.Client
import OpenAlex.ServantClientLogging import OpenAlex.ServantClientLogging
import OpenAlex.Types import OpenAlex.Types (ListOf(..), Page, PerPage, Cursor, Concept, Work)
import Servant.Client (BaseUrl(..), ClientEnv(..), ClientError, Scheme(Https), defaultMakeClientRequest, mkClientEnv, runClientM) import Servant.Client (BaseUrl(..), ClientEnv(..), ClientError, Scheme(Https), defaultMakeClientRequest, mkClientEnv, runClientM)
defaultClientEnv :: IO ClientEnv defaultClientEnv :: IO ClientEnv
...@@ -46,6 +48,11 @@ fetchConcepts mPage mPerPage mCursor = do ...@@ -46,6 +48,11 @@ fetchConcepts mPage mPerPage mCursor = do
env <- defaultClientEnv env <- defaultClientEnv
runClientM (concepts mPage mPerPage mCursor) env runClientM (concepts mPage mPerPage mCursor) env
fetchWorks :: Maybe Page -> Maybe PerPage -> Maybe Cursor -> IO (Either ClientError (ListOf Work))
fetchWorks mPage mPerPage mCursor = do
env <- defaultClientEnv
runClientM (works mPage mPerPage mCursor) env
-- fetchConcepts' :: IO (Either Text (ListOf Concept)) -- fetchConcepts' :: IO (Either Text (ListOf Concept))
-- fetchConcepts' = do -- fetchConcepts' = do
-- manager <- newManager tlsManagerSettings -- manager <- newManager tlsManagerSettings
......
...@@ -16,7 +16,7 @@ import Protolude ...@@ -16,7 +16,7 @@ import Protolude
import Servant.API import Servant.API
import Servant.Client import Servant.Client
import OpenAlex.Types import OpenAlex.Types (Page, PerPage, Cursor, ListOf(..), Concept, Work)
type API_URL = Text type API_URL = Text
apiUrl :: API_URL apiUrl :: API_URL
...@@ -37,9 +37,19 @@ type OpenAlexAPI = ...@@ -37,9 +37,19 @@ type OpenAlexAPI =
-- TODO: filter, search, sort -- TODO: filter, search, sort
:> Get '[JSON] (ListOf Concept) :> Get '[JSON] (ListOf Concept)
-- https://docs.openalex.org/api-entities/works
:<|> "works"
:> QueryParam "page" Page
:> QueryParam "per-page" PerPage
:> QueryParam "cursor" Cursor
-- TODO: filter, search, sort
:> Get '[JSON] (ListOf Work)
openAlexApi :: Proxy OpenAlexAPI openAlexApi :: Proxy OpenAlexAPI
openAlexApi = Proxy openAlexApi = Proxy
concepts :: Maybe Page -> Maybe PerPage -> Maybe Cursor -> ClientM (ListOf Concept) concepts :: Maybe Page -> Maybe PerPage -> Maybe Cursor -> ClientM (ListOf Concept)
concepts {- :<|> fetch -} = client openAlexApi works :: Maybe Page -> Maybe PerPage -> Maybe Cursor -> ClientM (ListOf Work)
concepts :<|> works = client openAlexApi
This diff is collapsed.
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