[LON-CAPA-cvs] cvs: loncom /homework chemresponse.pm /xml lonxml.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 07 Jun 2004 21:56:25 -0000
albertel Mon Jun 7 17:56:25 2004 EDT
Modified files:
/loncom/homework chemresponse.pm
/loncom/xml lonxml.pm
Log:
- BUG#2783, <reactionresponse> now does a parse pass to reorder strip whitespace etc, from oth instructor supplied answer and student supplid answer before comparing.
- new function &chem_standard_order available to Safe space
Index: loncom/homework/chemresponse.pm
diff -u loncom/homework/chemresponse.pm:1.33 loncom/homework/chemresponse.pm:1.34
--- loncom/homework/chemresponse.pm:1.33 Mon Jun 7 17:17:42 2004
+++ loncom/homework/chemresponse.pm Mon Jun 7 17:56:24 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# chemical equation style response
#
-# $Id: chemresponse.pm,v 1.33 2004/06/07 21:17:42 albertel Exp $
+# $Id: chemresponse.pm,v 1.34 2004/06/07 21:56:24 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,6 +35,33 @@
&Apache::lonxml::register('Apache::chemresponse',('organicresponse','organicstructure','reactionresponse'));
}
+sub chem_standard_order {
+ my ($reaction) = @_;
+ my ($re,$pr) = split(/->|<=>/,$reaction);
+ my @reactants = split(/\s\+/,$re);
+ my @products = split(/\s\+/,$pr);
+ foreach my $substance (@reactants,@products) {
+ $substance =~ s/(\^\d*)\s+/$1_/g; # protect superscript space
+ $substance =~ s/\s*//g; # strip whitespace
+ $substance =~ s/_/ /g; # restore superscript space
+ }
+ @reactants = sort @reactants;
+ @products = sort @products;
+ my $standard = '';
+ foreach my $substance (@reactants) {
+ $standard .= $substance;
+ $standard .= ' + ';
+ }
+ $standard =~ s/ \+ $//; # get rid of trailing plus sign
+ $standard .= ' -> ';
+ foreach my $substance (@products) {
+ $standard .= $substance;
+ $standard .= ' + ';
+ }
+ $standard =~ s/ \+ $//; # get rid of trailing plus sign
+ return $standard;
+}
+
sub separate_jme_window {
my ($smile_input,$jme_input,$molecule,$options)=@_;
my $smilesection;
@@ -345,7 +372,8 @@
my $ad;
foreach my $answer (@answers) {
&Apache::lonxml::debug("submitted a $response for $answer<br \>\n");
- if ($response eq $answer) {
+ if (&chem_standard_order($response) eq
+ &chem_standard_order($answer)) {
$ad='EXACT_ANS';
} else {
$ad='INCORRECT';
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.323 loncom/xml/lonxml.pm:1.324
--- loncom/xml/lonxml.pm:1.323 Sat Jun 5 10:46:12 2004
+++ loncom/xml/lonxml.pm Mon Jun 7 17:56:24 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.323 2004/06/05 14:46:12 www Exp $
+# $Id: lonxml.pm,v 1.324 2004/06/07 21:56:24 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -662,7 +662,9 @@
$safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
$safehole->wrap(\&Apache::outputtags::multipart,$safeeval,'&multipart');
$safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
-
+ $safehole->wrap(\&Apache::chemresponse::chem_standard_order,$safeeval,
+ '&chem_standard_order');
+
$safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
$safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
$safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');