Files
tools/publish/src/rdf/curie.rs
T

30 lines
759 B
Rust
Raw Normal View History

2026-07-13 14:05:40 -04:00
use std::collections::BTreeMap;
#[derive(Clone)]
pub struct CurieHelper {
prefixes: BTreeMap<String, String>,
}
impl CurieHelper {
pub fn new(prefixes: BTreeMap<String, String>) -> Self {
Self {
prefixes,
}
}
pub fn abbreviate(&self, iri: &str) -> Option<String> {
for (name, base) in &self.prefixes {
if let Some(local_name) = iri.strip_prefix(base) {
return Some(format!("{name}:{local_name}"));
}
}
None
}
pub fn expand(&self, abbreviated_iri: &str) -> Option<String> {
let (prefix, name) = abbreviated_iri.split_once(':')?;
self.prefixes
.get(prefix)
.map(|base| format!("{base}{name}"))
}
}