Last active
December 12, 2015 00:58
-
-
Save zefhemel/4687096 to your computer and use it in GitHub Desktop.
Sample that demonstrates how to generate Datalog with new Java API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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