Question

I want to write a Python web application that queries RDF triples using Prolog. I found pyswip for interfacing Python with SWI-Prolog, and I am currently looking into SWI-Prolog's RDF capabilities. I am wondering if anyone has tried this before--and if anyone has: what did your setup look like? How do you get pyswip to work with the SWI-Prolog semantic web library? Or is there another Python-Prolog interface that makes this easier?

Edit:

I actually found a really nice solution to this. I have used the AllegroGraph 3.3 Python API before to do Prolog queries on RDF data, but I thought their Prolog extension to Allegro Common Lisp was kind of lacking because it was missing things like number comparison operators. I have since tried out AllegroGraph 4.6 and I found that anything missing from their Prolog extension is made up for by the fact that you can use the lisp escape functor to write Allegro Common Lisp expressions to take care of anything you need to do that isn't offered by the Prolog extension. For some reason this functor was not defined when I used the AllegroGraph 3.3 Python API, but clearly the developers at Allegro have come a long way since then.

I suggest this for anybody who wants to build a Python web app that queries RDF data using Prolog. It's super fast and super powerful.

Was it helpful?

Solution

I haven't used pyswip, although some time ago I took a look to it. Your question is compelling, and pyswip looks attractive, specially the 'pythonic' interface.

Then I managed to install, but when done (I had to tweak install 'instructions', because I'm running a fairly up-to-date SWI-Prolog), I can't run the simple introductory samples without incurring in weird problems: wrong arity in sample declarations, SWI-Prolog complains on mishandled term references on 2^ assertz, and the like. And I can't find any documentation....

I would suggest to use Boost.Python and the C++ SWI-Prolog FLI (Foreign Language Interface).

Maybe we need just a single method: say PrologEngine.call(TermArray), mapped to call/N, to fully access the rich Prolog library (among others, SemWeb), and some reflective call.

That said, I think that is not a trivial task, and maybe pyswip provides a better way, once debugged...

I could be interested to collaborate in coding something, I know a bit of Boost and C++ FLI, but I'm not a Python coder, just used it to prototype usage of Google Docs (or better, just Spreadsheets)...

OTOH I enjoy writing in Prolog, and now, off-topic, I would take a digression, and propose you a slightly different approach: make a more distinct interface between logic and presentation (i.e. more MVC), using HTTP server capabilities of SWI-Prolog.

Write a server that exposes as (X)HTML (+JSON+SVG+...), and in python use (or parse) the output. A kind of RPC.

That way the logic will be strongly decoupled, and then will increase much the reusability. Of course this make sense if you are not interested in the triples 'in se', but in their semantic.

I think that also debugging can be much easier, always due to decoupling. Jan Wielemaker, main SWI-Prolog developer, often advises about the difficulty to harness the behaviour of complex engines running together, like Java (and I think Python will be similar) and Prolog, specially when multi threading is involved (always, if we think of it). And today, multi threading is to be used.

OTHER TIPS

ive no experience with pyswip. but for your reference, swi prolog seems quite capable, as i have some experience with the library knowrob , which is for ai reasoning in robotics. not sure if this helps though

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top