Skip to content

Instantly share code, notes, and snippets.

@zefhemel
Last active December 12, 2015 00:58
Show Gist options
  • Save zefhemel/4687096 to your computer and use it in GitHub Desktop.
Save zefhemel/4687096 to your computer and use it in GitHub Desktop.
Sample that demonstrates how to generate Datalog with new Java API.
parent(a, b) ->
string(a),
string(b).
ancestor(a, b) ->
string(a),
string(b).
ancestor(a, c) <-
parent(a, b).
ancestor(a, c) <-
ancestor(a, b),
ancestor(b, c).
DatalogEnv env = new DatalogEnv();
env.addClause(constraint(
singleAtomList("parent", "a", "b"), // ->
conList(atom("string", "a"),
atom("string", "b"))));
env.addClause(constraint(
singleAtomList("ancestor", "a", "b"), // ->
conList(atom("string", "a"),
atom("string", "b"))));
env.addClause(rule(
singleAtomList("ancestor", "a", "c"), // <-
singleAtomList("parent", "a", "b")));
env.addClause(rule(
singleAtomList("ancestor", "a", "c"), // <-
conList(atom("ancestor", "a", "b"),
atom("ancestor", "b", "c"))));
env.validateEnv();
System.out.println(env.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment