def __generate_qualification_question(self, sentence_data, question_num):
        '''
            Returns a sentence coding qualification test, with answer key
        '''
        url_left = sentence_data['question_'+str(question_num+1)]['URL_left']
        url_right = sentence_data['question_'+str(question_num+1)]['URL_right']

        # retrieve picture to examine its resolution
        file_left = cStringIO.StringIO(urllib.urlopen(url_left).read())
        img_left = Image.open(file_left)
        left_height = img_left.height
        if left_height > 400:
            left_height = 400

        file_right = cStringIO.StringIO(urllib.urlopen(url_right).read())
        img_right = Image.open(file_right)
        right_height = img_right.height
        if right_height > 400:
            right_height = 400

        options = [('Left', '0'), ('Right','1')]
        question_content = QuestionContent()
        question_content.append_field('Title', 'Indicate which one of the following images is better in terms of composition.')
        question_content.append(FormattedContent('Left:&nbsp;<img src="' + url_left + '" height="' + str(left_height) +
            '" alt="Left picture"></img>Right:&nbsp;<img src="' + url_right + '" height="' + str(right_height) + '" alt="Right picutre"></img>'))
        answer_selection = SelectionAnswer(min=1, max=1, style='radiobutton', selections=options, type='text', other=False)
        question = Question(identifier='photo_pair_'+str(question_num),
                            content=question_content,
                            answer_spec=AnswerSpecification(answer_selection),
                            is_required=True)

        # Glue everything together in a dictionary, keyed by the question_num
        return {"question_num" : question_num,
                "question_"+str(question_num) : question,
                "answer_key_"+str(question_num) : self.__generate_answer_form(sentence_data, question_num)}
Esempio n. 2
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
Esempio n. 3
0
def createQuestion(identifier, displayName, questionText, answers):
    """
    Create a question
    """
    questionContent = QuestionContent()

    #questionTitle = FormattedContent('<font face="Helvetica" size="2"><b> Sentence #' + str(displayName + 1) + '</b></font>')
    #questionContent.append(questionTitle)

    instruction = 'Which of the following sentiments <i>best</i> matches the sentiment expressed in the above sentence?'

    #questionBody = FormattedContent('<font face="Helvetica" size="2">' + questionText + '</font>')
    #questionContent.append(questionBody)

    questionInstruction = FormattedContent('<font face="Helvetica" size="2">' +
                                           instruction + '</font>')
    questionContent.append(questionInstruction)

    #answerTuple = tuple([('<a href="https://wikipedia.org/en/' + y.replace(" ","_") + '" target="_blank">' + y + "</a>") for y in list(answers)])
    #links = FormattedContent('<b>Links</b> | ' + answerTuple[0] + ' | ' + answerTuple[1])
    #questionContent.append(links)

    displayName = "Question #" + str(displayName + 1)
    question = MTurkQuestion(identifier=identifier,
                             content=questionContent,
                             display_name=displayName,
                             answer_spec=AnswerSpecification(
                                 buildAnswers(answers)),
                             is_required=True)
    return question
Esempio n. 4
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
    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
