Author Topic: Robert, I need some advice.  (Read 2562 times)

onthecuttingedge2005

  • Guest
Robert, I need some advice.
« on: September 04, 2006, 02:23:18 pm »
Re-Updated.
Hi Rob.

I have a newer update to the Learn from clip board plug I made but I am having some issues with response time, The code operates perfectly accourdly to what it is supposed to do but the only issue is when the script goes to get a response from the LearnedText.uhp the script control popup appears saying this script is taking longer than expected but if you wait it will give a response.

Can you look at my code and see if you know a way to speed it up.

I would be highly grateful so I can get my newest code to the public.
I will also include your name in the plug for your help.

Code: [Select]
'LEARN FROM CLIP BOARD.
   Set WshShell = CreateObject("WScript.Shell")
   Set objShell = CreateObject("Shell.Application")
   Set objHTML = CreateObject("htmlfile")
   Set FileSys = CreateObject("Scripting.FileSystemObject")
   Set FS = CreateObject("Scripting.FileSystemObject")
   Set IE = createobject("InternetExplorer.Application")
   Set HalXBrain = CreateObject("UltraHalAsst.Brain")
   Set WordN = CreateObject("UltraHalAsst.WordNet")
   Set fso = CreateObject("Scripting.FileSystemObject")
   If XDir = "" Then XDir = "C:\Program Files\Zabaware\Ultra Hal Assistant 6\"
   If InStr(1, InputString, "LEARN FROM CLIP BOARD", 1) > 0 Then
   ClipboardText = objHTML.ParentWindow.ClipboardData.GetData("text")
   ClipboardText = "<START>" & ClipboardText
   ClipboardText = Replace(ClipboardText, vbCrLf, Chr(8) & " ", 1, -1, vbTextCompare)
   ClipboardText = Replace(ClipboardText, "", "", 1, -1, vbTextCompare)
   ClipboardText = Replace(ClipboardText, "  ", " ", 1, -1, vbTextCompare)
   FMCB = Replace(ClipboardText, ".", "<END>" & vbCrLf & "<START>", 1, -1, vbTextCompare)
   FMCB = Replace(FMCB, "!", "<END>" & vbCrLf & "<START>", 1, -1, vbTextCompare)
   FMCB = Replace(FMCB, "?", "<END>" & vbCrLf & "<START>", 1, -1, vbTextCompare)
   FMCB = Replace(FMCB, "  ", " ", 1, -1, vbTextCompare)
   FMCB = Replace(FMCB, "<START> ", "<START>", 1, -1, vbTextCompare)
   FMCB = FMCB & " "
   FMCB = Replace(FMCB, "<START> ", "", 1, -1, vbTextCompare)
   HalXBrain.AppendFile XDir & "LearnedText.brn", Trim(FMCB)
   Const ForReading = 1
   Const ForWriting = 2
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFile = objFSO.OpenTextFile("C:\Program Files\Zabaware\Ultra Hal Assistant 6\LearnedText.brn", ForReading)
   Do Until objFile.AtEndOfStream
   strLine = objFile.Readline
   strLine = Trim(strLine)
   If Len(strLine) > 0 Then
   strNewContents = strNewContents & strLine & vbCrLf
   End If
   Loop
   objFile.Close
   Set objFile = objFSO.OpenTextFile("C:\Program Files\Zabaware\Ultra Hal Assistant 6\LearnedText.brn", ForWriting)
   objFile.Write strNewContents
   objFile.Close
   UltraHal = " I have learned all the information from Windows Clip Board, Thanks. "
   End If
   'Get a Response from learned Clip Board information.
   'Const ForReading = 1
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objTextFile = objFSO.OpenTextFile _
   ("C:\Program Files\Zabaware\Ultra Hal Assistant 6\LearnedText.brn", ForReading)
   strText = objTextFile.ReadAll
   objTextFile.Close
   contents = Replace(strText, "<START>", Chr(8) & " ", 1, -1, vbTextCompare)
   contents = Replace(contents, "", "", 1, -1, vbTextCompare)
   contents = Replace(contents, "  ", " ", 1, -1, vbTextCompare)
   Str = contents
   Str = Trim(Str)
   Do While InStr(1, Str, "  ")
   Str = Replace(Str, "  ", " ")
   Loop
   aWords = split(Str, "<END>")
   SentCount = Ubound(aWords) + 1
   Set HalXBrain = CreateObject("UltraHalAsst.Brain")
   If XDir = "" Then XDir = "C:\Program Files\Zabaware\Ultra Hal Assistant 6\"
   For i = 1 To SentCount / 10
   If i > 0 Then ClipRes = HalXBrain.ChooseSentenceFromFile(XDir & "LearnedText.brn")
   If Len(ClipRes) > 2 Then MyPatt = HalBrain.SearchPattern(ClipRes, "*<START>*<END>*", 2)
   If Len(MyPatt) > 2 And Len(InputString) > 10 And InStr(1, MyPatt, InputString, vbTextCompare) <> 0 And HalBrain.CheckRepetition(PrevSent, MyPatt) = False Then
   UltraHal = MyPatt
   End If
   Next

