コード例 #1
0
    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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
ファイル: amt.py プロジェクト: zhydhkcws/CDB
def make_question_form(questions):
    if not questions:
        raise ValueError('Questions cannot be empty!')
    question_form = QuestionForm()

    for q in questions:
        qid = q['id']
        q_text = SimpleField('Text', q['content'])
        q_content = QuestionContent([q_text])
        selections = [('Yes', 1), ('No', 0)]
        answer_spec = AnswerSpecification(SelectionAnswer(style='radiobutton', selections=selections))
        question = Question(qid, q_content, answer_spec, True)
        question_form.append(question)

    return question_form
コード例 #5
0
ファイル: phillyTechMturk.py プロジェクト: vgoklani/mturk
def make_question(url, selections):
    """Build a formatted question to be posted on mechanical turk.

    :param urls: Images to be displayed in mc question.
    :param selections: Answer selections.
    :param fta: True if the question includes a FreeTextAnswer.

    """
    mc_overview = Overview()
    mc_overview.append_field('Title', title)

    question_form = QuestionForm()
    question_form.append(mc_overview)
    question_form.append(make_mc_question(url, selections))
    return question_form
コード例 #6
0
    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)
コード例 #7
0
ファイル: amt_voting.py プロジェクト: baykovr/AMT
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
コード例 #8
0
ファイル: amt.py プロジェクト: zhydhkcws/CDB
def make_many_to_many_form(questions):
    if not questions:
        raise ValueError('Questions cannot be empty!')
    question_form = QuestionForm()

    for q in questions:
        qid = q['id']
        q_text = SimpleField('Text', q['content'])
        contents = [q_text]
        if q.has_key('url'):
            contents.append(FormattedContent(make_image_content(q['url'])))
        q_content = QuestionContent(contents)
        selections = [(i, i) for i in q['options']]
        answer_spec = AnswerSpecification(SelectionAnswer(min=1, max=len(q['options']), style='checkbox', selections=selections))
        question = Question(qid, q_content, answer_spec, True)
        question_form.append(question)

    return question_form
コード例 #9
0
ファイル: amt.py プロジェクト: zhydhkcws/CDB
def make_free_text_question_form(questions):
    if not questions:
        raise ValueError('Questions cannot be empty!')
    question_form = QuestionForm()

    for q in questions:
        qid = q['id']
        for field in q['columns']:
            if field == q['columns'][0]:
                hint = SimpleField('Title', q['content'])
                question_form.append(Overview([hint]))
            field_id = str(qid) + free_sep + field
            q_text = SimpleField('Text', field)
            q_content = QuestionContent([q_text])
            cons = Constraints([LengthConstraint(min_length=1, max_length=100)])
            answer_spec = AnswerSpecification(FreeTextAnswer(constraints=cons))
            question = Question(field_id, q_content, answer_spec, True)
            question_form.append(question)

    return question_form
コード例 #10
0
def createQuestionForm(overviewTitle, overviewDescription, numberOfTweets,
                       listOfTweets, listOfTweetIDs):
    """
    Create an overview for an MTurk HIT
    """

    #The Question Form should contain 1 overview and 3 odd questions
    questionForm = QuestionForm()

    #Define the Overview
    overview = Overview()
    Title = FormattedContent(overviewTitle)
    overview.append(Title)
    overviewDescription1 = FormattedContent(overviewDescription[0])
    overviewDescription2 = FormattedContent(overviewDescription[1])
    overviewDescription3 = FormattedContent(overviewDescription[2])
    overview.append(overviewDescription1)
    overview.append(overviewDescription2)
    overview.append(overviewDescription3)
    #Append the Overview to the Question Form
    questionForm.append(overview)

    #Create the Questions, and Add them
    for i in xrange(numberOfTweets):
        overview = Overview()
        questionTitle = FormattedContent(
            '<font face="Helvetica" size="2"><b> Tweet #' + str(i + 1) +
            '</b></font>')
        overview.append(questionTitle)
        questionBody = FormattedContent('<font face="Helvetica" size="2">' +
                                        listOfTweets[i] + '</font>')
        overview.append(questionBody)
        #answerTuple = tuple([('<a href="https://wikipedia.org/en/' + y.replace(" ","_") + '" target="_blank">' + y + "</a>") for y in list(listOfAnswers[i])])
        #links = FormattedContent('<b>Links</b> | ' + answerTuple[0] + ' | ' + answerTuple[1])
        #overview.append(links)
        questionForm.append(overview)
        question = createQuestion(listOfTweetIDs[i], i, listOfTweets[i],
                                  ["Positive", "Negative"])
        questionForm.append(question)

    return questionForm
コード例 #11
0
    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)
コード例 #12
0
    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
