Java Code Examples for org.apache.uima.cas.CAS#createMarker()
The following examples show how to use
org.apache.uima.cas.CAS#createMarker() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmiCasDeserializerTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testDeltaCasIndexing() throws Exception { try { CAS cas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); cas1.setDocumentText("This is a test document in the initial view"); FSIndexRepositoryImpl ir1 = (FSIndexRepositoryImpl) cas1.getIndexRepository(); AnnotationFS anAnnotBefore = cas1.createAnnotation(cas1.getAnnotationType(), 0, 2); ir1.addFS(anAnnotBefore); cas1.createMarker(); // will start journaling index updates AnnotationFS anAnnot1 = cas1.createAnnotation(cas1.getAnnotationType(), 0, 4); ir1.addFS(anAnnot1); ir1.removeFS(anAnnot1); ir1.addFS(anAnnot1); assertTrue(ir1.getAddedFSs().size() == 1); assertTrue(ir1.getDeletedFSs().size() == 0); assertTrue(ir1.getReindexedFSs().size() == 0); ir1.removeFS(anAnnotBefore); ir1.addFS(anAnnotBefore); assertTrue(ir1.getAddedFSs().size() == 1); assertTrue(ir1.getDeletedFSs().size() == 0); assertTrue(ir1.getReindexedFSs().size() == 1); ir1.removeFS(anAnnotBefore); assertTrue(ir1.getAddedFSs().size() == 1); assertTrue(ir1.getDeletedFSs().size() == 1); assertTrue(ir1.getReindexedFSs().size() == 0); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example 2
Source File: XmiCasDeserializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testDeltaCasIndexExistingFsInView() throws Exception { CAS cas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); cas1.setDocumentText("This is a test document in the initial view"); Type referentType = cas1.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent"); FeatureStructure fs1 = cas1.createFS(referentType); cas1.getIndexRepository().addFS(fs1); //serialize complete XmiSerializationSharedData sharedData = new XmiSerializationSharedData(); String xml = serialize(cas1, sharedData); // System.out.println(xml); 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(); //create View CAS view = cas2.createView("NewView"); //add FS to index Type referentType2 = cas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent"); Iterator<FeatureStructure> fsIter = cas2.getIndexRepository().getAllIndexedFS(referentType2); while (fsIter.hasNext()) { FeatureStructure fs = fsIter.next(); view.getIndexRepository().addFS(fs); } AnnotationFS cas2newAnnot = view.createAnnotation(cas2.getAnnotationType(), 6, 8); view.getIndexRepository().addFS(cas2newAnnot); // serialize cas2 in delta format String deltaxml1 = serialize(cas2, sharedData2, marker); // System.out.println(deltaxml1); //deserialize delta xmi into cas1 this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.allow); //check that new View contains the FS CAS deserView = cas1.getView("NewView"); Iterator<FeatureStructure> deserFsIter = deserView.getIndexRepository().getAllIndexedFS(referentType); assertTrue(deserFsIter.hasNext()); }
Example 3
Source File: XmiCasDeserializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testDeltaCasIndexExistingFsInInitialView() throws Exception { CAS cas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); // no sofa // cas1.setDocumentText("This is a test document in the initial view"); Type referentType = cas1.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent"); FeatureStructure fs1 = cas1.createFS(referentType); cas1.getIndexRepository().addFS(fs1); // index in initial view //serialize complete XmiSerializationSharedData sharedData = new XmiSerializationSharedData(); String xml = serialize(cas1, sharedData); // System.out.println(xml); 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(); //create View CAS view = cas2.createView("NewView"); //add FS to index Type referentType2 = cas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent"); Iterator<FeatureStructure> fsIter = cas2.getIndexRepository().getAllIndexedFS(referentType2); while (fsIter.hasNext()) { FeatureStructure fs = fsIter.next(); view.getIndexRepository().addFS(fs); } AnnotationFS cas2newAnnot = view.createAnnotation(cas2.getAnnotationType(), 6, 8); view.getIndexRepository().addFS(cas2newAnnot); // add fs to initial view index repo. fs1 = cas2.createFS(referentType); cas2.getIndexRepository().addFS(fs1); // serialize cas2 in delta format String deltaxml1 = serialize(cas2, sharedData2, marker); // System.out.println(deltaxml1); //deserialize delta xmi into cas1 this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.allow); //check that new View contains the FS CAS deserView = cas1.getView("NewView"); Iterator<FeatureStructure> deserFsIter = deserView.getIndexRepository().getAllIndexedFS(referentType); assertTrue(deserFsIter.hasNext()); }
Example 4
Source File: XmiCasDeserializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testDeltaCasIndexExistingFsInNewView() throws Exception { CAS cas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); cas1.setDocumentText("This is a test document in the initial view"); Type referentType = cas1.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent"); FeatureStructure fs1 = cas1.createFS(referentType); cas1.getIndexRepository().addFS(fs1); //serialize complete XmiSerializationSharedData sharedData = new XmiSerializationSharedData(); String xml = serialize(cas1, sharedData); // System.out.println(xml); 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(); //create View CAS view = cas2.createView("NewView"); //add FS to index Type referentType2 = cas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Referent"); Iterator<FeatureStructure> fsIter = cas2.getIndexRepository().getAllIndexedFS(referentType2); while (fsIter.hasNext()) { FeatureStructure fs = fsIter.next(); view.getIndexRepository().addFS(fs); } AnnotationFS cas2newAnnot = view.createAnnotation(cas2.getAnnotationType(), 6, 8); view.getIndexRepository().addFS(cas2newAnnot); // serialize cas2 in delta format String deltaxml1 = serialize(cas2, sharedData2, marker); // System.out.println(deltaxml1); //deserialize delta xmi into cas1 this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.allow); //check that new View contains the FS CAS deserView = cas1.getView("NewView"); Iterator<FeatureStructure> deserFsIter = deserView.getIndexRepository().getAllIndexedFS(referentType); assertTrue(deserFsIter.hasNext()); }
Example 5
Source File: XmiCasDeserializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testDeltaCasIgnorePreexistingFS() throws Exception { try { CAS cas1 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); TypeSystem ts = cas1.getTypeSystem(); CAS cas2 = CasCreationUtils.createCas(ts, new TypePriorities_impl(), indexes, null); 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<AnnotationFS> 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<AnnotationFS> 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); //modify language feature Feature languageF2 = cas2.getDocumentAnnotation().getType().getFeatureByBaseName(CAS.FEATURE_BASE_NAME_LANGUAGE); docAnnot.setStringValue(languageF2, "en"); // serialize cas2 in delta format String deltaxml1 = serialize(cas2, sharedData2, marker); //System.out.println("delta cas"); //System.out.println(deltaxml1); //deserialize delta xmi into cas1 this.deserialize(deltaxml1, cas1, sharedData, true, maxOutgoingXmiId, AllowPreexistingFS.ignore); //check language feature of doc annot is not changed. //System.out.println(cas1.getDocumentAnnotation().getStringValue(languageF)); Feature languageF1 = cas1.getDocumentAnnotation().getType().getFeatureByBaseName(CAS.FEATURE_BASE_NAME_LANGUAGE); assertTrue( cas1.getAnnotationIndex().iterator().next().getStringValue(languageF1).equals("x-unspecified")); //check new annotation exists and preexisting is not deleted assertTrue(cas1.getAnnotationIndex().size()==4); } catch (Exception e) { JUnitExtension.handleException(e); } }