Package org.apache.uima.cas

Examples of org.apache.uima.cas.FSIndex


    cas1.setDocumentText("This is a test document in the initial view");
    AnnotationFS anAnnot1 = cas1.createAnnotation(cas1.getAnnotationType(), 0, 4);
    cas1.getIndexRepository().addFS(anAnnot1);
    AnnotationFS anAnnot2 = cas1.createAnnotation(cas1.getAnnotationType(), 5, 10);
    cas1.getIndexRepository().addFS(anAnnot2);
    FSIndex tIndex = cas1.getAnnotationIndex();
    assertTrue(tIndex.size() == 3); //doc annot plus  annots
   
    //serialize complete 
    XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
    String xml = this.serialize(cas1, sharedData);
    int maxOutgoingXmiId = sharedData.getMaxXmiId();
    //deserialize into cas2
    XmiSerializationSharedData sharedData2 = new XmiSerializationSharedData();     
    //XmiCasDeserializer.deserialize(new StringBufferInputStream(xml), cas2, true, sharedData2);
    this.deserialize(xml, cas2, sharedData2, true, -1);
    CasComparer.assertEquals(cas1, cas2);
   
    //create Marker, add/modify fs and serialize in delta xmi format.
    Marker marker = cas2.createMarker();
    FSIndex cas2tIndex = cas2.getAnnotationIndex();
   
    //create an annotation and add to index
    AnnotationFS cas2newAnnot = cas2.createAnnotation(cas2.getAnnotationType(), 6, 8);
    cas2.getIndexRepository().addFS(cas2newAnnot);
    assertTrue(cas2tIndex.size() == 4); // prev annots and this new one
   
    //modify an existing annotation
    Iterator<FeatureStructure> tIndexIter = cas2tIndex.iterator();
    AnnotationFS docAnnot = (AnnotationFS) tIndexIter.next(); //doc annot
    //delete from index
    AnnotationFS delAnnot = (AnnotationFS) tIndexIter.next(); //annot
    cas2.getIndexRepository().removeFS(delAnnot);
    assertTrue(cas2.getAnnotationIndex().size() == 3);
View Full Code Here


      this.deserialize(xml, cas2, sharedData2, true, -1);
      CasComparer.assertEquals(cas1, cas2);
     
      //create Marker, add/modify fs and serialize in delta xmi format.
      Marker marker = cas2.createMarker();
      FSIndex cas2tIndex = cas2.getAnnotationIndex();
     
      //create an annotation and add to index
      AnnotationFS cas2newAnnot = cas2.createAnnotation(cas2.getAnnotationType(), 6, 8);
      cas2.getIndexRepository().addFS(cas2newAnnot);
      assertTrue(cas2tIndex.size() == 4); // prev annots and this new one
     
      //modify language feature
      Iterator<FeatureStructure> tIndexIter = cas2tIndex.iterator();
      AnnotationFS docAnnot = (AnnotationFS) tIndexIter.next();
      Feature languageF = cas2.getDocumentAnnotation().getType().getFeatureByBaseName(CAS.FEATURE_BASE_NAME_LANGUAGE);
      docAnnot.setStringValue(languageF, "en");
    
      // serialize cas2 in delta format
View Full Code Here

        this.deserialize(xml, cas2, sharedData2, true, -1);
        CasComparer.assertEquals(cas1, cas2);
       
        //create Marker, add/modify fs and serialize in delta xmi format.
        Marker marker = cas2.createMarker();
        FSIndex cas2tIndex = cas2.getAnnotationIndex();
       
        // serialize cas2 in delta format
        String deltaxml1 = serialize(cas2, sharedData2, marker);
        //System.out.println(deltaxml1);
       
