aboutsummaryrefslogtreecommitdiff
path: root/crates/cli/src/inflection.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-01-14 15:11:28 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-01-14 15:20:23 +0100
commita2b36100cc7e88e49f370d8649cc394e6da51e0c (patch)
treec362bd7d9f9b53c63f122c1cf4fcff64e062f6bd /crates/cli/src/inflection.rs
parenteff293a336d6211672b1d76fcdb4ffe74ef233db (diff)
downloadmihi-a2b36100cc7e88e49f370d8649cc394e6da51e0c.tar.gz
mihi-a2b36100cc7e88e49f370d8649cc394e6da51e0c.zip
Add the ability to sort cases via configuration
This means that it's no longer a matter of configuring it via the database, but much simpler. This should be more than enough. That being said, this is to be configured by hand so to not further complicate things. This is left to be done for the future, even if the default is basically what I use. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'crates/cli/src/inflection.rs')
-rw-r--r--crates/cli/src/inflection.rs133
1 files changed, 75 insertions, 58 deletions
diff --git a/crates/cli/src/inflection.rs b/crates/cli/src/inflection.rs
index 05c4c70..c8b8574 100644
--- a/crates/cli/src/inflection.rs
+++ b/crates/cli/src/inflection.rs
@@ -1,4 +1,7 @@
-use mihi::{group_declension_inflections, Category, DeclensionInfo, DeclensionTable, Gender, Word};
+use mihi::{
+ configuration, group_declension_inflections, Category, DeclensionInfo, DeclensionTable, Gender,
+ Word,
+};
fn get_inflected_from(word: &Word, row: &[DeclensionInfo; 2]) -> String {
if word.is_flag_set("onlysingular") {
@@ -27,20 +30,27 @@ fn print_noun_inflection(word: &Word) -> Result<(), String> {
println!("\n== Inflection ==\n");
- println!(
- "Nominative:\t{}",
- get_inflected_from(word, &table.nominative)
- );
- println!("Vocative:\t{}", get_inflected_from(word, &table.vocative));
- println!(
- "Accusative:\t{}",
- get_inflected_from(word, &table.accusative)
- );
- println!("Genitive:\t{}", get_inflected_from(word, &table.genitive));
- println!("Dative:\t\t{}", get_inflected_from(word, &table.dative));
- println!("Ablative:\t{}", get_inflected_from(word, &table.ablative));
- if word.locative {
- println!("Locative:\t{}", get_inflected_from(word, &table.locative));
+ for idx in configuration().case_order.to_usizes() {
+ match idx {
+ 0 => println!(
+ "Nominative:\t{}",
+ get_inflected_from(word, &table.nominative)
+ ),
+ 1 => println!("Vocative:\t{}", get_inflected_from(word, &table.vocative)),
+ 2 => println!(
+ "Accusative:\t{}",
+ get_inflected_from(word, &table.accusative)
+ ),
+ 3 => println!("Genitive:\t{}", get_inflected_from(word, &table.genitive)),
+ 4 => println!("Dative:\t\t{}", get_inflected_from(word, &table.dative)),
+ 5 => println!("Ablative:\t{}", get_inflected_from(word, &table.ablative)),
+ 6 => {
+ if word.locative {
+ println!("Locative:\t{}", get_inflected_from(word, &table.locative));
+ }
+ }
+ _ => {}
+ }
}
Ok(())
@@ -76,49 +86,56 @@ fn print_adjective_inflection(word: &Word) -> Result<(), String> {
println!("\n== Inflection ==\n");
- println!(
- "Nominative:\t{} | {} | {}",
- get_inflected_from(word, &tables[0].nominative),
- get_inflected_from(word, &tables[1].nominative),
- get_inflected_from(word, &tables[2].nominative)
- );
- println!(
- "Vocative:\t{} | {} | {}",
- get_inflected_from(word, &tables[0].vocative),
- get_inflected_from(word, &tables[1].vocative),
- get_inflected_from(word, &tables[2].vocative)
- );
- println!(
- "Accusative:\t{} | {} | {}",
- get_inflected_from(word, &tables[0].accusative),
- get_inflected_from(word, &tables[1].accusative),
- get_inflected_from(word, &tables[2].accusative)
- );
- println!(
- "Genitive:\t{} | {} | {}",
- get_inflected_from(word, &tables[0].genitive),
- get_inflected_from(word, &tables[1].genitive),
- get_inflected_from(word, &tables[2].genitive)
- );
- println!(
- "Dative:\t\t{} | {} | {}",
- get_inflected_from(word, &tables[0].dative),
- get_inflected_from(word, &tables[1].dative),
- get_inflected_from(word, &tables[2].dative)
- );
- println!(
- "Ablative:\t{} | {} | {}",
- get_inflected_from(word, &tables[0].ablative),
- get_inflected_from(word, &tables[1].ablative),
- get_inflected_from(word, &tables[2].ablative)
- );
- if word.locative {
- println!(
- "Locative:\t{} | {} | {}",
- get_inflected_from(word, &tables[0].locative),
- get_inflected_from(word, &tables[1].locative),
- get_inflected_from(word, &tables[2].locative)
- );
+ for idx in configuration().case_order.to_usizes() {
+ match idx {
+ 0 => println!(
+ "Nominative:\t{} | {} | {}",
+ get_inflected_from(word, &tables[0].nominative),
+ get_inflected_from(word, &tables[1].nominative),
+ get_inflected_from(word, &tables[2].nominative)
+ ),
+ 1 => println!(
+ "Vocative:\t{} | {} | {}",
+ get_inflected_from(word, &tables[0].vocative),
+ get_inflected_from(word, &tables[1].vocative),
+ get_inflected_from(word, &tables[2].vocative)
+ ),
+ 2 => println!(
+ "Accusative:\t{} | {} | {}",
+ get_inflected_from(word, &tables[0].accusative),
+ get_inflected_from(word, &tables[1].accusative),
+ get_inflected_from(word, &tables[2].accusative)
+ ),
+ 3 => println!(
+ "Genitive:\t{} | {} | {}",
+ get_inflected_from(word, &tables[0].genitive),
+ get_inflected_from(word, &tables[1].genitive),
+ get_inflected_from(word, &tables[2].genitive)
+ ),
+ 4 => println!(
+ "Dative:\t\t{} | {} | {}",
+ get_inflected_from(word, &tables[0].dative),
+ get_inflected_from(word, &tables[1].dative),
+ get_inflected_from(word, &tables[2].dative)
+ ),
+ 5 => println!(
+ "Ablative:\t{} | {} | {}",
+ get_inflected_from(word, &tables[0].ablative),
+ get_inflected_from(word, &tables[1].ablative),
+ get_inflected_from(word, &tables[2].ablative)
+ ),
+ 6 => {
+ if word.locative {
+ println!(
+ "Locative:\t{} | {} | {}",
+ get_inflected_from(word, &tables[0].locative),
+ get_inflected_from(word, &tables[1].locative),
+ get_inflected_from(word, &tables[2].locative)
+ );
+ }
+ }
+ _ => {}
+ }
}
Ok(())