Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e293f78
feat: implementing the parser of the unique_lang constraint component
angelip2303 Mar 3, 2025
ebf8c54
fix: Validator and NativeValidator traits are merged, and changing th…
angelip2303 Mar 3, 2025
2c75f1c
fix: removing the Debug + 'static constraints from the generic types …
angelip2303 Mar 3, 2025
2967cfd
feat: using zero-sized types for reprsenting the engine to be used fo…
angelip2303 Mar 3, 2025
e83d054
fix: fixing clippy
angelip2303 Mar 3, 2025
20a43a7
fix: fixing the way we perform the conversion to IriS for Constraint …
angelip2303 Mar 3, 2025
7b61b57
fix: beautifying how we obtain the value nodes for the node shapes
angelip2303 Mar 3, 2025
1a48358
fix: minor fixes in the examples
angelip2303 Mar 3, 2025
dea6a49
fix: improving how Constraint Component IRIs are retrieved
angelip2303 Mar 4, 2025
59942ab
fix: improving how checks for equality are implemented in the case of…
angelip2303 Mar 4, 2025
3e042a6
fix: removing unnecessary blank lines in the tests
angelip2303 Mar 4, 2025
ed4d637
fix: removing unnecessary dependency
angelip2303 Mar 4, 2025
2ac81c0
fix: improving how the MaxLength component is validated
angelip2303 Mar 4, 2025
a4f541f
fix: improving how the MinLength component is validated
angelip2303 Mar 4, 2025
6fe4fb2
fix: fixing the serialization to IRI of the NodeKind constraint compo…
angelip2303 Mar 4, 2025
f721523
fix: fixing the formatting
angelip2303 Mar 4, 2025
1674334
fix: fixing clippy
angelip2303 Mar 4, 2025
1a440cd
fix: improving the implementation of the Matcher trait
angelip2303 Mar 4, 2025
98d534d
feat: removing the SRDF helper from the shacl_validation crate
angelip2303 Mar 4, 2025
6503415
fix: removing unnecessary conversion in the Query implementation of S…
angelip2303 Mar 4, 2025
300e70b
fix: removing unnecessary error variants
angelip2303 Mar 4, 2025
f0f3eb9
fix: using any instead of find in the class constraint evaluation
angelip2303 Mar 4, 2025
6d96cd8
fix: the evaluation of the constraints now returns a Result
angelip2303 Mar 4, 2025
1a86a80
WIP
angelip2303 Jul 10, 2025
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
2 changes: 1 addition & 1 deletion python/src/pyrudof_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl PyRudof {
let shapes_graph_source = cnv_shapes_graph_source(shapes_graph_source);
let result = self
.inner
.validate_shacl(&mode, &shapes_graph_source)
.validate_shacl(&shapes_graph_source, mode)
.map_err(cnv_err)?;
Ok(PyValidationReport { inner: result })
}
Expand Down
2 changes: 1 addition & 1 deletion rudof_cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::input_spec::InputSpec;
use crate::{InputConvertFormat, OutputConvertFormat};
use clap::{Parser, Subcommand, ValueEnum};
use shacl_validation::shacl_processor::ShaclValidationMode;
use rudof_lib::ShaclValidationMode;
use srdf::{RDFFormat, ReaderMode};
use std::fmt::Display;
use std::{fmt::Formatter, path::PathBuf};
Expand Down
29 changes: 10 additions & 19 deletions rudof_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,9 @@ fn run_validate_shacl(
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())
rudof.validate_shacl(&ShapesGraphSource::current_schema(), mode)
} else {
rudof.validate_shacl(&mode, &ShapesGraphSource::current_data())
rudof.validate_shacl(&ShapesGraphSource::current_schema(), mode)
}?;

writeln!(writer, "Result:\n{}", result)?;
Expand Down Expand Up @@ -1159,17 +1159,14 @@ fn run_node(
)
}

