pyswip query does'nt seem to properly return complex answers

瀏覽次數:255 次
跳到第一則未讀訊息

Sandeep

未讀,
2009年5月12日 上午9:47:362009/5/12
收件者:pyswip
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).

Sandeep

未讀,
2009年5月12日 下午1:29:562009/5/12
收件者:pyswip
Ok, just need to change easy.py:
Put this in try block of _unifier.
# or is it PL_is_functor()
if isinstance(args[1], Functor):
return {args[0].chars:args[1]}
else:
return {args[0].chars:args[1].value}

Found some complaints regarding this problem:
http://www.kuliniewicz.org/blog/archives/2007/10/21/python-v-prolog-round-1-fight/

Fabiano Luz

未讀,
2015年7月3日 下午4:47:012015/7/3
收件者:pys...@googlegroups.com
In my case, this change doesn't work
I get this result: geral(2)

the correct: geral(structure('SELECT X'), get_object(s(paulo_de_tarso), p(email)))

Can someone help me?

NonDucor

未讀,
2015年7月5日 凌晨12:21:132015/7/5
收件者:pys...@googlegroups.com
The following patch may be useful. It improves the Functor class so its default "value" makes more sense than "Functor6820108".
functor_pprint.patch
回覆所有人
回覆作者
轉寄
0 則新訊息