コード例 #13
0
def PublishTasks(hitNum, maxAssignments):
    # sandbox in which to simulate: mechanicalturk.sandbox.amazonaws.com
    # real environment: mechanicalturk.amazonaws.com
    mtc = MTurkConnection(host='mechanicalturk.amazonaws.com')

    # print mtc.APIVersion
    # print mtc.get_account_balance()
    # print mtc.get_reviewable_hits()
    # print mtc.get_all_hits()

    #---------------  BUILD OVERVIEW -------------------

    # jbragg: Modified maximum reward description.
    #title = '(Maximum reward possible: $70) Identify the relation between two entities in English sentences'
    title = 'Identify the relation between two entities in English sentences'
    #description = 'You will be given English sentences in which your task is to identify the relation between two designated entities. Your reward will depend on how many questions you have answered. The maximum reward you can earn is $70.'
    description = 'You will be given English sentences in which your task is to identify the relation between two designated entities. Your reward will depend on how many questions you have answered. The maximum reward you can earn is approximately $5.'
    keywords = 'English sentences, relation identification'

    ratings = [('Very Bad', '-2'), ('Bad', '-1'), ('Not bad', '0'),
               ('Good', '1'), ('Very Good', '1')]

    #---------------  BUILD OVERVIEW -------------------

    overview = Overview()
    overview_title = 'Exercise link (please copy the link and paste it in your browser if it cannot be opened directly.)'
    link = '<a target="_blank"' ' href="http://128.208.3.167:3000/mturk">' ' http://128.208.3.167:3000/mturk</a>'
    # jbragg: Commented out long-term bonus.
    instructions = '<p>Instructions:</p><ul><li>You will be presented with sentences that have a person and a location highlighted.</li><li>Your task is to determine which of the 5 designated relations are expressed between the person and location.</li><li>You&#39;ll get paid $0.50 after each successful set of 20 questions<!-- -- plus a bonus of $2.00 after every 10 batches (equal to 200 questions)-->.</li><li>We know the correct answers to some of these sentence questions, and you can stay if you get these questions right.</li><li>You can start by going to the external link above now. After you finish all the questions, you will be provided with a confirm code, used for authentication and determining the appropriate amount of money as the payment.</li><li>In very rare cases where the website crashes, you could click backward and then forward on your browser to reload the question. It won\'t affect the payment because all the questions you have answered are recorded, on which the amount of payment is based. So please don\'t worry about that.</li></ul>'
    overview_content = link + instructions
    overview.append_field('Title', overview_title)
    overview.append(FormattedContent(overview_content))

    #---------------  BUILD QUESTION 1 -------------------

    qc1 = QuestionContent()
    qc1.append_field('Title', 'How looks the design ?')

    fta1 = SelectionAnswer(min=1,
                           max=1,
                           style='dropdown',
                           selections=ratings,
                           type='text',
                           other=False)

    q1 = Question(identifier='design',
                  content=qc1,
                  answer_spec=AnswerSpecification(fta1),
                  is_required=True)

    #---------------  BUILD QUESTION 2 -------------------

    qc2 = QuestionContent()
    qc2.append_field(
        'Title',
        'Confirm code \n1. The code will be provided to you as you finish from the exercise link. \n2. The code will be verified before paying. \n3. By the end of every 20 questions (as a batch), You can choose to finish and get a confirm code, or continue.'
    )

    fta2 = FreeTextAnswer()

    q2 = Question(identifier="Confirm_code",
                  content=qc2,
                  answer_spec=AnswerSpecification(fta2))

    #--------------- BUILD THE QUESTION FORM -------------------

    question_form = QuestionForm()
    question_form.append(overview)
    # question_form.append(q1)
    question_form.append(q2)

    #--------------- CREATE HITs -------------------

    HIT_num = hitNum
    for i in range(HIT_num):
        # max_assignments: how many replicas this HIT has
        mtc.create_hit(questions=question_form,
                       max_assignments=maxAssignments,
                       title=title,
                       description=description,
                       keywords=keywords,
                       duration=60 * 60 * 10,
                       reward=0.50)
コード例 #14
0
def generate_hits(subset, begin_index, args, data_ids, images_metainfo):

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

    ACCESS_ID = amazon_config.ACCESS_ID
    SECRET_KEY = amazon_config.SECRET_KEY
    HOST = 'mechanicalturk.amazonaws.com'

    mtc = MTurkConnection(aws_access_key_id=ACCESS_ID,
                          aws_secret_access_key=SECRET_KEY,
                          host=HOST)

    title = 'Give your opinion of interestingness level about images'
    description = (
        'Watch images and give us your opinion of interestingness level about the images'
    )
    keywords = 'image, interestingness, interesting, rating, opinions'

    ratings = [('Very boring', '-2'), ('Boring', '-1'), ('Neutral', '0'),
               ('Interesting', '1'),
               ('Very interesting, I would like to share it with my friends.',
                '2')]

    #---------------  BUILD OVERVIEW -------------------

    overview = Overview()
    overview.append_field(
        'Title',
        'Give your opinion about interestingness level on those images')

    #---------------  BUILD QUESTIONs -------------------

    questions = []

    utils.write_file(subset, args.o + '.index_' + str(begin_index) + '.txt')

    index = 0
    for image_url in subset:

        image_id = data_ids[index]
        image = images_metainfo[image_id]
        interestingness = 0

        if ('repin_count' in image):
            interestingness = int(image['repin_count']) + int(
                image['like_count'])
        #else:
        # interestingness = int(image['interestingness'])

        index = index + 1

        qc = QuestionContent()

        context = ''
        if (interestingness > 0):
            context = ' (shared by ' + str(interestingness) + ' people)'

        qc.append_field('Title',
                        'How interesting the image' + context + ' to you?')
        qc.append(
            FormattedContent('<img src="' + image_url + '" alt="image" />'))

        fta = SelectionAnswer(min=1,
                              max=1,
                              style='dropdown',
                              selections=ratings,
                              type='text',
                              other=False)

        q = Question(identifier='interestingness',
                     content=qc,
                     answer_spec=AnswerSpecification(fta),
                     is_required=True)

        questions.append(q)

    #--------------- BUILD THE QUESTION FORM -------------------

    question_form = QuestionForm()
    question_form.append(overview)

    for question in questions:
        question_form.append(question)

    # BUILD QUALIFICATION

    qualifications = Qualifications()
    req = PercentAssignmentsApprovedRequirement(comparator="GreaterThan",
                                                integer_value="95")
    qualifications.add(req)

    #--------------- CREATE THE HIT -------------------

    mtc.create_hit(questions=question_form,
                   qualifications=qualifications,
                   max_assignments=10,
                   title=title,
                   description=description,
                   keywords=keywords,
                   duration=60 * 30,
                   reward=0.2)
