version 1.1, 2004/02/17 23:03:34
|
version 1.5, 2004/08/05 21:08:24
|
Line 1
|
Line 1
|
|
# Handler for parsing text upload problem descriptions into .problems |
|
# $Id$ |
|
# |
|
# Copyright Michigan State University Board of Trustees |
|
# |
|
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
|
# |
|
# LON-CAPA is free software; you can redistribute it and/or modify |
|
# it under the terms of the GNU General Public License as published by |
|
# the Free Software Foundation; either version 2 of the License, or |
|
# (at your option) any later version. |
|
# |
|
# LON-CAPA is distributed in the hope that it will be useful, |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
# GNU General Public License for more details. |
|
# |
|
# You should have received a copy of the GNU General Public License |
|
# along with LON-CAPA; if not, write to the Free Software |
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
# |
|
# /home/httpd/html/adm/gpl.txt |
|
# |
|
# http://www.lon-capa.org/ |
|
# |
|
|
package Apache::testbankimport; |
package Apache::testbankimport; |
|
|
use strict; |
use strict; |
use Apache::Constants qw(:common :http :methods); |
use Apache::Constants qw(:common :http :methods); |
use Apache::loncacc; |
use Apache::loncacc; |
use Apache::loncommon(); |
use Apache::loncommon(); |
use Apache::Log(); |
use Apache::Log(); |
use Apache::lonnet; |
use Apache::lonnet; |
use HTML::Entities(); |
use HTML::Entities(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::lonupload; |
use Apache::lonupload; |
use File::Basename(); |
use File::Basename(); |
|
|
# ---------------------------------------------------------------- Display Control |
# ---------------------------------------------------------------- Display Control |
sub display_control { |
sub display_control { |
Line 222 function colSet(caller) {
|
Line 248 function colSet(caller) {
|
poolForm.elements[caller*5+4].options[2] = new Option("A.","ucperiod",false,false) |
poolForm.elements[caller*5+4].options[2] = new Option("A.","ucperiod",false,false) |
poolForm.elements[caller*5+4].options[3] = new Option("(a)","lcparen",false,false) |
poolForm.elements[caller*5+4].options[3] = new Option("(a)","lcparen",false,false) |
poolForm.elements[caller*5+4].options[4] = new Option("(A)","ucparen",false,false) |
poolForm.elements[caller*5+4].options[4] = new Option("(A)","ucparen",false,false) |
poolForm.elements[caller*5+4].options[5] = new Option("(i)","romparen",false,false) |
poolForm.elements[caller*5+4].options[5] = new Option("a)","lconeparen",false,false) |
poolForm.elements[caller*5+4].options[6] = new Option("i.","romperiod",false,false) |
poolForm.elements[caller*5+4].options[6] = new Option("A)","uconeparen",false,false) |
|
poolForm.elements[caller*5+4].options[7] = new Option("a.)","lcdotparen",false,false) |
|
poolForm.elements[caller*5+4].options[8] = new Option("A.)","ucdotparen",false,false) |
|
poolForm.elements[caller*5+4].options[9] = new Option("(i)","romparen",false,false) |
|
poolForm.elements[caller*5+4].options[10] = new Option("i)","romoneparen",false,false) |
|
poolForm.elements[caller*5+4].options[11] = new Option("i.)","romdotparen",false,false) |
|
poolForm.elements[caller*5+4].options[12] = new Option("i.","romperiod",false,false) |
poolForm.elements[caller*5+4].selectedIndex = 0 |
poolForm.elements[caller*5+4].selectedIndex = 0 |
} |
} |
else { |
else { |
Line 255 function colSet(caller) {
|
Line 287 function colSet(caller) {
|
if (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "TF") { |
if (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "TF") { |
poolForm.elements[caller*5+5].options[0] = new Option("Please Select","-1",true,true) |
poolForm.elements[caller*5+5].options[0] = new Option("Please Select","-1",true,true) |
poolForm.elements[caller*5+5].options[1] = new Option("True or False","word",false,false) |
poolForm.elements[caller*5+5].options[1] = new Option("True or False","word",false,false) |
poolForm.elements[caller*5+5].options[2] = new Option("T or F","lett",false,false) |
poolForm.elements[caller*5+5].options[2] = new Option("true or false","word",false,false) |
|
poolForm.elements[caller*5+5].options[3] = new Option("TRUE or FALSE","word",false,false) |
|
poolForm.elements[caller*5+5].options[4] = new Option("T or F","lett",false,false) |
|
poolForm.elements[caller*5+5].options[5] = new Option("t or f","lett",false,false) |
} |
} |
else { |
else { |
poolForm.elements[caller*5+5].options[0] = new Option("Not required","0",true,true) |
poolForm.elements[caller*5+5].options[0] = new Option("Not required","0",true,true) |
Line 924 END_OF_ONE
|
Line 959 END_OF_ONE
|
$foiltag = $alphabet[$k-1].'.'; |
$foiltag = $alphabet[$k-1].'.'; |
} elsif ($foilformats[$i] eq "lcparen") { |
} elsif ($foilformats[$i] eq "lcparen") { |
$foiltag = '('.$alphabet[$k-1].')'; |
$foiltag = '('.$alphabet[$k-1].')'; |
|
} elsif ($foilformats[$i] eq "lconeparen") { |
|
$foiltag = $alphabet[$k-1].')'; |
|
} elsif ($foilformats[$i] eq "lcdotparen") { |
|
$foiltag = $alphabet[$k-1].'.)'; |
} elsif ($foilformats[$i] eq "ucperiod") { |
} elsif ($foilformats[$i] eq "ucperiod") { |
$foiltag = $alphabet[$k-1].'.'; |
$foiltag = $alphabet[$k-1].'.'; |
$foiltag =~ tr/a-z/A-Z/; |
$foiltag =~ tr/a-z/A-Z/; |
} elsif ($foilformats[$i] eq "ucparen") { |
} elsif ($foilformats[$i] eq "ucparen") { |
$foiltag = '('.$alphabet[$k-1].')'; |
$foiltag = '('.$alphabet[$k-1].')'; |
$foiltag =~ tr/a-z/A-Z/; |
$foiltag =~ tr/a-z/A-Z/; |
|
} elsif ($foilformats[$i] eq "uconeparen") { |
|
$foiltag = $alphabet[$k-1].')'; |
|
$foiltag =~ tr/a-z/A-Z/; |
|
} elsif ($foilformats[$i] eq "ucdotparen") { |
|
$foiltag = $alphabet[$k-1].'.)'; |
|
$foiltag =~ tr/a-z/A-Z/; |
} elsif ($foilformats[$i] eq "romperiod") { |
} elsif ($foilformats[$i] eq "romperiod") { |
$foiltag = $romans[$k-1].'.'; |
$foiltag = $romans[$k-1].'.'; |
} elsif ($foilformats[$i] eq "romparen") { |
} elsif ($foilformats[$i] eq "romparen") { |
$foiltag = '('.$romans[$k-1].')'; |
$foiltag = '('.$romans[$k-1].')'; |
} |
} elsif ($foilformats[$i] eq "romoneparen") { |
|
$foiltag = $romans[$k-1].')'; |
|
} elsif ($foilformats[$i] eq "romdotparen") { |
|
$foiltag = $romans[$k-1].'.)'; |
|
} |
$r->print(qq|$foiltag $multparts{$j}[$k]<br>\n|); |
$r->print(qq|$foiltag $multparts{$j}[$k]<br>\n|); |
} |
} |
} |
} |
Line 1104 sub final_display {
|
Line 1153 sub final_display {
|
for (my $k=$numitems+$start[$i]-1; $k<$numitems+$end[$i]; $k++) { |
for (my $k=$numitems+$start[$i]-1; $k<$numitems+$end[$i]; $k++) { |
@{$answers{$k}} = (); |
@{$answers{$k}} = (); |
if ($qtype[$i] eq "MC") { |
if ($qtype[$i] eq "MC") { |
lc $items[$k]; |
$items[$k] =~ tr/A-Z/a-z/; |
$items[$k] =~ s/\W//g; |
$items[$k] =~ s/\W//g; |
if ($foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod") { |
if ($foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "lconeparen" || $foilformats[$i] eq "lcdotparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod" || $foilformats[$i] eq "uconeparen" || $foilformats[$i] eq "ucdotparen") { |
for (my $j=0; $j<@alphabet; $j++) { |
for (my $j=0; $j<@alphabet; $j++) { |
if ($alphabet[$j] eq $items[$k]) { |
if ($alphabet[$j] eq $items[$k]) { |
push @{$answers{$k}}, $j; |
push @{$answers{$k}}, $j; |
last; |
last; |
} |
} |
} |
} |
} elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod")) { |
} elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod") || ($foilformats[$i] eq "romoneparen") || ($foilformats[$i] eq "romdotparen")) { |
for (my $j=0; $j<@romans; $j++) { |
for (my $j=0; $j<@romans; $j++) { |
if ($romans[$j] eq $items[$k]) { |
if ($romans[$j] eq $items[$k]) { |
push @{$answers{$k}}, $j; |
push @{$answers{$k}}, $j; |
Line 1122 sub final_display {
|
Line 1171 sub final_display {
|
} |
} |
} |
} |
} elsif (($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) { |
} elsif (($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) { |
lc $items[$k]; |
$items[$k] =~ tr/A-Z/a-z/; |
my @corrects = split/$patterns{$ansrtypes[$i]}/,$items[$k]; |
my @corrects = split/$patterns{$ansrtypes[$i]}/,$items[$k]; |
foreach my $correct (@corrects) { |
foreach my $correct (@corrects) { |
$correct =~s/\W//g; |
$correct =~s/\W//g; |
Line 1133 sub final_display {
|
Line 1182 sub final_display {
|
last; |
last; |
} |
} |
} |
} |
} elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod")) { |
} elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod") || ($foilformats[$i] eq "romoneparen") || ($foilformats[$i] eq "romdotparen")) { |
for (my $j=0; $j<@romans; $j++) { |
for (my $j=0; $j<@romans; $j++) { |
if ($romans[$j] eq $correct) { |
if ($romans[$j] eq $correct) { |
push @{$answers{$k}}, $j; |
push @{$answers{$k}}, $j; |
Line 1384 sub file_split {
|
Line 1433 sub file_split {
|
} elsif ($qnumformat eq "trailparen") { |
} elsif ($qnumformat eq "trailparen") { |
$qpattern = '\d{1'.$numpat.'\)'; |
$qpattern = '\d{1'.$numpat.'\)'; |
} |
} |
my @questions = split/[\r\n\f]+\s?$qpattern\s?/,$text_in; |
my @questions = split/[\r\n\f]+\s*$qpattern\s*/,$text_in; |
# my @questions = split/\n\s\d{1,3}\.\s/,$text_in; |
# my @questions = split/\n\s\d{1,3}\.\s/,$text_in; |
shift @questions; |
shift @questions; |
my %multparts = (); |
my %multparts = (); |
Line 1396 sub file_split {
|
Line 1445 sub file_split {
|
$splitstr = '[a-z]\.'; |
$splitstr = '[a-z]\.'; |
} elsif (${$foilsref}[$i] eq "lcparen") { |
} elsif (${$foilsref}[$i] eq "lcparen") { |
$splitstr = '\([a-z]\)'; |
$splitstr = '\([a-z]\)'; |
|
} elsif (${$foilsref}[$i] eq "lconeparen") { |
|
$splitstr = '[a-z]\)'; |
|
} elsif (${$foilsref}[$i] eq "lcdotparen") { |
|
$splitstr = '[a-z]\.\)'; |
} elsif (${$foilsref}[$i] eq "ucperiod") { |
} elsif (${$foilsref}[$i] eq "ucperiod") { |
$splitstr = '[A-Z]\.'; |
$splitstr = '[A-Z]\.'; |
} elsif (${$foilsref}[$i] eq "ucparen") { |
} elsif (${$foilsref}[$i] eq "ucparen") { |
$splitstr = '\([A-Z]\)'; |
$splitstr = '\([A-Z]\)'; |
|
} elsif (${$foilsref}[$i] eq "uconeparen") { |
|
$splitstr = '[A-Z]\)'; |
|
} elsif (${$foilsref}[$i] eq "ucdotparen") { |
|
$splitstr = '[A-Z]\.\)'; |
} elsif (${$foilsref}[$i] eq "romperiod") { |
} elsif (${$foilsref}[$i] eq "romperiod") { |
$splitstr = '[ivx]+\.'; |
$splitstr = '[ivx]+\.'; |
} elsif (${$foilsref}[$i] eq "romparen") { |
} elsif (${$foilsref}[$i] eq "romparen") { |
$splitstr = '\([ivx]+\)'; |
$splitstr = '\([ivx]+\)'; |
|
} elsif (${$foilsref}[$i] eq "romoneparen") { |
|
$splitstr = '[ivx]+\)'; |
|
} elsif (${$foilsref}[$i] eq "romdotparen") { |
|
$splitstr = '[ivx]+\.\)'; |
} |
} |
for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) { |
for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) { |
@{$multparts{$j}} = split/[\r\n\f]+\s?$splitstr\s?/,$questions[$j]; |
@{$multparts{$j}} = split/[\r\n\f]+\s*$splitstr\s*/,$questions[$j]; |
chomp(@{$multparts{$j}}); |
chomp(@{$multparts{$j}}); |
foreach my $foil (@{$multparts{$j}}) { |
|
} |
|
} |
} |
} elsif (${$qtyperef}[$i] eq "FIB") { |
} elsif (${$qtyperef}[$i] eq "FIB") { |
for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) { |
for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) { |
Line 1521 sub create_mcq {
|
Line 1580 sub create_mcq {
|
$tol = 5; |
$tol = 5; |
$numans = $$answerref[0]; |
$numans = $$answerref[0]; |
} else { |
} else { |
my $min = 0; |
my $min = $$answerref[0]; |
my $max = 0; |
my $max = $$answerref[0]; |
for (my $i=0; $i<@{$answerref}; $i++) { |
for (my $i=1; $i<@{$answerref}; $i++) { |
if ($$answerref[$i]<$min) { |
if ($$answerref[$i]<=$min) { |
$min = $$answerref[$i]; |
$min = $$answerref[$i]; |
} elsif ($$answerref[$i] > $max) { |
} elsif ($$answerref[$i] >= $max) { |
$max = $$answerref[$i]; |
$max = $$answerref[$i]; |
} |
} |
} |
} |