本文整理汇总了Python中boto.mturk.question.QuestionForm.get_as_xml方法的典型用法代码示例。如果您正苦于以下问题:Python QuestionForm.get_as_xml方法的具体用法?Python QuestionForm.get_as_xml怎么用?Python QuestionForm.get_as_xml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.mturk.question.QuestionForm
的用法示例。
在下文中一共展示了QuestionForm.get_as_xml方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_question_form
# 需要导入模块: from boto.mturk.question import QuestionForm [as 别名]
# 或者: from boto.mturk.question.QuestionForm import get_as_xml [as 别名]
def create_question_form(mtc, uuid, url):
title = 'Bovid Labs HIT v2017.07.31 - %(uuid)s' % vars()
description = ('Help us extract a polygon from this research image.')
keywords = 'image, extraction, gimp'
overview = Overview()
overview.append_field('Title', 'Instructions')
# Overview text is where we'll put the details about the HIT
# img previews the tooth image
# a allows user to download the image and save as
text = """
<p>Your job is to extract the outline of the tooth in the following image.</p>
<p>You need to install the current version of Gimp on your computer. It can
be downloaded from
<a href="https://www.gimp.org/downloads/">https://www.gimp.org/downloads/</a></p>
<p>We have prepared a video at <a href="https://www.youtube.com/watch?v=nzxZqIp3XZY">
https://www.youtube.com/watch?v=nzxZqIp3XZY</a> showing how to do the task. Once you have extracted
the outline, you will upload the final result (file) to this HIT.
</p>
<p>For the HIT to be complete, you must upload a the black polygon against
a white background. The image size must match the original image size.</p>
<p>Image download URL: <br/>
<a href="%(url)s">
<img src="%(url)s" alt="direct link to image %(uuid)s"/>
</a>
</p>
""" % vars()
overview.append(FormattedContent(text))
qc1 = QuestionContent()
qc1.append_field('Title', 'File Upload Question')
fu1 = FileUploadAnswer(1024, 1024 * 1024 * 10)
q1 = Question(identifier="fileupload",
content=qc1,
answer_spec=AnswerSpecification(fu1))
question_form = QuestionForm()
question_form.append(overview)
question_form.append(q1)
# TODO: We want to separate creation of form from uploading the hit
# need to factor out arguments....
# duration and lifetime are in seconds.
# we will give 30 minutes duration (30 * 60) to complete the task
# we will keep these hits around for 14 days (14 * 24 * 60 * 60)
print(question_form.get_as_xml())
mtc.create_hit(questions=question_form, max_assignments=3, title=title, description=description, keywords=keywords,
duration=60 * 30, lifetime=3 * 24 * 60 * 60, reward=0.10)
示例2: make_question_form_elicitation_HIT
# 需要导入模块: from boto.mturk.question import QuestionForm [as 别名]
# 或者: from boto.mturk.question.QuestionForm import get_as_xml [as 别名]
def make_question_form_elicitation_HIT(self,prompt_list,hit_title,prompt_title,keywords,
duration=DEFAULT_DURATION,reward_per_clip=DEFAULT_REWARD,max_assignments=DEFAULT_MAX_ASSIGNMENTS):
overview = Overview()
overview.append_field("Title",hit_title)
#overview.append(FormattedContent('<a target = "_blank" href="url">hyperlink</a>'))
question_form = QuestionForm()
descriptions = ["The following prompts are in English.",
"Approve the flash permissions to record audio.",
"Click the red circle to record yourself.",
"Read the words after 'prompt:'",
"Click 'Click to Stop'",
"Play the clip back to verify sound quality.",
"After you are happy with your recording, click 'Click here to save >>'",
"Copy & paste the URL under 'Sharing options' into the text field for the prompt.",
"You will NEVER be asked to divulge any personal or identifying information."
]
keywords = "audio, recording, elicitation, English"
# for i, description in enumerate(descriptions):
# overview.append_field("%dDescription"%i, description)
# flash_xml = FlashXml(self.flash_xml.replace(self.html_tags["flash_url"],self.vocaroo_url))
# overview.append(flash_xml)
question_form.append(overview)
qc = QuestionContent()
# qc.append(FormattedContent(flash_xml))
qc.append_field("Title","Please select the type of microphone you are using.")
# qc.append(Flash(self.vocaroo_url,525,450))
#
#answer = FreeTextAnswer()
answer = SelectionAnswer(max=1,style="radiobutton",selections=self.mic_selections)
q = Question(identifier="MIC",
content=qc,
answer_spec=AnswerSpecification(answer))
question_form.append(q)
qual = qualification.LocaleRequirement("in","USA")
reward = reward_per_clip * len(prompt_list)
xml = question_form.get_as_xml()
try:
response = self.conn.create_hit(questions=question_form,
max_assignments=1,
title=hit_title,
qualification= qual,
description=descriptions[0],
keywords=keywords,
duration=duration,
reward=reward)
except MTurkRequestError as e:
if e.reason != "OK":
raise
return True
示例3: create_hit
# 需要导入模块: from boto.mturk.question import QuestionForm [as 别名]
# 或者: from boto.mturk.question.QuestionForm import get_as_xml [as 别名]
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)
示例4: create_hit
# 需要导入模块: from boto.mturk.question import QuestionForm [as 别名]
# 或者: from boto.mturk.question.QuestionForm import get_as_xml [as 别名]
def create_hit(self, hit_type=None, question=None, hit_layout=None,
lifetime=datetime.timedelta(days=7),
max_assignments=1,
title=None, description=None, keywords=None,
reward=None, duration=datetime.timedelta(days=7),
approval_delay=None, annotation=None,
questions=None, qualifications=None,
layout_params=None, response_groups=None):
"""
Creates a new HIT.
Returns a ResultSet
See: http://docs.amazonwebservices.com/AWSMechTurk/2012-03-25/AWSMturkAPI/ApiReference_CreateHITOperation.html
"""
# Handle basic required arguments and set up params dict
params = {'LifetimeInSeconds':
self.duration_as_seconds(lifetime),
'MaxAssignments': max_assignments,
}
# handle single or multiple questions or layouts
neither = question is None and questions is None
if hit_layout is None:
both = question is not None and questions is not None
if neither or both:
raise ValueError("Must specify question (single Question instance) or questions (list or QuestionForm instance), but not both")
if question:
questions = [question]
question_param = QuestionForm(questions)
if isinstance(question, QuestionForm):
question_param = question
elif isinstance(question, ExternalQuestion):
question_param = question
elif isinstance(question, HTMLQuestion):
question_param = question
params['Question'] = question_param.get_as_xml()
else:
if not neither:
raise ValueError("Must not specify question (single Question instance) or questions (list or QuestionForm instance) when specifying hit_layout")
params['HITLayoutId'] = hit_layout
if layout_params:
params.update(layout_params.get_as_params())
# if hit type specified then add it
# else add the additional required parameters
if hit_type:
params['HITTypeId'] = hit_type
else:
# Handle keywords
final_keywords = MTurkConnection.get_keywords_as_string(keywords)
# Handle price argument
final_price = MTurkConnection.get_price_as_price(reward)
final_duration = self.duration_as_seconds(duration)
additional_params = dict(
Title=title,
Description=description,
Keywords=final_keywords,
AssignmentDurationInSeconds=final_duration,
)
additional_params.update(final_price.get_as_params('Reward'))
if approval_delay is not None:
d = self.duration_as_seconds(approval_delay)
additional_params['AutoApprovalDelayInSeconds'] = d
# add these params to the others
params.update(additional_params)
# add the annotation if specified
if annotation is not None:
params['RequesterAnnotation'] = annotation
# Add the Qualifications if specified
if qualifications is not None:
params.update(qualifications.get_as_params())
# Handle optional response groups argument
if response_groups:
self.build_list_params(params, response_groups, 'ResponseGroup')
# Submit
return self._process_request('CreateHIT', params, [('HIT', HIT)])
示例5: create_hit
# 需要导入模块: from boto.mturk.question import QuestionForm [as 别名]
# 或者: from boto.mturk.question.QuestionForm import get_as_xml [as 别名]
def create_hit(
self,
hit_type=None,
question=None,
lifetime=datetime.timedelta(days=7),
max_assignments=1,
title=None,
description=None,
keywords=None,
reward=None,
duration=datetime.timedelta(days=7),
approval_delay=None,
annotation=None,
questions=None,
qualifications=None,
response_groups=None,
):
"""
Creates a new HIT.
Returns a ResultSet
See: http://docs.amazonwebservices.com/AWSMechanicalTurkRequester/2006-10-31/ApiReference_CreateHITOperation.html
"""
# handle single or multiple questions
neither = question is None and questions is None
both = question is not None and questions is not None
if neither or both:
raise ValueError(
"Must specify either question (single Question instance) or questions (list or QuestionForm instance), but not both"
)
if question:
questions = [question]
question_param = QuestionForm(questions)
if isinstance(question, QuestionForm):
question_param = question
elif isinstance(question, ExternalQuestion):
question_param = question
# Handle basic required arguments and set up params dict
params = {
"Question": question_param.get_as_xml(),
"LifetimeInSeconds": self.duration_as_seconds(lifetime),
"MaxAssignments": max_assignments,
}
# if hit type specified then add it
# else add the additional required parameters
if hit_type:
params["HITTypeId"] = hit_type
else:
# Handle keywords
final_keywords = MTurkConnection.get_keywords_as_string(keywords)
# Handle price argument
final_price = MTurkConnection.get_price_as_price(reward)
final_duration = self.duration_as_seconds(duration)
additional_params = dict(
Title=title,
Description=description,
Keywords=final_keywords,
AssignmentDurationInSeconds=final_duration,
)
additional_params.update(final_price.get_as_params("Reward"))
if approval_delay is not None:
d = self.duration_as_seconds(approval_delay)
additional_params["AutoApprovalDelayInSeconds"] = d
# add these params to the others
params.update(additional_params)
# add the annotation if specified
if annotation is not None:
params["RequesterAnnotation"] = annotation
# Add the Qualifications if specified
if qualifications is not None:
params.update(qualifications.get_as_params())
# Handle optional response groups argument
if response_groups:
self.build_list_params(params, response_groups, "ResponseGroup")
# Submit
return self._process_request("CreateHIT", params, [("HIT", HIT)])