## Forum archive 2000-2006

### Thomas Hagedorn - Can Parser.pl be Modified to Accept Answers in Different Forms?

by Arnold Pizer -
Number of replies: 0
 Can Parser.pl be Modified to Accept Answers in Different Forms? topic started 8/27/2005; 12:57:34 AMlast post 8/29/2005; 9:11:57 PM
 Thomas Hagedorn - Can Parser.pl be Modified to Accept Answers in Different Forms?  8/27/2005; 12:57:34 AM (reads: 490, responses: 7) We've written a number of linear algebra problems along the lines of "Please enter a vector v satisfying the following conditions ...." Using Davide's answer parser (which is marvelous!), a student needs to enter a vector in the form <4,5,6> (for a 3-dimensional vector). In class and in our book, we will be writing these vectors as (4,5,6) using parentheses. We are going to try to make it clear to our students that they need to enter a vector using < , > instead of (,). Still, I expect to hear some complaints. Could there be a way to indicate to the Parser.pl that it should count (4,5,6) as the vector <4,5,6>? Perhaps if it is expecting a vector and it sees that (4,5,6) has been entered, it could be programmed to recognize (4,5,6) as a vector instead of a point? Thanks, Tom <| Post or View Comments |>

 John Jones - Re: Can Parser.pl be Modified to Accept Answers in Different Forms?  8/27/2005; 10:39:02 AM (reads: 558, responses: 0) Hi, This sort of thing should be managable through the Context. If you were writing the problems now, or were going to modify them, you could could make a new Context which was just like Vector but had the different treatment of parentheses. I won't try to describe that since it sounds like you have the problems written already and want to change the treatment of parentheses in Vector context. The problems themselves should already have Context('Vector') in them. To do this, you could modify pg/lib/Parser/Context/Default.pm. That is where vector context is defined. You could add the line $vectorContext->parens->set('(' => {close => ')', type => 'Vector', formMatrix => 1}); in the area where vectorContext is defined. John <| Post or View Comments |>  Thomas Hagedorn - Re: Can Parser.pl be Modified to Accept Answers in Different Forms? 8/27/2005; 7:17:15 PM (reads: 567, responses: 0) Hi John, That change by itself didn't seem to work (The problem still expects a '<'). Does the system need to be restarted for the change to be incorporated into the system? Thanks, Tom <| Post or View Comments |>  John Jones - Re: Can Parser.pl be Modified to Accept Answers in Different Forms? 8/27/2005; 9:59:22 PM (reads: 556, responses: 0) You definitely need to restart apache. An apachectl graceful should be sufficient. John <| Post or View Comments |>  Arnold K. Pizer - Re: Can Parser.pl be Modified to Accept Answers in Different Forms? 8/28/2005; 5:55:58 PM (reads: 558, responses: 0) Hi, Can this be done on a course by course basis? For example different courses on the same server might be using different textbooks with different notation. Also is it possible to accept e.g. ( or < ? Arnie <| Post or View Comments |>  John Jones - Re: Can Parser.pl be Modified to Accept Answers in Different Forms? 8/28/2005; 9:22:06 PM (reads: 566, responses: 0) Hi, The modification I gave above should already allow (1,2,3) or <1,2,3> There may be some problems associated to the quick fix I gave. I think Davide is away right now, but he would certainly know more. The quick fix does not easily extend to a course by course customization. I am sure it can be done, but the changes would extend pretty far. If there are several things like this people would want to control, then how configuration should work deserves some thought. On an individual problem, it is not hard to set it to use () in addition to angle brackets. One could keep parallel versions of problems depending on the tastes of the instructor accordingly. It may seem like lots of work, but we see that sort of thing in other problems where people have different tastes (e.g., should an intercept be entered as a number or a point). John <| Post or View Comments |>  Davide P. Cervone - Re: Can Parser.pl be Modified to Accept Answers in Different Forms? 8/29/2005; 7:09:49 PM (reads: 535, responses: 0) John, thanks for covering for me while I was out of town. There are two issues involved in this discussion: how to make global parser changes on a course-by-course basis, and how to change the way vectors are entered and displayed. I had been thinking about the first of these for a while, and I think the easiest solution would be to have Parser.pl load another file called, say, parserCustomization.pl after it is finished initializing the parser. This file would normally be empty (or could contain system-wide customization), but professors could put a copy of this in their course templates/macros directory and include other customization. For example, if they wanted vectors to be entered and displayed using ijk notation rather than <,,> notation. This would require minimal changes (just one line added to Parser.pl and one new empty file), so I'll probably add that to the CVS repository as soon as I get the chance. These sorts of changes need to be done VERY carefully, however, as they could easily cause trouble for problems that expect the original behavior. For example, ijk notation is only for R3, so it could cause problems that use other dimensions to fail, and there might not be an easy way around that. As for how to change the context so that (,,) will produce vectors, there are several approaches. If you are writing your own problems, an easy solution is to use the promotePoints option of the Vector object's answer checker, which will cause points to be converted to vectors automatically (this is not true by default). For example, ANS(Vector(1,2,3)->cmp(promotePoints=>1)); would accept either (1,2,3) or <1,2,3> (or i+2j+3k, etc.) as a valid answer. John's suggestion doesn't require the problem to be written specifically to handle the alternate notation, so is better from that point of view. It has a problem, however, in that there is now no way for the student to enter a point, so ANS(Point(1,2,3)) will not be able to be answered correctly (the student will receive an error message about entering a vector but expecting a point). To get a round this, there probably needs to be a Point context, just as there is a Vector one. I didn't make one originally since Vector already included the notation for points, but it is probably a good idea to have one so that Vector can be changed while leaving Point unaffected. I will add such a context to the default contexts known to the Parser, but older problems that use Vector context when they are asking for Points will suffer if you change the Vector context to make (,,) produce vectors. In addition to making (,,) produce vectors, you probably also want to make vectors output as (,,) rather than <,,>, so that students will see the same format that they have to use to enter their answers. There is another portion of the context that should be adjusted for that:$context->lists->set(Vector => {open=>"(",close=>")"})would do it (where $context is the Context object to be changed). You could also remove the <,,> notation if you wished by using$context->parens->remove('<'); I'll post more once I make the changes to allow course-by-course customization of the Parser. Davide <| Post or View Comments |>

 Davide P. Cervone - Re: Can Parser.pl be Modified to Accept Answers in Different Forms?  8/29/2005; 9:11:57 PM (reads: 545, responses: 0) OK, I've just made some minor changes to the Parser that I think will make it possible to do what you want. There are two changes of importance here: first, the inclusion of the parserCustomization.pl file that I mentioned above, and the ability to include default options to the various answer checkers as part of the Context object. Now to allow students to use (,,) notation to enter vectors (in addition to <,,>), you should put the following lines in templates/macros/parserCustomization.pl in your course directory: $context{Vector} =$Parser::Context::Default::context{Vector}->copy; $context{Vector}->{cmpDefaults}{Vector} = {promotePoints => 1};$context{Vector}->lists->set(Vector=>{open=>'(', close=>')'}); The first line makes a copy of the Vector context that is local to the problem being executed (this is important, so that it does not affect the whole system). When the Context("Vector") command is called, it will load the local copy rather than the default one (the local %context hash is searched before the one in Parser::Context::Default). The second line makes the Vector answer checker automatically allow points to be promoted to vectors when the answer is checked (unless the problem specifically disallows it). This is probably better than having (,,) produce vectors directly, because this still allows students to enter points when a question asks for one. If we changed (,,) to generate a vector, there would be no way for a student to produce a point when the context was set to Vector context (though you could still do it in Point context). This puts off the decision about what the type is supposed to be until the answer is being checked. I don't think that there will be unforeseen problems with this, but it's possible that something may show up, so keep your eyes open for it. Most of the functions and operators that work on vectors should promote points to vectors automatically, so even though students are actually entering points instead of vectors, I don't think there will be problems from that. Finally, the last line makes sure that vectors are displayed using parentheses instead of angle braces when TeX or string output is produced. That should do it. While I'm at it, some of you might want to use ijk notation rather than coordinate notation. You can do that by having parserCustomization.pl include: $context{Vector} =$Parser::Context::Default::context{Vector}->copy; $context{Vector}->flags->set(ijk=>1);$context{Vector}->parens->remove('<'); The second line makes vectors print using the ijk format, while the third disables the coordinate notation. (One could arrange for a better error message, if desired.) Note, however, that if a problem includes a statement like $V = Formula(""), then this will produce an error if you have removed the '<' parenthesis. By subclassing Parser::List::Vector it should be possible to allow professor's answers to be entered in <,,> form, but students would have to use ijk format. If someone needs that, let me know and I'll work it out. Finally, if you want to prevent students from using ijk format, you can use$context{Vector} = $Parser::Context::Default::context{Vector}->copy;$context{Vector}->constants->remove('i','j','k'); Again, keep your eyes open for unwanted side-effects of these settings. Good luck! Davide <| Post or View Comments |>