[system] / trunk / webwork / system / courseScripts / AnswerHash.pm Repository:
ViewVC logotype

Diff of /trunk/webwork/system/courseScripts/AnswerHash.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 292 Revision 293
1########################################################################## 1##########################################################################
2## AnswerHash Package 2## AnswerHash Package
3## 3##
4## Provides a data structure for answer hashes. Currently just a wrapper 4## Provides a data structure for answer hashes. Currently just a wrapper
5## for the hash, but that might change 5## for the hash, but that might change
6####################################################################
7# Copyright @ 1995-2002 WeBWorK Team
8# All Rights Reserved
9####################################################################
10#$Id$
6 11
7=pod 12=head1 NAME
8 13
9For the most part AnswerHash is an object which contains data. It has only a few methods. 14 AnswerHash.pl -- located in the courseScripts directory
10The data which is automatically initiallized by the constructor new is given here: 15
16 This file contains the packages/classes:
17 AnswerHash and AnswerEvaluator
11 18
12 $new_answer_hash = { 'score' => 0, 19=head1 SYNPOSIS
13 'correct_ans' => "No correct answer specified", 20
14 'student_ans' => undef, 21 AnswerHash -- this class stores information related to the student's
15 'original_student_ans', => undef, 22 answer. It is little more than a standard perl hash with
16 'type' => 'Undefined answer evaluator type', 23 a special name, butit does have some access and
24 manipulation methods. More of these may be added as it
25 becomes necessary.
26
27 Usage: $rh_ans = new AnswerHash;
28
29 AnswerEvaluator -- this class organizes the construction of
30 answer evaluator subroutines which check the
31 student's answer. By plugging filters into the
32 answer evaluator class you can customize the way the
33 student's answer is normalized and checked. Our hope
34 is that with properly designed filters, it will be
35 possible to reuse the filters in different
36 combinations to obtain different answer evaluators,
37 thus greatly reducing the programming and maintenance
38 required for constructing answer evaluators.
39
40=cut
41
42=head1 DESCRIPTION
43
44The answer hash class is guaranteed to contain the following instance variables:
45
46 score => $correctQ,
47 correct_ans => $originalCorrEqn,
48 student_ans => $modified_student_ans
49 original_student_ans => $original_student_answer,
50 ans_message => $PGanswerMessage,
51 type => 'typeString',
52 preview_text_string => $preview_text_string,
53 preview_latex_string => $preview_latex_string
54
55
56 $ans_hash->{score} -- a number between 0 and 1 indicating
57 whether the answer is correct. Fractions
58 allow the implementation of partial
59 credit for incorrect answers.
60
61 $ans_hash->{correct_ans} -- The correct answer, as supplied by the
62 instructor and then formatted. This can
63 be viewed by the student after the answer date.
64
65 $ans_hash->{student_ans} -- This is the student answer, after reformatting;
66 for example the answer might be forced
67 to capital letters for comparison with
68 the instructors answer. For a numerical
69 answer, it gives the evaluated answer.
70 This is displayed in the section reporting
71 the results of checking the student answers.
72
73 $ans_hash->{original_student_ans} -- This is the original student answer. This is displayed
74 on the preview page and may be used for sticky answers.
75
76 $ans_hash->{ans_message} -- Any error message, or hint provided by the answer evaluator.
77 This is also displayed in the section reporting
78 the results of checking the student answers.
79
80 $ans_hash->{type} -- A string indicating the type of answer evaluator. This
81 helps in preprocessing the student answer for errors.
82 Some examples:
83 'number_with_units'
84 'function'
85 'frac_number'
86 'arith_number'
87
88
89 $ans_hash{preview_text_string} -- This typically shows how the student answer was parsed. It is
90 displayed on the preview page. For a student answer of 2sin(3x)
91 this would be 2*sin(3*x). For string answers it is typically the
92 same as $ans_hash{student_ans}.
93
94
95 $ans_hash{preview_latex_string} -- THIS IS OPTIONAL. This is latex version of the student answer
96 which is used to show a typeset view on the answer on the preview
97 page. For a student answer of 2/3, this would be \frac{2}{3}.
98
17 'ans_message' => '', 99 'ans_message' => '',
18 100
19 'preview_text_string' => undef, 101 'preview_text_string' => undef,
20 'preview_latex_string' => undef, 102 'preview_latex_string' => undef,
21 'error_flag' => undef, 103 'error_flag' => undef,
22 'error_message' => '', 104 'error_message' => '',
23
24 };
25
26 105
27 106
28Methods: 107Methods:
29 new 108
109 new
30 110
31 setKeys $rh_ans->setKeys{score=>1}; Sets elements in the AnswerHash. 111 setKeys $rh_ans->setKeys(score=>1, student_answer => "yes");
32 There is a check to make sure that the 112 Sets standard elements in the AnswerHash (the ones defined
33 key is one of the values listed above. 113 above).
34 114
115
35 $rh_ans->{non_standard_value} = 'oops'; 116 $rh_ans->{non_standard_value} = 'oops';
36 Add an element to the AnswerHash. 117 Add an element to the AnswerHash or replace that element. (No
37 No checks are made. Can be used (cautiously) 118 checks are made, use wisely!)
38 to customize and extend the AnswerHash type. 119 OR($rh_ans)
39 120
40 OR 121 AND($rh_ans)
41 122
42 AND 123 data
124 input
125
126 score
127
128 throw_error
129
130 catch_error
131
132 clear_error
133
134 error_flag
135
136 error_message
137
138 pretty_print
139
43 140
44=cut 141=cut
45 142
46BEGIN { 143BEGIN {
47 be_strict(); # an alias for use strict. This means that all global variable must contain main:: as a prefix. 144 be_strict(); # an alias for use strict. This means that all global variable must contain main:: as a prefix.

Legend:
Removed from v.292  
changed lines
  Added in v.293

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9