Esempio n. 6
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
Esempio n. 7
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
Esempio n. 8
0
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'])
Esempio n. 9
0
    def __generate_qualification_question(self, sentence_data, question_num):
        '''
            Returns a sentence coding qualification test, with answer key
        '''
        url_left = sentence_data['question_' +
                                 str(question_num + 1)]['URL_left']
        url_right = sentence_data['question_' +
                                  str(question_num + 1)]['URL_right']

        # retrieve picture to examine its resolution
        file_left = cStringIO.StringIO(urllib.urlopen(url_left).read())
        img_left = Image.open(file_left)
        left_height = img_left.height
        if left_height > 400:
            left_height = 400

        file_right = cStringIO.StringIO(urllib.urlopen(url_right).read())
        img_right = Image.open(file_right)
        right_height = img_right.height
        if right_height > 400:
            right_height = 400

        options = [('Left', '0'), ('Right', '1')]
        question_content = QuestionContent()
        question_content.append_field(
            'Title',
            'Indicate which one of the following images is better in terms of composition.'
        )
        question_content.append(
            FormattedContent(
                'Left:&nbsp;<img src="' + url_left + '" height="' +
                str(left_height) +
                '" alt="Left picture"></img>Right:&nbsp;<img src="' +
                url_right + '" height="' + str(right_height) +
                '" alt="Right picutre"></img>'))
        answer_selection = SelectionAnswer(min=1,
                                           max=1,
                                           style='radiobutton',
                                           selections=options,
                                           type='text',
                                           other=False)
        question = Question(identifier='photo_pair_' + str(question_num),
                            content=question_content,
                            answer_spec=AnswerSpecification(answer_selection),
                            is_required=True)

        # Glue everything together in a dictionary, keyed by the question_num
        return {
            "question_num":
            question_num,
            "question_" + str(question_num):
            question,
            "answer_key_" + str(question_num):
            self.__generate_answer_form(sentence_data, question_num)
        }
def create_rank_hit(mturk, src_url, URLs, num_assignment, qualification):
    # Constant data for HIT generation
    hit_title = "Photo Quality Ranking"
    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.04
    #approval_delay = 86400

    # Question form for the HIT
    question_form = QuestionForm()

    overview = Overview()
    overview.append_field('Title', 'Photo Quality Ranking')
    overview.append(FormattedContent('Source Image: <img src="'+src_url+'" alt="Image not shown correctly!"></img>'))
    overview.append(FormattedContent('Each of the following questions shows a pair of crops from the source image shown in the above.'))
    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('Note that it is possible that both of the cropped images do not possess a good composition. Please just select the more preferable one 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>'))
        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
Esempio n. 11
0
    def SubmitHIT(self, sandbox = 'false'):
        """
        Constructs a HIT from the HITGenerator's attributes, registers it with Amazon, and returns the HITId as a unicode string.

        If the sandbox flag is set to true then the hit will be registered with the Sandbox, otherwise it is registered to AWS
        directly.  All of the necessary data must have been submitted during the HITGenerator's initiation.
        """

        if sandbox is 'true':
            self.host = 'mechanicalturk.sandbox.amazonaws.com'
        conn = MTurkConnection(host = self.host, aws_access_key_id = self.AWS_KEY, aws_secret_access_key = self.AWS_SECRET)
        answer_specification = AnswerSpecification(SelectionAnswer(style = self.answer_style, selections = self.answer_options))
        overview = Overview()
        overview.append('Title', 'Translate these sentences')
        overview.append('FormattedContent', overview_content) 
        qc = QuestionContent()
        the_text = "Some arabic Words."
        qc.append('FormattedContent', u'<table><tr><td></td><td align="right" width="538">%s</td></tr></table>' % the_text)
       # construct an answer field
        fta = FreeTextAnswer()
        ansp = AnswerSpecification(fta)
        ql = []
        for q in self.question_list:
            ql.append(Question(identifier=q[1],
                               content=q[0],
                               answer_spec=ansp))
        #q = Question(identifier=str(uuid.uuid4()),
        #             content=qc,
        #             answer_spec=ansp)
        # build question form with question list
        qf = QuestionForm(ql, overview=overview)
        self.hit_response = conn.create_hit(question = qf,
                                            lifetime = self.lifetime,
                                            max_assignments = self.assignment_count,
                                            title = self.title,
                                            description = self.description,
                                            keywords = self.keywords,
                                            reward = self.reward,
                                            )
        # Returns the HITId as a unicode string
#        self.HITId = self.hit_response.HITId
#        return self.HITId
        return self.hit_response
