--- loncom/homework/chemresponse.pm 2004/06/07 21:17:42 1.33 +++ loncom/homework/chemresponse.pm 2004/06/07 21:56:24 1.34 @@ -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 @@ BEGIN { &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 @@ sub end_reactionresponse { my $ad; foreach my $answer (@answers) { &Apache::lonxml::debug("submitted a $response for $answer
\n"); - if ($response eq $answer) { + if (&chem_standard_order($response) eq + &chem_standard_order($answer)) { $ad='EXACT_ANS'; } else { $ad='INCORRECT';