Package org.apache.uima.cas

Examples of org.apache.uima.cas.FeatureStructure


      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();
      AnnotationFS delAnnot = (AnnotationFStIndexIter.next();
     
      //modify language feature
      Feature languageF = cas2.getDocumentAnnotation().getType().getFeatureByBaseName(CAS.FEATURE_BASE_NAME_LANGUAGE);
      docAnnot.setStringValue(languageF, "en");
     
      //index update - reindex
      cas2.getIndexRepository().removeFS(modAnnot1);
      Feature endF = cas2.getAnnotationType().getFeatureByBaseName(CAS.FEATURE_BASE_NAME_END);
      modAnnot1.setIntValue(endF, 4);
      cas2.getIndexRepository().addFS(modAnnot1);
      //index update - remove annotation from index
      cas2.getIndexRepository().removeFS(delAnnot);
     
      //modify FS - string feature and FS feature.
      Iterator<FeatureStructure> personIter = cas2personIndex.iterator();    
      AnnotationFS cas2person1 = (AnnotationFS) personIter.next();
      AnnotationFS cas2person2 = (AnnotationFS) personIter.next();
     
      cas2person1.setFloatValue(confidenceFeat, (float) 99.99);
      cas2person1.setStringValue(mentionTypeFeat, "FULLNAME");
     
      cas2person2.setStringValue(componentIdFeat, "delataCas2");
      cas2person2.setStringValue(mentionTypeFeat, "FIRSTNAME");
     
      Iterator<FeatureStructure> orgIter = cas2orgIndex.iterator();
      AnnotationFS cas2orgAnnot = (AnnotationFS) orgIter.next();
      cas2orgAnnot.setStringValue(mentionTypeFeat, "ORGNAME");
     
      //modify FS feature
      Iterator<FeatureStructure> ownerIter = cas2ownerIndex.iterator();
      AnnotationFS cas2ownerAnnot = (AnnotationFS) ownerIter.next();
      FeatureStructure cas2relArgs = cas2ownerAnnot.getFeatureValue(argsFeat);
      cas2relArgs.setFeatureValue(rangeFeat, cas2orgAnnot);
     
    //Test modification of a nonshared multivalued feature.
      //This should serialize the encompassing FS.
      Iterator<FeatureStructure> iter = cas2.getIndexRepository().getIndex("testEntityIndex").iterator();
      FeatureStructure cas2EntityFS = (FeatureStructure) iter.next();
      StringArrayFS cas2strarrayFS = (StringArrayFS) cas2EntityFS.getFeatureValue(classesFeat);
      cas2strarrayFS.set(1, "class2");
      cas2strarrayFS.set(2, "class3");
      cas2strarrayFS.set(3, "class4");
      cas2strarrayFS.set(4, "class5");
     
      //add to FSList
      FeatureStructure cas2linksFS = cas2EntityFS.getFeatureValue(linksFeat);
      FeatureStructure cas2secondNode = cas2linksFS.getFeatureValue(tailFeat);
      FeatureStructure cas2emptyNode = cas2secondNode.getFeatureValue(tailFeat);
      FeatureStructure cas2thirdNode = cas2.createFS(nonEmptyFsListType);
      cas2thirdNode.setFeatureValue(headFeat, cas2anAnnot5);
      cas2thirdNode.setFeatureValue(tailFeat, cas2emptyNode);
      cas2secondNode.setFeatureValue(tailFeat, cas2thirdNode);
     
//      // Test that the new access method returns an array containing just the right marker
      // removed per https://issues.apache.org/jira/browse/UIMA-2478
//      List<Marker> mkrs = cas2.getMarkers();
View Full Code Here


        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);
        FeatureStructure cas2secondNode = cas2linksFS.getFeatureValue(tailFeat);
        FeatureStructure cas2emptyNode = cas2secondNode.getFeatureValue(tailFeat);
        FeatureStructure cas2thirdNode = cas2.createFS(nonEmptyFsListType);
        FeatureStructure cas2fourthNode = cas2.createFS(nonEmptyFsListType);
       
        cas2secondNode.setFeatureValue(tailFeat, cas2thirdNode);
        cas2thirdNode.setFeatureValue(headFeat, cas2anAnnot5);
        cas2thirdNode.setFeatureValue(tailFeat, cas2fourthNode);
        cas2fourthNode.setFeatureValue(headFeat, cas2anAnnot6);
        cas2fourthNode.setFeatureValue(tailFeat, cas2emptyNode);
       
        // serialize cas2 in delta format
        String deltaxml1 = serialize(cas2, sharedData2, marker);
        //System.out.println("delta cas");
        //System.out.println(deltaxml1);
