Crate asdi

source · []
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.

module UML

Library features

The library has a number of features, most of which are opt-out as they are included in the default feature.

FeatureDefaultEnables
graphvizYesGraph representation for dependency graphs and stratification
parserYesParsing of textual representation
tabularYesTabular output for views
ioYescollects all the common I/O formats
io_csvIndirectlyDelimited line format support
io_jsonIndirectlyJSON format support
io_textIndirectlyNative 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

This module provides the set of types that primarily describe the Extensional Database (EDB).

This module provides the common Error and Result types for this library.

This module provides the Feature and FeatureSet types that allow programs to support specific extensions to Datalog.

This module provides the set of types that primarily describe the Intensional Database (IDB).

This module provides the type Parsed that contains a program parsed from the text representation as well as the parse_file, parse_str, and parse_str_with_features functions.

This module provides the trait Typesetter, and implementation

Structs

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.

A program consists of a set of extensional RelationSet, a set of intensional RelationSet, a set of RuleSet, and a set of queries.

Constants

Traits

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.

All collections of things in the library implement these basic methods.

All indexed collections of things in the library implement these basic methods.

Implemented by types that have a label.

Implemented by types that have the notion of an anonymous value.

Implemented by types that need to distinguished between values that may contain negative literals.

Core, readable, properties of a Datalog program.

Type Definitions

A reference type for attribute names.