'x=x=x=x=x=x=x=x==vonsmith==x=x=x=x=x=x=x=x=x 'In Ultra Hal Assistant v5.0 the "RESPOND: MAKE COMMENTS ABOUT SHORT PHRASES" ' function should precede this function. 'PROCESS: REVERSE CERTAIN CONTRACTIONS AND OTHER SUBSTITUTIONS 'This is the version entirely rewritten by =vonsmith= , version 11-10-03a. 'This function improves on the original function in Ultra Hal Assistant v5.0 and 'provides new capability. Just delete the entire original "PROCESS: REVERSE CERTAIN 'CONTRACTIONS AND OTHER SUBSTITUTIONS" in the hal5.uhp file and replace it with 'this script. Always back up the original hal5.uhp file!!! ' 'ORIGINAL CAPABILITY: 'Standardizing on contractions can make Hal sound conversational. 'However, certain sentence constructions don't work well if expressed as 'contractions. For example: '"I don't know where it is" becomes "I don't know where it's." 'For another example, "That's how he is" becomes "That's how he's." 'To solve these types of cases we attempt to modify certain contractions, words, 'and phrases at the end of this function, now that Hal's thinking is done. ' 'ADDITIONAL CAPABILITIES: 'Normally Hal converts every user input into all caps to evaluate the sentence 'and create a response. However if Hal parrots back the user input the user's 'capitalization is lost. Example: ' User: Where is Disneyland? Hal: Where is disneyland? We must examine this. 'Capitals in names of people and places are lost similarly. ' User: Do you know Ted and Mark? Hal: Should I know ted and mark? 'The programmer could edit the corrections.brn file to substitute Mark for mark 'in all cases, but this would erroneously lead to: ' User: How much should I fill a glass? Hal: Fill it to the Mark. ' 'This rewritten function will preserve the user's capitalized words in the input 'sentence and replace Hal's uncapitalized words in GetResponse with the correct 'user capitalized versions. Example: ' User: Where is Ted and Mark? Hal: I don't know Ted and Mark. 'Hal now takes a clue from the user about capitalization. ' User: Where is Ted's mark? Hal: Ted's mark is not here. ' User: I know ted and mark. Hal: Where is ted and mark. ' 'In cases where the user always wants a word capitalized, then Hal can save a 'word to the corrections.brn for the user. Example: ' User: Hal caps Disneyland. ' Hal: Your input Disneyland is saved as capitalized in the corrections brn file. 'If your Hal is named Betty instead type: ' User: Betty caps Saint Mary. ' Hal: Your input Saint Mary is saved as capitalized in the corrections brn file. 'Since Hal's computername appears in the user input this programming type input 'will not be saved to any other brn files or anywhere else in Hal's data base. 'Now for example: ' User: I hear Saint Mary's bells. Hal: What is Saint Mary's bells? 'However Hal still takes a clue from the user's input. ' User: I hear saint mary's bells. Hal: What is saint mary's bells? 'The phrase "saint mary's" is still lower case even if it is in the corrections.brn 'file. Hal always assumes the user's use of capitalization is correct. 'This method should produce the correct capitalization in almost every case. The 'programmer shouldn't add words like "Mark" or "Hall" to corrections.brn because 'these names can also be used as uncapitalized words. However words like "Fred", '"God", "Christmas", "Knott's Berry Farm" can be added with reasonable certainty 'that they should always be capitalized. You can add as many words to 'corrections.brn as you like. Duplicated words will not be added to the file. ' 'This function does not handle all capitalized words like acronyms, i.e., DOA, SUV. 'Unfortunately Hal's other functions do not preserve all cap words during the final 'processing of GetResponse. ' 'Have fun with this improved function. =vonsmith= ' 'P.S. - Try this. User: Where is Mark's mark? See if Hal gets it right. ' Dim WordArray, CapsWord(50) WordArray = Split(Trim(OriginalSentence), " ", -1, 1) 'WordArray() contains each word in sentence. ArraySize = UBound(WordArray) If ArraySize > 50 Then ArraySize = 50 'Limit array size to something manageable. 'Check all words in the user's input and preserve capitalized words in the CapsWord() array. 'Variable 'I' starts at 1 instead of zero and thus ignores the first word in the sentence ' since that will always be capitalized. CapsCnt = 0 For I = 1 To ArraySize WordArray(I) = HalBrain.AlphaNumericalOnly(trim(WordArray(I))) LeftChar = Left(WordArray(I), 1) If Len(LeftChar) = 0 Then LeftChar = " " If (Asc(LeftChar) > 64 And Asc(LeftChar) < 91) Then 'Check if first letter is capitalized. CapsCnt = CapsCnt + 1 CapsWord(CapsCnt) = WordArray(I) End If Next 'Check to see if the user wants to add a word or phrase to the corrections.brn file. If InStr(1, UserSentence, ComputerName & " CAPS " , vbTextCompare) > 0 Or InStr(1, UserSentence, ComputerName & " CAP " , vbTextCompare) > 0 Then CapPhrase = "" For I = 2 To ArraySize 'Format word or phrase. CapPhrase = CapPhrase & " " & WordArray(I) Next CapPhrase = Trim(CapPhrase) 'Check and see if capitalized word has been saved to corrections.brn before. Only save if doesn't exist there. If HalBrain.TopicSearch(" " & LCase(CapPhrase) & " ", WorkingDir & "corrections.brn") <> " " & CapPhrase & " " Then HalBrain.AppendFile WorkingDir & "corrections.brn", """" & " " & LCase(CapPhrase) & " " & """,""" & " " & CapPhrase & " " & """" HalBrain.AppendFile WorkingDir & "corrections.brn", """" & " " & LCase(CapPhrase) & "'" & """,""" & " " & CapPhrase & "'" & """" End If GetResponse = "Your input " & CapPhrase & " is saved as capitalized in the corrections brn file. " End If 'HalFormat the GetResponse to clean up a few things before proceeding. GetResponse = HalBrain.HalFormat(GetResponse) 'Add spaces to aid word detection for capitalizaton and error correction. 'Excess spaces will be removed by existing Hal functions later. GetResponse = Replace(GetResponse, ".", " . ", 1, -1, vbTextCompare) GetResponse = Replace(GetResponse, "?", " ? ", 1, -1, vbTextCompare) GetResponse = Replace(GetResponse, ",", " , ", 1, -1, vbTextCompare) GetResponse = Replace(GetResponse, "!", " ! ", 1, -1, vbTextCompare) 'GetResponse = " " & GetResponse & " " 'Make corrections for capitalization and other errors. GetResponse = HalBrain.ProcessSubstitutions(GetResponse, WorkingDir & "corrections.brn") 'User knows best. Capitalize words in the GetResponse if user has used that word as upper case. For I = 1 To CapsCnt GetResponse = Replace(GetResponse, " " & LCase(CapsWord(I)) & " ", " " & CapsWord(I) & " ", 1, -1, vbTextCompare) Next 'User knows best. Uncapitalize words in the GetResponse if user has used that word as lower case. Dim CappedWord(50) For I = 1 To ArraySize LeftChar = UCase(Left(WordArray(I), 1)) CappedWord(I) = LeftChar & Mid(WordArray(I), 2) GetResponse = Replace(GetResponse, " " & CappedWord(I) & " ", " " & WordArray(I) & " ", 1, -1, vbBinaryCompare) Next ' 'In Ultra Hal Assistant v5.0 the "RESPOND: CHANGE TOPIC" process should follow ' this function. 'x=x=x=x=x=x=x=x==vonsmith==x=x=x=x=x=x=x=x=x