use crate::consts::{DECLARE, IMPORTS, ONTOLOGY, PREFIXES, TYPE};
use oxigraph::model::{Dataset, Graph, Quad, QuadRef, SubjectRef, Triple, TripleRef};
pub fn rewrite_sh_prefixes(graph: &mut Dataset, root: SubjectRef) {
let mut to_remove: Vec<Quad> = vec![];
let mut to_add: Vec<Quad> = vec![];
for quad in graph.quads_for_predicate(PREFIXES) {
let s = quad.subject;
let g = quad.graph_name;
let new_quad = QuadRef::new(s, PREFIXES, root, g);
to_remove.push(quad.into());
to_add.push(new_quad.into());
}
for quad in graph.quads_for_predicate(DECLARE) {
let o = quad.object;
let g = quad.graph_name;
let new_quad = QuadRef::new(root, DECLARE, o, g);
to_remove.push(quad.into());
to_add.push(new_quad.into());
}
for quad in to_remove {
graph.remove(quad.as_ref());
}
for quad in to_add {
graph.insert(quad.as_ref());
}
}
pub fn rewrite_sh_prefixes_graph(graph: &mut Graph, root: SubjectRef) {
let mut to_remove: Vec<Triple> = vec![];
let mut to_add: Vec<Triple> = vec![];
for triple in graph.triples_for_predicate(PREFIXES) {
let s = triple.subject;
let new_triple = TripleRef::new(s, PREFIXES, root);
to_remove.push(triple.into());
to_add.push(new_triple.into());
}
for triple in graph.triples_for_predicate(DECLARE) {
let o = triple.object;
let new_triple = TripleRef::new(root, DECLARE, o);
to_remove.push(triple.into());
to_add.push(new_triple.into());
}
for triple in to_remove {
graph.remove(triple.as_ref());
}
for triple in to_add {
graph.insert(triple.as_ref());
}
}
pub fn remove_owl_imports(graph: &mut Dataset) {
let mut to_remove: Vec<Quad> = vec![];
for quad in graph.quads_for_predicate(IMPORTS) {
to_remove.push(quad.into());
}
for quad in to_remove {
graph.remove(quad.as_ref());
}
}
pub fn remove_owl_imports_graph(graph: &mut Graph) {
let mut to_remove: Vec<Triple> = vec![];
for triple in graph.triples_for_predicate(IMPORTS) {
to_remove.push(triple.into());
}
for triple in to_remove {
graph.remove(triple.as_ref());
}
}
pub fn remove_ontology_declarations(graph: &mut Dataset, root: SubjectRef) {
let mut to_remove: Vec<Quad> = vec![];
for quad in graph.quads_for_object(ONTOLOGY) {
let s = quad.subject;
let p = quad.predicate;
if p == TYPE && s != root {
to_remove.push(quad.into());
}
}
for quad in to_remove {
graph.remove(quad.as_ref());
}
}
pub fn remove_ontology_declarations_graph(graph: &mut Graph, root: SubjectRef) {
let mut to_remove: Vec<Triple> = vec![];
for triple in graph.triples_for_object(ONTOLOGY) {
let s = triple.subject;
let p = triple.predicate;
if p == TYPE && s != root {
to_remove.push(triple.into());
}
}
for triple in to_remove {
graph.remove(triple.as_ref());
}
}