View Full Code Here

      cas1.setDocumentText("This is a test document in the initial view");
      AnnotationFS anAnnot1 = cas1.createAnnotation(cas1.getAnnotationType(), 0, 4);
      cas1.getIndexRepository().addFS(anAnnot1);
      AnnotationFS anAnnot2 = cas1.createAnnotation(cas1.getAnnotationType(), 5, 10);
      cas1.getIndexRepository().addFS(anAnnot2);
      FSIndex tIndex = cas1.getAnnotationIndex();
      assertTrue(tIndex.size() == 3); //doc annot plus 2 annots
     
      //serialize complete 
      XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
      String xml = serialize(cas1, sharedData);
      int maxOutgoingXmiId = sharedData.getMaxXmiId();
     
      //deserialize into cas2
      XmiSerializationSharedData sharedData2 = new XmiSerializationSharedData();     
      this.deserialize(xml, cas2, sharedData2, true, -1);
      CasComparer.assertEquals(cas1, cas2);
     
      //create Marker, add/modify fs and serialize in delta xmi format.
      Marker marker = cas2.createMarker();
      FSIndex cas2tIndex = cas2.getAnnotationIndex();
     
      //create an annotation and add to index
      AnnotationFS cas2newAnnot = cas2.createAnnotation(cas2.getAnnotationType(), 6, 8);
      cas2.getIndexRepository().addFS(cas2newAnnot);
      assertTrue(cas2tIndex.size() == 4); // prev annots and this new one
     
      //modify language feature
      Iterator<FeatureStructure> tIndexIter = cas2tIndex.iterator();
      AnnotationFS docAnnot = (AnnotationFS) tIndexIter.next();
     
      //delete annotation from index   
      AnnotationFS delAnnot = (AnnotationFS) tIndexIter.next(); //annot
      cas2.getIndexRepository().removeFS(delAnnot);
View Full Code Here

      cas1.getIndexRepository().addFS(anAnnot2);
      AnnotationFS anAnnot3 = cas1.createAnnotation(cas1.getAnnotationType(), 8, 13);
      cas1.getIndexRepository().addFS(anAnnot3);
      AnnotationFS anAnnot4 = cas1.createAnnotation(cas1.getAnnotationType(), 15, 30);
      cas1.getIndexRepository().addFS(anAnnot4);
      FSIndex tIndex = cas1.getAnnotationIndex();
      assertTrue(tIndex.size() == 5); //doc annot plus 4 annots
     
      FeatureStructure entityFS = cas1.createFS(entityType);
      cas1.getIndexRepository().addFS(entityFS);
     
      StringArrayFS strArrayFS = cas1.createStringArrayFS(5);
      strArrayFS.set(0, "class1");
      entityFS.setFeatureValue(classesFeat, strArrayFS);
     
      //create listFS and set the link feature
      FeatureStructure emptyNode = cas1.createFS(emptyFsListType);
      FeatureStructure secondNode = cas1.createFS(nonEmptyFsListType);
      secondNode.setFeatureValue(headFeat, anAnnot2);
      secondNode.setFeatureValue(tailFeat, emptyNode);
      FeatureStructure firstNode = cas1.createFS(nonEmptyFsListType);
      firstNode.setFeatureValue(headFeat, anAnnot1);
      firstNode.setFeatureValue(tailFeat, secondNode);
      entityFS.setFeatureValue(linksFeat, firstNode);
     
      // create a view w/o setting document text
      CAS view1 = cas1.createView("View1");
     
      // create another view
      CAS preexistingView = cas1.createView("preexistingView");
      String preexistingViewText = "John Smith blah blah blah";
      preexistingView.setDocumentText(preexistingViewText);
      AnnotationFS person1Annot = createPersonAnnot(preexistingView, 0, 10);
      person1Annot.setStringValue(componentIdFeat, "deltacas1");
      AnnotationFS person2Annot = createPersonAnnot(preexistingView, 0, 5);
      AnnotationFS orgAnnot = preexistingView.createAnnotation(orgType, 16, 24);
      preexistingView.addFsToIndexes(orgAnnot);
     
      AnnotationFS ownerAnnot = preexistingView.createAnnotation(ownerType, 0, 24);
      preexistingView.addFsToIndexes(ownerAnnot);
      FeatureStructure relArgs = cas1.createFS(relArgsType);
      relArgs.setFeatureValue(domainFeat, person1Annot);
      ownerAnnot.setFeatureValue(argsFeat, relArgs);
     
      //serialize complete 
      XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
      String xml = serialize(cas1, sharedData);
      int maxOutgoingXmiId = sharedData.getMaxXmiId();
      //System.out.println("CAS1 " + xml);
      //System.out.println("MaxOutgoingXmiId " + maxOutgoingXmiId);
  
      //deserialize into cas2
      XmiSerializationSharedData sharedData2 = new XmiSerializationSharedData();     
      this.deserialize(xml, cas2, sharedData2, true, -1);
      CasComparer.assertEquals(cas1, cas2);
      //=======================================================================
      //create Marker, add/modify fs and serialize in delta xmi format.
      Marker marker = cas2.createMarker();
      FSIndex cas2tIndex = cas2.getAnnotationIndex();
      CAS cas2preexistingView = cas2.getView("preexistingView");
      FSIndex cas2personIndex = cas2preexistingView.getAnnotationIndex(personType);
      FSIndex cas2orgIndex = cas2preexistingView.getAnnotationIndex(orgType);
      FSIndex cas2ownerIndex = cas2preexistingView.getAnnotationIndex(ownerType);
     
      // create an annotation and add to index
      AnnotationFS cas2anAnnot5 = cas2.createAnnotation(cas2.getAnnotationType(), 6, 8);
      cas2.getIndexRepository().addFS(cas2anAnnot5);
      assertTrue(cas2tIndex.size() == 6); // prev annots and this new one
    
      // set document text of View1
      CAS cas2view1 = cas2.getView("View1");
      cas2view1.setDocumentText("This is the View1 document.");
      //create an annotation in View1
      AnnotationFS cas2view1Annot = cas2view1.createAnnotation(cas2.getAnnotationType(), 1, 5);
      cas2view1.getIndexRepository().addFS(cas2view1Annot);
      FSIndex cas2view1Index = cas2view1.getAnnotationIndex();
      assertTrue(cas2view1Index.size() == 2); //document annot and this annot
     
      //modify an existing annotation
      Iterator<FeatureStructure> tIndexIter = cas2tIndex.iterator();
      AnnotationFS docAnnot = (AnnotationFS) tIndexIter.next(); //doc annot
      AnnotationFS modAnnot1 = (AnnotationFS) tIndexIter.next();