コード例 #15
0
ファイル: djurk_demo.py プロジェクト: sekharroyal/djurk
def demo_create_favorite_color_hit():
    """A HIT to determine the Worker's favorite color"""

    TITLE = 'Tell me your favorite color'
    DESCRIPTION = ('This is a HIT that is created by a computer program '
                   'to demonstrate how Mechanical Turk works. This should '
                   'be a free HIT for the worker.')
    KEYWORDS = 'data collection, favorite, color'
    DURATION = 15 * 60  # 15 minutes (Time to work on HIT)
    MAX_ASSIGNMENTS = 1  # Number of assignments per HIT
    REWARD_PER_ASSIGNMENT = 0.00  # $0.00 USD (1 cent)

    #--------------- BUILD HIT container -------------------
    overview = Overview()
    overview.append_field('Title', TITLE)
    overview.append(
        FormattedContent(
            "<p>This is an experiment to learn Mechanical Turk</p>"))

    #---------------  BUILD QUESTION 1 -------------------
    question_content = QuestionContent()
    question_content.append(
        FormattedContent(
            "<b>What is your favorite color?</b> There isn't a financial "
            "reward for answering, but you will get an easy approval for your "
            "statistics."))

    free_text_answer = FreeTextAnswer(num_lines=1)

    q1 = Question(identifier='favorite_color',
                  content=question_content,
                  answer_spec=AnswerSpecification(free_text_answer),
                  is_required=True)

    #---------------  BUILD QUESTION 3 -------------------
    question_content = QuestionContent()
    question_content.append(
        FormattedContent("""<p>Give me a fun comment:</p>"""))

    q2 = Question(identifier="comments",
                  content=question_content,
                  answer_spec=AnswerSpecification(FreeTextAnswer()))

    #--------------- BUILD THE QUESTION FORM -------------------
    question_form = QuestionForm()
    question_form.append(overview)
    question_form.append(q1)
    question_form.append(q2)

    #--------------- CREATE THE HIT -------------------
    mtc = get_connection()
    hit = mtc.create_hit(questions=question_form,
                         max_assignments=MAX_ASSIGNMENTS,
                         title=TITLE,
                         description=DESCRIPTION,
                         keywords=KEYWORDS,
                         duration=DURATION,
                         reward=REWARD_PER_ASSIGNMENT)

    #---------- SHOW A LINK TO THE HIT GROUP -----------
    base = get_worker_url()

    print "\nVisit this website to see the HIT that was created:"
    print "%s/mturk/preview?groupId=%s" % (base, hit[0].HITTypeId)

    return hit[0]
コード例 #16
0
def createForm(overview, questions):
	q_form = QuestionForm()
	q_form.append(overview)
	for q in questions:
		q_form.append(q)
	return q_form
コード例 #17
0
ファイル: take_out_a_hit.py プロジェクト: JuliaMerz/pincys
def new_rate_hit(PIN_IMAGE_URL, PIN_IMAGE_TITLE, MACYS_IMAGE_URL,
                 MACYS_IMAGE_TITLE):
    mtc = MTurkConnection(aws_access_key_id=AWS_ACCESS_KEY_ID,
                          aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
                          host=HOST)

    if debug: print mtc.get_account_balance()

    title = 'Match these Pictures to Macy\'s Products'
    description = 'Look at this photo and match it to Macy\'s products'
    keywords = 'clothing, rating, opinions, easy, quick, macys'

    ratings = [('Very Bad', '1'), ('Bad', '2'), ('OK', '3'), ('Good', '4'),
               ('Very Good', '5')]

    #make overview

    overview = Overview()
    overview.append_field('Title', 'Rank how these two images match.')
    overview.append(
        FormattedContent('<table border="1">><tr><td width="50%"><img src="' +
                         PIN_IMAGE_URL + '" alt="Pintrest Image" /></td>'
                         '<td width="50%"><img src="' + MACYS_IMAGE_URL +
                         '" alt="Macys Image" /></td></tr><tr>'
                         '<td width="50%">' + PIN_IMAGE_TITLE +
                         '</td><td width="50%">' + MACYS_IMAGE_TITLE +
                         '</td></tr></table>'))
    #make q1

    qc1 = QuestionContent()
    qc1.append_field('Title', 'Rank the match between these two')

    fta1 = SelectionAnswer(min=1,
                           max=1,
                           style='dropdown',
                           selections=ratings,
                           type='text',
                           other=False)

    q1 = Question(identifier='rating',
                  content=qc1,
                  answer_spec=AnswerSpecification(fta1),
                  is_required=True)

    #make q2

    qc2 = QuestionContent()
    qc2.append_field('Title', 'Comments about the HIT (Optional)')

    fta2 = FreeTextAnswer()

    q2 = Question(identifier="comments",
                  content=qc2,
                  answer_spec=AnswerSpecification(fta2))

    #make 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=1,
                   title=title,
                   description=description,
                   keywords=keywords,
                   duration=60 * 5,
                   reward=0.05)