fn show_node_info<S, W: Write>(
fn show_node_info<Q: Query, W: Write>(
node_selector: NodeSelector,
predicates: &Vec<String>,
rdf: &S,
rdf: &Q,
show_node_mode: &ShowNodeMode,
_show_hyperlinks: &bool,
writer: &mut W,
) -> Result<()>
where
S: Query,
{
) -> Result<()> {
for node in node_selector.iter_node(rdf) {
let subject = node_to_subject(node, rdf)?;
writeln!(
Expand Down Expand Up @@ -1215,7 +1212,7 @@ where
match show_node_mode {
ShowNodeMode::Incoming | ShowNodeMode::Both => {
writeln!(writer, "Incoming arcs")?;
let object: S::Term = subject.clone().into();
let object: Q::Term = subject.clone().into();
let map = match rdf.incoming_arcs(object.clone()) {
Result::Ok(m) => m,
Err(e) => bail!("Can't get outgoing arcs of node {subject}: {e}"),
Expand All @@ -1240,10 +1237,7 @@ where
Ok(())
}

fn cnv_predicates<S>(predicates: &Vec<String>, rdf: &S) -> Result<Vec<S::IRI>>
where
S: Query,
{
fn cnv_predicates<Q: Query>(predicates: &Vec<String>, rdf: &Q) -> Result<Vec<Q::IRI>> {
let mut vs = Vec::new();
for s in predicates {
let iri_ref = parse_iri_ref(s)?;
Expand Down Expand Up @@ -1278,20 +1272,17 @@ fn run_shapemap(
Ok(())
}

fn node_to_subject<S>(node: &ObjectValue, rdf: &S) -> Result<S::Subject>
where
S: Query,
{
fn node_to_subject<Q: Query>(node: &ObjectValue, rdf: &Q) -> Result<Q::Subject> {
match node {
ObjectValue::IriRef(iri_ref) => {
let iri: S::IRI = match iri_ref {
let iri: Q::IRI = match iri_ref {
IriRef::Iri(iri_s) => iri_s.clone().into(),
IriRef::Prefixed { prefix, local } => {
let iri_s = rdf.resolve_prefix_local(prefix, local)?;
iri_s.into()
}
};
let term: S::Term = iri.into();
let term: Q::Term = iri.into();
match term.clone().try_into() {
Ok(subject) => Ok(subject),
Err(_) => bail!("node_to_subject: Can't convert term {term} to subject"),
Expand Down
1 change: 1 addition & 0 deletions rudof_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ thiserror = "1.0"
serde_json.workspace = true
serde_yml = "0.0.12"
oxrdf = { workspace = true, features = ["oxsdatatypes"] }
clap.workspace = true
43 changes: 26 additions & 17 deletions rudof_lib/src/rudof.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{RudofConfig, RudofError, ShapesGraphSource};
use clap::ValueEnum;
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::{DefaultShaclProcessor, SparqlShaclProcessor};

use shapemap::{NodeSelector, ShapeSelector};
use shapes_converter::{ShEx2Uml, Tap2ShEx};
Expand All @@ -21,7 +21,6 @@ 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 shapemap::{QueryShapeMap, ResultShapeMap, ShapeMapFormat, ValidationStatus};
pub use shex_compact::{ShExFormatter, ShapeMapParser, ShapemapFormatter as ShapeMapFormatter};
Expand All @@ -34,6 +33,12 @@ pub use shapes_converter::UmlGenerationMode;
pub use shex_ast::Schema as ShExSchema;
pub use sparql_service::RdfData;

#[derive(ValueEnum, Copy, Clone, Debug, PartialEq)]
pub enum ShaclValidationMode {
Native,
Sparql,
}

/// This represents the public API to interact with `rudof`
#[derive(Debug)]
pub struct Rudof {
Expand Down Expand Up @@ -469,10 +474,12 @@ impl Rudof {
/// If there is no current SHACL schema, it tries to get it from the current RDF data
pub fn validate_shacl(
&mut self,
mode: &ShaclValidationMode,
shapes_graph_source: &ShapesGraphSource,
mode: ShaclValidationMode,
) -> Result<ValidationReport> {
let (compiled_schema, shacl_schema) = match shapes_graph_source {
let data = self.rdf_data.clone();

let (schema, original_schema) = match shapes_graph_source {
ShapesGraphSource::CurrentSchema if self.shacl_schema.is_some() => {
let ast_schema = self.shacl_schema.as_ref().unwrap();
let compiled_schema = ast_schema.clone().to_owned().try_into().map_err(|e| {
Expand All @@ -494,14 +501,17 @@ impl Rudof {
Ok((compiled_schema, ast_schema))
}
}?;
let validator = GraphValidation::from_graph(Graph::from_data(self.rdf_data.clone()), *mode);
let result = ShaclProcessor::validate(&validator, &compiled_schema).map_err(|e| {
RudofError::SHACLValidationError {
error: format!("{e}"),
schema: Box::new(shacl_schema),
}

// TODO: fix the error thing...
let report = match mode {
ShaclValidationMode::Native => DefaultShaclProcessor::new(data).validate(&schema),
ShaclValidationMode::Sparql => SparqlShaclProcessor::new(data).validate(&schema),
}
.map_err(|e| RudofError::SHACLValidationError {
error: format!("{e}"),
schema: Box::new(original_schema),
})?;
Ok(result)
Ok(report)
}

/// Validate RDF data using ShEx
Expand Down Expand Up @@ -692,7 +702,6 @@ 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 shapemap::ShapeMapFormat;
use shex_ast::{compiled::shape_label::ShapeLabel, Node};
use shex_validation::ShExFormat;
Expand Down Expand Up @@ -793,8 +802,8 @@ mod tests {
.unwrap();
let result = rudof
.validate_shacl(
&ShaclValidationMode::Native,
&crate::ShapesGraphSource::CurrentSchema,
crate::ShaclValidationMode::Native,
)
.unwrap();
assert!(result.results().is_empty())
Expand Down Expand Up @@ -838,8 +847,8 @@ mod tests {
.unwrap();
let result = rudof
.validate_shacl(
&ShaclValidationMode::Native,
&crate::ShapesGraphSource::CurrentSchema,
crate::ShaclValidationMode::Native,
)
.unwrap();
assert!(!result.conforms())
Expand Down Expand Up @@ -873,8 +882,8 @@ mod tests {
.unwrap();
let result = rudof
.validate_shacl(
&ShaclValidationMode::Native,
&crate::ShapesGraphSource::CurrentData,
crate::ShaclValidationMode::Native,
)
.unwrap();
assert!(!result.conforms())
Expand Down Expand Up @@ -908,8 +917,8 @@ mod tests {
.unwrap();
let result = rudof
.validate_shacl(
&ShaclValidationMode::Native,
&crate::ShapesGraphSource::CurrentData,
crate::ShaclValidationMode::Native,
)
.unwrap();
assert!(result.conforms())
Expand Down
1 change: 0 additions & 1 deletion shacl_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ thiserror = "1.0"
lazy_static = "1"
const_format = "0.2"
itertools = "0.13"
oxrdf = { workspace = true, features = ["oxsdatatypes"] }
22 changes: 22 additions & 0 deletions shacl_ast/src/ast/node_kind.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::fmt::Display;

use srdf::TermKind;

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum NodeKind {
Iri,
Expand All @@ -23,3 +25,23 @@ impl Display for NodeKind {
write!(f, "{}", node)
}
}

impl PartialEq<TermKind> for NodeKind {
fn eq(&self, other: &TermKind) -> bool {
matches!(
(self, other),
(NodeKind::Iri, TermKind::Iri)
| (NodeKind::Literal, TermKind::Literal)
| (NodeKind::BlankNode, TermKind::BlankNode)
| (
NodeKind::BlankNodeOrIri,
TermKind::BlankNode | TermKind::Iri
)
| (
NodeKind::BlankNodeOrLiteral,
TermKind::BlankNode | TermKind::Literal
)
| (NodeKind::IRIOrLiteral, TermKind::Iri | TermKind::Literal)
)
}
}
Loading
Loading