View Full Code Here

        cas1.getIndexRepository().addFS(anAnnot2);
        AnnotationFS anAnnot3 = cas1.createAnnotation(cas1.getAnnotationType(), 8, 13);
        cas1.getIndexRepository().addFS(anAnnot3);
        AnnotationFS anAnnot4 = cas1.createAnnotation(cas1.getAnnotationType(), 15, 30);
        cas1.getIndexRepository().addFS(anAnnot4);
        FSIndex tIndex = cas1.getAnnotationIndex();
        assertTrue(tIndex.size() == 5); //doc annot plus 4 annots
       
        FeatureStructure entityFS = cas1.createFS(entityType);
        cas1.getIndexRepository().addFS(entityFS);
       
        StringArrayFS strArrayFS = cas1.createStringArrayFS(5);
        strArrayFS.set(0, "class1");
        entityFS.setFeatureValue(classesFeat, strArrayFS);
       
        //create listFS and set the link feature
        FeatureStructure emptyNode = cas1.createFS(emptyFsListType);
        FeatureStructure secondNode = cas1.createFS(nonEmptyFsListType);
        secondNode.setFeatureValue(headFeat, anAnnot2);
        secondNode.setFeatureValue(tailFeat, emptyNode);
        FeatureStructure firstNode = cas1.createFS(nonEmptyFsListType);
        firstNode.setFeatureValue(headFeat, anAnnot1);
        firstNode.setFeatureValue(tailFeat, secondNode);
        entityFS.setFeatureValue(linksFeat, firstNode);
       
        // create a view w/o setting document text
        CAS view1 = cas1.createView("View1");
        
        //serialize complete 
        XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
        String xml = serialize(cas1, sharedData);
        int maxOutgoingXmiId = sharedData.getMaxXmiId();
        //System.out.println("CAS1 " + xml);
        //System.out.println("MaxOutgoingXmiId " + maxOutgoingXmiId);
    
        //deserialize into cas2
        XmiSerializationSharedData sharedData2 = new XmiSerializationSharedData();     
        this.deserialize(xml, cas2, sharedData2, true, -1);
        CasComparer.assertEquals(cas1, cas2);
  
        //=======================================================================
        //create Marker, add/modify fs and serialize in delta xmi format.
        Marker marker = cas2.createMarker();
        FSIndex cas2tIndex = cas2.getAnnotationIndex();
       
        // create an annotation and add to index
        AnnotationFS cas2anAnnot5 = cas2.createAnnotation(cas2.getAnnotationType(), 6, 8);
        cas2.getIndexRepository().addFS(cas2anAnnot5);
        assertTrue(cas2tIndex.size() == 6); // prev annots and this new one
        // create an annotation and add to index
        AnnotationFS cas2anAnnot6 = cas2.createAnnotation(cas2.getAnnotationType(), 6, 8);
        cas2.getIndexRepository().addFS(cas2anAnnot6);
        assertTrue(cas2tIndex.size() == 7); // prev annots and twonew one
       
        //add to FSList
        Iterator<FeatureStructure> iter = cas2.getIndexRepository().getIndex("testEntityIndex").iterator();
        FeatureStructure cas2EntityFS = iter.next();
        FeatureStructure cas2linksFS = cas2EntityFS.getFeatureValue(linksFeat);
