protocol
datalog_protocol
Datalog and incremental rule engine protocol (stratified negation subset).
logtalk_load(datalog(loader))static
Rules: Rules are represented as
rule(Id, Head, Body)whereBodyis a list of literals usingTermfor positive,neg(Term)for negative, andagg(Op, Template, Goals, Result)for aggregates whereOpis one ofcount,sum,min, ormax.Facts: EDB facts are represented by callable and ground terms.
Limitations: Current version requires aggregate dependencies to be in lower strata.
Public predicates
clear/0
Clears all loaded rules, base facts, derived facts, and explanation supports.
staticclear - oneload_program/1
Loads a full program represented as a list of rule(Id,Head,Body) and fact(Fact) terms, replacing current engine state.
staticload_program(Program)load_program(+list) - oneadd_rule/3
Adds or replaces a rule. Rule safety is checked.
staticadd_rule(Id,Head,Body)add_rule(+nonvar,+callable,+list(callable)) - oneremove_rule/1
Removes all rules matching a rule identifier.
staticremove_rule(Id)remove_rule(+nonvar) - onebegin/0
Starts a transaction by saving the current engine state snapshot.
staticbegin - onecommit/0
Commits a transaction by discarding the saved state snapshot.
staticcommit - onerollback/0
Rolls back a transaction by restoring the saved state snapshot.
staticrollback - oneassert_fact/1
Asserts a ground EDB fact if not already present.
staticassert_fact(Fact)assert_fact(+callable) - oneretract_fact/1
Retracts an EDB fact if present.
staticretract_fact(Fact)retract_fact(+callable) - onematerialize/0
Computes rule closure from current EDB facts and loaded rules using a fixpoint algorithm.
staticmaterialize - oneupdate/3
Applies incremental EDB updates and propagates derivation additions/removals; returns the resulting truth delta.
staticupdate(Inserts,Deletes,Delta)update(+list(callable),+list(callable),-compound) - onequery/1
Enumerates currently true facts (EDB + IDB).
staticquery(Goal)query(?callable) - zero_or_morequery/2
Same as query/1 while returning the unified goal as the second argument.
staticquery(Goal,Bindings)query(?callable,?callable) - zero_or_moreexplain/2
Returns one explanation for a currently true fact.
staticexplain(Fact,Explanation)explain(+callable,-nonvar) - zero_or_more(rules)/1
Returns the loaded rules.
staticrules Rulesrules-list - onefacts/1
Returns all currently true facts as a sorted list.
staticfacts(Facts)facts(-list(callable)) - onepredicate_stratum/3
Enumerates predicate strata as functor, arity, and stratum number.
staticpredicate_stratum(Functor,Arity,Stratum)predicate_stratum(?atom,?integer,?integer) - zero_or_morestrata/1
Returns all strata grouped by stratum number and contained predicates.
staticstrata(Strata)strata(-list) - oneProtected predicates
(none)
Private predicates
(none)
Operators
(none)