fix: require digit after Table/Figure prefix in caption detection

Caption detection was incorrectly classifying "Table of Contents" as a
caption because it starts with "Table ". Now "Table" and "Figure"
prefixes require a digit, parenthesis, or hash after them — matching
actual captions like "Table 1", "Figure 3.2" but not titles.

Also removes debug logging left from previous iteration.

Benchmark improvement: MHS 0.52→0.54, overall 0.757→0.761.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Abimael Martell
2026-04-04 01:13:17 -07:00
co-authored by Claude Opus 4.6
parent 103995c200
commit b25a122655
2 changed files with 31 additions and 11 deletions
+29 -9
View File
@@ -4,13 +4,11 @@
pub(crate) fn is_caption_line(text: &str) -> bool { pub(crate) fn is_caption_line(text: &str) -> bool {
let trimmed = text.trim(); let trimmed = text.trim();
// Common caption prefixes in multiple languages // Caption prefixes that always match (always followed by identifiers)
let caption_prefixes = [ let always_prefixes = [
"Figure ",
"Figura ", "Figura ",
"Fig. ", "Fig. ",
"Fig ", "Fig ",
"Table ",
"Tabela ", "Tabela ",
"Source:", "Source:",
"Fonte:", "Fonte:",
@@ -27,17 +25,39 @@ pub(crate) fn is_caption_line(text: &str) -> bool {
"Photo ", "Photo ",
"Foto ", "Foto ",
]; ];
for prefix in &always_prefixes {
// Check if line starts with a caption prefix
for prefix in &caption_prefixes {
if trimmed.starts_with(prefix) { if trimmed.starts_with(prefix) {
return true; return true;
} }
} }
// Check case-insensitive patterns // "Figure" and "Table" need a digit/reference after them to distinguish
// captions ("Table 1", "Figure 3.2") from headings ("Table of Contents")
for prefix in ["Figure ", "Table "] {
if let Some(rest) = trimmed.strip_prefix(prefix) {
if rest
.trim_start()
.starts_with(|c: char| c.is_ascii_digit() || c == '(' || c == '#')
{
return true;
}
}
}
// Check case-insensitive patterns — require digit or punctuation after
// prefix to avoid matching "Table of Contents" or "Figure drawing" etc.
let lower = trimmed.to_lowercase(); let lower = trimmed.to_lowercase();
if lower.starts_with("figure ") || lower.starts_with("table ") || lower.starts_with("source:") { for pfx in ["figure ", "table "] {
if let Some(rest) = lower.strip_prefix(pfx) {
if rest
.trim_start()
.starts_with(|c: char| c.is_ascii_digit() || c == '(' || c == '#')
{
return true;
}
}
}
if lower.starts_with("source:") {
return true; return true;
} }
+2 -2
View File
@@ -6,7 +6,7 @@
8 4 Z E L L / L U R I E R E A L E S T A T E C E N T E R 8 4 Z E L L / L U R I E R E A L E S T A T E C E N T E R
**Table I: Cap rate correlations** ## Table I: Cap rate correlations
## Cap Rate Correlation With:* ## Cap Rate Correlation With:*
@@ -38,7 +38,7 @@ R E V I E W 8 5
1982 1986 1990 1994 1998 2002 2006 1982 1986 1990 1994 1998 2002 2006
**Table II: Correlationsofspreadsbypropertytype** ## Table II: Correlationsofspreadsbypropertytype
## Correlation of Cap Rate Spreads Over Treasury ## Correlation of Cap Rate Spreads Over Treasury