papers_helpers.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """论文辅助函数 —— arXiv ID 标准化与论文元数据提取."""
  2. from typing import Any
  3. from ...utils import normalize_arxiv_id
  4. def daily_paper_identity_sig(p: Any) -> str:
  5. ax = normalize_arxiv_id(getattr(p, "arxiv_id", None))
  6. if ax:
  7. return f"arxiv:{ax}"
  8. doi = (getattr(p, "doi", None) or "").strip().lower()
  9. if doi:
  10. return f"doi:{doi}"
  11. t = (getattr(p, "title", None) or "").strip().lower()
  12. y = int(getattr(p, "year", 0) or 0)
  13. return f"ty:{t}|{y}"
  14. def graph_author_node_id(paper_id: int, author_index: int, author: Any) -> str:
  15. raw_orcid = getattr(author, "orcid", None)
  16. orc = None
  17. if raw_orcid:
  18. s = str(raw_orcid).strip().lower()
  19. for prefix in ("https://orcid.org/", "http://orcid.org/"):
  20. if s.startswith(prefix):
  21. s = s[len(prefix):]
  22. s = s.strip().rstrip("/")
  23. if len(s) >= 10:
  24. orc = s
  25. if orc:
  26. return f"author:o:{orc}"
  27. try:
  28. aid = getattr(author, "db_id", None)
  29. if aid is not None and int(aid) > 0:
  30. return f"author:db:{int(aid)}"
  31. except Exception:
  32. pass
  33. return f"author:p:{int(paper_id)}:{int(author_index)}"
  34. def graph_author_label(author: Any, author_index: int, node_id: str) -> str:
  35. name = (getattr(author, "name", None) or "").strip() or "Unknown"
  36. if not str(node_id).startswith("author:p:"):
  37. return name[:120]
  38. aff = (getattr(author, "affiliation", None) or "").strip()
  39. if aff:
  40. short = aff[:26] + ("…" if len(aff) > 26 else "")
  41. return f"{name[:80]} ({short})"
  42. return f"{name[:80]} (#{author_index + 1})"