2

I am using alice 2 aiml chatbot in android. My need is to be able to invoke certain methods when certain questions are asked by the users to return the answer after a few calculations. I followed this question posted earlier in the exact same domain but failed to understand the implementation of aimlprocessorextension and desperately need some sort of exemplar implementation of it for things such as making call or even just showing an alertbox on certain msg by the user.

Please help.

Dev_Man
  • 847
  • 1
  • 10
  • 28
  • hi.. did you solved this issue ? – Jugi Sep 21 '17 at 09:49
  • @Jugi Yes. but I solved it in a very crude manner. So what I did was add a # symbol in front of the replies in aiml for which i needed to invoke a certain function. If the # was detected by the java code (using split method) then the particular function was invoked using a switch case. I can also show my aiml files in case have a doubt. – Dev_Man Sep 21 '17 at 13:30
  • thank you. I have found a solution for this using AIMLProcessorExtension. i will share my answer in the post. Meanwhile please share your implementation to know how you have resolved this. – Jugi Sep 22 '17 at 08:15

1 Answers1

1

This is what i did to solve the issue from java side. Create a class which implements the AIMLProcessorExtension. The class will look something like below,

public class TestAIMLExtenstion implements AIMLProcessorExtension
{
    public Set<String> extensionTagNames = Utilities.stringSet("contactid","multipleids","displayname","dialnumber","emailaddress","contactbirthday","addinfo");
    public Set <String> extensionTagSet() {
        return extensionTagNames;
    }

public String recursEval(Node node, ParseState ps) {
        try {
            String nodeName = node.getNodeName();
            if (nodeName.equals("contactid"))
                return contactId(node, ps);
            else if (nodeName.equals("multipleids"))
                return multipleIds(node, ps);
            else if (nodeName.equals("dialnumber"))
                return dialNumber(node, ps);
            else if (nodeName.equals("addinfo"))
                return newContact(node, ps);
            else if (nodeName.equals("displayname"))
                return displayName(node, ps);
            else if (nodeName.equals("emailaddress"))
                return emailAddress(node, ps);
            else if (nodeName.equals("contactbirthday"))
                return contactBirthday(node, ps) ;
            else return (AIMLProcessor.genericXML(node, ps));
        } catch (Exception ex) {
            ex.printStackTrace();
            return "";
        }
    }
}

And in my main class i have added something like,

AIMLProcessor.extension =  new TestAIMLExtenstion();

I have done m implementation using the above approach.

Jugi
  • 1,244
  • 3
  • 23
  • 51
  • This was there in the docs for aiml but i wasnt able to implement it as it somehow didnt seem to match my requirement. Maybe this is better . Thanks for sharing! +1 – Dev_Man Sep 22 '17 at 14:06