1

I'm trying to make an AI chatbot using Android Studio which is supposed to use a Python core. I learnt how to run Python scripts in Android Studio using Chaquopy but when I run my .py file which imports theaiml library, there's always a "No match found for input" error. Here's my code for the file home.py which I'm running in Android Studio using Chaquopy:

import aiml

kernel = aiml.Kernel()
kernel.learn("std_startup.xml")
kernel.respond("load aiml b")

def response(message):
    res = kernel.respond(message)
    if res is None or res=="":
        return "Sorry"
    else:
        return res

This is std_startup.xml

<aiml version="2.0" encoding="UTF-8">
<category>
    <pattern>LOAD AIML B</pattern>
    <template>
        <learn>basic_chat.xml</learn>
    </template>
</category>
</aiml>

This is basic_chat.xml

<aiml version="2.0" encoding="UTF-8">
<category>
        <pattern>HELLO</pattern>
        <template>
            <random>
                <li>Hey there!</li>
                <li>H1!</li>
                <li>Hello!</li>
            </random>
        </template>
    </category>    
</aiml>

The code in the Android project activity is:

    if (!Python.isStarted()) {
                 Python.start(new AndroidPlatform(this));
    }
    Python python = Python.getInstance();
    PyObject pythonFile = python.getModule("home");
    PyObject response = pythonFile.callAttr("response", message.toString());
    button.setText(response.toString());

All files are in the same directory. Chaquopy worked perfectly for simple python programs and home.py worked fine when I was running it on cmd. I've tried changing the .xml to .aiml in the code but it still doesn't work. I also tried changing the aiml version. What am I doing wrong? Or does Chaquopy just not support AIML? Please suggest any changes

ank266
  • 31
  • 2

2 Answers2

0

The current directory of an Android app could be anywhere, but it's unlikely to be the directory containing your data files. So instead of passing std_startup.xml with a simple filename, use a path relative to __file__, as described in the FAQ.

I don't know how filenames within std_startup.xml are evaluated. If they're relative to the location of the std_startup.xml file, then your current approach should work fine. If they're relative to the current directory, then you may need to generate the std_startup.xml file programmatically so it can contain the absolute path to basic_chat.xml.

mhsmith
  • 6,675
  • 3
  • 41
  • 58
-1

Try directly learning the basic.aiml file. And change extension to .aiml