Please Help w/ASP Parser for Online Test

Results 1 to 6 of 6

Thread: Please Help w/ASP Parser for Online Test

  1. #1
    Scott Miller Guest

    Default Please Help w/ASP Parser for Online Test

    Hello, I have to write a parser in ASP to filter a large textbox entry into a database of questions and answers. Basically, someone will type in a test with questions and any number of multiple choice answers in a text editor, then copy and paste this text into a textbox. Once submitted from the textbox page, a parser will parse through the text and populate a database with the questions and answers for each question along with the flagged correct answer. <BR><BR>The text will be entered in this format:<BR><BR>1) What year is this?<BR><BR> a. 1980<BR> b. 1990<BR> * c. 2000 <BR> d. 2001<BR><BR>2) Next question .....<BR><BR>I know how to stick the information in the Access database I created once the questions and answers are separated, but I have never written a smart parser to handle this type of text entry.<BR>Thank you in advance for anyones help and input.<BR><BR>Scott Miller

  2. #2
    SPG Guest

    Default Regular Expressions to the Rescue!

    It&#039s simple, just use the questions and selected answers as flags to be collected by a regular expression.<BR><BR>??1) Blah Blah Blarg?<BR>a. Foo!<BR>*b. Bar!<BR>c. Twonk!<BR><BR>??2) Foo Blarg Twonk?<BR><BR>The ?? flags a question number, the * flags an answer letter.<BR>Then you&#039ve got a regular expression that looks kind of like this:<BR><BR>"??(d+)[sS]*?*s*(w)[sS]*?(?=??)" which can collect the question number (objMatch.subValue(0) -- it&#039s the d+) and the letter which the student selected (objMatch.subValue(1) -- it&#039s the w)<BR><BR>It should be global, ignore case, for each match it finds, it should extract and store the subvalues mentioned above.<BR><BR>The one important (and odd) trick is that after all the questions and answers are done, there needs to be a "??" for closure at the end...<BR><BR>Oh, warn your students that they *cannot* skip any questions, as that will throw off all of their future answers...<BR><BR>Hope it helps,<BR>SPG

  3. #3
    Join Date
    Dec 1969

    Default RE: Regular Expressions to the Rescue!

    Also I may not have been that clear in my initial post, but the test that is entered will be from the instructor. Then the parser will parse the text and populate the Access database and another ASP page will be used to pull the questions and answers from the database to create the online exam.

  4. #4
    Scott Miller Guest

    Default RE: Regular Expressions to the Rescue!

    Thanks a million for help, however I am not familiar with using the objMatch function. If possible, could you show me how to do this with a brief code example. Thanks a lot for help again.<BR><BR>Scott

  5. #5
    SPG Guest

    Default Meditate on this Example...

    Okay, this is probably a bit more like what you&#039re looking for. It takes an outer loop defined by ##&#039s (similiar to what was done with the ??s in the previous suggestion) and uses that as a "Topic". Then it takes all the contents of the topic and parses those out as questions and answers (using ""s and ??s). It will probably help if you think of the ## regExp as finding Questions, and the ?? and "" regExp as finding right & wrong answers.<BR><BR>Additionally, has good info on VBScript regExps. But here&#039s the code. (Oh, ignore the db and resp calls -- this came from my VB style [DB = database; Resp = Response]. And sorry about the formatting, it&#039s the messageboard.)<BR><BR>HiH, SPG (code below)<BR><BR> &#039 Setup RegExp Objects<BR> bError = False<BR> outerRE.Global = True<BR> innerRE.Global = True<BR> outerRE.IgnoreCase = True<BR> innerRE.IgnoreCase = True<BR> &#039 Find & store a Topic. Collect everything until next topic is Found (not stored).<BR> outerRE.Pattern = "## (.*?) ##([sS]*?)(?=## .*? ##)"<BR> &#039 Find a question (?? * ??) and an answer (""*"")<BR> innerRE.Pattern = "?? ([sS]*?) ??[sS]*?\""\""([sS]*?)\""\"""<BR> &#039 Done establishing objects<BR> <BR> If db.beginTransaction Then<BR> If db.doSQL("insert into " & dbCustomerTable & "(sCustomer, dDate, sType) values (&#039" & strCustomer & "&#039, &#039" & dDate & "&#039, &#039" & Replace(strType, "&#039", "") & "&#039)") Then<BR> iCustomer = CInt(db.topValue(dbCustomerTable, "objID", "sCustomer = &#039" & strCustomer & "&#039 and dDate = &#039" & dDate & "&#039", , , "-1"))<BR> Else<BR> Call db.terminateTransaction<BR> Err.Raise 500, , "Could not create customer record; see below."<BR> End If<BR> <BR> Set outerMatches = outerRE.Execute(strFileIn)<BR> For Each outerMatch In outerMatches<BR> strTopic = outerMatch.SubMatches(0)<BR> strSurveyBlock = outerMatch.SubMatches(1)<BR> resp.Write "&#060;!-- " & strSurveyBlock & " --&#062;" & vbCrLf<BR> Set innerMatches = innerRE.Execute(strSurveyBlock)<BR> For Each innerMatch In innerMatches<BR> resp.Write "&#060;!-- Inserting for Customer #" & iCustomer & " --&#062;" & vbCrLf & "&#060;!-- [" & strTopic & "] " & innerMatch.SubMatches(0) & " --&#062;" & vbCrLf & "&#060;!-- " & innerMatch.SubMatches(1) & " --&#062;" & vbCrLf<BR> If Not submitAnswer(iCustomer, strTopic, innerMatch.SubMatches(0), innerMatch.SubMatches(1)) Then bError = True<BR> If bError Then Exit For<BR> Next<BR> If bError Then Exit For<BR> Next<BR> If bError Then db.terminateTransaction Else db.completeTransaction<BR> Else<BR> Err.Raise 500, , "Database does not support ADO Transactions"<BR> End If<BR> <BR> Set innerMatches = Nothing<BR> Set innerRE = Nothing<BR> Set outerMatches = Nothing<BR> Set outerRE = Nothing<BR> scanUpload = True

  6. #6
    Scott Miller Guest

    Default RE: Meditate on this Example...

    Just got it, thanks a million for your help.<BR><BR>Scott

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts