Add example scripts
This commit is contained in:
parent
8f8e63b2f7
commit
e24876b8f5
@ -89,7 +89,7 @@ cargo run -- repl
|
||||
cargo run -- gui
|
||||
|
||||
# Run a script file
|
||||
cargo run -- script examples/session.chase
|
||||
cargo run -- script examples/scripts/ancestor.chase
|
||||
```
|
||||
|
||||
The REPL and GUI share a minimal command language:
|
||||
|
||||
13
examples/scripts/README.md
Normal file
13
examples/scripts/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Example Scripts
|
||||
|
||||
These scripts can be executed with:
|
||||
|
||||
```bash
|
||||
make script SCRIPT=examples/scripts/ancestor.chase
|
||||
```
|
||||
|
||||
Available examples:
|
||||
|
||||
- `ancestor.chase`: transitive closure over `Parent/2`
|
||||
- `employee_departments.chase`: existential rule that creates labeled nulls
|
||||
- `same_team.chase`: conjunctive query with a self-join
|
||||
11
examples/scripts/ancestor.chase
Normal file
11
examples/scripts/ancestor.chase
Normal file
@ -0,0 +1,11 @@
|
||||
# Derive ancestors from parent relationships.
|
||||
|
||||
fact Parent(alice, bob).
|
||||
fact Parent(bob, carol).
|
||||
fact Parent(carol, dave).
|
||||
|
||||
rule Parent(?X, ?Y) -> Ancestor(?X, ?Y).
|
||||
rule Ancestor(?X, ?Y), Parent(?Y, ?Z) -> Ancestor(?X, ?Z).
|
||||
|
||||
run.
|
||||
query Ancestor(?X, ?Y)?
|
||||
11
examples/scripts/employee_departments.chase
Normal file
11
examples/scripts/employee_departments.chase
Normal file
@ -0,0 +1,11 @@
|
||||
# Existential rule example: each employee works in some department.
|
||||
|
||||
fact Employee(alice).
|
||||
fact Employee(bob).
|
||||
fact Employee(carol).
|
||||
|
||||
rule Employee(?X) -> WorksIn(?X, ?Dept).
|
||||
|
||||
run.
|
||||
show facts
|
||||
query WorksIn(?X, ?Dept)?
|
||||
11
examples/scripts/same_team.chase
Normal file
11
examples/scripts/same_team.chase
Normal file
@ -0,0 +1,11 @@
|
||||
# Query people who share a manager.
|
||||
|
||||
fact ManagedBy(alice, eve).
|
||||
fact ManagedBy(bob, eve).
|
||||
fact ManagedBy(carol, frank).
|
||||
|
||||
rule ManagedBy(?X, ?M), ManagedBy(?Y, ?M) -> SameTeam(?X, ?Y).
|
||||
|
||||
run.
|
||||
query SameTeam(?X, ?Y)?
|
||||
query SameTeam(alice, bob)?
|
||||
Loading…
x
Reference in New Issue
Block a user