ian-andrich / PythonPengines

A Python interface to the Prolog pengines library. Makes it exceedingly easy to call out to SWI-Prolog within Python!
MIT License
12 stars 9 forks source link

not getting any results back from dockerized pengines in python #20

Closed andreaBelmont closed 4 years ago

andreaBelmont commented 4 years ago

Hello,

I am trying to understand how to work with pengines. I have opened up an issue in the swi-prolog forum but got no attention there yet:

https://swi-prolog.discourse.group/t/pengines-issue/1838

That I am reproducing here below:


I’m using: SWI-Prolog version 8.0.3, via pengines on docker

Gundam:my_codes andreacortis$ docker run -p 0.0.0.0:3030:3030 -i -d -t pengines

Gundam:my_codes andreacortis$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
c988c1b8f54e        pengines            "swipl daemon.pl --p…"   16 minutes ago      Up 16 minutes       0.0.0.0:3030->3030/tcp   elegant_noether

the server is up and running

Gundam:my_codes andreacortis$ curl http://0.0.0.0:3030/docs/index.html
<!DOCTYPE html>
<html lang="en">
   <head>
      <!-- Meta, title, CSS, favicons, etc. -->
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta name="description" content="">
      <meta name="author" content="">
      <title>
[...]

I want the code to: reproduce the example at https://github.com/ian-andrich/PythonPengines

by using these commands in python:

from pengines.Builder import PengineBuilder 
from pengines.Pengine import Pengine 
pengine_builder = PengineBuilder(urlserver="http://0.0.0.0:3030") 

In [20]: pengine = Pengine(builder=pengine_builder,slave_limit=1, debug=True)                                                                   
Starting call.
Starting post request with URL http://0.0.0.0:3030/pengine/create, content_type: application/json, and body: {"chunk": 100, "format": "json"}
Starting Post request.
URL is:  http://0.0.0.0:3030/pengine/create
Data (body) :  b'{"chunk": 100, "format": "json"}'
Headers:  {'User-Agent': 'PythonPengine', 'Accept': 'application/json', 'Accept-Language': 'en-us,en;q=0.5', 'Content-type': 'application/json'}
response_string is : {
  "event":"create",
  "id":"84ec823c-c2dc-4993-86f5-7d64d8ee996f",
  "slave_limit":3
}
{'event': 'create', 'id': '84ec823c-c2dc-4993-86f5-7d64d8ee996f', 'slave_limit': 3}
Initialization complete.

In [21]: query = "X = 3, writeln(X)" 
    ...: pengine.ask(query) 
    ...: print(pengine.currentQuery.availProofs)                                                                                                
Starting the call to ask.
Current state is idle
Initializing query with query: X = 3, writeln(X)
Call to ask is complete
[]

I am not getting anything back and I do not understand if this is a prolog issue or a python issue.

By the way, I also get an empty list by trying the query

query = "member(X, [1,2,3])"
pengine.ask(query)
print(pengine.currentQuery.availProofs)
or any other query.

Any advice, please?

Thanks

Andrea

ian-andrich commented 4 years ago

@cmungall We aren't having this problem in the test suite are we?

ian-andrich commented 4 years ago

@andreaBelmont Please take a look at our test suite and travis ci stuff. @cmungall Uses a comparable docker based set up for running the Pengine, and our tests don't seem to be having problems.

I suspect at least part of the problem is our documentation is out of date.

andreaBelmont commented 4 years ago

Just saw this: I am going to take a look.

ian-andrich commented 4 years ago

@andreaBelmont Let me know if it's not making sense.

andreaBelmont commented 4 years ago

You are right, I am now able to run the query by first running the docker container

docker run -d -p 4242:9083 -e PORT=9083 --name sparqlprog_pengines cmungall/sparqlprog

and then using it from python

In [1]: from pengines.Builder import PengineBuilder
   ...: from pengines.Pengine import Pengine
   ...: q = "member(X, [1,2,3])"
   ...: factory = PengineBuilder(urlserver="http://localhost:4242", destroy=False, ask=q)
   ...: pengine = Pengine(builder=factory, debug=False)
   ...: results = pengine.currentQuery.availProofs
   ...: print(results)
[{'X': 1}, {'X': 2}, {'X': 3}]