@Test
  public void whenCreateTable_thenCreated() {
    final Table<String, String, Integer> distance = HashBasedTable.create();
    distance.put("London", "Paris", 340);
    distance.put("New York", "Los Angeles", 3940);
    distance.put("London", "New York", 5576);

    assertEquals(3940, distance.get("New York", "Los Angeles").intValue());
    assertThat(distance.columnKeySet(), containsInAnyOrder("Paris", "New York", "Los Angeles"));
    assertThat(distance.rowKeySet(), containsInAnyOrder("London", "New York"));
  }
  @Test
  public void whenTransposeTable_thenCorrect() {
    final Table<String, String, Integer> distance = HashBasedTable.create();
    distance.put("London", "Paris", 340);
    distance.put("New York", "Los Angeles", 3940);
    distance.put("London", "New York", 5576);

    final Table<String, String, Integer> transposed = Tables.transpose(distance);
    assertThat(transposed.rowKeySet(), containsInAnyOrder("Paris", "New York", "Los Angeles"));
    assertThat(transposed.columnKeySet(), containsInAnyOrder("London", "New York"));
  }
Example #3
0
  @Override
  public void process(JCas aJCas) throws AnalysisEngineProcessException {
    super.process(aJCas);
    Table<WSDItem, String, FSArray> testResults =
        TreeBasedTable.create(new WSDItemComparator(), new StringComparator());

    for (WSDResult r : JCasUtil.select(aJCas, WSDResult.class)) {
      if (r.getWsdItem() == null) {
        logger.info(
            "skipping "
                + r.getDisambiguationMethod()
                + " result for \""
                + r.getCoveredText()
                + "\" because it has no instance");
        continue;
      }
      if (r.getSenses() == null) {
        logger.info(
            "skipping "
                + r.getDisambiguationMethod()
                + " result for "
                + r.getWsdItem().getId()
                + " because no senses are assigned");
        continue;
      }
      if (ignoreResult(r)) {
        logger.info(
            goldStandardAlgorithm
                + " result for "
                + r.getWsdItem().getId()
                + " matches the ignore pattern");
      } else {
        testResults.put(r.getWsdItem(), r.getDisambiguationMethod(), r.getSenses());
      }
    }

    try {
      beginDocument("Document");
      beginTable(testResults.rowKeySet().size(), testResults.columnKeySet().size());
      beginTableRow();
      tableHeader("instance");
      tableHeader(goldStandardAlgorithm);
      for (String testAlgorithm : testResults.columnKeySet()) {
        if (!testAlgorithm.equals(goldStandardAlgorithm)) {
          tableHeader(testAlgorithm);
        }
      }
      endTableRow();
      for (WSDItem wsdItem : testResults.rowKeySet()) {
        if (maxItemsAttempted >= 0 && numItemsAttempted++ >= maxItemsAttempted) {
          break;
        }
        FSArray goldResults = testResults.get(wsdItem, goldStandardAlgorithm);
        beginTableRow();
        tableHeaderInstance(wsdItem);
        tableCellGoldResults(goldResults);
        for (String testAlgorithm : testResults.columnKeySet()) {
          if (!testAlgorithm.equals(goldStandardAlgorithm)) {
            tableCellTestResults(goldResults, testResults.get(wsdItem, testAlgorithm));
          }
        }
        endTableRow();
      }
      endTable();
      endDocument();
    } catch (IOException e) {
      throw new AnalysisEngineProcessException(e);
    }
  }