I want to use a Python script as a frontend to a Prolog program that uses the SWI-PL engine.
So, the components of the setup are:
I've been looking around for an interface between SWI-PL and Python. What I found are:
PySwip but it seems to be lacking from what i see from old questions here, and also seems unsupported.
PyLog, which seems newer but also has some activity. Although i don't know how good it is.
What is the recommended way of using Python to communicate with SWI-prolog? Are there perhaps other ways to accomplish this? Maybe with another prolog engine?
I'm stuck with the Prolog language and Python because I know them best, so that would be necessary (I know for instance there are also tools for Java).
The Python version has also a foreign function interface. But easiest to try your knowledge base is put it into a Prolog text file, consult it and query it: >python.exe toplevel.py Dogelog Runtime, Prolog to the Moon, 0.9.
Open a terminal (Ctrl+Alt+T) and navigate to the directory where you stored your program. Open SWI-Prolog by invoking swipl . In SWI-Prolog, type [program] to load the program, i.e. the file name in brackets, but without the ending. In order to query the loaded program, type goals and watch the output.
PySWIP is a Python - SWI-Prolog bridge enabling to query SWI-Prolog in your Python programs. It features an (incomplete) SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.
Online Prolog (swi) compiler.
I've personally used PySWIP successfully. Here's a link to a project I did for my AI class in university in which I used PySWIP.
I think the difference is that PySWIP is a bridge (just send queries to a Prolog database and get responses) whereas PyLog seems to be an implementation of Prolog (or a built-in Prolog engine) in Python, with abstractions on Prolog code using objects.
I have no particular recommendation for you. Choose whichever you deem will suit your project best. Consider the licenses under which these libraries are published if you will need to worry about your code's license.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With