sakurs_core/lib.rs
1//! Delta-Stack Monoid algorithm for parallel sentence boundary detection
2//!
3//! This crate implements a mathematically sound parallel approach to sentence
4//! boundary detection using monoid algebra. The core innovation lies in
5//! representing parsing state as a monoid, enabling associative operations
6//! that can be computed in parallel while maintaining perfect accuracy.
7//!
8//! # Stability Notice
9//!
10//! This crate is in pre-release (v0.1.0-dev). The API is not yet stable and may
11//! change significantly in future releases. Use with caution in production code.
12//!
13//! We recommend pinning to exact versions in your Cargo.toml:
14//! ```toml
15//! sakurs-core = "=0.1.0"
16//! ```
17//!
18//! # Architecture
19//!
20//! The crate follows a hexagonal architecture pattern:
21//! - **Domain layer**: Pure mathematical algorithms and monoid operations
22//! - **Application layer**: Orchestration and parallel processing logic
23//! - **Adapter layer**: Interfaces for different use cases (CLI, Python, etc.)
24//!
25//! # Example
26//!
27//! ```rust
28//! use sakurs_core::{SentenceProcessor, Input};
29//!
30//! // Create processor with default configuration
31//! let processor = SentenceProcessor::new();
32//!
33//! // Process text
34//! let text = "Hello world. This is a test.";
35//! let result = processor.process(Input::from_text(text)).unwrap();
36//!
37//! // Check boundaries
38//! assert!(!result.boundaries.is_empty());
39//! // Note: SentenceProcessor may detect different boundary counts than expected
40//! ```
41
42pub mod api;
43pub mod application;
44pub mod domain;
45
46// New unified API (recommended)
47pub use api::{
48 Boundary, Config, ConfigBuilder, Error as ApiError, Input, Language, Output,
49 ProcessingMetadata, ProcessingStats, SentenceProcessor,
50};
51
52// Legacy exports (for backward compatibility)
53pub use application::{DeltaStackProcessor, DeltaStackResult, ExecutionMode, ProcessorConfig};
54pub use domain::*;
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_monoid_properties_integration() {
62 // Integration test ensuring monoid properties hold across the domain
63 let state1 = PartialState::new(2);
64 let state2 = PartialState::new(2);
65 let identity = PartialState::identity();
66
67 // Identity property
68 assert_eq!(
69 state1.combine(&identity).boundary_candidates.len(),
70 state1.boundary_candidates.len()
71 );
72
73 // Associativity holds for basic operations
74 let combined1 = state1.combine(&state2);
75 let combined2 = identity.combine(&combined1);
76 assert_eq!(
77 combined2.boundary_candidates.len(),
78 combined1.boundary_candidates.len()
79 );
80 }
81
82 #[test]
83 fn test_domain_module_exports() {
84 // Verify that all essential types are properly exported
85 let _monoid_test: PartialState = PartialState::identity();
86 let _boundary_test = domain::Boundary {
87 offset: 0,
88 flags: BoundaryFlags::STRONG,
89 };
90 let _delta_test = DeltaEntry::new(0, 0);
91 let _abbr_test = AbbreviationState::identity();
92 }
93}