Java Code Examples for org.apache.uima.cas.CASException#printStackTrace()

The following examples show how to use org.apache.uima.cas.CASException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypePriorityTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private CASMgr initCAS() {
  // Create a CASMgr. Ensures existence of AnnotationFS type.

  CASMgr localCas = CASFactory.createCAS(200);
  // Create a writable type system.
  TypeSystemMgr tsa = localCas.getTypeSystemMgr();
  // Add new types and features.

  addTypesForLevel(tsa, 4);

  // Commit the type system.
  ((CASImpl) localCas).commitTypeSystem();
  try {
    localCas.initCASIndexes();
  } catch (CASException e2) {
    e2.printStackTrace();
    assertTrue(false);
  }

  localCas.getIndexRepositoryMgr().commit();
  // assert(cas.getIndexRepositoryMgr().isCommitted());
  return localCas;
}
 
Example 2
Source File: IteratorTestSorted.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void setUp() {
  CASImpl casMgr = (CASImpl) CASFactory.createCAS();
  TypeSystemImpl tsi = (TypeSystemImpl) casMgr.getTypeSystemMgr();
  TypeImpl level_1_type = tsi.addType("org.apache.uima.cas.test.Level_1", tsi.annotType);
  tsi.addFeature("id", level_1_type, tsi.floatType);
  TypeImpl level_2_type = tsi.addType("org.apache.uima.cas.test.Level_2",  level_1_type);
  TypeImpl level_3_type = tsi.addType("org.apache.uima.cas.test.Level_3",  level_2_type);
  TypeImpl level_4_type = tsi.addType("org.apache.uima.cas.test.Level_4",  level_3_type);
  TypeImpl level_5_type = tsi.addType("org.apache.uima.cas.test.Level_5",  level_4_type);
  TypeImpl level_6_type = tsi.addType("org.apache.uima.cas.test.Level_6",  level_5_type);
  
  casMgr.commitTypeSystem();
  try {
    FSIndexRepositoryMgr irm = casMgr.getIndexRepositoryMgr();
    casMgr.initCASIndexes();
    irm.commit();
    
    jcas = casMgr.getCurrentView().getJCas();
  } catch (CASException e) {
    e.printStackTrace();
    fail();
  }
}
 
Example 3
Source File: PredictionsWriter.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override
    public void process(CAS aCAS) throws AnalysisEngineProcessException {

        try {
            JCas jCas = aCAS.getJCas();

            Collection<Sentence> sentences = JCasUtil.select(jCas, Sentence.class);
            for (Sentence sentence : sentences) {
                List<Token> tokens = JCasUtil.selectCovered(jCas, Token.class, sentence);
                Class<? extends Annotation> goldAnnotation;
                Class<? extends Annotation> predAnnotation;
                if (knowNER) {
                    goldAnnotation = NamedEntity.class;
                    predAnnotation = TextClassificationOutcome.class;
                } else {
                    goldAnnotation = TextClassificationOutcome.class;
                    predAnnotation = NamedEntity.class;
                }

                for (Token token : tokens) {

                    String line = getTag(goldAnnotation, jCas, token) + "\t" + getTag(predAnnotation, jCas, token);
                    out.add(line);
//                    verboseOut.add(token.getCoveredText() + "\t" + line);

                }
//                verboseOut.add("\n");
                out.add("\n");
            }
//            System.out.println(out);
        }catch (CASException e) {
            e.printStackTrace();
        }
//        out.flush();
    }
 
Example 4
Source File: CasAnnotationViewer.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Refreshes the selected annotation tree.
 * 
 * @param aPosition
 *          the currently selected offset into the document. All annotations overlapping this
 *          point will be rendered in the tree.
 */
private void updateSelectedAnnotationTree(int aPosition) {
  if (this.cas == null || this.selectedAnnotationTreeModel == null) {
    return;
  }
  JCas jcas = null;
  try {
    jcas = this.cas.getJCas();
  } catch (CASException e) {
      e.printStackTrace();
      return;
  }

  DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.selectedAnnotationTreeModel.getRoot();
  root.removeAllChildren();

  AnnotationIndex<Annotation> annotationIndex = jcas.getAnnotationIndex();
  if (annotationIndex == null) {
    return;
  }
  FSIterator<Annotation> annotationIterator = annotationIndex.iterator();
  if (annotationIterator == null || !annotationIterator.hasNext()) {
    return;
  }

  while (annotationIterator.hasNext()) {
    Annotation annotation = annotationIterator.next();
    int begin = annotation.getBegin();
    if (begin > aPosition) {
      // Assuming all annotation objects are sorted by begin/end, if this one passed the given offset,
      // there is no need to keep looking at the subsequent ones.
      break;
    }
    if (annotation.getEnd() > aPosition && this.isMatch(annotation)) {
      // The annotation covers the given position (begins before and ends after the given position).
      this.addAnnotationToTree(annotation);
    }
  }
  this.selectedAnnotationTreeModel.nodeStructureChanged(root);
  // hmmm.. how to get scroll pane to resize properly??
  this.selectedAnnotationTree.treeDidChange();
  // this.selectedAnnotationTree.setPreferredSize(this.selectedAnnotationTree.getSize());
  this.selectedAnnotationTree.revalidate();
  this.horizontalSplitPane.revalidate();
}