.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "gl-graph"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
oxigraph.workspace = true
|
||||
tracing.workspace = true
|
||||
@@ -0,0 +1,87 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::LazyLock;
|
||||
use oxigraph::model::{GraphNameRef, NamedNodeRef};
|
||||
use tracing::debug;
|
||||
|
||||
const ONTOLOGY_PREFIX: &str = "https://graphofliberty.org/2026/04/ont/";
|
||||
const ONTOLOGY_GRAPH_NAME: GraphNameRef = GraphNameRef::NamedNode(NamedNodeRef::new_unchecked("https://graphofliberty.org/2026/04/ont"));
|
||||
|
||||
pub static PREFIXES: LazyLock<BTreeMap<String, String>> = LazyLock::new(|| {
|
||||
BTreeMap::from_iter([
|
||||
("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"),
|
||||
("rdfs", "http://www.w3.org/2000/01/rdf-schema#"),
|
||||
("owl", "http://www.w3.org/2002/07/owl#"),
|
||||
("xsd", "http://www.w3.org/2001/XMLSchema#"),
|
||||
("ldp", "http://www.w3.org/ns/ldp#"),
|
||||
("dc", "http://purl.org/dc/elements/1.1/"),
|
||||
("posix", "http://www.w3.org/ns/posix/stat#"),
|
||||
(
|
||||
"ebucore",
|
||||
"http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#",
|
||||
),
|
||||
("prov", "http://www.w3.org/ns/prov#"),
|
||||
("locid", "http://id.loc.gov/vocabulary/identifiers/"),
|
||||
("loclang", "http://id.loc.gov/vocabulary/languages/"),
|
||||
("premis", "http://www.loc.gov/premis/rdf/v1#"),
|
||||
("premis3", "http://www.loc.gov/premis/rdf/v3/"),
|
||||
("dcterms", "http://purl.org/dc/terms/"),
|
||||
("fedora", "http://fedora.info/definitions/v4/repository#"),
|
||||
("rdaa", "http://rdaregistry.info/Elements/a/"),
|
||||
("rdac", "http://rdaregistry.info/Elements/c/"),
|
||||
("rdae", "http://rdaregistry.info/Elements/e/"),
|
||||
("rdai", "http://rdaregistry.info/Elements/i/"),
|
||||
("rdam", "http://rdaregistry.info/Elements/m/"),
|
||||
("rdan", "http://rdaregistry.info/Elements/n/"),
|
||||
("rdap", "http://rdaregistry.info/Elements/p/"),
|
||||
("rdaf", "http://rdaregistry.info/Elements/rof/"),
|
||||
("rdat", "http://rdaregistry.info/Elements/t/"),
|
||||
("rdau", "http://rdaregistry.info/Elements/u/"),
|
||||
("rdaw", "http://rdaregistry.info/Elements/w/"),
|
||||
("rdax", "http://rdaregistry.info/Elements/x/"),
|
||||
("rdaco", "http://rdaregistry.info/termList/RDAContentType/"),
|
||||
("rdact", "http://rdaregistry.info/termList/RDACarrierType/"),
|
||||
("rdamt", "http://rdaregistry.info/termList/RDAMediaType/"),
|
||||
("rdaft", "http://rdaregistry.info/termList/fileType/"),
|
||||
("schema", "https://schema.org/"),
|
||||
("gl", "http://fedora.quill.lan/rest/"),
|
||||
("glo", ONTOLOGY_PREFIX),
|
||||
].map(|(k, v)| (k.to_string(), v.to_string())))
|
||||
});
|
||||
|
||||
#[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, 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}"));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn expand(&self, base: Option<&str>, abbreviated_iri: &str) -> Option<String> {
|
||||
let (prefix, name) = abbreviated_iri.split_once(':')?;
|
||||
|
||||
if prefix == "" && let Some(base) = base {
|
||||
Some(format!("{base}{name}"))
|
||||
} else {
|
||||
self.prefixes
|
||||
.get(prefix)
|
||||
.map(|base| format!("{base}{name}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
mod curie;
|
||||
pub mod vocab;
|
||||
|
||||
pub use curie::{PREFIXES, CurieHelper};
|
||||
@@ -0,0 +1,73 @@
|
||||
pub use oxigraph::model::vocab::rdf;
|
||||
pub use oxigraph::model::vocab::rdfs;
|
||||
|
||||
pub mod gl {
|
||||
use oxigraph::model::NamedNodeRef;
|
||||
|
||||
pub const TEMPLATE: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("https://graphofliberty.org/2026/04/ont/template");
|
||||
|
||||
pub const INDEXED_BY_FIELD: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("https://graphofliberty.org/2026/04/ont/indexedByField");
|
||||
|
||||
pub const CATEGORY_ID: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("https://graphofliberty.org/2026/04/ont/categoryId");
|
||||
|
||||
pub const SEARCHABLE_CLASS: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("https://graphofliberty.org/2026/04/ont/SearchableClass");
|
||||
|
||||
pub const ENTITY: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("https://graphofliberty.org/2026/04/ont/Entity");
|
||||
|
||||
pub const ASSOCIATED_PROPERTY: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("https://graphofliberty.org/2026/04/ont/associatedProperty");
|
||||
|
||||
pub const READ_ONLY: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("https://graphofliberty.org/2026/04/ont/readOnly");
|
||||
}
|
||||
|
||||
pub mod skos {
|
||||
use oxigraph::model::NamedNodeRef;
|
||||
|
||||
pub const CONCEPT: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://www.w3.org/2004/02/skos/core#Concept");
|
||||
}
|
||||
|
||||
pub mod owl {
|
||||
use oxigraph::model::NamedNodeRef;
|
||||
|
||||
pub const SAME_AS: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://www.w3.org/2002/07/owl#sameAs");
|
||||
}
|
||||
|
||||
pub mod rdac {
|
||||
use oxigraph::model::NamedNodeRef;
|
||||
|
||||
pub const PERSON: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://rdaregistry.info/Elements/c/C10004");
|
||||
|
||||
pub const CORPORATE_BODY: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://rdaregistry.info/Elements/c/C10005");
|
||||
|
||||
pub const WORK: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://rdaregistry.info/Elements/c/C10001");
|
||||
|
||||
pub const EXPRESSION: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://rdaregistry.info/Elements/c/C10006");
|
||||
|
||||
pub const MANIFESTATION: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://rdaregistry.info/Elements/c/C10007");
|
||||
}
|
||||
|
||||
pub mod rdaad {
|
||||
use oxigraph::model::NamedNodeRef;
|
||||
|
||||
pub const GIVEN_NAME: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://rdaregistry.info/Elements/a/datatype/P50292");
|
||||
|
||||
pub const SURNAME: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://rdaregistry.info/Elements/a/datatype/P50291");
|
||||
|
||||
pub const NAME_OF_CORPORATE_BODY: NamedNodeRef =
|
||||
NamedNodeRef::new_unchecked("http://rdaregistry.info/Elements/a/datatype/P50032");
|
||||
}
|
||||
Reference in New Issue
Block a user