openalex
zocrates.discovery.providers.openalex ¶
OpenAlex scholarly literature search provider and identifier resolver.
OPENALEX_SELECT_FIELDS
module-attribute
¶
OPENALEX_SELECT_FIELDS = 'id,doi,title,display_name,authorships,publication_year,primary_location,open_access,abstract_inverted_index,cited_by_count,type,ids,primary_topic,keywords,locations'
CandidatePaper
dataclass
¶
CandidatePaper(candidate_id, title, authors=list(), year=None, venue=None, doi=None, arxiv_id=None, openalex_id='', abstract=None, tldr=None, is_oa=False, oa_pdf_url=None, oa_pdf_urls=list(), citation_count=0, primary_topic=None, keywords=list(), in_library=False)
Represents a discovered scholarly paper candidate.
from_dict
classmethod
¶
Deserialize CandidatePaper from a dictionary.
Source code in zocrates/discovery/models.py
to_dict ¶
Serialize CandidatePaper to a plain dictionary.
Source code in zocrates/discovery/models.py
OpenAlexProvider ¶
Bases: SearchProvider
Primary search provider backed by the OpenAlex REST API. Indexes 250M+ scholarly works, arXiv preprints, and open-access metadata.
Initialize the OpenAlex search provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Contact email for polite-pool API requests. |
DEFAULT_POLITE_EMAIL
|
rate_limiter
|
TokenBucketRateLimiter | None
|
Token bucket rate limiter instance. |
None
|
timeout
|
float
|
HTTP request timeout in seconds. |
15.0
|
api_key
|
str | None
|
Optional OpenAlex premium API key. |
None
|
Source code in zocrates/discovery/providers/openalex.py
extract_arxiv_id_from_work
staticmethod
¶
Extract canonical arXiv ID without version suffix from an OpenAlex work record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work
|
dict[str, Any]
|
OpenAlex work dictionary. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Canonical lowercase arXiv ID without 'v' suffix (e.g. '2305.12345'), or None. |
Source code in zocrates/discovery/providers/openalex.py
reconstruct_abstract
staticmethod
¶
Reconstruct plain-text abstract from an OpenAlex abstract_inverted_index dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inverted_index
|
dict[str, list[int]] | None
|
Mapping of words to their token position indices. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Coherent, human-readable abstract string, or None if empty/invalid. |
Source code in zocrates/discovery/providers/openalex.py
resolve_identifier
async
¶
Resolve a paper by DOI, arXiv ID, or OpenAlex ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
DOI, arXiv ID, or OpenAlex ID. |
required |
Returns:
| Type | Description |
|---|---|
CandidatePaper | None
|
Resolved CandidatePaper, or None if not found. |
Source code in zocrates/discovery/providers/openalex.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
search
async
¶
Execute free-text or conceptual search against OpenAlex works.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User search query string. |
required |
limit
|
int
|
Maximum candidate works to return. |
10
|
year_from
|
int | None
|
Optional minimum publication year. |
None
|
year_to
|
int | None
|
Optional maximum publication year. |
None
|
is_oa_only
|
bool
|
Restrict to open-access papers. |
False
|
Returns:
| Type | Description |
|---|---|
list[CandidatePaper]
|
List of parsed CandidatePaper instances. |
Source code in zocrates/discovery/providers/openalex.py
SearchProvider ¶
Bases: ABC
Abstract base class for scholarly literature search providers.
resolve_identifier
abstractmethod
async
¶
Resolve a single scholarly paper by DOI, arXiv ID, or provider-specific ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
DOI, arXiv ID, or provider ID string. |
required |
Returns:
| Type | Description |
|---|---|
CandidatePaper | None
|
CandidatePaper if resolved, or None if not found. |
Source code in zocrates/discovery/providers/base.py
search
abstractmethod
async
¶
Search for scholarly literature matching the query and filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Free-text search terms or conceptual query. |
required |
limit
|
int
|
Maximum number of candidate papers to return. |
10
|
year_from
|
int | None
|
Optional minimum publication year (inclusive). |
None
|
year_to
|
int | None
|
Optional maximum publication year (inclusive). |
None
|
is_oa_only
|
bool
|
When True, restrict results to open-access works. |
False
|
Returns:
| Type | Description |
|---|---|
list[CandidatePaper]
|
List of CandidatePaper instances. |
Source code in zocrates/discovery/providers/base.py
TokenBucketRateLimiter ¶
Token-bucket rate limiter for respectful, throttled API consumption. Thread/asyncio safe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Refill rate in tokens per second. |
10.0
|
capacity
|
float
|
Maximum burst capacity in tokens. |
10.0
|
Source code in zocrates/discovery/providers/base.py
acquire
async
¶
Acquire tokens from the bucket, sleeping if necessary until replenished.
Source code in zocrates/discovery/providers/base.py
make_user_agent ¶
Build a respectful User-Agent header string adhering to API etiquette.
Source code in zocrates/discovery/providers/base.py
normalize_arxiv_id ¶
Normalize an arXiv identifier by stripping URL prefixes, 'arxiv:' tags, and version suffixes.
Source code in zocrates/rag/zotero_db.py
normalize_doi ¶
Normalize DOI by stripping standard URI and resolver prefixes and lowercasing.