Examples of FSIterator


Examples of org.apache.uima.cas.FSIterator

      FeatureStructure f1 = localCas.createFS(subTok);
      localCas.getIndexRepository().addFS(f1);

      JFSIndexRepository ir = jcas.getJFSIndexRepository();
      FSIndex index = ir.getAnnotationIndex();
      FSIterator it = index.iterator();

      try {

        while (it.isValid()) {
          Object o = it.get();
          assertTrue(o instanceof Annotation);
          it.moveToNext();
        }
      } catch (Exception e) {
        System.out.println("failed: nonJCasCovered by JCas");
      }
    } catch (Exception e) {
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

  public void testIteratorGetsJCasType() throws Exception {
    try {
      Token tok1 = new Token(jcas);
      tok1.addToIndexes();
      FSIterator it = jcas.getJFSIndexRepository().getIndex("all", Token.type).iterator();
      while (it.hasNext()) {
        Token token = (Token) it.next();
        token.addToIndexes(); // something to do to keep Java from optimizing this away.
      }
    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

    // Add an FS with an array of existing annotations in another view
    int nToks = 3;
    ArrayFS array = newView2.createArrayFS(nToks);
    Type thingType = newCas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Thing");
    FSIterator thingIter = newCas2.getAnnotationIndex(thingType).iterator();
    for (int i = 0; i < nToks; ++i)
      array.set(i, (FeatureStructure)thingIter.next())
    Type annotArrayTestType = newView2.getTypeSystem().getType("org.apache.uima.testTypeSystem.AnnotationArrayTest");
    Feature annotArrayFeat = annotArrayTestType.getFeatureByBaseName("arrayOfAnnotations");
    AnnotationFS fsArrayTestAnno = newView2.createAnnotation(annotArrayTestType, 13, 27);
    fsArrayTestAnno.setFeatureValue(annotArrayFeat,array);
    newView2.addFsToIndexes(fsArrayTestAnno);
   
    // re-serialize each new CAS back to XMI, keeping consistent ids
    String newSerCas1 = serialize(newCas1, deserSharedData1, marker1);
    String newSerCas2 = serialize(newCas2, deserSharedData2, marker2);
   
    // merge the two XMI CASes back into the original CAS
    // the shared data will be reset and recreated if not using deltaCas
    if (useDeltas) {
      deserialize(newSerCas1, cas, serSharedData, false, maxOutgoingXmiId);
    } else {
      deserialize(newSerCas1, cas, serSharedData, false, -1);
    }
    assertEquals(numAnnotations + 2, cas.getAnnotationIndex().size());

    deserialize(newSerCas2, cas, serSharedData, false, maxOutgoingXmiId);
    assertEquals(numAnnotations + 5, cas.getAnnotationIndex().size());
    assertEquals(docText, cas.getDocumentText());

    // Serialize/deserialize again in case merge created duplicate ids
    String newSerCasMerged = serialize(cas, serSharedData);
    deserialize(newSerCasMerged, cas, serSharedData, false, -1);
   
    //check covered text of annotations
    FSIterator iter = cas.getAnnotationIndex().iterator();
    while (iter.hasNext()) {
      AnnotationFS annot = (AnnotationFS)iter.next();
      assertEquals(cas.getDocumentText().substring(
              annot.getBegin(), annot.getEnd()), annot.getCoveredText());
    }
    //check Owner annotation we created to test link across merge boundary
    iter = cas.getAnnotationIndex(ownerType).iterator();
    while (iter.hasNext()) {
      AnnotationFS
      annot = (AnnotationFS)iter.next();
      String componentId = annot.getStringValue(componentIdFeat);
      if ("XCasDeserializerTest".equals(componentId)) {
        FeatureStructure targetRelArgs = annot.getFeatureValue(argsFeat);
        AnnotationFS targetDomain = (AnnotationFS)targetRelArgs.getFeatureValue(domainFeat);
        assertEquals(60, targetDomain.getBegin());
        assertEquals(70, targetDomain.getEnd());
        AnnotationFS targetRange = (AnnotationFS)targetRelArgs.getFeatureValue(rangeFeat);
        assertEquals(orgBegin, targetRange.getBegin());
        assertEquals(orgEnd, targetRange.getEnd());
      }    
    }
    //check Sofas
    CAS targetView1 = cas.getView("newSofa1");
    assertEquals(sofaText1, targetView1.getDocumentText());
    CAS targetView2 = cas.getView("newSofa2");
    assertEquals(sofaText2, targetView2.getDocumentText());
    AnnotationFS targetAnnot1 = (AnnotationFS)
      targetView1.getAnnotationIndex(orgType).iterator().get();
    assertEquals(annotText, targetAnnot1.getCoveredText());
    AnnotationFS targetAnnot2 = (AnnotationFS)
    targetView2.getAnnotationIndex(orgType).iterator().get();
    assertEquals(annotText, targetAnnot2.getCoveredText());
    assertTrue(targetView1.getSofa().getSofaRef() !=
            targetView2.getSofa().getSofaRef());
   
    CAS checkPreexistingView = cas.getView("preexistingView");
    assertEquals(preexistingViewText, checkPreexistingView.getDocumentText());
    Type personType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.Person");   
    AnnotationFS targetAnnot3 = (AnnotationFS)
            checkPreexistingView.getAnnotationIndex(personType).iterator().get();
    assertEquals("John Smith", targetAnnot3.getCoveredText());

    // Check the FS with an array of pre-existing FSs
    iter = targetView2.getAnnotationIndex(annotArrayTestType).iterator();
    componentIdFeat = thingType.getFeatureByBaseName("componentId");
    while (iter.hasNext()) {
      AnnotationFS annot = (AnnotationFS)iter.next();
      ArrayFS fsArray = (ArrayFS)annot.getFeatureValue(annotArrayFeat);
      assertTrue(fsArray.size() == 3);
      for (int i = 0; i < fsArray.size(); ++i) {
        AnnotationFS refAnno = (AnnotationFS)fsArray.get(i);
        assertEquals(thingType.getName(), refAnno.getType().getName());
View Full Code Here

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

    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

Examples of org.apache.uima.cas.FSIterator

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

    // retrieve 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 {
        // handle blanks in path
        // https://issues.apache.org/jira/browse/UIMA-1748
        // use 3 arg form of URI Constructor to properly quote any otherwise illegal chars such as blank
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

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

    // retrieve 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 {
        // handle blanks in path
        // https://issues.apache.org/jira/browse/UIMA-1748
        // use 3 arg form of URI Constructor to properly quote any otherwise illegal chars such as blank
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

    int end = whiskRuleItem.getWordConstraint().getTokenAnnotation().getEnd();
    CAS cas = example.getDocumentCAS();
    // TODO: access type with string constant
    Type frameType = cas.getTypeSystem().getType("org.apache.uima.ruta.type.RutaFrame");
    AnnotationFS pointer = cas.createAnnotation(frameType, end, Integer.MAX_VALUE);
    FSIterator iterator = cas.getAnnotationIndex().iterator(pointer);
    int nextBegin = -1;
    while (iterator.isValid()) {
      FeatureStructure fs = iterator.get();
      if (fs instanceof AnnotationFS) {
        AnnotationFS a = (AnnotationFS) fs;
        if (!filterSetWithSlotNames.contains(a.getType().getName())) {
          if (nextBegin == -1) {
            nextBegin = a.getBegin();
          } else if (nextBegin != a.getBegin()) {
            break;
          }
          if (a.getBegin() <= nextBegin && a.getBegin() >= end) {
            WhiskRuleItem term = new WhiskRuleItem(new TextRulerAnnotation(a,
                    example.getDocument(), consideredFeatures));
            result.add(term);
          }
        }
      }
      iterator.moveToNext();
    }
    return result;
  }
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

    CAS cas = example.getDocumentCAS();

    // TODO: access type with string constant
    Type frameType = cas.getTypeSystem().getType("org.apache.uima.ruta.type.RutaFrame");
    AnnotationFS pointer = cas.createAnnotation(frameType, begin, begin);
    FSIterator iterator = cas.getAnnotationIndex().iterator(pointer);
    int nextEnd = -1;

    // ???
    iterator.moveToPrevious();
    iterator.moveToPrevious();
    while (iterator.isValid()) {
      FeatureStructure fs = iterator.get();
      if (fs instanceof AnnotationFS) {
        AnnotationFS a = (AnnotationFS) fs;
        if (!filterSetWithSlotNames.contains(a.getType().getName())) {
          if (a.getEnd() > example.getAnnotation().getEnd()) {
            iterator.moveToPrevious();
            continue;
          }
          if (nextEnd == -1) {
            nextEnd = a.getEnd();
          } else if (nextEnd != a.getEnd()) {
            break;
          }
          if (a.getEnd() >= nextEnd && a.getEnd() <= begin) {
            WhiskRuleItem term = new WhiskRuleItem(new TextRulerAnnotation(a,
                    example.getDocument(), consideredFeatures));
            result.add(term);
          }
        }
      }
      iterator.moveToPrevious();
    }
    return result;
  }
View Full Code Here

Examples of org.apache.uima.cas.FSIterator

    List<List<WhiskRuleItem>> result = new ArrayList<List<WhiskRuleItem>>();
    CAS cas = example.getDocumentCAS();
    // TODO: access type with string constant
    Type frameType = cas.getTypeSystem().getType("org.apache.uima.ruta.type.RutaFrame");
    AnnotationFS pointer = cas.createAnnotation(frameType, startPos, endPos);
    FSIterator iterator = cas.getAnnotationIndex().iterator(pointer);
    List<AnnotationFS> startAs = new ArrayList<AnnotationFS>();
    int firstBegin = -1;
    while (iterator.isValid()) {
      FeatureStructure fs = iterator.get();
      AnnotationFS a = (AnnotationFS) fs;

      // TODO change for multislot rules!
      if (a.getBegin() >= startPos && a.getEnd() <= endPos) {
        if (!filterSetWithSlotNames.contains(a.getType().getName())) {
          if (firstBegin == -1) {
            firstBegin = a.getBegin();
          } else if (firstBegin != a.getBegin()) {
            break;
          }
          if (a.getBegin() == firstBegin)
            startAs.add(a);
        }
        iterator.moveToNext();
      } else {
        iterator.moveToNext();
      }
    }

    for (AnnotationFS annotation : startAs) {
      List<WhiskRuleItem> startList = new ArrayList<WhiskRuleItem>();
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.