Esempio n. 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
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)
Esempio n. 14
0
    def SubmitHIT(self, sandbox = 'false'):
        """
        Constructs a HIT from the HITGenerator's attributes, registers it with Amazon, and returns the HITId as a unicode string.

        If the sandbox flag is set to true then the hit will be registered with the Sandbox, otherwise it is registered to AWS
        directly.  All of the necessary data must have been submitted during the HITGenerator's initiation.
        """

        if sandbox is 'true':
            self.host = 'mechanicalturk.sandbox.amazonaws.com'

        conn = MTurkConnection(host = self.host, aws_access_key_id = self.AWS_KEY, aws_secret_access_key = self.AWS_SECRET)

        answer_specification = AnswerSpecification(SelectionAnswer(style = self.answer_style, selections = self.answer_options))
        
        overview_content = """<p>Your task is to translate the Urdu sentences into English.  Please make sure that your English translation:</p>
<ul>
    <li>Is faithful to the original in both meaning and style</li>
    <li>Is grammatical, fluent, and natural-sounding English</li>
    <li>Does not add or delete information from the original text</li>
    <li>Does not contain any spelling errors</li>
</ul>
<p>When creating your translation, please follow these guidelines:</p>
<ul>
    <li><b>Do not use any machine translation systems (like translation.babylon.com)</b></li>
    <li><b>You may</b> look up a word on <a href="http://www.urduword.com/">an online dictionary</a> if you do not know its translation</li></ul>
<p>Afterwards, we'll ask you a few quick questions about your language abilities.</p>
"""

        overview = Overview()
        overview.append('Title', 'Translate these sentences')
        overview.append('FormattedContent', overview_content) 
        
        qc = QuestionContent()
        the_text = "Some arabic Words."
        qc.append('FormattedContent', u'<table><tr><td></td><td align="right" width="538">%s</td></tr></table>' % the_text)

        
       # construct an answer field
        fta = FreeTextAnswer()
        ansp = AnswerSpecification(fta)
        
        q = Question(identifier=str(uuid.uuid4()),
                     content=qc,
                     answer_spec=ansp)
        
       # put question(s) in a list
        ql = [q,q,q,q] # repeat question four times

       # build question form with question list
        qf = QuestionForm(ql, overview=overview)
        
        self.hit_response = conn.create_hit(question = qf,
                                            lifetime = self.lifetime,
                                            max_assignments = self.assignment_count,
                                            title = self.title,
                                            description = self.description,
                                            keywords = self.keywords,
                                            reward = self.reward,
                                            )
        
        # Returns the HITId as a unicode string
        print self.hit_response
#        self.HITId = self.hit_response.HITId
#        return self.HITId
        return self.hit_response
