Examples of FSIterator


Examples of org.apache.uima.cas.FSIterator

      FSIndex engIndex = indexes.getAnnotationIndex(Annotation.type);
      indexes = gerJcas.getJFSIndexRepository();
      FSIndex gerIndex = indexes.getAnnotationIndex(Annotation.type);
      indexes = frJcas.getJFSIndexRepository();
      FSIndex frIndex = indexes.getAnnotationIndex(Annotation.type);
      FSIterator sofaIter = jcas.getSofaIterator();
      int numSofas = 0;
      while (sofaIter.isValid()) {
        numSofas++;
        sofaIter.moveToNext();
      }
      // assertTrue(sofaIndex.size() == 3); // 3 sofas
      assertTrue(numSofas == 3);
      assertTrue(engIndex.size() == 5); // 4 annots plus documentAnnotation
      assertTrue(gerIndex.size() == 5); // 4 annots plus documentAnnotation
      assertTrue(frIndex.size() == 5); // 4 annots plus documentAnnotation

      // Test that the annotations are of the correct types
      FSIterator engIt = engIndex.iterator();
      FSIterator gerIt = gerIndex.iterator();
      FSIterator frIt = frIndex.iterator();
      Annotation engAnnot = (Annotation) engIt.get();
      Annotation gerAnnot = (Annotation) gerIt.get();
      Annotation frAnnot = (Annotation) frIt.get();
      assertTrue((CAS.TYPE_NAME_DOCUMENT_ANNOTATION).equals(engAnnot.getType().getName()));
      assertTrue((CAS.TYPE_NAME_DOCUMENT_ANNOTATION).equals(gerAnnot.getType().getName()));
      assertTrue((CAS.TYPE_NAME_DOCUMENT_ANNOTATION).equals(frAnnot.getType().getName()));

      engIt.moveToNext();
      gerIt.moveToNext();
      frIt.moveToNext();
      engAnnot = (Annotation) engIt.get();
      CrossAnnotation gerCrossAnnot = (CrossAnnotation) gerIt.get();
      frAnnot = (Annotation) frIt.get();
      assertTrue((CAS.TYPE_NAME_ANNOTATION).equals(engAnnot.getType().getName()));
      assertTrue(("this").equals(engAnnot.getCoveredText()));
      assertTrue((CAS.TYPE_NAME_ANNOTATION).equals(frAnnot.getType().getName()));
      assertTrue(("cette").equals(frAnnot.getCoveredText()));
      assertTrue(("org.apache.uima.cas.test.CrossAnnotation").equals(gerCrossAnnot.getType()
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

    // print out annotations of the Source SofA
    CAS englishView = cas.getView("SourceDocument");
    Assert.assertNotNull(englishView);
    Assert.assertEquals("this beer is good", englishView.getDocumentText());
    FSIndex anIndex = englishView.getAnnotationIndex();
    FSIterator anIter = anIndex.iterator();
    Assert.assertEquals("this beer is good", ((AnnotationFS) anIter.next()).getCoveredText());
    Assert.assertEquals("this", ((AnnotationFS) anIter.next()).getCoveredText());
    if ("this".equals(((AnnotationFS) anIter.get()).getCoveredText()))
      anIter.moveToNext(); // because sometimes the test case runs 2 copies of the TransAnnotator
    Assert.assertEquals("beer", ((AnnotationFS) anIter.next()).getCoveredText());
    if ("beer".equals(((AnnotationFS) anIter.get()).getCoveredText()))
      anIter.moveToNext();
    Assert.assertEquals("is", ((AnnotationFS) anIter.next()).getCoveredText());
    if ("is".equals(((AnnotationFS) anIter.get()).getCoveredText()))
      anIter.moveToNext();
    Assert.assertEquals("good", ((AnnotationFS) anIter.next()).getCoveredText());
    if (anIter.isValid() && "good".equals(((AnnotationFS) anIter.get()).getCoveredText()))
      anIter.moveToNext();
    Assert.assertFalse(anIter.hasNext());

    // print out annotations of the transalation SofA
    // System.out.println("\n----------------\n");
    CAS germanView = cas.getView("TranslatedDocument");
    Assert.assertNotNull(germanView);
    Assert.assertEquals("das bier ist gut", germanView.getDocumentText());
    Type cross = cas.getTypeSystem().getType("sofa.test.CrossAnnotation");
    Feature other = cross.getFeatureByBaseName("otherAnnotation");
    anIndex = germanView.getAnnotationIndex(cross);
    anIter = anIndex.iterator();
    AnnotationFS annot = (AnnotationFS) anIter.next();
    Assert.assertEquals("das", annot.getCoveredText());
    AnnotationFS crossAnnot = (AnnotationFS) annot.getFeatureValue(other);
    Assert.assertEquals("this", crossAnnot.getCoveredText());
    annot = (AnnotationFS) anIter.next();
    Assert.assertEquals("bier", annot.getCoveredText());
    crossAnnot = (AnnotationFS) annot.getFeatureValue(other);
    Assert.assertEquals("beer", crossAnnot.getCoveredText());
    annot = (AnnotationFS) anIter.next();
    Assert.assertEquals("ist", annot.getCoveredText());
    crossAnnot = (AnnotationFS) annot.getFeatureValue(other);
    Assert.assertEquals("is", crossAnnot.getCoveredText());
    annot = (AnnotationFS) anIter.next();
    Assert.assertEquals("gut", annot.getCoveredText());
    crossAnnot = (AnnotationFS) annot.getFeatureValue(other);
    Assert.assertEquals("good", crossAnnot.getCoveredText());
    Assert.assertFalse(anIter.hasNext());
  }
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

    Assert.assertNotNull(cas);
    Assert.assertEquals("das bier ist gut", cas.getDocumentText());
    Type cross = cas.getTypeSystem().getType("sofa.test.CrossAnnotation");
    Feature other = cross.getFeatureByBaseName("otherAnnotation");
    FSIndex anIndex = cas.getAnnotationIndex(cross);
    FSIterator anIter = anIndex.iterator();
    AnnotationFS annot = (AnnotationFS) anIter.next();
    Assert.assertEquals("das", annot.getCoveredText());
    AnnotationFS crossAnnot = (AnnotationFS) annot.getFeatureValue(other);
    Assert.assertEquals("this", crossAnnot.getCoveredText());
    annot = (AnnotationFS) anIter.next();
    Assert.assertEquals("bier", annot.getCoveredText());
    crossAnnot = (AnnotationFS) annot.getFeatureValue(other);
    Assert.assertEquals("beer", crossAnnot.getCoveredText());
    annot = (AnnotationFS) anIter.next();
    Assert.assertEquals("ist", annot.getCoveredText());
    crossAnnot = (AnnotationFS) annot.getFeatureValue(other);
    Assert.assertEquals("is", crossAnnot.getCoveredText());
    annot = (AnnotationFS) anIter.next();
    Assert.assertEquals("gut", annot.getCoveredText());
    crossAnnot = (AnnotationFS) annot.getFeatureValue(other);
    Assert.assertEquals("good", crossAnnot.getCoveredText());
    Assert.assertFalse(anIter.hasNext());
  }
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

  public void actionPerformed(ActionEvent event) {
    String title = this.main.getIndexLabel() + " - " + this.main.getIndex().getType().getName();
    MultiAnnotViewerFrame f = new MultiAnnotViewerFrame(title);
    f.addWindowListener(new CloseAnnotationViewHandler(this.main));
    FSIterator it = this.main.getIndex().iterator();
    final String text = this.main.getCas().getDocumentText();
    System.out.println("Creating extents.");
    AnnotationExtent[] extents = MultiMarkup.createAnnotationMarkups(it, text.length(), this.main
        .getStyleMap());
    System.out.println("Initializing text frame.");
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

      // (it was put there by the FileSystemCollectionReader)
      if (!(xcasInput || xmiInput)) {
        Type fileLocType = aCas.getTypeSystem().getType(
                "org.apache.uima.examples.SourceDocumentInformation");
        Feature fileNameFeat = fileLocType.getFeatureByBaseName("uri");
        FSIterator it = aCas.getAnnotationIndex(fileLocType).iterator();
        FeatureStructure fileLoc = it.get();
        File inFile = new File(fileLoc.getStringValue(fileNameFeat));
        System.out.println("Processed Document " + inFile.getName());
      } else {
        System.out.println("doc" + docsProcessed++ + " processed successfully");
      }
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

    } catch (BadLocationException e) {
      throw new RuntimeException(e);
    }

    // Iterate over annotations
    FSIterator iter = mCAS.getAnnotationIndex().iterator();
    Hashtable checkBoxes = new Hashtable();
    HashSet checkBoxesDone = new HashSet();
    while (iter.isValid()) {
      AnnotationFS fs = (AnnotationFS) iter.get();
      iter.moveToNext();

      Type type = fs.getType();

      // have we seen this type before?
      JCheckBox checkbox = (JCheckBox) mTypeToCheckboxMap.get(type);
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

      // noticeable delay when the user first switches to Entity mode.
      jcas = mCAS.getJCas();
    } catch (CASException e) {
      throw new RuntimeException(e);
    }
    FSIterator iter = jcas.getAnnotationIndex().iterator();
    while (iter.isValid()) {
      Annotation annot = (Annotation) iter.get();
      iter.moveToNext();

      // find out what entity this annotation represents
      EntityResolver.Entity entity = mEntityResolver.getEntity(annot);

      //if not an entity, skip it
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

   */
  private void updateSelectedAnnotationTree(int aPosition) {
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.selectedAnnotationTreeModel
            .getRoot();
    root.removeAllChildren();
    FSIterator annotIter = this.mCAS.getAnnotationIndex().iterator();
    while (annotIter.isValid()) {
      AnnotationFS annot = (AnnotationFS) annotIter.get();
      // if (getPanePosition(annot.getBegin()) <= aPosition
      // && getPanePosition(annot.getEnd()) > aPosition)
      if (annot.getBegin() <= aPosition && annot.getEnd() > aPosition) {
        JCheckBox checkbox = (JCheckBox) mTypeToCheckboxMap.get(annot.getType());
        if (checkbox != null && checkbox.isSelected()) {
          addAnnotationToTree(annot);
        }
      }
      // else if (getPanePosition(annot.getBegin()) > aPosition)
      else if (annot.getBegin() > aPosition)
        break;
      annotIter.moveToNext();
    }
    this.selectedAnnotationTreeModel.nodeStructureChanged(root);
    // expand first level
    // int row = 0;
    // while (row < this.selectedAnnotationTree.getRowCount())
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

    } catch (CASException e) {
      throw new ResourceProcessException(e);
    }

    // retreive the filename of the input file from the CAS
    FSIterator it = jcas.getAnnotationIndex(SourceDocumentInformation.type).iterator();
    File outFile = null;
    if (it.hasNext()) {
      SourceDocumentInformation fileLoc = (SourceDocumentInformation) it.next();
      File inFile;
      try {
        inFile = new File(new URL(fileLoc.getUri()).getPath());
        String outFileName = inFile.getName();
        if (fileLoc.getOffsetInSource() > 0) {
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

    if (mTEXT) {
      // get the default View if it exists
      try {
        jcas = aCAS.getView(CAS.NAME_DEFAULT_SOFA).getJCas();
        hasDefaultView = true;
        FSIterator it = jcas.getAnnotationIndex(SourceDocumentInformation.type).iterator();
        if (it.hasNext()) {
          // get the output file name from the annotation in the CAS ...
          // ... note this is a little flakey if processing an XCAS file,
          // which could have such an annotation with a different name than the input XCAS file!
          // So we don't do this if XCAS output is specified.
          SourceDocumentInformation fileLoc = (SourceDocumentInformation) it.next();
          File inFile;
          inFile = new File(new URL(fileLoc.getUri()).getPath());
          outFile = new File(mOutputDir, inFile.getName());
        }
      } catch (CASRuntimeException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.