Once aDocumentation 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.
DatalogExecutor has been started, you can push new EDB facts into the running evaluation at any time using addFactAsynchronously(PositiveAtom). The executor incorporates each fact and derives any consequences that follow, firing registered listeners as new facts are produced. This page walks through a complete working example and explains the rules that govern which facts can be added.
Complete example
The following program computes the transitive closure of a graph, starting with two edges in the initial program. Three more edges — including one that closes a cycle — are added asynchronously after evaluation has started.Step-by-step breakdown
Parse the Datalog program
Use
DatalogTokenizer and DatalogParser.parseProgram() to turn the program string into a Set<Clause>. The program here encodes transitive closure (tc) and a zero-arity cycle detector (cycle). The initial EDB facts (edge(0,1) and edge(1,2)) are embedded directly in the program string.Create a DatalogParallelExecutor
Instantiate
DatalogParallelExecutor, the concrete implementation of DatalogExecutor that runs evaluation concurrently in separate threads.Call initialize()
Pass the parsed program and a set of
PredicateSym values representing which EDB predicates may be extended at runtime. In this example, only the edge predicate is extendible. Any fact added later via addFactAsynchronously() must use one of these predicates.Register listeners
Register
DatalogListener callbacks before calling start(). See Reacting to derived facts with DatalogListener for full details on writing listeners safely.Call start()
Start the evaluation. The executor begins processing the initial facts and rules in background threads. After this point, listener registration is no longer allowed.
Add facts with addFactAsynchronously()
Parse each new fact as a
PositiveAtom and pass it to addFactAsynchronously(). The executor enqueues the fact and incorporates it into the running evaluation. Any derivations triggered by the new fact will be processed concurrently and can cause listener callbacks to fire.Rules for addFactAsynchronously()
addFactAsynchronously(PositiveAtom edbFact) enforces the following constraints:
- The fact must be ground. A ground atom contains no variables — all argument positions must be bound to concrete constants. If
edbFact.isGround()returnsfalse, the method throwsIllegalArgumentException. - The predicate must be extendible. The predicate symbol of
edbFactmust appear in theextendibleEdbPredsset passed toinitialize(). If it does not, the method throwsIllegalArgumentExceptionwith the message"Atom is not part of an extendible EDB relation.". - The executor must be initialized. Calling this method before
initialize()throwsIllegalStateException.
addFactAsynchronously() is thread-safe. Multiple threads can safely call it concurrently on the same executor, making it straightforward to feed facts from several producer threads simultaneously.