MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / parse_google_scholar_profile

Function parse_google_scholar_profile

agents/coldstart-agent/main.py:1354–1422  ·  view source on GitHub ↗

Fetch a Google Scholar profile and convert it into a bootstrap profile fragment.

(scholar_url: str, use_llm: bool = True)

Source from the content-addressed store, hash-verified

1352 errors.append("Scholar page loaded but structured profile signals were empty")
1353 continue
1354 page_data = parsed
1355 page_loaded = True
1356 break
1357 except requests.RequestException as exc:
1358 errors.append(f"{type(exc).__name__}: {exc}")
1359
1360 if not page_loaded:
1361 if profile.get("all_publications") or profile.get("interests"):
1362 break
1363 raise ValueError("failed to fetch Google Scholar profile; " + "; ".join(errors[-3:]))
1364
1365 profile = _merge_scholar_page_data(profile, page_data, publication_limit)
1366
1367 current_page_publications = page_data.get("all_publications") or page_data.get("publications") or []
1368 if len(current_page_publications) < page_size:
1369 break
1370
1371 if not profile.get("interests") and not profile.get("publications"):
1372 raise ValueError("no scholar interests or publication rows found")
1373
1374 if errors:
1375 profile["fetch_warnings"] = errors[-3:]
1376 return profile
1377
1378
1379def _build_scholar_heat_maps(scholar_profile: Dict[str, Any]) -> Dict[str, Dict[str, float]]:
1380 """Convert coauthor and affiliation signals into profile heat maps."""
1381 author_heat: Dict[str, float] = {}
1382 institution_heat: Dict[str, float] = {}
1383
1384 network_entries = scholar_profile.get("collaboration_network") or scholar_profile.get("top_coauthors") or []
1385 for index, entry in enumerate(network_entries):
1386 name = _collapse_whitespace(entry.get("name", ""))
1387 count = int(entry.get("count") or 0)
1388 citation_sum = int(entry.get("citation_sum") or 0)
1389 last_year = int(entry.get("last_year") or 0)
1390 if not name or count <= 0:
1391 continue
1392 recent_bonus = 0.03 if last_year and last_year >= datetime.now().year - 1 else 0.0
1393 citation_bonus = min(0.12, citation_sum / 800.0)
1394 seeded = min(0.82, 0.18 + 0.07 * count + citation_bonus + recent_bonus - 0.015 * index)
1395 author_heat[name] = round(max(0.15, seeded), 4)
1396
1397 affiliation = _collapse_whitespace(scholar_profile.get("affiliation", ""))
1398 if affiliation:
1399 institution_heat[affiliation] = 0.6
1400
1401 return {
1402 "author_heat": author_heat,
1403 "institution_heat": institution_heat,
1404 }
1405
1406
1407def parse_google_scholar_profile(scholar_url: str, use_llm: bool = True) -> Dict[str, Any]:
1408 """Fetch a Google Scholar profile and convert it into a bootstrap profile fragment."""
1409 scholar_profile = _fetch_google_scholar_profile_pages(scholar_url)
1410
1411 interest_texts = [str(item) for item in scholar_profile.get("interests", []) if str(item).strip()]

Callers 1

cold_startFunction · 0.85

Tested by

no test coverage detected