Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give basic boto create_qualification_type example

Can anyone give a basic example on how to use boto's mturk create_qualification_type? Please include an example of a valid answer_key_xml.

Or please point to some documentation with examples. The official documentation is not very helpful.

Thanks!

like image 998
Watson Avatar asked Feb 10 '26 06:02

Watson


1 Answers

Here is an example that creates a qualification test using boto 2. There should be a way to create an answer key using boto, instead of writing XML, but I have not found it.

from boto.mturk.connection import MTurkConnection
from boto.mturk.question import AnswerSpecification, SelectionAnswer
from boto.mturk.question import Question, QuestionContent, QuestionForm
from boto.mturk.question import FormattedContent, Overview

AWS_ACCESS_KEY_ID = 'PUT YOUR AWS KEY ID HERE'
AWS_SECRET_ACCESS_KEY = 'PUT YOUR AWS ACCESS KEY HERE'

questions = []
answers = []

# Question 1
questionContent = QuestionContent()
questionContent.append_field('Title', 'What is your favorite meme?')
questionContent.append(
    FormattedContent('<p>Make sure to think this through!</p>')
)
questionAnswer = AnswerSpecification(SelectionAnswer(
    min=1,
    max=1,
    style='radiobutton',
    selections=[
        ('Good Guy Greg', 0),
        ('Scumbag Steve', 1),
        ('Success Kid', 2)
    ],
))
questions.append(Question(
    identifier='q1',
    content=questionContent,
    answer_spec=questionAnswer,
    is_required=True,
))
answers.append("""\
<Question>
    <QuestionIdentifier>q1</QuestionIdentifier>
    <AnswerOption>
        <SelectionIdentifier>2</SelectionIdentifier>
        <AnswerScore>60</AnswerScore>
    </AnswerOption>
</Question> 
""")

# Question 2
questionContent = QuestionContent()
questionContent.append_field(
    'Title',
    'Complete the name of this meme: Socially Awkward ___ ?'
)
questionAnswer = AnswerSpecification(SelectionAnswer(
    min=1,
    max=1,
    style='radiobutton',
    selections=[
        ('Adult', 0),
        ('Penguin', 1),
        ('Doge', 2)
    ],
))
questions.append(Question(
    identifier='q2',
    content=questionContent,
    answer_spec=questionAnswer,
    is_required=True,
))
answers.append("""\
<Question>
    <QuestionIdentifier>q2</QuestionIdentifier>
    <AnswerOption>
        <SelectionIdentifier>1</SelectionIdentifier>
        <AnswerScore>40</AnswerScore>
    </AnswerOption>
</Question> 
""")

# Make the overall question form
testForm = QuestionForm()
overview = Overview()
overview.append_field('Text', 'This test is hard but fair. Try it!')
testForm.append(overview)
for q in questions:
    testForm.append(q)

# Make the answer key XML
answerKey = '<AnswerKey xmlns="%s">\n' % (
    'http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/AnswerKey.xsd'
)
answerKey += ''.join(answers)
answerKey += """\
<QualificationValueMapping>
    <PercentageMapping>
        <MaximumSummedScore>100</MaximumSummedScore>
    </PercentageMapping>
</QualificationValueMapping>
</AnswerKey>
"""

name = 'My Special Qualification'
description = 'My HITS require you to know your memes.'
mtc = MTurkConnection(
    aws_access_key_id=AWS_ACCESS_KEY_ID,
    aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
    host='mechanicalturk.sandbox.amazonaws.com',
)
mtc.create_qualification_type(
    name,
    description,
    status='Active',
    keywords=['memes', 'fun'],
    retry_delay=120,
    test=testForm,
    answer_key=answerKey,
    test_duration=3600,
    auto_granted=False,
)
like image 69
Sergei Krupenin Avatar answered Feb 12 '26 22:02

Sergei Krupenin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!