Java 类com.amazonaws.mturk.service.axis.RequesterService 实例源码

项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testSearchHITsResponseGroups() throws ServiceException {
  getTestHITId(); // make sure there is at least one HIT

  SearchHITsResult result = service.searchHITs(RequesterService.DEFAULT_SORT_DIRECTION,
      SearchHITsSortProperty.CreationTime, defaultPageNum, defaultPageSize,
      new String [] {"Minimal", "HITQuestion"});

  assertNotNull(result);
  assertNotNull(result.getHIT(0));
  HIT hit = result.getHIT(0);
  assertNotNull(hit.getQuestion());

  result = service.searchHITs(RequesterService.DEFAULT_SORT_DIRECTION,
      SearchHITsSortProperty.CreationTime, defaultPageNum, defaultPageSize,
      new String [] {"Minimal"});

  assertNotNull(result);
  assertNotNull(result.getHIT(0));
  hit = result.getHIT(0);
  assertNull(hit.getQuestion());
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public void testUpdateHITTextAttributes() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), 
      defaultMaxAssignments, true);

  String newHITTypeId = service.updateHIT(hit.getHITId(), 
                    hit.getTitle() + " amended", 
      hit.getDescription() + " amended",
      "new, updated, improved, amended", null);

  HIT newHIT = service.getHIT(hit.getHITId());

  assertFalse(newHITTypeId.equals(hit.getHITTypeId()));
  assertEquals(newHITTypeId, newHIT.getHITTypeId());
  assertEquals(hit.getHITId(), newHIT.getHITId());
   assertTrue(newHIT.getTitle().endsWith(" amended"));
  assertTrue(newHIT.getDescription().endsWith(" amended"));
  assertTrue(newHIT.getKeywords().endsWith(" amended"));
  assertEquals(hit.getReward(), newHIT.getReward());
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public void testUpdateHITReward() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), 
      defaultMaxAssignments, true);

  String newHITTypeId = service.updateHIT(hit.getHITId(), 
      null, null, null, 0.50);

  HIT newHIT = service.getHIT(hit.getHITId());

  assertFalse(newHITTypeId.equals(hit.getHITTypeId()));
  assertEquals(newHITTypeId, newHIT.getHITTypeId());
  assertEquals(hit.getHITId(), newHIT.getHITId());
  assertEquals(hit.getTitle(), newHIT.getTitle());
  assertEquals(hit.getDescription(), newHIT.getDescription());
  assertEquals(hit.getKeywords(), newHIT.getKeywords());
  assertEquals(0.50, newHIT.getReward().getAmount().doubleValue());
}
项目:java-aws-mturk    文件:TestRequesterService.java   
@SuppressWarnings("unchecked")
public void testParseAnswers() throws ServiceException {
  QuestionFormAnswers qfa = RequesterService.parseAnswers(DEFAULT_ANSWER_XML);
  List<QuestionFormAnswersType.AnswerType> answers = 
    (List<QuestionFormAnswersType.AnswerType>) qfa.getAnswer();

  for (int i=0; i< answers.size(); i++) {
    QuestionFormAnswersType.AnswerType answer = answers.get(i);
    assertNotNull(null, RequesterService.getAnswerValue(null, answer));

    // check order
    String result = RequesterService.getAnswerValue("TEST_ASSIGNMENT_ID", answer, true);
    if (i == 0) {
      assertTrue(result.equals("freeText\tfreeText_answer"));
    } else if (i == 1) {
      assertTrue(result.equals("otherSelection\totherSelection_answer"));
    } else if (i == 2) {
      assertTrue(result.startsWith("url\t"));
    } else {
      assertTrue(result.equals("selectionIdentifier\tselection_answer|selection_answer2"));
    }
  }
}
项目:java-aws-mturk    文件:TestBase.java   
protected HIT createHIT(QualificationRequirement qualRequirement) throws ServiceException {
  QualificationRequirement[] qualRequirements = null;
  if (qualRequirement != null) { 
    qualRequirements = new QualificationRequirement[] { qualRequirement };
  }

  HIT hit = service.createHIT(null, // HITTypeId 
      defaultHITTitle + unique, 
      defaultHITDescription, null, // keywords 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultReward, 
      defaultAssignmentDurationInSeconds, defaultAutoApprovalDelayInSeconds, 
      defaultLifetimeInSeconds, defaultMaxAssignments, null, // requesterAnnotation 
      qualRequirements,
      null  // responseGroup
    );

  assertNotNull(hit);
  assertNotNull(hit.getHITId());

  return hit;
}
项目:java-aws-mturk    文件:MTurkHelloWorld.java   
/**
 * Creates the simple HIT.
 * 
 */