コード例 #18
0
def check_notes_mailbox():
    MTURK_HOST = run_mturk('get_extract_keywords_results')
    if not MTURK_HOST:
        return

    try:
        MAILBOX_USER = os.environ['NOTES_MAILBOX_USERNAME']
        MAILBOX_PASSWORD = os.environ['NOTES_MAILBOX_PASSWORD']
        FILEPICKER_API_KEY = os.environ['FILEPICKER_API_KEY']
    except:
        logger.warn(
            'Could not find notes mailbox secrets, not running check_notes_mailbox'
        )
        return

    connection = MTurkConnection(settings.AWS_ACCESS_KEY_ID,
                                 settings.AWS_SECRET_ACCESS_KEY,
                                 host=MTURK_HOST)

    mailbox = poplib.POP3_SSL('pop.gmail.com', 995)
    mailbox.user(MAILBOX_USER)
    mailbox.pass_(MAILBOX_PASSWORD)
    numMessages = len(mailbox.list()[1])
    for i in range(numMessages):
        # construct message object from raw message
        raw_message_string = '\n'.join(mailbox.retr(i + 1)[1])
        message = email.message_from_string(raw_message_string)

        if not message.is_multipart():
            logger.warn('Got an email with no attachments')
            continue

        attachments = []
        message_body = ''

        message_parts = message.get_payload()
        for part in message_parts:
            # Look for the message's plain text body
            if part.get_content_type(
            ) == 'text/plain' and part['Content-Disposition'] is None:
                message_body = part.get_payload()

            # Look for attachments
            elif part['Content-Disposition'] and 'attachment;' in part[
                    'Content-Disposition']:
                attachment_mimetype = part.get_content_type()
                attachment_filename = re.search(
                    CONTENT_DISPOSITION_REGEX,
                    part['Content-Disposition']).group('filename')

                if part['Content-Transfer-Encoding'] == 'base64':
                    attachment_data = base64.decodestring(part.get_payload())
                else:
                    attachment_data = part.get_payload()

                # Upload attachment to filepicker
                resp = requests.post('https://www.filepicker.io/api/store/S3?key={key}&policy={policy}&' \
                                     'signature={signature}&mimetype={mimetype}&filename={filename}'
                                     .format(key=FILEPICKER_API_KEY, policy=FP_POLICY_READ_WRITE,
                                             signature=FP_SIGNATURE_READ_WRITE, mimetype=attachment_mimetype,
                                             filename=attachment_filename),
                                      data=attachment_data)

                if resp.status_code == 200:
                    url = json.loads(resp.text)['url']
                    url = url + '?policy={policy}&amp;signature={signature}'\
                        .format(policy=FP_POLICY_READ, signature=FP_SIGNATURE_READ)
                    attachments.append((url, attachment_filename))
                else:
                    logger.warn('Could not upload an attachment to filepicker')

        message_subject = message['Subject']

        overview = Overview()
        overview.append(
            FormattedContent(
                EMAIL_HIT_OVERVIEW_TEMPLATE.format(subject=message_subject,
                                                   body=message_body,
                                                   attachments='')))

        single_line_answer = FreeTextAnswer()
        single_line_answer.num_lines = 1

        question_form = QuestionForm()
        question_form.append(overview)

        course_spam_content = QuestionContent()
        course_spam_content.append_field(
            'Title',
            'Does the email contain course notes (check attachments below)?')
        answer = SelectionAnswer(style='dropdown',
                                 selections=[('No', 'no'), ('Yes', 'yes')])
        course_spam = Question(identifier=COURSE_SPAM_QID,
                               content=course_spam_content,
                               answer_spec=AnswerSpecification(answer),
                               is_required=True)
        question_form.append(course_spam)

        course_name_content = QuestionContent()
        course_name_content.append_field('Title', 'Course Name')
        course_name = Question(
            identifier=COURSE_NAME_QID,
            content=course_name_content,
            answer_spec=AnswerSpecification(single_line_answer),
            is_required=True)
        question_form.append(course_name)

        instructor_names_content = QuestionContent()
        instructor_names_content.append_field('Title', 'Instructor Name(s)')
        instructor_names = Question(
            identifier=INSTRUCTOR_NAMES_QID,
            content=instructor_names_content,
            answer_spec=AnswerSpecification(single_line_answer),
            is_required=False)
        question_form.append(instructor_names)

        school_name_content = QuestionContent()
        school_name_content.append_field('Title', 'School Name')
        school_name = Question(
            identifier=SCHOOL_NAME_QID,
            content=school_name_content,
            answer_spec=AnswerSpecification(single_line_answer),
            is_required=True)
        question_form.append(school_name)

        department_name_content = QuestionContent()
        department_name_content.append_field('Title', 'Department Name')
        department_name = Question(
            identifier=DEPARTMENT_NAME_QID,
            content=department_name_content,
            answer_spec=AnswerSpecification(single_line_answer),
            is_required=False)
        question_form.append(department_name)

        for i in range(len(attachments)):
            overview = Overview()
            overview.append(
                FormattedContent(
                    EMAIL_HIT_ATTACHMENT_OVERVIEW_TEMPLATE.format(
                        link=attachments[i][0], name=attachments[i][1])))

            question_form.append(overview)

            note_title_content = QuestionContent()
            note_title_content.append_field('Title', 'Note Title')
            note_title = Question(
                identifier=NOTE_TITLE_QID_TEMPLATE + str(i),
                content=note_title_content,
                answer_spec=AnswerSpecification(single_line_answer),
                is_required=True)
            question_form.append(note_title)

            note_category_content = QuestionContent()
            note_category_content.append_field('Title', 'Note Category')
            answer = SelectionAnswer(style='dropdown',
                                     selections=NOTE_CATEGORIES_FOR_MTURK)
            note_category = Question(identifier=NOTE_CATEGORY_QID_TEMPLATE +
                                     str(i),
                                     content=note_category_content,
                                     answer_spec=AnswerSpecification(answer),
                                     is_required=True)
            question_form.append(note_category)

        hit = connection.create_hit(questions=question_form,
                                    max_assignments=1,
                                    title=EMAIL_HIT_TITLE,
                                    description=EMAIL_HIT_DESCRIPTION,
                                    keywords=EMAIL_HIT_KEYWORDS,
                                    duration=EMAIL_HIT_DURATION,
                                    reward=EMAIL_HIT_REWARD,
                                    qualifications=EMAIL_HIT_QUALIFICATION)[0]
