This commit is contained in:
2026-08-08 23:50:04 -04:00
parent 9177c8902b
commit 79894f654d
26 changed files with 748 additions and 411 deletions
+51 -46
View File
@@ -1,49 +1,52 @@
use oxigraph::model::{GraphNameRef, NamedNodeRef};
use std::collections::BTreeMap;
use std::sync::LazyLock;
use oxigraph::model::{GraphNameRef, NamedNodeRef};
const ONTOLOGY_PREFIX: &str = "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())))
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)]
@@ -53,13 +56,13 @@ pub struct CurieHelper {
impl CurieHelper {
pub fn new(prefixes: BTreeMap<String, String>) -> Self {
Self {
prefixes,
}
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) {
if let Some(base) = base
&& let Some(local_name) = iri.strip_prefix(base)
{
return Some(format!(":{local_name}"));
}
@@ -74,7 +77,9 @@ impl CurieHelper {
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 {
if prefix == ""
&& let Some(base) = base
{
Some(format!("{base}{name}"))
} else {
self.prefixes
@@ -82,4 +87,4 @@ impl CurieHelper {
.map(|base| format!("{base}{name}"))
}
}
}
}
+4 -4
View File
@@ -9,13 +9,13 @@ pub enum Error {
#[error(transparent)]
Storage(#[from] oxigraph::store::StorageError),
#[error(transparent)]
SparqlSyntax(#[from] oxigraph::sparql::SparqlSyntaxError),
#[error(transparent)]
QueryEvaluation(#[from] oxigraph::sparql::QueryEvaluationError),
#[error(transparent)]
UpdateEvaluation(#[from] oxigraph::sparql::UpdateEvaluationError)
}
UpdateEvaluation(#[from] oxigraph::sparql::UpdateEvaluationError),
}
+30 -16
View File
@@ -1,13 +1,14 @@
use std::sync::Arc;
use oxigraph::model::{Dataset, GraphNameRef, NamedNodeRef, Quad, QuadRef};
use oxigraph::sparql::{QueryResults, SparqlEvaluator};
use oxigraph::store::Store;
use tracing::{debug, debug_span, field};
use tracing::{debug_span, field};
const RDF_SCHEMA_PREFIX: &str = "http://www.w3.org/2000/01/rdf-schema#";
const GL_PREFIX: &str = "https://graphofliberty.org/";
const INFERENCE_GRAPH: GraphNameRef = GraphNameRef::NamedNode(NamedNodeRef::new_unchecked("https://graphofliberty.org/inference"));
const INFERENCE_GRAPH: GraphNameRef = GraphNameRef::NamedNode(NamedNodeRef::new_unchecked(
"https://graphofliberty.org/inference",
));
/// `prp-spo1`
const SUB_PROPERTY_OF_QUERY: &str = r#"CONSTRUCT {
@@ -49,14 +50,22 @@ fn run_query(name: &str, query: &str, dataset: &Dataset) -> crate::Result<Datase
query.dataset_mut().set_default_graph_as_union();
let inferences = if let QueryResults::Graph(result) = query.on_queryable_dataset(dataset).execute()? {
result.filter_map(Result::ok)
.map(|triple| Quad::new(triple.subject, triple.predicate, triple.object, INFERENCE_GRAPH))
.collect()
} else {
Dataset::new()
};
let inferences =
if let QueryResults::Graph(result) = query.on_queryable_dataset(dataset).execute()? {
result
.filter_map(Result::ok)
.map(|triple| {
Quad::new(
triple.subject,
triple.predicate,
triple.object,
INFERENCE_GRAPH,
)
})
.collect()
} else {
Dataset::new()
};
Ok(inferences)
}
@@ -86,15 +95,20 @@ impl InferenceEngine {
ontology.extend(store.iter().filter_map(Result::ok));
});
Self {
ontology,
}
Self { ontology }
}
pub fn run(&self, dataset: &Dataset) -> crate::Result<Dataset> {
let span = debug_span!("Inference", inferences = field::Empty).entered();
let input = dataset.iter().map(|triple| QuadRef::new(triple.subject, triple.predicate, triple.object, INFERENCE_GRAPH));
let input = dataset.iter().map(|triple| {
QuadRef::new(
triple.subject,
triple.predicate,
triple.object,
INFERENCE_GRAPH,
)
});
let mut ontology = self.ontology.clone();
ontology.extend(input);
@@ -105,4 +119,4 @@ impl InferenceEngine {
span.record("inferences", result.len());
Ok(result)
}
}
}
+3 -3
View File
@@ -2,8 +2,8 @@ mod curie;
//mod materialize;
mod error;
pub mod vocab;
pub mod inference;
pub mod vocab;
pub use curie::{PREFIXES, CurieHelper};
pub use error::{Error, Result};
pub use curie::{CurieHelper, PREFIXES};
pub use error::{Error, Result};
+1 -1
View File
@@ -70,4 +70,4 @@ pub mod rdaad {
pub const NAME_OF_CORPORATE_BODY: NamedNodeRef =
NamedNodeRef::new_unchecked("http://rdaregistry.info/Elements/a/datatype/P50032");
}
}