WeBWorK Main Forum

Bug trying to make grader in PGML problem give partial credit for wrong units.

Bug trying to make grader in PGML problem give partial credit for wrong units.

by Christian Seberino -
Number of replies: 1
I'm trying to modify a working PGML problem below to give partial credit if
numerical part of answer is right but units are wrong.
(Give only 75% of old score if units missing or incorrect.)

I'm aware of the withPostFilter method of "answerHints.pl"
but not sure how to integrate the ANS(...) piece into this PGML
problem.

Furthermore, withPostFilter is normally used to give hints so I'm not
sure if I'm tweaking it appropriately to just change score.

Right now below gives this error...

panic: sv_setpvn called with negative strlen -2 at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 788

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

Context("Numeric") ; Context()->flags->set(tolerance => 0.01);

$ans = NumberWithUnits("2 ft");

ANS($ans->cmp()->withPostFilter(
     if ($ans->{student_ans} =~ /ft\z/) {
             $ans->{score} = 0.75 * $ans->{score};
     });

BEGIN_PGML
How many feet are equal to 24 inches?

[________________________]{$ans}
END_PGML

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

In reply to Christian Seberino

Re: Bug trying to make grader in PGML problem give partial credit for wrong units.

by Geoff Goehle -
I messed around with things for a bit, but there is kind of a fundamental issue. The NumberWithUnits parser you are using (http://webwork.maa.org/wiki/ProblemsWithUnits) allows students to use equivalent answers with different numbers (e.g. "12 in" or "1 ft"). They are set up to spit out an error message to the student if there isn't a unit attached to the number or if the unit given is incompatible with the correct answer unit because otherwise it is actually impossible to do the comparison. (After all *any* number would be correct with the "right" units.) So in some sense what you are asking for is impossible with NumberWithUnits.

You might be able to accomplish something similar with multiple answer blanks, or just a custom answer checker with some regexp parsing. But fundamentally any system which can reward the "right" answer without units also has to be very limited in the variety of units it can accept.