Another Simplistic Datalog Implementation (in Rust)
MIT License
Another Simplistic Datalog Implementation (in Rust).
This package provides a data model to represent Datalog programs in memory, a parser for the textual representation, and some evaluation implementations. As well as the generated rustdoc we also maintain a mdbook generated site with more information.
io
module includes traits forThe crate has a number of features, most of which are opt-out as they are included in the
default
feature.
Feature | Default | Enables |
---|---|---|
graphviz |
Yes | Graph representation for dependency graphs and stratification |
parser |
Yes | Parsing of textual representation |
tabular |
Yes | Tabular output for views |
io |
Yes | collects all the common I/O formats |
io_csv |
Indirectly | Delimited line format support |
io_json |
Indirectly | JSON format support |
io_text |
Indirectly | Native text format (write only) support |
parent(xerces, brooke).
parent(brooke, damocles).
ancestor(X, Y) ⟵ parent(X, Y).
ancestor(X, Y) ⟵ parent(X, Z) ⋀ parent(Z, Y).
?- ancestor(xerces, X).
use asdi::edb::{Attribute, Predicate};
use asdi::idb::{Atom, Query, Term, Variable};
use asdi::Program;
use std::str::FromStr;
fn ancestor_example() {
// See https://en.wikipedia.org/wiki/Datalog
let mut ancestors = Program::default();
let parent_predicate = Predicate::from_str("parent").unwrap();
{
let parent = ancestors
.add_new_relation(
parent_predicate.clone(),
vec![Attribute::string(), Attribute::string()],
)
.unwrap();
parent
.add_as_fact(["xerces".into(), "brooke".into()])
.unwrap();
parent
.add_as_fact(["brooke".into(), "damocles".into()])
.unwrap();
};
let ancestor_predicate = Predicate::from_str("ancestor").unwrap();
let var_x: Term = Variable::from_str("X").unwrap().into();
let var_y: Term = Variable::from_str("Y").unwrap().into();
let var_z: Term = Variable::from_str("Z").unwrap().into();
ancestors
.add_new_rule(
ancestor_predicate.clone(),
[var_x.clone(), var_y.clone()],
[Atom::new(parent_predicate.clone(), [var_x.clone(), var_y.clone()]).into()],
)
.unwrap();
ancestors
.add_new_rule(
ancestor_predicate.clone(),
[var_x.clone(), var_y.clone()],
[
Atom::new(parent_predicate, [var_x.clone(), var_z.clone()]).into(),
Atom::new(ancestor_predicate.clone(), [var_z, var_y]).into(),
],
)
.unwrap();
ancestors
.add_new_query(ancestor_predicate, ["xerces".into(), var_x])
.unwrap();
println!(">{}<", ancestors);
}
Please review our Contributing guidelines, Code of Conduct and License.
Version 0.2.5
Version 0.2.4
StratifiedEvaluator
implementation that performs stratification as well as using the semi-naive evaluationVersion 0.2.3
LiteralInner
/Literal
to be Relational
and Arithmetic
to convey meaning, not just type.Relations
to RelationSet
and Rules
to RuleSet
.PredicateSet
to NameReferenceSet
and used for variables also; this also addedAttributeNameRef
type for clarity.Version 0.2.2
%
instead of #
for line comments,/*
and */
for block comments,@
prefix on the boolean constants true
and false
,.
instead of @
for pragmas.assert
and infer
pragmas rather than Soufflé's single decl
..
whereas in Soufflé they do not.Version 0.2.1
Version 0.2.0
Version 0.1.0
Version 0.1.0-dev