Ejemplo n.º 1
0
 @Override
 public void initialize(UimaContext context) throws ResourceInitializationException {
   super.initialize(context);
   if (outputFilename != null) {
     try {
       output = new BufferedWriter(new FileWriter(outputFilename));
     } catch (IOException e) {
       throw new ResourceInitializationException(e);
     }
   } else {
     output = new BufferedWriter(new OutputStreamWriter(System.out));
   }
   try {
     beginFile(this.getClass().getSimpleName());
   } catch (IOException e) {
     throw new ResourceInitializationException(e);
   }
 }
Ejemplo n.º 2
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);
    }
  }