How to match input text with rules in p.query?

71 views
Skip to first unread message

Yoga Perdana Sasmita

unread,
Feb 6, 2015, 10:39:13 AM2/6/15
to pys...@googlegroups.com
First i input like this in the text box using wx.python:

participant(client)
participant(server)
key(kcs)
message(mes)
believes(client, shared(client, server, kcs))
believes(server, shared(client, server, kcs))
sees(server, encrypted(mes, kcs))
sees(client, encrypted(mes, kcs))

Then, i want to match that input text with the rules that I have in another file:

        p.assertz("believes(A, said(B, X)):- participant(A), participant(B), A\=B, key(K), message(X), believes(A, shared(A, B, K)), sees(A, encrypted(X, K))")
        p.assertz("believes(A, said(B, X)):- participant(A), participant(B), A\=B, key(K), message(X), believes(A, public(B, K)), sees(A, encrypted(X, K))")
        p.assertz("believes(A, believes(B, X)):- participant(A), participant(B), A\=B, message(X), believes(A, fresh(X)), believes(A, said(B, X))")
        p.assertz("believes(A, X):- participant(A), participant(B), A\=B, message(X), believes(A, controls(B, X)), believes(A, believes(B, X))")
        p.assertz("believes(A, [X, Y]):- message(X), message(Y), X\=Y, participant(A), believes(A, X), believes(A, Y)")
        p.assertz("believes(A, Y):- message(X), participant(A), member(Y, X), X\=Y, believes(A, X)")
        p.assertz("believes(A, believes(B, Y)):- message(X), participant(A), participant(B), member(Y, X), X\=Y, believes(A, believes(B, X))")
        p.assertz("believes(A, said(B, Y)):- message(X), participant(A), participant(B), member(Y, X), X\=Y, believes(A, said(B, X))")
        p.assertz("believes(A, fresh([X, Y])):- message(X), message(Y), X\=Y, participant(A), believes(A, fresh(X))")
        p.assertz("sees(A, Y):- message(X), participant(A), member(Y, X), X\=Y, sees(A, X)")
        p.assertz("sees(A, X):- message(X), participant(A), participant(B), A\=B, believes(A, share(A, B, K)), sees(encrypted(X, K))")
        p.assertz("sees(A, X):- message(X), participant(A), participant(B), A\=B, believes(A, public(B, K)), sees(encrypted(X, K))")
        p.assertz("believes(A, shared(A,B,K)):- participant(A), participant(B), key(K), A\=B, believes(A, shared(B,A,K))")
        p.assertz("believes(A, believes(B,shared(A,B,K))):- participant(A), participant(B), key(K), A\=B, believes(A, believes(B,shared(B,A,K)))")

I match it using iteration like this :

try:
     for pquery in p.query("believes(A, said(B, X))"):
            print pquery
            pquery["A"], " believes ", pquery["B"], " believes ", pquery["X"]
                if i >= 1:
                    print "true"
                else:
                    print "false"
except:
      print("False")

Iteration = rules, i have 14 rules, so i have 14 iterations

But when i run the program i get False answer, did i miss something in iteration?because i expect on true answer from the iterations. Need Help. Thank you very much.


Rodrigo Starr

unread,
Feb 9, 2015, 9:52:54 PM2/9/15
to pys...@googlegroups.com
Are you sure you are asserting the data you put in the text box?

(also, I am considering your iteration code is just a sketch...)

best regards,
Rodrigo
--
You received this message because you are subscribed to the Google Groups "pyswip" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyswip+un...@googlegroups.com.
To post to this group, send email to pys...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyswip.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages