Zabaware Forums > Programming using the Ultra Hal Brain Editor

Comparing a text file to brain contents

(1/2) > >>

Spitfire2600:
I'm working on a plug in that compares a text file to contents of a Sentence table in Hals brain.


What I have doesn't seem to do the job correctly. It indeed works, however, I notice the program picking up contents that already exist. I was wondering if anyone has a more effective method they've used in the past. 


'Open the text file
         Set objFile = objFSO.OpenTextFile("text file location", ReadVariable())
         Do Until objFile.AtEndOfStream
                TextCheck = objFile.Readline
         Loop
         objFile.Close   

         
'Make sure word chosen is not word that exists
         PickAWord = HalBrain.ChooseSentenceFromFile("TableName")
         If LCase(PickAWord) = LCase(TextCheck) Then   
         PickAWord = HalBrain.ChooseSentenceFromFile("TableName")
         Do Until LCase(TextCheck) <> LCase(PickAWord)
         Exit Do
         Loop
         End If

'Add new word to new document
                        If PickAWord <> "" Then
                             HalBrain.AppendFile(DifferentTextFile,PickAWord)
                        End If






Again, that method only works about 50 percent of the time for some reason. Any ideas?

Thanks,
Spitfire2600

onthecuttingedge2005:
you could just remove the duplicate lines using a script like this:

https://www.experts-exchange.com/questions/22462672/Remove-duplicate-lines-from-text-file-using-vbscript.html

Good Luck.
Jerry 8)

Spitfire2600:
Indeed that did work, thank you very much. Now I need a way to prevent doubles from being saved to the halbrain table.

-Spitfire

onthecuttingedge2005:

--- Quote from: Spitfire2600 on October 06, 2017, 05:13:25 am ---Indeed that did work, thank you very much. Now I need a way to prevent doubles from being saved to the halbrain table.

-Spitfire

--- End quote ---

Hi SpitFire.

I have a solution for you.
try it in your routine and get back to me.


--- Code: ---'ONTHECUTTINGEDGE.
'THIS SCRIPT IS AN EXAMPLE OF SCANNING FOR DUPLICATE STRINGS.   
'TEST STRING 01.   
PreRec01 = "Hello, How are you?" 'OUR CONTROL STRING.
'REMOVE PUNCTUATIONS.
PreRec01 = HalBrain.AlphaNumericalOnly(PreRec01)
'REMOVE MULTIPLE SPACES THAT CAN RESULT IN A FAILED COMPARE.
PreRec01 = Replace(PreRec01, "  ", " ",   1, - 1, vbTextCompare)

'TEST STRING 02.
'LETS TRY TO TRICK THE COMPARE FUNCTION.
PreRec02 = "Hello  How are you?" '<-- MISSING A COMMA AND ADDED AN EXTRA SPACE.
'REMOVE PUNCTUATIONS.
PreRec02 = HalBrain.AlphaNumericalOnly(PreRec02)
'REMOVE MULTIPLE SPACES THAT CAN RESULT IN A FAILED COMPARE.
PreRec02 = Replace(PreRec02, "  ", " ",   1, - 1, vbTextCompare)

'IF BOTH STRINGS ARE THE SAME THEN DUPLICATES HAVE BEEN FOUND.
If PreRec01 = PreRec02 Then SameRecord = True
'DEBUG
HalBrain.DebugWatch SameRecord, "SameRecord"
'IF RULES APPLY THEN DO SOMETHING.
If SameRecord = True Then
'YOU CAN CHOOSE ANOTHER ROUTINE HERE.
GetResponse = " they are duplicates. "
Else
'YOU CAN CHOOSE ANOTHER ROUTINE HERE.
GetResponse = " they are not duplicates. "
'END ANY OTHER ROUTINES AFTER THIS FUNCTION COMPLETES.
Exit Function
'GOODBYE.
End If

--- End code ---

It is purely an example of how I might keep duplicate entries from being saved.
Small but powerful scripts is what I like best.

Jerry 8)

onthecuttingedge2005:
Here is a Level 2 Anti-Dupe Save Example:

I actually use this.


--- Code: ---'ONTHECUTTINGEDGE.
If ProNouns = "False" And OperQuestion = "False" And Operators = "True" And Len(TempUserSent) > 11 Then
'THIS SCRIPT IS AN EXAMPLE OF SCANNING FOR DUPLICATE STRINGS.   
'TEST STRING 01.   
PreRec01 = TempUserSent 'OUR CONTROL STRING.
'REMOVE PUNCTUATIONS.
PreRec01 = HalBrain.AlphaNumericalOnly(PreRec01)
'REMOVE MULTIPLE SPACES THAT CAN RESULT IN A FAILED COMPARE.
PreRec01 = Replace(PreRec01, "  ", " ",   1, - 1, vbTextCompare)

'TEST STRING 02.
PreRec02 = HalBrain.QABrain(TempUserSent, "General_Reasoning", UserBrainRel)
'REMOVE PUNCTUATIONS.
PreRec02 = HalBrain.AlphaNumericalOnly(PreRec02)
'REMOVE MULTIPLE SPACES THAT CAN RESULT IN A FAILED COMPARE.
PreRec02 = Replace(PreRec02, "  ", " ",   1, - 1, vbTextCompare)

'IF BOTH STRINGS ARE THE SAME THEN DUPLICATES HAVE BEEN FOUND.
If PreRec01 = PreRec02 Then SameRecord = True
'DEBUG
HalBrain.DebugWatch SameRecord, "SameRecord"
'IF RULES APPLY THEN DO SOMETHING.
If SameRecord = True Then
'YOU CAN CHOOSE ANOTHER ROUTINE HERE.
GetResponse = GetResponse & vbCrLf
Else
'YOU CAN CHOOSE ANOTHER ROUTINE HERE.
HalBrain.AddToTable  "General_Reasoning", "Brain", TempUserSent, TempUserSent
GetResponse = GetResponse & vbCrLf
'END ANY OTHER ROUTINES AFTER THIS FUNCTION COMPLETES.
HalBrain.ReadOnlyMode = True
Exit Function
'GOODBYE.
'GOD BLESS.
End If
End If

--- End code ---

Wouldn't You like to see what plug that came out of...
Jerry 8)

Navigation

[0] Message Index

[#] Next page

Go to full version