Skip to content

Commit

Permalink
SAM-2534 SamLite: randomize answers in multiple choice questions
Browse files Browse the repository at this point in the history
  • Loading branch information
annuelo committed Apr 8, 2015
1 parent 6a5e5c8 commit e0607be
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Question {
private String questionTypeAsString;
private String feedbackOK;
private String feedbackNOK;
private boolean randomize;

public Question() {
this.questionNumber = 0;
Expand All @@ -45,6 +46,7 @@ public Question() {
this.hasPoints = false;
this.hasDiscount = false;
this.questionTypeAsString = "";
this.randomize = false;
}

public void addAnswer(String id, String text, boolean isCorrect) {
Expand Down Expand Up @@ -175,6 +177,14 @@ public String getQuestionTypeAsString() {
public void setQuestionTypeAsString(String questionTypeAsString) {
this.questionTypeAsString = questionTypeAsString;
}

public boolean isRandomize() {
return randomize;
}

public void setRandomize(boolean randomize) {
this.randomize = randomize;
}

public String getFeedbackOK() {
return feedbackOK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ general_instructions_conclude=The text of the question itself may be placed on t
general_instructions_feedback=To add correct feedback you need to add a line like this: '#FBOK: Text of the correct feedback'. In case of Incorrect feedback the line must be '#FBNOK: Text of the incorrect feedback'.

example_mc_label=Multiple Choice
example_mc_instructions=Each answer should begin with its appropriate letter, in alphabetical order. The correct answer should be prefixed with an asterisk (*).
example_mc_instructions=Each answer should begin with its appropriate letter, in alphabetical order. The correct answer should be prefixed with an asterisk (*).
example_mc_instructions_1=Optionally, the key word \#randomize will create questions with randomized answers
example_mc_question_format1=Question 1 (10 points) (2.5 discount)
example_mc_question_format2=Question (10 points) (2.5 discount)
example_mc_question_format3=Question 1
Expand All @@ -30,10 +31,12 @@ example_mc_question_text=Who was the first president of the United States?
example_mc_answer_a=*a. Washington
example_mc_answer_b=b. Jefferson
example_mc_answer_c=c. Lincoln
example_mc_answer_d=d. Clinton
example_mc_answer_d=d. Clinton
example_mc_question_random=\#randomize

example_mcmc_label=Multiple Correct Answer
example_mcmc_instructions=Each answer should begin with its appropriate letter, in alphabetical order. The correct answer should be prefixed with an asterisk (*).
example_mcmc_instructions_1=Optionally, the key word \#randomize will create questions with randomized answers
example_mcmc_question_format1=Question 2 (15 points)
example_mcmc_question_format2=Question (15 points)
example_mcmc_question_format3=Question 2
Expand All @@ -42,7 +45,8 @@ example_mcmc_question_format5=2.
example_mcmc_question_text=Which of the writers below were American citizens at some point in their lives?
example_mcmc_answer_a=*a. Bill Faulkner
example_mcmc_answer_b=b. Ginny Woolf
example_mcmc_answer_c=*c. Tom Eliot
example_mcmc_answer_c=*c. Tom Eliot
example_mcmc_question_random=\#randomize

example_fib_label=Fill in the Blank
example_fib_instructions=The correct answer should be prefixed with an asterisk (*).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ general_instructions_format5=Un n\u00famero, seguit d'un punt, de manera que s'
general_instructions_conclude=El text de la pregunta es pot posar a la mateixa l\u00ednia o sota d'ella, i l'han de seguir les respostes en el format apropiat pel tipus de q\u00fcesti\u00f3. L'int\u00e8rpret usar\u00e0 aquest format per a deduir de quin tipus \u00e9s la pregunta.

example_mc_label=Selecci\u00f3 m\u00faltiple
example_mc_instructions=Cada resposta ha de comen\u00e7ar amb la lletra apropiada, en ordre alfab\u00e8tic. La resposta correcta ha de dur al davant un asterisc(*).
example_mc_instructions=Cada resposta ha de comen\u00e7ar amb la lletra apropiada, en ordre alfab\u00e8tic. La resposta correcta ha de dur al davant un asterisc(*).
example_mc_instructions_1=Opcionalment, la paraula clau \#aleatorizar crear\u00e0 preguntes amb les respostes aleatorizades
example_mc_question_format1=Pregunta 1 (10 punts) (2.5 descompte)
example_mc_question_format2=Pregunta (10 punts) (2.5 descompte)
example_mc_question_format3=Pregunta 1
Expand All @@ -31,9 +32,11 @@ example_mc_answer_a=*a. Washington
example_mc_answer_b=b. Jefferson
example_mc_answer_c=c. Lincoln
example_mc_answer_d=d. Clinton
example_mc_question_random=\#aleatorizar

example_mcmc_label=Resposta correcta m\u00faltiple
example_mcmc_instructions=Cada resposta ha de comen\u00e7ar amb la lletra apropiada, en ordre alfab\u00e8tic. La resposta correcta ha de dur al davant un asterisc (*).
example_mcmc_instructions_1=Opcionalment, la paraula clau \#aleatorizar crear\u00e0 preguntes amb les respostes aleatorizades
example_mcmc_question_format1=Pregunta 2 (15 punts)
example_mcmc_question_format2=Pregunta (15 punts)
example_mcmc_question_format3=Pregunta 2
Expand All @@ -43,6 +46,7 @@ example_mcmc_question_text=Quins dels seg\u00fcents escriptors \n eren ciutadans
example_mcmc_answer_a=*a. Bill Faulkner
example_mcmc_answer_b=b. Ginny Woolf
example_mcmc_answer_c=*c. Tom Eliot
example_mcmc_question_random=\#aleatorizar

example_fib_label=Ompliu l'espai en blanc
example_fib_instructions=La resposta correcta ha de dur al davant un asterisc (*).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ general_instructions_conclude=El texto de la pregunta se debe situar en la \nmis
general_instructions_feedback=Para a\u00f1adir comentarios en caso de respuesta correcta se necesita a\u00f1adir una l\u00ednea como esta\: '\#FBOK\: Texto del comentario correcto'. En caso de comentario de respuesta incorrecta, la l\u00ednea debe ser '\#FBNOK\: Texto del comentario incorrecto'.

example_mc_label=Selecci\u00f3n M\u00faltiple
example_mc_instructions=Cada respuesta debe comenzar con su letra apropiada, en \norden alfab\u00e9tico. La respuesta correcta vendr\u00e1 precedida de un asterisco (*).
example_mc_instructions=Cada respuesta debe comenzar con su letra apropiada, en \norden alfab\u00e9tico. La respuesta correcta vendr\u00e1 precedida de un asterisco (*).
example_mc_instructions_1=Opcionalmente, la palabra clave \#aleatorizar crear\u00e1 preguntas con las respuestas aleatorizadas
example_mc_question_format1=Pregunta 1 (10 puntos) (2.5 descuento)
example_mc_question_format2=Pregunta (10 puntos) (2.5 descuento)
example_mc_question_format3=Pregunta 1
Expand All @@ -31,9 +32,11 @@ example_mc_answer_a=*a. Cristobal Col\u00f3n
example_mc_answer_b=b. Hernan Cort\u00e9s
example_mc_answer_c=c. Carlo Magno
example_mc_answer_d=d. Julio C\u00e9sar
example_mc_question_random=\#aleatorizar

example_mcmc_label=M\u00faltiple respuesta correcta
example_mcmc_instructions=Cada respuesta debe comenzar por sus letra apropiada, en \norden alfab\u00e9tico. La respuestas correctas deben ir precedidas de un asterisco (*).
example_mcmc_instructions_1=Opcionalmente, la palabra clave \#aleatorizar crear\u00e1 preguntas con las respuestas aleatorizadas
example_mcmc_question_format1=Pregunta 2 (15 puntos)
example_mcmc_question_format2=Pregunta (15 puntos)
example_mcmc_question_format3=Pregunta 2
Expand All @@ -43,6 +46,7 @@ example_mcmc_question_text=\u00bfCuales de los siguientes escritores \n\n fueron
example_mcmc_answer_a=*a. Camilo Jos\u00e9 Cela
example_mcmc_answer_b=b. William Shakespeare
example_mcmc_answer_c=*c. Miguel de Unamuno
example_mcmc_question_random=\#aleatorizar

example_fib_label=Completar los espacios en blanco
example_fib_instructions=La respuesta correcta debe ir precedida de un asterisco (*).
Expand Down
12 changes: 9 additions & 3 deletions samigo/samigo-app/src/webapp/jsf/samlite/samLiteEntry.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,34 @@
<td align="left" valign="top">
<a href="javascript:toggleLayer('example_mc_question');"><h:outputText value="#{samLiteMessages.example_mc_label}"/></a>
<div id="example_mc_question" class="inopPanel" style="display:none">
<strong><h:outputText value="#{samLiteMessages.example_instruction_label}"/></strong><h:outputText value="#{samLiteMessages.example_mc_instructions}"/><p/>
<strong><h:outputText value="#{samLiteMessages.example_instruction_label}"/></strong>
<h:outputText value="#{samLiteMessages.example_mc_instructions}"/><br/>
<h:outputText value="#{samLiteMessages.example_mc_instructions_1}"/><p/>
<strong><h:outputText value="#{samLiteMessages.example_example_label}"/></strong><br/>
<h:outputText value="#{samLiteMessages.example_mc_question_format4}"/><br/>
<h:outputText value="#{samLiteMessages.example_mc_question_text}"/><p/>
<h:outputText value="#{samLiteMessages.example_mc_answer_a}"/><br/>
<h:outputText value="#{samLiteMessages.example_mc_answer_b}"/><br/>
<h:outputText value="#{samLiteMessages.example_mc_answer_c}"/><br/>
<h:outputText value="#{samLiteMessages.example_mc_answer_d}"/>
<h:outputText value="#{samLiteMessages.example_mc_answer_d}"/><br/>
<h:outputText value="#{samLiteMessages.example_mc_question_random}"/>
</div>
</td>
</tr>
<tr>
<td align="left" valign="top">
<a href="javascript:toggleLayer('example_mcmc_question');"><h:outputText value="#{samLiteMessages.example_mcmc_label}"/></a>
<div id="example_mcmc_question" class="inopPanel" style="display:none">
<strong><h:outputText value="#{samLiteMessages.example_instruction_label}"/></strong><h:outputText value="#{samLiteMessages.example_mcmc_instructions}"/><p/>
<strong><h:outputText value="#{samLiteMessages.example_instruction_label}"/></strong>
<h:outputText value="#{samLiteMessages.example_mcmc_instructions}"/><br/>
<h:outputText value="#{samLiteMessages.example_mcmc_instructions_1}"/><p/>
<strong><h:outputText value="#{samLiteMessages.example_example_label}"/></strong><br/>
<h:outputText value="#{samLiteMessages.example_mcmc_question_format4}"/><br/>
<h:outputText value="#{samLiteMessages.example_mcmc_question_text}"/><p/>
<h:outputText value="#{samLiteMessages.example_mcmc_answer_a}"/><br/>
<h:outputText value="#{samLiteMessages.example_mcmc_answer_b}"/><br/>
<h:outputText value="#{samLiteMessages.example_mcmc_answer_c}"/><br/>
<h:outputText value="#{samLiteMessages.example_mcmc_question_random}"/><br/>
</div>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
question=Question
points=point(s?)
discount=discount(s?)
randomize=\#randomize
save_answer=Save answer
true=True
false=False
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ discount=Descompte(s?)
save_answer=Desa la resposta
true=Veritat
false=Fals
randomize=\#aleatorizar

Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ discount=Descuento(s?)
save_answer=Guardar la respuesta
true=Verdadero
false=Falso
randomize=\#aleatorizar
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@
import org.sakaiproject.tool.assessment.samlite.api.SamLiteService;
import org.sakaiproject.tool.assessment.services.assessment.AssessmentService;
import org.sakaiproject.tool.assessment.data.dao.assessment.AssessmentMetaData;
import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemMetaDataIfc;
import org.w3c.dom.Document;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.util.ResourceLoader;

public class SamLiteServiceImpl implements SamLiteService {
private static Log log = LogFactory.getLog(SamLiteServiceImpl.class);
public static final String DEFAULT_CHARSET = "UTF-8";
private static ResourceLoader rb = new ResourceLoader("org.sakaiproject.tool.assessment.bundle.SamLitePatternMessages");

private Pattern justQuestionPattern, startOfQuestionPattern, correctAnswerPattern;
private Pattern correctFillInPattern, answerPattern, endQuestionPattern, correctMultipleChoicePattern;
Expand All @@ -76,6 +78,7 @@ public class SamLiteServiceImpl implements SamLiteService {
private Pattern pointsPattern;
private Pattern discountPattern;
String realPatternString = "((\\+||\\-)?(\\d+((\\.|\\,)\\d+)?)((E|e)(\\-|\\+)?\\d+)?)";
private Pattern randomizePattern;

private Pattern extendedMatchingCorrectAnswersPattern;

Expand Down Expand Up @@ -173,7 +176,6 @@ private String removeMatchedPattern(Matcher m) {


public QuestionGroup parse(String name, String description, String data) {
ResourceLoader rb = new ResourceLoader("org.sakaiproject.tool.assessment.bundle.SamLitePatternMessages");
String stQuestion = rb.getString("question");
startOfQuestionPattern = Pattern.compile("^(" + stQuestion + "\\s*\\d*\\s*)", Pattern.CASE_INSENSITIVE);
String stPoints = rb.getString("points");
Expand All @@ -188,6 +190,8 @@ public QuestionGroup parse(String name, String description, String data) {
correctFalsePattern = Pattern.compile("^\\*\\s*" + stFalse + "$");
unnecessaryTruePattern = Pattern.compile("^" + stTrue + "$");
unnecessaryFalsePattern = Pattern.compile("^" + stFalse + "$");
String txtRandomize = rb.getString("randomize", "#randomize");
randomizePattern = Pattern.compile("^" + txtRandomize + "$", Pattern.CASE_INSENSITIVE);

QuestionGroup questionGroup = new QuestionGroup(name, description);

Expand Down Expand Up @@ -269,6 +273,7 @@ private void parseLine(Question question, String line) {
boolean hasfeedbackOK = feedbackOKMatcher.find();
Matcher feedbackNOKMatcher = feedbackNOKPattern.matcher(line);
boolean hasfeedbackNOK = feedbackNOKMatcher.find();
boolean randomize = randomizePattern.matcher(line).find();

boolean isEMICorrectAnswer = extendedMatchingCorrectAnswersPattern.matcher(line).find();

Expand Down Expand Up @@ -327,6 +332,11 @@ private void parseLine(Question question, String line) {
question.setFeedbackOK(feedbackOKMatcher.group(1));
} else if (hasfeedbackNOK) {
question.setFeedbackNOK(feedbackNOKMatcher.group(1));
} else if (randomize) {
if (question.getQuestionType() == Question.MULTIPLE_CHOICE_QUESTION ||
question.getQuestionType() == Question.MULTIPLE_CHOICE_MULTIPLE_ANSWER_QUESTION) {
question.setRandomize(randomize);
}
} else {
// If we didn't match anything, then assume it's just part of the question text
question.append(line);
Expand Down Expand Up @@ -745,6 +755,7 @@ private void processMultipleChoiceQuestion(SectionType section, Question questio
buildMetaDataField(qtiMetaData, "qmd_itemtype", "Multiple Choice");
buildMetaDataField(qtiMetaData, "TEXT_FORMAT", "HTML");
buildMetaDataField(qtiMetaData, "hasRationale", "False");
buildMetaDataField(qtiMetaData, ItemMetaDataIfc.RANDOMIZE, Boolean.valueOf(question.isRandomize()).toString());

ItemrubricType itemRubric = item.addNewItemrubric();
MattextType mattext = itemRubric.addNewMaterial().addNewMattext();
Expand Down Expand Up @@ -776,6 +787,7 @@ private void processMultipleChoiceMultipleAnswerQuestion(SectionType section, Qu
buildMetaDataField(qtiMetaData, "qmd_itemtype", "Multiple Correct Answer");
buildMetaDataField(qtiMetaData, "TEXT_FORMAT", "HTML");
buildMetaDataField(qtiMetaData, "hasRationale", "False");
buildMetaDataField(qtiMetaData, ItemMetaDataIfc.RANDOMIZE, Boolean.valueOf(question.isRandomize()).toString());

ItemrubricType itemRubric = item.addNewItemrubric();
MattextType mattext = itemRubric.addNewMaterial().addNewMattext();
Expand Down

0 comments on commit e0607be

Please sign in to comment.