One parsed snapshot and one parsed shapes/import closure are reused for target coverage and validation. Focus selection is performed by PurRDF; Atomic's callback only records coverage and applies explicit CLI selectors.
(
data: &str,
snapshot_identity: &str,
request: &ValidationRequest,
)
| 149 | /// target coverage and validation. Focus selection is performed by PurRDF; |
| 150 | /// Atomic's callback only records coverage and applies explicit CLI selectors. |
| 151 | pub fn validate_ntriples( |
| 152 | data: &str, |
| 153 | snapshot_identity: &str, |
| 154 | request: &ValidationRequest, |
| 155 | ) -> Result<ValidationOutput, ValidationError> { |
| 156 | let mut bundles = vec![ShapeBundle { |
| 157 | iri: "https://atomic.dev/ns/shapes/projection/1.0.0".into(), |
| 158 | turtle: PROJECTION_SHAPES.into(), |
| 159 | }]; |
| 160 | if request.profile == Profile::Publication { |
| 161 | bundles.push(ShapeBundle { |
| 162 | iri: "https://atomic.dev/ns/shapes/publication/1.0.0".into(), |
| 163 | turtle: PUBLICATION_SHAPES.into(), |
| 164 | }); |
| 165 | } |
| 166 | bundles.extend(request.custom.clone()); |
| 167 | let mut imports = ShapesImports::new(); |
| 168 | let mut root = String::new(); |
| 169 | let mut identity = blake3::Hasher::new(); |
| 170 | for bundle in &bundles { |
| 171 | imports |
| 172 | .insert_turtle(&bundle.iri, &bundle.turtle) |
| 173 | .map_err(|e| ValidationError::Shapes(e.to_string()))?; |
| 174 | root.push_str(&format!( |
| 175 | "<urn:atomic:shapes:selection> <http://www.w3.org/2002/07/owl#imports> <{}> .\n", |
| 176 | bundle.iri |
| 177 | )); |
| 178 | identity.update(&(bundle.iri.len() as u64).to_be_bytes()); |
| 179 | identity.update(bundle.iri.as_bytes()); |
| 180 | identity.update(&(bundle.turtle.len() as u64).to_be_bytes()); |
| 181 | identity.update(bundle.turtle.as_bytes()); |
| 182 | } |
| 183 | let shapes = engine::parse_shapes_with_config( |
| 184 | &root, |
| 185 | Some("urn:atomic:shapes:selection"), |
| 186 | None, |
| 187 | &imports, |
| 188 | ) |
| 189 | .map_err(|e| ValidationError::Shapes(e.to_string()))?; |
| 190 | if shapes.rules.entailment |
| 191 | || !shapes.rules.global_rules.is_empty() |
| 192 | || !shapes.rules.rule_sets.is_empty() |
| 193 | || shapes |
| 194 | .node_shapes |
| 195 | .iter() |
| 196 | .any(|shape| !shape.rules.is_empty()) |
| 197 | { |
| 198 | return Err(ValidationError::Shapes( |
| 199 | "Phase 1 validates asserted snapshots; inference rules require a later profile".into(), |
| 200 | )); |
| 201 | } |
| 202 | if let Some(shape) = &request.shape { |
| 203 | if !shapes |
| 204 | .node_shapes |
| 205 | .iter() |
| 206 | .any(|candidate| term_value(&candidate.id) == *shape) |
| 207 | { |
| 208 | return Err(ValidationError::Shapes(format!( |