Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query a database with multiple pieces of data
#1
Need to split a string into pieces of data that will query a database:

Figure I'll use something like sel and case...the problem I see using that is I would rather maintain text files with the words in them so I can edit without having to touch the code in QM and restart the macro with the updated word list.

First off:
Is there anything that works like sel and case that I can set up using variables instead of constants?
Help file says only constants...so is there something similar that I don't know about?

Here's a basic example:
Code:
Copy      Help
str SelWord="One"
str CaseWordListEven=
;Two
;Four
;Six
;Eight
;Ten
str CaseWordListOdd=
;One
;Three
;Five
;Seven
;Nine
sel SelWord 1
,case CaseWordListEven
,out "Even"
,case CaseWordListOdd
,out "Odd"
,case else out "No Match"

Here's an example of splitting data using sel and case (this one does work):
I figure it could go something like this
Code:
Copy      Help
out
str SearchWord="is dinner going to be at 7:00pm tomorrow"

str Meal
str Day
;Search
sel SearchWord 1|2
,case ["*breakfast*"]
,Meal="breakfast"
,SearchWord.findreplace("breakfast" "" 4|1)
,goto Search
,case ["*lunch*"]
,Meal="lunch"
,SearchWord.findreplace("lunch" "" 4|1)
,goto Search
,case ["*dinner*"]
,Meal="dinner"
,SearchWord.findreplace("dinner" "" 4|1)
,goto Search
,case ["*yesterday*"]
,Day="yesterday"
,SearchWord.findreplace("yesterday" "" 4|1)
,goto Search
,case ["*today*"]
,Day="today"
,SearchWord.findreplace("today" "" 4|1)
,goto Search
,case ["*tomorrow*"]
,Day="tomorrow"
,SearchWord.findreplace("tomorrow" "" 4|1)
,goto Search
,
out Meal
out Day

I need it to be a bit more complicated:
Code:
Copy      Help
str SearchWord="Who's Bobby w/2nite?"
str Day Person
;Search
sel SearchWord 1|2
,case ["*tonight*","*2nite*","*tonight*","*2nit*","*now*"]
,Day="tonight"
,;;Need to romove from SearchWord("*tonight*","*2nite*","*tonight*","*2nit*","*now*")
,goto Search

,case ["*bobby Darin*","*bobbie Darin*"]
,str Person="Bobby"
,;;Need to romove from SearchWord("bobby darin","bobbie darin")
,goto Search

out Day
out Person

So the data base will have different keys that I'll search. In the example above, Day and Person. The query will be able to be asked in a sentence and will be able to contain misspellings (That's what the word lists will be for, which is why I want them to be external, because I plan on monitoring what people are searching and adding to the lists as the program gets used. That way it can get smarter!)

So I need cases that work from text stored in a file
I need to remove what ever the case matches from the text file.

Hopefully this is enough information so someone can see what I am trying to do...
Please help...I may even be totally off track and there is an easier way of doing all this.

Thanks,
Jimmy Vig
#2
Quote:Is there anything that works like sel and case that I can set up using variables instead of constants?
if/else
or, especially if there are many cases, use rep or for or foreach
or string functions
#3
Thanks for the suggestions!

Here's what I was able to work up:
This is set up to run with word lists in a directory:
"$program files$\QueryProgram\WordLists\Who\*"
"$program files$\QueryProgram\WordLists\What\*"
"$program files$\QueryProgram\WordLists\Where\*"
"$program files$\QueryProgram\WordLists\When\*"

Database contains columns (who, what, where, when,other information)
If Who="Johnny Cash"
a WordList in the Who directory would contain the file Johnny_Cash.txt
WordList=
Johnny Cash
Jonny Cash
Johny Cash
...
Code:
Copy      Help
str SearchWord
inp- SearchWord "Ask me a question about who what where and when" "" "type your question here"
SearchWord.setfile("$program files$\QueryProgram\Searches.txt" -1 -1 1)
str When="null123"
str Who="null123"
str Where="null123"
str What="null123"
Dir d
foreach(d "$program files$\QueryProgram\WordLists\Where\*" FE_Dir)
,str sPath=d.FileName(1)
,str WordList.getfile(sPath)
,str ID.getfilename(sPath)
,ARRAY(str) arr
,int i nt
,nt = tok(WordList arr -1 "[]")
,for(i 0 nt)
,,arr[i]-"*"
,,arr[i]+"*"
,,if(matchw(SearchWord arr[i] 1))
,,,arr[i].findreplace("*")
,,,SearchWord.findreplace(arr[i] "" 1)
,,,Where=ID
Dir d1
foreach(d1 "$program files$\QueryProgram\WordLists\When\*" FE_Dir)
,str sPath1=d1.FileName(1)
,str WordList1.getfile(sPath1)
,;out WordList1
,str ID1.getfilename(sPath1)
,ARRAY(str) arr1
,int i1 nt1
,nt1 = tok(WordList1 arr1 -1 "[]")
,;out arr1[i1]
,for(i1 0 nt1)
,,arr1[i1]-"*"
,,arr1[i1]+"*"
,,;out arr1[i1]
,,if(matchw(SearchWord arr1[i1] 1))
,,,arr1[i1].findreplace("*")
,,,SearchWord.findreplace(arr1[i1] "" 1)
,,,When=ID1
Dir d2
foreach(d2 "$program files$\QueryProgram\WordLists\Who\*" FE_Dir)
,str sPath2=d2.FileName(1)
,str WordList2.getfile(sPath2)
,;out WordList1
,str ID2.getfilename(sPath2)
,ARRAY(str) arr2
,int i2 nt2
,nt2 = tok(WordList2 arr2 -1 "[]")
,;out arr1[i1]
,for(i2 0 nt2)
,,arr2[i2]-"*"
,,arr2[i2]+"*"
,,;out arr1[i1]
,,if(matchw(SearchWord arr2[i2] 1))
,,,arr2[i2].findreplace("*")
,,,SearchWord.findreplace(arr2[i2] "" 1)
,,,Who=ID2
Dir d3
foreach(d3 "$program files$\QueryProgram\WordLists\What\*" FE_Dir)
,str sPath3=d3.FileName(1)
,str WordList3.getfile(sPath3)
,;out WordList1
,str ID3.getfilename(sPath3)
,ARRAY(str) arr3
,int i3 nt3
,nt3 = tok(WordList3 arr3 -1 "[]")
,;out arr1[i1]
,for(i3 0 nt3)
,,arr2[i3]-"*"
,,arr2[i3]+"*"
,,;out arr1[i1]
,,if(matchw(SearchWord arr3[i3] 1))
,,,arr3[i3].findreplace("*")
,,,SearchWord.findreplace(arr3[i3] "" 1)
,,,What=ID3
if Who="null123"; Who="anyone"
if Where="null123"; Where="anywhere"
if When="null123"; When="anytime"
if What="null123"; What="anything"
_s.format("You will be searching for %s doing %s %s %s." Who What Where When)
mes _s

