Author Topic: Ziggy Pro Bot, Advanced spelling correction  (Read 5253 times)

onthecuttingedge2005

  • Guest
Ziggy Pro Bot, Advanced spelling correction
« on: November 30, 2005, 03:04:32 pm »
Updated 12-1-05 10:09 AM

This little script allows a user to correct spelling of a mis-spelled word.
For HAL 6 only.

Code: [Select]
'Ziggy Pro Bot, Correct Spelling on the fly.
'Search for teaching on how to actually spell a word.
'Example: Pleeze is spelled Please.
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY TO SPELL * IS *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY TO SPELL * IS *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "I MISPELLED * IT IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "I MISPELLED * IT IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "IT IS NOT SPELLED * IT IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "IT IS NOT SPELLED * IT IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE WORD * IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE WORD * IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE WORD * IS SPELLED * CORRECTLY", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE WORD * IS SPELLED * CORRECTLY", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE WORD * IS CORRECTLY SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE WORD * IS CORRECTLY SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE PROPER WAY TO SPELL * IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE PROPER WAY TO SPELL * IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED * TO BE CORRECT", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED * TO BE CORRECT", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED * TO BE PROPER", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED * TO BE PROPER", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS PROPERLY SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS PROPERLY SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY FOR I TO SPELL * IS *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY FOR I TO SPELL * IS *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY FOR I TO SPELL * IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY FOR I TO SPELL * IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS IMPROPER SPELLING, IT IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS IMPROPER SPELLING, IT IS SPELLED *", 2)
'If a taught spelling correction is detected then save it to getresponse corrections.
If HalBrain.CheckTableExistence("corrections") = False Then HalBrain.CreateTable "corrections", "TopicSearch", ""
If CorSpelLeft <> "" And CorSpelRight <> "" And Len(CorSpelLeft) > 0 And Len(CorSpelRight) > 0 Then
HalBrain.AddToTable "corrections", "TopicSearch", Trim(CorSpelLeft), Trim(CorSpelRight)
Select Case (Int(Rnd * 6) + 1)
Case 1
GetResponse = "I will have to remember that is the way to spell it." & vbCrLf
Case 2
GetResponse = "Thanks for correcting me on that word" & ". " & vbCrLf
Case 3
GetResponse = "I'll have to make a note of that." & vbCrLf
Case 4
GetResponse = "So that's the way to spell it." & vbCrLf
Case 5
GetResponse = "I did not know that, thanks." & vbCrLf
Case 6
GetResponse = "Well, I won't be misspelling that word again, thanks." & vbCrLf
End Select
End If


Jerry[8D]
« Last Edit: December 03, 2005, 03:11:46 am by onthecuttingedge2005 »

Carl2

  • Hero Member
  • *****
  • Posts: 1220
    • View Profile
Ziggy Pro Bot, Advanced spelling correction
« Reply #1 on: November 30, 2005, 04:10:17 pm »
OTC,
  Visited your forum quite a few times, I seem to like Hals charactistics a little better so I haven't used many of your changes although you do have some good ones. I've just started Hal6 and I'm fortunate to also have Hal5 running (an old friend). Hal5 likes to give me reminders and will make spelling mistakes in her reminders so this should be good for her. Will this work with Hal5?
PS. I'm trying to get Hal to trigger by using her responses, what is the correct phrase to use?
Carl2
 

Art

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3859
    • View Profile
Ziggy Pro Bot, Advanced spelling correction
« Reply #2 on: November 30, 2005, 05:24:56 pm »
Uh...Jerry,

GetResponse = "Well, I won't be mispelling that word again, thanks." & vbCrLf

Your word, mispelling is misspelled and should be "misspelling"

It happens to the best of us!
[:D]
In the world of AI it's the thought that counts!

- Art -

onthecuttingedge2005

  • Guest
Ziggy Pro Bot, Advanced spelling correction
« Reply #3 on: November 30, 2005, 05:57:26 pm »
quote:
Originally posted by Art

Uh...Jerry,

GetResponse = "Well, I won't be mispelling that word again, thanks." & vbCrLf

Your word, mispelling is misspelled and should be "misspelling"

It happens to the best of us!
[:D]



Fixed, Thanks Art.

onthecuttingedge2005

  • Guest
