Fetch a Google Scholar profile and convert it into a bootstrap profile fragment.
(scholar_url: str, use_llm: bool = True)
| 1352 | |
| 1353 | |
| 1354 | def parse_google_scholar_profile(scholar_url: str, use_llm: bool = True) -> Dict[str, Any]: |
| 1355 | """Fetch a Google Scholar profile and convert it into a bootstrap profile fragment.""" |
| 1356 | scholar_profile = _fetch_google_scholar_profile_pages(scholar_url) |
| 1357 | |
| 1358 | interest_texts = [str(item) for item in scholar_profile.get("interests", []) if str(item).strip()] |
| 1359 | publication_titles = [ |
| 1360 | str(paper.get("title") or "").strip() |
| 1361 | for paper in scholar_profile.get("publications", []) or [] |
| 1362 | if str(paper.get("title") or "").strip() |
| 1363 | ] |
| 1364 | top_cited_titles = [ |
| 1365 | str(paper.get("title") or "").strip() |
| 1366 | for paper in scholar_profile.get("top_cited_publications", []) or [] |
| 1367 | if str(paper.get("title") or "").strip() |
| 1368 | ] |
| 1369 | secondary_texts: List[str] = [] |
| 1370 | if scholar_profile.get("affiliation"): |
| 1371 | secondary_texts.append(f"Affiliation: {scholar_profile['affiliation']}") |
| 1372 | secondary_texts.extend( |
| 1373 | [f"Highly cited work: {title}" for title in top_cited_titles[:3]] |
| 1374 | ) |
| 1375 | |
| 1376 | scholar_fragment = _build_bootstrap_fragment_from_structured_sources( |
| 1377 | explicit_texts=interest_texts, |
| 1378 | secondary_texts=secondary_texts, |
| 1379 | publication_titles=_dedupe_preserve_order(top_cited_titles + publication_titles), |
| 1380 | use_llm=use_llm, |
| 1381 | ) |
| 1382 | |
| 1383 | scholar_fragment.update(_build_scholar_heat_maps(scholar_profile)) |
| 1384 | scholar_fragment["interest_vector"] = generate_interest_vector(scholar_fragment.get("core_directions", {})) |
| 1385 | |
| 1386 | notes: List[str] = [] |
| 1387 | if scholar_profile.get("interests"): |
| 1388 | notes.append("已从 Google Scholar 研究兴趣提取信号:" + "、".join(scholar_profile["interests"][:4])) |
| 1389 | if scholar_profile.get("publications"): |
| 1390 | notes.append(f"已结合 Google Scholar 代表论文 {len(scholar_profile['publications'])} 篇补充冷启动画像。") |
| 1391 | if scholar_profile.get("top_cited_publications"): |
| 1392 | top_cited_titles = [item.get("title", "") for item in scholar_profile["top_cited_publications"][:2] if item.get("title")] |
| 1393 | if top_cited_titles: |
| 1394 | notes.append("已提取高引代表作信号:" + "、".join(top_cited_titles)) |
| 1395 | if scholar_profile.get("top_coauthors"): |
| 1396 | top_names = [entry.get("name", "") for entry in scholar_profile["top_coauthors"][:3] if entry.get("name")] |
| 1397 | if top_names: |
| 1398 | notes.append("已提取高频合作作者信号:" + "、".join(top_names)) |
| 1399 | if scholar_profile.get("collaboration_network"): |
| 1400 | lead_network = scholar_profile["collaboration_network"][0] |
| 1401 | lead_name = str(lead_network.get("name") or "").strip() |
| 1402 | lead_count = int(lead_network.get("count") or 0) |
| 1403 | lead_citations = int(lead_network.get("citation_sum") or 0) |
| 1404 | if lead_name: |
| 1405 | notes.append( |
| 1406 | f"已构建更细粒度合作网络:当前最强合作节点为 {lead_name}" |
| 1407 | f"(合作 {lead_count} 篇,累计引用 {lead_citations})" |
| 1408 | ) |
| 1409 | if scholar_profile.get("stats"): |
| 1410 | citations = scholar_profile["stats"].get("citations") |
| 1411 | if citations is not None: |
no test coverage detected