shacl_ast/compiled/
mod.rs1use compiled_shacl_error::CompiledShaclError;
2use prefixmap::IriRef;
3use shape::CompiledShape;
4use srdf::Object;
5use srdf::Rdf;
6
7use crate::value::Value;
8use crate::Schema;
9
10pub mod compiled_shacl_error;
11pub mod component;
12pub mod node_shape;
13pub mod property_shape;
14pub mod schema;
15pub mod severity;
16pub mod shape;
17pub mod target;
18
19fn convert_iri_ref<S: Rdf>(iri_ref: IriRef) -> Result<S::IRI, CompiledShaclError> {
20 let iri = iri_ref
21 .get_iri()
22 .map_err(|_| CompiledShaclError::IriRefConversion)?
23 .into();
24 Ok(iri)
25}
26
27fn compile_shape<S: Rdf>(
28 shape: Object,
29 schema: &Schema,
30) -> Result<CompiledShape<S>, CompiledShaclError> {
31 let shape = schema
32 .get_shape(&shape)
33 .ok_or(CompiledShaclError::ShapeNotFound)?;
34 CompiledShape::compile(shape.to_owned(), schema)
35}
36
37fn compile_shapes<S: Rdf>(
38 shapes: Vec<Object>,
39 schema: &Schema,
40) -> Result<Vec<CompiledShape<S>>, CompiledShaclError> {
41 let compiled_shapes = shapes
42 .into_iter()
43 .map(|shape| compile_shape::<S>(shape, schema))
44 .collect::<Result<Vec<_>, _>>()?;
45 Ok(compiled_shapes)
46}
47
48fn convert_value<S: Rdf>(value: Value) -> Result<S::Term, CompiledShaclError> {
49 let ans = match value {
50 Value::Iri(iri_ref) => {
51 let iri_ref = convert_iri_ref::<S>(iri_ref)?;
52 iri_ref.into()
53 }
54 Value::Literal(literal) => {
55 let literal: S::Literal = literal.into();
56 literal.into()
57 }
58 };
59 Ok(ans)
60}