MCPcopy Create free account
hub / github.com/917Dhj/DeepPaperNote / normalize_openalex_work

Function normalize_openalex_work

scripts/common.py:623–666  ·  view source on GitHub ↗
(item: dict[str, Any])

Source from the content-addressed store, hash-verified

621
622
623def normalize_openalex_work(item: dict[str, Any]) -> dict[str, Any]:
624 title = normalize_whitespace(str(item.get("display_name", "")))
625 authors = []
626 affiliations = []
627 for authorship in item.get("authorships", []) or []:
628 if not isinstance(authorship, dict):
629 continue
630 author = authorship.get("author", {}) or {}
631 name = normalize_whitespace(str(author.get("display_name", "")))
632 if name:
633 authors.append(name)
634 for institution in authorship.get("institutions", []) or []:
635 if not isinstance(institution, dict):
636 continue
637 inst_name = normalize_whitespace(str(institution.get("display_name", "")))
638 if inst_name and inst_name not in affiliations:
639 affiliations.append(inst_name)
640 ids = item.get("ids", {}) or {}
641 doi_url = normalize_whitespace(str(ids.get("doi", "")))
642 doi = extract_doi(doi_url or normalize_whitespace(str(item.get("doi", "")))) or ""
643 primary_location = item.get("primary_location", {}) or {}
644 pdf_url = normalize_whitespace(str((primary_location.get("pdf_url") or "")))
645 landing_page_url = normalize_whitespace(str(primary_location.get("landing_page_url") or ""))
646 best_oa = item.get("best_oa_location", {}) or {}
647 if not pdf_url:
648 pdf_url = normalize_whitespace(str(best_oa.get("pdf_url") or ""))
649 if not landing_page_url:
650 landing_page_url = normalize_whitespace(str(best_oa.get("landing_page_url") or ""))
651 venue = normalize_whitespace(str((primary_location.get("source", {}) or {}).get("display_name", "")))
652 year = normalize_whitespace(str(item.get("publication_year", "")))
653 return {
654 "title": title,
655 "authors": authors,
656 "affiliations": affiliations,
657 "venue": venue,
658 "year": year,
659 "doi": doi,
660 "source": "openalex",
661 "source_type": "openalex",
662 "source_url": landing_page_url or normalize_whitespace(str(item.get("id", ""))),
663 "pdf_url": pdf_url,
664 "abstract": "",
665 "metadata_sources": ["openalex"],
666 }
667
668
669def fetch_openalex_by_doi(doi: str) -> dict[str, Any] | None:

Callers 2

fetch_openalex_by_doiFunction · 0.85
search_openalex_by_titleFunction · 0.85

Calls 2

normalize_whitespaceFunction · 0.85
extract_doiFunction · 0.85

Tested by

no test coverage detected