2

I'm trying to extract free-text answer submitted by workers of Amazon Mechanical Turk using the boto library.

assignments = conn.get_assignments(hit_id)
for assignment in assignments:
    worker = assignment.WorkerId
    answer = assignment.Answer

Here I expect answer to be a free-text string (the only thing that the HIT asks workers to submit) submitted by a worker, however, the code above doesn't give me that. What am I missing here?

2 Answers 2

3

In boto in order to get the FreeText information you are looking for, you'll need to iterate over the assignment property answers. Unless you have submitted multiple forms, your form should be the first index.

This list is of type QuestionFormAnswer

Here is boto documentation on QuestionFormAnswer
http://sourcecodebrowser.com/python-boto/2.3.0/classboto_1_1mturk_1_1connection_1_1_question_form_answer.html

You can see that the properties you actually want are qid and fields

Here is some updated code that should make better sense.

assignments = conn.get_assignments(hit_id)
for assignment in assignments:
    worker_id = assignment.WorkerId
    # Iterate through question forms answers which are our fields
    for question_form_answer in assignment.answers[0]:
        field_id = question_form_answer.qid
        field_value = question_form_answer.fields
2

I think the assignment object in the above example will have an attribute called answers which is a list of QuestionFormAnswer objects. Each of these objects should have an attribute called FreeText.

3
  • Looking at this: docs.pythonboto.org/en/latest/ref/…, which suggests to follow the definitions here: docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkAPI/…, I was expecting a property named Answer of an assignment object... Mar 20, 2013 at 14:35
  • The docs do suggest that. I looked at the code and it seemed to be accumulating the answers in an attribute called answers. Does that exist on the object?
    – garnaat
    Mar 20, 2013 at 14:39
  • thanks for pointing me to the right direction. Actually, what you said above is not entirely correct for my situation, to get the input by Turkers, I had to use this: assignment.answers[0][0].fields[0] for each assignment. In fact, assignment.answers[0] gives a ResultSet object, and assignment.answers[0][0] gives a QuestionFormAnswer object, and I didn't find any FreeText attribute on that... I wonder if FreeText attribute only exists when you explicitly create one for the HIT using the API. Thanks anyway. Apr 5, 2013 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.