Skip to content

Commit

Permalink
Merge branch 'main' into add-logical-support
Browse files Browse the repository at this point in the history
  • Loading branch information
J535D165 committed Dec 22, 2024
2 parents 5c00f20 + c8d00f8 commit bf8ed69
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
rev: v0.6.7
hooks:
- id: ruff
args: [--fix]
Expand Down
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Works()["W2741809807"]["open_access"]
The previous works also for Authors, Sources, Institutions, Concepts and Topics

```python
Authors()["A2887243803"]
Authors()["A5027479191"]
Authors()["https://orcid.org/0000-0002-4297-0502"] # same
```

Expand All @@ -115,7 +115,6 @@ Works().random()
Authors().random()
Sources().random()
Institutions().random()
Concepts().random()
Topics().random()
Publishers().random()
Funders().random()
Expand Down Expand Up @@ -354,11 +353,27 @@ Works()["W2023271753"].ngrams()
```


### Serialize

All results from PyAlex can be serialized. For example, save the results to a JSON file:

```python
import json
from pathlib import Path
from pyalex import Work

with open(Path("works.json"), "w") as f:
json.dump(Works().get(), f)

with open(Path("works.json")) as f:
works = [Work(w) for w in json.load(f)]
```

## Code snippets

A list of awesome use cases of the OpenAlex dataset.

### Cited publications (referenced works)
### Cited publications (works referenced by this paper, outgoing citations)

```python
from pyalex import Works
Expand All @@ -369,6 +384,13 @@ w = Works()["W2741809807"]
Works()[w["referenced_works"]]
```

### Citing publications (other works that reference this paper, incoming citations)

```
from pyalex import Works
Works().filter(cites="W2741809807").get()
```

### Get works of a single author

```python
Expand Down Expand Up @@ -427,6 +449,7 @@ R users can use the excellent [OpenAlexR](https://github.com/ropensci/openalexR)

> This library is a community contribution. The authors of this Python library aren't affiliated with OpenAlex.
This library is maintained by [J535D165](https://github.com/J535D165) and [PeterLombaers](https://github.com/PeterLombaers).
Feel free to reach out with questions, remarks, and suggestions. The
[issue tracker](/issues) is a good starting point. You can also email me at
[issue tracker](/issues) is a good starting point. You can also reach out via
[[email protected]](mailto:[email protected]).
2 changes: 1 addition & 1 deletion pyalex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __setattr__(self, key, value):
config = AlexConfig(
email=None,
api_key=None,
user_agent="pyalex/{__version__}",
user_agent=f"pyalex/{__version__}",
openalex_url="https://api.openalex.org",
max_retries=0,
retry_backoff_factor=0.1,
Expand Down
16 changes: 15 additions & 1 deletion tests/test_pyalex.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ def test_referenced_works():
)

assert set([w["id"] for w in w_new]).difference(set(w["referenced_works"])) == set()
# assert set(w["referenced_works"]).difference(set([w["id"] for w in w_new])) == set()
# assert set(w["referenced_works"]).difference(set([w["id"] for w in w_new]))
# == set()

assert m["count"] < len(w["referenced_works"])

Expand Down Expand Up @@ -252,12 +253,25 @@ def test_serializable(tmpdir):
assert "W4238809453" in json.load(f)["id"]


def test_serializable_list(tmpdir):
with open(Path(tmpdir, "test.json"), "w") as f:
json.dump(Works().get(), f)

with open(Path(tmpdir, "test.json")) as f:
works = [Work(w) for w in json.load(f)]

assert len(works) == 25
assert all(isinstance(w, Work) for w in works)


@pytest.mark.skip("This test is not working due to unavailable API.")
def test_ngrams_without_metadata():
r = Works()["W2023271753"].ngrams(return_meta=False)

assert len(r) == 1068


@pytest.mark.skip("This test is not working due to unavailable API.")
def test_ngrams_with_metadata():
r, meta = Works()["W2023271753"].ngrams(return_meta=True)

Expand Down

0 comments on commit bf8ed69

Please sign in to comment.