Python interface with SWI-Prolog
Asked Answered
D

2

11

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

Domitiladomonic answered 26/6, 2013 at 17:24 Comment(0)
C
14

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.

Cony answered 26/6, 2013 at 18:30 Comment(0)
T
0

The recommended way of using prolog in python is using janus-swi package. Here is how to set it up.

First you install the package

pip install janus-swi

If you got a problem in downloading and it said that C++ build tools aren't found, you just need to install Microsoft C++ Build Tools from here. Basically, you download Visual Studio and make sure to select C/C++ build tools during the installation process.

Next and lastly, it is important to have the environment variable SWI_HOME_DIR pointing at swipl installation directory. Use the corresponding command:

Windows

setx SWI_HOME_DIR "C:\Program Files\swipl"

Linux

set SWI_HOME_DIR="~/swipl"

For information on how to use the package refer to the documentation for details.

Tunis answered 14/7 at 1:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.