pub fn validate(
data: &Graph,
schema: &Schema,
) -> Result<ValidationOutcome, NonStratifiable>Expand description
Validate data against schema.
Honors the decided recursion semantics (docs/03-recursion-semantics.md):
the schema must be stratifiable (no recursion through net negation), else
we return NonStratifiable. For a stratifiable schema all recursion is
net-positive (monotone), and explain/holds’s “assume conforming on a
back-edge” cycle guard computes exactly the greatest fixpoint — the
coinductive validation reading we chose.
Examples found in repository?
examples/bench.rs (line 44)
13fn main() {
14 let persons = 1_000;
15 let decoys = 20_000;
16 let runs = 5;
17
18 let mut ttl = String::new();
19 ttl.push_str(
20 "@prefix ex: <http://ex/> .\n\
21 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\
22 @prefix sh: <http://www.w3.org/ns/shacl#> .\n\
23 ex:PersonShape a sh:NodeShape ; sh:targetClass ex:Person ;\n\
24 sh:property [ sh:path ex:name ; sh:minCount 1 ; sh:datatype xsd:string ] ;\n\
25 sh:property [ sh:path ex:age ; sh:datatype xsd:integer ] .\n",
26 );
27 for i in 0..persons {
28 ttl.push_str(&format!(
29 "ex:p{i} a ex:Person ; ex:name \"P{i}\" ; ex:age {i} .\n"
30 ));
31 }
32 for i in 0..decoys {
33 ttl.push_str(&format!("ex:d{i} a ex:Thing ; ex:label \"D{i}\" .\n"));
34 }
35
36 let parsed = shifty_parse::parse_turtle(ttl.as_bytes(), None).unwrap();
37 let loaded = shifty_parse::load_turtle(ttl.as_bytes(), None).unwrap();
38 let normalized = shifty_opt::normalize(&parsed.schema);
39 let physical = shifty_opt::plan(&normalized);
40
41 let mut reference_conforms = true;
42 let t = Instant::now();
43 for _ in 0..runs {
44 reference_conforms = shifty_engine::validate(&loaded.graph, &parsed.schema)
45 .unwrap()
46 .conforms;
47 }
48 let reference = t.elapsed() / runs;
49
50 let mut planned_conforms = true;
51 let t = Instant::now();
52 for _ in 0..runs {
53 planned_conforms = shifty_engine::validate_plan(&loaded.graph, &physical)
54 .unwrap()
55 .conforms;
56 }
57 let planned = t.elapsed() / runs;
58
59 assert_eq!(reference_conforms, planned_conforms, "executors disagree");
60
61 println!(
62 "graph: {persons} Person instances + {decoys} decoys = {} nodes",
63 persons + decoys
64 );
65 println!("reference validate: {reference:>10.2?}/run (conforms={reference_conforms})");
66 println!("planned validate: {planned:>10.2?}/run (conforms={planned_conforms})");
67 println!(
68 "speedup: {:.1}x",
69 reference.as_secs_f64() / planned.as_secs_f64().max(1e-9)
70 );
71}