Skip to main content

validate_plan

Function validate_plan 

Source
pub fn validate_plan(
    data: &Graph,
    plan: &PhysicalPlan,
) -> Result<ValidationOutcome, NonStratifiable>
Expand description

Validate using a PhysicalPlan (Layer 5): focus nodes come from compiled FocusSources (so class targets seed backward from the constant instead of scanning every node) and checks run over the plan’s cost-ordered arena. The result is identical to validate on the same schema — the W3C harness cross-checks this.

Examples found in repository?
examples/bench.rs (line 53)
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}