Esempio n. 15
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
Esempio n. 16
0
    def __generate_qualification_question(self, sentence_data, question_num):
        '''
		Returns a sentence coding qualification test, with answer key
		'''

        # # Coding scale data
        econ_scale = [('', 'NA'), ('Very left', '-2'), ('Somewhat left', '-1'),
                      ('Neither left nor right', '0'), ('Somewhat right', '1'),
                      ('Very right', '2')]

        soc_scale = [('', 'NA'), ('Very liberal', '2'),
                     ('Somewhat liberal', '-1'),
                     ('Neither liberal nor conservative', '0'),
                     ('Somewhat conservative', '1'),
                     ('Very conservative', '2')]

        policy_area = [('Select policy area', '0'),
                       ('Not Economic or Social', '1'), ('Economic', '2'),
                       ('Social', '3')]

        # Generate the question text externally.
        tuid = sentence_data["text_unit_id"]
        q_url = "http://s3.amazonaws.com/aws.drewconway.com/mt/experiments/cmp/html/formatted_sentence.html?text_unit_id="
        q_url_formatted = q_url + str(tuid) + "&amp;question_num=" + str(
            question_num)

        # Create policy area question and answer fields
        content_sentence = QuestionContent()
        content_sentence.append_field("Title", "#" + str(question_num + 1))
        content_sentence.append(
            FormattedContent(
                '<iframe src="' + q_url_formatted +
                '" frameborder="0" width="1280" height="180" scrolling="auto">This text is necessary to ensure proper XML validation</iframe>'
            ))
        ans_policy_area = SelectionAnswer(min=1,
                                          max=1,
                                          style="dropdown",
                                          selections=policy_area)
        qst_policy_area = Question(
            identifier="policy_area_" + str(question_num),
            content=content_sentence,
            answer_spec=AnswerSpecification(ans_policy_area),
            is_required=True)

        # Create 'Economic' policy scale question and answer fields
        content_econ_policy = QuestionContent()
        content_econ_policy.append_field(
            "Text",
            "If you selected 'Not Economic or Social' the task is complete. Either move to the next sentence, or submit your answers."
        )
        content_econ_policy.append_field(
            "Text",
            "If you selected 'Economic', now select economic policy scale below.  Otherwise, do not make a selection."
        )
        ans_econ_scale = SelectionAnswer(min=1,
                                         max=1,
                                         style="dropdown",
                                         selections=econ_scale)
        qst_econ_policy = Question(
            identifier="econ_scale_" + str(question_num),
            content=content_econ_policy,
            answer_spec=AnswerSpecification(ans_econ_scale),
            is_required=True)

        # Create 'Social' policy scale question and answer fields
        content_soc_policy = QuestionContent()
        content_soc_policy.append_field(
            "Text",
            "If you selected 'Social', now select the social policy scale below.  Otherwise, do not make a selection."
        )
        ans_soc_scale = SelectionAnswer(min=1,
                                        max=1,
                                        style="dropdown",
                                        selections=soc_scale)
        qst_soc_policy = Question(
            identifier="soc_scale_" + str(question_num),
            content=content_soc_policy,
            answer_spec=AnswerSpecification(ans_soc_scale),
            is_required=True)

        # Glue everything together in a dictionary, keyed by the question_num
        return {
            "question_num":
            question_num,
            "policy_area_" + str(question_num):
            qst_policy_area,
            "econ_scale_" + str(question_num):
            qst_econ_policy,
            "soc_scale_" + str(question_num):
            qst_soc_policy,
            "answer_key_" + str(question_num):
            self.__generate_answer_form(sentence_data, question_num)
        }
Esempio n. 17
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
def generate_hits(mtc_type, 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, Requirement


    mtc = mtk_utils.get_mtc(mtc_type)

    title = 'Tell us if you like those images or not'
    description = ('View following images and tell us if you like them or not.')
    keywords = 'image, like, interesting, rating, opinions'

    ratings =[('Very hate it','-2'),
             ('Hate it','-1'),
             ('Neutral','0'),
             ('Like it','1'),
             ('Very like it.','2')]

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

    overview = Overview()
    overview.append_field('Title', 'Tell us if you like those images or not.')

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

    questions = []

    subset_with_pinterest = []

    index = 0
    for image_url in subset:

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

        index = index + 1

        if ('repin_count' in image):
            interestingness = int(image['repin_count']) + int(image['like_count'])
            subset_with_pinterest.append(image_url)
        else:
            continue
            # interestingness = int(image['interestingness'])


        qc = QuestionContent()

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

        qc.append_field('Title', str(interestingness) + ' people said they like following image, would you like it too?')
        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)
     

    if (len(questions) == 0):
        return

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

    if (args.m == 'qua_init' and begin_index > 0):
        return
 
    #--------------- 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 * 4,
                   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)
