TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/HarvardPL/AbcDatalog/llms.txt
Use this file to discover all available pages before exploring further.
edu.harvard.seas.pl.abcdatalog.ast package defines the Java object model for a parsed Datalog program. Every clause produced by DatalogParser, and every clause you construct programmatically, is made up of these types. Understanding the AST classes is essential for building programs in code, for inspecting parsed results, and for writing visitors that traverse or transform programs.
Class hierarchy
| Class / Interface | Role |
|---|---|
Clause | A rule or ground fact. Holds a Head and a List<Premise> body. |
Head | Interface for the head of a clause. Currently only PositiveAtom implements it. |
Premise | Interface for body elements. Implemented by PositiveAtom, NegatedAtom, BinaryUnifier, and BinaryDisunifier. |
PositiveAtom | A positive (non-negated) atom: a PredicateSym paired with a Term[] argument array. Implements both Head and Premise. |
NegatedAtom | Wraps a PositiveAtom with negation (not atom). Implements Premise. |
BinaryUnifier | Represents a left = right unification premise in a rule body. Implements Premise. |
BinaryDisunifier | Represents a left != right disunification premise. Implements Premise. |
Term | Interface for terms. Implemented by Variable and Constant. |
Variable | A logic variable, identified by name. Names starting with uppercase or _ parse as variables. |
Constant | A ground constant (zero-ary function symbol). Names starting with a lowercase letter parse as constants. |
PredicateSym | A predicate name plus its arity. All atoms with the same name and arity share the same PredicateSym instance. |
Factory methods
All concrete AST types use static factory methods rather than public constructors. BothVariable and Constant memoize instances, so Variable.create("X") == Variable.create("X") holds by reference equality. PredicateSym.create does the same for (name, arity) pairs.
Clause uses a public constructor directly:
Visitor pattern
BothHead and Premise support the visitor pattern via accept methods that take a typed visitor and a state object. This is the preferred way to write code that handles multiple AST node kinds without instanceof chains.
Facts vs. rules
AClause with an empty body (getBody().isEmpty()) represents a ground EDB fact. A clause with a non-empty body is a rule. When you pass a Set<Clause> to DatalogEngine.init or DatalogValidator.validate, the validator separates the two automatically based on body emptiness and predicate membership in IDB vs. EDB.
Applying substitutions
EveryHead, Premise, and Term instance implements applySubst(Substitution subst), which returns a new AST node with the substitution applied. This is used internally by the engines and is useful when working with ConstOnlySubstitution results from conjunctive queries.