Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
openalex
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
crawlers
openalex
Commits
0083c02d
Verified
Commit
0083c02d
authored
Jun 29, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement the 'search' querystring
parent
723a641f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
27 deletions
+52
-27
Main.hs
app/Main.hs
+22
-13
OpenAlex.hs
src/OpenAlex.hs
+13
-10
Client.hs
src/OpenAlex/Client.hs
+15
-3
Types.hs
src/OpenAlex/Types.hs
+1
-0
Utils.hs
src/OpenAlex/Utils.hs
+1
-1
No files found.
app/Main.hs
View file @
0083c02d
...
...
@@ -20,9 +20,18 @@ import Protolude
import
qualified
OpenAlex
as
OA
import
qualified
OpenAlex.Types
as
OA
data
Options
=
Options
{
filter
::
Maybe
OA
.
Filter
,
search
::
Maybe
OA
.
Search
}
main
::
IO
()
main
=
do
let
filterHelp
=
help
"Filter, for example: display_name.search:einstein , see https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/filter-entity-lists"
let
commonOptions
=
Options
<$>
optional
(
strOption
(
long
"filter"
))
<*>
optional
(
strOption
(
long
"search"
))
(
opts
,
runCmd
)
<-
simpleOptions
"0.1.0.0"
"OpenAlex"
...
...
@@ -31,38 +40,38 @@ main = do
addCommand
"concepts"
"Fetch OpenAlex concepts (https://docs.openalex.org/api-entities/concepts/concept-object)"
fetchConcepts
(
strOption
(
long
"filter"
))
commonOptions
addCommand
"works"
"Fetch OpenAlex works (https://docs.openalex.org/api-entities/works/work-object)"
fetchWorks
(
strOption
(
long
"filter"
))
commonOptions
addCommand
"works-c"
"Fetch OpenAlex works (https://docs.openalex.org/api-entities/works/work-object) with conduit"
fetchWorksC
(
strOption
(
long
"filter"
))
commonOptions
runCmd
()
fetchConcepts
::
O
A
.
Filter
->
()
->
IO
()
fetchConcepts
fltr
_
=
do
ec
<-
OA
.
fetchConcepts
(
Just
1
)
(
Just
1
)
(
Just
"*"
)
(
Just
fltr
)
fetchConcepts
::
O
ptions
->
()
->
IO
()
fetchConcepts
Options
{
..
}
_
=
do
ec
<-
OA
.
fetchConcepts
(
Just
1
)
(
Just
1
)
(
Just
"*"
)
filter
search
case
ec
of
Left
err
->
putText
$
"error: "
<>
show
err
Right
c
->
do
putText
$
show
c
fetchWorks
::
O
A
.
Filter
->
()
->
IO
()
fetchWorks
fltr
_
=
do
ew
<-
OA
.
fetchWorks
(
Just
1
)
(
Just
1
)
(
Just
"*"
)
(
Just
fltr
)
fetchWorks
::
O
ptions
->
()
->
IO
()
fetchWorks
Options
{
..
}
_
=
do
ew
<-
OA
.
fetchWorks
(
Just
1
)
(
Just
1
)
(
Just
"*"
)
filter
search
case
ew
of
Left
err
->
putText
$
"error: "
<>
show
err
Right
w
->
do
putText
$
show
w
fetchWorksC
::
O
A
.
Filter
->
()
->
IO
()
fetchWorksC
fltr
_
=
do
eWorksC
<-
OA
.
fetchWorksC
Nothing
(
Just
fltr
)
fetchWorksC
::
O
ptions
->
()
->
IO
()
fetchWorksC
Options
{
..
}
_
=
do
eWorksC
<-
OA
.
fetchWorksC
Nothing
filter
search
case
eWorksC
of
Left
err
->
putText
$
"error: "
<>
show
err
Right
(
mCount
,
c
)
->
do
...
...
@@ -71,6 +80,6 @@ fetchWorksC fltr _ = do
.|
takeC
3
.|
mapM_C
(
\
w
@
(
OA
.
Work
{
..
})
->
do
liftIO
$
putText
$
show
id
<>
" :: "
<>
show
display_name
liftIO
$
putText
abstract_reconstructed
--
liftIO $ putText abstract_reconstructed
)
pure
()
src/OpenAlex.hs
View file @
0083c02d
...
...
@@ -27,7 +27,7 @@ import Network.HTTP.Client.TLS (tlsManagerSettings)
import
Protolude
hiding
(
yield
)
import
OpenAlex.Client
import
OpenAlex.ServantClientLogging
import
OpenAlex.Types
(
ListOf
(
..
),
Meta
(
..
),
Page
,
PerPage
,
Cursor
,
Filter
,
Concept
,
Work
)
import
OpenAlex.Types
(
ListOf
(
..
),
Meta
(
..
),
Page
,
PerPage
,
Cursor
,
Filter
,
Search
,
Concept
,
Work
)
import
Servant.Client
(
BaseUrl
(
..
),
ClientEnv
(
..
),
ClientError
,
Scheme
(
Https
),
defaultMakeClientRequest
,
mkClientEnv
,
runClientM
)
defaultClientEnv
::
IO
ClientEnv
...
...
@@ -45,29 +45,32 @@ fetchConcepts :: Maybe Page
->
Maybe
PerPage
->
Maybe
Cursor
->
Maybe
Filter
->
Maybe
Search
->
IO
(
Either
ClientError
(
ListOf
Concept
))
fetchConcepts
mPage
mPerPage
mCursor
mFilter
=
do
fetchConcepts
mPage
mPerPage
mCursor
mFilter
mSearch
=
do
env
<-
defaultClientEnv
runClientM
(
concepts
mPage
mPerPage
mCursor
mFilter
)
env
runClientM
(
concepts
mPage
mPerPage
mCursor
mFilter
mSearch
)
env
fetchWorks
::
Maybe
Page
->
Maybe
PerPage
->
Maybe
Cursor
->
Maybe
Filter
->
Maybe
Search
->
IO
(
Either
ClientError
(
ListOf
Work
))
fetchWorks
mPage
mPerPage
mCursor
mFilter
=
do
fetchWorks
mPage
mPerPage
mCursor
mFilter
mSearch
=
do
env
<-
defaultClientEnv
runClientM
(
works
mPage
mPerPage
mCursor
mFilter
)
env
runClientM
(
works
mPage
mPerPage
mCursor
mFilter
mSearch
)
env
fetchWorksC
::
Maybe
Cursor
->
Maybe
Filter
->
Maybe
Search
->
IO
(
Either
ClientError
(
Maybe
Integer
,
ConduitT
()
Work
IO
()
))
fetchWorksC
Nothing
mFilter
=
do
fetchWorksC
(
Just
"*"
)
mFilter
fetchWorksC
mCursor
mFilter
=
do
fetchWorksC
Nothing
mFilter
mSearch
=
do
fetchWorksC
(
Just
"*"
)
mFilter
mSearch
fetchWorksC
mCursor
mFilter
mSearch
=
do
env
<-
defaultClientEnv
-- NOTE: per-page max is 200
eRes
<-
runClientM
(
works
(
Just
1
)
(
Just
1
)
Nothing
mFilter
)
env
eRes
<-
runClientM
(
works
(
Just
1
)
(
Just
1
)
Nothing
mFilter
mSearch
)
env
case
eRes
of
Left
err
->
pure
$
Left
err
Right
ListOf
{
meta
=
Meta
{
count
}}
->
do
...
...
@@ -76,7 +79,7 @@ fetchWorksC mCursor mFilter = do
where
producer
::
ClientEnv
->
Maybe
Cursor
->
ConduitT
()
Work
IO
()
producer
env
mCursor'
=
do
eRes
<-
liftIO
$
runClientM
(
works
Nothing
(
Just
200
)
mCursor'
mFilter
)
env
eRes
<-
liftIO
$
runClientM
(
works
Nothing
(
Just
200
)
mCursor'
mFilter
mSearch
)
env
-- liftIO $ putText $ "Conduit fetching page with cursor " <> show mCursor'
case
eRes
of
Left
err
->
panic
$
"error: "
<>
show
err
...
...
src/OpenAlex/Client.hs
View file @
0083c02d
...
...
@@ -16,7 +16,7 @@ import Protolude
import
Servant.API
import
Servant.Client
import
OpenAlex.Types
(
Page
,
PerPage
,
Cursor
,
Filter
,
ListOf
(
..
),
Concept
,
Work
)
import
OpenAlex.Types
(
Page
,
PerPage
,
Cursor
,
Filter
,
Search
,
ListOf
(
..
),
Concept
,
Work
)
type
API_URL
=
Text
apiUrl
::
API_URL
...
...
@@ -35,6 +35,7 @@ type OpenAlexAPI =
:>
QueryParam
"per-page"
PerPage
:>
QueryParam
"cursor"
Cursor
:>
QueryParam
"filter"
Filter
:>
QueryParam
"search"
Search
-- TODO: filter, search, sort
:>
Get
'[
J
SON
]
(
ListOf
Concept
)
...
...
@@ -44,14 +45,25 @@ type OpenAlexAPI =
:>
QueryParam
"per-page"
PerPage
:>
QueryParam
"cursor"
Cursor
:>
QueryParam
"filter"
Filter
:>
QueryParam
"search"
Search
-- TODO: filter, search, sort
:>
Get
'[
J
SON
]
(
ListOf
Work
)
openAlexApi
::
Proxy
OpenAlexAPI
openAlexApi
=
Proxy
concepts
::
Maybe
Page
->
Maybe
PerPage
->
Maybe
Cursor
->
Maybe
Filter
->
ClientM
(
ListOf
Concept
)
concepts
::
Maybe
Page
->
Maybe
PerPage
->
Maybe
Cursor
->
Maybe
Filter
->
Maybe
Search
->
ClientM
(
ListOf
Concept
)
works
::
Maybe
Page
->
Maybe
PerPage
->
Maybe
Cursor
->
Maybe
Filter
->
ClientM
(
ListOf
Work
)
works
::
Maybe
Page
->
Maybe
PerPage
->
Maybe
Cursor
->
Maybe
Filter
->
Maybe
Search
->
ClientM
(
ListOf
Work
)
concepts
:<|>
works
=
client
openAlexApi
src/OpenAlex/Types.hs
View file @
0083c02d
...
...
@@ -30,6 +30,7 @@ type Page = Int
type
PerPage
=
Int
type
Filter
=
Text
type
Search
=
Text
-- API response types
...
...
src/OpenAlex/Utils.hs
View file @
0083c02d
{-|
Module : OpenAlex Utils
Description : Textmining Collaborative Platform
Copyright : (c) CNRS, 2023
Copyright : (c) CNRS, 2023
-present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment