pyswip does'nt seem to properly return complex answers. For example
for the given snippet at the end it returns:
Functor5234828 <type 'str'> which is not at all useful.
I replaced the following loop in __call__ in prolog.py:
for r in [x.value for x in t]:
v.update(r)
with: (also import Functor from easy.py)
for x in t:
if isinstance(x.args[1], Functor):
r = {x.args[0].chars:x.args[1]}
else:
r = x.value
v.update(r)
Then it returns a functor if available "son(1) <class
'pyswip.easy.Functor'>"
Its a quick dirty fix that solves my problem. There should be some
elegant way to do this, may be in
easy.py, but not sure. Any ideas?
--------------------------------------------------------
from pyswip import Prolog
p = Prolog()
p.consult("
father.pl")
soln = [s["Y"] for s in p.query("friend(john,Y), father(Y,kur)",
maxresult=1)]
print soln[0], type(soln[0])
#####
friend.pl ###
friend(john,son(miki)).
friend(john,son(kiwi)).
friend(john,son(wiki)).
friend(john,son(tiwi)).
father(son(miki),kur).
father(son(kiwi),kur).
father(son(wiki),kur).