From 28e853e6b085c625af03be5211ded3f307c0fd96 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 15 Jan 2026 15:43:15 +0100 Subject: Add a 'categories' parameter to 'select_words_except' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way the -c/--category flag can also work together with the -i/--inflection one. Signed-off-by: Miquel Sabaté Solà --- lib/mihi/src/lib.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs index ea7839e..8153b87 100644 --- a/lib/mihi/src/lib.rs +++ b/lib/mihi/src/lib.rs @@ -659,11 +659,23 @@ pub fn select_relevant_words( } /// Select a set of words except for the ones passed in the `excluded` -/// vector. It also accepts a set of boolean `flags` as with functions like -/// `select_relevant_words`. -pub fn select_words_except(excluded: &[Word], flags: &Vec) -> Result, String> { +/// vector. You have to pass the categories to be selected via the `categories` +/// parameter, which cannot be empty. It also accepts a set of boolean `flags` +/// as with functions like `select_relevant_words`. +pub fn select_words_except( + excluded: &[Word], + categories: &[Category], + flags: &Vec, +) -> Result, String> { + assert!(!categories.is_empty()); + let ids = excluded.iter().map(|w| w.id).collect::>(); let placeholders = ids.iter().map(|_| "?").collect::>().join(", "); + let cats = categories + .iter() + .map(|c| format!("{}", *c as isize)) + .collect::>() + .join(", "); let conn = get_connection()?; let mut stmt = conn @@ -673,12 +685,11 @@ pub fn select_words_except(excluded: &[Word], flags: &Vec) -> Result