INNER CODE UNIT · Python
normalize_figure
gokayfem/awesome-vlm-architectures · scripts/extract_architecture_figures.py:46
def normalize_figure(value: str) -> str:
return re.sub(
r"[^0-9a-z]", "", value.lower().replace("figure", "").replace("fig", "")
)
def find_caption_block(page: fitz.Page, figure: str) -> tuple[fitz.Rect, str]:
wanted = normalize_figure(figure)
patterns = [
re.compile(rf"(?:Figure|Fig\.)\s*{re.escape(wanted)}\b", re.I),
re.compile(
rf"(?:Figure|Fig\.)\s*{re.escape(wanted.rstrip('abcdefghijklmnopqrstuvwxyz'))}\b",
re.I,
),
]
matches: list[tuple[fitz.Rect, str]] = []
for block in page.get_text("blocks", sort=True):
text = re.sub(r"\s+", " ", block[4]).strip()