View Full Code Here

    XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
    deserialize(xmiStr, partialTsCas, sharedData, true, -1);
   
    //check out of type system data
    Type testAnnotType2 = partialTsCas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation");
    FeatureStructure testAnnot2 = partialTsCas.getAnnotationIndex(testAnnotType2).iterator().get();
    Feature arrayFeat2 = testAnnotType2.getFeatureByBaseName("arrayFeat");
    FeatureStructure arrayFs2 = testAnnot2.getFeatureValue(arrayFeat2);
    List ootsElems = sharedData.getOutOfTypeSystemElements();
    assertEquals(2, ootsElems.size());
    List ootsArrayElems = sharedData.getOutOfTypeSystemArrayElements(arrayFs2.hashCode());
    assertEquals(2, ootsArrayElems.size());
    for (int i = 0; i < 2; i++) {
      OotsElementData oed = (OotsElementData)ootsElems.get(i);
      XmiArrayElement arel = (XmiArrayElement)ootsArrayElems.get(i);
      assertEquals(oed.xmiId, arel.xmiId);     
View Full Code Here

    cas.addFsToIndexes(testAnnot);
    Type nonEmptyFsListType = cas.getTypeSystem().getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
    Type emptyFsListType = cas.getTypeSystem().getType(CAS.TYPE_NAME_EMPTY_FS_LIST);
    Feature headFeat = nonEmptyFsListType.getFeatureByBaseName("head");
    Feature tailFeat = nonEmptyFsListType.getFeatureByBaseName("tail");
    FeatureStructure emptyNode = cas.createFS(emptyFsListType);
    FeatureStructure secondNode = cas.createFS(nonEmptyFsListType);
    secondNode.setFeatureValue(headFeat, orgAnnot2);
    secondNode.setFeatureValue(tailFeat, emptyNode);
    FeatureStructure firstNode = cas.createFS(nonEmptyFsListType);
    firstNode.setFeatureValue(headFeat, orgAnnot1);
    firstNode.setFeatureValue(tailFeat, secondNode);
   
    Feature listFeat = testAnnotType.getFeatureByBaseName("listFeat");
    testAnnot.setFeatureValue(listFeat, firstNode);
   
    //serialize to XMI
    String xmiStr = serialize(cas, null);
//    System.out.println(xmiStr);
   
    //deserialize into a CAS that's missing the Organization type
    File partialTypeSystemFile = JUnitExtension.getFile("ExampleCas/partialTestTypeSystem.xml");
    TypeSystemDescription partialTypeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
            new XMLInputSource(partialTypeSystemFile));
    testAnnotTypeDesc = partialTypeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation");
    testAnnotTypeDesc.addFeature("listFeat", "", "uima.cas.FSList");
    CAS partialTsCas = CasCreationUtils.createCas(partialTypeSystem, null, null);
    XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
    deserialize(xmiStr, partialTsCas, sharedData, true, -1);
   
    //check out of type system data
    Type testAnnotType2 = partialTsCas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation");
    FeatureStructure testAnnot2 = partialTsCas.getAnnotationIndex(testAnnotType2).iterator().get();
    Feature listFeat2 = testAnnotType2.getFeatureByBaseName("listFeat");
    FeatureStructure listFs = testAnnot2.getFeatureValue(listFeat2);
    List ootsElems = sharedData.getOutOfTypeSystemElements();
    assertEquals(2, ootsElems.size());
    OotsElementData oed = sharedData.getOutOfTypeSystemFeatures(listFs.hashCode());
    XmlAttribute attr = (XmlAttribute)oed.attributes.get(0);
    assertNotNull(attr);
    assertEquals(CAS.FEATURE_BASE_NAME_HEAD, attr.name);
    assertEquals(attr.value, ((OotsElementData)ootsElems.get(0)).xmiId);
   
