跳转至

src/openalex_enricher

阶段 2a 模块,使用 OpenAlex 的概念、主题和领域分类富化论文。

函数

fetch_work_concepts(work_id: str, email: str, cache_dir: str) → dict

从 OpenAlex API 获取单篇论文的概念和主题数据。

参数:

名称 类型 说明
work_id str OpenAlex work ID(如 W2078536640
email str Polite pool 访问邮箱
cache_dir str 缓存 JSON 响应的目录

返回值: 包含以下键的字典:

  • concepts — 概念条目列表 {name, score}
  • topics — 主题分类列表
  • field — 主要领域名称(如 "Physics")

副作用: 将响应缓存到 {cache_dir}/{work_id}.json


enrich_publications(publications: pl.DataFrame, cfg: dict) → pl.DataFrame

批量使用 OpenAlex 数据富化论文 DataFrame。

参数:

名称 类型 说明
publications pl.DataFrame openalex_work_id 列的论文
cfg dict 项目配置字典

返回值: 更新后的 DataFrame,新增列:

  • openalex_concepts — 概念列表的 JSON 字符串
  • openalex_topics — 主题列表的 JSON 字符串
  • openalex_field — 主要领域字符串

run() → None

执行完整的阶段 2a 流水线:

  1. 加载 publications.parquet
  2. 为每篇论文获取 OpenAlex 数据
  3. 添加概念/主题/领域列
  4. 覆盖 publications.parquet