Esempio n. 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)
Esempio n. 20
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
	def __generate_qualification_question(self, sentence_data, question_num):
		'''
		Returns a sentence coding qualification test, with answer key
		'''

		# # Coding scale data
		econ_scale = [('', 'NA'),
					  ('Very left','-2'),
					  ('Somewhat left','-1'),
					  ('Neither left nor right','0'),
					  ('Somewhat right','1'),
					  ('Very right','2')]

		soc_scale = [('', 'NA'),
					 ('Very liberal','2'), 
					 ('Somewhat liberal','-1'),
					 ('Neither liberal nor conservative','0'), 
					 ('Somewhat conservative','1'), 
					 ('Very conservative','2')]

		policy_area = [('Select policy area', '0'),
					   ('Not Economic or Social','1'),
					   ('Economic','2'),
					   ('Social','3')]	

		# Generate the question text externally.
		tuid = sentence_data["text_unit_id"]
		q_url = "http://s3.amazonaws.com/aws.drewconway.com/mt/experiments/cmp/html/formatted_sentence.html?text_unit_id="
		q_url_formatted = q_url + tuid + "&amp;question_num=" + str(question_num)

		# Create policy area question and answer fields
		content_sentence = QuestionContent()
		content_sentence.append_field("Title", "#" + str(question_num+1))
		content_sentence.append(FormattedContent('<iframe src="'+q_url_formatted+'" frameborder="0" width="1280" height="180" scrolling="auto">This text is necessary to ensure proper XML validation</iframe>'))
		ans_policy_area = SelectionAnswer(min=1, max=1, style="dropdown", selections=policy_area)
		qst_policy_area = Question(identifier = "policy_area_"+str(question_num),
								  content=content_sentence,
								  answer_spec=AnswerSpecification(ans_policy_area),
								  is_required=True)

		# Create 'Economic' policy scale question and answer fields
		content_econ_policy = QuestionContent()
		content_econ_policy.append_field("Text", "If you selected 'Not Economic or Social' the task is complete. Either move to the next sentence, or submit your answers.")
		content_econ_policy.append_field("Text", "If you selected 'Economic', now select economic policy scale below.  Otherwise, do not make a selection.")
		ans_econ_scale = SelectionAnswer(min=1, max=1, style="dropdown", selections=econ_scale)
		qst_econ_policy = Question(identifier = "econ_scale_"+str(question_num),
								   content = content_econ_policy,
								   answer_spec = AnswerSpecification(ans_econ_scale),
								   is_required=True)

		# Create 'Social' policy scale question and answer fields
		content_soc_policy = QuestionContent()
		content_soc_policy.append_field("Text", "If you selected 'Social', now select the social policy scale below.  Otherwise, do not make a selection.")
		ans_soc_scale = SelectionAnswer(min=1, max=1, style="dropdown", selections=soc_scale)
		qst_soc_policy = Question(identifier = "soc_scale_"+str(question_num),
								  content = content_soc_policy,
								  answer_spec = AnswerSpecification(ans_soc_scale),
								  is_required=True)

		# Glue everything together in a dictionary, keyed by the question_num
		return {"question_num" : question_num,
				"policy_area_"+str(question_num) : qst_policy_area, 
				"econ_scale_"+str(question_num) : qst_econ_policy, 
				"soc_scale_"+str(question_num) : qst_soc_policy,
				"answer_key_"+str(question_num) : self.__generate_answer_form(sentence_data, question_num)}
Esempio n. 22
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)
Esempio n. 23
0
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.01  # $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> Just testing an API hit. Any answer will win an award."))

    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]
 
 overview.append(FormattedContent(html_code))
  
 #---------------  BUILD QUESTION 1 -------------------
  
 qc1 = QuestionContent()
 qc1.append_field('Title','Select better description')
 
 html_code = ""
 html_code += '<b>Instructions:</b> Select the better description of the auction item'
 html_code += '<ul>'
 html_code += '<li>Read the descriptions of option A and B and take a look at the item(s) on the images (at the beginning of the HIT)</li>'
 html_code += '<li>Select the option (A or B) which provides a clear and accurate description of the auction item(s)</li>'
 html_code += '</ul>'
 
 qc1.append(FormattedContent(html_code))
 
 ratings = [('Option A', options[rnd[0]][0]),('Option B', options[rnd[1]][0])]
  
 fta1 = SelectionAnswer(min=1, max=1,style='radiobutton',
                       selections=ratings,
                       type='text',
                       other=False)
  
 q1 = Question(identifier='evaluation',
               content=qc1,
               answer_spec=AnswerSpecification(fta1),
               is_required=True)
               
 #---------------  BUILD QUESTION 2 -------------------
  
Esempio n. 25
0
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]