Skip to content

Commit

Permalink
Merge pull request #15 from OKN-CollabNext/skip-work-nodes
Browse files Browse the repository at this point in the history
Don't display work nodes
  • Loading branch information
lewlefton committed Apr 19, 2024
2 parents 0696bfb + b564c6a commit c4cb4c0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
16 changes: 16 additions & 0 deletions collabnext/openalex/inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def infer_author_topic_edges(
author_work_edges: list[dict], work_topic_edges: list[dict]
) -> list[dict]:
return [
{
"id": f"{author_work_edge['start']}-{work_topic_edge['end']}",
"start": author_work_edge["start"],
"end": work_topic_edge["end"],
"label": "TOPIC",
"start_type": "AUTHOR",
"end_type": "TOPIC",
}
for author_work_edge in author_work_edges
for work_topic_edge in work_topic_edges
if author_work_edge["end"] == work_topic_edge["start"]
]
2 changes: 1 addition & 1 deletion collabnext/openalex/institutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def get_institutions() -> list[Institution]:
# Get 3 random institutions for now
return [Institutions().random() for _ in range(3)]
return [Institutions().random() for _ in range(5)]
Empty file.
16 changes: 12 additions & 4 deletions observable/docs/data/graph.sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
make_author_work_edges,
make_work_topic_edges,
)
from collabnext.openalex.inference import infer_author_topic_edges
from collabnext.openalex.institutions import (
get_institutions,
)
Expand Down Expand Up @@ -43,22 +44,29 @@
# Create work nodes
work_nodes = make_work_nodes(works)

# Create work author edges
work_author_edges = make_author_work_edges(works)
# Create author-work edges
author_work_edges = make_author_work_edges(works)

# Get topics from works
topics = get_work_topics(works)

# Create topic nodes
topic_nodes = make_topic_nodes(topics)

# Create work topic edges
# Create work-topic edges
work_topic_edges = make_work_topic_edges(works)

# Infer author-topic edges
author_topic_edges = infer_author_topic_edges(author_work_edges, work_topic_edges)

# Group all nodes and edges together
nodes = [*institution_nodes, *author_nodes, *work_nodes, *topic_nodes]
edges = [*affiliated_author_edges, *work_author_edges, *work_topic_edges]
edges = [
*affiliated_author_edges,
*author_work_edges,
*author_topic_edges,
*work_topic_edges,
]

# Create nodes dataframe
df_nodes = pd.DataFrame(nodes, columns=["id", "label", "type"])
Expand Down
5 changes: 5 additions & 0 deletions observable/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const nodes = db.query(
*
FROM
nodes
WHERE
nodes.type <> 'WORK'
`
);
```
Expand All @@ -37,6 +39,9 @@ const edges = db.query(
*
FROM
edges
WHERE
edges.start_type <> 'WORK'
OR edges.end_type <> 'WORK'
`
);
```
Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ def clean_branches(c):
@task
def touch(c):
with cwd("observable/docs/data"):
c.run("touch graph.json.py")
c.run("touch graph.sqlite.py")

0 comments on commit c4cb4c0

Please sign in to comment.