MCPcopy Create free account
hub / github.com/917Dhj/DeepPaperNote / normalize_caption_label

Function normalize_caption_label

scripts/common.py:2045–2081  ·  view source on GitHub ↗
(label: str)

Source from the content-addressed store, hash-verified

2043
2044
2045def normalize_caption_label(label: str) -> str:
2046 label = normalize_whitespace(label)
2047 chinese_match = re.match(r"^(图|表)\s*([A-Z]?\d+[a-z]?)$", label, re.IGNORECASE)
2048 if chinese_match:
2049 return f"{chinese_match.group(1)} {chinese_match.group(2)}"
2050 extended_figure_match = re.match(
2051 r"^extended\s+data\s+fig(?:ure)?\.?\s*(\d+[a-z]?)$",
2052 label,
2053 re.IGNORECASE,
2054 )
2055 if extended_figure_match:
2056 return f"Extended Data Fig {extended_figure_match.group(1)}"
2057 extended_table_match = re.match(
2058 r"^extended\s+data\s+table\.?\s*(\d+[a-z]?)$",
2059 label,
2060 re.IGNORECASE,
2061 )
2062 if extended_table_match:
2063 return f"Extended Data Table {extended_table_match.group(1)}"
2064 scheme_match = re.match(r"^(scheme|algorithm)\.?\s*(\d+[a-z]?)$", label, re.IGNORECASE)
2065 if scheme_match:
2066 return f"{scheme_match.group(1).capitalize()} {scheme_match.group(2)}"
2067 supplementary_match = re.match(
2068 r"^(supplementary)\s+(fig(?:ure)?|table)\.?\s*(\d+[a-z]?)$",
2069 label,
2070 re.IGNORECASE,
2071 )
2072 if supplementary_match:
2073 return f"{supplementary_match.group(1)} {supplementary_match.group(2)} {supplementary_match.group(3)}"
2074 english_match = re.match(
2075 r"^(fig(?:ure)?|table)\.?\s*([AS]?\d+[a-z]?)$",
2076 label,
2077 re.IGNORECASE,
2078 )
2079 if english_match:
2080 return f"{english_match.group(1)} {english_match.group(2)}"
2081 return label
2082
2083
2084CAPTION_REFERENCE_VERBS = {

Calls 1

normalize_whitespaceFunction · 0.85