2017-10-11 1 views
0

機械翻訳でboto3を使用して質問をプログラムで作成しようとしていますが、create_hitに必要なデータ構造ExternalQuestionが欠落していると思われます。投稿する機械的なTurk ExternalQuestions with boto3

私はそうのようなHITを作成しよう:

import boto3 

#... 

client = boto3.client(
    'mturk', 
    endpoint_url=endpoint_url, 
    region_name=region_name, 
    aws_access_key_id=aws_access_key_id, 
    aws_secret_access_key=aws_secret_access_key, 
) 

question = ExternalQuestion(external_url=question_target, frame_height=800) 

response = client.create_hit(
     MaxAssignments=10, 
     Title='Test', 
     Description='This is a test of ExternalQuestion', 
     Question=question, 
     AssignmentDurationInSeconds=60, 
     LifetimeInSeconds=24 * 60 * 60, 
     Reward=0.01) 

失敗する:

Traceback (most recent call last): 
    File "createTask.py", line 21, in <module> 
    question = ExternalQuestion(external_url=question_target, frame_height=800) 
NameError: name 'ExternalQuestion' is not defined 

続行する方法上の任意のアドバイスが高く評価されています。

+0

ExternalQuestionは、データ構造、ではない機能です。 XMLファイルで作成し、Pythonで 'open()'コマンドを使用し、 'file.read()'をQuestionパラメータに渡します。 – Mangohero1

+0

サンプルコード[here](http://docs.aws .amazon.com/AWSMechTurk/latest/AWSMturkAPI/ApiReference_ExternalQuestionArticle.html) – Mangohero1

答えて

0

これは私のプロダクションコードからの直接の切り取りです。私は、あなたがリクエスタサイトからテンプレートを取得して、自分のjavascriptとhtmlを含むようにすることができるXMLファイルを開きます。私は下のサンプルを添付します。

パイソン

import boto3 
region_name = 'us-east-1' 
aws_access_key_id = '*********************' 
aws_secret_access_key = '*********************' 
endpoint_url = 'https://mturk-requester-sandbox.us-east-1.amazonaws.com' 

# Uncomment this line to use in production 
#endpoint_url = 'https://mturk-requester.us-east-1.amazonaws.com' 
client = boto3.client(
    'mturk', 
    endpoint_url=endpoint_url, 
    region_name=region_name, 
    aws_access_key_id=aws_access_key_id, 
    aws_secret_access_key=aws_secret_access_key, 
) 
questionSampleFile = open("K:/" + str(somefile) + ".xml", "r") 
questionSample = questionSampleFile.read() 

localRequirements = [{ 
    'QualificationTypeId': '00000000000000000071', 
    'Comparator': 'NotIn', 
    'LocaleValues': [{ 
    'Country': 'WF' 
    }], 
    'RequiredToPreview': True 
    }] 
xReward = '0.25' 
# Create the HIT 
response = client.create_hit(
    MaxAssignments = 1, 
    #AutoApprovalDelayInSeconds = 259200, 
    #3 days for lifetime 
    LifetimeInSeconds = 172800, 
    #1 hour to finish the assignment 
    AssignmentDurationInSeconds = 5400, 
    Reward = xReward, 
    Title = 'Enter Missing Data', 
    Keywords = 'data entry, typing, inspection', 
    Description = 'Edit and Add Data from PDF', 
    Question = questionSample, 
    QualificationRequirements = localRequirements 
) 

XML

<HTMLQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2011-11-11/HTMLQuestion.xsd"> 
    <HTMLContent><![CDATA[ 

]]> 
    </HTMLContent> 
    <FrameHeight>900</FrameHeight> 
</HTMLQuestion> 
関連する問題