.
This commit is contained in:
@@ -12,7 +12,11 @@ impl CurieHelper {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn abbreviate(&self, iri: &str) -> Option<String> {
|
||||
pub fn abbreviate(&self, base: Option<&str>, iri: &str) -> Option<String> {
|
||||
if let Some(base) = base && let Some(local_name) = iri.strip_prefix(base) {
|
||||
return Some(format!(":{local_name}"));
|
||||
}
|
||||
|
||||
for (name, base) in &self.prefixes {
|
||||
if let Some(local_name) = iri.strip_prefix(base) {
|
||||
return Some(format!("{name}:{local_name}"));
|
||||
@@ -21,10 +25,15 @@ impl CurieHelper {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn expand(&self, abbreviated_iri: &str) -> Option<String> {
|
||||
pub fn expand(&self, base: Option<&str>, abbreviated_iri: &str) -> Option<String> {
|
||||
let (prefix, name) = abbreviated_iri.split_once(':')?;
|
||||
self.prefixes
|
||||
.get(prefix)
|
||||
.map(|base| format!("{base}{name}"))
|
||||
|
||||
if prefix == "" && let Some(base) = base {
|
||||
Some(format!("{base}{name}"))
|
||||
} else {
|
||||
self.prefixes
|
||||
.get(prefix)
|
||||
.map(|base| format!("{base}{name}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user