use crate::error::ValidationError;
use crate::validator::ShaclValidationMode;
#[cfg(feature = "sparql")]
use crate::validator::engine::SparqlEngine;
use crate::validator::engine::{Engine, NativeEngine};
use crate::validator::processor::ShaclProcessor;
use crate::validator::store::{Graph, Store};
use rudof_rdf::rdf_core::RDFFormat;
#[cfg(not(feature = "sparql"))]
use rudof_rdf::rdf_impl::OxigraphInMemory;
#[cfg(feature = "sparql")]
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()),
}
}
fn prepare_store(&mut self) -> Result<(), ValidationError> {
self.store.store_mut().check_store().map_err(ValidationError::from)
}
}
#[cfg(not(feature = "sparql"))]
impl ShaclProcessor<OxigraphInMemory> for GraphValidation {
fn store(&self) -> &OxigraphInMemory {
self.store.store()
}
fn runner(mode: &ShaclValidationMode) -> Box<dyn Engine<OxigraphInMemory>> {
match mode {
ShaclValidationMode::Native => Box::new(NativeEngine::new()),
}
}
}
impl From<Graph> for GraphValidation {
fn from(value: Graph) -> Self {
Self::new(value)
}
}