2026-03-09 10:49:50 +01:00
|
|
|
## Chase-rs
|
2026-03-09 09:59:10 +01:00
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
An implementation of the chase algorithm in Rust for advanced reasoning engines.
|
2026-03-09 09:59:10 +01:00
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
### Overview
|
2026-03-09 09:59:10 +01:00
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
The chase algorithm is a fundamental technique in context of database theory and knowledge representation used for:
|
2026-03-09 09:59:10 +01:00
|
|
|
|
|
|
|
|
- Query answering under tuple-generating dependencies (TGDs)
|
|
|
|
|
- Computing universal models
|
|
|
|
|
- Ontology-based data access (OBDA)
|
|
|
|
|
- Datalog with existential rules
|
|
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
This implementation provides a **restricted chase** that guarantees termination even with existential rules by tracking applied triggers.
|
2026-03-09 09:59:10 +01:00
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
### Features
|
2026-03-09 09:59:10 +01:00
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
- **Core Data Types**: Terms, Atoms, Rules, and Instances
|
2026-03-09 09:59:10 +01:00
|
|
|
- **Existential Quantification**: Automatic generation of labeled nulls
|
|
|
|
|
- **Restricted Chase**: Termination guarantees via trigger tracking
|
|
|
|
|
- **Fluent API**: `RuleBuilder` for readable rule construction
|
|
|
|
|
- **Zero Dependencies**: Pure Rust with no external runtime dependencies
|
|
|
|
|
|
2026-03-09 11:05:09 +01:00
|
|
|
See [ROADMAP.md](ROADMAP.md) for the list of implemented and planned features.
|
|
|
|
|
|
|
|
|
|
> [!IMPORTANT]
|
|
|
|
|
> This project is still in early development, so bugs and breaking changes are expected.
|
|
|
|
|
> Please use the [issues page](https://code.obsidian.systems/habedi-work/chase-rs/issues) to report bugs or request features.
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
### Quick Start
|
2026-03-09 09:59:10 +01:00
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
use chase_rs::{chase, Atom, Instance, Term};
|
|
|
|
|
use chase_rs::chase::rule::RuleBuilder;
|
|
|
|
|
|
|
|
|
|
// Create initial facts
|
|
|
|
|
let instance: Instance = vec![
|
|
|
|
|
Atom::new("Parent", vec![Term::constant("alice"), Term::constant("bob")]),
|
|
|
|
|
Atom::new("Parent", vec![Term::constant("bob"), Term::constant("carol")]),
|
|
|
|
|
].into_iter().collect();
|
|
|
|
|
|
|
|
|
|
// Define rules
|
|
|
|
|
// Parent(X, Y) -> Ancestor(X, Y)
|
|
|
|
|
let rule1 = RuleBuilder::new()
|
|
|
|
|
.when("Parent", vec![Term::var("X"), Term::var("Y")])
|
|
|
|
|
.then("Ancestor", vec![Term::var("X"), Term::var("Y")])
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
// Ancestor(X, Y), Parent(Y, Z) -> Ancestor(X, Z)
|
|
|
|
|
let rule2 = RuleBuilder::new()
|
|
|
|
|
.when("Ancestor", vec![Term::var("X"), Term::var("Y")])
|
|
|
|
|
.when("Parent", vec![Term::var("Y"), Term::var("Z")])
|
|
|
|
|
.then("Ancestor", vec![Term::var("X"), Term::var("Z")])
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
// Run the chase
|
|
|
|
|
let result = chase(instance, &[rule1, rule2]);
|
|
|
|
|
|
|
|
|
|
assert!(result.terminated);
|
|
|
|
|
println!("Derived {} facts", result.instance.len());
|
|
|
|
|
```
|
|
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
### Existential Rules
|
2026-03-09 09:59:10 +01:00
|
|
|
|
|
|
|
|
Rules with head-only variables (existential quantification) automatically generate fresh labeled nulls:
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
// Every person has an SSN: Person(X) -> HasSSN(X, Y)
|
|
|
|
|
let rule = RuleBuilder::new()
|
|
|
|
|
.when("Person", vec![Term::var("X")])
|
|
|
|
|
.then("HasSSN", vec![Term::var("X"), Term::var("Y")]) // Y is existential
|
|
|
|
|
.build();
|
|
|
|
|
```
|
|
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
### Building and Testing
|
2026-03-09 09:59:10 +01:00
|
|
|
|
|
|
|
|
```bash
|
2026-03-09 10:49:50 +01:00
|
|
|
## Run all tests
|
2026-03-09 09:59:10 +01:00
|
|
|
cargo test
|
|
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
## Run with optimizations
|
2026-03-09 09:59:10 +01:00
|
|
|
cargo build --release
|
|
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
## Check for lint warnings
|
2026-03-09 09:59:10 +01:00
|
|
|
cargo clippy
|
|
|
|
|
```
|
|
|
|
|
|
2026-03-09 10:49:50 +01:00
|
|
|
### License
|
2026-03-09 09:59:10 +01:00
|
|
|
|
|
|
|
|
This project is licensed under [BSD-3](LICENSE).
|