From 3956c16a4ecf8f8b5fdf23eb9ea6ec6dba2bd4f3 Mon Sep 17 00:00:00 2001 From: Laurin Weger Date: Wed, 1 Oct 2025 21:43:44 +0200 Subject: [PATCH] create_orm_from_triples --- ng-net/src/orm.rs | 20 +++++++++++++++++--- ng-verifier/src/orm.rs | 11 +++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ng-net/src/orm.rs b/ng-net/src/orm.rs index d46f442..561a2f9 100644 --- a/ng-net/src/orm.rs +++ b/ng-net/src/orm.rs @@ -104,13 +104,20 @@ pub struct OrmSubscription<'a> { pub tracked_objects: HashMap>, } +/// A struct for recording the state of subjects and its predicates +/// relevant to its shape. #[derive(Clone, Debug)] pub struct OrmTrackedSubjectAndShape<'a> { + /// The known predicates (only those relevant to the shape). + /// If there are no triples with a predicate, they are discarded pub tracked_predicates: HashMap>, - // Parents and if they are currently tracking us. + /// If this is a nested subject, this records the parents + /// and if they are currently tracking this subject. pub parents: HashMap, bool)>, + /// Validity. When untracked, triple updates are not processed here. pub valid: OrmTrackedSubjectValidity, - pub subj_iri: &'a String, + pub subject_iri: &'a String, + /// The shape for which the predicates are tracked. pub shape: &'a OrmSchemaShape, } @@ -125,9 +132,14 @@ pub enum OrmTrackedSubjectValidity { #[derive(Clone, Debug)] pub struct OrmTrackedPredicate<'a> { + /// The predicate schema pub schema: &'a OrmSchemaPredicate, + /// TODO: This is not correctly implemented. + /// If the schema is a nested object, the children. pub tracked_children: Vec>>, + /// The count of triples for this subject and predicate. pub current_cardinality: i32, + /// If schema is of type literal, the currently present ones. pub current_literals: Option>, } @@ -135,14 +147,16 @@ pub struct OrmTrackedPredicate<'a> { // in parallel to modifying the tracked objects and predicates. pub struct OrmTrackedSubjectChange<'a> { pub subject_iri: String, + /// Predicates that were changed. pub predicates: HashMap>, + /// During validation, the current state of validity. pub valid: OrmTrackedSubjectValidity, } pub struct OrmTrackedPredicateChanges<'a> { + /// The tracked predicate for which those changes were recorded. pub tracked_predicate: &'a OrmTrackedPredicate<'a>, pub values_added: Vec, pub values_removed: Vec, - pub validity: OrmTrackedSubjectValidity, } #[derive(Clone, Debug)] diff --git a/ng-verifier/src/orm.rs b/ng-verifier/src/orm.rs index 84bfb05..000e68a 100644 --- a/ng-verifier/src/orm.rs +++ b/ng-verifier/src/orm.rs @@ -158,7 +158,7 @@ impl Verifier { tracked_predicates: HashMap::new(), parents: HashMap::new(), valid: ng_net::orm::OrmTrackedSubjectValidity::NotEvaluated, - subj_iri: subject_iri, + subject_iri, shape, }); @@ -196,7 +196,6 @@ impl Verifier { tracked_predicate: &tp, values_added: Vec::new(), values_removed: Vec::new(), - validity: OrmTrackedSubjectValidity::NotEvaluated, }); pred_changes.values_added.push(obj_term.clone()); @@ -434,7 +433,7 @@ impl Verifier { { if let Some(tc) = o.upgrade() { if tc.valid == OrmTrackedSubjectValidity::Untracked { - new_unknowns.push((tc.subj_iri, tc.shape, true)); + new_unknowns.push((tc.subject_iri, tc.shape, true)); } } } @@ -1096,15 +1095,15 @@ fn oxrdf_term_to_orm_basic_type(term: &ng_oxigraph::oxrdf::Term) -> BasicType { } fn has_cycle(subject: &OrmTrackedSubjectAndShape, visited: &mut HashSet) -> bool { - if visited.contains(subject.subj_iri) { + if visited.contains(subject.subject_iri) { return true; } - visited.insert(subject.subj_iri.clone()); + visited.insert(subject.subject_iri.clone()); for (_parent_iri, (parent_subject, _)) in &subject.parents { if has_cycle(parent_subject, visited) { return true; } } - visited.remove(subject.subj_iri); + visited.remove(subject.subject_iri); false }