Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python interface with SWI-Prolog

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:

  • Python (2.7 or higher)
  • SWI-PL: website here

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).

like image 938
Mythio Avatar asked Jun 26 '13 17:06

Mythio


People also ask

How do you use Prolog in Python?

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.

How do I run SWI on Prolog?

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.

What is PySWIP?

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.

Is SWI-Prolog a compiler?

Online Prolog (swi) compiler.


1 Answers

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.

like image 107
2rs2ts Avatar answered Oct 13 '22 15:10

2rs2ts