Trait holmes::fact_db::FactDB
[−]
[src]
pub trait FactDB { type Error: Error; fn insert_fact(&self, fact: &Fact) -> Result<bool, Self::Error>; fn add_type(&self, type_: Type) -> Result<(), Self::Error>; fn get_type(&self, type_str: &str) -> Option<Type>; fn get_predicate(&self, pred_name: &str) -> Option<Predicate>; fn new_predicate(&self, pred: &Predicate) -> Result<(), Self::Error>; fn new_rule_cache(&self, pred: Vec<String>) -> Result<CacheId, Self::Error>; fn cache_hit(
&self,
cache: CacheId,
_: Vec<FactId>
) -> Result<(), Self::Error>; fn search_facts(
&self,
query: &Vec<Clause>,
cache: Option<CacheId>
) -> Result<Vec<(Vec<FactId>, Vec<Value>)>, Self::Error>; }
This is the interface which a fact database must satisfy to be used by the Holmes engine.
Associated Types
Required Methods
fn insert_fact(&self, fact: &Fact) -> Result<bool, Self::Error>
Adds a new fact to the database, returning false if the fact was already present in the database, and true if it was inserted.
fn add_type(&self, type_: Type) -> Result<(), Self::Error>
Registers a new type with the database. This is unstable, and will likely need to be moved to the initialization of the database object in order to allow reconnecting to an existing database.
fn get_type(&self, type_str: &str) -> Option<Type>
Looks for a named type in the database's registry. This function is primarily useful for the DSL shorthand for constructing queries, since it allows you to use names of types when declaring functions rather than type objects.
fn get_predicate(&self, pred_name: &str) -> Option<Predicate>
Fetches a predicate by name
fn new_predicate(&self, pred: &Predicate) -> Result<(), Self::Error>
Persists a predicate by name
fn new_rule_cache(&self, pred: Vec<String>) -> Result<CacheId, Self::Error>
Creates a cache table for a new rule, returning a handle
fn cache_hit(&self, cache: CacheId, _: Vec<FactId>) -> Result<(), Self::Error>
Update
fn search_facts(
&self,
query: &Vec<Clause>,
cache: Option<CacheId>
) -> Result<Vec<(Vec<FactId>, Vec<Value>)>, Self::Error>
&self,
query: &Vec<Clause>,
cache: Option<CacheId>
) -> Result<Vec<(Vec<FactId>, Vec<Value>)>, Self::Error>
Attempt to match the right hand side of a datalog rule against the database, returning a list of solution assignments to the bound variables. Optionally provide a cache handle to have the db filter already processed results based on a provided cache.