WeBWorK Main Forum

How turn off "preprocessing and error detection" of/in student answers before handing to custom grader? (giving errors)

How turn off "preprocessing and error detection" of/in student answers before handing to custom grader? (giving errors)

by Christian Seberino -
Number of replies: 3
Before Webwork gives student answers to custom graders, it seems to do some preprocessing such as trying to detect implied multiplication. This preprocessing is sometimes a problem because it causes Webwork to think there are errors that aren't really there.

How set Webwork to NOT do ANY preprocessing of the student answers and just send the raw text exactly as it appears to the custom grader?

(The context of the question is that I'm trying to write a Webwork problem that accepts source code and can grade it. (See below.) As you can imagine, entering source code for an answer confused Webwork which thinks there are all kinds of botched implied mutliplications and other errors in the answer.)





DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGML.pl",
"MathObjects.pl",
"PGcourse.pl",
"parserNumberWithUnits.pl",
"contextArbitraryString.pl",
"parserMultiAnswer.pl",
"parserPopUp.pl",
"contextInequalities.pl",
"PGgraphmacros.pl",
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
######################################################################

Context("ArbitraryString");
@answers = ("<source code>");
$ans = Compute(@answers[0])->cmp(checker => sub {
my ($temp1, $response, $temp2) = @_;

$x = SourceCodeGrader::sourcecodegrader($response);

return 1;
});

BEGIN_PGML
Text of question goes here.

[@ ANS($ans), ans_box(30, 90) @]*
END_PGML

######################################################################
ENDDOCUMENT();




In reply to Christian Seberino

Re: How turn off "preprocessing and error detection" of/in student answers before handing to custom grader? (giving errors)

by Michael Gage -
Here are some notes from my reply to Chris in the IRC:

I think what you want to do is to avoid MathObjects all together and create and AnswerEvaluator -- somewhat lower level machinery

References are in the "POD" documentation

 

The answerHash is just a hash with a bunch of information -- it's what you see when you use PGLabs --  The AnswerEvaluator allows you to take a string of filters which input the answer Hash, process the information in it and then out the answer hash to be passed on to the next filter.  This is how the basic evaluators were created.  The MathObject evaluators were created somewhat separately but hook in to this mechanism.  You want to hook into this mechanism directly since you want to by pass the features provided by the MathObjects class.


 

Looking at the code in the files labeled PG***evaluators.pl will give you some ideas.  The old macros num_cmp() and fun_cmp() used the AnswerEvaluators directly but they have been modified to use the MathObjects routines in order to provide the students with superior feedback.

 

Value/AnswerChecker.pm  the cmp() method around line 79 gives you another example of creating the answer evaluator and using it.



In reply to Christian Seberino

Re: How turn off "preprocessing and error detection" of/in student answers before handing to custom grader? (giving errors)

by Davide Cervone -
I think the issue is the newlines in the answer; the ArbitraryString object doesn't expect there to be newlines, and the pattern it uses to obtain them doesn't work with them, so you end up getting several arbitrary strings (one for each line) with what the parser will consider to be implied multiplication between them.

This can be fixed by adding

   Context()->strings->{patterns}{'(.|~~n)*'} = [-25,str];
   Context()->update;
right after the
  Context("ArbitraryString");
command. This will let the arbitrary string span newlines. I think that should work for you.

Davide

PS, if you want to include this within a macro file, change ~~n to \n in the pattern above.

In reply to Davide Cervone

Re: How turn off "preprocessing and error detection" of/in student answers before handing to custom grader? (giving errors)

by Christian Seberino -
Thanks Davide! I can vouch that that worked.

If anyone reads this and needs to still pursue Prof. Gage's idea to write an answer evaluator, the easiest way to get started is probably to just add a copy of std_cs_str_cmp next to the original in pg/macros/PGstringevalators.pl, rename it, and start tweaking that.

Sincerely,

Chris