Java Code Examples for org.apache.uima.cas.ByteArrayFS#set()
The following examples show how to use
org.apache.uima.cas.ByteArrayFS#set() .
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: SerDesTest6.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testDeltaWithByteArrayMod() { for (int i = 0; i < 10; i++) { TTypeSystem m = getTT(EqTwoTypes); remoteCas = setupCas(m); loadCas(casSrc, mSrc); 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"); if (sfs == null) { // could happen because features are randomly omitted System.out.println(" Abyte feature omitted, retrying"); } else if (sfs.size() == 0) { System.out.println(" Abyte feature array has 0 length, retrying"); } else { sfs.set(0, (byte) 21); verifyDelta(marker, ri); break; } // setRandom(); // retry with different random number setUp(); System.out.println(" testDelta w byte array mod retrying, i = " + i); } }
Example 2
Source File: FSCollectionFactory.java From uima-uimafit with Apache License 2.0 | 5 votes |
public static ByteArrayFS fillArrayFS(ByteArrayFS aArrayFs, Iterable<Byte> aValues) { int i = 0; for (Byte fs : aValues) { aArrayFs.set(i, fs); i++; } return aArrayFs; }
Example 3
Source File: SerDesTest4.java From uima-uimaj with Apache License 2.0 | 5 votes |
private ByteArrayFS randomByteA(Random r) { int length = r.nextInt(2) + 1; ByteArrayFS fs = createByteArrayFS(cas, length); for (int i = 0; i < length; i++) { int bvidx = r.nextInt(byteValues.length); fs.set(i, byteValues[bvidx]); } return fs; }
Example 4
Source File: SerDesTest6.java From uima-uimaj with Apache License 2.0 | 5 votes |
private ByteArrayFS randomByteA(CASImpl cas) { int length = random.nextInt(2) + 1; ByteArrayFS fs = cas.createByteArrayFS(length); for (int i = 0; i < length; i++) { fs.set(i, byteValues[random.nextInt(byteValues.length)]); } return fs; }
Example 5
Source File: SofaTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testSetSofaDataArray() { final String TEST_MIME = "text/plain"; CAS testView = this.cas.createView("TestView"); ByteArrayFS sofaDataArray = testView.createByteArrayFS(2); sofaDataArray.set(0, (byte)0); sofaDataArray.set(1, (byte)42); testView.setSofaDataArray(sofaDataArray, TEST_MIME); assertEquals(sofaDataArray, testView.getSofa().getLocalFSData()); assertEquals(TEST_MIME, testView.getSofa().getSofaMime()); }
Example 6
Source File: SofaTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testSetSofaDataArrayOnInitialView() { final String TEST_MIME = "text/plain"; ByteArrayFS sofaDataArray = this.cas.createByteArrayFS(2); sofaDataArray.set(0, (byte)0); sofaDataArray.set(1, (byte)42); this.cas.setSofaDataArray(sofaDataArray, TEST_MIME); assertEquals(sofaDataArray, this.cas.getSofa().getLocalFSData()); assertEquals(TEST_MIME, this.cas.getSofa().getSofaMime()); }
Example 7
Source File: CasAnnotationViewerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
private void createExampleFS(CAS cas) throws Exception { // Set the document text cas.setDocumentText("this beer is good"); // create an FS of exampleType and index it AnnotationFS fs = cas.createAnnotation(exampleType, 1, 5); cas.getIndexRepository().addFS(fs); // create Array FSs StringArrayFS strArrayFS = cas.createStringArrayFS(5); strArrayFS.set(0, "zzzzzz"); strArrayFS.set(1, "yyyyyy"); strArrayFS.set(2, "xxxxxx"); strArrayFS.set(3, "wwwwww"); strArrayFS.set(4, "vvvvvv"); IntArrayFS intArrayFS = cas.createIntArrayFS(5); intArrayFS.set(0, Integer.MAX_VALUE); intArrayFS.set(1, Integer.MAX_VALUE - 1); intArrayFS.set(2, 42); intArrayFS.set(3, Integer.MIN_VALUE + 1); intArrayFS.set(4, Integer.MIN_VALUE); FloatArrayFS floatArrayFS = cas.createFloatArrayFS(5); floatArrayFS.set(0, Float.MAX_VALUE); floatArrayFS.set(1, (float) (Float.MAX_VALUE / 1000.0)); floatArrayFS.set(2, (float) 42); floatArrayFS.set(3, (float) (Float.MIN_VALUE * 1000.0)); floatArrayFS.set(4, Float.MIN_VALUE); ByteArrayFS byteArrayFS = cas.createByteArrayFS(5); byteArrayFS.set(0, (byte) 8); byteArrayFS.set(1, (byte) 16); byteArrayFS.set(2, (byte) 64); byteArrayFS.set(3, (byte) 128); byteArrayFS.set(4, (byte) 255); BooleanArrayFS boolArrayFS = cas.createBooleanArrayFS(8); boolean val = false; for (int i = 0; i < 8; i++) { boolArrayFS.set(i, val = !val); } ShortArrayFS shortArrayFS = cas.createShortArrayFS(5); shortArrayFS.set(0, Short.MAX_VALUE); shortArrayFS.set(1, (short) (Short.MAX_VALUE - 1)); shortArrayFS.set(2, (short) (Short.MAX_VALUE - 2)); shortArrayFS.set(3, (short) (Short.MAX_VALUE - 3)); shortArrayFS.set(4, (short) (Short.MAX_VALUE - 4)); LongArrayFS longArrayFS = cas.createLongArrayFS(5); longArrayFS.set(0, Long.MAX_VALUE); longArrayFS.set(1, Long.MAX_VALUE - 1); longArrayFS.set(2, Long.MAX_VALUE - 2); longArrayFS.set(3, Long.MAX_VALUE - 3); longArrayFS.set(4, Long.MAX_VALUE - 4); DoubleArrayFS doubleArrayFS = cas.createDoubleArrayFS(5); doubleArrayFS.set(0, Double.MAX_VALUE); doubleArrayFS.set(1, Double.MIN_VALUE); doubleArrayFS.set(2, Double.parseDouble("1.5555")); doubleArrayFS.set(3, Double.parseDouble("99.000000005")); doubleArrayFS.set(4, Double.parseDouble("4.44444444444444444")); // set features of fs fs.setStringValue(stringFeature, "aaaaaaa"); fs.setFloatValue(floatFeature, (float) 99.99); fs.setFeatureValue(intArrayFeature, intArrayFS); fs.setFeatureValue(floatArrayFeature, floatArrayFS); fs.setFeatureValue(stringArrayFeature, strArrayFS); // fs.setByteValue(byteFeature, Byte.MAX_VALUE); fs.setByteValue(byteFeature, (byte) 'z'); fs.setFeatureValue(byteArrayFeature, byteArrayFS); fs.setBooleanValue(booleanFeature, true); fs.setFeatureValue(booleanArrayFeature, boolArrayFS); fs.setShortValue(shortFeature, Short.MIN_VALUE); fs.setFeatureValue(shortArrayFeature, shortArrayFS); fs.setLongValue(longFeature, Long.MIN_VALUE); fs.setFeatureValue(longArrayFeature, longArrayFS); fs.setDoubleValue(doubleFeature, Double.MAX_VALUE); fs.setFeatureValue(doubleArrayFeature, doubleArrayFS); cas.getIndexRepository().addFS(fs); }
Example 8
Source File: SerializationReinitTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** Test basic blob serialization */ public void testBlob() throws Exception { /* * Test that FS, indexes and strings work after repeated blob serialization * For each iteration, add two new FS, serialize and test all created so * The first FS sets the string feature using standard API => goes into stringlist * The second FS sets the string feature using lowlevel API => goes into stringheap * * Throw in tests of the byte, short and long heaps as well * */ String testString = "testString"; cas.reset(); LowLevelCAS ll_cas = cas.getLowLevelCAS(); FSIndexRepository ir = cas.getIndexRepository(); int ll_strfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theStringFeature); int ll_bytefeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theByteFeature); int ll_shortfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theShortFeature); int ll_bytearrayfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theByteArrayFeature); int ll_shortarrayfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theShortArrayFeature); int ll_longfeatcode = ll_cas.ll_getTypeSystem().ll_getCodeForFeature(theLongFeature); for (int cycle = 0; cycle < 10; cycle +=2 ) { FeatureStructure newFS1 = cas.createFS(theTypeType); newFS1.setIntValue(startFeature, cycle); newFS1.setIntValue(endFeature, cycle+1); // set string using normal string feature create newFS1.setStringValue(theStringFeature, testString); newFS1.setByteValue(theByteFeature, (byte)cycle); newFS1.setShortValue(theShortFeature, (short)cycle); newFS1.setLongValue(theLongFeature, (long)cycle); ByteArrayFS newBA1 = cas.createByteArrayFS(1); ShortArrayFS newSA1 = cas.createShortArrayFS(1); newBA1.set(0, (byte)cycle); newSA1.set(0, (short)cycle); newFS1.setFeatureValue(theByteArrayFeature, newBA1); newFS1.setFeatureValue(theShortArrayFeature, newSA1); ir.addFS(newFS1); FeatureStructure newFS2 = cas.createFS(theTypeType); ByteArrayFS newBA2 = cas.createByteArrayFS(1); ShortArrayFS newSA2 = cas.createShortArrayFS(1); newFS2.setIntValue(startFeature, cycle+1); newFS2.setIntValue(endFeature, cycle+2); ir.addFS(newFS2); CASImpl ci = (CASImpl) cas; ci.setId2FSsMaybeUnconditionally(newFS2, newBA2, newSA2); // set string using lowlevel string create API final int llfs2 = ll_cas.ll_getFSRef(newFS2); final int llba2 = ll_cas.ll_getFSRef(newBA2); final int llsa2 = ll_cas.ll_getFSRef(newSA2); ll_cas.ll_setCharBufferValue(llfs2, ll_strfeatcode, testString.toCharArray(), 0, testString.length()); ll_cas.ll_setByteValue(llfs2, ll_bytefeatcode, (byte)(cycle+1)); ll_cas.ll_setShortValue(llfs2, ll_shortfeatcode, (short)(cycle+1)); ll_cas.ll_setLongValue(llfs2, ll_longfeatcode, (long)(cycle+1)); ll_cas.ll_setByteArrayValue(llba2, 0, (byte)(cycle+1)); ll_cas.ll_setShortArrayValue(llsa2, 0, (short)(cycle+1)); newFS2.setFeatureValue(theByteArrayFeature, newBA2); newFS2.setFeatureValue(theShortArrayFeature, newSA2); ir.addFS(newFS2); ByteArrayOutputStream fos = new ByteArrayOutputStream(); Serialization.serializeCAS(cas, fos); cas.reset(); ByteArrayInputStream fis = new ByteArrayInputStream(fos.toByteArray()); Serialization.deserializeCAS(cas, fis); FSIndex<AnnotationFS> idx = cas.getAnnotationIndex(theTypeType); FSIterator<AnnotationFS> iter = idx.iterator(); for (int tc = 0; tc < cycle + 1; tc++) { FeatureStructure testFS = iter.get(); iter.moveToNext(); assertTrue(tc == testFS.getIntValue(startFeature)); assertTrue(testString.equals(testFS.getStringValue(theStringFeature))); assertTrue(tc == testFS.getByteValue(theByteFeature)); assertTrue(tc == testFS.getShortValue(theShortFeature)); assertTrue(tc == testFS.getLongValue(theLongFeature)); ByteArrayFS ba = (ByteArrayFS)testFS.getFeatureValue(theByteArrayFeature); assertTrue(tc == ba.get(0)); ShortArrayFS sa = (ShortArrayFS)testFS.getFeatureValue(theShortArrayFeature); assertTrue(tc == sa.get(0)); } } }
Example 9
Source File: SerializationReinitTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testDeltaBinaryShortLongArrayMods() throws Exception { CASImpl cas2 = (CASImpl) initCAS(); CASImpl cas3 = (CASImpl) initCAS(); // create short array and long array FeatureStructure newFS1 = cas.createFS(theTypeType); ByteArrayFS newBA1 = cas.createByteArrayFS(1); ShortArrayFS newSA1 = cas.createShortArrayFS(1); LongArrayFS newLA1 = cas.createLongArrayFS(1); newBA1.set(0, (byte)1); newSA1.set(0, (short)2); newLA1.set(0, (long)4); newFS1.setFeatureValue(theByteArrayFeature, newBA1); newFS1.setFeatureValue(theShortArrayFeature, newSA1); newFS1.setFeatureValue(theLongArrayFeature, newLA1); cas.getIndexRepository().addFS(newFS1); //serialize binary, non compressed, not delta ByteArrayOutputStream fos = new ByteArrayOutputStream(); Serialization.serializeCAS(cas, fos); //deserialize into cas2 ByteArrayInputStream fis = new ByteArrayInputStream(fos.toByteArray()); Serialization.deserializeCAS(cas2, fis); CasComparer.assertEquals(cas, cas2); //======================================================================= //create Marker, add/modify fs and serialize in delta xmi format. Marker marker = cas2.createMarker(); // modify a value in the int arrays Iterator<AnnotationFS> typeIterator = cas2.getAnnotationIndex(theTypeType).iterator(); assertTrue(typeIterator.hasNext()); FeatureStructure fsWithArrays = typeIterator.next(); ((ByteArrayFS)fsWithArrays.getFeatureValue(theByteArrayFeature)).set(0, (byte) 11); ((ShortArrayFS)fsWithArrays.getFeatureValue(theShortArrayFeature)).set(0, (short) 22); ((LongArrayFS)fsWithArrays.getFeatureValue(theLongArrayFeature)).set(0, (long) 44); // serialize cas2 in delta format ByteArrayOutputStream fosDelta = new ByteArrayOutputStream(); Serialization.serializeCAS(cas2, fosDelta, marker); //====================================================================== //deserialize delta binary into cas1 ByteArrayInputStream fisDelta = new ByteArrayInputStream(fosDelta.toByteArray()); Serialization.deserializeCAS(cas, fisDelta); //====================================================================== //serialize complete cas and deserialize into cas3 and compare with cas1. ByteArrayOutputStream fosFull = new ByteArrayOutputStream(); Serialization.serializeCAS(cas2, fosFull); ByteArrayInputStream fisFull = new ByteArrayInputStream(fosFull.toByteArray()); Serialization.deserializeCAS(cas3, fisFull); CasComparer.assertEquals(cas, cas3); }
Example 10
Source File: NewPrimitiveTypesTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
private FeatureStructure createExampleFS(CAS parmCas) throws Exception { // Create a view CAS englishView = parmCas.createView("EnglishDocument"); // Set the document text englishView.setDocumentText("this beer is good"); // create an FS of exampleType and index it AnnotationFS fs = englishView.createAnnotation(exampleType, 1, 5); // create Array FSs StringArrayFS strArrayFS = parmCas.createStringArrayFS(5); strArrayFS.set(0, "zzzzzz"); strArrayFS.set(1, "yyyyyy"); strArrayFS.set(2, "xxxxxx"); strArrayFS.set(3, "wwwwww"); strArrayFS.set(4, "vvvvvv"); IntArrayFS intArrayFS = parmCas.createIntArrayFS(5); intArrayFS.set(0, Integer.MAX_VALUE); intArrayFS.set(1, Integer.MAX_VALUE - 1); intArrayFS.set(2, 42); intArrayFS.set(3, Integer.MIN_VALUE + 1); intArrayFS.set(4, Integer.MIN_VALUE); FloatArrayFS floatArrayFS = parmCas.createFloatArrayFS(5); floatArrayFS.set(0, Float.MAX_VALUE); floatArrayFS.set(1, (float) (Float.MAX_VALUE / 1000.0)); floatArrayFS.set(2, 42); floatArrayFS.set(3, (float) (Float.MIN_VALUE * 1000.0)); floatArrayFS.set(4, Float.MIN_VALUE); ByteArrayFS byteArrayFS = parmCas.createByteArrayFS(5); byteArrayFS.set(0, (byte) 8); byteArrayFS.set(1, (byte) 16); byteArrayFS.set(2, (byte) 64); byteArrayFS.set(3, (byte) 128); byteArrayFS.set(4, (byte) 255); BooleanArrayFS boolArrayFS = parmCas.createBooleanArrayFS(20); boolean val = false; for (int i = 0; i < 20; i++) { boolArrayFS.set(i, val = !val); } ShortArrayFS shortArrayFS = parmCas.createShortArrayFS(5); shortArrayFS.set(0, Short.MAX_VALUE); shortArrayFS.set(1, (short) (Short.MAX_VALUE - 1)); shortArrayFS.set(2, (short) (Short.MAX_VALUE - 2)); shortArrayFS.set(3, (short) (Short.MAX_VALUE - 3)); shortArrayFS.set(4, (short) (Short.MAX_VALUE - 4)); LongArrayFS longArrayFS = parmCas.createLongArrayFS(5); longArrayFS.set(0, Long.MAX_VALUE); longArrayFS.set(1, Long.MAX_VALUE - 1); longArrayFS.set(2, Long.MAX_VALUE - 2); longArrayFS.set(3, Long.MAX_VALUE - 3); longArrayFS.set(4, Long.MAX_VALUE - 4); DoubleArrayFS doubleArrayFS = parmCas.createDoubleArrayFS(5); doubleArrayFS.set(0, Double.MAX_VALUE); doubleArrayFS.set(1, Double.MIN_VALUE); doubleArrayFS.set(2, Double.parseDouble("1.5555")); doubleArrayFS.set(3, Double.parseDouble("99.000000005")); doubleArrayFS.set(4, Double.parseDouble("4.44444444444444444")); // set features of fs fs.setStringValue(stringFeature, "aaaaaaa"); fs.setFloatValue(floatFeature, (float) 99.99); fs.setFeatureValue(intArrayFeature, intArrayFS); fs.setFeatureValue(floatArrayFeature, floatArrayFS); fs.setFeatureValue(stringArrayFeature, strArrayFS); // fs.setByteValue(byteFeature, Byte.MAX_VALUE); fs.setByteValue(byteFeature, (byte) 'z'); fs.setFeatureValue(byteArrayFeature, byteArrayFS); fs.setBooleanValue(booleanFeature, true); fs.setFeatureValue(booleanArrayFeature, boolArrayFS); fs.setShortValue(shortFeature, Short.MIN_VALUE); fs.setFeatureValue(shortArrayFeature, shortArrayFS); fs.setLongValue(longFeature, Long.MIN_VALUE); fs.setFeatureValue(longArrayFeature, longArrayFS); fs.setDoubleValue(doubleFeature, Double.MAX_VALUE); fs.setFeatureValue(doubleArrayFeature, doubleArrayFS); englishView.getIndexRepository().addFS(fs); return fs; }