create_orm_from_triples

feat/orm
Laurin Weger 3 weeks ago
parent 1a04b9bea7
commit 3956c16a4e
No known key found for this signature in database
GPG Key ID: 9B372BB0B792770F
  1. 20
      ng-net/src/orm.rs
  2. 11
      ng-verifier/src/orm.rs

@ -104,13 +104,20 @@ pub struct OrmSubscription<'a> {
pub tracked_objects: HashMap<String, OrmTrackedSubjectAndShape<'a>>,
}
/// 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<String, OrmTrackedPredicate<'a>>,
// 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<String, (OrmTrackedSubjectAndShape<'a>, 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<Weak<OrmTrackedSubjectAndShape<'a>>>,
/// 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<Vec<BasicType>>,
}
@ -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<String, OrmTrackedPredicateChanges<'a>>,
/// 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<BasicType>,
pub values_removed: Vec<BasicType>,
pub validity: OrmTrackedSubjectValidity,
}
#[derive(Clone, Debug)]

@ -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<String>) -> 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
}

Loading…
Cancel
Save