コード例 #19
0
def generate_hits(mtc_type, subset, begin_index, args):

    from boto.mturk.connection import MTurkConnection
    from boto.mturk.question import QuestionContent, Question, QuestionForm, Overview, AnswerSpecification, SelectionAnswer, FormattedContent, FreeTextAnswer
    from boto.mturk.qualification import PercentAssignmentsApprovedRequirement, Qualifications, Requirement


    mtc = mtk_utils.get_mtc(mtc_type)
 
    title = 'Give your opinion of aesthetics level about images'
    description = ('View images and give us your opinion of aesthetics level about the images')
    keywords = 'image, aesthetic, aesthetics, rating, opinions'

    ratings =[('Very ugly','-2'),
             ('Ugly','-1'),
             ('Neutral','0'),
             ('Beautiful','1'),
             ('Very beautiful, I would like to take such beautiful photo too.','2')]

    #---------------  BUILD OVERVIEW -------------------

    overview = Overview()
    overview.append_field('Title', 'Give your opinion about aesthetics level on those images')
 
    #---------------  BUILD QUESTIONs -------------------

    questions = []

    if (args.m != 'qua'):
        utils.write_file(subset, args.o + '.index_' + str(begin_index) + '.txt')

    if (args.m == 'qua_init' and begin_index > 0):
        return

    for image_url in subset:
     
        qc = QuestionContent()
        qc.append_field('Title','How beautiful the image to you?')
        qc.append(FormattedContent('<img src="' + image_url + '" alt="image" />'))


        fta = SelectionAnswer(min=1, max=1,style='dropdown',
                              selections=ratings,
                              type='text',
                              other=False)

        q = Question(identifier='aesthetics',
                      content=qc,
                      answer_spec=AnswerSpecification(fta),
                      is_required=True)

        questions.append(q)

 
    #--------------- BUILD THE QUESTION FORM -------------------
 
    question_form = QuestionForm()
    question_form.append(overview)

    for question in questions:
        question_form.append(question)

    # BUILD QUALIFICATION

    qualifications = Qualifications()
    req = PercentAssignmentsApprovedRequirement(comparator = "GreaterThan", integer_value = "95")
    qualifications.add(req)

    if (args.m == 'qua'):
        if (args.q != None): 
            qua_req = Requirement(qualification_type_id = args.q, comparator = 'EqualTo', integer_value = '1')
            qualifications.add(qua_req)
        else:
            print("Please give qualification type id in 'qua' mode.")
            sys.exit(0)
 
    #--------------- CREATE THE HIT -------------------
 
    hit = mtc.create_hit(questions = question_form,
                   qualifications = qualifications,
                   max_assignments = 10 * 2,
                   title = title,
                   description = description,
                   keywords = keywords,
                   duration = 60 * 30 * 2,
                   reward = 0.2 * 2)

    if (args.m == 'qua_init'):
        print("Create qualification type for HIT id: " + hit[0].HITId)
        quatype = mtc.create_qualification_type(name = hit[0].HITId, description = "Temporary qualification for HIT " + hit[0].HITId, status = 'Active')
        print("Qualification type id: " + quatype[0].QualificationTypeId)