public void createHelloWorld() {
  try {

    // The createHIT method is called using a convenience static method of
    // RequesterService.getBasicFreeTextQuestion that generates the QAP for
    // the HIT.
    HIT hit = service.createHIT(
            title,
            description,
            reward,
            RequesterService.getBasicFreeTextQuestion(
                "What is the weather like right now in Seattle, WA?"),
            numAssignments);

    System.out.println("Created HIT: " + hit.getHITId());

    System.out.println("You may see your HIT with HITTypeId '" 
        + hit.getHITTypeId() + "' here: ");
    System.out.println(service.getWebsiteURL() 
        + "/mturk/preview?groupId=" + hit.getHITTypeId());

  } catch (ServiceException e) {
    System.err.println(e.getLocalizedMessage());
  }
}
项目:java-aws-mturk    文件:MyHIT.java   
public void createMyHIT() {
    try {

        // The createHIT method is called using a convenience static method of
        // RequesterService.getBasicFreeTextQuestion that generates the QAP for
        // the HIT.
        HIT hit = service.createHIT(
                title,
                description,
                reward,
                RequesterService.getBasicFreeTextQuestion(
                    "What is the current temperature now in Seattle, WA?"),
                numAssignments);

        System.out.println("Created HIT: " + hit.getHITId());

        System.out.println("You may see your HIT with HITTypeId '" 
            + hit.getHITTypeId() + "' here: ");
        System.out.println(service.getWebsiteURL() 
            + "/mturk/preview?groupId=" + hit.getHITTypeId());

      } catch (ServiceException e) {
        System.err.println(e.getLocalizedMessage());
      }
}
项目:lense    文件:MTurkSystem.java   
/**
 * Instantiating an MTurkSystem should be enough to handle your human worker issues. It handles the rest, as in
 * booting up the jetty server, the API server, and a payments thread to go through and make payments to workers.
 */
