public class Question extends SurveyObj implements Serializable, Comparable
Modifier and Type | Class and Description |
---|---|
static class |
Question.MalformedOptionException
Thrown by the Parser.
|
static class |
Question.OptionNotFoundException
Thrown whenever the user or system attempts to find an option by text, input cell, etc.
|
Modifier and Type | Field and Description |
---|---|
SurveyDatum |
answer
Answer to the question, if it exists.
|
Block |
block
The enclosing block for this question.
|
protected BranchMap |
branchMap
Map from answer options to branch destinations (
Block ). |
String |
correlation
A correlation label.
|
SurveyDatum |
data
Data to be displayed when the user takes the survey.
|
Boolean |
exclusive
True if respondents may only answer one of the answer options.
|
Boolean |
freetext
True if this question requires a text response.
|
String |
freetextDefault
Set if this question requires a text response and should display example text.
|
Pattern |
freetextPattern
Set if this question requires a text response and must conform to a regular expression.
|
String |
id
Unique question identifier.
|
protected static int |
nextRow |
protected static int |
OPTION_COL |
Map<String,SurveyDatum> |
options
Map from data identifiers to answer option objects (
SurveyDatum ). |
Boolean |
ordered
True if the answer options have a natural ordering (e.g., Likert scales).
|
Map<String,String> |
otherValues
Map from other input column headers to their values, when they exist for this question.
|
boolean |
permitBreakoff
Indicates whether respondents may submit their results immediately after answering this questions, regardless of
its position in the survey.
|
protected static int |
QUESTION_COL |
Boolean |
randomize
True if the answer options may be randomized.
|
List<Integer> |
sourceLineNos
Source data line numbers corresponding to this question.
|
Modifier | Constructor and Description |
---|---|
|
Question(String data)
Constructor for the programmatic creation of questions.
|
protected |
Question(String data,
int row,
int col) |
|
Question(SurveyDatum data) |
protected |
Question(SurveyDatum data,
int row,
int col) |
Modifier and Type | Method and Description |
---|---|
void |
addOption(String surfaceText)
Add an option with the input surface text.
|
void |
addOption(String surfaceText,
boolean exclusive,
boolean ordered)
Adds an option to the question.
|
void |
addOption(SurveyDatum surveyDatum)
Adds the input surveyDatum as an answer option to the question.
|
void |
addOption(SurveyDatum surveyDatum,
Block branchTo)
Adds an answer option as part of a branch question.
|
void |
addOption(SurveyDatum surveyDatum,
Block branchTo,
boolean exclusive,
boolean ordered)
Adds an answer option as part of a branch question.
|
void |
addOption(SurveyDatum surveyDatum,
boolean exclusive,
boolean ordered)
Adds the input surveyDatum as an answer option to the question.
|
void |
addOptions(String... surfaceTexts)
Adds options with the input surface text.
|
boolean |
before(Question q)
Tests whether this question precedes the input question, according to their enclosing blocks.
|
int |
compareTo(Object o) |
protected int |
countLines() |
static boolean |
customQuestion(String quid)
Determines whether the input question id corresponds to a known custom question pattern.
|
boolean |
equals(Object o)
Two questions are equal if the following are equal:
|
Block |
getBranchDest(SurveyDatum c)
Returns the branch destination for the input question.
|
Set<Block> |
getBranchDestinations()
Loops through the branch destinations for this question and returns the set of blocks this question branches to.
|
SurveyDatum |
getOptById(String oid)
Returns the answer option associated with this question having the input
SurveyDatum identifier. |
SurveyDatum[] |
getOptListByIndex()
Returns a sorted array of the answer options.
|
int |
getSourceCol()
Getter for the input source column.
|
int |
getSourceRow()
Getter for the input source line.
|
List<Question> |
getVariants()
For each question, returns the set of all equivalent questions (including itself).
|
int |
hashCode()
Hashcodes are computed from the id.
|
boolean |
isBranchQuestion()
Tests whether this question is a branch question.
|
boolean |
isCustomQuestion()
Determines whether the question id corresponds to a known custom question pattern.
|
boolean |
isInstructional()
Tests whether this question is instructional.
|
protected String |
jsonize() |
protected static String |
jsonize(List<Question> questionList) |
protected String |
jsonizeOrdering() |
static void |
makeOrderedRadioQuestions(Question[] questions,
String... surfaceStrings) |
static Question |
makeQuestion(String data,
int row,
int col)
Creates a question whose identifier is based on the question's input location and whose associated data
SurveyDatum is data. |
static Question |
makeQuestion(SurveyDatum data,
int row,
int col)
Used by the
edu.umass.cs.surveyman.input parsers. |
static void |
makeUnorderedCheckQuestions(Question[] questions,
String... surfaceStrings) |
static void |
makeUnorderedRadioQuestions(Question[] questions,
String... surfaceStrings)
Convenience method for quickly creating a series of questions with the default settings.
|
double |
responseToDouble(List<OptTuple> opts,
boolean noise)
Converts a response to a double precision representation, for use in clustering.
|
void |
setBranchDest(SurveyDatum c,
Block dest)
Sets the branch destination of this question at the input option to the input destination.
|
String |
toString()
Returns a string of the question data.
|
protected void |
updateFromSurvey(Survey s) |
protected static int QUESTION_COL
protected static int OPTION_COL
protected static int nextRow
public String id
public SurveyDatum data
public SurveyDatum answer
public Map<String,SurveyDatum> options
SurveyDatum
).protected BranchMap branchMap
Block
). This may be left
empty if there is no branching.public final List<Integer> sourceLineNos
public Map<String,String> otherValues
public Block block
public Boolean exclusive
public Boolean ordered
public Boolean randomize
public Boolean freetext
public Pattern freetextPattern
public String freetextDefault
public boolean permitBreakoff
public String correlation
protected Question(String data, int row, int col)
protected Question(SurveyDatum data, int row, int col)
public Question(SurveyDatum data)
public Question(String data)
data
- The data associated with this question.public static boolean customQuestion(String quid)
quid
- The identifier of the question we are testing.public boolean isCustomQuestion()
public int compareTo(Object o)
compareTo
in interface Comparable
public static Question makeQuestion(String data, int row, int col)
SurveyDatum
is data.data
- The data associated with this question.row
- This question's initial input row index.col
- The question column index.public static Question makeQuestion(SurveyDatum data, int row, int col)
edu.umass.cs.surveyman.input
parsers.data
- The parsed, internal representation of the data in a cell.row
- The input row (literal or calculated, as with JSON).col
- The input column (literal or calculated, as with JSON).protected int countLines()
protected void updateFromSurvey(Survey s)
public void addOption(String surfaceText, boolean exclusive, boolean ordered) throws SurveyException
surfaceText
- The answer option text to display.exclusive
- Boolean indicating whether this should be a radio button question. Must agree with the default
question setting.ordered
- Boolean indicating whether the answer options are ordered. Must agree with the default question
setting.SurveyException
public void addOption(String surfaceText) throws SurveyException
surfaceText
- The text this option should display.SurveyException
public void addOptions(String... surfaceTexts) throws SurveyException
surfaceTexts
- The surface texts to display.SurveyException
public void addOption(SurveyDatum surveyDatum, boolean exclusive, boolean ordered) throws SurveyException
surveyDatum
- The option to add.exclusive
- Boolean indicating whether this should be a radio button question. Must agree with the default
question setting.ordered
- Boolean indicating whether the answer options are ordered. Must agree with the default question
setting.SurveyException
public void addOption(SurveyDatum surveyDatum) throws SurveyException
surveyDatum
- The option to add.SurveyException
public void addOption(SurveyDatum surveyDatum, Block branchTo, boolean exclusive, boolean ordered) throws SurveyException
surveyDatum
- The option to add.branchTo
- The block this option points to.exclusive
- Boolean indicating whether this should be a radio button question. Must agree with the default
question setting.ordered
- Boolean indicating whether the answer options are ordered. Must agree with the default question
setting.SurveyException
public void addOption(SurveyDatum surveyDatum, Block branchTo) throws SurveyException
surveyDatum
- The option to add.branchTo
- The block this option points to.SurveyException
public Set<Block> getBranchDestinations()
public boolean isBranchQuestion()
public boolean isInstructional()
public Block getBranchDest(SurveyDatum c) throws SurveyException
c
- The answer option whose branch destination we want to know.SurveyException
public void setBranchDest(SurveyDatum c, Block dest) throws SurveyException
c
- The answer option whose branch destination we need to set.dest
- The branch destination for the input answer option.SurveyException
public SurveyDatum getOptById(String oid) throws SurveyException
SurveyDatum
identifier.oid
- The input SurveyDatum
identifier.SurveyDatum
subclass.Question.OptionNotFoundException
- if there is no answer option associated
with this question.SurveyException
public SurveyDatum[] getOptListByIndex() throws SurveyException
SurveyDatum
array of the answer options, sorted by their relative
indices.Question.MalformedOptionException
- if there is an error with the options'
indices.SurveyException
public boolean before(Question q)
before
.q
- Question to compare.true
if the input question follows this question. false
if randomization and/or partial
ordering cannot determine a strict ordering.public int getSourceRow()
int
corresponding to the first input source line.public int getSourceCol()
int
corresponding to the QUESTION column.public List<Question> getVariants()
protected String jsonizeOrdering() throws SurveyException
SurveyException
protected String jsonize() throws SurveyException
SurveyException
protected static String jsonize(List<Question> questionList) throws SurveyException
SurveyException
public static void makeUnorderedRadioQuestions(Question[] questions, String... surfaceStrings)
questions
- An array that will be populated with new question objects.surfaceStrings
- The strings corresponding to the text the user will see.public static void makeOrderedRadioQuestions(Question[] questions, String... surfaceStrings)
public static void makeUnorderedCheckQuestions(Question[] questions, String... surfaceStrings)
public String toString()
public boolean equals(Object o)
public int hashCode()
public double responseToDouble(List<OptTuple> opts, boolean noise) throws SurveyException
opts
- The answer set to this question.noise
- Boolean indicating whether we should add noise.SurveyException
Copyright © 2015. All rights reserved.