Skip to content

Commit

Permalink
fix: subsetting is now used
Browse files Browse the repository at this point in the history
  • Loading branch information
angelip2303 committed Nov 6, 2024
1 parent 01fe113 commit 1908783
Show file tree
Hide file tree
Showing 22 changed files with 150 additions and 49 deletions.
11 changes: 9 additions & 2 deletions shacl_validation/src/constraints/core/cardinality/max_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ impl<S: SRDFBasic + Debug> Validator<S> for MaxCount {
_: &Store<S>,
_: impl Engine<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let max_count = |targets: &FocusNodes<S>| targets.len() > self.max_count();
validate_native_with_strategy(component, shape, value_nodes, FocusNodeIteration, max_count)
validate_native_with_strategy(
component,
shape,
value_nodes,
FocusNodeIteration,
max_count,
subsetting,
)
}
}

Expand Down
14 changes: 11 additions & 3 deletions shacl_validation/src/constraints/core/cardinality/min_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ impl<S: SRDFBasic + Debug> Validator<S> for MinCount {
_: &Store<S>,
_: impl Engine<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
// If min_count is 0, then it always passes
if self.min_count() == 0 {
// If min_count is 0, then it always passes
return Ok(Default::default());
}

let min_count = |targets: &FocusNodes<S>| targets.len() < self.min_count();
validate_native_with_strategy(component, shape, value_nodes, FocusNodeIteration, min_count)
validate_native_with_strategy(
component,
shape,
value_nodes,
FocusNodeIteration,
min_count,
subsetting,
)
}
}

Expand Down
9 changes: 8 additions & 1 deletion shacl_validation/src/constraints/core/logical/and.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ impl<S: SRDFBasic + Debug> Validator<S> for And<S> {
.not()
};

validate_native_with_strategy(component, shape, value_nodes, ValueNodeIteration, and)
validate_native_with_strategy(
component,
shape,
value_nodes,
ValueNodeIteration,
and,
subsetting,
)
}
}

Expand Down
9 changes: 8 additions & 1 deletion shacl_validation/src/constraints/core/logical/not.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ impl<S: SRDFBasic + Debug> Validator<S> for Not<S> {
inner_results.is_err() || inner_results.unwrap().is_empty()
};

validate_native_with_strategy(component, shape, value_nodes, ValueNodeIteration, not)
validate_native_with_strategy(
component,
shape,
value_nodes,
ValueNodeIteration,
not,
subsetting,
)
}
}

Expand Down
9 changes: 8 additions & 1 deletion shacl_validation/src/constraints/core/logical/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ impl<S: SRDFBasic + Debug> Validator<S> for Or<S> {
.not()
};

validate_native_with_strategy(component, shape, value_nodes, ValueNodeIteration, or)
validate_native_with_strategy(
component,
shape,
value_nodes,
ValueNodeIteration,
or,
subsetting,
)
}
}

Expand Down
9 changes: 8 additions & 1 deletion shacl_validation/src/constraints/core/logical/xone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ impl<S: SRDFBasic + Debug> Validator<S> for Xone<S> {
.ne(&1usize)
};

validate_native_with_strategy(component, shape, value_nodes, ValueNodeIteration, xone)
validate_native_with_strategy(
component,
shape,
value_nodes,
ValueNodeIteration,
xone,
subsetting,
)
}
}

Expand Down
11 changes: 9 additions & 2 deletions shacl_validation/src/constraints/core/other/has_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ impl<S: SRDFBasic + Debug> Validator<S> for HasValue<S> {
_: &Store<S>,
_: impl Engine<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let has_value =
|targets: &FocusNodes<S>| !targets.iter().any(|value| value == self.value());
validate_native_with_strategy(component, shape, value_nodes, FocusNodeIteration, has_value)
validate_native_with_strategy(
component,
shape,
value_nodes,
FocusNodeIteration,
has_value,
subsetting,
)
}
}

Expand Down
11 changes: 9 additions & 2 deletions shacl_validation/src/constraints/core/other/in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ impl<S: SRDFBasic + Debug> Validator<S> for In<S> {
_: &Store<S>,
_: impl Engine<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let r#in = |value_node: &S::Term| !self.values().contains(value_node);
validate_native_with_strategy(component, shape, value_nodes, ValueNodeIteration, r#in)
validate_native_with_strategy(
component,
shape,
value_nodes,
ValueNodeIteration,
r#in,
subsetting,
)
}
}

Expand Down
9 changes: 8 additions & 1 deletion shacl_validation/src/constraints/core/shape_based/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ impl<S: SRDFBasic + Debug> Validator<S> for Node<S> {
inner_results.is_err() || !inner_results.unwrap().is_empty()
};

