-
|
In the readme we have 2 examples about rules and predicates (and grounded facts), namely contains_jar_direct and direct_conn. As far as I understand, these are grounded facts to be imported or referenced at runtime (like a connection to Postgres, or a Rest API call). Could you direct me to concrete examples of how it is to be done? I can work directly with C, Go. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
There are a few ways / patterns / conventions which are often good enough in the meantime. I should document these recipes better. Let me know if these examples help, or whether you really prefer runtime external predicates. 1. offline, full, ahead-of-timeThe simplest is to retrieve the data and then populate the factstore with facts, before doing evaluation. Ths README was written with such a setup in mind, where we can retrieve all the data upfront. Example code that populates a factstore from a file. You could also just add the facts to the fact store one by one. When the data is changing, one can periodically repeat this, replacing factstore, redoing evaluation. 2. interactive, selectiveFor an interactive use case (you get a Mangle program which needs external data and need to build a database to compute the result), there are atoms that are fully determined external queries whose results fits in memory:
For type-checking, you want a declaration like this that defines a "mode". A "+" mode indicates input, a "-" mode indicates output. To remember which is which for the modes, think of shooting an arrow: for input, you shoot the arrow and see the read-end, for output, the arrow-head is pointing at you. 3. offline, selective, dynamic in phasesIf database computed ahead of time, the full external data would be too much, the relevant data fits in-memory and your program needs specific subset but you only know what in the middle of evaluation, one can do something like this:
This can even be done in a loop, with caching, until no more facts are added. If the data is huge, one can save the factstore to a file (or cloud service) between phases. This all needs dev work, but overcomes in-memory limitations. |
Beta Was this translation helpful? Give feedback.
-
|
I filed issue #59 for proper external predicates. |
Beta Was this translation helpful? Give feedback.
Proper external predicates called during evaluation are not supported yet (they will be).UPDATE: There is an external predicates API now ea0330cThere are a few ways / patterns / conventions which are often good enough in the meantime. I should document these recipes better.
Let me know if these examples help, or whether you really prefer runtime external predicates.
1. offline, full, ahead-of-time
The simplest is to retrieve the data and then populate the factstore with facts, before doing evaluation. Ths README was written with such a setup in mind, where we can retrieve all the data upfront. Example code that populates a factstore from a file. You could also just add the facts to the …