(document: Dict[str, Any])
| 1451 | |
| 1452 | def _normalize_source_page_document(document: Dict[str, Any]) -> Optional[Dict[str, Any]]: |
| 1453 | if not isinstance(document, dict): |
| 1454 | return None |
| 1455 | |
| 1456 | sections = document.get("sections") or {} |
| 1457 | normalized_sections: Dict[str, str] = {} |
| 1458 | if isinstance(sections, dict): |
| 1459 | for key, value in sections.items(): |
| 1460 | cleaned_key = _clean_text(key).lower() |
| 1461 | cleaned_value = _clean_text(value) |
| 1462 | if cleaned_key and cleaned_value: |
| 1463 | normalized_sections[cleaned_key] = cleaned_value |
| 1464 | |
| 1465 | normalized_document = { |
| 1466 | "source_kind": "source_page", |
| 1467 | "source_url": _clean_text(document.get("source_url")), |
| 1468 | "abstract": _clean_text(document.get("abstract")), |
| 1469 | "sections": normalized_sections, |
| 1470 | "full_text": _clean_text(document.get("full_text")), |
| 1471 | } |
| 1472 | |
| 1473 | if not ( |
| 1474 | normalized_document["abstract"] |
| 1475 | or normalized_document["sections"] |
| 1476 | or normalized_document["full_text"] |
| 1477 | ): |
| 1478 | return None |
| 1479 | |
| 1480 | if not normalized_document["full_text"]: |
| 1481 | ordered_parts: List[str] = [] |
| 1482 | if normalized_document["abstract"]: |
| 1483 | ordered_parts.append(normalized_document["abstract"]) |
| 1484 | for section_name in ( |
| 1485 | "introduction", |
| 1486 | "background", |
| 1487 | "method", |
| 1488 | "results", |
| 1489 | "experiments", |
| 1490 | "discussion", |
| 1491 | "limitations", |
| 1492 | "conclusion", |
| 1493 | ): |
| 1494 | section_text = normalized_document["sections"].get(section_name) |
| 1495 | if section_text and section_text not in ordered_parts: |
| 1496 | ordered_parts.append(section_text) |
| 1497 | for section_text in normalized_document["sections"].values(): |
| 1498 | if section_text and section_text not in ordered_parts: |
| 1499 | ordered_parts.append(section_text) |
| 1500 | normalized_document["full_text"] = " ".join(ordered_parts).strip() |
| 1501 | |
| 1502 | return normalized_document |
| 1503 | |
| 1504 | |
| 1505 | def _get_source_page_document(paper: Dict[str, Any]) -> Optional[Dict[str, Any]]: |
| 1506 | metadata = paper.get("metadata") or {} |
no test coverage detected