How to get facts, variables using python-call

  • speleolinux

    speleolinux - 2007-11-16

    Hi all

    I have a clips session running as a UNIX daemon and communication with a cgi script using sockets.
    I can send questions from clips rules to the socket and read them from my cgi script.
    I can send answers from the cgi script (single characters from pushed buttons) to clips.

    Part of the CLIPs file is here:

    (defrule get-cell-type ""
        (sample-composition C)
        (python-call to_user "Is the sample Mammalian cells (M) or Plant (P) cells ?")
        (bind ?cell-type (python-call from_user))
        (assert (cell-type (upcase ?cell-type)))

    CLIPS asks a question and it's sent to the cgi (buttons are created by the cgi from the M & P).
    The user clips the M or P button and (python-call from_user) gets the answer.

    My Problem:
    1. What I need to do is get the list of facts (and rules) from clips to the cgi script.
    I have tried (python-call to_user (facts)) but (facts) does not return a string that to_user() can use. Clips just seems to exit. [Note: I can't use clips.Facts() from the cgi as the cgi only talks through sockets as the clips session is persistent and the cgi script is not. ]

    2. I also have a stack fact (stack A B C) and can't seem to get
    (python-call to_user $stack) to work either.

    Relevant parts of the python script which becomes the daemon is shown below.

    def to_user(data):
        # This sends data from CLIPS to a socket.
        data_length = connection.send(data)
        return data_length

    def from_user:
        # This reads a character from a socket into CLIPS.
        connection,addr = s.accept()
        answer = connection.recv(2028)
        return clips.Symbol(answer)

    some more code...

    • Francesco Garosi

      Hi Michael,

      probably I'll be repeating some of the things we've been discussing about by e-mail. However, after having dealt with this issue (and other ones) I ended up with RFE 1868029 ( which is now closed). My work on this request resulted in release 1.0.6 which, among other things, behaves in a way that should help you solve this particular case: actually, while you can't pass "(facts)" to a "python-call" function - just because "(facts)" does not return a result, but only prints the list of facts on PyCLIPS clips.StdoutStream (that is, "stdout" in CLIPS) as a "side effect" - with PyCLIPS 1.0.6 you can use the fact functions (like "do-for-all-facts") in CLIPS to build a list of facts as a multifield (like your fact stack, I think) and pass it back to Python either as a result of something like Eval() or via "python-call".

      Please, if you have time to test it, I'd appreciate any feedback.


      • Francesco Garosi

        By the way, I just discovered that it's 2012 now! Happy New (future) Year!


      • speleolinux

        speleolinux - 2008-01-25

        Hi Franz

        Thanks for this work. I have just downloaded svn 295 and will have a play with it. I browsed over the svn diffs at sourceforge and its looks pretty complicated. I hope others will also get benefit from these enhancements.
        I have been off on annual leave for a month and about to go to the Linux Conf 2009 in Melbourne for all next week so it will be some time before I can get back about this. Again thanks.

        Best wishes


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks