pub struct MaterializedDatalogView { /* private fields */ }Expand description
A incrementally maintained view of a graph over a property graph
Implementations§
Source§impl MaterializedDatalogView
impl MaterializedDatalogView
Sourcepub fn push_fact(
&mut self,
relation_symbol: &'_ str,
fact: impl Into<Fact>,
) -> bool
pub fn push_fact( &mut self, relation_symbol: &'_ str, fact: impl Into<Fact>, ) -> bool
Pushes a fact into the materialized view.
§Examples
use materialized_view::*;
let query = program! {
reaches(?x, ?y) <- [edge(?x, ?y)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("edge", (1, 2));
dynamic_view.poll();
assert!(dynamic_view.contains("edge", (1, 2)).unwrap());
assert!(dynamic_view.contains("reaches", (1, 2)).unwrap());
Sourcepub fn retract_fact(
&mut self,
relation_symbol: &'_ str,
fact: impl Into<Fact>,
) -> bool
pub fn retract_fact( &mut self, relation_symbol: &'_ str, fact: impl Into<Fact>, ) -> bool
Retracts facts from the materialized view.
§Examples
use materialized_view::*;
let query = program! {
reaches(?x, ?y) <- [edge(?x, ?y)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("edge", (1, 2));
dynamic_view.poll();
assert!(dynamic_view.contains("edge", (1, 2)).unwrap());
assert!(dynamic_view.contains("reaches", (1, 2)).unwrap());
dynamic_view.retract_fact("edge", (1, 2));
dynamic_view.poll();
assert!(!dynamic_view.contains("edge", (1, 2)).unwrap());
assert!(!dynamic_view.contains("reaches", (1, 2)).unwrap());
let expected_update = vec![(-1, (1, 2))];
let actual_update_edge: Vec<((isize, (i32, i32)))> = dynamic_view
.query_frontier_binary("edge", (ANY_VALUE, ANY_VALUE))
.unwrap()
.map(|((x, y), weight)| (weight, (*x, *y)))
.collect();
assert_eq!(expected_update, actual_update_edge);
let actual_update_reaches: Vec<((isize, (i32, i32)))> = dynamic_view
.query_frontier_binary("reaches", (ANY_VALUE, ANY_VALUE))
.unwrap()
.map(|((x, y), weight)| (weight, (*x, *y)))
.collect();
assert_eq!(expected_update, actual_update_reaches);Sourcepub fn push_rule(&mut self, rule: impl Into<Rule>)
pub fn push_rule(&mut self, rule: impl Into<Rule>)
Pushes a rule into the materialized view.
§Examples
use materialized_view::*;
let query = program! {
reaches(?x, ?y) <- [edge(?x, ?y)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("edge", (1, 2));
dynamic_view.push_fact("edge", (2, 3));
dynamic_view.poll();
assert!(!dynamic_view.contains("reaches", (1, 3)).unwrap());
dynamic_view.push_rule(rule!{ reaches(?x, ?z) <- [edge(?x, ?y), reaches(?y, ?z)] });
dynamic_view.poll();
assert!(dynamic_view.contains("reaches", (1, 3)).unwrap());
Sourcepub fn retract_rule(&mut self, rule: impl Into<Rule>)
pub fn retract_rule(&mut self, rule: impl Into<Rule>)
Retracts a rule from the materialized view.
§Examples
use materialized_view::*;
let query = program! {
reaches(?x, ?y) <- [edge(?x, ?y)],
reaches(?x, ?z) <- [edge(?x, ?y), reaches(?y, ?z)]
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("edge", (1, 2));
dynamic_view.push_fact("edge", (2, 3));
dynamic_view.poll();
assert!(dynamic_view.contains("reaches", (1, 3)).unwrap());
dynamic_view.retract_rule(rule!{ reaches(?x, ?z) <- [edge(?x, ?y), reaches(?y, ?z)] });
dynamic_view.poll();
assert!(!dynamic_view.contains("reaches", (1, 3)).unwrap());Sourcepub fn contains(
&self,
relation_symbol: &'_ str,
fact: impl Into<Fact>,
) -> Result<bool, PollingError>
pub fn contains( &self, relation_symbol: &'_ str, fact: impl Into<Fact>, ) -> Result<bool, PollingError>
Checks whether a fact is true in the consolidated view. Throws an error if a poll is needed to obtain correct results.
§Examples
use materialized_view::*;
let query = program! {
reaches(?x, ?y) <- [edge(?x, ?y)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("edge", (1, 2));
dynamic_view.push_fact("edge", (2, 3));
println!("{}", dynamic_view.contains("reaches", (2, 3)).unwrap_err());
dynamic_view.poll();
println!("{}", dynamic_view.contains("reaches", (2, 3)).unwrap());Sourcepub fn query_unary<'a, T: 'static>(
&self,
relation_symbol: &'_ str,
goal: impl Into<Goal>,
) -> Result<impl Iterator<Item = (&T,)>, PollingError>
pub fn query_unary<'a, T: 'static>( &self, relation_symbol: &'_ str, goal: impl Into<Goal>, ) -> Result<impl Iterator<Item = (&T,)>, PollingError>
Queries the consolidated view of a unary relation.
§Examples
use materialized_view::*;
let query = program! {
rdfType(?o) <- [RDF(?s, "rdf:type", ?o)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("RDF", ("rust", "rdf:type", "programmingLanguage".to_string()));
dynamic_view.poll();
let query_result: Vec<((String,))> = dynamic_view
.query_unary::<String>("rdfType", (ANY_VALUE,))
.unwrap()
.map(|((x,))| (x.clone(),))
.collect();
let expected_query_result = vec![("programmingLanguage".to_string(),)];
assert_eq!(expected_query_result, query_result)Sourcepub fn query_frontier_unary<'a, T: 'static>(
&self,
relation_symbol: &'_ str,
goal: impl Into<Goal>,
) -> Result<impl Iterator<Item = ((&T,), isize)>, PollingError>
pub fn query_frontier_unary<'a, T: 'static>( &self, relation_symbol: &'_ str, goal: impl Into<Goal>, ) -> Result<impl Iterator<Item = ((&T,), isize)>, PollingError>
Queries the frontier view of a unary relation.
§Examples
use materialized_view::*;
let query = program! {
rdfType(?o) <- [RDF(?s, "rdf:type", ?o)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("RDF", ("rust", "rdf:type", "programmingLanguage".to_string()));
dynamic_view.poll();
dynamic_view.push_fact("RDF", ("emacs", "rdf:type", "operatingSystem".to_string()));
dynamic_view.poll();
let query_result: Vec<(isize, (String,))> = dynamic_view
.query_frontier_unary::<String>("rdfType", (ANY_VALUE,))
.unwrap()
.map(|((x,), weight)| (weight, (x.clone(),)))
.collect();
let expected_query_result = vec![(1, ("operatingSystem".to_string(),))];
assert_eq!(expected_query_result, query_result)Sourcepub fn query_binary<'a, T: 'static, R: 'static>(
&self,
relation_symbol: &'_ str,
goal: impl Into<Goal>,
) -> Result<impl Iterator<Item = (&T, &R)>, PollingError>
pub fn query_binary<'a, T: 'static, R: 'static>( &self, relation_symbol: &'_ str, goal: impl Into<Goal>, ) -> Result<impl Iterator<Item = (&T, &R)>, PollingError>
Queries the consolidated view of a binary relation.
§Examples
use std::collections::HashSet;
use materialized_view::*;
let query = program! {
subClassOf(?s, ?o) <- [RDF(?s, "rdfs:subClassOf", ?o)],
subClassOf(?s, ?t) <- [subClassOf(?s, ?o), subClassOf(?o, ?t)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("RDF", ("animal".to_string(), "rdfs:subClassOf", "livingForm".to_string()));
dynamic_view.push_fact("RDF", ("bird".to_string(), "rdfs:subClassOf", "animal".to_string()));
dynamic_view.poll();
let query_result: HashSet<((String, String))> = dynamic_view
.query_binary::<String, String>("subClassOf", (ANY_VALUE, ANY_VALUE))
.unwrap()
.map(|((x, y))| (x.clone(), y.clone()))
.collect();
let expected_query_result: HashSet<_> = vec![
("animal".to_string(), "livingForm".to_string()),
("bird".to_string(), "animal".to_string()),
("bird".to_string(), "livingForm".to_string())].into_iter().collect();
assert_eq!(expected_query_result, query_result);Sourcepub fn query_frontier_binary<'a, T: 'static, R: 'static>(
&self,
relation_symbol: &'_ str,
goal: impl Into<Goal>,
) -> Result<impl Iterator<Item = ((&T, &R), isize)>, PollingError>
pub fn query_frontier_binary<'a, T: 'static, R: 'static>( &self, relation_symbol: &'_ str, goal: impl Into<Goal>, ) -> Result<impl Iterator<Item = ((&T, &R), isize)>, PollingError>
Queries the frontier of a binary relation.
§Examples
use std::collections::HashSet;
use materialized_view::*;
let query = program! {
subClassOf(?s, ?o) <- [RDF(?s, "rdfs:subClassOf", ?o)],
subClassOf(?s, ?t) <- [subClassOf(?s, ?o), subClassOf(?o, ?t)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("RDF", ("animal".to_string(), "rdfs:subClassOf", "livingForm".to_string()));
dynamic_view.push_fact("RDF", ("bird".to_string(), "rdfs:subClassOf", "animal".to_string()));
dynamic_view.poll();
dynamic_view.retract_fact("RDF", ("animal".to_string(), "rdfs:subClassOf", "livingForm".to_string()));
dynamic_view.poll();
let query_result: HashSet<((isize, (String, String)))> = dynamic_view
.query_frontier_binary::<String, String>("subClassOf", (ANY_VALUE, ANY_VALUE))
.unwrap()
.map(|((x, y), weight)| (weight, (x.clone(), y.clone())))
.collect();
let expected_query_result: HashSet<_> = vec![
(-1, ("animal".to_string(), "livingForm".to_string())),
(-1, ("bird".to_string(), "livingForm".to_string()))].into_iter().collect();
assert_eq!(expected_query_result, query_result);Sourcepub fn query_ternary<'a, T: 'static, R: 'static, S: 'static>(
&self,
relation_symbol: &'_ str,
goal: impl Into<Goal>,
) -> Result<impl Iterator<Item = (&T, &R, &S)>, PollingError>
pub fn query_ternary<'a, T: 'static, R: 'static, S: 'static>( &self, relation_symbol: &'_ str, goal: impl Into<Goal>, ) -> Result<impl Iterator<Item = (&T, &R, &S)>, PollingError>
Queries the consolidated view of a ternary relation.
§Examples
use std::collections::HashSet;
use materialized_view::*;
let query = program! {
triangle(?a, ?b, ?c) <- [edge(?a, ?b), edge(?b, ?c), edge(?c, ?a)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("edge", (1, 2));
dynamic_view.push_fact("edge", (2, 3));
dynamic_view.push_fact("edge", (3, 1));
dynamic_view.push_fact("edge", (4, 5));
dynamic_view.push_fact("edge", (5, 6));
dynamic_view.poll();
let query_result: HashSet<((i32, i32, i32))> = dynamic_view
.query_ternary::<i32, i32, i32>("triangle", (ANY_VALUE, ANY_VALUE, ANY_VALUE))
.unwrap()
.map(|((a, b, c))| (*a, *b, *c))
.collect();
let expected_query_result: HashSet<_> = vec![(1, 2, 3), (2, 3, 1), (3, 1, 2)].into_iter().collect();
assert_eq!(expected_query_result, query_result);Sourcepub fn query_frontier_ternary<'a, T: 'static, R: 'static, S: 'static>(
&self,
relation_symbol: &'_ str,
goal: impl Into<Goal>,
) -> Result<impl Iterator<Item = ((&T, &R, &S), isize)>, PollingError>
pub fn query_frontier_ternary<'a, T: 'static, R: 'static, S: 'static>( &self, relation_symbol: &'_ str, goal: impl Into<Goal>, ) -> Result<impl Iterator<Item = ((&T, &R, &S), isize)>, PollingError>
Queries the frontier of a ternary relation.
§Examples
use std::collections::HashSet;
use materialized_view::*;
let query = program! {
triangle(?a, ?b, ?c) <- [edge(?a, ?b), edge(?b, ?c), edge(?c, ?a)],
};
let mut dynamic_view = MaterializedDatalogView::new(query);
dynamic_view.push_fact("edge", (1, 2));
dynamic_view.push_fact("edge", (2, 3));
dynamic_view.push_fact("edge", (3, 1));
dynamic_view.push_fact("edge", (4, 5));
dynamic_view.push_fact("edge", (5, 6));
dynamic_view.poll();
let query_result: HashSet<((isize, (i32, i32, i32)))> = dynamic_view
.query_frontier_ternary::<i32, i32, i32>("triangle", (ANY_VALUE, ANY_VALUE, ANY_VALUE))
.unwrap()
.map(|(((a, b, c), weight))| (weight, (*a, *b, *c)))
.collect();
let expected_query_result: HashSet<_> = vec![(1, (1, 2, 3)), (1, (2, 3, 1)), (1, (3, 1, 2))].into_iter().collect();
assert_eq!(expected_query_result, query_result);Trait Implementations§
Source§impl<'a, R> Extend<(&'a str, R)> for MaterializedDatalogViewwhere
R: Into<Fact>,
impl<'a, R> Extend<(&'a str, R)> for MaterializedDatalogViewwhere
R: Into<Fact>,
Source§fn extend<T: IntoIterator<Item = (&'a str, R)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (&'a str, R)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<R> Extend<R> for MaterializedDatalogViewwhere
R: Into<Rule>,
impl<R> Extend<R> for MaterializedDatalogViewwhere
R: Into<Rule>,
Source§fn extend<T: IntoIterator<Item = R>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = R>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Auto Trait Implementations§
impl !Freeze for MaterializedDatalogView
impl !RefUnwindSafe for MaterializedDatalogView
impl !Send for MaterializedDatalogView
impl !Sync for MaterializedDatalogView
impl Unpin for MaterializedDatalogView
impl !UnwindSafe for MaterializedDatalogView
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more