本文整理汇总了Python中boto.mturk.question.QuestionForm类的典型用法代码示例。如果您正苦于以下问题:Python QuestionForm类的具体用法?Python QuestionForm怎么用?Python QuestionForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QuestionForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_question_form_HIT
def make_question_form_HIT(self,audio_clip_urls,hit_title,question_title,description,keywords,
duration=DEFAULT_DURATION,reward=DEFAULT_REWARD):
overview = Overview()
overview.append_field("Title",hit_title)
#overview.append(FormattedContent('<a target = "_blank" href="url">hyperlink</a>'))
question_form = QuestionForm()
question_form.append(overview)
for ac in audio_clip_urls:
audio_html = self.transcription_question.replace(self.audio_url_tag,ac)
qc = QuestionContent()
qc.append_field("Title",question_title)
qc.append(FormattedContent(audio_html))
fta = FreeTextAnswer()
q = Question(identifier="transcription",
content=qc,
answer_spec=AnswerSpecification(fta))
question_form.append(q)
try:
response = self.conn.create_hit(questions=question_form,
max_assignments=1,
title=hit_title,
description=description,
keywords=keywords,
duration=duration,
reward=reward)
except MTurkRequestError as e:
if e.reason != "OK":
raise
return question_form, response
示例2: generate_hit
def generate_hit(self, num_assignments, hit_duration, hit_reward):
"""
Purpose: Generate and publish the HIT
Parameters: num_assignments is the number of avaliable assignments for hit,
hit_duration is the duration of the hit in seconds (60*5 for 5 minutes),
hit_reward is the reward given per hit in dollars (0.05 is 5 cents)
"""
# CONNECT TO MTURK
mtc = MTurkConnection(aws_access_key_id = self.access_id,
aws_secret_access_key = self.secret_key,
host = self.host)
# BUILD OVERVIEW
overview = Overview()
overview.append_field('Title', 'The following one or more sentences constitute an incomplete story.')
story = ""
for sentence in self.story_sentences:
story += sentence + " "
overview.append(FormattedContent(story))
# BUILD QUESTION 1: Copy the first sentence of the story
qc1 = QuestionContent()
qc1.append_field('Title','Copy verbatim the first sentence of the provided incomplete story. Please keep all capitalization and punctuation as given. Your sumbission will automatically be rejected if any character is incorrect.')
fta1 = FreeTextAnswer()
q1 = Question(identifier='verify_sentence', content = qc1, answer_spec = AnswerSpecification(fta1), is_required = True)
# BUILD QUESTION 2: Vote on the best sentence to continue the story
sentence_options = []
for i, sentence in enumerate (self.vote_sentences):
selection = (sentence, str(i))
sentence_options.append(selection)
qc2 = QuestionContent()
qc2.append_field('Title','Choose the best sentence to continue the story.')
fta2 = SelectionAnswer(min=1, max=1,style='radiobutton',
selections=sentence_options,
type='text',
other=False)
q2 = Question(identifier='vote_sentence', content = qc2, answer_spec = AnswerSpecification(fta2), is_required = True)
# BUILD THE QUESTION FORM
question_form = QuestionForm()
question_form.append(overview)
question_form.append(q1)
question_form.append(q2)
# CREATE THE HIT
mtc.create_hit(questions = question_form,
max_assignments = num_assignments,
title = self.title,
description = self.description,
keywords = self.keywords,
duration = hit_duration,
reward = hit_reward)
示例3: __generate_qualification_test
def __generate_qualification_test(self, question_data, num_correct, title):
'''
Returns a QuestionForm and AnswerKey for a qualification test from a list of sentence dictionaries.
question_data : json object containing all the questions.
'''
# Get question and answer data
questions = map(lambda (i,x): self.__generate_qualification_question(x,i), enumerate(question_data))
answers = map(lambda (i,x): x["answer_key_"+str(i)], enumerate(questions))
answer_key = self.__generate_answer_key(answers, num_correct, len(question_data))
# Create form setup
qual_overview = Overview()
qual_overview.append_field("Title", title)
# Instructions
qual_overview.append(FormattedContent("<h1>Please answer all the questions below.</h1>"))
qual_overview.append(FormattedContent("<h2>For each question, please choose either the left or right image \
which you think is more beautiful in terms of its composition. Hints: Please make your decision based on\
several 'rules of thumb' in photography, such as rule of thirds, visual balance and golden ratio. \
You may also make your decision by judging which image contains less unimportant or distracting contents.</h2>"))
# Create question form and append contents
qual_form = QuestionForm()
qual_form.append(qual_overview)
for q in questions:
i = q["question_num"]
qual_form.append(q["question_"+str(i)])
return (qual_form, answer_key)
示例4: question_form
def question_form( self ):
qc = QuestionContent()
# qc.append_field( 'Title', 'Is she hot?' )
qc.append( Binary( 'image', 'jpg', 'http://www.miranchomeatmarket.com/images/T-%20bone%20steak.jpg', 'steak' ) )
q = Question( identifier="This is the first girl!",
content=qc,
answer_spec=AnswerSpecification( FreeTextAnswer() ),
is_required=True,
display_name="This is display name" )
qf = QuestionForm()
qf.append( q )
if self.hit_type_id:
try:
create_hit_rs = self.connect.create_hit( hit_type=self.hit_type_id,
question=qf,
lifetime=datetime.timedelta( days=14 ),
max_assignments=10,
annotation="This is a annotation"
)
except MTurkRequestError as e:
print "create hit type error:\n status: %s reason: %s\n body: %s" % ( e.status, e.reason, e.body )
else:
print "success!! key: %s" % create_hit_rs
示例5: createHits
def createHits(question, answers, params):
if SANDBOX:
mturk_url = 'mechanicalturk.sandbox.amazonaws.com'
preview_url = 'https://workersandbox.mturk.com/mturk/preview?groupId='
else:
mturk_url = 'mechanicalturk.amazonaws.com'
preview_url = 'https://mturk.com/mturk/preview?groupId='
#Create Hit Form Structure
overview = Overview()
overview.append_field('Title', 'We want to know the crowds opinion!')
overview.append(FormattedContent('<a href="http://programthecrowd.com/">Visit us here</a>'))
questionContent = QuestionContent()
questionContent.append_field('Title', question);
answerChoices = SelectionAnswer(min=1, max=1, style='checkbox', selections=answers, type='text', other=False)
q = Question(identifier='Help', content=questionContent, answer_spec=AnswerSpecification(answerChoices), is_required=True)
questionForm = QuestionForm();
questionForm.append(overview)
questionForm.append(q)
hitIdList = []
global conn
# key = params['aws_access_key']
# secret = params['aws_secret_key']
conn = MTurkConnection(aws_access_key_id='AKIAJBTEJI2RGTJH7OBA', aws_secret_access_key='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', host=mturk_url)
#For Loop to create and post hits
for i in range(0, NUMBER_OF_HITS):
create_hit_rs = conn.create_hit(questions=questionForm, lifetime=LIFETIME, max_assignments=NUMBER_OF_ASSIGNMENTS, title=TITLE, keywords=KEYWORDS, reward=REWARD, duration=DURATION, approval_delay=APPROVAL_DELAY, annotation=DESCRIPTION)
#print(preview_url + create_hit_rs[0].HITTypeId)
#print("HIT ID: " + create_hit_rs[0].HITId)
hitIdList.append(create_hit_rs[0].HITId);
return hitIdList
示例6: generate_question_forms
def generate_question_forms(task_item, retval=DEFAULT_RETVAL):
"""
Works on the output of prepare_media by generating a QuestionForm
for each page in retval. Returns a list of QuestionForm instances.
"""
pages = retval
task_config = task_item.config
overview = _gen_overview()
retval = []
for page in pages:
qf = QuestionForm()
qf.append(overview)
for s in page:
qc = QuestionContent()
binary_content = {'type': s['type'],
'subtype': s['subtype'],
'dataurl': '%s%s' % (DEFAULT_IMAGE_HOST, s['dataurl']),
#'alttext': s['sentence']}
'alttext': 'no cheating!'}
qc.append('Binary', binary_content)
fta = FreeTextAnswer()
ansp = AnswerSpecification(fta)
q = Question(identifier=str(uuid.uuid4()),
content=qc,
answer_spec=ansp)
qf.append(q)
retval.append(qf)
return retval
示例7: createHIT2
def createHIT2(possibleAnswers,sentence, context):
title = 'Pick the best translation!'
description = ('Pick the best translation!')
keywords = 'translate, language'
ratingsDic = {}
ratings = []
i = 0
for answer in possibleAnswers:
ratings.append((answer,i))
ratingsDic[i] = answer
i = i + 1
#--------------- BUILD OVERVIEW -------------------
overview = Overview()
overview.append_field('Title', title)
overview.append(FormattedContent('<p>' + context + '</p>' + '<p><b>' + sentence + '</b></p>'))
#--------------- BUILD QUESTION 2 -------------------
qc1 = QuestionContent()
qc1.append_field('Title','Please pick the best translation for the bolded sentence above.')
fta1 = SelectionAnswer(min=1, max=1,style='radiobutton',
selections=ratings,
type='text',
other=False)
q1 = Question(identifier='pick',
content=qc1,
answer_spec=AnswerSpecification(fta1),
is_required=True)
#--------------- BUILD THE QUESTION FORM -------------------
question_form = QuestionForm()
question_form.append(overview)
question_form.append(q1)
#--------------- CREATE QUALIFICATION REQUIREMENT -------------------
qual_req = Requirement(qualification_type_id=QUALIFICATION_ID,
comparator="Exists")
quals = Qualifications(requirements=[qual_req])
#--------------- CREATE THE HIT -------------------
resultSet = mtc.create_hit(questions=question_form,
max_assignments=HIT2_MAX_ASSIGN,
title=title,
description=description,
keywords=keywords,
duration = 60*5,
reward=0.50,
qualifications=quals)
return (resultSet[0].HITId,ratingsDic)
示例8: post_HIT1
def post_HIT1(ACCESS_ID,SECRET_KEY,HOST,url_to_task):
mtc = MTurkConnection(aws_access_key_id=ACCESS_ID,
aws_secret_access_key=SECRET_KEY,
host=HOST)
title = 'Dev deploying simulation test Report From SERVER'
description = ('Report on events in a simulation')
keywords = 'website, rating, opinions'
instructions=('<p>You will take part in a web-based experiment where you will watch a simple simulation and provide reports on events</p>'
'<p>Instructions:</p>'
'<p>1. Click the link below, which will open the webpage in a new window in your browser</p>'
'<p>2. Follow the instructions on the website</p>'
'<p>3. Once you have completed your work, you will receive a Reward Code</p>'
'<p>4. Return to the mechanical turk webpage and enter your code in the Reward Code text box</p>'
'<p>5. Your work will then be checked, after which you will receive your payment</p>'
'<br/>CLICK "ACCEPT HIT" BEFORE FOLLOWING LINK'
'<br/>YOU WILL NOT BE PAID WITHOUT ACCEPTING THE HIT')
#--------------- BUILD OVERVIEW -------------------
overview = Overview()
overview.append_field('Title', description)
overview.append(FormattedContent(instructions))
overview.append(FormattedContent('<p>Click "Accept HIT" then click this link <a target="_blank"'
' href="'+url_to_task+'">'
' Link to task</a></p>'))
#--------------- BUILD QUESTION 1 -------------------
qc1 = QuestionContent()
qc1.append_field('Title','Enter reward code here:')
fta1 = FreeTextAnswer(num_lines=1)
q1 = Question(identifier='reward_code',
content=qc1,
answer_spec=AnswerSpecification(fta1),
is_required=True)
#--------------- BUILD THE QUESTION FORM -------------------
question_form = QuestionForm()
question_form.append(overview)
question_form.append(q1)
#--------------- CREATE THE HIT -------------------
mtc.create_hit(questions=question_form,
max_assignments=1,
title=title,
description=description,
keywords=keywords,
duration = 60*5,
reward=0.05)
示例9: launchHIT
def launchHIT(mtc, drawing_id, payment, title):
#title = 'Add a single line to this drawing: easy!'
description = ('We need your help to make the best art possible!')
keywords = 'drawing, web, art, research, paint, creative, easy, simple, fast'
choices = [('done','done')]
drawing_id = "http://2.distributeddrawing.appspot.com/" + drawing_id
#------------------- Overview ---------------------
overview_content = ("<p>Your task is to follow the link and draw a single line stroke in the box shown. It's Easy! Just left-click in the box and drag your cursor around to create your stroke (just like in MS Paint).</p>"
'<p>BUT...try to add something to the picture. If the square is blank, start off the image with something cool. If there is already an image going, add something that makes it better.</p>'
'<p>Help us make some great drawings!</p>'
'<ul>'
'<li><b>Get started: </b> <a href=" ' + drawing_id + '" target="_blank">Click here</a> </li>'
'</ul>')
overview = Overview()
overview.append_field('Title', 'Draw a line in the box to complete the task.')
overview.append(FormattedContent( overview_content))
#------------------- Question test ---------------------
#urlContent = '<a target="_blank" href="http://www.toforge.com"> Canvas </a>'
qc1 = QuestionContent()
qc1.append_field('Title','Click on the submit button once you have finished the task.')
qc1.append(FormattedContent('The payment will not be authorized if you have not completed the task. Also, you can only complete this task once (all subsequent submissions will be rejected).'))
answers = SelectionAnswer(min=1, max=1,style='dropdown',
selections=choices,
type='text',
other=False)
#question1 = ExternalQuestion(external_url='http://distributeddrawing.appspot.com/',frame_height=400)
q1 = Question(identifier='task',
content=qc1,
answer_spec=AnswerSpecification(answers),
is_required=True)
#------------------- Question form creation ---------------------
questionForm = QuestionForm()
questionForm.append(overview)
questionForm.append(q1)
#------------------- HIT creation ---------------------
return mtc.create_hit(question=questionForm,
max_assignments=1,
lifetime=datetime.timedelta(days=1),
title=title,
description=description,
keywords=keywords,
duration = 60*5,
reward=payment,
response_groups=['Minimal'])
示例10: create_question_form
def create_question_form(title, description, keywords):
"""
Create an overview for an MTurk HIT
"""
overview = Overview()
overview.append_field('Title', title)
question_form = QuestionForm()
question_form.append(overview)
return question_form
示例11: __generate_qualification_test
def __generate_qualification_test(self, question_data, num_correct, title):
'''
Returns a QuestionForm and AnswerKey for a qualification test from a list of sentence dictionaries
'''
# Get question and answer data
questions = map(lambda (i,x): self.__generate_qualification_question(x,i), enumerate(question_data))
answers = map(lambda (i,x): x["answer_key_"+str(i)], enumerate(questions))
answer_key = self.__generate_answer_key(answers, num_correct, len(question_data))
# Create form setup
qual_overview = Overview()
qual_overview.append_field("Title",title)
# Instructions
qual_overview.append(FormattedContent("<h1>You must correctly code "+str(num_correct)+" out of the "+str(len(question_data))+" test sentences below.</h1>"))
qual_overview.append(FormattedContent("<h2>Coding instructions are listed below. Please read through these carefully before continuing on to the coding task.</h2>"))
inst_url = "https://s3.amazonaws.com/aws.drewconway.com/mt/experiments/cmp/html/instructions.html"
qual_overview.append(FormattedContent('<iframe src="'+inst_url+'" frameborder="0" width="1280" height="300" scrolling="auto">This text is necessary to ensure proper XML validation</iframe>'))
# Create question form and append contents
qual_form = QuestionForm()
qual_form.append(qual_overview)
for q in questions:
i = q["question_num"]
qual_form.append(q["policy_area_"+str(i)])
qual_form.append(q["econ_scale_"+str(i)])
qual_form.append(q["soc_scale_"+str(i)])
return (qual_form, answer_key)
示例12: create_HIT
def create_HIT(mturk_conn, letter, imgur_links):
# Given a char and set of links
# create and push HIT
try:
canary = mturk_conn.get_account_balance()
except Exception as e1:
print "[Error Connecting]", e1
print "[Exiting]"
exit(1)
hit = None
# -HIT Properties
title = "Select the Best Character"
description = (
"Of the available options below, please select the best representation of the following chracter: "
+ letter
+ "\n Your vote will help determine which character gets selected to be used in a collaborative typeface."
)
keywords = "image, voting, opinions"
# -Question Overview
overview = Overview()
overview.append_field("Title", "Choose the best looking letter")
# -Question
qc1 = QuestionContent()
qc1.append_field("Title", "Select Letter")
# Generate Awnsers 1 per imgur_links[]
choices = boto_injector(imgur_links)
# -Awnser Choices
fta1 = SelectionAnswer(min=1, max=1, style="radiobutton", selections=choices, type="binary", other=False)
q1 = Question(identifier="design", content=qc1, answer_spec=AnswerSpecification(fta1), is_required=True)
# -Question Form
question_form = QuestionForm()
question_form.append(overview)
question_form.append(q1)
# Put the HIT up
try:
mturk_conn.create_hit(
questions=question_form,
max_assignments=5,
title=title,
description=description,
keywords=keywords,
duration=60 * HIT_TIME,
reward=0.01,
)
print "Hit issued for item:", letter
except Exception as e1:
print "Could not issue hit", e1
示例13: createQualification
def createQualification(language): #returns the qualType
title = "English to " + language + " Translator Qualification"
descrip = "Obtain a qualification to complete tasks requiring translation from English to " + language
status = 'Active'
keywords = "qualification, translation"
retry_delay = 10 #small for testing, should be alot bigger or not specified
test_duration = 300 #5 minutes
answer_key=None
answer_key_xml=None
auto_granted=False
auto_granted_value=1
#string to check for translation:
test_trans = "Siempre como huevos para desayuno cuando me despierto." #"I always eat eggs for breakfast when I wake up"
#--------------- BUILD OVERVIEW -------------------
qual_overview = Overview()
qual_overview.append_field('Title', title)
qual_overview.append_field('Text' , descrip)
#--------------- BUILD FREE TEXT ANSWER -------------------
#--------------- BUILD QUESTION -------------------
qual_qc = QuestionContent()
qual_qc.append_field('Title','Please translate the sentence')
qual_qc.append_field('Text', test_trans) #This is where the actual question is printed
qual_fta = FreeTextAnswer()
qual_q1 = Question(identifier="translation",
content=qual_qc,
answer_spec=AnswerSpecification(qual_fta))
#--------------- BUILD THE QUESTION FORM -------------------
qual_question_form = QuestionForm()
qual_question_form.append(qual_overview)
qual_question_form.append(qual_q1)
#--------------- CREATE THE QUALIFICATION TYPE -------------------
qualType = mtc.create_qualification_type(title,
descrip,
status,
keywords,
retry_delay,
qual_question_form, #the "test" value
answer_key,
answer_key_xml,
test_duration,
auto_granted,
auto_granted_value)
return qualType
示例14: create_hit
def create_hit(self, title=None, description=None, keywords=None, reward=0.00,
duration=60*60*24*7, approval_delay=None, qual_req=None, hit_type=None,
question=None, questions=None):
"""
Creates a new HIT.
Returns HITId as a string.
See: http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2006-10-31/ApiReference_CreateHITOperation.html
"""
# handle single or multiple questions
if question is not None and questions is not None:
raise ValueError("Must specify either question (single Question instance) or questions (list), but not both")
if question is not None and questions is None:
questions = [question]
# Handle keywords
final_keywords = MTurkConnection.get_keywords_as_string(keywords)
# Handle price argument
final_price = MTurkConnection.get_price_as_price(reward)
# Set up QuestionForm data structure
qf = QuestionForm(questions=questions)
# Handle basic arguments and set up params dict
params = {'Title': title,
'Description' : description,
'Keywords': final_keywords,
'AssignmentDurationInSeconds' : duration,
'Question': qf.get_as_xml() }
if approval_delay is not None:
params.update({'AutoApprovalDelayInSeconds': approval_delay })
params.update(final_price.get_as_params('Reward'))
# Handle optional hit_type argument
if hit_type is not None:
params.update({'HITTypeId': hit_type})
# Submit
response = self.make_request('CreateHIT', params)
body = response.read()
if response.status == 200:
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs.HITId
#return rs # return entire ResultSet for testing purposes
else:
raise EC2ResponseError(response.status, response.reason, body)
示例15: make_poll
def make_poll(title, question, description, keywords, poll_price, ratings):
"""Take submitted request and answers.
Resubmit for polling to ensure validity."""
ACCESS_ID = mtkey.ACCESS_KEY
SECRET_KEY = mtkey.SECRET_KEY
HOST = 'mechanicalturk.amazonaws.com'
# link to HITs: https://requester.mturk.com/mturk/manageHITs
# HOST = 'mechanicalturk.sandbox.amazonaws.com'
# link to HITs: https://requestersandbox.mturk.com/mturk/manageHITs
mtc = MTurkConnection(aws_access_key_id=ACCESS_ID,
aws_secret_access_key=SECRET_KEY,
host=HOST)
#--------------- BUILD OVERVIEW -------------------
overview = Overview()
overview.append_field('Title', title)
#--------------- BUILD POLL -------------------
qc2 = QuestionContent()
qc2.append_field('Title', question)
fta2 = SelectionAnswer(min=1, max=4, style='checkbox',
selections=ratings,
type='text',
other=False)
q2 = Question(identifier='selection',
content=qc2,
answer_spec=AnswerSpecification(fta2),
is_required=True)
#--------------- BUILD THE POLL FORM -------------------
question_form = QuestionForm()
question_form.append(overview)
question_form.append(q2)
#--------------- CREATE THE HIT -------------------
return mtc.create_hit(questions=question_form,
max_assignments=8,
title=title,
description=description,
keywords=keywords,
duration=60*5,
reward=poll_price)