Author Topic: Comparing a text file to brain contents  (Read 197 times)

Spitfire2600

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Comparing a text file to brain contents
« 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
 

OnTheCuttingEdge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2318
  • My Wife is Wicked Smart, lol
    • View Profile
Re: Comparing a text file to brain contents
« Reply #1 on: October 06, 2017, 01:32:09 am »
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)
Plug =N= Play HAL v7.0 coming soon.

Spitfire2600

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Comparing a text file to brain contents
« Reply #2 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
 

OnTheCuttingEdge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2318
  • My Wife is Wicked Smart, lol
    • View Profile
Re: Comparing a text file to brain contents
« Reply #3 on: October 06, 2017, 05:54:17 pm »
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.

Code: [Select]
'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)
« Last Edit: October 07, 2017, 12:33:08 am by OnTheCuttingEdge »
Plug =N= Play HAL v7.0 coming soon.

OnTheCuttingEdge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2318
  • My Wife is Wicked Smart, lol
    • View Profile
Re: Comparing a text file to brain contents
« Reply #4 on: October 07, 2017, 11:20:55 pm »
Here is a Level 2 Anti-Dupe Save Example:

I actually use this.

Code: [Select]
'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)
« Last Edit: October 07, 2017, 11:43:22 pm by OnTheCuttingEdge »
Plug =N= Play HAL v7.0 coming soon.

Spitfire2600

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Comparing a text file to brain contents
« Reply #5 on: October 15, 2017, 02:55:19 am »
Yes, that worked perfect! What plugin was that part of?

- Spitfire_2600
 

OnTheCuttingEdge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2318
  • My Wife is Wicked Smart, lol
    • View Profile
Re: Comparing a text file to brain contents
« Reply #6 on: October 15, 2017, 03:08:59 am »
Plug =N= Play HAL v7.0 coming soon.

Spitfire2600

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Comparing a text file to brain contents
« Reply #7 on: October 15, 2017, 03:57:08 pm »
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
 

Spitfire2600

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Comparing a text file to brain contents
« Reply #8 on: October 15, 2017, 04:00:59 pm »
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