public MTurkSystem() {
    humanSourceServer = new HumanSourceServer();
    new Thread(humanSourceServer).start();

    jettyServer = new JettyServer();
    new Thread(jettyServer).start();

    paymentsThread = new PaymentsThread(((jobRecord, amountOwed) -> payWorker(jobRecord.workerID, jobRecord.assignmentID, amountOwed)));
    new Thread(paymentsThread).start();

    try {
        mturkService = new RequesterService(new PropertiesClientConfig("/home/keenon/.aws/mturk.properties"));
    }
    catch (Exception e) {

    }

    mTurkServer = new MTurkServer(this::hireWorkers, this::numWorkersPaidFor);
    new Thread(mTurkServer).start();
}
项目:mturksdk-java-code-maven    文件:TestRequesterServiceRaw.java   
public void testSearchHITsResponseGroups() throws ServiceException {
  getTestHITId(); // make sure there is at least one HIT

  SearchHITsResult result = service.searchHITs(RequesterService.DEFAULT_SORT_DIRECTION,
      SearchHITsSortProperty.CreationTime, defaultPageNum, defaultPageSize,
      new String [] {"Minimal", "HITQuestion"});

  assertNotNull(result);
  assertNotNull(result.getHIT(0));
  HIT hit = result.getHIT(0);
  assertNotNull(hit.getQuestion());

  result = service.searchHITs(RequesterService.DEFAULT_SORT_DIRECTION,
      SearchHITsSortProperty.CreationTime, defaultPageNum, defaultPageSize,
      new String [] {"Minimal"});

  assertNotNull(result);
  assertNotNull(result.getHIT(0));
  hit = result.getHIT(0);
  assertNull(hit.getQuestion());
}
项目:mturksdk-java-code-maven    文件:TestRequesterService.java   
public void testUpdateHITTextAttributes() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), 
      defaultMaxAssignments, true);

  String newHITTypeId = service.updateHIT(hit.getHITId(), 
                    hit.getTitle() + " amended", 
      hit.getDescription() + " amended",
      "new, updated, improved, amended", null);

  HIT newHIT = service.getHIT(hit.getHITId());

  assertFalse(newHITTypeId.equals(hit.getHITTypeId()));
  assertEquals(newHITTypeId, newHIT.getHITTypeId());
  assertEquals(hit.getHITId(), newHIT.getHITId());
   assertTrue(newHIT.getTitle().endsWith(" amended"));
  assertTrue(newHIT.getDescription().endsWith(" amended"));
  assertTrue(newHIT.getKeywords().endsWith(" amended"));
  assertEquals(hit.getReward(), newHIT.getReward());
}
项目:mturksdk-java-code-maven    文件:TestRequesterService.java   
public void testUpdateHITReward() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), 
      defaultMaxAssignments, true);

  String newHITTypeId = service.updateHIT(hit.getHITId(), 
      null, null, null, 0.50);

  HIT newHIT = service.getHIT(hit.getHITId());

  assertFalse(newHITTypeId.equals(hit.getHITTypeId()));
  assertEquals(newHITTypeId, newHIT.getHITTypeId());
  assertEquals(hit.getHITId(), newHIT.getHITId());
  assertEquals(hit.getTitle(), newHIT.getTitle());
  assertEquals(hit.getDescription(), newHIT.getDescription());
  assertEquals(hit.getKeywords(), newHIT.getKeywords());
  assertEquals(0.50, newHIT.getReward().getAmount().doubleValue());
}
项目:mturksdk-java-code-maven    文件:TestRequesterService.java   
@SuppressWarnings("unchecked")
public void testParseAnswers() throws ServiceException {
  QuestionFormAnswers qfa = RequesterService.parseAnswers(DEFAULT_ANSWER_XML);
  List<QuestionFormAnswersType.AnswerType> answers = 
    (List<QuestionFormAnswersType.AnswerType>) qfa.getAnswer();

  for (int i=0; i< answers.size(); i++) {
    QuestionFormAnswersType.AnswerType answer = answers.get(i);
    assertNotNull(null, RequesterService.getAnswerValue(null, answer));

    // check order
    String result = RequesterService.getAnswerValue("TEST_ASSIGNMENT_ID", answer, true);
    if (i == 0) {
      assertTrue(result.equals("freeText\tfreeText_answer"));
    } else if (i == 1) {
      assertTrue(result.equals("otherSelection\totherSelection_answer"));
    } else if (i == 2) {
      assertTrue(result.startsWith("url\t"));
    } else {
      assertTrue(result.equals("selectionIdentifier\tselection_answer|selection_answer2"));
    }
  }
}
项目:mturksdk-java-code-maven    文件:TestBase.java   
protected HIT createHIT(QualificationRequirement qualRequirement) throws ServiceException {
  QualificationRequirement[] qualRequirements = null;
  if (qualRequirement != null) { 
    qualRequirements = new QualificationRequirement[] { qualRequirement };
  }

  HIT hit = service.createHIT(null, // HITTypeId 
      defaultHITTitle + unique, 
      defaultHITDescription, null, // keywords 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultReward, 
      defaultAssignmentDurationInSeconds, defaultAutoApprovalDelayInSeconds, 
      defaultLifetimeInSeconds, defaultMaxAssignments, null, // requesterAnnotation 
      qualRequirements,
      null  // responseGroup
    );

  assertNotNull(hit);
  assertNotNull(hit.getHITId());

  return hit;
}
项目:mturksdk-java-code-maven    文件:MTurkHelloWorld.java   
/**
 * Creates the simple HIT.
 * 
 */
