use crate::error::ValidationError;
use crate::validator::ShaclValidationMode;
use crate::validator::engine::{Engine, NativeEngine, SparqlEngine};
use crate::validator::processor::ShaclProcessor;
use crate::validator::store::{Graph, Store};
use rudof_rdf::rdf_core::RDFFormat;
use sparql_service::RdfData;
use std::path::Path;
pub struct GraphValidation {
store: Graph,
}
impl GraphValidation {
pub fn new(store: Graph) -> Self {
Self { store }
}
#[cfg(not(target_family = "wasm"))]
pub fn from_path<P: AsRef<Path>>(path: P, format: RDFFormat, base: Option<&str>) -> Result<Self, ValidationError> {
let store = Graph::from_path(path.as_ref(), &format, base)?;
Ok(Self { store })
}
}
#[cfg(feature = "sparql")]
impl ShaclProcessor<RdfData> for GraphValidation {
fn store(&self) -> &RdfData {
self.store.store()
}
fn runner(mode: &ShaclValidationMode) -> Box<dyn Engine<RdfData>> {
match mode {
ShaclValidationMode::Native => Box::new(NativeEngine::new()),
ShaclValidationMode::Sparql => Box::new(SparqlEngine::new()),
}
}
}
impl From<Graph> for GraphValidation {
fn from(value: Graph) -> Self {
Self::new(value)
}
}