added optional param -> add edges to collab graph or not
This commit is contained in:
@@ -24,7 +24,8 @@ from inse.model import ESIndex
|
||||
from inse.models.openalex.author import Author
|
||||
from inse.works.v2.model import WorkPageV2
|
||||
from sqlmodel import Session
|
||||
|
||||
from .model import Edge
|
||||
from itertools import combinations
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -359,6 +360,7 @@ async def _build_collaboration_graph(
|
||||
max_collaborators: int | None = None,
|
||||
topic_ids: list[str] | None = None,
|
||||
institution_ids: list[str] | None = None,
|
||||
all_edges: bool = False,
|
||||
) -> CollaborationGraph:
|
||||
"""Gets a collaboration graph for a given author ID, optionally filtered by year range, collaborator count, topic IDs, and institution IDs.
|
||||
|
||||
@@ -401,12 +403,12 @@ async def _build_collaboration_graph(
|
||||
)
|
||||
|
||||
return _build_collaboration_graph_from_works(
|
||||
page=work_page, raw_oa_author_id=raw_oa_author_id
|
||||
page=work_page, raw_oa_author_id=raw_oa_author_id, all_edges=all_edges
|
||||
)
|
||||
|
||||
|
||||
def _build_collaboration_graph_from_works(
|
||||
page: WorkPageV2, raw_oa_author_id: str, min_edge_weight: float = 1.0
|
||||
page: WorkPageV2, raw_oa_author_id: str, min_edge_weight: float = 1.0, all_edges: bool = False
|
||||
) -> CollaborationGraph:
|
||||
"""Builds a collaboration graph from a page of works and a raw OpenAlex author ID.
|
||||
|
||||
@@ -466,10 +468,10 @@ def _build_collaboration_graph_from_works(
|
||||
),
|
||||
author_ids=work_author_ids,
|
||||
)
|
||||
|
||||
# Toggle to add edges between all pairs of authors for each work. This can create a dense graph if many authors co-author works together.
|
||||
# for author_a, author_b in combinations(sorted(set(work_author_ids)), 2):
|
||||
# internal_graph.add_edge(Edge(source=author_a, target=author_b, weight=1.0))
|
||||
if all_edges:
|
||||
# Toggle to add edges between all pairs of authors for each work. This can create a dense graph if many authors co-author works together.
|
||||
for author_a, author_b in combinations(sorted(set(work_author_ids)), 2):
|
||||
internal_graph.add_edge(Edge(source=author_a, target=author_b, weight=1.0))
|
||||
|
||||
graph = CollaborationGraph.from_internal_graph(
|
||||
internal_graph, min_edge_weight=min_edge_weight
|
||||
|
||||
Reference in New Issue
Block a user