Skip to content

Commit

Permalink
Merge pull request #5 from OKN-CollabNext/institution-nodes
Browse files Browse the repository at this point in the history
Use real data from OpenAlex for Institutions
  • Loading branch information
lewlefton committed Apr 14, 2024
2 parents 8b8aea6 + 77a1582 commit 67d2289
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ __pycache__/
.venv/

# Ignore vscode settings
.vscode/
.vscode/

# Ignore dot env files
.env
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ You can then install project dependencies as follows:
poetry install
```

You need a `.env` file to store secrets as follows:

```
OPENALEX_EMAIL=mailto@example.com
```

The OPENALEX_EMAIL secret is used to [speed up calls](https://docs.openalex.org/how-to-use-the-api/api-overview) to the OpenAlex REST API.

## Running

This project uses [Observable Framework](https://observablehq.com/framework/). You can run the site locally as follows
Expand Down
9 changes: 0 additions & 9 deletions observable/docs/data/edges.json.py

This file was deleted.

36 changes: 36 additions & 0 deletions observable/docs/data/graph.json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json
import os

import pyalex
from dotenv import load_dotenv
from pyalex import Institutions

# Load Secrets
load_dotenv()

# Initialize the pyalex client
pyalex.config.email = os.getenv("OPENALEX_EMAIL")

# Get 5 random institutions
institutions = [Institutions().random() for _ in range(5)]

# Gather associated institutions
associated_institutions = [
y for x in institutions for y in x["associated_institutions"]
]

# Combine all institutions
all_institutions = [*institutions, *associated_institutions]

# Create nodes
nodes = [{"id": x["id"], "label": x["display_name"]} for x in all_institutions]

# Create associated institution edges
edges = [
{"id": x["id"], "start": x["id"], "end": y["id"], "label": "ASSOCIATED"}
for x in institutions
for y in x["associated_institutions"]
]


print(json.dumps({"nodes": nodes, "edges": edges}))
10 changes: 0 additions & 10 deletions observable/docs/data/nodes.json.py

This file was deleted.

7 changes: 5 additions & 2 deletions observable/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ const query = view(Inputs.text());
### Your Peer Network

```js
const nodes = FileAttachment("data/nodes.json").json();
const edges = FileAttachment("data/edges.json").json();
const graph = FileAttachment("data/graph.json").json();
```

```js
const { nodes, edges } = graph;
```

<script src="https://unpkg.com/@memgraph/orb/dist/browser/orb.min.js"></script>
Expand Down
194 changes: 193 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ packages = [

[tool.poetry.dependencies]
python = "^3.11"
pyalex = "^0.14"
python-dotenv = "^1.0.1"


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 67d2289

Please sign in to comment.