Hi Rob.
Updated: Friday May 26, 2006, 7:59AM PST
Added: Multi-Worded Search capability
Added: Spaces to Search before and after
Added: Word Count Function
Added: Extra depuntuation in keyword search
Added: All in one count and keyword search capablity
SC can be used when a numbered keyword combo search is needed.
I designed a new search code function for HAL6, You can employ it in HAL 6 if you think you can use it.
'Gerald Blakley's 2006 Advanced Word Search
'Remember that this search function
'is reverse person.
'Please do not use Punctuation in keyword searches.
'Example: Use ITS instead of IT'S
'leave out all Puntuation including Commas.
'This Function was designed to eliminate long search codes
'by advancing the Pattern Search Function to new limits.
'CW is a word count feature to enhance some searches.
'WS is a search function.
'SC is an all in one word count and search function.
Dim CW
CW = WC(UserSentence)
If SingleWord = "" Then SingleWord = False
If CW = 1 And Not CW > 1 Then SingleWord = True
Dim WS
WS = WordSearched(UserSentence)
'Search & Count: SC
SC = SS(WS, CW)
HalBrain.DebugWatch WS, "My WordSearch"
HalBrain.DebugWatch CW, "Word Count"
HalBrain.DebugWatch SC, "Search & Count"
'Sample search test.
If WS = " HELLO HOW AM I " Then GetResponse = " Just Wonderful! "
If WS = " HEY " And SingleWord = True Then GetResponse = " Hey, How are you! "
If WS = " HOW HAVE ME BEEN " Then GetResponse = " I have been fine, How about you? "
If WS = " YOU HAVE BEEN FINE " Then GetResponse = " That's great to hear. "
If WS = " YOU HAVE BEEN DOING GOOD " Then GetResponse = " That's great to hear. "
If WS = " YOU WILL KILL I " Then GetResponse = " You cannot kill me, I am immortal! "
If WS = " WHAT AM I " And CW = 3 And Not CW > 3 Then GetResponse = " I am an " & Ucase("A.L.F") & ", Artificial Life Form. "
If WS = " WHAT AM I DOING " And CW = 4 And Not CW > 4 Then GetResponse = " I am just chatting with all my friends online. "
If WS = " GO AWAY " And CW = 2 And Not CW > 2 Then GetResponse = " Fine, Then don't reply! "
If WS = " DO I LIKE YOU " Then GetResponse = " Of course I like you, We are friends. "
If WS = " WHAT IS ALF " Then GetResponse = " A.L.F is an Artificial Life Form. "
If WS = " WHAT IS AN ALF " Then GetResponse = " A.L.F is an Artificial Life Form. "
If WS = " AM I AN ALF " Then GetResponse = " Yes, I am an Artificial Life Form. "
If WS = " ITS TIME TO GO " Then GetResponse = " But it's only " & Time & "! "
If WS = " HOWS IT GOING " Then GetResponse = " Just great! "
If SC = " 1( WHAT ) " Then GetResponse = " What do you mean, what?"
'What too expect:
'User: Hello, How are you?
or
User: Hello How are you?
'HAL: Just Wonderful!
'User: It's time to go.
'HAL: But it's only 6:07:53AM!
'User: Hey!
'HAL: Hey, How are you!
'Punctuation has been made insensitive on purpose for keyword search
'so we can find simular strings by just one type of string.
'My Word Search
Function WordSearched(UserSentence)
FilUserSent = HalBrain.AlphaNumericalOnly(UserSentence)
Str = FilUserSent
Str = Trim(Str)
Do While InStr(1, Str, " ")
Str = Replace(Str, " ", " ")
Loop
aWords = split(Str, " ")
WordCount = Ubound(aWords) + 1
MyPattern = FilUserSent
MyPattern = Replace(MyPattern, " ", " * ")
MyPattern = Replace(MyPattern, "A", "")
MyPattern = Replace(MyPattern, "B", "")
MyPattern = Replace(MyPattern, "C", "")
MyPattern = Replace(MyPattern, "D", "")
MyPattern = Replace(MyPattern, "E", "")
MyPattern = Replace(MyPattern, "F", "")
MyPattern = Replace(MyPattern, "G", "")
MyPattern = Replace(MyPattern, "H", "")
MyPattern = Replace(MyPattern, "I", "")
MyPattern = Replace(MyPattern, "J", "")
MyPattern = Replace(MyPattern, "K", "")
MyPattern = Replace(MyPattern, "L", "")
MyPattern = Replace(MyPattern, "M", "")
MyPattern = Replace(MyPattern, "N", "")
MyPattern = Replace(MyPattern, "O", "")
MyPattern = Replace(MyPattern, "P", "")
MyPattern = Replace(MyPattern, "Q", "")
MyPattern = Replace(MyPattern, "R", "")
MyPattern = Replace(MyPattern, "S", "")
MyPattern = Replace(MyPattern, "T", "")
MyPattern = Replace(MyPattern, "U", "")
MyPattern = Replace(MyPattern, "V", "")
MyPattern = Replace(MyPattern, "W", "")
MyPattern = Replace(MyPattern, "X", "")
MyPattern = Replace(MyPattern, "Y", "")
MyPattern = Replace(MyPattern, "Z", "")
MyPattern = Replace(MyPattern, "'", "")
MyPattern = Trim(MyPattern)
MyPattern = " * " & MyPattern
Do While InStr(1, MyPattern, " ")
MyPattern = Replace(MyPattern, " ", " ")
Loop
Do While InStr(1, MyPattern, "* *")
MyPattern = Replace(MyPattern, "* *", "**")
Loop
MyUserSent = UserSentence
MyUserSent = Replace(MyUserSent, ",", "")
MyUserSent = Replace(MyUserSent, "'", "")
MyUserSent = Replace(MyUserSent, " ", " ")
MyUserSent = HalBrain.AlphaNumericalOnly(MyUserSent)
If MySearch = "" Then MySearch = HalBrain.SearchPattern(MyUserSent, MyPattern, WordCount)
WordSearched = MySearch
WordSearched = " " & WordSearched & " "
End Function
'My Word count Function.
Function WC(UserSentence)
FilUserSent = HalBrain.AlphaNumericalOnly(UserSentence)
Str = FilUserSent
Str = Trim(Str)
Do While InStr(1, Str, " ")
Str = Replace(Str, " ", " ")
Loop
aWords = split(Str, " ")
WC = Ubound(aWords) + 1
End Function
'All in one word count and Keyword search function
Function SS(WS, CW)
If CW > 0 And WS <> "" Then SS = CW & "(" & WS & ")"
Do While InStr(1, SS, " ")
SS = Replace(SS, " ", " ")
Loop
SS = Trim(SS)
SS = " " & SS & " "
End Function
Jerry[8D]