validate_native_with_strategy(component, shape, value_nodes, ValueNodeIteration, node)
validate_native_with_strategy(
component,
shape,
value_nodes,
ValueNodeIteration,
node,
subsetting,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<S: SRDFBasic + Debug> Validator<S> for LanguageIn<S> {
_: &Store<S>,
_: impl Engine<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let language_in = |value_node: &S::Term| {
if let Some(lang) = S::term_as_literal(value_node) {
Expand All @@ -46,6 +46,7 @@ impl<S: SRDFBasic + Debug> Validator<S> for LanguageIn<S> {
value_nodes,
ValueNodeIteration,
language_in,
subsetting,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<S: SRDF + Debug + 'static> NativeValidator<S> for MaxLength {
shape: &CompiledShape<S>,
_: &Store<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let max_length = |value_node: &S::Term| {
if S::term_is_bnode(value_node) {
Expand All @@ -45,6 +45,7 @@ impl<S: SRDF + Debug + 'static> NativeValidator<S> for MaxLength {
value_nodes,
ValueNodeIteration,
max_length,
subsetting,
)
}
}
Expand All @@ -56,7 +57,7 @@ impl<S: QuerySRDF + Debug + 'static> SparqlValidator<S> for MaxLength {
shape: &CompiledShape<S>,
store: &Store<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let max_length_value = self.max_length();

Expand All @@ -67,6 +68,6 @@ impl<S: QuerySRDF + Debug + 'static> SparqlValidator<S> for MaxLength {
}
};

validate_sparql_ask(component, shape, store, value_nodes, query)
validate_sparql_ask(component, shape, store, value_nodes, query, subsetting)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<S: SRDF + Debug + 'static> NativeValidator<S> for MinLength {
shape: &CompiledShape<S>,
_: &Store<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let min_length = |value_node: &S::Term| {
if S::term_is_bnode(value_node) {
Expand All @@ -45,6 +45,7 @@ impl<S: SRDF + Debug + 'static> NativeValidator<S> for MinLength {
value_nodes,
ValueNodeIteration,
min_length,
subsetting,
)
}
}
Expand All @@ -56,7 +57,7 @@ impl<S: QuerySRDF + Debug + 'static> SparqlValidator<S> for MinLength {
shape: &CompiledShape<S>,
store: &Store<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let min_length_value = self.min_length();

Expand All @@ -67,6 +68,6 @@ impl<S: QuerySRDF + Debug + 'static> SparqlValidator<S> for MinLength {
}
};

validate_sparql_ask(component, shape, store, value_nodes, query)
validate_sparql_ask(component, shape, store, value_nodes, query, subsetting)
}
}
15 changes: 11 additions & 4 deletions shacl_validation/src/constraints/core/string_based/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<S: SRDF + Debug + 'static> NativeValidator<S> for Pattern {
shape: &CompiledShape<S>,
_: &Store<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let pattern = |value_node: &S::Term| {
if S::term_is_bnode(value_node) {
Expand All @@ -34,7 +34,14 @@ impl<S: SRDF + Debug + 'static> NativeValidator<S> for Pattern {
todo!()
}
};
validate_native_with_strategy(component, shape, value_nodes, ValueNodeIteration, pattern)
validate_native_with_strategy(
component,
shape,
value_nodes,
ValueNodeIteration,
pattern,
subsetting,
)
}
}

Expand All @@ -45,7 +52,7 @@ impl<S: QuerySRDF + Debug + 'static> SparqlValidator<S> for Pattern {
shape: &CompiledShape<S>,
store: &Store<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let flags = self.flags().clone();
let pattern = self.pattern().clone();
Expand All @@ -61,6 +68,6 @@ impl<S: QuerySRDF + Debug + 'static> SparqlValidator<S> for Pattern {
},
};

validate_sparql_ask(component, shape, store, value_nodes, query)
validate_sparql_ask(component, shape, store, value_nodes, query, subsetting)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<S: SRDFBasic + Debug> Validator<S> for UniqueLang {
_: &Store<S>,
_: impl Engine<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
if !self.unique_lang() {
return Ok(Default::default());
Expand Down Expand Up @@ -60,6 +60,7 @@ impl<S: SRDFBasic + Debug> Validator<S> for UniqueLang {
value_nodes,
ValueNodeIteration,
unique_lang,
subsetting,
)
}
}
Expand Down
15 changes: 11 additions & 4 deletions shacl_validation/src/constraints/core/value/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<S: SRDF + 'static> NativeValidator<S> for Class<S> {
shape: &CompiledShape<S>,
store: &Store<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let class = |value_node: &S::Term| {
if S::term_is_literal(value_node) {
Expand All @@ -53,7 +53,14 @@ impl<S: SRDF + 'static> NativeValidator<S> for Class<S> {
!is_class_valid
};

validate_native_with_strategy(component, shape, value_nodes, ValueNodeIteration, class)
validate_native_with_strategy(
component,
shape,
value_nodes,
ValueNodeIteration,
class,
subsetting,
)
}
}

Expand All @@ -64,7 +71,7 @@ impl<S: QuerySRDF + Debug + 'static> SparqlValidator<S> for Class<S> {
shape: &CompiledShape<S>,
store: &Store<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let class_value = self.class_rule().clone();

Expand All @@ -77,6 +84,6 @@ impl<S: QuerySRDF + Debug + 'static> SparqlValidator<S> for Class<S> {
}
};

validate_sparql_ask(component, shape, store, value_nodes, query)
validate_sparql_ask(component, shape, store, value_nodes, query, subsetting)
}
}
11 changes: 9 additions & 2 deletions shacl_validation/src/constraints/core/value/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<S: SRDFBasic + Debug> Validator<S> for Datatype<S> {
_: &Store<S>,
_: impl Engine<S>,
value_nodes: &ValueNodes<S>,
_subsetting: &Subsetting,
subsetting: &Subsetting,
) -> Result<Vec<ValidationResult>, ConstraintError> {
let datatype = |value_node: &S::Term| {
if let Some(literal) = S::term_as_literal(value_node) {
Expand All @@ -38,7 +38,14 @@ impl<S: SRDFBasic + Debug> Validator<S> for Datatype<S> {
true
};

validate_native_with_strategy(component, shape, value_nodes, ValueNodeIteration, datatype)
validate_native_with_strategy(
component,
shape,
value_nodes,
ValueNodeIteration,
datatype,
subsetting,
)
}
}

Expand Down
Loading

0 comments on commit 1908783

Please sign in to comment.