format tables code
This commit is contained in:
+24
-8
@@ -6,25 +6,41 @@ fn main() {
|
|||||||
// Find items containing "Description" or section numbers
|
// Find items containing "Description" or section numbers
|
||||||
println!("Items containing section markers:");
|
println!("Items containing section markers:");
|
||||||
for item in items.iter().filter(|i| i.page == 1) {
|
for item in items.iter().filter(|i| i.page == 1) {
|
||||||
if item.text.contains("Description") ||
|
if item.text.contains("Description")
|
||||||
item.text.starts_with("3 ") ||
|
|| item.text.starts_with("3 ")
|
||||||
item.text.starts_with("3 ") {
|
|| item.text.starts_with("3 ")
|
||||||
|
{
|
||||||
println!(" x={:6.1} y={:6.1} \"{}\"", item.x, item.y, item.text);
|
println!(" x={:6.1} y={:6.1} \"{}\"", item.x, item.y, item.text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look at the Y range for right column
|
// Look at the Y range for right column
|
||||||
let right_col: Vec<_> = items.iter()
|
let right_col: Vec<_> = items
|
||||||
|
.iter()
|
||||||
.filter(|i| i.page == 1 && i.x > 300.0 && i.x < 400.0)
|
.filter(|i| i.page == 1 && i.x > 300.0 && i.x < 400.0)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let y_min = right_col.iter().map(|i| i.y).fold(f32::INFINITY, f32::min);
|
let y_min = right_col.iter().map(|i| i.y).fold(f32::INFINITY, f32::min);
|
||||||
let y_max = right_col.iter().map(|i| i.y).fold(f32::NEG_INFINITY, f32::max);
|
let y_max = right_col
|
||||||
println!("\nRight column (x=300-400) Y range: {:.1} to {:.1}", y_min, y_max);
|
.iter()
|
||||||
|
.map(|i| i.y)
|
||||||
|
.fold(f32::NEG_INFINITY, f32::max);
|
||||||
|
println!(
|
||||||
|
"\nRight column (x=300-400) Y range: {:.1} to {:.1}",
|
||||||
|
y_min, y_max
|
||||||
|
);
|
||||||
|
|
||||||
// Show items near Y=675 (where "3 Description" appears)
|
// Show items near Y=675 (where "3 Description" appears)
|
||||||
println!("\nItems near Y=675 (±10):");
|
println!("\nItems near Y=675 (±10):");
|
||||||
for item in items.iter().filter(|i| i.page == 1 && (i.y - 675.0).abs() < 10.0) {
|
for item in items
|
||||||
println!(" x={:6.1} y={:6.1} \"{}\"", item.x, item.y, &item.text[..item.text.len().min(50)]);
|
.iter()
|
||||||
|
.filter(|i| i.page == 1 && (i.y - 675.0).abs() < 10.0)
|
||||||
|
{
|
||||||
|
println!(
|
||||||
|
" x={:6.1} y={:6.1} \"{}\"",
|
||||||
|
item.x,
|
||||||
|
item.y,
|
||||||
|
&item.text[..item.text.len().min(50)]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-6
@@ -111,7 +111,9 @@ pub fn to_markdown_from_items(items: Vec<TextItem>, options: MarkdownOptions) ->
|
|||||||
|
|
||||||
// Calculate base font size for table detection
|
// Calculate base font size for table detection
|
||||||
let font_stats = calculate_font_stats_from_items(&items);
|
let font_stats = calculate_font_stats_from_items(&items);
|
||||||
let base_size = options.base_font_size.unwrap_or(font_stats.most_common_size);
|
let base_size = options
|
||||||
|
.base_font_size
|
||||||
|
.unwrap_or(font_stats.most_common_size);
|
||||||
|
|
||||||
// Detect tables on each page
|
// Detect tables on each page
|
||||||
let mut table_items: HashSet<usize> = HashSet::new();
|
let mut table_items: HashSet<usize> = HashSet::new();
|
||||||
@@ -124,11 +126,7 @@ pub fn to_markdown_from_items(items: Vec<TextItem>, options: MarkdownOptions) ->
|
|||||||
pages.dedup();
|
pages.dedup();
|
||||||
|
|
||||||
for page in pages {
|
for page in pages {
|
||||||
let page_items: Vec<TextItem> = items
|
let page_items: Vec<TextItem> = items.iter().filter(|i| i.page == page).cloned().collect();
|
||||||
.iter()
|
|
||||||
.filter(|i| i.page == page)
|
|
||||||
.cloned()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let tables = detect_tables(&page_items, base_size);
|
let tables = detect_tables(&page_items, base_size);
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -159,9 +159,7 @@ fn check_column_alignment(items: &[(usize, &TextItem)], columns: &[f32]) -> f32
|
|||||||
let tolerance = 40.0;
|
let tolerance = 40.0;
|
||||||
let aligned = items
|
let aligned = items
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, item)| {
|
.filter(|(_, item)| columns.iter().any(|&col| (item.x - col).abs() < tolerance))
|
||||||
columns.iter().any(|&col| (item.x - col).abs() < tolerance)
|
|
||||||
})
|
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
aligned as f32 / items.len() as f32
|
aligned as f32 / items.len() as f32
|
||||||
|
|||||||
Reference in New Issue
Block a user