Crates.io | asdi |
lib.rs | asdi |
version | 0.2.5 |
source | src |
created_at | 2021-12-03 02:56:15.77834 |
updated_at | 2022-02-16 04:31:44.335565 |
description | Another Simplistic Datalog Implementation (in Rust) |
homepage | |
repository | https://github.com/johnstonskj/rust-asdi |
max_upload_size | |
id | 491529 |
size | 1,302,825 |
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. For more information see the ASDI book.
The text representation parser is a separate feature, so if you only need to construct and evaluate programs using the API you may opt out of the Pest parser and support.
io
module includes traits for
reading/writing relations as well as basic JSON and CSV 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);
}
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 |
Version 0.2.5
Version 0.2.4
StratifiedEvaluator
implementation that performs stratification as well as using the semi-naive evaluation
scheme.Version 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 added
AttributeNameRef
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