コード例 #1
0
  private static void verifyCategoryCell(Cell cell) throws ParseException {

    verifyStringCell(cell, "category cell");

    Category cat = Category.getCategory(cell.getStringCellValue());
    if (cat == Category.UNKNOWN)
      throw new ParseException(
          "Unknown category: " + cell.getStringCellValue() + "in row " + cell.getRow().getRowNum(),
          0);
  }
コード例 #2
0
  private static InterviewInstance getInstance(Row row) throws ParseException {

    // extract the cells needed from this row
    Cell interview_id_cell = row.getCell(0, Row.CREATE_NULL_AS_BLANK);
    Cell line_cell = row.getCell(1, Row.CREATE_NULL_AS_BLANK);
    Cell speaker_cell = row.getCell(2, Row.CREATE_NULL_AS_BLANK);
    Cell comment_cell = row.getCell(3, Row.CREATE_NULL_AS_BLANK);
    ArrayList<Cell> category_cells = new ArrayList<>(5);
    for (int i = 4; i <= 8; ++i) {
      Cell cell = row.getCell(i, Row.CREATE_NULL_AS_BLANK);
      if (cell.getCellType() != Cell.CELL_TYPE_BLANK) category_cells.add(cell);
    }
    Cell sentiment_cell = row.getCell(9, Row.CREATE_NULL_AS_BLANK);

    // verify that all the required information is present
    verifyNumericCell(interview_id_cell, "Interview ID field");
    verifyNumericCell(line_cell, "Line field");
    verifySpeakerCell(speaker_cell);
    verifyCellNotEmpty(comment_cell, "Comment cell");

    if (category_cells.isEmpty())
      throw new ParseException("No category labels given for samples in row " + row.getRowNum(), 0);

    Iterator<Cell> row_iter = category_cells.iterator();
    ArrayList<Category> categories = new ArrayList<>();
    while (row_iter.hasNext()) {
      Cell category_cell = row_iter.next();
      verifyCategoryCell(category_cell);
      categories.add(Category.getCategory(category_cell.getStringCellValue()));
    }

    // convert the cell into an interviewInstance
    InterviewInstance instance =
        new InterviewInstance(
            (int) interview_id_cell.getNumericCellValue(),
            (int) line_cell.getNumericCellValue(),
            Speaker.getSpeaker(speaker_cell.getStringCellValue()),
            comment_cell.getStringCellValue(),
            categories);

    return instance;
  }