コード例 #20
0
    def question_form_formatted_content(self):
        qc = QuestionContent()
        formatted_xhtml = """\
<table border="1">
  <tr>
    <td></td>
    <td align="center">1</td>
    <td align="center">2</td>
    <td align="center">3</td>
  </tr>
  <tr>
    <td align="right">A</td>
    <td align="center"><b>X</b></td>
    <td align="center">&nbsp;</td>
    <td align="center"><b>O</b></td>
  </tr>
  <tr>
    <td align="right">B</td>
    <td align="center">&nbsp;</td>
    <td align="center"><b>O</b></td>
    <td align="center">&nbsp;</td>
  </tr>
  <tr>
    <td align="right">C</td>
    <td align="center">&nbsp;</td>
    <td align="center">&nbsp;</td>
    <td align="center"><b>X</b></td>
  </tr>
  <tr>
    <td align="center" colspan="4">It is <b>X</b>'s turn.</td>
  </tr>
</table>
"""
        qc.append(FormattedContent(formatted_xhtml))

        q = Question(
            identifier="Formatted content test!",
            content=qc,
            answer_spec=AnswerSpecification(
                SelectionAnswer(
                    min=1,
                    max=5,
                    style='checkbox',
                    selections=[
                        (Binary(
                            'image', 'jpg',
                            'http://images.google.com/images?q=tbn:ANd9GcSh1HXq3WyOvvG7-AgvNugKC2LzImMUvUDNTuDAPwVKuw8NZzvLN62pGYhX:farm1.static.flickr.com/21/24204504_e143536a2e.jpg',
                            'steak1').get_as_xml(), 'img1'),
                        (Binary(
                            'image', 'jpg',
                            'http://images.google.com/images?q=tbn:ANd9GcTkMoChevUBvQfmfksKDBM5oj4V2ruj6riqv7kC-_6qf9MR0igeBlJLkSI:www.miranchomeatmarket.com/images/T-%2520bone%2520steak.jpg',
                            'steak2').get_as_xml(), 'img2'),
                        (Binary(
                            'image', 'jpg',
                            'http://images.google.com/images?q=tbn:ANd9GcSttsqT7kj9siDKZg1p4fU6W9IFlMZHCFSxFd49ECJR1Bu_1QlHQwmH1DU:img4.myrecipes.com/i/recipes/ck/06/08/grilled-steak-ck-1215910-l.jpg',
                            'steak3').get_as_xml(), 'img3'),
                        (Binary(
                            'image', 'jpg',
                            'http://images.google.com/images?q=tbn:ANd9GcRfdQ-vuNt-W4W7JZRkAmbZpE6LLA0puCQs5erSzrGtsOY8H8t-vgEzqA:www.greendiamondgrille.com/images/new/NewYorkStripSteak.jpg',
                            'steak4').get_as_xml(), 'img4'),
                        (Binary(
                            'image', 'jpg',
                            'http://images.google.com/images?q=tbn:ANd9GcTsJzCp6En1R9yvFQw7bGsSxiiQCqlMrFg7XCbcJ13G39Aa3e6ZilWW34oI:www.bunrab.com/dailyfeed/dailyfeed_images_jan-07/df07_01-08_steak.jpg',
                            'steak5').get_as_xml(), 'img5'),
                        (Binary(
                            'image', 'jpg',
                            'http://images.google.com/images?q=tbn:ANd9GcTkMoChevUBvQfmfksKDBM5oj4V2ruj6riqv7kC-_6qf9MR0igeBlJLkSI:www.miranchomeatmarket.com/images/T-%2520bone%2520steak.jpg',
                            'steak2').get_as_xml(), 'img6'),
                        (Binary(
                            'image', 'jpg',
                            'http://images.google.com/images?q=tbn:ANd9GcSttsqT7kj9siDKZg1p4fU6W9IFlMZHCFSxFd49ECJR1Bu_1QlHQwmH1DU:img4.myrecipes.com/i/recipes/ck/06/08/grilled-steak-ck-1215910-l.jpg',
                            'steak3').get_as_xml(), 'img7'),
                        (Binary(
                            'image', 'jpg',
                            'http://images.google.com/images?q=tbn:ANd9GcRfdQ-vuNt-W4W7JZRkAmbZpE6LLA0puCQs5erSzrGtsOY8H8t-vgEzqA:www.greendiamondgrille.com/images/new/NewYorkStripSteak.jpg',
                            'steak4').get_as_xml(), 'img8'),
                        (Binary(
                            'image', 'jpg',
                            'http://images.google.com/images?q=tbn:ANd9GcTsJzCp6En1R9yvFQw7bGsSxiiQCqlMrFg7XCbcJ13G39Aa3e6ZilWW34oI:www.bunrab.com/dailyfeed/dailyfeed_images_jan-07/df07_01-08_steak.jpg',
                            'steak5').get_as_xml(), 'img9')
                    ],
                    type='binary')),
            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=1,
                    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
コード例 #21
0
ファイル: snippet.py プロジェクト: someburner/GistsHub
#
# A QuestionForm is a container for what the HIT task is shaped like. In this
# example, we build one like:
#
#     <QuestionForm>
#        <Overview></Overview>
#        <QuestionContent></QuestionContent>
#        ...,
#        <QuestionContent></QuestionContent>
#     </QuestionForm>

question_form_title = overview_title  # reuse it
question_form_description = 'Help us by listing your five favorite things'
question_form_reward = 0.2

qf = QuestionForm()
qf.append(overview)
for q in question_list:
    qf.append(q)

# Assignments is an interesting concept in the mechanical turk API. You can have
# multiple instances of a hit's design by assigning it multiple times.
#
# Many users, however, work through the web interface and seem to create many
# copies of the same HIT instead. Be mindful of the way assignments are used.
max_assignments = 1

# create funciton to make a hit using our arguments
make_demo_hit = lambda: mtc.create_hit(question=qf,
                                       max_assignments=max_assignments,
                                       title=question_form_title,
コード例 #22
0
    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
コード例 #23
0
def create_crop_hit(mturk,
                    URLs,
                    num_assignment,
                    qualification=Qualifications()):
    # Constant data for HIT generation
    hit_title = "Photo Quality Assessment"
    hit_description = "This task involves viewing pairs of pictures and judging which picture among the image pair is more beautiful."
    lifetime = 259200
    keywords = ["photo", "quality", "ranking"]
    duration = 30 * 60
    reward = 0.05
    #approval_delay = 86400

    # Question form for the HIT
    question_form = QuestionForm()

    overview = Overview()
    overview.append_field('Title', 'Photo Quality Assessment')
    overview.append(
        FormattedContent(
            'For each question, please choose either the left or right image which you think is more beautiful in terms of its <u>composition</u>.'
        ))
    overview.append(
        FormattedContent(
            '<b>Hints: Please make your decision based on several "rules of thumb" in photography, such as rule of thirds, visual balance and golden ratio.</b>'
        ))
    #overview.append(FormattedContent('<b>You may also make your decision by judging which image contains less unimportant or distracting contents</b>.'))
    overview.append(
        FormattedContent(
            'For those hard cases, please just select your preferred image based on your sense of aesthetics.'
        ))
    question_form.append(overview)

    ratings = [('Left', '0'), ('Right', '1')]
    for i in xrange(len(URLs)):
        qc = QuestionContent()
        qc.append_field('Title', 'Question')
        qc.append_field(
            'Text',
            'Please indicate which one of the following images is more beautiful.'
        )
        qc.append(
            FormattedContent('<img src="' + URLs[i] +
                             '" alt="Image not shown correctly!"></img>'))
        #URLs[i]
        fta = SelectionAnswer(min=1,
                              max=1,
                              style='radiobutton',
                              selections=ratings,
                              type='text',
                              other=False)
        q = Question(identifier='photo_pair_' + str(i),
                     content=qc,
                     answer_spec=AnswerSpecification(fta),
                     is_required=True)
        question_form.append(q)

    hit_res = mturk.create_hit(
        title=hit_title,
        description=hit_description,
        reward=Price(amount=reward),
        duration=duration,
        keywords=keywords,
        #approval_delay=approval_delay,
        question=question_form,
        #lifetime=lifetime,
        max_assignments=num_assignment,
        qualifications=qualification)
    # return HIT ID
    return hit_res[0].HITId
コード例 #24
0
	def testCallCreateHitWithQuestionForm(self):
		create_hit_rs = self.conn.create_hit(
			questions=QuestionForm([self.get_question()]),
			**self.get_hit_params()
			)
コード例 #25
0
ファイル: question_form.py プロジェクト: stolati/fhack
              answer_spec=AnswerSpecification(fta1),
              is_required=True)
 
#---------------  BUILD QUESTION 2 -------------------
 
qc2 = QuestionContent()
qc2.append_field('Title','Your personal comments')
 
fta2 = FreeTextAnswer()
 
q2 = Question(identifier="comments",
              content=qc2,
              answer_spec=AnswerSpecification(fta2))
 
#--------------- 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=1,
               title=title,
               description=description,
               keywords=keywords,
               duration = 60*5,
               reward=0.05)
