This commit is contained in:
2026-08-27 13:00:36 -04:00
parent a8938176be
commit 277d1d2a2d
4 changed files with 42 additions and 38 deletions
+28 -26
View File
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;
use std::sync::LazyLock;
use oxigraph::model::NamedNode;
use url::Url;
const ONTOLOGY_PREFIX: &str = "https://graphofliberty.org/2026/04/ont/";
@@ -61,37 +62,38 @@ impl CurieHelper {
Self { prefixes }
}
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}"));
}
pub fn abbreviate(&self, base: Option<&Url>, iri: &str) -> Option<String> {
let relative_iri = base.and_then(|base| {
let iri = Url::parse(iri).ok()?;
base.make_relative(&iri)
});
for (name, base) in &self.prefixes {
if let Some(local_name) = iri.strip_prefix(base) {
return Some(format!("{name}:{local_name}"));
if relative_iri.is_some() {
relative_iri
} else {
for (name, prefix) in &self.prefixes {
if let Some(local_name) = iri.strip_prefix(prefix) {
return Some(format!("{name}:{local_name}"));
}
}
None
}
if let Some(base) = base &&
let Some(parsed_iri) = Url::parse(iri).ok() &&
let Some(parsed_base) = Url::parse(base).ok() {
parsed_base.make_relative(&parsed_iri)
} else { None }
}
pub fn expand(&self, base: Option<&str>, abbreviated_iri: &str) -> Option<String> {
let (prefix, name) = abbreviated_iri.split_once(':')?;
pub fn expand(&self, base: Option<&Url>, abbreviated_iri: &str) -> Option<String> {
let absolute_iri = base.and_then(|base| {
base.join(abbreviated_iri).ok().map(|absolute| absolute.as_str().to_string())
}).unwrap_or_else(|| abbreviated_iri.to_string());
if prefix == ""
&& let Some(base) = base
{
Some(format!("{base}{name}"))
} else {
self.prefixes
.get(prefix)
.map(|base| format!("{base}{name}"))
}
absolute_iri.split_once(':')
.and_then(|(prefix, name)| {
if prefix == "" && let Some(base) = base {
Some(format!("{base}{name}"))
} else {
self.prefixes
.get(prefix)
.map(|base| format!("{base}{name}"))
}
})
}
}
+1
View File
@@ -2,6 +2,7 @@ use rayon::iter::ParallelIterator;
use std::collections::{HashMap, HashSet};
use oxigraph::model::{Graph, NamedNode, TermRef, NamedOrBlankNodeRef, NamedNodeRef};
use rayon::iter::IntoParallelRefIterator;
use url::Url;
use gl_search::{Field, OwnedValue, Schema};
use crate::class::Class;
use crate::{helpers, vocab, CurieHelper};