2014-07-09 61 views
0

我正嘗試在boto中使用boto在Amazon Mechanical Turk中創建一些自動HIT,並且有興趣爲問題添加一個AnswerFormatRegex限制。如何將這個約束添加到問題中?下面是我編寫問題的一個片段。使用BOTO爲Mechanical Turk項目添加AnswerFormatRegex約束

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

### JUMPING TO RELEVANT CODE ### 

qc1 = QuestionContent() 
qc1.append_field('Title','Question 1') 

fta1 = FreeTextAnswer(num_lines=1) 

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

回答

0

不好意思回答我自己的問題,但我終於能夠圍住它了。以下是我用過的似乎有效的工作:

qc1 = QuestionContent() 
qc1.append_field('Title','DATE:') 

constraints1 = [RegExConstraint("***REGEX HERE****", 
           error_text="ERROR.", 
           flags='i')] 

fta1 = FreeTextAnswer(constraints=constraints, default="", num_lines=1) 

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