コード例 #26
0
 def launch(self, data={}):
     qf = QuestionForm()
     form_json = BotoFormGenerator.inject_data(self.form_json, data)
     BotoFormGenerator.from_json(qf, form_json)
     return self.create_hit(qf)
コード例 #27
0
ファイル: mturk_hits.py プロジェクト: yingning/text-scene
def make_hit(image_url):
    title = 'Label image with its location'
    description = 'Answer questions about an image to label its location.'
    keywords = 'image categorization, locations, scene recognition'

    in_out = [('indoors', '0'), ('outdoors', '1')]
    nat_manmade = [('man-made', '0'), ('natural', '1')]
    functions = [('transportation/urban', '0'), ('restaurant', '1'),
                 ('recreation', '2'), ('domestic', '3'),
                 ('work/education', '4'), ('other/unclear', '5')]
    landscapes = [('body of water/beach', '0'), ('field', '1'),
                  ('mountain', '2'), ('forest/jungle', '3'),
                  ('other/unclear', '4')]

    #---------------  BUILD OVERVIEW -------------------

    overview = Overview()
    overview.append_field('Title', title)
    with open(INSTRUCTIONS_HTML) as html:
        instructions = html.read()
    overview.append(FormattedContent(instructions))

    image = Binary('image', None, image_url, 'image')
    overview.append(image)

    #---------------  BUILD QUESTION 1 -------------------

    qc1 = QuestionContent()
    qc1.append_field(
        'Text', 'Is the location shown in the image indoors or outdoors?')

    fta1 = SelectionAnswer(min=1,
                           max=1,
                           style='checkbox',
                           selections=in_out,
                           type='text',
                           other=False)

    q1 = Question(identifier='Question 1',
                  content=qc1,
                  answer_spec=AnswerSpecification(fta1),
                  is_required=True)

    #---------------  BUILD QUESTION 2 -------------------

    qc2 = QuestionContent()
    qc2.append_field(
        'Text', 'Is the location shown in the image man-made or ' +
        'natural? Examples of man-made locations include ' +
        'buildings and parks while examples of natural ' +
        'locations include mountains and rivers.')

    fta2 = SelectionAnswer(min=1,
                           max=1,
                           style='checkbox',
                           selections=nat_manmade,
                           type='text',
                           other=False)

    q2 = Question(identifier='Question 2',
                  content=qc2,
                  answer_spec=AnswerSpecification(fta2),
                  is_required=True)

    #---------------  BUILD QUESTION 3 -------------------

    qc3 = QuestionContent()
    qc3.append_field(
        'Text', 'If the location in the image is man-made, what is the ' +
        'general function or type of the location? If the ' +
        'location is natural (not man-made), don\'t select ' +
        'anything here.')

    fta3 = SelectionAnswer(min=0,
                           max=1,
                           style='checkbox',
                           selections=functions,
                           type='text',
                           other=False)

    q3 = Question(identifier='Question 3',
                  content=qc3,
                  answer_spec=AnswerSpecification(fta3),
                  is_required=False)

    #---------------  BUILD QUESTION 4 -------------------

    qc4 = QuestionContent()
    qc4.append_field(
        'Text', 'If the location in the picture is natural, what ' +
        'kind of natural location is it? If the location ' +
        'man-made (not natural), don\'t select anything here.')

    fta4 = SelectionAnswer(min=0,
                           max=1,
                           style='checkbox',
                           selections=landscapes,
                           type='text',
                           other=False)

    q4 = Question(identifier='Question 4',
                  content=qc4,
                  answer_spec=AnswerSpecification(fta4),
                  is_required=False)

    #--------------- BUILD THE QUESTION FORM -------------------

    question_form = QuestionForm()
    question_form.append(overview)
    question_form.append(q1)
    question_form.append(q2)
    question_form.append(q3)
    question_form.append(q4)

    #-------------- QUALIFICATIONS -------------------

    percent = PercentAssignmentsApprovedRequirement('GreaterThanOrEqualTo', 95)
    number = NumberHitsApprovedRequirement('GreaterThanOrEqualTo', 200)
    quals = Qualifications()
    quals.add(percent)
    quals.add(number)

    #--------------- CREATE THE HIT -------------------

    mtc.create_hit(questions=question_form,
                   max_assignments=1,
                   title=title,
                   description=description,
                   keywords=keywords,
                   qualifications=quals,
                   annotation=image_url,
                   duration=60 * 10,
                   reward=0.03)
