summaryrefslogtreecommitdiff
path: root/morphology/examples
diff options
context:
space:
mode:
Diffstat (limited to 'morphology/examples')
-rw-r--r--morphology/examples/test_all_sorting_options.rs69
-rw-r--r--morphology/examples/test_length_sorting.rs64
2 files changed, 133 insertions, 0 deletions
diff --git a/morphology/examples/test_all_sorting_options.rs b/morphology/examples/test_all_sorting_options.rs
new file mode 100644
index 0000000..2b60b3f
--- /dev/null
+++ b/morphology/examples/test_all_sorting_options.rs
@@ -0,0 +1,69 @@
+// Test program demonstrating all sorting options working together
+
+use meta_affine::{Sequence, Value};
+use meta_affine::sequence::{
+ sort_sequences, SequenceOptions,
+ PrecedenceOrder, SortingMethod, SortingDirection, LengthSorting
+};
+
+fn print_sequences(label: &str, sequences: &[Sequence]) {
+ println!("\n{}:", label);
+ for (i, seq) in sequences.iter().enumerate() {
+ print!(" {}: len={} [", i, seq.length());
+ for (j, v) in seq.values().iter().enumerate() {
+ if j > 0 { print!(", "); }
+ print!("({},{})", v.outer, v.inner);
+ }
+ println!("]");
+ }
+}
+
+fn main() {
+ // Create diverse sequences to showcase all options
+ let sequences = vec![
+ Sequence::new(vec![Value::new(1, 0), Value::new(0, 0)]),
+ Sequence::new(vec![Value::new(0, 0)]),
+ Sequence::new(vec![Value::new(0, 1), Value::new(1, 0), Value::new(0, 0)]),
+ Sequence::new(vec![Value::new(1, 0), Value::new(0, 1), Value::new(0, 0)]),
+ Sequence::new(vec![Value::new(0, 1), Value::new(0, 0)]),
+ ];
+
+ print_sequences("Original sequences", &sequences);
+
+ // Example 1: All defaults
+ let mut test1 = sequences.clone();
+ sort_sequences(&mut test1, None);
+ print_sequences("Defaults (InterpolateLength, Forward, DepthFirst, IncreasingPositiveFirst)", &test1);
+
+ // Example 2: SegregateLength only
+ let mut test2 = sequences.clone();
+ let opts = SequenceOptions::new()
+ .length_sorting(LengthSorting::SegregateLength);
+ sort_sequences(&mut test2, opts);
+ print_sequences("SegregateLength + defaults", &test2);
+
+ // Example 3: BreadthFirst + Backward
+ let mut test3 = sequences.clone();
+ let opts = SequenceOptions::new()
+ .sorting_method(SortingMethod::BreadthFirst)
+ .sorting_direction(SortingDirection::Backward);
+ sort_sequences(&mut test3, opts);
+ print_sequences("BreadthFirst + Backward + InterpolateLength", &test3);
+
+ // Example 4: All custom options combined
+ let mut test4 = sequences.clone();
+ let opts = SequenceOptions::new()
+ .length_sorting(LengthSorting::SegregateLength)
+ .sorting_direction(SortingDirection::Backward)
+ .sorting_method(SortingMethod::BreadthFirst)
+ .outer_order(PrecedenceOrder::IncreasingNegativeFirst)
+ .inner_order(PrecedenceOrder::IncreasingPositiveFirst);
+ sort_sequences(&mut test4, opts);
+ print_sequences("All custom: SegregateLength + Backward + BreadthFirst + custom precedence", &test4);
+
+ println!("\n=== Complete Sorting Options ===");
+ println!("LengthSorting: InterpolateLength (default) | SegregateLength");
+ println!("SortingDirection: Forward (default) | Backward");
+ println!("SortingMethod: DepthFirst (default) | BreadthFirst");
+ println!("PrecedenceOrder: IncreasingPositiveFirst (default) | IncreasingNegativeFirst");
+}
diff --git a/morphology/examples/test_length_sorting.rs b/morphology/examples/test_length_sorting.rs
new file mode 100644
index 0000000..2163e50
--- /dev/null
+++ b/morphology/examples/test_length_sorting.rs
@@ -0,0 +1,64 @@
+// Test program to demonstrate InterpolateLength vs SegregateLength sorting
+
+use meta_affine::{Sequence, Value};
+use meta_affine::sequence::{sort_sequences, SequenceOptions, LengthSorting, SortingMethod};
+
+fn print_sequences(label: &str, sequences: &[Sequence]) {
+ println!("\n{}:", label);
+ for (i, seq) in sequences.iter().enumerate() {
+ print!(" {}: [", i);
+ for (j, v) in seq.values().iter().enumerate() {
+ if j > 0 { print!(", "); }
+ print!("({},{})", v.outer, v.inner);
+ }
+ println!("] (length {})", seq.length());
+ }
+}
+
+fn main() {
+ // Create sequences of different lengths
+ let sequences = vec![
+ // Length 3
+ Sequence::new(vec![Value::new(1, 0), Value::new(0, 1), Value::new(0, 0)]),
+ // Length 1
+ Sequence::new(vec![Value::new(0, 0)]),
+ // Length 2
+ Sequence::new(vec![Value::new(1, 0), Value::new(0, 0)]),
+ // Length 3
+ Sequence::new(vec![Value::new(0, 1), Value::new(1, 0), Value::new(0, 0)]),
+ // Length 2
+ Sequence::new(vec![Value::new(0, 1), Value::new(0, 0)]),
+ // Length 4
+ Sequence::new(vec![Value::new(1, 0), Value::new(0, 1), Value::new(1, 0), Value::new(0, 0)]),
+ ];
+
+ print_sequences("Original sequences", &sequences);
+
+ // Test InterpolateLength (default) - sequences sorted by content, length mixed in
+ let mut interpolate = sequences.clone();
+ let opts = SequenceOptions::new()
+ .length_sorting(LengthSorting::InterpolateLength)
+ .sorting_method(SortingMethod::DepthFirst);
+ sort_sequences(&mut interpolate, opts);
+
+ print_sequences("InterpolateLength (sorted by content, lengths mixed)", &interpolate);
+ println!(" Explanation: Sequences are sorted by their content values");
+ println!(" Length is only considered when content is equal");
+
+ // Test SegregateLength - sequences grouped by length, then sorted by content within each group
+ let mut segregate = sequences.clone();
+ let opts = SequenceOptions::new()
+ .length_sorting(LengthSorting::SegregateLength)
+ .sorting_method(SortingMethod::DepthFirst);
+ sort_sequences(&mut segregate, opts);
+
+ print_sequences("SegregateLength (grouped by length, then by content)", &segregate);
+ println!(" Explanation: All length-1 sequences come first (sorted by content)");
+ println!(" Then all length-2 sequences (sorted by content)");
+ println!(" Then all length-3 sequences (sorted by content)");
+ println!(" Then all length-4 sequences (sorted by content)");
+
+ println!("\n=== Summary ===");
+ println!("InterpolateLength: Length is only a tiebreaker when content is equal");
+ println!("SegregateLength: Sequences are grouped by length first, shorter always before longer");
+}