(pdf_path: Any)
| 553 | return _first_matching_url(body, "/abs/") |
| 554 | |
| 555 | |
| 556 | def _extract_institution_from_pdf(pdf_path: Any) -> str: |
| 557 | path = Path(str(pdf_path or "")).expanduser() |
| 558 | if not path.exists() or not path.is_file(): |
| 559 | return "" |
| 560 | try: |
| 561 | import fitz # type: ignore |
| 562 | except Exception: |
| 563 | return "" |
| 564 | try: |
| 565 | with fitz.open(str(path)) as doc: |
| 566 | text = "\n".join(doc[index].get_text() for index in range(min(2, len(doc)))) |
| 567 | except Exception: |
| 568 | return "" |
| 569 | |
| 570 | institutions: List[str] = [] |
| 571 | strong_institution_terms = ( |
| 572 | "university", |
| 573 | "academy", |
| 574 | "institute", |
| 575 | "laboratory", |
| 576 | "lab", |
| 577 | "college", |
| 578 | "school", |
| 579 | "centre", |
| 580 | "center", |
| 581 | ) |
| 582 | stop_terms = ("abstract", "introduction", "figure", "code is available") |
| 583 | for raw_line in text.splitlines()[:120]: |
| 584 | line = re.sub(r"^\s*\d+\s*", "", raw_line).strip() |
| 585 | line = re.sub(r"\s+", " ", line) |
| 586 | if not line: |
| 587 | continue |
| 588 | lowered = line.lower() |
| 589 | if any(term in lowered for term in stop_terms): |
| 590 | break |
| 591 | if "@" in line or len(line) > 140: |
| 592 | continue |
| 593 | if any(term in lowered for term in strong_institution_terms): |
| 594 | value = re.sub(r"^[*†‡§\d,\s]+", "", line).strip(" ;,") |
| 595 | if value and value not in institutions: |
| 596 | institutions.append(value) |
| 597 | return "; ".join(institutions[:8]) |
| 598 | |
| 599 |
no outgoing calls
no test coverage detected