package cz.muni.fi.bronchus.questions; import javax.swing.text.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.Vector; /** * Standard Fill-In-Blank question or "Cloze test". In text there are input lines * for filling an answers when testing the student * @author Tomáš Udržal */ public class FillInBlankQuestion extends Question { /** * Answer wording */ private String answer; /** * Vector of inputs */ private Vector inputs; // public static String[] answerLetters={"A","B","C","D","E","F","G","H","I","J", // "K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; /** Creates a new instance of FillInBlankQuestion */ public FillInBlankQuestion() { super("Fill-In-Blank"); answer=null; inputs=new Vector(); } /** * Returns the Vector of inputs contained in aswer, each element of this Vector * is another Vector, which has 3 items: * letter 'A'..'Z' of the input indexed from the 'A' * size of the input in chars * data type * @return Vector of inputs */ public java.util.Vector getInputs() { inputs.clear(); final Pattern imgPat = Pattern.compile("(?i)(?s)()"); final Pattern velikostPat = Pattern.compile("(?i)velikost=\"(.*?)\""); final Pattern dataPat = Pattern.compile("(?i)data=\"(.*?)\""); Matcher m = imgPat.matcher(answer); int pocet=0; while (m.find()) { Vector a=new Vector(); String imgText = m.group(1); a.add(answerLetters[pocet]); Matcher m2=velikostPat.matcher(imgText); a.add((m2.find()) ? m2.group(1) : ""); m2 = dataPat.matcher(imgText); a.add((m2.find()) ? m2.group(1) : ""); inputs.add(a); pocet++; } return inputs; } /** * Returns the count of the inputs contained in the answer * @return count of the inputs */ public int getCountFIBInputs() { final Pattern pat = Pattern.compile("(?i)(?s)"); String text = answer; Matcher matcher = pat.matcher(text); int pocet=0; while (matcher.find()) pocet++; if (pocet==0) return -1; else return pocet; } /** * Setter method for the answer * @param x answer */ public void setAnswer(String x) { answer=x; } /** * Getter method for the answer * @return answer */ public String getAnswer() { return answer; } /** * Method for generating a response processing condition from a selected answers. * Returns empty String because the condition for this type of question cannot be * generated, user creates conditions later manually. * @return empty String */ public String generateCondition() { return ""; } }