Exemple #1
0
  public List<String> assemblePybossaTaskPublishFormWithIndex(
      String inputData, ClientApp clientApp, int indexStart, int indexEnd) throws Exception {

    List<String> outputFormatData = new ArrayList<String>();
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(inputData);

    JSONArray jsonObject = (JSONArray) obj;
    Iterator itr = jsonObject.iterator();

    for (int i = indexStart; i < indexEnd; i++) {
      JSONObject featureJsonObj = (JSONObject) jsonObject.get(i);
      JSONObject info = assemblePybossaInfoFormat(featureJsonObj, parser, clientApp);

      JSONObject tasks = new JSONObject();

      tasks.put("info", info);
      tasks.put("n_answers", clientApp.getTaskRunsPerTask());
      tasks.put("quorum", clientApp.getQuorum());
      tasks.put("calibration", new Integer(0));
      tasks.put("app_id", clientApp.getPlatformAppID());
      tasks.put("priority_0", new Integer(0));

      outputFormatData.add(tasks.toJSONString());
    }

    return outputFormatData;
  }
Exemple #2
0
  public List<String> assemblePybossaTaskPublishForm(String inputData, ClientApp clientApp)
      throws Exception {

    List<String> outputFormatData = new ArrayList<String>();
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(inputData);

    JSONArray jsonObject = (JSONArray) obj;
    Iterator itr = jsonObject.iterator();

    while (itr.hasNext()) {
      JSONObject featureJsonObj = (JSONObject) itr.next();
      JSONObject info = assemblePybossaInfoFormat(featureJsonObj, parser, clientApp);

      JSONObject tasks = new JSONObject();

      tasks.put("info", info);
      tasks.put("n_answers", clientApp.getTaskRunsPerTask());
      tasks.put("quorum", clientApp.getQuorum());
      tasks.put("calibration", new Integer(0));
      tasks.put("app_id", clientApp.getPlatformAppID());
      tasks.put("priority_0", new Integer(0));

      outputFormatData.add(tasks.toJSONString());

      // System.out.println(featureJsonObj.toString());
    }

    return outputFormatData;
  }
Exemple #3
0
  public String getAnswerResponse(
      ClientApp clientApp,
      String pybossaResult,
      JSONParser parser,
      ClientAppAnswer clientAppAnswer,
      Long taskQueueID)
      throws Exception {
    JSONObject responseJSON = new JSONObject();

    String[] questions = getQuestion(clientAppAnswer, parser);
    int[] responses = new int[questions.length];
    int translationResponses = 0;

    JSONArray array = (JSONArray) parser.parse(pybossaResult);

    Iterator itr = array.iterator();
    String answer = null;
    int cutoffSize = getCutOffNumber(array.size(), clientApp.getTaskRunsPerTask(), clientAppAnswer);
    System.out.print("getAnswerResponse - cutoffSize :" + cutoffSize);
    while (itr.hasNext()) {
      JSONObject featureJsonObj = (JSONObject) itr.next();
      JSONObject info = (JSONObject) featureJsonObj.get("info");

      answer = this.getUserAnswer(featureJsonObj, clientApp);
      System.out.print("getAnswerResponse - answer :" + answer);
      translationResponses = 0;
      for (int i = 0; i < questions.length; i++) {
        if (questions[i].trim().equalsIgnoreCase(answer.trim())) {
          responses[i] = responses[i] + 1;
        } else {
          if (answer.equalsIgnoreCase(ANSWER_NOT_ENGLISH)) {
            translationResponses++;
          }
        }
      }
      if (answer.equalsIgnoreCase(ANSWER_NOT_ENGLISH)) {
        System.out.println("translationResponses: " + translationResponses);

        handleTranslationItem(
            taskQueueID, translationResponses, answer, info, clientAppAnswer, cutoffSize);
      }
    }

    String finalAnswer = null;

    for (int i = 0; i < questions.length; i++) {
      if (responses[i] >= cutoffSize) {
        finalAnswer = questions[i];
      }
    }

    return finalAnswer;
  }
Exemple #4
0
  private JSONObject assemblePybossaInfoFormat(
      JSONObject featureJsonObj, JSONParser parser, ClientApp clientApp) throws Exception {

    String attributeInfo = (String) featureJsonObj.get("attributeInfo");
    JSONObject data = (JSONObject) parser.parse((String) featureJsonObj.get("data"));

    Long documentID = (Long) featureJsonObj.get("documentID");
    Long crisisID = (Long) featureJsonObj.get("crisisID");

    JSONObject usr = (JSONObject) data.get("user");
    String userName = (String) usr.get("name");
    Long userID = (Long) usr.get("id");
    String tweetTxt = (String) data.get("text");
    String createdAt = (String) data.get("created_at");
    Long tweetID = (Long) data.get("id");

    Integer n_answers = 1;
    if (clientApp != null) {
      n_answers = clientApp.getTaskRunsPerTask();
    }

    JSONObject pybossaData = new JSONObject();
    pybossaData.put("question", "please tag it.");
    pybossaData.put("userName", userName);
    pybossaData.put("tweetid", tweetID);
    pybossaData.put("userID", userID.toString());
    pybossaData.put("text", tweetTxt);
    pybossaData.put("createdAt", createdAt);
    pybossaData.put("n_answers", n_answers);
    // pybossaData.put("attributeInfo",attributeInfo);
    pybossaData.put("documentID", documentID);
    pybossaData.put("crisisID", crisisID);
    pybossaData.put("aidrID", clientApp.getClient().getAidrUserID());

    return pybossaData;
  }
Exemple #5
0
  public TaskQueueResponse getTaskQueueResponse(
      ClientApp clientApp,
      String pybossaResult,
      JSONParser parser,
      Long taskQueueID,
      ClientAppAnswer clientAppAnswer,
      ReportTemplateService rtpService)
      throws Exception {
    if (clientAppAnswer == null) {
      return null;
    }

    JSONObject responseJSON = new JSONObject();

    String[] questions = getQuestion(clientAppAnswer, parser);
    int[] responses = new int[questions.length];

    JSONArray array = (JSONArray) parser.parse(pybossaResult);

    int cutOffSize = getCutOffNumber(array.size(), clientApp.getTaskRunsPerTask(), clientAppAnswer);

    System.out.println("cutOffSize :" + cutOffSize);
    Iterator itr = array.iterator();
    String answer = null;
    boolean foundCutoffItem = false;
    while (itr.hasNext()) {
      JSONObject featureJsonObj = (JSONObject) itr.next();

      JSONObject info = (JSONObject) featureJsonObj.get("info");

      Long taskID = (Long) featureJsonObj.get("id");

      answer = this.getUserAnswer(featureJsonObj, clientApp);
      System.out.println("answer :" + answer);
      if (answer != null && !clientApp.getAppType().equals(StatusCodeType.APP_MAP)) {
        for (int i = 0; i < questions.length; i++) {
          if (questions[i].trim().equalsIgnoreCase(answer.trim())) {
            responses[i] = responses[i] + 1;
            foundCutoffItem =
                handleItemAboveCutOff(
                    taskQueueID,
                    responses[i],
                    answer,
                    info,
                    clientAppAnswer,
                    rtpService,
                    cutOffSize);
          }
        }
      }
    }

    String taskInfo = "";
    String responseJsonString = "";

    for (int i = 0; i < questions.length; i++) {
      responseJSON.put(questions[i], responses[i]);
    }
    responseJsonString = responseJSON.toJSONString();

    TaskQueueResponse taskQueueResponse =
        new TaskQueueResponse(taskQueueID, responseJsonString, taskInfo);
    return taskQueueResponse;
  }