[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

API for Edu-Quizzers



I've been productive!

Here is a proposal for an API (a list of recipes for doing Quiz items):
(Like any active teacher, I stole these ideas from various sources.)
What I like about this proposal is that it fits nicely in EDUML inside <rpc>
elements and the recipes are translated into any language in <SCRIPT>
elements below.  This is relatively readable and easy to edit because I use
a standard API format instead of XML elements for the recipes.

This is how it works: An EDUML compliant courseware database contains both
the quiz items and the script snippets that will be used and then a
relatively simple program (30 lines so far in perl) extracts from this
database the questions and recipes and produces on-the-fly a script that
students can use.  Anyone can spend a few hours to write their own quizzer
by simply recycling the data and scripts in any way they want.  Anyone can
add to the database because it works for ultra simple items as well as
cleverly complex composites.

I show here a complete example with math and perl and incomplete examples with
a unit on email literacy: 


    <ITEM level="1"> <!--complete example-->
     <rpc>eduRandom(R1,10)</rpc>
     <rpc>eduRandom(R2,10)</rpc>
     <rpc>eduMath(R3,R1+R2)</rpc>
     </ITEM>
     
    <ITEM level="2"> <!--incomplete--> 
     <rpc sep=",">eduShortanswer(what is 2+2?,4,four)</rpc>
     <rpc>eduMatching(array_questions,array_answers,5)</rpc>
     <rpc>eduShortanswer(what is R1+R2,4,four)</rpc>
     <rpc>eduHash(Qh,email_vocab,email,meaning)</rpc>
     <rpc>eduArray(Qa,email_vocab,email)</rpc>
     <rpc>eduChoiceHash(What is the meaning of Qh ?,email_vocab,4)</rpc>
     <rpc>eduChoiceArray(What is the meaning of Qa ?,email_vocab,4)</rpc>
     <rpc>eduChoiceSimple(What is cc: ?,Carbon Copy,
          Clear Conscience,Core Choice)</rpc>
     <rpc>eduMatching(email_vocab,5)</rpc>
     <rpc>eduPrompt(press enter to continue)</rpc>
     <rpc>eduEmail(instructor,reflection)</rpc>
     <rpc>eduProgram(adventure)</rpc>
     </ITEM>
    </ITEMS>
   </OUTCOME>


<SCRIPTS>
 <SCRIPT lang="perl">
   sub eduRandom {my($R,$max,$min)=@_;
       srand();$scalars .= "\t$R"; 
       ${$R}=int($max*rand($R))
       }
   </SCRIPT>
  <SCRIPT lang="perl"><![CDATA[
   sub eduMath {my($R1,$MATH)=@_; 
       for $s (split(/\t/,$scalars)) { $MATH=~s/$s/$$s/g };
       print "\n$MATH \n"; $answer=eval($MATH);$A=<STDIN>;print $answer  }
       ]]>
   </SCRIPT>
  </SCRIPTS>

 </EDU>

============================================================================

Then a parser like the following can take the above data and produce the
usable perl script which asks arithmetic questions (seen at the very bottom)
(this parser can also convert the EDUML into HTML (not shown here but
viewable on http://cran.seul.org/~vernier/eduml)

#!/bin/sh
case $1 in
 edu2perl) cat >/tmp/essai <<- 'EOF'
	use XML::Parser;
	$p = new XML::Parser(Style => 'stream', ErrorContext => '3');
	$p->parsefile($ARGV[0]);
	sub StartTag { my ($p,$data)=@_; #this is critical for expat context matching 
	  if (/ITEM/) {$level=$_{"level"};}; 
	  if (/TABLE/) {$index=$_{"col"};$name=$_{"id"};}; 
	  if (/COL|ROW|TABLE/) {$sep=$_{"sep"} if $_{"sep"}}; # $_{"attrib"}="value"
	 };
	sub EndTag { my ($p,$data)=@_;
	  print "<insert question here>" if $p->in_element("rpc"); #in_element
	  print "\n" if /rpc|COL/;
	  if (/TABLE/) { $i=0; print "\%$name = \{\n";
	    while ($i++ <= $index) {
	      print "\t\"$cols[$i]\" \=> \"$name{$cols[$i]}\"\,\n" }; 
	    print "\}\;\n\n";
	    ($i,$index,$name,$sep,$cols,$rows)=(); @cols=() }; #reset
	 };
	sub Text { my ($p,$data)=@_;
	  if ($p->in_element("rpc")) {
	      $_=~ s/\,/\"\,\"/g; 
	      $_ =~ s/\(/\(\"/g;
	      $_ =~ s/\)/\"\)\;/g;
	      print $_};
	  $cols = $_ if $p->in_element("COL");
	  $rows = $_ if $p->in_element("ROW");
	  print $_ if $p->in_element("SCRIPT");
	  if ($p->in_element("COL")) {@cols=split(/\Q$sep/,$cols,$index)};#\Q$sep
	  if ($p->in_element("ROW")) {
	    @rows=split(/\Q$sep/,$rows,$index);
	    while ($i++ <= $index) {$name{$cols[$i]}=$rows[$i]}
	    };
	 };
	EOF
	perl /tmp/essai $2 ;;
 esac

==========================================================================

which produces this perl script on the fly:

#!/usr/bin/perl

eduRandom("R1","10");
eduRandom("R2","10");
eduMath("R3","R1+R2");

sub eduRandom {my($R,$max,$min)=@_;
       srand();$scalars .= "\t$R"; 
       ${$R}=int($max*rand($R))
       }
   
sub eduMath {my($R1,$MATH)=@_; 
       for $s (split(/\t/,$scalars)) { $MATH=~s/$s/$$s/g };
       print "\n$MATH \n"; $answer=eval($MATH);$A=<STDIN>;print $answer  }
       
========================================================================

which, I think, is a proof-of-concept that EDUML works!

If you have read this far, and would like to help build an Open Source Open
Content Test-bank/Courseware system, please send comments or recipes or
translate the API into your favorite language.

Bruno