Zabaware Support Forums
Zabaware Forums => Programming using the Ultra Hal Brain Editor => Topic started by: Spitfire2600 on October 05, 2017, 12:54:17 pm
-
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
-
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)
-
Indeed that did work, thank you very much. Now I need a way to prevent doubles from being saved to the halbrain table.
-Spitfire
-
Indeed that did work, thank you very much. Now I need a way to prevent doubles from being saved to the halbrain table.
-Spitfire
Hi SpitFire.
I have a solution for you.
try it in your routine and get back to me.
'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
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)
-
Here is a Level 2 Anti-Dupe Save Example:
I actually use this.
'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
Wouldn't You like to see what plug that came out of...
Jerry 8)
-
Yes, that worked perfect! What plugin was that part of?
- Spitfire_2600
-
this plug-in.
http://www.ultrahal.com/community/index.php?topic=14021.msg79244#new
enjoy.
Jerry 8)
-
Ah yes, I saw that you posted this but I haven't had the pleasure of taking it around the block yet.
I'll test it out and let you know how it works. It is a brilliant idea. I could see this being used in conjunction with my ConceptNet plugin.
-Spitfire_2600
-
Also, I found another way around the randomization of the ChooseSentenceFromBrain function.
I created 2 text files that compare against each other, then adds only the first result to a brain table. It doesn't fully utilize Hal's brain as intended, however, it is quite effective.
-Spitfire_2600
-
Can you give the forum an example?