Jump to content

not reading AIML correctly


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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"))
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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"))
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...