View Full Code Here

      Assert.assertEquals("EnumType", et.getName());
      Assert.assertEquals(et, f2.getRange());

      // indexes
      FSIndexRepository irep = cas.getIndexRepository();
      FSIndex ind = irep.getIndex("Index1");
      Assert.assertNotNull(ind);
      Assert.assertEquals("Type1", ind.getType().getName());
      Assert.assertEquals(FSIndex.SORTED_INDEX, ind.getIndexingStrategy());

      FeatureStructure fs1 = cas.createFS(t1);
      fs1.setIntValue(f1, 0);
      FeatureStructure fs2 = cas.createFS(t1);
      fs2.setIntValue(f1, 1);
      Assert.assertTrue(ind.compare(fs1, fs2) < 0);

      FSIndex ind2 = irep.getIndex("Index2");
      Assert.assertNotNull(ind2);
      Assert.assertEquals("Type2", ind2.getType().getName());
      Assert.assertEquals(FSIndex.SET_INDEX, ind2.getIndexingStrategy());

      FeatureStructure fs3 = cas.createFS(t2);
      fs3.setStringValue(f2, "One");
      FeatureStructure fs4 = cas.createFS(t2);
      fs4.setStringValue(f2, "Two");
      Assert.assertTrue(ind2.compare(fs3, fs4) > 0);

      FSIndex ind3 = irep.getIndex("Index3");
      Assert.assertNotNull(ind3);
      Assert.assertEquals("uima.tcas.Annotation", ind3.getType().getName());
      Assert.assertEquals(FSIndex.SORTED_INDEX, ind3.getIndexingStrategy());

      AnnotationFS fs5 = cas.createAnnotation(t1, 0, 0);
      AnnotationFS fs6 = cas.createAnnotation(t2, 0, 0);
      AnnotationFS fs7 = cas.createAnnotation(t1, 0, 0);
      Assert.assertTrue(ind3.compare(fs5, fs6) < 0);
      Assert.assertTrue(ind3.compare(fs6, fs7) > 0);

      // only way to check if allowed values is correct is to try to set an
      // invalid value?
      CASRuntimeException ex = null;
      try {
View Full Code Here

      // Test that the annotations are in separate index spaces, and that Sofas are indexed
      JFSIndexRepository indexes = jcas.getJFSIndexRepository();
      // FSIndex sofaIndex = indexes.getIndex(CAS.SOFA_INDEX_NAME);
      indexes = engJcas.getJFSIndexRepository();
      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()));
View Full Code Here

      }
      return;
    }
    // Attempt to find a non-set index first.
    // If none found, then use the an arbitrary set index if any.
    FSIndex setIndex = null;
    final Iterator<String> iter = getLabels();
    while (iter.hasNext()) {
      final String label = iter.next();
      final FSIndex index = getIndex(label);
      // Ignore auto-indexes at this stage, they're handled above.
      if (index.getIndexingStrategy() == FSIndex.DEFAULT_BAG_INDEX) {
        continue;
      }
      if (this.typeSystem.subsumes(index.getType(), type)) {
        if (index.getIndexingStrategy() != FSIndex.SET_INDEX) {
          iteratorList.add(getIndex(label, type).iterator());
          // Done, found non-set index.
          return;
        }
        setIndex = getIndex(label, type);
View Full Code Here

      }
      return;
    }
    // Attempt to find a non-set index first.
    // If none found, then use the an arbitrary set index if any.
    FSIndex setIndex = null;
    final Iterator<String> iter = getLabels();
    while (iter.hasNext()) {
      final String label = iter.next();
      final FSIndex index = getIndex(label);
      // Ignore auto-indexes at this stage, they're handled above.
      if (index.getIndexingStrategy() == FSIndex.DEFAULT_BAG_INDEX) {
        continue;
      }
      if (this.typeSystem.subsumes(index.getType(), type)) {
        if (index.getIndexingStrategy() != FSIndex.SET_INDEX) {
          iteratorList.add(getIndex(label, type).iterator());
          // Done, found non-set index.
          return;
        }
        setIndex = getIndex(label, type);
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.FSIndex

Copyright © 2018 www.massapicom. 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.