Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
[submodule "shacl_testsuite/data-shapes"]
path = shacl_testsuite/data-shapes
url = https://github.com/w3c/data-shapes.git
[submodule "shacl_validation/tests/data-shapes"]
path = shacl_validation/tests/data-shapes
url = https://github.com/w3c/data-shapes
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ members = [
"shapemap",
"shacl_ast",
"shacl_validation",
"shacl_testsuite",
"shapes_converter",
"sparql_service",
"python",
Expand All @@ -26,8 +25,9 @@ exclude = [
"shex_compact_winnow"
]

default-members = [
"rudof_cli"
default-members = [ # TODO: this can possibly be removed when changing shex_testsuite
"rudof_cli",
"shacl_validation",
]

[workspace.package]
Expand Down Expand Up @@ -58,13 +58,11 @@ shapemap = { version = "0.1.0", path = "./shapemap" }
shacl_ast = { version = "0.1.35", path = "./shacl_ast" }
shacl_validation = { version = "0.1.37", path = "./shacl_validation" }
shapes_converter = { version = "0.1.33", path = "./shapes_converter" }
shex_testsuite = { version = "0.1.0", path = "./shex_testsuite" }
shex_validation = { version = "0.1.0", path = "./shex_validation" }
shex_compact = { version = "0.1.0", path = "./shex_compact" }
srdf = { version = "0.1.35", path = "./srdf" }
sparql_service = { version = "0.1.37", path = "./sparql_service" }

# [dependencies]
# External dependencies
anyhow = "1.0"
clap = { version = "4.2.1", features = ["derive"] }
Expand Down
25 changes: 21 additions & 4 deletions python/src/pyrudof_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use pyo3::{exceptions::PyValueError, pyclass, pymethods, PyErr, PyResult, Python
use rudof_lib::{
iri, DCTAPFormat, PrefixMap, QueryShapeMap, RDFFormat, ReaderMode, ResultShapeMap, Rudof,
RudofConfig, RudofError, ShExFormat, ShExFormatter, ShExSchema, ShaclFormat, ShaclSchema,
ShaclValidationMode, ShapeMapFormat, ShapeMapFormatter, ShapesGraphSource, UmlGenerationMode,
ValidationReport, ValidationStatus, DCTAP,
ShaclValidationMode, ShapeMapFormat, ShapeMapFormatter, ShapesGraphSource, Subsetting,
UmlGenerationMode, ValidationReport, ValidationStatus, DCTAP,
};
use std::{ffi::OsStr, fs::File, io::BufReader, path::Path};

Expand Down Expand Up @@ -309,17 +309,18 @@ impl PyRudof {
/// which can be extracted from the current RDF data,
/// or from the current SHACL schema.
/// If there is no current SHACL schema, it tries to get it from the current RDF data
#[pyo3(signature = (mode = &PyShaclValidationMode::Native, shapes_graph_source = &PyShapesGraphSource::CurrentSchema ))]
#[pyo3(signature = (mode = &PyShaclValidationMode::Native, shapes_graph_source = &PyShapesGraphSource::CurrentSchema, subsetting = &PySubsetting::None ))]
pub fn validate_shacl(
&mut self,
mode: &PyShaclValidationMode,
shapes_graph_source: &PyShapesGraphSource,
subsetting: &PySubsetting,
) -> PyResult<PyValidationReport> {
let mode = cnv_shacl_validation_mode(mode);
let shapes_graph_source = cnv_shapes_graph_source(shapes_graph_source);
let result = self
.inner
.validate_shacl(&mode, &shapes_graph_source)
.validate_shacl(&mode, &shapes_graph_source, cnv_subsetting(subsetting))
.map_err(cnv_err)?;
Ok(PyValidationReport { inner: result })
}
Expand Down Expand Up @@ -657,6 +658,14 @@ pub enum PyShaclValidationMode {
Sparql,
}

#[pyclass(eq, eq_int, name = "Subsetting")]
#[derive(PartialEq)]
pub enum PySubsetting {
None,
Full,
Provenance,
}

#[pyclass(eq, eq_int, name = "ShapesGraphSource")]
#[derive(PartialEq)]
pub enum PyShapesGraphSource {
Expand Down Expand Up @@ -800,6 +809,14 @@ fn cnv_shacl_validation_mode(mode: &PyShaclValidationMode) -> ShaclValidationMod
}
}

fn cnv_subsetting(subsetting: &PySubsetting) -> Subsetting {
match subsetting {
PySubsetting::None => Subsetting::None,
PySubsetting::Full => Subsetting::Full,
PySubsetting::Provenance => Subsetting::Provenance,
}
}

fn cnv_shapes_graph_source(sgs: &PyShapesGraphSource) -> ShapesGraphSource {
match sgs {
PyShapesGraphSource::CurrentData => ShapesGraphSource::CurrentData,
Expand Down
21 changes: 21 additions & 0 deletions rudof_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::input_spec::InputSpec;
use crate::{InputConvertFormat, OutputConvertFormat};
use clap::{Parser, Subcommand, ValueEnum};
use shacl_validation::shacl_processor::ShaclValidationMode;
use shacl_validation::Subsetting;
use srdf::{RDFFormat, ReaderMode};
use std::fmt::Display;
use std::{fmt::Formatter, path::PathBuf};
Expand Down Expand Up @@ -208,6 +209,16 @@ pub enum Command {
/// Config file path, if unset it assumes default config
#[arg(short = 'c', long = "config-file", value_name = "Config file name")]
config: Option<PathBuf>,

/// Subsetting mode
#[arg(
short = 'u',
long = "subsetting",
value_name = "Subsetting mode",
default_value_t = Subsetting::None,
value_enum
)]
subsetting: Subsetting,
},

/// Validate RDF using ShEx schemas
Expand Down Expand Up @@ -347,6 +358,16 @@ pub enum Command {
/// Config file path, if unset it assumes default config
#[arg(short = 'c', long = "config-file", value_name = "Config file name")]
config: Option<PathBuf>,

/// Subsetting mode
#[arg(
short = 'u',
long = "subsetting",
value_name = "Subsetting mode",
default_value_t = Subsetting::None,
value_enum
)]
subsetting: Subsetting,
},

/// Show information about RDF data
Expand Down
18 changes: 13 additions & 5 deletions rudof_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use rudof_lib::{
Rudof, RudofConfig, ShExFormat, ShExFormatter, ShaclFormat, ShaclValidationMode,
ShapeMapFormatter, ShapeMapParser, ShapesGraphSource,
};
use shacl_validation::Subsetting;
use shapemap::{NodeSelector, ShapeMapFormat as ShapemapFormat, ShapeSelector};
use shapes_converter::ShEx2Sparql;
use shapes_converter::{ImageFormat, ShEx2Html, ShEx2Uml, Shacl2ShEx, Tap2ShEx, UmlGenerationMode};
Expand Down Expand Up @@ -147,6 +148,7 @@ fn main() -> Result<()> {
output,
config,
force_overwrite,
subsetting,
}) => {
let config = get_config(config)?;
match validation_mode {
Expand Down Expand Up @@ -186,6 +188,7 @@ fn main() -> Result<()> {
output,
&config,
*force_overwrite,
*subsetting,
)
}
}
Expand Down Expand Up @@ -234,6 +237,7 @@ fn main() -> Result<()> {
output,
force_overwrite,
config,
subsetting,
}) => {
let config = get_config(config)?;
run_validate_shacl(
Expand All @@ -248,6 +252,7 @@ fn main() -> Result<()> {
output,
&config,
*force_overwrite,
*subsetting,
)
}
Some(Command::Data {
Expand Down Expand Up @@ -615,20 +620,23 @@ fn run_validate_shacl(
output: &Option<PathBuf>,
config: &RudofConfig,
force_overwrite: bool,
subsetting: Subsetting,
) -> Result<()> {
let (mut writer, _color) = get_writer(output, force_overwrite)?;
let mut rudof = Rudof::new(config);

get_data_rudof(&mut rudof, data, data_format, endpoint, reader_mode, config)?;
let result = if let Some(schema) = schema {

if let Some(schema) = schema {
let reader_mode = reader_mode_convert(*reader_mode);
let shapes_format = shapes_format.unwrap_or_default();
add_shacl_schema_rudof(&mut rudof, schema, &shapes_format, &reader_mode, config)?;
rudof.validate_shacl(&mode, &ShapesGraphSource::current_schema())
} else {
rudof.validate_shacl(&mode, &ShapesGraphSource::current_data())
}?;
};

let result = rudof.validate_shacl(&mode, &ShapesGraphSource::current_schema(), subsetting)?;

writeln!(writer, "Result:\n{}", result)?;

Ok(())
}

Expand Down
14 changes: 9 additions & 5 deletions rudof_lib/src/rudof.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{RudofConfig, RudofError, ShapesGraphSource};
use iri_s::IriS;
use shacl_ast::{ShaclParser, ShaclWriter};
use shacl_validation::shacl_processor::{GraphValidation, ShaclProcessor};
use shacl_validation::store::graph::Graph;
use shacl_validation::shacl_processor::ShaclProcessor;

use shapemap::{NodeSelector, ShapeSelector};
use shapes_converter::{ShEx2Uml, Tap2ShEx};
Expand All @@ -21,8 +20,8 @@ pub use dctap::{DCTAPFormat, DCTap as DCTAP};
pub use iri_s::iri;
pub use prefixmap::PrefixMap;
pub use shacl_ast::ShaclFormat;
pub use shacl_validation::shacl_processor::ShaclValidationMode;
pub use shacl_validation::validation_report::report::ValidationReport;
pub use shacl_validation::{shacl_processor::ShaclValidationMode, Subsetting};
pub use shapemap::{QueryShapeMap, ResultShapeMap, ShapeMapFormat, ValidationStatus};
pub use shex_compact::{ShExFormatter, ShapeMapParser, ShapemapFormatter as ShapeMapFormatter};
pub use shex_validation::Validator as ShExValidator;
Expand Down Expand Up @@ -436,6 +435,7 @@ impl Rudof {
&mut self,
mode: &ShaclValidationMode,
shapes_graph_source: &ShapesGraphSource,
subsetting: Subsetting,
) -> Result<ValidationReport> {
let (compiled_schema, shacl_schema) = match shapes_graph_source {
ShapesGraphSource::CurrentSchema if self.shacl_schema.is_some() => {
Expand All @@ -459,7 +459,7 @@ impl Rudof {
Ok((compiled_schema, ast_schema))
}
}?;
let validator = GraphValidation::from_graph(Graph::from_data(self.rdf_data.clone()), *mode);
let validator = ShaclProcessor::new(self.rdf_data.clone(), *mode, subsetting);
let result = ShaclProcessor::validate(&validator, &compiled_schema).map_err(|e| {
RudofError::SHACLValidationError {
error: format!("{e}"),
Expand Down Expand Up @@ -657,7 +657,7 @@ fn shacl_format2rdf_format(shacl_format: &ShaclFormat) -> Result<RDFFormat> {
mod tests {
use iri_s::iri;
use shacl_ast::ShaclFormat;
use shacl_validation::shacl_processor::ShaclValidationMode;
use shacl_validation::{shacl_processor::ShaclValidationMode, Subsetting};
use shapemap::ShapeMapFormat;
use shex_ast::{compiled::shape_label::ShapeLabel, Node};
use shex_validation::ShExFormat;
Expand Down Expand Up @@ -760,6 +760,7 @@ mod tests {
.validate_shacl(
&ShaclValidationMode::Native,
&crate::ShapesGraphSource::CurrentSchema,
Subsetting::None,
)
.unwrap();
assert!(result.results().is_empty())
Expand Down Expand Up @@ -805,6 +806,7 @@ mod tests {
.validate_shacl(
&ShaclValidationMode::Native,
&crate::ShapesGraphSource::CurrentSchema,
Subsetting::None,
)
.unwrap();
assert!(!result.conforms())
Expand Down Expand Up @@ -840,6 +842,7 @@ mod tests {
.validate_shacl(
&ShaclValidationMode::Native,
&crate::ShapesGraphSource::CurrentData,
Subsetting::None,
)
.unwrap();
assert!(!result.conforms())
Expand Down Expand Up @@ -875,6 +878,7 @@ mod tests {
.validate_shacl(
&ShaclValidationMode::Native,
&crate::ShapesGraphSource::CurrentData,
Subsetting::None,
)
.unwrap();
assert!(result.conforms())
Expand Down
27 changes: 0 additions & 27 deletions shacl_testsuite/Cargo.toml

This file was deleted.

15 changes: 0 additions & 15 deletions shacl_testsuite/README.md

This file was deleted.

7 changes: 0 additions & 7 deletions shacl_testsuite/src/helper/helper_error.rs

This file was deleted.

2 changes: 0 additions & 2 deletions shacl_testsuite/src/helper/mod.rs

This file was deleted.

35 changes: 0 additions & 35 deletions shacl_testsuite/src/helper/srdf.rs

This file was deleted.

Loading
Loading