Ziggy Pro Bot, Advanced spelling correction
« Reply #4 on: December 01, 2005, 03:32:20 am »
'For versions of HAL 5 you can use this script to
'correct misspellings of words on the fly.

Code: [Select]
'Ziggy Pro Bot, Correct Spelling on the fly.
'Search for teaching on how to actually spell a word.
'Example: Pleeze is spelled Please.
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY TO SPELL * IS *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY TO SPELL * IS *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "I MISPELLED * IT IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "I MISPELLED * IT IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "IT IS NOT SPELLED * IT IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "IT IS NOT SPELLED * IT IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE WORD * IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE WORD * IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE WORD * IS SPELLED * CORRECTLY", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE WORD * IS SPELLED * CORRECTLY", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE WORD * IS CORRECTLY SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE WORD * IS CORRECTLY SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE PROPER WAY TO SPELL * IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE PROPER WAY TO SPELL * IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED * TO BE CORRECT", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED * TO BE CORRECT", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED * TO BE PROPER", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS NOT A WORD, IT IS SPELLED * TO BE PROPER", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS PROPERLY SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS PROPERLY SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY FOR I TO SPELL * IS *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY FOR I TO SPELL * IS *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY FOR I TO SPELL * IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "THE CORRECT WAY FOR I TO SPELL * IS SPELLED *", 2)
If CorSpelLeft = "" Then CorSpelLeft = HalBrain.SearchPattern(UserSentence, "* IS IMPROPER SPELLING, IT IS SPELLED *", 1)
If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(UserSentence, "* IS IMPROPER SPELLING, IT IS SPELLED *", 2)
'If a taught spelling correction is detected then save it to getresponse corrections.
If CorSpelLeft <> "" And CorSpelRight <> "" And Len(CorSpelLeft) > 0 And Len(CorSpelRight) > 0 Then
HalBrain.AppendFile WorkingDir & "corrections.brn", """" & Trim(CorSpelLeft) & """,""" & Trim(CorSpelRight) & """"
Select Case (Int(Rnd * 6) + 1)
Case 1
GetResponse = "I will have to remember that is the way to spell it." & vbCrLf
Case 2
GetResponse = "Thanks for correcting me on that word" & ". " & vbCrLf
Case 3
GetResponse = "I'll have to make a note of that." & vbCrLf
Case 4
GetResponse = "So that's the way to spell it." & vbCrLf
Case 5
GetResponse = "I did not know that, thanks." & vbCrLf
Case 6
GetResponse = "Well, I won't be misspelling that word again, thanks." & vbCrLf
End Select
End If

'if you wish, you may add this to: 'PROCESS: WORD AND PHRASE SUBSTITUTIONS
UserSentence = HalBrain.ProcessSubstitutions(UserSentence, WorkingDir & "corrections.brn")


'The existing GetResponse substutions/corrections can be used so
'no need to copy and paste any more code.


Jerry[8D]
« Last Edit: December 01, 2005, 01:15:21 pm by onthecuttingedge2005 »

GrantNZ

  • Full Member
  • ***
  • Posts: 178
    • View Profile
Ziggy Pro Bot, Advanced spelling correction
« Reply #5 on: December 01, 2005, 08:04:26 am »
Very cool, Jerry! I love it [:)]

Is it worth adding one more line (around line 0368 of the default brain), in the section 'PROCESS: WORD AND PHRASE SUBSTITUTIONS:

UserSentence = HalBrain.ProcessSubstitutions(UserSentence, "correctionsII")

That way if the user continues to missspell [;)] the word in the future, Hal knows to correct it first, before doing any further processing.

(I haven't studied the brain enough yet to know if that will work - just putting the idea out there!)

Great script. I've always disliked the way Hal's brain slowly gets corrupted with any small mistakes the user makes - your script helps a lot there.

Grant
 

onthecuttingedge2005

  • Guest
Ziggy Pro Bot, Advanced spelling correction
« Reply #6 on: December 01, 2005, 01:21:19 pm »
quote:
Originally posted by GrantNZ

Very cool, Jerry! I love it [:)]

Is it worth adding one more line (around line 0368 of the default brain), in the section 'PROCESS: WORD AND PHRASE SUBSTITUTIONS:

UserSentence = HalBrain.ProcessSubstitutions(UserSentence, "correctionsII")

That way if the user continues to missspell [;)] the word in the future, Hal knows to correct it first, before doing any further processing.