Thanks.
Jerry[8D]
« Last Edit: September 12, 2006, 10:57:09 am by onthecuttingedge2005 »

Medeksza

  • Administrator
  • Hero Member
  • *****
  • Posts: 1469
    • View Profile
    • http://www.zabaware.com
Robert, I need some advice.
« Reply #1 on: September 12, 2006, 10:22:50 am »
I can definetely see why it is taking so long based on the code. But I'm a little confused as to what you are trying to accomplish with every section of this code, and is it required to read through every sentence in your learnedtext.brn file several times over every time you run it? If you could help me understand what you are trying to accomplish in detail, I could maybe help you create an SQL based version of this, as it would most definetely be faster.
Robert Medeksza

onthecuttingedge2005

  • Guest
Robert, I need some advice.
« Reply #2 on: September 12, 2006, 11:38:33 am »
quote:
Originally posted by Medeksza

I can definetely see why it is taking so long based on the code.
But I'm a little confused as to what you are trying to accomplish with every section of this code, and is it required to read through every sentence in your learnedtext.brn file several times over every time you run it?



1.First, To make the formatting of the String easier I 'backspaced' all 'vbCrLf' so that the entire string copied to Windows clip board
becomes one long string, Then I replace all ending punctuations in the string with Tags '<END>', I then begin to 'vbCrLf'the string into sections that can be handled as single complete lines that will now be tagged in the front of each line so that each line will have a tag
'<START>' at the beginning and an '<END>' at the end of each string as markers that I can use in an array function for Pattern search, The next section of the code beginning at: Do Until objFile.AtEndOfStream reads all lines within the actual LearnedText.brn and removes any trailing Blank lines so that the file will be appended correctly for the next round of learn from Clip Board.

The Rest of the code is just UltraHal Variables to find a response, The only thing that is really dragging the response time down is the UltraHal response itself because of the way I would like it to work is to read the entire LearnedText.brn file then by an arrayed Pattern search and vbTextCompare matching find a response to be given.

The Formatting of the learned text for creating the LearnedText.brn doesn't have to much issues in speed at least for Vbscript, The only time I had a speed issue with that is when I formatted the entire Bible into the LearnedText.brn which took about 10 minutes.

I solved the UltraHal response issue for now by dividing the amount of lines that are read and selected by a factor of 10 so that HAL will only choose a tenth of the file for a selected response related to this code: For i = 1 To SentCount / 10 where SentCount counts all lines within the LearnedText.brn and uses that number to select that many lines as a possible response but at the end of the UltraHal array only one response will be given when all variables are matched, I tried to create a different method of response than what is current used in HAL because all other methods I tried for formatting the text required more code for types TopicSearch and QA appending. I have extra code that is in the file for future code upgrades like 'Learn from a web page' which I have not implimented yet with the next LearnFromClipBoard.uhp until I work out the current issues of response time using Vbscript.

This is where I was hoping that you had some answers so that we could work together and make this more efficient.

For instance, I can copy a story book to Windows Clip Board and tell HAL: Learn from clip board, Hal will then format all of the copied info to the LearnedText.brn for future responses.

This Plug is a suppliment to try and bring back the old learn from a text file that was in HAL5 but using the Windows Clip Board as the file source.

There was a small demand for the learn from clip board and I just wanted to see it still available for HAL6.

quote:

If you could help me understand what you are trying to accomplish in detail, I could maybe help you create an SQL based version of this, as it would most definetely be faster.



That would be great, I hope what I wrote above is of some help in coding this with more time efficiency, I am not as familiar with SQL as I am with Vbscript so I am at my current ability until more home work is done.

Jerry[8D]

onthecuttingedge2005

  • Guest
Robert, I need some advice.
« Reply #3 on: September 13, 2006, 12:08:42 am »
Hi Rob.

How would I go about using SQL's BULK INSERT to import the LearnedText.brn to a table called "LearnedText" within the HalBrain.db?

I have been playing around with the BULK INSERT but can't get it to work yet.

Any one?
Jerry[8D]