-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from OKN-CollabNext/authors-without-topics
Clamp nodes and edges
- Loading branch information
Showing
6 changed files
with
160 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def clamp_author_nodes_to_edges( | ||
author_nodes: list[dict], edges: list[dict] | ||
) -> list[dict]: | ||
author_ids = {x["start"] for x in edges} | ||
return [x for x in author_nodes if x["id"] in author_ids] | ||
|
||
def clamp_author_edges_to_nodes( | ||
author_edges: list[dict], nodes: list[dict] | ||
) -> list[dict]: | ||
author_ids = {x["id"] for x in nodes} | ||
return [x for x in author_edges if x["start"] in author_ids] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,33 @@ | ||
from pyalex import Works, Work, Author | ||
from pyalex import Author, Institution, Work, Works | ||
|
||
|
||
def get_works_by_authors(authors: list[Author]) -> list[Work]: | ||
seen = set() | ||
works_by_authors = [] | ||
for author in authors: | ||
works = Works().filter(authorships={"author": {"id": author["id"]}}).get() | ||
works = [x for x in works if not (x["id"] in seen or seen.add(x["id"]))] | ||
works_by_authors.extend(works) | ||
return works_by_authors | ||
return works_by_authors | ||
|
||
|
||
def get_work_institutions(works: list[Work]) -> list[Institution]: | ||
seen = set() | ||
return [ | ||
y | ||
for x in works["authorships"] | ||
for y in x["institutions"] | ||
if not (y["id"] in seen or seen.add(y["id"])) | ||
] | ||
|
||
|
||
def clamp_works_to_institutions( | ||
works: list[Work], institutions: list[Institution] | ||
) -> list[Author]: | ||
institution_ids = {x["id"] for x in institutions} | ||
result = [] | ||
for work in works: | ||
work_institution_ids = {x["id"] for x in get_work_institutions(work)} | ||
if len(institution_ids & work_institution_ids) > 0: | ||
result.append(work) | ||
return result |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters