QuestionForm

The QuestionForm data format describes one or more "questions" for a HIT, or for a Qualification test. It contains instructions and data to be used in answering the questions, and a set of one or more form fields, which are rendered as a web form for a Worker to fill out and submit.

Tip:

For information about creating HITs that use your own web site in a frame instead of questions, see the ExternalQuestion data structure.

A QuestionForm is a string value that consists of XML data. The XML data must conform to the QuestionForm schema. See WSDL and Schema Locations for the location of this schema. For more information about using XML data as a parameter or return value, see Using XML Parameter Values.

Note:

The "answer specification" for a question influences how the Worker sees the question at the Mechanical Turk web site. It also tells Mechanical Turk to perform some validation of the data submitted via the web form. Neither the requested display nor validation of the answers are guaranteed by the Mechanical Turk Service. When your application retrieves the answer data, it should check that the data sufficiently answers the question.

The QuestionForm data structure is used as a parameter value for the following operations:

  • CreateHIT

  • CreateQualificationType

The QuestionForm data structure is a value in a HIT data structure, and a value in a QualificationType data structure.

All elements in a QuestionForm belong to a namespace whose name is identical to the URL of the QuestionForm schema document for the version of the API you are using.

The top-most element of a QuestionForm data structure is a QuestionForm element. The element contains an optional Overview element, and one or more Question elements.

<QuestionForm xmlns="[the QuestionForm schema URL]">
  <Overview>
    [...]
  </Overview>
  <Question>
    [...]
  </Question>
  <Question>
    [...]
  </Question>
  [...]
</QuestionForm>

The Overview element describes instructions and information presented separately from the set of questions. It can contain any kind of informational content, as described below. If omitted, no overview text will be displayed above the questions.

Each Question element can contain the following elements:

NameDescriptionTypeValue
QuestionIdentifier

An identifier for the question. This identifier is used to associate the Worker's answers with the question in the answer data.

Required

An alphanumeric string

DisplayName

A name for the question, displayed as a prominent heading. It is optional.

Optional

A string

IsRequired

This is true if the Worker must provide an answer for this question to successfully submit the form. If not specified, the default is false.

Optional

A Boolean value, either true or false

QuestionContent

The instructions and data specific to this question, such as the text of the question. It can contain any kind of informational content, as described below.

Required

A content structure, as described below

AnswerSpecification

A structure describing the field type and possible values for the answer to this question. This controls how the form field is rendered, and describes which values are valid answers for this question.

Required

An answer specification structure, as described below

For example:

  <Question>
    <QuestionIdentifier>my_question_id</QuestionIdentifier>
    <DisplayName>My Question</DisplayName>
    <IsRequired>true</IsRequired>
    <QuestionContent>
      [...]
    </QuestionContent>
    <AnswerSpecification>
      [...]
    </AnswerSpecification>
  </Question>

The Overview element and the QuestionContent elements of a QuestionForm can contain information of several kinds. For example, you might include a paragraph of text and an image in your HIT's overview.

Each kind of information is specified with a corresponding element. These elements can appear in any number, in any order. The content elements are rendered in the order they appear in the containing element.

The following kinds of information can be included in content:

An Application element specifies an embedded application, such as a Java applet or a Flash movie. It contains either a JavaApplet element or a Flash element.

You can specify zero or more parameters to pass to your Java applet or Flash application when it is opened in the web page. For a HIT, in addition to the parameters you specify, Mechanical Turk will include two parameters specific to the HIT: a hitId parameter, equal to the ID of the HIT, and assignmentId, equal to the ID of the assignment if the Worker has accepted the HIT, or equal to ASSIGNMENT_ID_NOT_AVAILABLE if the Worker is only previewing the HIT.

JavaApplet includes the following elements:

Flash includes the following elements:

<Application>
  <JavaApplet>
    <AppletPath>http://tictactoe.amazon.com/applets/</AppletPath>
    <AppletFilename>GameViewer.class</AppletFilename>
    <Width>400</Width>
    <Height>300</Height>
    <ApplicationParameter>
      <Name>game_id<Name>
      <Value>01523</Value>
    </ApplicationParameter>
  </JavaApplet>
</Application>

For finer control over the display of your HIT information, you can specify a FormattedContent element. Formatted content is a block of text with formatting information specified using XHTML tags. For example, you can use XHTML tags to specify that certain words appear in a boldface font, or to include a table in your HIT information.

Only a limited subset of XHTML is supported. For more information on the creating and validating XHTML formatted content, see Formatted Content: XHTML.

The value of the FormattedContent element must be specified as an XML CDATA block. CDATA tells the web service that the XHTML elements are not part of the QuestionForm data schema. For example, the following describes a paragraph of formatted text:

<FormattedContent><![CDATA[
  <p>This is a paragraph with <b>bold text,</b>
  <i>italic text,</i> and <b><i>bold italic text</i></b>.</p>
]]></FormattedContent>

The AnswerSpecification element describes the format and possible values for answers to a question. It contains a FreeTextAnswer element, which describes a text field; a SelectionAnswer element, which describes a multiple choice field; or, a FileUploadAnswer, which prompts the Worker to upload a file as the answer to the question.

A FreeTextAnswer describes a text field, and constraints on its possible values. It contains an optional Constraints element, an optional DefaultText element, and an optional NumberOfLinesSuggestion element.

Note:

A Qualification test that is to be graded automatically using an answer key cannot have any free-text questions. An answer key can only match multiple-choice questions, and cannot match free-text fields.

The optional Constraints element describes constraints on the possible values that are accepted in the text field. The mechanism presenting the question to the Worker (such as the Mechanical Turk web site) may use these constraints to render the question and validate the answer, though this is not guaranteed.

If the Constraints element contains an IsNumeric element, then the value the Worker enters must be a number. IsNumeric is an empty element with two optional attributes: minValue specifies a minimum number value, and maxValue specifies a maximum.

If the Constraints element contains a Length element, then the value the Worker enters must be of a length within the given range. Length is an empty element with two optional attributes: minLength specifies a minimum number of characters, and maxLength specifies a maximum.

If no constraints are specified, any value is accepted for the field.

An optional DefaultText element specifies a default value for the field. This value appears in the form when it is rendered, and is accepted as the answer if the Worker does not change it. The default is an empty value.

An optional NumberOfLinesSuggestion element specifies how tall the form field should be, if possible. The field may or may not be rendered as a text box with this many lines, depending on the device the Worker is using to see the form. The default is a one-line text box.

<FreeTextAnswer>
  <Constraints>
    <Length minLength="2" maxLength="2" />
  </Constraints>
  <DefaultText>C1</DefaultText>
</FreeTextAnswer>

A SelectionAnswer describes a multiple-choice question. The Worker can select zero, one or multiple items from a set list as the answer to the question. SelectionAnswer contains optional MinSelectionCount and MaxSelectionCount elements to restrict the number of options that make up a valid answer, an optional StyleSuggestion element to recommend a particular kind of multiple-choice display, and a Selections element that lists the options.

Optional MinSelectionCount and MaxSelectionCount elements specify a minimum number of selections, and a maximum number of selections, respectively. MinSelectionCount can be from 0 up to the number of selections, and defaults to 1. MaxSelectionCount can be from 1 up to the number of selections, and defaults to 1.

An optional StyleSuggestion element specifies what style of multiple-choice form field to use when displaying the question to the Worker. The styles radiobutton and dropdown can be used if MaxSelectionCount is 1 (the default), as they restrict the user to selecting zero or one items from the list. The styles checkbox, list, combobox, and multichooser allow for multiple selections, though they can also be restricted using MaxSelectionCount. The field may or may not use the suggested style, depending on the device the Worker is using to see the form.

