Skip to main content

docvortex_core/
lib.rs

1//! 不访问 Python 对象或 PDFium 的单线程批量计算内核。
2
3pub const PROTOCOL_VERSION: u32 = 35;
4pub mod classification_visuals;
5pub mod columns;
6pub mod form_events;
7pub mod note_index;
8pub mod row_geometry;
9pub mod rule_graphics;
10pub mod rule_text;
11pub mod spatial;
12pub mod text_classification;
13pub mod text_projection;
14
15pub mod dedup;
16pub mod extraction;
17pub mod geometry;
18pub mod scripts;
19pub mod tables;
20
21/// 对有限数值稳定排序并计算与 statistics.median 相同的中位数。
22pub fn median(mut values: Vec<f64>) -> f64 {
23    values.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal));
24    let n = values.len();
25    if n == 0 {
26        return 0.0;
27    }
28    if n % 2 == 1 {
29        values[n / 2]
30    } else {
31        (values[n / 2 - 1] + values[n / 2]) / 2.0
32    }
33}
34
35/// 使用 Python round 的偶数舍入选择已有样本,不做插值。
36pub fn quantile(mut values: Vec<f64>, fraction: f64) -> f64 {
37    if values.is_empty() {
38        return 0.0;
39    }
40    values.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal));
41    values[((values.len() - 1) as f64 * fraction).round_ties_even() as usize]
42}
43
44pub mod statistics;
45
46pub mod inline_pairs;
47
48pub mod annotation_geometry;
49pub mod table_candidates;
50pub mod text_pipeline;
51
52pub mod text_assignment;
53pub mod text_content;
54pub mod text_snapshot;
55pub mod text_spacing;
56
57pub mod geometry_risk;
58pub mod geometry_runs;
59pub mod geometry_style;
60
61pub mod geometry_lines;
62
63pub mod table_merge;
64
65pub mod exact_mean;
66pub mod pixels;
67
68pub mod inline_styles;
69
70pub mod image_drawing;
71pub mod image_numeric;