Expand description
Another Simplistic Datalog Implementation (ASDI), in Rust.
This package provides a data model to represent Datalog programs in memory, a parser for the textual representation, and some evaluation implementations.
§Library features
The library 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 |
§Example
The following program is the classical syllogism example, in the text representation.
human("Socrates").
mortal(X) <- human(X).
?- mortal("Socrates").Note in this example we allow the parser to identify the schema for the relations human and
mortal rather than using the pragmas assert and infer.
The following is the same example constructed via the ASDI library.
use asdi::{NameReferenceSet, Program};
use asdi::edb::{Attribute, Predicate};
use asdi::idb::{Atom, Term, Variable};
use std::str::FromStr;
let mut syllogism = Program::default();
let predicates = syllogism.predicates();
let p_human = predicates.fetch("human").unwrap();
let p_mortal = predicates.fetch("mortal").unwrap();
let human = syllogism
.add_new_extensional_relation(p_human.clone(), vec![Attribute::string()])
.unwrap();
human.add_as_fact(["Socrates".into()]).unwrap();
let variables = syllogism.variables();
let var_x: Term = variables.fetch("X").unwrap().into();
syllogism
.add_new_pure_rule(
p_mortal.clone(),
[var_x.clone()],
[Atom::new(p_human, [var_x]).into()],
)
.unwrap();
syllogism
.add_new_query(p_mortal, ["Socrates".into()])
.unwrap();The execution of this program will start with the goal query “is Socrates mortal?” and in doing so will evaluate the necessary rule and derive the relation mortal. The result is a boolean value denoting whether the goal is satisfied.
+------------+
| _: boolean |
+============+
| true |
+------------+However, if we were to change the final query to replace the constant with a variable, as follows.
?- mortal(X).The program will select all matching (in this case all) facts from the mortal relation.
+------------+
| X: string |
+============+
| "Socrates" |
+------------+Modules§
- edb
- This module provides the set of types that primarily describe the Extensional Database (EDB).
- error
- This module provides the common
ErrorandResulttypes for this library. - features
- This module provides the
FeatureandFeatureSettypes that allow programs to support specific extensions to Datalog. - idb
- This module provides the set of types that primarily describe the Intensional Database (IDB).
- parse
- This module provides the type
Parsedthat contains a program parsed from the text representation as well as theparse_file,parse_str, andparse_str_with_featuresfunctions. - visitor
- This module provides the trait Typesetter, and implementation
Structs§
- Name
Reference Set - The predicate set $\small\mathcal{P}$ determines the labels of relations, atoms, and facts. This type keeps a mapping of strings to PredicateRefs to reduce memory duplication.
- Program
- A program consists of a set of extensional
RelationSet, a set of intensionalRelationSet, a set ofRuleSet, and a set of queries.
Constants§
Traits§
- Attribute
Name - Attributes, the members of Schema are named using different types in Relations and Views. This trait identifies the minimum set of implementations required for an attribute name.
- Collection
- All collections of things in the library implement these basic methods.
- Indexed
Collection - All indexed collections of things in the library implement these basic methods.
- Labeled
- Implemented by types that have a label.
- Maybe
Anonymous - Implemented by types that have the notion of an anonymous value.
- Maybe
Positive - Implemented by types that need to distinguished between values that may contain negative literals.
- Program
Core - Core, readable, properties of a Datalog program.
Type Aliases§
- Attribute
Name Ref - A reference type for attribute names.