How to run a Prolog/Datalog program where facts can be added interactively

71 Views Asked by At

I hope my question makes sense. I wasn't sure how it should be expressed. My apologies if it does not.

Suppose I have a Prolog query such as

ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Y), ancestor(Z, Y).

Now I want to run some web app or api that will allow me to add facts interactively. Perhaps like

POST /facts {"fact": "parent(beatrix, charlie)."}

Perhaps at some later point, I want to run the ancestor query, again via the api:

GET /ancestor {"x": "beatrix", "y": "charlie"}

which now hopefully returns true (or something similar).

Does anyone have some ideas of how this can be accomplished? Either in Prolog or Datalog? Or some Prolog wrapper like https://github.com/ichiban/prolog.

From what I have read so far it seems I need to :- dynamic parent/2 and keep adding facts with ?- assertz(parent(beatrix, charlie)). but surely there is a better way? Maybe this is where something like Datalog would shine? But I don't know much about Datalog yet.

Anyway, I would be greatful for any hints or links to reading material.

Thank you!

0

There are 0 best solutions below