public void createHelloWorld() {
  try {

    // The createHIT method is called using a convenience static method of
    // RequesterService.getBasicFreeTextQuestion that generates the QAP for
    // the HIT.
    HIT hit = service.createHIT(
            title,
            description,
            reward,
            RequesterService.getBasicFreeTextQuestion(
                "What is the weather like right now in Seattle, WA?"),
            numAssignments);

    System.out.println("Created HIT: " + hit.getHITId());

    System.out.println("You may see your HIT with HITTypeId '" 
        + hit.getHITTypeId() + "' here: ");
    System.out.println(service.getWebsiteURL() 
        + "/mturk/preview?groupId=" + hit.getHITTypeId());

  } catch (ServiceException e) {
    System.err.println(e.getLocalizedMessage());
  }
}
项目:mturksdk-java-code-maven    文件:MyHIT.java   
public void createMyHIT() {
    try {

        // The createHIT method is called using a convenience static method of
        // RequesterService.getBasicFreeTextQuestion that generates the QAP for
        // the HIT.
        HIT hit = service.createHIT(
                title,
                description,
                reward,
                RequesterService.getBasicFreeTextQuestion(
                    "What is the current temperature now in Seattle, WA?"),
                numAssignments);

        System.out.println("Created HIT: " + hit.getHITId());

        System.out.println("You may see your HIT with HITTypeId '" 
            + hit.getHITTypeId() + "' here: ");
        System.out.println(service.getWebsiteURL() 
            + "/mturk/preview?groupId=" + hit.getHITTypeId());

      } catch (ServiceException e) {
        System.err.println(e.getLocalizedMessage());
      }
}
项目:gort-public    文件:MovieSurvey.java   
/**
 * Create a simple survey.
 *
 */
public void createMovieSurvey()
 {
     try {
         // The createHIT method is called using a convenience static method
         // RequesterService.getBasicFreeTextQuestion() that generates the question format
         // for the HIT.
         HIT hit = service.createHIT
         (
             title,
             description,
             reward,
             RequesterService.getBasicFreeTextQuestion(
             "How many movies have you seen this month?"),
             numAssignments);
             // Print out the HITId and the URL to view the HIT.
             System.out.println("Created HIT: " + hit.getHITId());
             System.out.println("HIT location: ");
             System.out.println(service.getWebsiteURL() + "/mturk/preview?groupId="
             + hit.getHITTypeId());
     } catch (ServiceException e) {
         System.err.println(e.getLocalizedMessage());
     }
 }
项目:gort-public    文件:MTurkHelloWorld.java   
/**
 * Creates the simple HIT.
 * 
 */
