Parse a natural-language self-description into a bootstrap profile fragment.
(text: str, use_llm: bool = True)
| 1423 | if scholar_profile.get("affiliation"): |
| 1424 | secondary_texts.append(f"Affiliation: {scholar_profile['affiliation']}") |
| 1425 | secondary_texts.extend( |
| 1426 | [f"Highly cited work: {title}" for title in top_cited_titles[:3]] |
| 1427 | ) |
| 1428 | |
| 1429 | scholar_fragment = _build_bootstrap_fragment_from_structured_sources( |
| 1430 | explicit_texts=interest_texts, |
| 1431 | secondary_texts=secondary_texts, |
| 1432 | publication_titles=_dedupe_preserve_order(top_cited_titles + publication_titles), |
| 1433 | use_llm=use_llm, |
| 1434 | ) |
| 1435 | |
| 1436 | scholar_fragment.update(_build_scholar_heat_maps(scholar_profile)) |
| 1437 | scholar_fragment["interest_vector"] = generate_interest_vector(scholar_fragment.get("core_directions", {})) |
| 1438 | |
| 1439 | notes: List[str] = [] |
| 1440 | if scholar_profile.get("interests"): |
| 1441 | notes.append("已从 Google Scholar 研究兴趣提取信号:" + "、".join(scholar_profile["interests"][:4])) |
| 1442 | if scholar_profile.get("publications"): |
| 1443 | notes.append(f"已结合 Google Scholar 代表论文 {len(scholar_profile['publications'])} 篇补充冷启动画像。") |
| 1444 | if scholar_profile.get("top_cited_publications"): |
| 1445 | top_cited_titles = [item.get("title", "") for item in scholar_profile["top_cited_publications"][:2] if item.get("title")] |
| 1446 | if top_cited_titles: |
| 1447 | notes.append("已提取高引代表作信号:" + "、".join(top_cited_titles)) |
| 1448 | if scholar_profile.get("top_coauthors"): |
| 1449 | top_names = [entry.get("name", "") for entry in scholar_profile["top_coauthors"][:3] if entry.get("name")] |
| 1450 | if top_names: |
| 1451 | notes.append("已提取高频合作作者信号:" + "、".join(top_names)) |
| 1452 | if scholar_profile.get("collaboration_network"): |
| 1453 | lead_network = scholar_profile["collaboration_network"][0] |
| 1454 | lead_name = str(lead_network.get("name") or "").strip() |
| 1455 | lead_count = int(lead_network.get("count") or 0) |
| 1456 | lead_citations = int(lead_network.get("citation_sum") or 0) |
| 1457 | if lead_name: |
| 1458 | notes.append( |
| 1459 | f"已构建更细粒度合作网络:当前最强合作节点为 {lead_name}" |
| 1460 | f"(合作 {lead_count} 篇,累计引用 {lead_citations})" |
| 1461 | ) |
| 1462 | if scholar_profile.get("stats"): |
| 1463 | citations = scholar_profile["stats"].get("citations") |
| 1464 | if citations is not None: |
| 1465 | notes.append(f"Scholar 概览统计:总引用 {citations}") |
| 1466 | if scholar_profile.get("fetch_warnings"): |
| 1467 | notes.append("Scholar 抓取已启用 fallback:" + ";".join(scholar_profile["fetch_warnings"])) |
| 1468 | if scholar_profile.get("homepage_url"): |
| 1469 | notes.append("已识别 Scholar 主页外链,可优先按个人主页方向继续补强。") |
| 1470 | |
| 1471 | return { |
| 1472 | "scholar_profile": scholar_profile, |
| 1473 | "parsed_profile": scholar_fragment, |
| 1474 | "direction_explanations": notes, |
| 1475 | } |
| 1476 | |
| 1477 | |
| 1478 | def parse_natural_language(text: str, use_llm: bool = True) -> Dict[str, Any]: |
| 1479 | """Parse a natural-language self-description into a bootstrap profile fragment.""" |
| 1480 | normalized_text = re.sub(r"\s+", " ", (text or "").strip()).lower() |
| 1481 | if normalized_text in COLD_START_COMMAND_HINTS: |
| 1482 | return _empty_parsed_profile_fragment() |
no test coverage detected