(xml_content: str)
| 418 | |
| 419 | |
| 420 | def parse_arxiv_xml(xml_content: str) -> list[dict[str, Any]]: |
| 421 | papers: list[dict[str, Any]] = [] |
| 422 | root = ET.fromstring(xml_content) |
| 423 | for entry in root.findall("atom:entry", ARXIV_NS): |
| 424 | paper: dict[str, Any] = { |
| 425 | "source": "arxiv", |
| 426 | "source_type": "arxiv", |
| 427 | "metadata_sources": ["arxiv"], |
| 428 | } |
| 429 | id_elem = entry.find("atom:id", ARXIV_NS) |
| 430 | if id_elem is not None and id_elem.text: |
| 431 | paper["source_url"] = normalize_whitespace(id_elem.text) |
| 432 | paper["url"] = paper["source_url"] |
| 433 | arxiv_id = extract_arxiv_id(paper["source_url"]) |
| 434 | if arxiv_id: |
| 435 | paper["arxiv_id"] = arxiv_id |
| 436 | |
| 437 | title_elem = entry.find("atom:title", ARXIV_NS) |
| 438 | paper["title"] = normalize_whitespace(title_elem.text if title_elem is not None else "") |
| 439 | |
| 440 | summary_elem = entry.find("atom:summary", ARXIV_NS) |
| 441 | paper["abstract"] = normalize_whitespace(summary_elem.text if summary_elem is not None else "") |
| 442 | |
| 443 | journal_ref_elem = entry.find("arxiv:journal_ref", ARXIV_NS) |
| 444 | journal_ref = normalize_whitespace(journal_ref_elem.text if journal_ref_elem is not None else "") |
| 445 | if journal_ref: |
| 446 | paper["venue"] = journal_ref |
| 447 | |
| 448 | doi_elem = entry.find("arxiv:doi", ARXIV_NS) |
| 449 | if doi_elem is not None and doi_elem.text: |
| 450 | paper["doi"] = normalize_whitespace(doi_elem.text) |
| 451 | |
| 452 | authors = [] |
| 453 | for author in entry.findall("atom:author", ARXIV_NS): |
| 454 | name_elem = author.find("atom:name", ARXIV_NS) |
| 455 | if name_elem is not None and name_elem.text: |
| 456 | authors.append(normalize_whitespace(name_elem.text)) |
| 457 | paper["authors"] = authors |
| 458 | |
| 459 | published_elem = entry.find("atom:published", ARXIV_NS) |
| 460 | if published_elem is not None and published_elem.text: |
| 461 | paper["published"] = normalize_whitespace(published_elem.text) |
| 462 | if re.match(r"^\d{4}", paper["published"]): |
| 463 | paper["year"] = paper["published"][:4] |
| 464 | |
| 465 | for link in entry.findall("atom:link", ARXIV_NS): |
| 466 | if link.get("title") == "pdf" and link.get("href"): |
| 467 | paper["pdf_url"] = str(link.get("href")) |
| 468 | break |
| 469 | |
| 470 | papers.append(paper) |
| 471 | return papers |
| 472 | |
| 473 | |
| 474 | def fetch_arxiv_entries(*, search_query: str = "", id_list: str = "", max_results: int = 10) -> list[dict[str, Any]]: |
no test coverage detected