public void createHelloWorld() {
  try {

    // The createHIT method is called using a convenience static method of
    // RequesterService.getBasicFreeTextQuestion that generates the QAP for
    // the HIT.
    HIT hit = service.createHIT(
            title,
            description,
            reward,
            RequesterService.getBasicFreeTextQuestion(
                "What is the weather like right now in Seattle, WA?"),
            numAssignments);

    System.out.println("Created HIT: " + hit.getHITId());

    System.out.println("You may see your HIT with HITTypeId '" 
        + hit.getHITTypeId() + "' here: ");
    System.out.println(service.getWebsiteURL() 
        + "/mturk/preview?groupId=" + hit.getHITTypeId());

  } catch (ServiceException e) {
    System.err.println(e.getLocalizedMessage());
  }
}
项目:gort-public    文件:MyHIT.java   
public void createMyHIT() {
    try {

        // The createHIT method is called using a convenience static method of
        // RequesterService.getBasicFreeTextQuestion that generates the QAP for
        // the HIT.
        HIT hit = service.createHIT(
                title,
                description,
                reward,
                RequesterService.getBasicFreeTextQuestion(
                    "What is the current temperature now in Seattle, WA?"),
                numAssignments);

        System.out.println("Created HIT: " + hit.getHITId());

        System.out.println("You may see your HIT with HITTypeId '" 
            + hit.getHITTypeId() + "' here: ");
        System.out.println(service.getWebsiteURL() 
            + "/mturk/preview?groupId=" + hit.getHITTypeId());

      } catch (ServiceException e) {
        System.err.println(e.getLocalizedMessage());
      }
}
项目:java-aws-mturk    文件:HITResults.java   
@SuppressWarnings("unchecked")
private String getAnswers(Assignment assignment) {
  String result = EMPTY;

  AssignmentStatus status = assignment.getAssignmentStatus(); 
  if (status == null) {
    return NO_ANSWER;
  }

  String answerXML = assignment.getAnswer();

  QuestionFormAnswers qfa = RequesterService.parseAnswers(answerXML);
  List<QuestionFormAnswersType.AnswerType> answers = 
    (List<QuestionFormAnswersType.AnswerType>) qfa.getAnswer();

  for (QuestionFormAnswersType.AnswerType answer : answers) {

    String assignmentId = assignment.getAssignmentId();
    String answerValue = RequesterService.getAnswerValue(assignmentId, answer, true);

    if (answerValue != null) {
      result += answerValue + DELIMITER;
    }
  }

  return result;
}
项目:java-aws-mturk    文件:TestFilter.java   
public void testChangeReward() throws ServiceException {
    Filter filter = new CheckRewardFilter();
    service.addFilter(filter);
    String hitId = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
        RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultMaxAssignments).getHITId();

    HIT hit = service.getHIT(hitId);  
    assertEquals(hit.getReward().getAmount().doubleValue(), 0.05);
    service.removeFilter(filter);
}
项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testCreateHITIdempotency() throws ServiceException {
  try {
    String uniqueRequestToken = "testCreateHITIdempotency" + unique;
    for (int i = 0; i < 2; i++) {
      service.createHIT(
          null, // hitTypeId
          defaultHITTitle + unique,
          defaultHITDescription,
          null, // keywords
          RequesterService.getBasicFreeTextQuestion(defaultQuestion),
          defaultReward,
          defaultAssignmentDurationInSeconds,
          defaultAutoApprovalDelayInSeconds,
          defaultLifetimeInSeconds,
          defaultMaxAssignments,
          null, // requesterAnnotation
          null, // qualificationRequirements
          null, // responseGroup
          uniqueRequestToken,
          null, // assignmentReviewPolicy
          null); // hitReviewPolicy
    }
    fail("Re-use of uniqueRequestToken did not cause an error");
  } catch (ServiceException e) {
    // expected
    assertTrue("createHIT failed, but not because of uniqueRequestToken re-use",
        e.getMessage().contains("AWS.MechanicalTurk.HITAlreadyExists"));
  }
}
项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testCreateHITWithInvalidReviewPolicy() throws ServiceException {
  // create a SKA policy that is missing required parameter AnswerKey 
  ReviewPolicy assignmentReviewPolicy = new ReviewPolicy("ScoreMyKnownAnswers/2011-09-01",
      new PolicyParameter[] {});

  try {
    service.createHIT(
        null, // hitTypeId
        defaultHITTitle + unique,
        defaultHITDescription,
        null, // keywords
        RequesterService.getBasicFreeTextQuestion(defaultQuestion),
        defaultReward,
        defaultAssignmentDurationInSeconds,
        defaultAutoApprovalDelayInSeconds,
        defaultLifetimeInSeconds,
        defaultMaxAssignments,
        null, // requesterAnnotation
        null, // qualificationRequirements
        null, // responseGroup
        null, // uniqueRequestToken
        assignmentReviewPolicy,
        null); // hitReviewPolicy
    fail("createHIT succeeded, despite having an invalid review policy");
  } catch (ServiceException e) {
    // expected
    assertTrue("createHIT failed, but not because of an invalid review policy",
        e.getMessage().contains("The AnswerKey parameter is mandatory."));
  }
}
项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testSearchQualificationTypes()
  throws ServiceException {
  SearchQualificationTypesResult result = service.searchQualificationTypes(
      defaultQuery, false, // mustBeRequestable
      false, // mustBeOwnedByCaller
      RequesterService.DEFAULT_SORT_DIRECTION,
      SearchQualificationTypesSortProperty.Name,
      defaultPageNum, defaultPageSize
    );

  assertNotNull(result);
}
项目:java-aws-mturk    文件:TestRequesterServiceRaw.java   
public void testCreateHITAsync() {
  AsyncReply reply = service.createHITAsync(
      null, // HITTypeId
      "Async_" + defaultHITTitle + unique,
      "Async_" + defaultHITDescription,
      null, // keywords
      RequesterService.getBasicFreeTextQuestion(defaultQuestion),
      defaultReward, defaultAssignmentDurationInSeconds,
      defaultAutoApprovalDelayInSeconds, defaultLifetimeInSeconds,
      defaultMaxAssignments, null, // requesterAnnotation
      null, 
      null, // responseGroup
      null, // uniqueRequestToken
      null, // assignmentReviewPolicy
      null, // hitReviewPolicy
      null  // callback
  );

  assertNotNull(reply);
  assertNotNull(reply.getFuture());
  assertFalse(reply.getFuture().isDone());

  // wait for result
  HIT hit = ((HIT[]) reply.getResult())[0];

  assertNotNull(hit);
  assertNotNull(hit.getHITId());
  assertTrue(reply.getFuture().isDone());
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public static void main(String[] args) {
  QuestionFormAnswers qfa = RequesterService.parseAnswers(DEFAULT_ANSWER_XML);
  List<QuestionFormAnswersType.AnswerType> answers = 
    (List<QuestionFormAnswersType.AnswerType>) qfa.getAnswer();

  TestRunner.run(TestRequesterService.class);
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public void testCreateHITFreeText() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultMaxAssignments);

  assertNotNull(hit);
  assertNotNull(hit.getHITId());
}
项目:java-aws-mturk    文件:TestRequesterService.java   
public void testCreateHITFullResponse() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), 
      defaultMaxAssignments, true);

  assertNotNull(hit);
  assertNotNull(hit.getHITId());
  assertNotNull(hit.getQuestion());
  assertNotNull(hit.getCreationTime());
  assertNotNull(hit.getNumberOfAssignmentsCompleted());
}
项目:mturk-screening-presurvey    文件:FullSurvey.java   
public void createSurvey() {
  try {

    QualificationRequirement[] requirements = null;
    if(haveQualifications) {
      requirements = new QualificationRequirement[4];
      requirements[0] = new QualificationRequirement(RequesterService.LOCALE_QUALIFICATION_TYPE_ID, Comparator.EqualTo, null, new Locale("US"), invisible); //USA! USA!
      requirements[1] = new QualificationRequirement(getQualificationTypeId(), Comparator.EqualTo, 1, null, invisible); //Completed the screener
      requirements[2] = new QualificationRequirement(RequesterService.APPROVAL_RATE_QUALIFICATION_TYPE_ID, Comparator.GreaterThanOrEqualTo, 95, null, invisible); //>=95% approval
      requirements[3] = new QualificationRequirement("00000000000000000040", Comparator.GreaterThanOrEqualTo, 1000, null, invisible); //>=1000 HITs
    }

    String[] responseGroup = new String[]{"Minimal"};

    HITQuestion question = new HITQuestion("fullsurveyquestion.xml");

    SurveyParameters p = parameters;

    String hitType = service.registerHITType(p.autoApprovalDelay, p.assignmentDuration, p.reward, p.title, p.keywords, p.description, requirements);

    HIT hit = service.createHIT(hitType, p.title, p.description, p.keywords, question.getQuestion(), p.reward, p.assignmentDuration, p.autoApprovalDelay, p.lifetime, p.numAssignments, p.annotation, requirements, responseGroup);

    System.out.println("Created HIT: " + hit.getHITId());

    System.out.println("You may see your HIT with HITTypeId '" 
        + hit.getHITTypeId() + "' here: ");
    System.out.println(service.getWebsiteURL() 
        + "/mturk/preview?groupId=" + hit.getHITTypeId());

    PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("hitid.txt", append))); //Should hopefully append the hit id.
    writer.println(hit.getHITId() + " " + service.getWebsiteURL() + "/mturk/preview?groupId=" + hit.getHITTypeId());
    writer.close();

  } catch (Exception e) {
    System.err.println(e.getLocalizedMessage());
  }
}
项目:mturk-screening-presurvey    文件:ScreenerQuestion.java   
public void createScreener() {
  try {

    QualificationRequirement[] requirements = null;
    if(haveQualifications) {
      requirements = new QualificationRequirement[3];
      requirements[0] = new QualificationRequirement(RequesterService.APPROVAL_RATE_QUALIFICATION_TYPE_ID, Comparator.GreaterThanOrEqualTo, 95, null, invisible); //>=95% approval
      requirements[1] = new QualificationRequirement("00000000000000000040", Comparator.GreaterThanOrEqualTo, 1000, null, invisible); //>=1000 HITs
      requirements[2] = new QualificationRequirement(RequesterService.LOCALE_QUALIFICATION_TYPE_ID, Comparator.EqualTo, null, new Locale("US"), invisible); //USA! USA!
    }

    String[] responseGroup = new String[]{"Minimal"};

    HITQuestion question = new HITQuestion("screenerquestion.xml");

    String hitType = service.registerHITType(autoApprovalDelay, assignmentDuration, reward, title, keywords, description, requirements);

    HIT hit = service.createHIT(hitType, title, description, keywords, question.getQuestion(), reward, assignmentDuration, autoApprovalDelay, lifetime, numAssignments, annotation, requirements, responseGroup);

    System.out.println("Created HIT: " + hit.getHITId());

    System.out.println("You may see your HIT with HITTypeId '" 
        + hit.getHITTypeId() + "' here: ");
    System.out.println(service.getWebsiteURL() + "/mturk/preview?groupId=" + hit.getHITTypeId());

    PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("hitid.txt", append))); //Should hopefully append the hit id.
    writer.println(hit.getHITId() + " " + service.getWebsiteURL() + "/mturk/preview?groupId=" + hit.getHITTypeId());
    writer.close();

  } catch (Exception e) {
    System.err.println(e.getLocalizedMessage());
  }
}
项目:mturksdk-java-code-maven    文件:HITResults.java   
@SuppressWarnings("unchecked")
private String getAnswers(Assignment assignment) {
  String result = EMPTY;

  AssignmentStatus status = assignment.getAssignmentStatus(); 
  if (status == null) {
    return NO_ANSWER;
  }

  String answerXML = assignment.getAnswer();

  QuestionFormAnswers qfa = RequesterService.parseAnswers(answerXML);
  List<QuestionFormAnswersType.AnswerType> answers = 
    (List<QuestionFormAnswersType.AnswerType>) qfa.getAnswer();

  for (QuestionFormAnswersType.AnswerType answer : answers) {

    String assignmentId = assignment.getAssignmentId();
    String answerValue = RequesterService.getAnswerValue(assignmentId, answer, true);

    if (answerValue != null) {
      result += answerValue + DELIMITER;
    }
  }

  return result;
}
项目:mturksdk-java-code-maven    文件:TestFilter.java   
public void testChangeReward() throws ServiceException {
    Filter filter = new CheckRewardFilter();
    service.addFilter(filter);
    String hitId = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
        RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultMaxAssignments).getHITId();

    HIT hit = service.getHIT(hitId);  
    assertEquals(hit.getReward().getAmount().doubleValue(), 0.05);
    service.removeFilter(filter);
}
项目:mturksdk-java-code-maven    文件:TestRequesterServiceRaw.java   
public void testCreateHITIdempotency() throws ServiceException {
  try {
    String uniqueRequestToken = "testCreateHITIdempotency" + unique;
    for (int i = 0; i < 2; i++) {
      service.createHIT(
          null, // hitTypeId
          defaultHITTitle + unique,
          defaultHITDescription,
          null, // keywords
          RequesterService.getBasicFreeTextQuestion(defaultQuestion),
          defaultReward,
          defaultAssignmentDurationInSeconds,
          defaultAutoApprovalDelayInSeconds,
          defaultLifetimeInSeconds,
          defaultMaxAssignments,
          null, // requesterAnnotation
          null, // qualificationRequirements
          null, // responseGroup
          uniqueRequestToken,
          null, // assignmentReviewPolicy
          null); // hitReviewPolicy
    }
    fail("Re-use of uniqueRequestToken did not cause an error");
  } catch (ServiceException e) {
    // expected
    assertTrue("createHIT failed, but not because of uniqueRequestToken re-use",
        e.getMessage().contains("AWS.MechanicalTurk.HITAlreadyExists"));
  }
}
项目:mturksdk-java-code-maven    文件:TestRequesterServiceRaw.java   
public void testCreateHITWithInvalidReviewPolicy() throws ServiceException {
  // create a SKA policy that is missing required parameter AnswerKey 
  ReviewPolicy assignmentReviewPolicy = new ReviewPolicy("ScoreMyKnownAnswers/2011-09-01",
      new PolicyParameter[] {});

  try {
    service.createHIT(
        null, // hitTypeId
        defaultHITTitle + unique,
        defaultHITDescription,
        null, // keywords
        RequesterService.getBasicFreeTextQuestion(defaultQuestion),
        defaultReward,
        defaultAssignmentDurationInSeconds,
        defaultAutoApprovalDelayInSeconds,
        defaultLifetimeInSeconds,
        defaultMaxAssignments,
        null, // requesterAnnotation
        null, // qualificationRequirements
        null, // responseGroup
        null, // uniqueRequestToken
        assignmentReviewPolicy,
        null); // hitReviewPolicy
    fail("createHIT succeeded, despite having an invalid review policy");
  } catch (ServiceException e) {
    // expected
    assertTrue("createHIT failed, but not because of an invalid review policy",
        e.getMessage().contains("The AnswerKey parameter is mandatory."));
  }
}
项目:mturksdk-java-code-maven    文件:TestRequesterServiceRaw.java   
public void testSearchQualificationTypes()
  throws ServiceException {
  SearchQualificationTypesResult result = service.searchQualificationTypes(
      defaultQuery, false, // mustBeRequestable
      false, // mustBeOwnedByCaller
      RequesterService.DEFAULT_SORT_DIRECTION,
      SearchQualificationTypesSortProperty.Name,
      defaultPageNum, defaultPageSize
    );

  assertNotNull(result);
}
项目:mturksdk-java-code-maven    文件:TestRequesterServiceRaw.java   
public void testCreateHITAsync() {
  AsyncReply reply = service.createHITAsync(
      null, // HITTypeId
      "Async_" + defaultHITTitle + unique,
      "Async_" + defaultHITDescription,
      null, // keywords
      RequesterService.getBasicFreeTextQuestion(defaultQuestion),
      defaultReward, defaultAssignmentDurationInSeconds,
      defaultAutoApprovalDelayInSeconds, defaultLifetimeInSeconds,
      defaultMaxAssignments, null, // requesterAnnotation
      null, 
      null, // responseGroup
      null, // uniqueRequestToken
      null, // assignmentReviewPolicy
      null, // hitReviewPolicy
      null  // callback
  );

  assertNotNull(reply);
  assertNotNull(reply.getFuture());
  assertFalse(reply.getFuture().isDone());

  // wait for result
  HIT hit = ((HIT[]) reply.getResult())[0];

  assertNotNull(hit);
  assertNotNull(hit.getHITId());
  assertTrue(reply.getFuture().isDone());
}
项目:mturksdk-java-code-maven    文件:TestRequesterService.java   
public static void main(String[] args) {
  QuestionFormAnswers qfa = RequesterService.parseAnswers(DEFAULT_ANSWER_XML);
  List<QuestionFormAnswersType.AnswerType> answers = 
    (List<QuestionFormAnswersType.AnswerType>) qfa.getAnswer();

  TestRunner.run(TestRequesterService.class);
}
项目:mturksdk-java-code-maven    文件:TestRequesterService.java   
public void testCreateHITFreeText() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), defaultMaxAssignments);

  assertNotNull(hit);
  assertNotNull(hit.getHITId());
}
项目:mturksdk-java-code-maven    文件:TestRequesterService.java   
public void testCreateHITFullResponse() throws ServiceException {
  HIT hit = service.createHIT(defaultHITTitle + unique, defaultHITDescription, defaultReward, 
      RequesterService.getBasicFreeTextQuestion(defaultQuestion), 
      defaultMaxAssignments, true);

  assertNotNull(hit);
  assertNotNull(hit.getHITId());
  assertNotNull(hit.getQuestion());
  assertNotNull(hit.getCreationTime());
  assertNotNull(hit.getNumberOfAssignmentsCompleted());
}
项目:gort-public    文件:Utility.java   
public static Assignment[] getSubmittedAssignments(RequesterService service, String hitId) {
    if (service == null) {
        return null;
    }

    if (hitId == null || hitId.isEmpty()) {
        return null;
    }

    Assignment[] assignments = null;

    try {
        assignments = service.getAllAssignmentsForHIT(hitId);
    } catch (Exception e) {
        System.out.println("Could not connect to receive HIT assignments.");
        //e.printStackTrace();
    }

    if (assignments == null || assignments.length <= 0) {
        return null;
    }

    List<Assignment> retVal = new LinkedList<Assignment>();

    //Only assignments that have been submitted will contain answer data
    for (Assignment a : assignments) {
        if (a == null) {
            continue;
        }

        if (a.getAssignmentStatus() == AssignmentStatus.Submitted) {
            retVal.add(a);
        }

    }

    return (retVal.size() > 0) ? retVal.toArray(new Assignment[retVal.size()]) : null;
}
项目:gort-public    文件:BestImage.java   
/**
 * Constructor
 *
 */
public BestImage(String mTurkProperties) {

  //service = new RequesterService(new PropertiesClientConfig("../mturk.properties"));
    Path currentRelativePath = Paths.get("");
    String s = currentRelativePath.toAbsolutePath().toString();
    System.out.println("Current relative path is: " + s);
    System.out.println(mTurkProperties);
    service = new RequesterService(new PropertiesClientConfig(mTurkProperties));
}