Skip to main content

swls_core/feature/
parse.rs

1use bevy_ecs::{prelude::*, schedule::ScheduleLabel};
2
3pub use crate::systems::{
4    derive_ontologies, derive_prefix_links, extract_type_hierarchy, fetch_lov_properties,
5    infer_types,
6};
7use crate::{
8    client::Client,
9    store::Store,
10    systems::{
11        check_added_ontology_extract, derive_owl_imports_links, open_imports, prefix_diagnostics,
12        validate_namespace_properties, validate_shapes,
13    },
14};
15
16/// Parse schedule barrier, after this system, triples should be derived
17pub fn triples() {}
18/// Parse schedule barrier, after this system, prefixes should be derived
19pub fn prefixes() {}
20/// Parse schedule barrier marking the end of all derivation.
21///
22/// Every system that *produces* data (triples, prefixes, ontologies, store,
23/// type hierarchy, …) runs before this barrier; every system that merely
24/// *consumes* the fully-derived state to publish diagnostics (syntax errors,
25/// prefix diagnostics, SHACL validation) runs `.after(end)`.
26pub fn end() {}
27
28/// [`ScheduleLabel`] related to the Parse schedule
29#[derive(ScheduleLabel, Clone, Eq, PartialEq, Debug, Hash)]
30pub struct Label;
31
32pub fn setup_schedule<C: Client + Resource>(world: &mut World) {
33    let mut parse_schedule = bevy_ecs::schedule::Schedule::new(Label);
34    parse_schedule.add_systems((
35        prefixes,
36        triples,
37        // ── producers: everything that derives data runs before `end` ──────────
38        derive_prefix_links.after(prefixes).before(end),
39        derive_owl_imports_links.after(triples).before(end),
40        fetch_lov_properties::<C>.after(prefixes).before(end),
41        extract_type_hierarchy.after(triples).before(end),
42        infer_types.after(triples).before(end),
43        check_added_ontology_extract.after(triples).before(end),
44        open_imports::<C>.after(triples).before(end),
45        // store things
46        crate::store::load_store.after(triples).before(end),
47        derive_ontologies
48            .after(crate::store::load_store)
49            .before(end),
50        // ── end-of-derivation barrier ──────────────────────────────────────────
51        end.after(triples).after(prefixes),
52        // ── consumers: publish diagnostics from the fully-derived state ─────────
53        validate_shapes.after(end),
54        prefix_diagnostics.after(end),
55        validate_namespace_properties.after(end),
56    ));
57
58    parse_schedule.add_systems((crate::systems::derive_shapes.after(triples).before(end),));
59    world.add_schedule(parse_schedule);
60    world.insert_resource(Store(oxigraph::store::Store::new().unwrap()));
61}