yuce / pyswip

PySwip is a Python-Prolog interface that enables querying SWI-Prolog in your Python programs.
https://pyswip.org
MIT License
482 stars 98 forks source link

Issue #16(Can't Query Lists) which you closed is coming back to me #96

Closed ShubhamSharma1808 closed 4 years ago

ShubhamSharma1808 commented 4 years ago

Output shows the type Atom and address associated with it.the prolog list returned by the query is not getting properly stored in python list. where it should print -> [one,two,three,four]

from pyswip import Prolog
p = Prolog()
p.retractall('tran(_,_)')
p.retractall('listtran(_,_)')
p.assertz('tran(eins,one)')
p.assertz('tran(zwei,two)')
p.assertz('tran(drei,three)')
p.assertz('tran(vier,four)')
p.assertz('tran(fuenf,five)')
p.assertz('tran(sechs,six)')
p.assertz('tran(sieben,seven)')
p.assertz('tran(acht,eight)')
p.assertz('tran(neun,nine)')    
p.assertz('listtran([],[])')
p.assertz('listtran([X|Tx],[Y|Ty]) :- tran(X,Y) , listtran(Tx,Ty)')

Val = list(p.query('listtran([eins,zwei,drei,vier],Z)'))
print(Val)

Output:-

[{'Z': [Atom('468997'), Atom('469381'), Atom('469765'), Atom('470149')]}]
ShubhamSharma1808 commented 4 years ago

The alternate solution which worked for me, but still how to read the prolog list ?

from pyswip import Prolog
p = Prolog()
p.retractall('tran(_,_)')
p.retractall('listtran(_,_)')
p.assertz("tran(eins,one)")
p.assertz('tran(zwei,two)')
p.assertz('tran(drei,three)')
p.assertz('tran(vier,four)')
p.assertz('tran(fuenf,five)')
p.assertz('tran(sechs,six)')
p.assertz('tran(sieben,seven)')
p.assertz('tran(acht,eight)')
p.assertz('tran(neun,nine)')    
p.assertz('listtran([],[])')
p.assertz('listtran([X|Tx],[Y|Ty]) :- tran(X,Y) , listtran(Tx,Ty)')

for soln in p.query('listtran([eins,zwei,drei],[X,Y,Z])'):
    print(soln)

Output:-

{'X': 'one', 'Y': 'two', 'Z': 'three'}
yuce commented 4 years ago

@ShubhamSharma1808 The private repo that implements a fix will be made public soon. Let me know if you'd like to get access to it.

ShubhamSharma1808 commented 4 years ago

@yuce Would be great if you provide the access.

yuce commented 4 years ago

Can you send your Gitlab handle to pyswip@scaleplan.net so I can grant you access there?

yuce commented 4 years ago

@ShubhamSharma1808 Does the PR https://github.com/yuce/pyswip/pull/97 fix the problem for you?

ShubhamSharma1808 commented 4 years ago

Hey Yuce,

I am currently busy in some other problematic areas in my work , so i havent tested it yet. I will reach to you when i have done testing.

Thank you

On Tue, 7 Jul 2020, 4:17 pm Yüce Tekol, notifications@github.com wrote:

@ShubhamSharma1808 https://github.com/ShubhamSharma1808 Does the PR #97 https://github.com/yuce/pyswip/pull/97 fix the problem for you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yuce/pyswip/issues/96#issuecomment-654768177, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALRCA6HERO5NQ24Z5V6TP4TR2L4LHANCNFSM4OK43FXQ .

ShubhamSharma1808 commented 4 years ago

@yuce the issue is being solved by the update in the pyswip.