Source language: Translate to:

search database problem

Questions about NeoBook PlugIns

Moderator: Neosoft Support

search database problem

Postby Rox_Folder » Tue Feb 06, 2007 1:33 pm

Hello All,
I have use this code to search for names on database but when I put to search Caroline, I found carol, if I put Ana, I found Joana. what is wrong?

If "[Question]" "<>" ""

.Initialize variables
SetVar "[Found]" ""
SetVar "[Rank]" "0"
SetVar "[Q]" "[Question]"

.Remove punctuation from the question
StrReplace "[Q]" "?" "" "[Q]"
StrReplace "[Q]" "!" "" "[Q]"
StrReplace "[Q]" "." "" "[Q]"
StrReplace "[Q]" "," "" "[Q]"
StrReplace "[Q]" ":" "" "[Q]"
StrReplace "[Q]" "[#32][#32]" "" "[Q]"

.Break question into an array of words
StrParse "[Q]" "[#32]" "[Words]" "[WordCount]"

.Search database for different combinations of words from the question (max 5 words)
.Rate finds by how many words match. More matches is better.
Loop "1" "[WordCount]-1" "[X]"
SetVar "[Query1]" "Name = [Words[X]]"

dbfQuery "[PubDir]data/names.dbf" "[Query1]"
If "[dbfQueryResult]" ">" "0"
.we found a match, see if it's better than previous one
If "[Rank]" "<" "1"
SetVar "[Found]" "[data/names.action]"
SetVar "[Rank]" "1"
EndIf
EndIf

If "[X]+1" "<=" "[WordCount]"
Loop "[X]+1" "[WordCount]" "[Y]"
SetVar "[Query2]" "[Query1] AND Name = [Words[Y]]"

dbfQuery "[PubDir]data/names.dbf" "[Query2]"
If "[dbfQueryResult]" ">" "0"
.we found a match, see if it's better than previous one
If "[Rank]" "<" "2"
SetVar "[Found]" "[data/names.asction]"
SetVar "[Rank]" "2"
EndIf
EndIf

If "[Y]+1" "<=" "[WordCount]"
Loop "[Y]+1" "[WordCount]" "[Z]"
SetVar "[Query3]" "[Query2] AND Name= [Words[Z]]"

dbfQuery "[PubDir]data/names.dbf" "[Query3]"
If "[dbfQueryResult]" ">" "0"
.we found a match, see if it's better than previous one
If "[Rank]" "<" "3"
SetVar "[Found]" "[data/names.action]"
SetVar "[Rank]" "3"
EndIf
EndIf

If "[Z]+1" "<=" "[WordCount]"
Loop "[Z]+1" "[WordCount]" "[Q]"
SetVar "[Query4]" "[Query3] AND Nome = [Words[Q]]"

dbfQuery "[PubDir]data/names.dbf" "[Query4]"
If "[dbfQueryResult]" ">" "0"
.we found a match, see if it's better than previous one
If "[Rank]" "<" "4"
SetVar "[Found]" "[data/names.action]"
SetVar "[Rank]" "4"
EndIf

Thank you
The [TRUE] is in here.
User avatar
Rox_Folder
 
Posts: 10
Joined: Wed May 31, 2006 11:55 am

Postby Gaev » Tue Feb 06, 2007 1:55 pm

Rox_Folder:

First of all, you might want to use indentation whenever you have If...EndIf and Loop...EndLoop blocks of code ... this will allude you to unpaired blocks of this kind ... I see that you don't have EndLoop commands in your posted code ... and the number of If's and EndIf's don't match ... so it is hard to see how NeoBook will react to this command set.

As far as dbfQuery is concerned ... from the Help file for this command ...
Code: Select all
=   At least part of the search string can be found in the specified field.
==   The search string matches the field contents exactly.
... so try using something like ...
Code: Select all
SetVar "[Query1]" "Name == [Words[X]]"
User avatar
Gaev
 
Posts: 3734
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Rox_Folder » Tue Feb 06, 2007 2:40 pm

First off all Thank you for response Gaev

here are the source, I get from sample AI
.................................................................

If "[Question]" "<>" ""