コード例 #28
0
def submit_extract_keywords_hit(note):
    """Create a Mechanical Turk HIT that asks a worker to
    choose keywords and definitions from the given note."""

    MTURK_HOST = run_mturk('submit_extract_keywords_hit')
    if not MTURK_HOST:
        return

    connection = MTurkConnection(settings.AWS_ACCESS_KEY_ID,
                                 settings.AWS_SECRET_ACCESS_KEY,
                                 host=MTURK_HOST)

    if note.course.school:
        title = KEYWORDS_HIT_TITLE_TEMPLATE.format(
            course=note.course.name, school=note.course.school.name)
    else:
        title = KEYWORDS_HIT_TITLE_TEMPLATE.format(
            course=note.course.name, school=note.course.department.school.name)

    overview = Overview()
    overview.append(
        FormattedContent(
            KEYWORDS_HIT_OVERVIEW_TEMPLATE.format(
                domain=Site.objects.get_current(),
                link=note.get_absolute_url())))

    keyword_fta = FreeTextAnswer()
    keyword_fta.num_lines = 1

    definition_fta = FreeTextAnswer()
    definition_fta.num_lines = 3

    question_form = QuestionForm()
    question_form.append(overview)

    for i in range(
            min(len(KEYWORDS_HIT_KEYWORD_FIELDS),
                len(KEYWORDS_HIT_DEFINITION_FIELDS))):
        keyword_content = QuestionContent()
        keyword_content.append_field('Title',
                                     KEYWORDS_HIT_KEYWORD_FIELDS[i][1])
        keyword_question = Question(
            identifier=KEYWORDS_HIT_KEYWORD_FIELDS[i][0],
            content=keyword_content,
            answer_spec=AnswerSpecification(keyword_fta),
            is_required=True if i <= 10 else False)
        question_form.append(keyword_question)

        definition_content = QuestionContent()
        definition_content.append_field('Title',
                                        KEYWORDS_HIT_DEFINITION_FIELDS[i][1])
        definition_question = Question(
            identifier=KEYWORDS_HIT_DEFINITION_FIELDS[i][0],
            content=definition_content,
            answer_spec=AnswerSpecification(definition_fta),
            is_required=False)
        question_form.append(definition_question)

    hit = connection.create_hit(questions=question_form,
                                max_assignments=1,
                                title=title,
                                description=KEYWORDS_HIT_DESCRIPTION,
                                keywords=KEYWORDS_HIT_KEYWORDS,
                                duration=KEYWORDS_HIT_DURATION,
                                reward=KEYWORDS_HIT_REWARD,
                                qualifications=KEYWORDS_HIT_QUALIFICATION,
                                annotation=str(note.id))[0]

    KeywordExtractionHIT.objects.create(HITId=hit.HITId,
                                        note=note,
                                        processed=False)
コード例 #29
0
ファイル: connection.py プロジェクト: prufrax/boto
    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)])
コード例 #30
0
ファイル: take_out_a_hit.py プロジェクト: JuliaMerz/pincys
def new_sugg_hit(PIN_IMAGE_URL, PIN_IMAGE_TITLE):

    mtc = MTurkConnection(aws_access_key_id=AWS_ACCESS_KEY_ID,
                          aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
                          host=HOST)

    if debug: print mtc.get_account_balance()

    title = 'Match these Pictures to Macy\'s Products'
    description = 'Look at this photo and match it to Macy\'s products'
    keywords = 'clothing, rating, opinions, easy, quick, macys'

    #make overview

    overview = Overview()
    overview.append_field('Title',
                          'Find three Macys.com Product Web IDs That Match')
    overview.append(
        FormattedContent('<img src="' + PIN_IMAGE_URL +
                         '" alt="Pintrest Image" />'
                         '<br />' + PIN_IMAGE_TITLE))

    #make webid1

    qc1 = QuestionContent()
    qc1.append_field('Title', 'First WebID Code')

    fta1 = FreeTextAnswer(num_lines=1)

    q1 = Question(identifier="FirstWebCode",
                  content=qc1,
                  answer_spec=AnswerSpecification(fta1))

    #make webid2

    qc2 = QuestionContent()
    qc2.append_field('Title', 'Second WebID Code')

    fta2 = FreeTextAnswer(num_lines=1)

    q2 = Question(identifier="SecondWebCode",
                  content=qc2,
                  answer_spec=AnswerSpecification(fta2))

    #make webid1

    qc3 = QuestionContent()
    qc3.append_field('Title', 'Third WebID Code')

    fta3 = FreeTextAnswer(num_lines=1)

    q3 = Question(identifier="ThirdWebCode",
                  content=qc3,
                  answer_spec=AnswerSpecification(fta3))

    #make question form

    question_form = QuestionForm()
    question_form.append(overview)
    question_form.append(q1)
    question_form.append(q2)
    question_form.append(q3)

    #--------------- CREATE THE HIT -------------------

    mtc.create_hit(questions=question_form,
                   max_assignments=1,
                   title=title,
                   description=description,
                   keywords=keywords,
                   duration=60 * 5,
                   reward=0.05)