diff options
| -rw-r--r-- | README.md | 15 | ||||
| -rw-r--r-- | morphology-cli/src/main.rs | 54 | ||||
| -rw-r--r-- | morphology/src/lib.rs | 5 |
3 files changed, 66 insertions, 8 deletions
@@ -16,6 +16,21 @@ cargo run --bin generate 5 # Run the generate command with pretty printing cargo run --bin generate -- --pretty 5 +# Sort with negative-first outer precedence +cargo run --bin generate 5 --neg-first-outer + +# Sort with negative-first inner precedence +cargo run --bin generate 5 --neg-first-inner + +# Sort with breadth-first sorting +cargo run --bin generate 5 --breadth-first + +# Sort with backward sorting direction +cargo run --bin generate 5 --backward + +# Sort with interpolated length sorting +cargo run --bin generate 5 --interpolate-length + # Run the release version cli ./target/release/generate --pretty 6 diff --git a/morphology-cli/src/main.rs b/morphology-cli/src/main.rs index 4d183ae..3686842 100644 --- a/morphology-cli/src/main.rs +++ b/morphology-cli/src/main.rs @@ -1,15 +1,19 @@ //! CLI tool to generate all valid meta-affine sequences of a given length. //! -//! Usage: generate [--pretty] <length> +//! Usage: generate [options] <length> //! //! Example: //! generate 5 //! generate --pretty 5 +//! generate 5 --neg-first-outer --backward //! //! This will list all valid meta-affine sequences of length 5 and print the total count. //! With --pretty, values are displayed in nested bracket notation. -use meta_affine::sequence::generate_all_sequences; +use meta_affine::sequence::{ + generate_all_sequences, SequenceOptions, PrecedenceOrder, SortingMethod, + SortingDirection, LengthSorting +}; use std::env; use std::process; @@ -17,8 +21,13 @@ fn main() { // Parse command-line arguments let args: Vec<String> = env::args().collect(); - // Check for --pretty flag + // Check for flags let pretty = args.contains(&"--pretty".to_string()); + let neg_first_outer = args.contains(&"--neg-first-outer".to_string()); + let neg_first_inner = args.contains(&"--neg-first-inner".to_string()); + let breadth_first = args.contains(&"--breadth-first".to_string()); + let backward = args.contains(&"--backward".to_string()); + let interpolate_length = args.contains(&"--interpolate-length".to_string()); // Filter out flags to get positional arguments let positional: Vec<&String> = args.iter() @@ -27,13 +36,21 @@ fn main() { .collect(); if positional.len() != 1 { - eprintln!("Usage: {} [--pretty] <length>", args[0]); + eprintln!("Usage: {} [options] <length>", args[0]); eprintln!("\nGenerates all valid meta-affine sequences of the specified length."); eprintln!("\nOptions:"); - eprintln!(" --pretty Display values in nested bracket notation"); + eprintln!(" --pretty Display values in nested bracket notation"); + eprintln!("\nSorting options:"); + eprintln!(" --neg-first-outer Use IncreasingNegativeFirst for outer precedence"); + eprintln!(" --neg-first-inner Use IncreasingNegativeFirst for inner precedence"); + eprintln!(" --breadth-first Use BreadthFirst sorting method"); + eprintln!(" --backward Sort sequences backward (last to first)"); + eprintln!(" --interpolate-length Interpolate sequences of different lengths"); eprintln!("\nExamples:"); eprintln!(" {} 5", args[0]); eprintln!(" {} --pretty 5", args[0]); + eprintln!(" {} 5 --neg-first-outer --backward", args[0]); + eprintln!(" {} 5 --breadth-first --interpolate-length", args[0]); process::exit(1); } @@ -54,8 +71,31 @@ fn main() { println!("Generating all valid meta-affine sequences of length {}...\n", length); - // Generate all sequences with default options - let sequences = generate_all_sequences(length, None); + // Build sorting options from flags + let mut options = SequenceOptions::new(); + + if neg_first_outer { + options = options.outer_order(PrecedenceOrder::IncreasingNegativeFirst); + } + + if neg_first_inner { + options = options.inner_order(PrecedenceOrder::IncreasingNegativeFirst); + } + + if breadth_first { + options = options.sorting_method(SortingMethod::BreadthFirst); + } + + if backward { + options = options.sorting_direction(SortingDirection::Backward); + } + + if interpolate_length { + options = options.length_sorting(LengthSorting::InterpolateLength); + } + + // Generate all sequences with specified options + let sequences = generate_all_sequences(length, Some(options)); // Choose delimiters based on output format let (open, close) = if pretty { ("", "") } else { ("[", "]") }; diff --git a/morphology/src/lib.rs b/morphology/src/lib.rs index fdb788b..de33f70 100644 --- a/morphology/src/lib.rs +++ b/morphology/src/lib.rs @@ -19,4 +19,7 @@ pub mod sequence; // Re-export main types and functions for convenience pub use value::{Value, get_minimum_derivation_path, path_length}; pub use set::ValidSet; -pub use sequence::{Sequence, PrecedenceOrder, SequenceOptions, sort_sequences, generate_all_sequences}; +pub use sequence::{ + Sequence, PrecedenceOrder, SequenceOptions, SortingMethod, SortingDirection, + LengthSorting, sort_sequences, generate_all_sequences +}; |