Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Implemented Matching Questions.

  • Loading branch information...
commit a9981ba6194c438aace048e9fc3f8130a3155542 1 parent 94b2713
authored January 13, 2004
24  lang/en/help/quiz/formatgift.html
@@ -2,7 +2,7 @@
2 2
 
3 3
 <p>GIFT is the most comprehensive import format available for importing 
4 4
    Moodle quiz questions from a text file.  It supports Multiple-Choice, 
5  
-   True-False, Short Answer and Numerical questions, as well as insertion 
  5
+   True-False, Short Answer, Matching and Numerical questions, as well as insertion 
6 6
    of a _____ for the Missing Word format.  Various question-types can be 
7 7
    mixed in a single text file, and the format also supports line comments, 
8 8
    question names, feedback and percentage-weight grades.</p>
@@ -39,7 +39,23 @@
39 39
 
40 40
      The sun rises in the east.{T}</pre>
41 41
 
42  
-        <p><u>Numerical:</u><br>
  42
+        <p><u>Matching:</u><br />
  43
+        Matching pairs begin with an equal sign (=) and are seperated by this symbol "->". There must be at least three matching pairs.</p>
  44
+
  45
+<pre>     Matching Question. {
  46
+         =subquestion1 -> subanswer1
  47
+         =subquestion2 -> subanswer2
  48
+         =subquestion3 -> subanswer3
  49
+         }
  50
+     
  51
+     Match the following countries with their corresponding capitals. {
  52
+         =Canada -> Ottawa
  53
+         =Italy  -> Rome
  54
+         =Japan  -> Tokyo
  55
+         =India  -> New Delhi
  56
+         }</pre>
  57
+<p>Matching questions do not support feedback or percentage answer weights.</p>
  58