The Selections element contains one or more Selection elements, one for each possible answer in the set. A Selection element contains an SelectionIdentifier, a unique alphanumeric string that will be in the answer data if this selection is chosen, and either a Text element or a Binary element containing the content of the option. Text specifies a string, and Binary specifies binary data. See the explanation of content, above, for more information on the Binary element.

A Selections element may optionally contain an OtherSelection element, which specifies a text field to display below the selection list, allowing the Worker to enter an alternate answer that does not appear in the list of selections. The contents of OtherSelection are similar to FreeTextAnswer, described above.

Note:

A Qualification test that is to be graded automatically using an answer key cannot have an OtherSelection field for a multiple choice question. An answer key can only match multiple-choice questions, and cannot match free-text fields.

<SelectionAnswer>
  <StyleSuggestion>radiobutton</StyleSuggestion>
  <Selections>
    <Selection>
      <SelectionIdentifier>C1</SelectionIdentifier>
      <Text>C1 (northeast)</Text>
    </Selection>
    <Selection>
      <SelectionIdentifier>C2</SelectionIdentifier>
      <Text>C2 (east)</Text>
    </Selection>
    <Selection>
      <SelectionIdentifier>A3</SelectionIdentifier>
      <Text>A3 (southwest)</Text>
    </Selection>
    <Selection>
      <SelectionIdentifier>C3</SelectionIdentifier>
      <Text>C3 (southeast)</Text>
    </Selection>
  </Selections>  
</SelectionAnswer>

The following is an example of a complete QuestionForm data structure. Remember that to pass this structure in as a value of a parameter to an operation, XML characters must be escaped as character entities. (See Using XML Parameter Values for more information.)

<QuestionForm xmlns="[the QuestionForm schema URL]">
  <Overview>
    <Title>Game 01523, "X" to play</Title>
    <Text>
      You are helping to decide the next move in a game of Tic-Tac-Toe.  The board looks like this:
    </Text>
    <Binary>
      <MimeType>
        <Type>image</Type>
        <SubType>gif</SubType>
      </MimeType>
      <DataURL>http://tictactoe.amazon.com/game/01523/board.gif</DataURL>
      <AltText>The game board, with "X" to move.</AltText>
    </Binary>
    <Text>
      Player "X" has the next move.
    </Text>
  </Overview>
  <Question>
    <QuestionIdentifier>nextmove</QuestionIdentifier>
    <DisplayName>The Next Move</DisplayName>
    <IsRequired>true</IsRequired>
    <QuestionContent>
      <Text>
        What are the coordinates of the best move for player "X" in this game?
      </Text>
    </QuestionContent>
    <AnswerSpecification>
      <FreeTextAnswer>
        <Constraints>
          <Length minLength="2" maxLength="2" />
        </Constraints>
        <DefaultText>C1</DefaultText>
      </FreeTextAnswer>
    </AnswerSpecification>
  </Question>
  <Question>
    <QuestionIdentifier>likelytowin</QuestionIdentifier>
    <DisplayName>The Next Move</DisplayName>
    <IsRequired>true</IsRequired>
    <QuestionContent>
      <Text>
        How likely is it that player "X" will win this game?
      </Text>
    </QuestionContent>
    <AnswerSpecification>
      <SelectionAnswer>
        <StyleSuggestion>radiobutton</StyleSuggestion>
        <Selections>
          <Selection>
            <SelectionIdentifier>notlikely</SelectionIdentifier>
            <Text>Not likely</Text>
          </Selection>
          <Selection>
            <SelectionIdentifier>unsure</SelectionIdentifier>
            <Text>It could go either way</Text>
          </Selection>
          <Selection>
            <SelectionIdentifier>likely</SelectionIdentifier>
            <Text>Likely</Text>
          </Selection>
        </Selections>
      </SelectionAnswer>
    </AnswerSpecification>
  </Question>
</QuestionForm>