Can I enter rules into the data base?

131 views
Skip to first unread message

Sandeep

unread,
Oct 2, 2009, 9:06:26 AM10/2/09
to pyswip, dksr...@gmail.com
Hi,
Is there a way I can enter rules in database? One way is to consult
the .pl file that has
rules in it. But I want to use assertz.
Like: call(assertz("less(X,Y) :- X < Y.")) and query q = Query('less
(1,2)') or something like that.
I tried a lot but could not get it with call. Any help is appreciated.

Cheers,
Sandeep

yuce

unread,
Oct 2, 2009, 9:20:55 AM10/2/09
to pyswip
Hi Sandeep,

There is an example about that at the bottom of: http://code.google.com/p/pyswip/,
let me know if you have any problems with the code at Example (Using
Prolog) or Example (Pythonic Interface) sections of that page.

Best wishes,

Yuce

dksr

unread,
Oct 5, 2009, 9:28:28 AM10/5/09
to pyswip
Hi yuce,

> There is an example about that at the bottom of:http://code.google.com/p/pyswip/,

The examples you have provided are for 'facts' not for 'rules'.
Actually, my problem is to use two prolog data bases seperately. If I
consult them, swi mixes both the files.
If I have to use the technique as suggested in
http://code.google.com/p/pyswip/wiki/HowToSimulateMultipleKnowledgebases,
it does not accept 'rules'.
In prolog consulting, I tried to kill the prolog session by issuing
the query 'halt'. But after that I could not start a new session using
Prolog().
For example:
----------------
prolog = Prolog()
rr = 'halt'
res = list(prolog.query(rr))

prolog2 = Prolog() # Now won't start a new session

Could you suggest any work around or trick to overcome these problems?

BTW, in the example at http://code.google.com/p/pyswip/wiki/HowToSimulateMultipleKnowledgebases
I get error when I execute it (in 64-bit linux)
To make it run, I have to change the following line (and other similar
lines)
call(assertz(parent("john", "bob")), test1)
to
call(assertz(parent("john", "bob")), module=test1)

Could you please check and correct the example?

Cheers,
Sandeep

yuce

unread,
Oct 5, 2009, 8:34:35 PM10/5/09
to pyswip

You can enter rules using the "classic" interface to SWI-Prolog, you
can also use modules; the following example uses a module called
"test":

>>> from pyswip import Prolog
>>> p = Prolog()
>>> p.assertz('test:a(z)')
>>> p.assertz('test:b(z)')
>>> p.assertz('test:(c(X):-a(X),b(X))')
>>> list(p.query('test:c(X)'))
[{'X': 'z'}]

I hope that helps,

Best wishes,

Yuce



On Oct 5, 4:28 pm, dksr <dksre...@gmail.com> wrote:
> Hi yuce,
>
> > There is an example about that at the bottom of:http://code.google.com/p/pyswip/,
>
> The examples you have provided are for 'facts' not for 'rules'.
> Actually, my problem is to use two prolog data bases seperately. If I
> consult them, swi mixes both the files.
> If I have to use the technique as suggested inhttp://code.google.com/p/pyswip/wiki/HowToSimulateMultipleKnowledgebases,
> it does not accept 'rules'.
> In prolog consulting, I tried to kill the prolog session by issuing
> the query 'halt'. But after that I could not start a new session using
> Prolog().
> For example:
> ----------------
> prolog = Prolog()
> rr = 'halt'
> res = list(prolog.query(rr))
>
> prolog2 = Prolog()  # Now won't start a new session
>
> Could you suggest any work around or trick to overcome these problems?
>
> BTW, in the example athttp://code.google.com/p/pyswip/wiki/HowToSimulateMultipleKnowledgebases

dksr

unread,
Oct 6, 2009, 8:32:10 AM10/6/09
to pyswip
Hi Yuce,
This is what I was looking for :-)
Thanks very much. Sorry for bothering as I did not find the above
example anywhere in the site.

Cheers,
Sandeep

yuce

unread,
Oct 6, 2009, 5:14:45 PM10/6/09
to pyswip

I'm glad I could help. I will be adding the same example to the site.

Best wishes,

Yuce
Reply all
Reply to author
Forward
0 new messages