+        <p><u>Numerical:</u><br />
43 59
             The answer section for Numerical questions must start with a number sign (#). Numerical answers can include an error margin, which is written following the correct answer, seperated by a colon. So for example, if the correct answer is anything between 1.5 and 2.5, then it would be written as follows <u>{#2:0.5}</u>. This indicates that 2 with an error margin of 0.5 is correct (i.e., the span from 1.5 to 2.5). If no error margin is specified, it will be assumed to be zero.</p>
44 60
         <pre>     When was Ulysses S. Grant born? {#1822}
45 61
 
@@ -96,7 +112,7 @@
96 112
      =%25%Bethlehem#He was born here, but not raised here.}</pre>
97 113
 <p>Note that the last two examples are essentially the same question, first as multiple choice and then as short answer.</p>
98 114
 
99  
-<p><small>Note that it is possible to specify percentage answer weights that are NOT available through the browser interface. Such answer-weights will calculate correctly (according to the value assigned when imported), and will appear normal to students taking the test. But such answer-weights will not display correctly to teachers when editing them through Moodle's Edit Question interface. The pull-down menu only allows certain fixed values, and if the answer-weight does not exactly match one of those predetermined values, then it will not display correctly. If you edit such a question through the browser interface, the answer weight will change to that displayed.</small></p>
  115
+<p><font size="-1">Note that it is possible to specify percentage answer weights that are NOT available through the browser interface. Such answer-weights will calculate correctly (according to the value assigned when imported), and will appear normal to students taking the test. But such answer-weights will not display correctly to teachers when editing them through Moodle's Edit Question interface. The pull-down menu only allows certain fixed values, and if the answer-weight does not exactly match one of those predetermined values, then it will not display correctly. If you edit such a question through the browser interface, the answer weight will change to that displayed.</font></p>
100 116
 
101 117
 <p><u>Multiple Answers:</u><br />
102 118
 The Multiple Answers option is used for multiple choice questions when two or more answers must be selected in order to obtain full credit. The multiple answers option is enabled by assigning partial answer weight to multiple answers, while allowing no single answer to receive full credit.</p>
@@ -123,4 +139,4 @@
123 139
 <p></p>
124 140
 <h3>CREDITS</h3>
125 141
 <p>This filter was written through the collaboration of numerous members of the Moodle community. It was originally based on the missingword format, which included code from Martin Dougiamas, Thomas Robb and others. Paul Tsuchido Shew wrote this filter in December 2003 incorporating community suggestions for a more robust question format. The name was conceived as an acronym for  &quot;General Import Format Technology&quot; or something like that, but it's too long for a simple filter like this, so it just GIFT.</p>
126  
-        <p><small>GIFT documentation by Paul Tsuchido Shew, 10 Jan 2004.</small></p>
  142
+        <p><font size="-1">GIFT documentation by Paul Tsuchido Shew, 13 Jan 2004.</font></p>
34  mod/quiz/format/gift/examples.txt
@@ -52,6 +52,21 @@ The sun rises in the east.{T}
52 52
 
53 53
 // ===Numerical===
54 54
 
  55
+Matching Question. {
  56
+    =subquestion1 -> subanswer1
  57
+    =subquestion2 -> subanswer2
  58
+    =subquestion3 -> subanswer3
  59
+    }
  60
+    
  61
+Match the following countries with their corresponding capitals. {
  62
+    =Canada -> Ottawa
  63
+    =Italy  -> Rome
  64
+    =Japan  -> Tokyo
  65
+    =India  -> New Delhi
  66
+    }
  67
+
  68
+// ===Numerical===
  69
+
55 70
 When was Ulysses S. Grant born? {#1822}
56 71
 
57 72
 What is the value of pi (to 3 decimal places)? {#3.1415:0.0005}.
@@ -123,6 +138,23 @@ What two people are entombed in Grant's tomb? {
123 138
 //     EXAMPLES FROM gift/format.php
124 139
 //-----------------------------------------//
125 140
 
  141
+Who's buried in Grant's tomb?{~Grant ~Jefferson =no one}
  142
+
  143
+Grant is {~buried =entombed ~living} in Grant's tomb.
  144
+
  145
+Grant is buried in Grant's tomb.{FALSE}
  146
+
  147
+Who's buried in Grant's tomb?{=no one =nobody}
  148
+
  149
+When was Ulysses S. Grant born?{#1822:5}
  150
+
  151
+Match the following countries with their corresponding
  152
+capitals.{=Canada->Ottawa =Italy->Rome =Japan->Tokyo}
  153
+
  154
+//-----------------------------------------//
  155
+//     MORE COMPLICATED EXAMPLES
  156
+//-----------------------------------------//
  157
+
126 158
 ::Grant's Tomb::Grant is {
127 159
       ~buried#No one is buried there.
128 160
       =entombed#Right answer!
@@ -146,4 +178,4 @@ When was Ulysses S. Grant born? {#
146 178
      =1822:0      #Correct! 100% credit
147 179
      =%50%1822:2  #He was born in 1822.
148 180
                   You get 50% credit for being close.
149  
-}
  181
+}
89  mod/quiz/format/gift/format.php
... ...
@@ -1,12 +1,9 @@
1 1
 <?php // $Id$
2 2
 //
3 3
 ///////////////////////////////////////////////////////////////
4  
-// GIFT
5  
-//
6  
-// The GIFT import filter is an easy to use method for teachers 
7  
-// writing questions as a text file. It supports true-false, 
8  
-// short answer, multiple-choice and numerical questions, as well 
9  
-// as insertion of a blank line for the missing word format.
  4
+// The GIFT import filter was designed as an easy to use method 
  5
+// for teachers writing questions as a text file. It supports most
  6
+// question types and the missing word format.
10 7
 //
11 8
 // Multiple Choice / Missing Word
12 9
 //     Who's buried in Grant's tomb?{~Grant ~Jefferson =no one}
@@ -17,39 +14,16 @@
17 14
 //     Who's buried in Grant's tomb?{=no one =nobody}
18 15
 // Numerical
19 16
 //     When was Ulysses S. Grant born?{#1822:5}
  17
+// Matching
  18
+//     Match the following countries with their corresponding
  19
+//     capitals.{=Canada->Ottawa =Italy->Rome =Japan->Tokyo}
20 20
 //
21 21
 // Comment lines start with a double backslash (//). 
22 22
 // Optional question names are enclosed in double colon(::). 
23 23
 // Answer feedback is indicated with hash mark (#).
24 24
 // Percentage answer weights immediately follow the tilde (for
25 25
 // multiple choice) or equal sign (for short answer and numerical),
26  
-// and are enclosed in percent signs (% %). Below are more
27  
-// complicated examples with various options and formatting styles.
28  
-// 
29  
-//     ::Grant's Tomb::Grant is {
30  
-//         ~buried#No one is buried there.
31  
-//         =entombed#Right answer!
32  
-//         ~living#We hope not!
33  
-//     } in Grant's tomb.
34  
-//
35  
-//     Difficult multiple choice question.{
36  
-//         ~wrong answer           #comment on wrong answer
37  
-//         ~%50%half credit answer #comment on answer
38  
-//         =full credit answer     #well done!}
39  
-//
40  
-//     ::Jesus' hometown (Short answer ex.):: Jesus Christ was from {
41  
-//         =Nazareth#Yes! That's right!
42  
-//         =%75%Nazereth#Right, but misspelled.
43  
-//         =%25%Bethlehem#He was born here, but not raised here.
44  
-//     }.
45  
-//
46  
-//     //comment about questions below (this line ignored by filter)
47  
-//     ::Numerical example::
48  
-//     When was Ulysses S. Grant born? {#
49  
-//         =1822:0      #Correct! 100% credit
50  
-//         =%50%1822:2  #He was born in 1822.
51  
-//                       You get 50% credit for being close.
52  
-//      }
  26
+// and are enclosed in percent signs (% %). See docs and examples.txt for more.
53 27
 // 
54 28
 // This filter was written through the collaboration of numerous 
55 29
 // members of the Moodle community. It was originally based on 
@@ -164,10 +138,15 @@ function readquestion($lines) {
164 138
         if ($answertext{0} == "#"){
165 139
             $question->qtype = NUMERICAL;
166 140
 
167  
-        } elseif (strstr($answertext, "~") !== false)  {
  141
+        } elseif (strpos($answertext, "~") !== false)  {
168 142
             // only Multiplechoice questions contain tilde ~
169 143
             $question->qtype = MULTICHOICE;
170 144
     
  145
+        } elseif (strpos($answertext, "=")  !== false 
  146
+              AND strpos($answertext, "->") !== false) {
  147
+              // only Matching contains both = and ->
  148
+            $question->qtype = MATCH;
  149
+
171 150
         } else { // either TRUEFALSE or SHORTANSWER
172 151
     
173 152
             // TRUEFALSE question check
@@ -244,6 +223,48 @@ function readquestion($lines) {
244 223
                 $question->image = "";   // No images with this format
245 224
                 return $question;
246 225
                 break;
  226
+
  227
+            case MATCH:
  228
+                $answers = explode("=", $answertext);
  229
+                if (isset($answers[0])) {
  230
+                    $answers[0] = trim($answers[0]);
  231
+                }
  232
+                if (empty($answers[0])) {
  233
+                    array_shift($answers);
  234
+                }
  235
+    
  236
+                $countanswers = count($answers);
  237
+                if ($countanswers < 3) {
  238
+                    if ($this->displayerrors) {
  239
+                        echo "<P>$text<P>Found markers for Matching format 
  240
+                            (= and ->), but too few answers -- must be at least 3.<br />
  241
+                            Found <u>$countanswers</u> answers in answertext.";
  242
+                    }
  243
+                    return false;
  244
+                    break;
  245
+                }
  246
+    
  247
+                foreach ($answers as $key => $answer) {
  248
+                    $answer = trim($answer);
  249
+                    if (strpos($answer, "->") <= 0) {
  250
+                        if ($this->displayerrors) {
  251
+                        echo "<P>$text<P>Error processing Matching question.<br />
  252
+                            Improperly formatted answer: $answer";
  253
+                        }
  254
+                        return false;
  255
+                        break 2;
  256
+                    }
  257
+
  258
+                    $marker = strpos($answer,"->");
  259
+                    $question->subquestions[$key] = addslashes(trim(substr($answer, 0, $marker)));
  260
+                    $question->subanswers[$key]   = addslashes(trim(substr($answer, $marker+2)));
  261
+
  262
+                }  // end foreach answer
  263
+    
  264
+                $question->defaultgrade = 1;
  265
+                $question->image = "";   // No images with this format
  266
+                return $question;
  267
+                break;
247 268
             
248 269
             case TRUEFALSE:
249 270
                 $answer = $answertext;

0 notes on commit a9981ba

Please sign in to comment.
Something went wrong with that request. Please try again.