fix: incorrect colors in person card due to missing information
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -528,6 +528,9 @@ async def get_person_by_id(
|
||||
career_metrics=career_metrics,
|
||||
)
|
||||
|
||||
if custom_author.topics:
|
||||
await enrich_topic_descriptions(custom_author.topics)
|
||||
|
||||
return CustomAuthorsListResponse(results=[custom_author])
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ from inse.models.openalex.topics_by_time import TopicsByTime
|
||||
from inse.models.openalex.topics_by_year import TopicsByYear
|
||||
from inse.models.openalex.work import Work
|
||||
from inse.models.openalex.work_page import WorkPage
|
||||
from inse.models.openalex.work_topic import WorkTopic
|
||||
from inse.models.openalex.work_topic_domain import WorkTopicDomain
|
||||
from inse.models.openalex.work_topic_field import WorkTopicField
|
||||
from inse.models.openalex.work_topic_subfield import WorkTopicSubfield
|
||||
from inse.models.openalex.works_list_response import WorksListResponse
|
||||
|
||||
from .search_client import OpenAlexWorksSearchClient
|
||||
@@ -235,26 +239,39 @@ async def get_work(
|
||||
return elements[0]
|
||||
|
||||
|
||||
async def enrich_topic_descriptions(topics: list) -> None:
|
||||
"""Batch-fill missing descriptions on dehydrated topics.
|
||||
async def enrich_topic_descriptions(topics: list[WorkTopic]) -> None:
|
||||
"""Batch-fill missing hierarchy metadata and descriptions on dehydrated topics.
|
||||
|
||||
OpenAlex work and author documents carry dehydrated topics without a
|
||||
description, so we batch-load the details from the openalex-topics index.
|
||||
description, subfield, field, or domain, so we batch-load the details from
|
||||
the openalex-topics index.
|
||||
"""
|
||||
pending = [topic for topic in topics if topic.id and not topic.description]
|
||||
pending = [
|
||||
topic
|
||||
for topic in topics
|
||||
if topic.id and (not topic.description or not topic.var_field or not topic.domain)
|
||||
]
|
||||
|
||||
if not pending:
|
||||
return
|
||||
|
||||
details = await _get_topic_details(list({topic.id for topic in pending}))
|
||||
|
||||
if not details:
|
||||
return
|
||||
|
||||
for topic in pending:
|
||||
info = details.get(topic.id)
|
||||
if info:
|
||||
if not info:
|
||||
continue
|
||||
|
||||
if not topic.description:
|
||||
topic.description = info.get("description")
|
||||
if not topic.subfield and info.get("subfield"):
|
||||
topic.subfield = WorkTopicSubfield.from_dict(info["subfield"])
|
||||
if not topic.var_field and info.get("field"):
|
||||
topic.var_field = WorkTopicField.from_dict(info["field"])
|
||||
if not topic.domain and info.get("domain"):
|
||||
topic.domain = WorkTopicDomain.from_dict(info["domain"])
|
||||
|
||||
|
||||
async def _enrich_work_topic_descriptions(works: list[Work]) -> None:
|
||||
|
||||
Reference in New Issue
Block a user