version 1.168, 2014/06/25 15:43:04
|
version 1.173, 2017/02/07 21:24:29
|
Line 309 sub caparesponse_check_list {
|
Line 309 sub caparesponse_check_list {
|
#for numerical problems split off the unit |
#for numerical problems split off the unit |
my $part1; |
my $part1; |
my $part2; |
my $part2; |
|
my $match_algebra = qr{^(.*[^\s])\s+([^\s]+)$}; |
|
# FIXME: with the above regexp, algebra with spaces will not be evaluated correctly |
|
my $match_numerical_units = qr{^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$}; |
if ($allowalgebra) { |
if ($allowalgebra) { |
($part1,$part2)=($responses->[0][-1]=~ /^(.*[^\s])\s+([^\s]+)$/); |
($part1,$part2) = ($responses->[0][-1] =~ /$match_algebra/); |
} else { |
} else { |
($part1,$part2)=($responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$/); |
($part1,$part2) = ($responses->[0][-1] =~ /$match_numerical_units/); |
} |
} |
if (defined($part1) && defined($part2)) { |
if (defined($part1) && defined($part2)) { |
$responses->[0][-1]=$part1; |
$responses->[0][-1]=$part1; |
Line 327 sub caparesponse_check_list {
|
Line 330 sub caparesponse_check_list {
|
} |
} |
} |
} |
} |
} |
|
if (scalar(@$responses) > 0 && defined $answerunit) { |
|
# there are several response values, units should be the same for all |
|
$part2 =~ s/^\s+|\s+$//g; |
|
for (my $i=1; $i<scalar(@$responses); $i++) { |
|
my $element = $responses->[$i][-1]; |
|
my ($part1i, $part2i); |
|
if ($allowalgebra) { |
|
($part1i, $part2i) = ($element =~ /$match_algebra/); |
|
} else { |
|
($part1i, $part2i) = ($element =~ /$match_numerical_units/); |
|
} |
|
$part2i =~ s/^\s+|\s+$//g; |
|
if (!defined $part2i) { |
|
return 'NO_UNIT'; |
|
} elsif ($part2i ne $part2) { |
|
return ('UNIT_FAIL', "$part2 $part2i"); |
|
} else { |
|
$responses->[$i][-1] = $part1i; |
|
} |
|
} |
|
} |
} |
} |
} |
} |
$unit=~s/\s//; |
$unit=~s/\s//; |
Line 902 sub chemparse {
|
Line 926 sub chemparse {
|
my $formula = ''; |
my $formula = ''; |
foreach my $token (@tokens) { |
foreach my $token (@tokens) { |
if ($token eq '->' ) { |
if ($token eq '->' ) { |
$formula .= '<m>\ensuremath{\rightarrow}</m> '; |
if ($external::target eq 'web') { |
|
$formula .= '→ '; |
|
} else { |
|
$formula .= '<m>\ensuremath{\rightarrow}</m> '; |
|
} |
next; |
next; |
} |
} |
if ($token eq '<-' ) { |
if ($token eq '<-' ) { |
$formula .= '<m>\ensuremath{\leftarrow}</m> '; |
if ($external::target eq 'web') { |
|
$formula .= '← '; |
|
} else { |
|
$formula .= '<m>\ensuremath{\leftarrow}</m> '; |
|
} |
next; |
next; |
} |
} |
if ($token eq '<=>') { |
if ($token eq '<=>') { |
Line 1228 sub sec {
|
Line 1260 sub sec {
|
} |
} |
|
|
sub submission { |
sub submission { |
my ($partid,$responseid,$subnumber,$encode)=@_; |
my ($partid,$responseid,$subnumber,$encode,$cleanupnum,$mapalias)=@_; |
my $sub=''; |
my $sub=''; |
if ($subnumber) { $sub=$subnumber.':'; } |
if ($subnumber) { $sub=$subnumber.':'; } |
my $output = |
my $output = |
&EXT('user.resource.'.$sub.'resource.'.$partid.'.'.$responseid.'.submission'); |
&EXT('user.resource.'.$sub.'resource.'.$partid.'.'.$responseid.'.submission',$mapalias); |
if (ref($output) eq 'ARRAY') { |
if (ref($output) eq 'ARRAY') { |
my @items = @{$output}; |
my @items = @{$output}; |
if ($encode) { |
if ($encode) { |
@items = map { &encode_response($_); } @items; |
@items = map { &encode_response($_); } @items; |
} |
} |
|
if (ref($cleanupnum) eq 'HASH') { |
|
@items = map { &cleanup_numerical_response($cleanupnum,$_); } @items; |
|
} |
return \@items; |
return \@items; |
} else { |
} else { |
if ($encode) { |
if ($encode) { |
$output = &encode_response($output); |
$output = &encode_response($output); |
} |
} |
|
if (ref($cleanupnum) eq 'HASH') { |
|
$output = &cleanup_numerical_response($cleanupnum,$output); |
|
} |
return $output; |
return $output; |
} |
} |
} |
} |
Line 1256 sub encode_response {
|
Line 1294 sub encode_response {
|
return $value; |
return $value; |
} |
} |
|
|
|
sub cleanup_numerical_response { |
|
my ($cleanupnum,$value) = @_; |
|
if (ref($cleanupnum) eq 'HASH') { |
|
if ($cleanupnum->{exponent}) { |
|
if ($value =~ m{^(.*)[\*xX]\s*10\s*\^\s*(\+|\-)?\s*(\d+)(.*)$}) { |
|
my $pre_exp = $1; |
|
my $sign = $2; |
|
my $exponent = $3; |
|
my $post_exp = $4; |
|
if ($pre_exp !~ /\./) { |
|
$pre_exp .= '.'; |
|
} |
|
if ($sign eq '') { |
|
$sign = '+'; |
|
} |
|
$value = $pre_exp.'E'.$sign.$exponent.$post_exp; |
|
} |
|
} |
|
if ($cleanupnum->{comma}) { |
|
$value =~ s{(\d+),(\d+)}{$1$2}; |
|
} |
|
if ($cleanupnum->{letterforzero}) { |
|
$value =~ s/^\s*o(\.\d+)/0$1/i; |
|
} |
|
if ($cleanupnum->{spaces}) { |
|
$value =~ s{^\s+|\s+$}{}g; |
|
if ($value =~ m{^(.*)\.\s+(\d+)(.*)$}) { |
|
my $pre_pt = $1; |
|
my $decimal = $2; |
|
my $post_dec = $3; |
|
$value = $pre_pt.'.'.$decimal.$post_dec; |
|
} |
|
} |
|
if ($cleanupnum->{format} =~ /^\d+s$/i) { |
|
$value = &format_significant_figures($value,$cleanupnum->{format}); |
|
} |
|
} |
|
return $value; |
|
} |
|
|
sub currentpart { |
sub currentpart { |
return $external::part; |
return $external::part; |
} |
} |
Line 1412 sub proper_path {
|
Line 1490 sub proper_path {
|
} |
} |
} |
} |
|
|
|
sub input_id { |
|
my ($part_id, $response_id, $textline_id) = @_; |
|
return 'HWVAL_'.$part_id.'_'.$response_id.'_'.$textline_id; |
|
} |
|
|