コード例 #1
0
 protected void printTextAnnotations(Collection<TextAnnotation> annotations, PrintStream ps) {
   List<TextAnnotation> taList = new ArrayList<TextAnnotation>(annotations);
   Collections.sort(taList, TextAnnotation.BY_SPAN());
   for (TextAnnotation ta : annotations) {
     printTextAnnotation(ta, ps);
   }
 }
コード例 #2
0
  /** cycle through all annotations and remove any slots that have been inputted by the user */
  @Override
  public void process(JCas jCas) throws AnalysisEngineProcessException {
    // List<CCPTextAnnotation> annotationsToRemove = new ArrayList<CCPTextAnnotation>();

    for (Iterator<CCPTextAnnotation> annotIter = JCasUtil.iterator(jCas, CCPTextAnnotation.class);
        annotIter.hasNext(); ) {
      CCPTextAnnotation ccpTa = annotIter.next();
      TextAnnotation ta = new WrappedCCPTextAnnotation(ccpTa);
      try {
        switch (removeOption) {
          case REMOVE_ALL:
            if (ta.getClassMention().getPrimitiveSlotMentions().size() > 0
                || ta.getClassMention().getComplexSlotMentions().size() > 0) {
              //						logger.log(Level.INFO, "Removing ALL slots from: " + ta.toString());
              ta.getClassMention().setComplexSlotMentions(new ArrayList<ComplexSlotMention>());
              ta.getClassMention().setPrimitiveSlotMentions(new ArrayList<PrimitiveSlotMention>());
            }
            break;
          case REMOVE_COMPLEX:
            if (ta.getClassMention().getComplexSlotMentions().size() > 0) {
              //						logger.log(Level.INFO, "Removing complex slots from: " + ta.toString());
              ta.getClassMention().setComplexSlotMentions(new ArrayList<ComplexSlotMention>());
              //						logger.log(Level.INFO, "# complex slots remaining: "
              //								+ ta.getClassMention().getComplexSlotMentions().size());
            }
            break;
          case REMOVE_PRIMITIVE:
            if (ta.getClassMention().getPrimitiveSlotMentions().size() > 0) {
              //						logger.log(Level.INFO, "Removing primitive slots from: " + ta.toString());
              ta.getClassMention().setPrimitiveSlotMentions(new ArrayList<PrimitiveSlotMention>());
            }
            break;
          case REMOVE_NONE:
            // don't do anything
            break;
          default:
            throw new IllegalArgumentException(
                "Unhandled SlotRemoveOption: " + removeOption.name());
        }
      } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
      }
    }
    // else {
    // throw new UnsupportedOperationException("This needs to be implemented still");
    // String mentionName = ccpCM.getMentionName().toLowerCase();
    // logger.debug("MentionName: " + mentionName + "  MENTION NAMES OF INTEREST: "
    // + classesOfInterest.toString());
    // if (classesOfInterest.contains(mentionName)) {
    // logger.debug("Found class of interest: " + mentionName);
    //
    // FSArray ccpSlots = ccpCM.getSlotMentions();
    //
    // /*
    // * since the FSArray class has no remove() method, we will create a set of
    // * CCPSlotMentions that we will keep. If any slots are removed, they will
    // * not be added to this list, and then this new list will be put into a new
    // * FSArray, and replace the original FSArray. This is a bit of a
    // * work-around... perhaps there's a better way.
    // */
    // List<CCPSlotMention> slotsToKeep = new ArrayList<CCPSlotMention>();
    // boolean removedAtLeastOneSlot = false;
    //
    // if (ccpSlots != null) {
    // for (int i = 0; i < ccpSlots.size(); i++) {
    // CCPSlotMention ccpSM = (CCPSlotMention) ccpSlots.get(i);
    // String slotName = ccpSM.getMentionName().toLowerCase();
    // if (slotsToRemoveList.contains(mentionName + "|" + slotName)) {
    // logger.debug("Found slot of interest: " + slotName);
    // /* then remove this slot */
    // removedAtLeastOneSlot = true;
    // } else {
    // /*
    // * we are not going to remove this slot, so we store it in the
    // * list
    // */
    // slotsToKeep.add(ccpSM);
    // }
    // }
    // }
    //
    // /*
    // * if we removed a slot, then we need to replace the FSArray for this
    // * CCPClassMention
    // */
    // if (removedAtLeastOneSlot) {
    // FSArray keptSlots = new FSArray(jcas, slotsToKeep.size());
    // for (int i = 0; i < keptSlots.size(); i++) {
    // keptSlots.set(i, slotsToKeep.get(i));
    // }
    // ccpCM.setSlotMentions(keptSlots);
    // }
    // }
    // }

    // }
    // }

    // /*
    // * now remove annotations that had class mention types not in the classMentionTypesToKeep
    // * list
    // */
    // for (CCPTextAnnotation ccpTA : annotationsToRemove) {
    // ccpTA.removeFromIndexes();
    // ccpTA = null;
    // }

  }