[LON-CAPA-cvs] cvs: modules /gerd/ie ietrans.pl

www lon-capa-cvs@mail.lon-capa.org
Sat, 02 Apr 2005 17:38:34 -0000


www		Sat Apr  2 12:38:34 2005 EDT

  Modified files:              
    /modules/gerd/ie	ietrans.pl 
  Log:
  Translator - seems to work for sample question provided.
  
  
Index: modules/gerd/ie/ietrans.pl
diff -u modules/gerd/ie/ietrans.pl:1.1 modules/gerd/ie/ietrans.pl:1.2
--- modules/gerd/ie/ietrans.pl:1.1	Sat Apr  2 11:07:58 2005
+++ modules/gerd/ie/ietrans.pl	Sat Apr  2 12:38:34 2005
@@ -1,5 +1,5 @@
 # Translation program for IEs.
-# $Id: ietrans.pl,v 1.1 2005/04/02 16:07:58 www Exp $
+# $Id: ietrans.pl,v 1.2 2005/04/02 17:38:34 www Exp $
 #
 # Usage: perl ietrans.pl filename
 #
@@ -46,12 +46,22 @@
 my $answer='';
 my @optiontext=();
 my @optionvalue=();
+my @hints=();
+my @foilid=();
+my $idcounter=0;
+my $partid=0;
 #
 # Setup LON-CAPA headers
 #
-print <<ENDHEADERS;
+print <<'ENDHEADERS';
 <problem>
-<import>/res/msu/kortemey/physicslib/ie.library</import>
+<script type="loncapa/perl">
+sub solved {
+    my ($partID)=@_;
+    my $status=&EXT("user.resource.resource.$partID.solved");
+    return ($status =~ /^correct/);
+}
+</script>
 ENDHEADERS
 #
 # Main loop: look for tokens
@@ -71,12 +81,12 @@
         &pushoption('true',$line);
     } elsif ($line=~/^\s*wrong/) {
         &pushoption('false',$line);
+    } elsif ($line=~/^\s*say/) {
+        &say($line);
     } elsif ($line=~/^\s*radio/) {
         &makeradio($line);
     } elsif ($line=~/^\s*pause/) {
         &makepause($line);
-    } elsif ($line=~/^\s*say/) {
-        &say($line);
     } elsif ($line=~/^\s*\#/) {
         &comment($line);
     } elsif ($line!~/\w/) {
@@ -87,7 +97,7 @@
     }
 }
 &endquestion();
-print "\n<problem>\n";
+print "\n</problem>\n";
 #
 # Done
 #
@@ -156,17 +166,17 @@
 # produce outtext from string
 #
 sub say {
-    print "\n<startouttext />\n".&get_all_string(shift)."\n<endouttext />\n";
+    $hints[$#optionvalue]=&get_all_string(shift);
 }
 #
 # End last question, if there was one
 #
 sub endquestion {
     if ($insideaquestion) {
+	print "\n</part>\n";
 	if ($rootproblemasked) {
-	    print "\n<\\followupifpreviouscorrect>\n";
+	    print "\n</block>";
         } else {
-	    print "\n<\\rootproblem>\n";
             $rootproblemasked=1;
 	}
     }
@@ -179,11 +189,11 @@
     &endquestion();
     $insideaquestion=1;
     if ($rootproblemasked) {
-	print "\n<followupifpreviouscorrect>\n";
-    } else {
-        print "\n<rootproblem>";
+	print "\n<block condition='&solved($partid)'>\n";
     }
-    &say(shift);
+    $partid++;
+    print "\n<part id='$partid'>";
+    print "\n<startouttext />\n".&get_all_string(shift)."\n<endouttext />\n";
 }
 #
 # push option for radio response
@@ -191,7 +201,7 @@
 sub pushoption {
     my ($value,$text)=@_;
     push @optionvalue,$value;
-    push @optiontext,&say($text);
+    push @optiontext,&get_all_string($text);
 }
 #
 # Remember a global
@@ -204,16 +214,75 @@
     if ($what eq 'answer') { $answer=$value; }
 }
 
+sub makefoil {
+    my ($i,$value,$text)=@_;
+    $idcounter++;
+    print <<ENDFOIL;
+<foil name='foil$idcounter' value='$value'>
+<startouttext />$text<endouttext />
+</foil>
+ENDFOIL
+    $foilid[$i]="foil$idcounter";
+}
+
 sub makeradio {
+    $idcounter++;
+    print <<ENDRADIOHEADER;
+<radiobuttonresponse max="99" id="radio$idcounter" randomize="no">
+<foilgroup>
+ENDRADIOHEADER
+   for (my $i=0;$i<=$#optionvalue;$i++) {
+       &makefoil($i,$optionvalue[$i],$optiontext[$i]);
+   }
+   print "</foilgroup>\n";
+# Do we have hints?
+    if ($#hints>=0) {
+       print "<hintgroup showoncorrect='yes'>\n";
+# Generate hint conditions
+       for (my $i=0;$i<=$#optionvalue;$i++) {
+	   $idcounter++;
+	   print <<ENDHINTCOND;
+<radiobuttonhint answer="('foil','$foilid[$i]')" name="hinton$foilid[$i]" />
+ENDHINTCOND
+   }
+# Generate hint parts
+       for (my $i=0;$i<=$#optionvalue;$i++) {
+	   $idcounter++;
+	   print <<ENDHINTPART;
+<hintpart on="hinton$foilid[$i]" />
+<startouttext />$hints[$i]<endouttext />
+</hintpart>
+ENDHINTPART
+       }
+       print "</hintgroup>";
+   }
+# Done
+   print "\n</radiobuttonresponse>\n";
+   @optionvalue=();
+   @optiontext=();
+   @hints=();
 }
 
 sub makenumerical {
+    $idcounter++;
+    print <<ENDNUMERICAL;
+<numericalresponse answer="$answer" unit="$unit" id="num$idcounter">
+<textline />
+<responseparam name="tol" default="1%" type="tolerance" description="Numerical Tolerance" />
+</numericalresponse>
+ENDNUMERICAL
 }
 
 sub makepause {
+    $optionvalue[0]='true';
+    $optiontext[0]='I have read this';
+    @hints=();
+    &makeradio();
 }
 
 sub script {
+    my $text=shift;
+    print "\n<script type='loncapa/perl'>\n$text</script\>\n";
 }
 
 sub comment {