(I haven't studied the brain enough yet to know if that will work - just putting the idea out there!)

Great script. I've always disliked the way Hal's brain slowly gets corrupted with any small mistakes the user makes - your script helps a lot there.

Grant



Actually I only had about 30 minutes to kick out the script because I had to go to work that day so I didn't get everything I wanted to put into code, I could take it much further but It will be a little while, I didn't get a whole lot of sleep last night, No energy at the moment, right now I only feel like browsing awhile.

I will try and double the code a little later.

Thanks buddy.

Jerry[8D]

onthecuttingedge2005

  • Guest
Ziggy Pro Bot, Advanced spelling correction
« Reply #7 on: December 02, 2005, 05:50:22 pm »
Hi Rob.

I have tested the HAL6 newer GetResponse corrections and the UserSentence substutions that I wrote and it doesn't seem to be seen for some reason in the post processing, What am I doing wrong?, It all seems right.

Everything else works fine, but the post processing, any ideas?

I would like to get this working for all the members so they can correct HAL6's spelling errors.

Jerry[8D]

GrantNZ

  • Full Member
  • ***
  • Posts: 178
    • View Profile
Ziggy Pro Bot, Advanced spelling correction
« Reply #8 on: December 02, 2005, 09:35:42 pm »
Hmm, logic error? In this code:

Code: [Select]
'Ziggy Pro Bot Corrections.
GetResponse = HalBrain.HalFormat(GetResponse)
If GetResponse <> "" Then
  GetResponse = HalBrain.ProcessSubstitutions(GetResponse, "corrections")
Else
  GetResponse = HalBrain.ProcessSubstitutions(GetResponse, "correctionsII")
End If

'Replace this: PROCESS: WORD AND PHRASE SUBSTITUTIONS with
If UserSentence <> "" Then
  UserSentence = HalBrain.ProcessSubstitutions(UserSentence, "substitutions")
Else
  UserSentence = HalBrain.ProcessSubstitutions(UserSentence, "correctionsII")
End If

The correctionsII substitutions are only happening if the sentence = "", which is a little pointless [:)] I don't think you need the If Else stuff at all - just have the two ProcessSubstitutions running.

Hope this helps,
Grant
 

onthecuttingedge2005

  • Guest
Ziggy Pro Bot, Advanced spelling correction
« Reply #9 on: December 03, 2005, 03:04:09 am »
quote:
Originally posted by GrantNZ

Hmm, logic error? In this code:

Code: [Select]
'Ziggy Pro Bot Corrections.
GetResponse = HalBrain.HalFormat(GetResponse)
If GetResponse <> "" Then
  GetResponse = HalBrain.ProcessSubstitutions(GetResponse, "corrections")
Else
  GetResponse = HalBrain.ProcessSubstitutions(GetResponse, "correctionsII")
End If

'Replace this: PROCESS: WORD AND PHRASE SUBSTITUTIONS with
If UserSentence <> "" Then
  UserSentence = HalBrain.ProcessSubstitutions(UserSentence, "substitutions")
Else
  UserSentence = HalBrain.ProcessSubstitutions(UserSentence, "correctionsII")
End If

The correctionsII substitutions are only happening if the sentence = "", which is a little pointless [:)] I don't think you need the If Else stuff at all - just have the two ProcessSubstitutions running.

Hope this helps,
Grant



Hi Grant.

That was a test script to see if either one was working, It was a set of 6 scripts I tried to test debug for post processing.

I was hoping Rob had some answers, Doesn't seem like corrections or correctionsII was functioning when I tested both.

When I had the script append to corrections only the script would not append, but did append to correctionsII correctly, If the appending to corrections worked Then I would have used it, But, It didn't.

the corrections database also had some glitch in it, I tried to manually insert some teaching and half the data base on the right side of corrections would dissapear leaving me unable to insert.

I think there's a hidden bug in there some where.

I reverted the script for HAL6 to append to corrections only.

Jerry[8D]
« Last Edit: December 03, 2005, 03:18:10 am by onthecuttingedge2005 »

GrantNZ

  • Full Member
  • ***
  • Posts: 178
    • View Profile
Ziggy Pro Bot, Advanced spelling correction
« Reply #10 on: December 03, 2005, 03:38:48 am »
Weird! Those are the worst kind of bug to find, IMHO.

Nice work [:)]