keiffster / program-y

Python 3.x based AIML 2.0 Chatbot interpreter, framework, related programs and knowledge files
https://keiffster.github.io/program-y/
Other
350 stars 135 forks source link

'That' tag not working in the case srai to other pattern #151

Closed buinguyen closed 6 years ago

buinguyen commented 6 years ago

I tested with some cases on Ubuntu but it seems 'that' tag did not work in the case srai to other pattern.

Expected Behavior

That tag should work normally.

Hi -> Hello. Do you know explore the website? Yes -> The website was created in 2014.

Current Behavior

'That' pattern gets default value [*]

Hi -> Hello. Do you know explore the website? Yes -> Test pattern: AGREEMENT

Possible Solution

The function get_that_pattern() in programy/dialog.py I think the code: that_question = self.previous_nth_question(1) not working properly in this case.

Steps to Reproduce

Run my aiml code:

<category>
    <pattern>Yes</pattern>
    <template><srai>AGREEMENT</srai></template>
</category>

<category>
    <pattern>OK</pattern>
    <template><srai>AGREEMENT</srai></template>
</category>

<category>
    <pattern>No</pattern>
    <template><srai>DISAGREEMENT</srai></template>
</category>

<category>
    <pattern>Hi</pattern>
    <template><srai>GREETINGS</srai></template>
</category>

<category>
    <pattern>GREETINGS</pattern>
    <template>Hello. Do you know explore the website?</template>
</category>

<category>
    <pattern>AGREEMENT</pattern>
    <that>Do you know explore the website</that>
    <template>The website was created in 2014.</template>
</category>

<category>
    <pattern>AGREEMENT</pattern>
    <template>Test pattern: AGREEMENT</template>
</category>

<category>
    <pattern>DISAGREEMENT</pattern>
    <that>Do you know explore the website</that>
    <template>Disagreement with that pattern.</template>
</category>

<category>
    <pattern>DISAGREEMENT</pattern>
    <template>Test pattern: DISAGREEMENT</template>
</category>

Context (Environment)

Possible Implementation

The function get_that_pattern() in programy/dialog.py I change the code: that_question = self.previous_nth_question(1) I got previous question until response of that question is not None. This is my opinion.

Hope you check this issue. Many thanks!

keiffster commented 6 years ago

You need to convert you content to upper case, e.g

AGREEMENT DO YOU KNOW EXPLORE THE WEBSITE
buinguyen commented 6 years ago

Thank you for your guide. I tried to convert to upper case but it's not working. I still guess that the function get_that_pattern() has any problems.

Thanks!

keiffster commented 6 years ago

Ok let me take a look over the weekend and work out what is happening

I’ll had your aiml to a unit test

K

keiffster commented 6 years ago

Huge shout out to @nguyenbnt for finding this rather unpleasant bug, fixed with supporting unit tests and pushed to master and pypi

buinguyen commented 6 years ago

Hello, I saw the change. But may be it's not thorough yet. You can test the bellow case:


<category>
    <pattern>Hi</pattern>
    <template><srai>GREETINGS</srai></template>
</category>
<category>
    <pattern>GREETINGS</pattern>
    <template>
        <random>
        <li>Hello. Do you know explore the website?</li>
        <li>Good day. Do you know explore the website?</li>
        </random>
    </template>
</category>
<category>
    <pattern>Yes</pattern>
    <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
    <template><srai>AGREEMENT</srai></template>
</category>
<category>
    <pattern>AGREEMENT</pattern>
    <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
    <template><srai>GROUPAGREEMENT</srai></template>
</category>
<category>
    <pattern>GROUPAGREEMENT</pattern>
    <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
    <template>The website was created in 2014.</template>
</category>
<category>
    <pattern>GROUPAGREEMENT</pattern>
    <template>Default AGREEMENT</template>
</category>
<category>
<pattern>No</pattern>
    <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
    <template><srai>DISAGREEMENT</srai></template>
</category>
<category>
    <pattern>DISAGREEMENT</pattern>
    <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
    <template><srai>GROUPDISAGREEMENT</srai></template>
</category>
<category>
    <pattern>GROUPDISAGREEMENT</pattern>
    <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
    <template>Disagreement with that pattern.</template>
</category>
<category>
    <pattern>GROUPDISAGREEMENT</pattern>
    <template>Default DISAGREEMENT</template>
</category>

Input: Hi -> Yes Expected: The website was created in 2014.

Best Rg, Nguyen

keiffster commented 6 years ago

You have too many that elements. You only need that in the first statement to capture the conditional Yes/No, afterwards its better practice and more efficient to keep the statements free of that

