Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query a database with multiple pieces of data
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)