Examples of FSIndex


Examples of org.apache.uima.cas.FSIndex

    } catch (CASException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
      assertTrue(false);
    }
    FSIndex jcasSetIndex = jcas.getJFSIndexRepository().getIndex(CASTestSetup.ANNOT_SET_INDEX);
    Annotation jcasAnnotation = (Annotation) jcasSetIndex.find(annot);
    assertNotNull(jcasAnnotation);
    assertNull(jcasSetIndex.find(this.cas.createAnnotation(this.annotationType, -1, -1)));

    // /////////////////////////////////////////////////////////////////////////
    // Test fast fail.

    it = bagIndex.iterator(); // use bag index, remove add last one
View Full Code Here

Examples of org.apache.uima.cas.FSIndex

    // create an annotation and add to index of both views
    AnnotationFS anAnnot = cas.createAnnotation(cas.getAnnotationType(), 0, 5);
    cas.getIndexRepository().addFS(anAnnot);
    cas2.getIndexRepository().addFS(anAnnot);
    FSIndex tIndex = cas.getAnnotationIndex();
    FSIndex t2Index = cas2.getAnnotationIndex();
    assertTrue(tIndex.size() == 2); // document annot and this one
    assertTrue(t2Index.size() == 2); // ditto

    // serialize
    StringWriter sw = new StringWriter();
    XMLSerializer xmlSer = new XMLSerializer(sw, false);
    XCASSerializer xcasSer = new XCASSerializer(cas.getTypeSystem());
    xcasSer.serialize(cas, xmlSer.getContentHandler(), true);
    String xml = sw.getBuffer().toString();

    // deserialize into another CAS (repeat twice to check it still works after reset)
    CAS newCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
    for (int i = 0; i < 2; i++) {
      XCASDeserializer newDeser = new XCASDeserializer(newCas.getTypeSystem());
      ContentHandler newDeserHandler = newDeser.getXCASHandler(newCas);
      SAXParserFactory fact = SAXParserFactory.newInstance();
      SAXParser parser = fact.newSAXParser();
      XMLReader xmlReader = parser.getXMLReader();
      xmlReader.setContentHandler(newDeserHandler);
      xmlReader.parse(new InputSource(new StringReader(xml)));

      // check sofas
      assertEquals("This is a test", newCas.getDocumentText());
      CAS newCas2 = newCas.getView("OtherSofa");
      assertEquals("This is only a test", newCas2.getDocumentText());

      // check that annotation is still indexed in both views
      assertTrue(tIndex.size() == 2); // document annot and this one
      assertTrue(t2Index.size() == 2); // ditto
      newCas.reset();
    }
  }
View Full Code Here

Examples of org.apache.uima.cas.FSIndex

      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

Examples of org.apache.uima.cas.FSIndex

        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

Examples of org.apache.uima.cas.FSIndex

    // prettyPrint
    CAS englishView = cas.getView("EnglishDocument");
    assertNotNull(englishView);
    assertNotNull(englishView.getSofa());
    FSIndex index = englishView.getAnnotationIndex();
    FSIterator iter = index.iterator();
    // skip document annotation
    AnnotationFS fs = (AnnotationFS) iter.get();
    iter.moveToNext();

    // the exampleType fs
View Full Code Here

Examples of org.apache.uima.cas.FSIndex

  private void validateFSData(CAS parmCas) throws Exception {
    CAS englishView = parmCas.getView("EnglishDocument");
    assertNotNull(englishView);
    assertNotNull(englishView.getSofa());
    FSIndex index = englishView.getAnnotationIndex();
    FSIterator iter = index.iterator();
    // skip document annotation
    AnnotationFS fs = (AnnotationFS) iter.get();
    iter.moveToNext();

    // the exampleType fs
View Full Code Here

Examples of org.apache.uima.cas.FSIndex

      r2.addToIndexes();
      r1.addToIndexes();

      JFSIndexRepository jfsi = jcas.getJFSIndexRepository();
      FSIndex fsi1 = jfsi.getIndex("all", Root.type);
      FSIterator fsit1 = fsi1.iterator();
      assertTrue(fsit1.isValid());
      assertTrue(r2 == fsit1.get());
      fsit1.moveToNext();
      assertTrue(fsit1.isValid());
      assertTrue(r1 == fsit1.get());
View Full Code Here

Examples of org.apache.uima.cas.FSIndex

      a1.addToIndexes();
      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();
View Full Code Here

Examples of org.apache.uima.cas.FSIndex

      // create an annotation and add to index of both views
      AnnotationFS anAnnot = cas.createAnnotation(cas.getAnnotationType(), 0, 5);
      cas.getIndexRepository().addFS(anAnnot);
      cas2.getIndexRepository().addFS(anAnnot);
      FSIndex tIndex = cas.getAnnotationIndex();
      FSIndex t2Index = cas2.getAnnotationIndex();
      assertTrue(tIndex.size() == 2); // document annot and this one
      assertTrue(t2Index.size() == 2); // ditto

      // serialize
      StringWriter sw = new StringWriter();
      XMLSerializer xmlSer = new XMLSerializer(sw, false);
      XmiCasSerializer xmiSer = new XmiCasSerializer(cas.getTypeSystem());
      xmiSer.serialize(cas, xmlSer.getContentHandler());
      String xml = sw.getBuffer().toString();

      // deserialize into another CAS (repeat twice to check it still works after reset)
      CAS newCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
              new FsIndexDescription[0]);
      for (int i = 0; i < 2; i++) {
        XmiCasDeserializer newDeser = new XmiCasDeserializer(newCas.getTypeSystem());
        ContentHandler newDeserHandler = newDeser.getXmiCasHandler(newCas);
        SAXParserFactory fact = SAXParserFactory.newInstance();
        SAXParser parser = fact.newSAXParser();
        XMLReader xmlReader = parser.getXMLReader();
        xmlReader.setContentHandler(newDeserHandler);
        xmlReader.parse(new InputSource(new StringReader(xml)));

        // check sofas
        assertEquals("This is a test", newCas.getDocumentText());
        CAS newCas2 = newCas.getView("OtherSofa");
        assertEquals("This is only a test", newCas2.getDocumentText());

        // check that annotation is still indexed in both views
        assertTrue(tIndex.size() == 2); // document annot and this one
        assertTrue(t2Index.size() == 2); // ditto

        newCas.reset();
      }
    } catch (Exception e) {
      JUnitExtension.handleException(e);
View Full Code Here

Examples of org.apache.uima.cas.FSIndex

      assertTrue(cas2.getAnnotationIndex(orgType).size() == 0);
      assertTrue(cas.getAnnotationIndex(orgType).size() > 0);

      // but that some types are still there
      Type personType = cas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Person");
      FSIndex personIndex = cas2.getAnnotationIndex(personType);
      assertTrue(personIndex.size() > 0);

      // check that mentionType has been filtered out (set to null)
      FeatureStructure somePlace = personIndex.iterator().get();
      Feature mentionTypeFeat = personType.getFeatureByBaseName("mentionType");
      assertNotNull(mentionTypeFeat);
      assertNull(somePlace.getStringValue(mentionTypeFeat));
    } catch (Exception e) {
      JUnitExtension.handleException(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.