View Full Code Here

    remoteCas = setupCas(m);
   
    TTypeSystem mSrc = getTT(TwoTypes);
    makeFeaturesForAkof(casSrc, mSrc, Akof1);
   
    FeatureStructure otherTsFs = casSrc.createFS(mSrc.getType(Akof2));
    FeatureStructure fsOrig = lfs.get(0);
    fsOrig.setFeatureValue(mSrc.getFeature(fsOrig, "Fs"), otherTsFs);
   
    FeatureStructure ts1Fs = casSrc.createFS(mSrc.getType(Akof1));
    otherTsFs.setFeatureValue(mSrc.getFeature(otherTsFs, "Fs"), ts1Fs);
   
    if (indexed) {
      casSrc.addFsToIndexes(ts1Fs);
    }
View Full Code Here

    remoteCas = setupCas(m);
    loadCas(casSrc, mSrc);
    ReuseInfo[] ri = serializeDeserialize(casSrc, remoteCas, null, null);
    MarkerImpl marker = (MarkerImpl) remoteCas.createMarker();
    lfs = getIndexedFSs(remoteCas, m);
    FeatureStructure fs = lfs.get(10);
    StringArrayFS sa = (StringArrayFS) maybeGetFeatureKind(fs, m, "Astring");
    sa.set(0, "change2");
    verifyDelta(marker, ri);
  }
View Full Code Here

    remoteCas = setupCas(m);
    loadCas(casSrc, mSrc);
    ReuseInfo[] ri = serializeDeserialize(casSrc, remoteCas, null, null);
    MarkerImpl marker = (MarkerImpl) remoteCas.createMarker();
    lfs = getIndexedFSs(remoteCas, m);
    FeatureStructure fs = lfs.get(10)/* has double array length 2 */
    DoubleArrayFS d = (DoubleArrayFS) maybeGetFeatureKind(fs, m, "Adouble");
    d.set(0, 12.34D);
    verifyDelta(marker, ri);
  }
View Full Code Here

    ReuseInfo[] ri = serializeDeserialize(casSrc, remoteCas, null, null);
    MarkerImpl marker = (MarkerImpl) remoteCas.createMarker();
   
    lfs = getIndexedFSs(remoteCas, m); // gets FSs below the line

    FeatureStructure fs = lfs.get(10);
    ByteArrayFS sfs = (ByteArrayFS) maybeGetFeatureKind(fs, m, "Abyte");
    sfs.set(0, (byte)21);

    verifyDelta(marker, ri);
  }
View Full Code Here

    ReuseInfo[] ri = serializeDeserialize(casSrc, remoteCas, null, null);
    MarkerImpl marker = (MarkerImpl) remoteCas.createMarker();
   
    lfs = getIndexedFSs(remoteCas, m);

    FeatureStructure fs = lfs.get(10);
    StringArrayFS sfs = (StringArrayFS) maybeGetFeatureKind(fs, m, "Astring");
    if (sfs != null) {
      sfs.set(0, "change");
    }
View Full Code Here

    loadCas(casSrc, mSrc);
    ReuseInfo ri[] = serializeDeserialize(casSrc, remoteCas, null, null);
    MarkerImpl marker = (MarkerImpl) remoteCas.createMarker();
   
    lfs = getIndexedFSs(remoteCas, m);
    FeatureStructure fs = remoteCas.createFS(m.getType(Akof1));
    maybeSetFeature(fs, m, lfs.get(0));
    ArrayFS fsafs = remoteCas.createArrayFS(4);
    fsafs.set(1, lfs.get(1));
    fsafs.set(2, lfs.get(2));
    fsafs.set(3, lfs.get(3));
View Full Code Here

TOP

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

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.