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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Weighted Tree Transducers for syntax tree transformations.
//!
//! This module implements weighted tree transducers (WTTs) for transforming
//! weighted tree languages. Tree transducers generalize string transducers
//! to handle hierarchical structures like syntax trees.
//!
//! # Mathematical Definition
//!
//! A weighted tree transducer is a tuple T = (Q, Σ, Δ, q₀, F, R, ρ) where:
//! - Q: Finite set of states
//! - Σ: Input ranked alphabet (symbols with arities)
//! - Δ: Output ranked alphabet
//! - q₀: Initial state
//! - F ⊆ Q: Final states
//! - R: Set of weighted rules
//! - ρ: Final weight function
//!
//! # Rule Format
//!
//! Rules have the form:
//! ```text
//! q(σ(x₁,...,xₙ)) → δ(q₁(xπ(1)),...,qₘ(xπ(m))), w
//! ```
//!
//! Where variables can be reordered, copied, or deleted.
//!
//! # Example
//!
//! ```rust,ignore
//! use lling_llang::tree_transducers::{Tree, TreeTransducerBuilder, VectorTreeTransducer};
//! use lling_llang::semiring::TropicalWeight;
//!
//! // Build a tree transducer for syntax normalization
//! let mut builder = TreeTransducerBuilder::<String, TropicalWeight>::new();
//!
//! // Add rule: q(S(NP(x), VP(y))) → S(NP(x), VP(y)), 1.0
//! builder.add_rule(
//! 0, // state
//! "S".to_string(), // input symbol
//! vec![0, 1], // input children states
//! "S".to_string(), // output symbol
//! vec![TreeChild::Variable(0, 0), TreeChild::Variable(1, 1)], // output children
//! TropicalWeight::one(),
//! );
//!
//! let transducer = builder.build();
//! let output = transducer.transduce(&input_tree);
//! ```
//!
//! # Applications
//!
//! - Syntax-based machine translation
//! - Parse tree normalization
//! - AST-to-AST program transformation
//! - Tree-to-string linearization
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// State identifier for tree transducers.
pub type StateId = u32;