I have kept your original AIML but commented out below the unnecessary <that> tags

    <category>
        <pattern>Hi</pattern>
        <template>
            <srai>GREETINGS</srai>
        </template>
    </category>
    <category>
        <pattern>GREETINGS</pattern>
        <template>
            <random>
                <li>Hello. Do you know explore the website?</li>
                <li>Good day. Do you know explore the website?</li>
            </random>
        </template>
    </category>
    <category>
        <pattern>Yes</pattern>
        <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
        <template>
            <srai>AGREEMENT</srai>
        </template>
    </category>
    <category>
        <pattern>AGREEMENT</pattern>
        <!-- <that>DO YOU KNOW EXPLORE THE WEBSITE</that> -->
        <template>
            <srai>GROUPAGREEMENT</srai>
        </template>
    </category>
    <category>
        <pattern>GROUPAGREEMENT</pattern>
        <!-- <that>DO YOU KNOW EXPLORE THE WEBSITE</that> -->
        <template>The website was created in 2014.</template>
    </category>
    <category>
        <pattern>GROUPAGREEMENT</pattern>
        <template>Default AGREEMENT</template>
    </category>
    <category>
        <pattern>No</pattern>
        <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
        <template>
            <srai>DISAGREEMENT</srai>
        </template>
    </category>
    <category>
        <pattern>DISAGREEMENT</pattern>
        <!-- <that>DO YOU KNOW EXPLORE THE WEBSITE</that> -->
        <template>
            <srai>GROUPDISAGREEMENT</srai>
        </template>
    </category>
    <category>
        <pattern>GROUPDISAGREEMENT</pattern>
        <!-- <that>DO YOU KNOW EXPLORE THE WEBSITE</that> -->
        <template>Disagreement with that pattern.</template>
    </category>
    <category>
        <pattern>GROUPDISAGREEMENT</pattern>
        <template>Default DISAGREEMENT</template>
    </category>
buinguyen commented 6 years ago

Ok. I know. In this case, it's unnecessary. Above case is an example for testing. However, in fact, the case which has some patterns with 'that' tag still may occur.

keiffster commented 6 years ago

Thanks for the grammar, I added it to the unittests and updated the code to make it compatible

New version just pushed to master

askalee commented 6 years ago

Hi, after reading the above comments and doing some experiments, I am a bit confused about how tag should be used in a srai chain.

I have tried keiffster's version of AIML from the above comment, in which only the first tag is kept in a srai chain. However, it doesn't work as expected on https://home.pandorabots.com. The result is:

Input: Hi Output: Hello. Do you know explore the website? Input: yes Output: Default AGREEMENT

I think the expected response of the last one should be "The website was created in 2014."

When tag is moved to the end of a srai chain, it works as expected. The AIML that produces the expected result:

<category>
        <pattern>Hi</pattern>
        <template>
            <srai>GREETINGS</srai>
        </template>
    </category>
    <category>
        <pattern>GREETINGS</pattern>
        <template>
            <random>
                <li>Hello. Do you know explore the website?</li>
                <li>Good day. Do you know explore the website?</li>
            </random>
        </template>
    </category>
    <category>
        <pattern>Yes</pattern>
        <!-- <that>DO YOU KNOW EXPLORE THE WEBSITE</that> -->
        <template>
            <srai>AGREEMENT</srai>
        </template>
    </category>
    <category>
        <pattern>AGREEMENT</pattern>
        <!-- <that>DO YOU KNOW EXPLORE THE WEBSITE</that> -->
        <template>
            <srai>GROUPAGREEMENT</srai>
        </template>
    </category>
    <category>
        <pattern>GROUPAGREEMENT</pattern>
        <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
        <template>The website was created in 2014.</template>
    </category>
    <category>
        <pattern>GROUPAGREEMENT</pattern>
        <template>Default AGREEMENT</template>
    </category>
    <category>
        <pattern>No</pattern>
        <!-- <that>DO YOU KNOW EXPLORE THE WEBSITE</that> -->
        <template>
            <srai>DISAGREEMENT</srai>
        </template>
    </category>
    <category>
        <pattern>DISAGREEMENT</pattern>
        <!-- <that>DO YOU KNOW EXPLORE THE WEBSITE</that> -->
        <template>
            <srai>GROUPDISAGREEMENT</srai>
        </template>
    </category>
    <category>
        <pattern>GROUPDISAGREEMENT</pattern>
        <that>DO YOU KNOW EXPLORE THE WEBSITE</that>
        <template>Disagreement with that pattern.</template>
    </category>
    <category>
        <pattern>GROUPDISAGREEMENT</pattern>
        <template>Default DISAGREEMENT</template>
    </category>

Input: hi Output: Hello. Do you know explore the website? Input: yes Output: The website was created in 2014.

Which one is the suggested and efficient way to use tag in a srai chain?

askalee commented 6 years ago

Hi guys, please ignore my last comment. Sorry that I didn't notice that there are duplicate "GROUPAGREEMENT" pattern in the AIML. After removing the duplicate, the AIML works as expected on both Pandorabots site and the newest programy.

keiffster commented 6 years ago

That’s great news