AIML - Parsing user inputs as variable to Python

1.4k Views Asked by At

I am working on an AIML project for leisure and came across pandorabots. I was wondering if there is a way to parse a variable from the user inputs into other languages (in this case python) or framework so that we can do further manipulation through other third party API by means of any templating?

For instance, I want to obtain a date from the user and then feed it into the google calendar API. Is there a way to extract the 'date' variable and parse it to google calendar API in Python (or any other languages)?

<category><pattern># 1 MAY 2016 #</pattern>
    <think>{{ date }}</think> #is there a way to parse "1 May 2016" as a 
                              #variable date in python? 
    <template>...
    </template>
</category>

Ultimately, the goal I am trying to achieve would have a conversation something like this:

User: Hi bot, could you check if I am available on 1 May 2016?
Bot: Nope, you have a gathering at Mike's! #(<--- Response rendered after 
                         checking user's schedule on 1 May via google calendar )

I explored templating engine like mustache but apparently it does not talk to AIML (or rather xml). Is there anyone who can point me to a good example/tutorial that can help me get started?

ps: I'm using pandorabots API and python2.7

2

There are 2 best solutions below

0
On

In the pyAIML API, look for the keyword "predicates":

  • kernel.getPredicate('date')
  • kernel.getBotPredicate('dat')

it returns the predicate that was set using

<set name="date"><star/></set>

Then you can easily parse it with python.

But that brings me closer to the question: what do I need AIML for? what's AIML's added value here?

1
On

I was also looking information for such similar question. With the help of the answer provided by @Berry Tsakala... I was able to find a solution to my problem. Here is a detailed and improved version of the above example case...that might be useful for others having the same question...

<category><pattern>Hi bot, could you check if I am available on *</pattern>
<template>Let me check your schedules on <set name="date"><star/></set>
</template>
</category>

Then in your python script you can store it into a variable as,

import aiml
kernel = aiml.Kernel()
kernel.learn("std-startup.xml")
kernel.respond("load aiml b")
while True:
    try:
        kernel.respond(raw_input("Enter your message >> "))
        appointment_date = kernel.getPredicate('date')
        print appointment_date

Feel free to make any corrections to the answer if you find any errors, or if it needs any improvements. Hope you find it useful :)