/**
   * A Method to create a HIT with the target word and the 2 words on either side along with the
   * sense and part of speech
   *
   * @param Context before the target word
   * @param Target word
   * @param Context after the target word
   * @param Word sense
   * @param Part of speech
   */
  private void createPartialContextGivenSurvey(
      String partialFirst, String target, String partialSecond, String sense, String POS) {
    try {
      HIT hit =
          service.createHIT(
              null,
              partialContextTitle,
              partialContextDescription,
              null,
              partialContextSub(partialFirst, target, partialSecond, sense, POS),
              reward,
              (long) 300,
              (long) 432000,
              (long) 259200,
              numAssignments,
              target,
              requirements,
              null);

      // Print out the HITId and the URL to view the HIT.
      System.out.println("Created HIT: " + hit.getHITId());
      partialContextpr.println(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());
    }
  }
  /**
   * A method to create a HIT with context and the target word provided Takes in the target word and
   * the surrounding context in two pieces
   *
   * @param Context before the target word
   * @param Target word
   * @param Context after the target word
   * @throws FileNotFoundException
   */
  public void createContextGivenSurvey(String firstSentence, String word, String secondSentence)
      throws FileNotFoundException {
    try {
      HIT hit =
          service.createHIT(
              null,
              contextGivenTitle,
              contextGivenDescription,
              null,
              contextGivenSub(firstSentence, word, secondSentence),
              reward,
              (long) 300,
              (long) 432000,
              (long) 345600,
              numAssignments,
              word,
              requirements,
              null);

      // Print out the HITId and the URL to view the HIT.
      System.out.println("Created HIT: " + hit.getHITId());
      contextpr.println(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());
    }
  }
  public String createMyHit(
      RequesterService service,
      ArrayList<Object> inputs,
      int numberOfOutputs,
      int numberOfAssignments) {

    /* Some parameters used for initializing MTurk HIT.*/
    String title = "Select best description";
    String description = "Please selec the best description.";
    String keywords = "selection, description";
    Question question = new Question(inputs, numberOfOutputs);
    double reward = 0.01;
    long assignmentDurationInSeconds = 60 * 30; // 30 minutes
    long autoApprovalDelayInSeconds = 60; // 1 minute
    long lifetimeInSeconds = 60 * 60 * 24 * 7; // 1 week
    HIT hit =
        service.createHIT(
            null,
            title,
            description,
            keywords,
            question.getQuestion(),
            reward,
            assignmentDurationInSeconds,
            autoApprovalDelayInSeconds,
            lifetimeInSeconds,
            numberOfAssignments,
            null,
            null,
            null);
    return hit.getHITId();
  }
Exemple #4
0
  public void createHIT(Product product, int tier) {

    String parentCategoryName = turkDAO.getParentCategoryNameForProduct(product.getId());
    log.info("creating tier " + tier + " hit for productId " + product.getId());

    // String hitTypeId = null;
    String title = "Choose the best category for this " + parentCategoryName + " product";
    String description = "Please look at this product and select a categorization for it.";
    String keywords = "shopping,product,merchandise,categorization,shopzilla";

    double reward = 0.0;

    try {
      if (tier == 1) {
        reward = tierOneReward;
      } else {
        reward = tierTwoReward;
      }

    } catch (Exception ignore) {
    }

    int maxAssignments = 3 - tier;
    long assignmentDurationInSeconds = 60 * 60; // one hour
    long autoApprovalDelayInSeconds = 60 * 60 * 24 * 30; // one month
    long lifetimeInSeconds = 60 * 60 * 24; // one day
    String requesterAnnotation = "ShopZilla two plus one HIT";

    String externalURL = "http://" + hostname + "/cloudsort/hit.do?id=" + product.getId();
    if (tier == 2) {
      externalURL += "&amp;tier=2";
    }

    log.info("creating tier " + tier + " hit, url: " + externalURL);

    String question =
        "<?xml version=\"1.0\"?>"
            + "<ExternalQuestion xmlns=\"http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd\">"
            + "	<ExternalURL>"
            + externalURL
            + "</ExternalURL>"
            + "	<FrameHeight>500</FrameHeight>"
            + "</ExternalQuestion>";

    QualificationRequirement[] qualificationRequirements = null;

    Qualification qualification = null;

    try {
      qualification = turkDAO.getQualificationForCategoryId(product.getParentCategoryId());
    } catch (Exception ignore) {
      log.info("no qualification data found for parent category " + product.getParentCategoryId());
    }

    if (qualification != null) {

      if (tier == 2
              && qualification.getQualTypeIdTrusted() != null
              && qualification.getQualTypeIdTrusted().length() > 0
          || tier == 1
              && qualification.getQualTypeIdGeneral() != null
              && qualification.getQualTypeIdGeneral().length() > 0) {

        qualificationRequirements = new QualificationRequirement[1];
        qualificationRequirements[0] = new QualificationRequirement();
        qualificationRequirements[0].setComparator(Comparator.GreaterThanOrEqualTo);
        if (tier == 1) {
          qualificationRequirements[0].setQualificationTypeId(qualification.getQualTypeIdGeneral());
          qualificationRequirements[0].setIntegerValue(qualification.getQualTypeScoreGeneral());
        } else {
          qualificationRequirements[0].setQualificationTypeId(qualification.getQualTypeIdGeneral());
          qualificationRequirements[0].setIntegerValue(qualification.getQualTypeScoreGeneral());
        }
        qualificationRequirements[0].setRequiredToPreview(false);

        log.info(
            "qualification typeID: "
                + qualificationRequirements[0].getQualificationTypeId()
                + ", score: "
                + qualificationRequirements[0].getIntegerValue());
      }
    }

    String responseGroup[] = null;
    String hitTypeId = null;

    long startTime = System.currentTimeMillis();
    HIT hit =
        service.createHIT(
            hitTypeId,
            title,
            description,
            keywords,
            question,
            reward,
            assignmentDurationInSeconds,
            autoApprovalDelayInSeconds,
            lifetimeInSeconds,
            maxAssignments,
            requesterAnnotation,
            qualificationRequirements,
            responseGroup);

    long elapsed = System.currentTimeMillis() - startTime;
    log.info(
        "hit id "
            + hit.getHITId()
            + ", hitType "
            + hit.getHITTypeId()
            + " created in "
            + elapsed
            + " ms");

    Request request = new Request();
    request.setProductId(product.getId());
    request.setCreatedDate(new Date());
    request.setHitId(hit.getHITId());
    request.setParentCategoryId(product.getParentCategoryId());
    request.setTier(tier);
    startTime = System.currentTimeMillis();
    turkDAO.saveRequest(request);
    elapsed = System.currentTimeMillis() - startTime;
    log.info("request saved in " + elapsed + " ms");

    if (hitTypes.contains(hit.getHITTypeId())) {
      log.info("notification already set up for hitTypeId " + hit.getHITTypeId());
    } else {
      log.info("setting up notification for hitTypeId " + hit.getHITTypeId());
      NotificationSpecification notification = new NotificationSpecification();
      notification.setDestination("http://" + hostname + "/cloudsort/hitresult");
      notification.setEventType(
          new EventType[] {EventType.AssignmentSubmitted
            // ,EventType.AssignmentAccepted, EventType.AssignmentReturned,
            // EventType.AssignmentAbandoned
          });
      notification.setTransport(NotificationTransport.REST);
      notification.setVersion("2006-05-05");

      service.setHITTypeNotification(hit.getHITTypeId(), notification, true);

      hitTypes.add(hit.getHITTypeId());
      log.info("notification set up for Hit TypeID = " + hit.getHITTypeId());
    }
  }