Broadly, I have a database of transformation rules (O(10,000)), that form part of a larger inference engine. The database needs to be queried and updated interactively. The transformation rules have the form:
transform(State, Context, State_, RuleID_) :-
more_conditions(State, Context), % implementation expanded in-place
new_state(State, Context, State_), % implementation expanded in-place
RuleID = 1234. % Just for tracking what rule matched
-
State and Context are tree-like data-structures:
State = tree(node(...more data...), [ ...tree children... ] )
-
To allow SWI to index the head, we expand State (and sometimes Context) in the head: (e.g.: )
transform(tree(node(tok{x:a, y:_, z:c}), ChildrenTreeList), _, State_, RuleID_) :-
... more conditional tests on ChildrenTreeList ....
... State_ = ...
- The database is generated incrementally, and interactively updated, through a mix of manual and automatic processes. When generating new rules, it’s helpful to examine existing (conflicting) rules and decide whether the new rule should have higher or lower precedence than others, and insert the new rule before or after them in the database (and delete rules the new rule subsumes), and iterate.
More or less, the ruleset database is queried against each token of a document - it should be real-time or better. Currently it is - thanks for indexing! The bulk of the database doesn’t have to be built in real-time. However:
-
rules are generated with a human-in-the-loop process. So we should be able to test and insert new rules (before or after existing rules) more or less in real-time.
-
being able to both insert and test against the new database will also speed up database generation which helps my day go faster,
A solution is to dispose and re-assert the entire database for each incremental change. I could do it, but I would prefer a better way.