from here the data base will easily be able to be queried with Who, What, Where, and When.

This logs every search to a text file, so you'll be able to add to the WordLists as the program gets used based on habits.

My Question is, that I have four sections of code that are almost identical and I would like some help consolidating it down to one. I figure having a foreach for the folders in "$program files$\QueryProgram\WordLists\" directory should do the trick...this way if I wanted to add more classifications I could work it out by just adding a folder...like if I wanted to add a Why to the mix, I'd be able to just add the folder and never have to update anything in the actual program.

Thanks again!
Jimmy Vig
#4
Macro
Code:
Copy      Help
;displays all txt files in all folders in Program Files

out
Dir d
foreach(d "$Program Files$\*" FE_Dir 0x1)
,str sF=d.FileName(1)
,out d.FileName
,sF+"\*.txt"
,Dir d2
,foreach(d2 sF FE_Dir)
,,out "[9]%s" d2.FileName
#5
Macro
Code:
Copy      Help
out
str SearchWord
inp- SearchWord "Ask me a question about who what where and when" "" "type your question here"
SearchWord.setfile("$program files$\QueryProgram\Searches.txt" -1 -1 1)
str When="null123"
str Who="null123"
str Where="null123"
str What="null123"

Dir d Parent
foreach(Parent "$Program Files$\QueryProgram\WordLists\*" FE_Dir 0x1)
,str directory.format("$program files$\QueryProgram\WordLists\%s\*" Parent.FileName)
,foreach(d directory FE_Dir)
,,str sPath=d.FileName(1)
,,str WordList.getfile(sPath)
,,str ID.getfilename(sPath)
,,ARRAY(str) arr
,,int i nt
,,nt = tok(WordList arr -1 "[]")
,,for(i 0 nt)
,,,arr[i]-"*"
,,,arr[i]+"*"
,,,if(matchw(SearchWord arr[i] 1))
,,,,arr[i].findreplace("*")
,,,,SearchWord.findreplace(arr[i] "" 1)
,,,,str object=Parent.FileName
,,,,if object="Who";Who=ID
,,,,if object="What";What=ID
,,,,if object="Where";Where=ID
,,,,if object="When";When=ID
if Who="null123"; Who="anyone"
if Where="null123"; Where="anywhere"
if When="null123"; When="anytime"
if What="null123"; What="anything"
_s.format("You will be searching for %s doing %s %s %s." Who What Where When)
mes _s
#6
maybe this can be useful
i use single xml file for all wordlists
Macro
Code:
Copy      Help
str SearchWord="Who's Bobby Darin w/2nite?"

out
str defXml=
;<x>
;<w name="Tonight">
;tonight
;2nite
;tonight
;now
;</w>
;<w name="Bobby_Darin">
;bobby darin
;bobbie darin
;</w>
;</x>

IXml x=CreateXml
x.FromFile("$desktop$\0752.xml" defXml)

ARRAY(IXmlNode) aw
x.Path("x/w" aw) ;;get all w nodes

str s
int w nt

for w 0 aw.len
,foreach s aw[w].Value
,,if(!s.len) continue
,,if(SearchWord.findreplace(s "" 1))
,,,out aw[w].AttributeValue("name")
#7
That's a pretty cool example...I'll be using that later for another program I'm working up! I still have a lot of work to do with the XML...like making a calendar to manage my students. Do you know of any good resources I could study up on how to make a calendar? I've studied the XML of google calendar and other calendars...it looks pretty straight forward and I think I have the feel for it, but how do I go about getting it all to display like Google Calendar, Outlook, or Palm? I need it to perform some pretty specific tasks that I've never been able to find any calendar program that can do them....Well...that'll be another post someday.

I actually think I am pretty good with the text files right now. I think they'll be pretty easy to manage and update and I have them working just the way I want them! The question is...how much faster would the XML be? Are there any awesome advantages I might not have considered?

I will need some help in a day or two when I start to actually build the queries for the data base. Right now I think I am at a really good start by getting the the Who, What, When, and Where out of the way. Then it's just a matter of searching through the database in the proper columns. I'm not sure how it will go when combining and sorting data. I'm sure I'll hit some sort of problem...

Any advice or examples that can be added would be much appreciated...anything that can show off little tricks and methods I might not know due to my lack of experience.

Thanks again...
Jimmy Vig


Forum Jump:


Users browsing this thread: 1 Guest(s)