.Initialize variables
SetVar "[Found]" ""
SetVar "[Rank]" "0"
SetVar "[Q]" "[Question]"

.Remove punctuation from the question
StrReplace "[Q]" "?" "" "[Q]"
StrReplace "[Q]" "!" "" "[Q]"
StrReplace "[Q]" "." "" "[Q]"
StrReplace "[Q]" "," "" "[Q]"
StrReplace "[Q]" ":" "" "[Q]"
StrReplace "[Q]" "[#32][#32]" "" "[Q]"

.Break question into an array of words
StrParse "[Q]" "[#32]" "[Words]" "[WordCount]"

.Search database for different combinations of words from the question (max 5 words)
.Rate finds by how many words match. More matches is better.
Loop "1" "[WordCount]-1" "[X]"
SetVar "[Query1]" "Phrase = [Words[X]]"

dbfQuery "[PubDir]Lexicon.dbf" "[Query1]"
If "[dbfQueryResult]" ">" "0"
.we found a match, see if it's better than previous one
If "[Rank]" "<" "1"
SetVar "[Found]" "[Lexicon.Response]"
SetVar "[Rank]" "1"
EndIf
EndIf

If "[X]+1" "<=" "[WordCount]"
Loop "[X]+1" "[WordCount]" "[Y]"
SetVar "[Query2]" "[Query1] AND Phrase = [Words[Y]]"

dbfQuery "[PubDir]Lexicon.dbf" "[Query2]"
If "[dbfQueryResult]" ">" "0"
.we found a match, see if it's better than previous one
If "[Rank]" "<" "2"
SetVar "[Found]" "[Lexicon.Response]"
SetVar "[Rank]" "2"
EndIf
EndIf

If "[Y]+1" "<=" "[WordCount]"
Loop "[Y]+1" "[WordCount]" "[Z]"
SetVar "[Query3]" "[Query2] AND Phrase = [Words[Z]]"

dbfQuery "[PubDir]Lexicon.dbf" "[Query3]"
If "[dbfQueryResult]" ">" "0"
.we found a match, see if it's better than previous one
If "[Rank]" "<" "3"
SetVar "[Found]" "[Lexicon.Response]"
SetVar "[Rank]" "3"
EndIf
EndIf

If "[Z]+1" "<=" "[WordCount]"
Loop "[Z]+1" "[WordCount]" "[Q]"
SetVar "[Query4]" "[Query3] AND Phrase = [Words[Q]]"

dbfQuery "[PubDir]Lexicon.dbf" "[Query4]"
If "[dbfQueryResult]" ">" "0"
.we found a match, see if it's better than previous one
If "[Rank]" "<" "4"
SetVar "[Found]" "[Lexicon.Response]"
SetVar "[Rank]" "4"
EndIf
EndIf

EndLoop
EndIf

EndLoop
EndIf

EndLoop
EndIf
EndLoop

.Reset database
dbfShowAll "[PubDir]Lexicon.dbf"

.Display Gloria's response
If "[Found]" "<>" ""
SetVar "[Answer]" "Human: [Question][#13]Gloria: [Found]"
Else
SetVar "[Answer]" "Human: [Question][#13]Gloria: I don't understand."
EndIf

.Clear the last question
SetVar "[Question]" ""

Else
SetVar "[Answer]" "You forgot to enter a question!"
EndIf

So I use to make a dictionary for names, but If i type Ana, I get Joana, Adriana....
The [TRUE] is in here.
User avatar
Rox_Folder
 
Posts: 10
Joined: Wed May 31, 2006 11:55 am

Postby Wrangler » Wed Feb 07, 2007 8:36 am

That is the way it was coded in the example, but if you want to find the EXACT name, you will have to use ==.

SetVar "[Query1]" "Name == [Words[X]]"

It just depends on the type of search you want to perform. The example is searching for a phrase, or more than one word.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby Rox_Folder » Wed Feb 07, 2007 11:48 am

oh now i see the double ==, thank you wrangler
The [TRUE] is in here.
User avatar
Rox_Folder
 
Posts: 10
Joined: Wed May 31, 2006 11:55 am


Return to PlugIn Discussions

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest