1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Path extraction algorithms for lattices.
//!
//! This module provides efficient algorithms for finding optimal paths
//! through lattices:
//!
//! - **Viterbi**: Find the single best path using dynamic programming
//! - **N-best**: Extract the top-k paths using lazy enumeration
//! - **Beam search**: Approximate best paths with bounded memory
//!
//! # Algorithm Selection
//!
//! | Algorithm | Complexity | Memory | Use Case |
//! |-----------|------------|--------|----------|
//! | Viterbi | O(V + E) | O(V) | Single best path |
//! | N-best | O(k log k) | O(k × path_len) | Exact top-k paths |
//! | Beam | O(V × beam_width) | O(beam_width) | Approximate top-k |
//!
//! # Example
//!
//! ```rust
//! use lling_llang::lattice::{LatticeBuilder, EdgeMetadata};
//! use lling_llang::backend::HashMapBackend;
//! use lling_llang::semiring::TropicalWeight;
//! use lling_llang::path::{viterbi, nbest, beam_search};
//!
//! let backend = HashMapBackend::new();
//! let mut builder = LatticeBuilder::new(backend);
//!
//! builder.add_correction(0, 1, "the", TropicalWeight::new(0.5), EdgeMetadata::default());
//! builder.add_correction(0, 1, "a", TropicalWeight::new(1.0), EdgeMetadata::default());
//!
//! let mut lattice = builder.build(1);
//!
//! // Best path
//! let best = viterbi(&mut lattice);
//!
//! // Top 5 paths
//! let top5 = nbest(&mut lattice, 5);
//!
//! // Beam search with width 10
//! let approx = beam_search(&mut lattice, 10);
//! ```
pub use ;
pub use ;
pub use ;