Jump to content
Sign in to follow this  
theguy0000

not reading AIML correctly

Recommended Posts

theguy0000

ok, I am making a bot.

it should read brain.aiml, which is in the language AIML, which is essentially XML.

here is aiml.au3, which is what gets run:

XML.au3:

I did have this brain.aiml file:

<aiml>
    <botinfo>
        <name>MyBot</name>
        <unknown>I'm Sorry. I did not understand what you said. Please try again.</unknown>
    </botinfo>
    
    <category>
        <pattern>hello</pattern>
        <template>Hi there!</template>
    </category>
    
    <category>
        <pattern>What is your name?</pattern>
        <template>I am &botname;. Who are you?</template>
    </category>
</aiml>

All working well, the bot responds as it should.

Then, I added this after the last <category> and before </aiml>

<category>
        <pattern>I am Matt</pattern>
        <template>Hello, Master.</template>
    </category>

Well, the bot still recognizes the first two <pattern>s and responds to them correctly. But, when I say the third pattern, I am Matt, it does not recognize it and defaults out to the $unknown_response. I have it _ArrayDisplay both $patterns and $templates. EVERYTHING IS RIGHT, the third pattern and template is in there correctly, yet the bot does not recognize it.

I am convinced that the problem is in my __ArraySearchWithWildcards function. But where?

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites
greenmachine

Here, I fixed it.

The problem was that you had _arraymaxindex instead of ubound (array) - 1. I also combined the array and xml udfs into 1 file, since you used some array functions in the xml.au3.

XML.au3aiml.au3

Share this post


Link to post
Share on other sites
theguy0000

wow, thanks!


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites
theguy0000

oh wait...it still does not recognize wildcards...


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites
theguy0000

anyone? :lmao:


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites
greenmachine

What do you mean about the wildcards? Anything super specific I can target?

Share this post


Link to post
Share on other sites
theguy0000

I need to be able to search arrays with wildcards...

so, the array contains "My name is *, what is yours", and it would come up with a match if you _ArraySearched For "My name is Matt, what is yours?"


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites
greenmachine

Without looking at the code again, I have this idea:

When you get to the part with the wildcard, do StringInString for everything around the wildcard. Like in your example:

You _ArraySearch for "My name is Matt, what is yours?" and the code checks if your string contains "My name is " and ", what is yours" and if it does, returns the value.

That may or may not be followable.. I'll go try to write some code for it soon.

Hmm, now that I looked at it again, that seems to be what you're doing with the function. I'll test it some and see what's up.

Edited by greenmachine

Share this post


Link to post
Share on other sites
greenmachine

There we go, fixed it.

Global $TestArray[5] = ["hello", "my name is", "matt", "My name is *, what is yours", "what is yours"]

Func __ArraySearchWithWildcards ($array, $searchstring)
    If Not IsArray ($array) Then Return -2
    For $z = 0 To UBound ($array) - 1
        $string_split = StringSplit (StringStripWS ($array[$z], 3), "*")
        If $string_split[0] = 1 And StringInStr (StringStripWS ($searchstring, 3), $string_split[1]) Then
            If StringReplace (StringStripWS ($searchstring, 3), $string_split[1], "") = "" Then
                Return $z
            EndIf
        ElseIf $string_split[0] = 2 Then
            If StringInStr (StringStripWS ($searchstring, 3), $string_split[1]) And _ 
                StringInStr (StringStripWS($searchstring, 3), $string_split[2]) Then
                Return $z
            EndIf
        EndIf
    Next
    Return -1
EndFunc

MsgBox (0, "search", __ArraySearchWithWildcards ($TestArray, "My name is matt"))
MsgBox (0, "search", __ArraySearchWithWildcards ($TestArray, " My name is "))
MsgBox (0, "search", __ArraySearchWithWildcards ($TestArray, "what is yours"))
MsgBox (0, "search", __ArraySearchWithWildcards ($TestArray, "my name is matt, what is yours"))

Share this post


Link to post
Share on other sites
theguy0000

works almost great...A wildcard at the end would not match.

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites
greenmachine

This works, but since the wildcard at the end means that it could be anything, you have to put them last. (Notice how I switched the places in the TestArray).

Global $TestArray[5] = ["hello", "my name is *, what is yours", "matt", "My name is *", "what is yours"]

Func __ArraySearchWithWildcards ($array, $searchstring)
    If Not IsArray ($array) Then Return -2
    For $z = 0 To UBound ($array) - 1
        $string_split = StringSplit (StringStripWS ($array[$z], 3), "*")
        If $string_split[0] = 1 And StringInStr (StringStripWS ($searchstring, 3), $string_split[1]) Then
            If StringReplace (StringStripWS ($searchstring, 3), $string_split[1], "") = "" Then
                Return $z
            EndIf
        ElseIf $string_split[0] = 2 Then
            If StringInStr (StringStripWS ($searchstring, 3), $string_split[1]) And _ 
                StringInStr (StringStripWS($searchstring, 3), $string_split[2]) Then
                Return $z
            EndIf
            If $string_split[1] = "" And StringInStr (StringStripWS($searchstring, 3), $string_split[2]) Then
                Return $z
            EndIf
            If $string_split[2] = "" And StringInStr (StringStripWS($searchstring, 3), $string_split[1]) Then
                Return $z
            EndIf
        EndIf
    Next
    Return -1
EndFunc

MsgBox (0, "search", __ArraySearchWithWildcards ($TestArray, "my name is matt"))
MsgBox (0, "search", __ArraySearchWithWildcards ($TestArray, " My name is "))
MsgBox (0, "search", __ArraySearchWithWildcards ($TestArray, "what is yours"))
MsgBox (0, "search", __ArraySearchWithWildcards ($TestArray, "my name is matt, what is yours"))

Share this post


Link to post
Share on other sites
theguy0000

thank you so much! it works perfectly!


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×