File size: 945 Bytes
a4e4cb2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from __future__ import annotations
import re
from clause_index import normalize_node
SECTION_REF_RE = re.compile(r"Section\s+(\d+(?:\.\d+)*(?:\([a-z]\))?)")
APPENDIX_REF_RE = re.compile(r"Appendix\s+([IVXLC]+)")
SCHEDULE_REF_RE = re.compile(r"Schedule\s+([A-Z])")
def extract_reference_candidates(line: str, include_appendix_and_schedule: bool = False) -> list[dict]:
refs: list[dict] = []
for match in SECTION_REF_RE.finditer(line):
refs.append({"target": normalize_node("section", match.group(1)), "target_type": "section"})
if include_appendix_and_schedule:
for match in APPENDIX_REF_RE.finditer(line):
refs.append({"target": normalize_node("appendix", match.group(1)), "target_type": "appendix"})
for match in SCHEDULE_REF_RE.finditer(line):
refs.append({"target": normalize_node("schedule", match.group(1)), "target_type": "schedule"})
return refs
|