feat: introduce obitaxonomy crate for hierarchical taxonomy parsing

Adds the `obitaxonomy` crate to parse and validate hierarchical taxonomy paths using a strict `taxonomy:/name@rank/...` syntax. Replaces generic string-based path matching in predicates with structured `TaxPath` and `TaxPattern` types, enforcing explicit anchor constraints and rank-aware semantics. Updates filtering documentation to clarify optional leading slashes and segment-boundary matching rules.
This commit is contained in:
Eric Coissac committed 2026-06-22 10:24:04 +02:00
1 parent c694e1f2b0
commit 9356be4ec0
12 files changed
+464 -18

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ obikpartitionner = { path = "../obikpartitionner" }
obisys = { path = "../obisys" }
obiskio = { path = "../obiskio" }
obikindex = { path = "../obikindex" }
obitaxonomy = { path = "../obitaxonomy" }
obilayeredmap = { path = "../obilayeredmap" }
clap = { version = "4", features = ["derive"] }
serde_json = "1"
+8 -12
View File
@@ -3,6 +3,7 @@ use std::collections::HashMap;
use clap::Args;
use obikindex::GenomeInfo;
use obikpartitionner::{GroupQuorumFilter, KmerFilter};
use obitaxonomy::{TaxPath, TaxPattern};
// ── Operator ──────────────────────────────────────────────────────────────────
@@ -49,12 +50,6 @@ impl MetaPred {
if values.iter().any(|v| v.is_empty()) {
return Err(format!("empty value in predicate: {s}"));
}
if matches!(op, PredOp::Matches | PredOp::NotMatches) {
if let Some(v) = values.iter().find(|v| !v.starts_with('/')) {
return Err(format!("path predicate value must start with '/': {v:?} in predicate: {s}"));
}
}
Ok(Self { key, op, values })
}
@@ -75,14 +70,15 @@ impl MetaPred {
// ── Path matching ─────────────────────────────────────────────────────────────
/// True if `value` is equal to `pattern` or is a descendant of it in a `/`-separated hierarchy.
/// True if the stored taxonomy `value` matches `pattern`.
///
/// Both `value` and `pattern` must start with `/`.
/// `value` matches if it equals `pattern` exactly or starts with `pattern` followed by `/`.
/// `value` must be a valid `TaxPath` (starts with `taxonomy:/`).
/// `pattern` is a `TaxPattern` query (see `obitaxonomy::TaxPattern` for syntax).
/// Returns `false` if either fails to parse.
fn path_matches(value: &str, pattern: &str) -> bool {
value == pattern
|| (value.starts_with(pattern)
&& value[pattern.len()..].starts_with('/'))
let Ok(path) = TaxPath::parse(value) else { return false };
let Ok(pat) = TaxPattern::parse(pattern) else { return false };
pat.matches(&path)
}
// ── Three-value group evaluation ──────────────────────────────────────────────