Java Code Examples for org.apache.uima.cas.LongArrayFS#set()

The following examples show how to use org.apache.uima.cas.LongArrayFS#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: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
public static LongArrayFS fillArrayFS(LongArrayFS aArrayFs, Iterable<Long> aValues) {
  int i = 0;
  for (Long fs : aValues) {
    aArrayFs.set(i, fs);
    i++;
  }
  return aArrayFs;
}
 
Example 2
Source File: SerDesTest4.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void createLongA(FeatureStructure fs, long x) {
  LongArrayFS lafs = createLongArrayFS(cas, 4);
  lafs.set(0, Long.MAX_VALUE - x);
  lafs.set(1, Long.MIN_VALUE + x);
  lafs.set(2, -45 + x);
  fs.setFeatureValue(akofAlong, lafs);
}
 
Example 3
Source File: SerDesTest4.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private LongArrayFS randomLongA(Random r) {
  int length = r.nextInt(2) + 1;
  LongArrayFS fs = createLongArrayFS(cas, length);
  for (int i = 0; i < length; i++) {
    fs.set(i, longValues[r.nextInt(longValues.length)]);
  }
  return fs;
}
 
Example 4
Source File: SerDesTest6.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void createLongA(CASImpl cas, TTypeSystem m, FeatureStructure fs, long x) {
  LongArrayFS lafs = cas.createLongArrayFS(4);
  lafs.set(0, Long.MAX_VALUE - x);
  lafs.set(1, Long.MIN_VALUE + x);
  lafs.set(2, -45 + x);
  maybeSetFeatureKind(fs, m, "Along", lafs);
}
 
Example 5
Source File: SerDesTest6.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private LongArrayFS randomLongA(CASImpl cas) {
  int length = random.nextInt(2) + 1;
  LongArrayFS fs = cas.createLongArrayFS(length);
  for (int i = 0; i < length; i++) {
    fs.set(i, longValues[random.nextInt(longValues.length)]);
  }
  return fs;
}
 
Example 6
Source File: CasAnnotationViewerTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
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 7
Source File: SerDesTest4.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void testArrayAux() {
  ArrayList<FeatureStructure> fsl = new ArrayList<>();
  /**
   * Strings, non-array Long/Double:
   * Make equal items,
   * ser/deser, update one of the equal items, insure other not updated
   */
  FeatureStructure fsAt1 = newAkof(fsl);
  FeatureStructure fsAt2 = newAkof(fsl);
  cas.addFsToIndexes(fsAt1);
  cas.addFsToIndexes(fsAt2);

  createStringA(fsAt1, "at");
  createStringA(fsAt2, "at");
  verify("ArrayAuxStrings");

  FSIterator<FeatureStructure> it = deserCas.indexRepository.getAllIndexedFS(akof);
  FeatureStructure fsAt1d = it.next();
  FeatureStructure fsAt2d = it.next();
  StringArrayFS sa1 = (StringArrayFS) fsAt1d.getFeatureValue(akofAstring);
  StringArrayFS sa2 = (StringArrayFS) fsAt2d.getFeatureValue(akofAstring);
  sa1.set(1, "def");
  assertEquals(sa2.get(1), "abcat");
  assertEquals(sa1.get(1), "def");
  cas.reset();

  fsAt1 = newAkof(fsl);
  fsAt2 = newAkof(fsl);
  cas.addFsToIndexes(fsAt1);
  cas.addFsToIndexes(fsAt2);

  createLongA(fsAt1, 9);
  createLongA(fsAt2, 9);
  verify("ArrayAuxLongs");

  it = deserCas.indexRepository.getAllIndexedFS(akof);
  fsAt1d = it.next();
  fsAt2d = it.next();
  LongArrayFS la1 = (LongArrayFS) fsAt1d.getFeatureValue(akofAlong);
  LongArrayFS la2 = (LongArrayFS) fsAt2d.getFeatureValue(akofAlong);
  la1.set(2, 123L);
  assertEquals(la2.get(2), -45 + 9);
  assertEquals(la1.get(2), 123);
}
 
Example 8
Source File: SerDesTest6.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void testArrayAux() {
  ArrayList<FeatureStructure> fsList = new ArrayList<>();
  /**
   * Strings, non-array Long/Double:
   * Make equal items,
   * ser/deser, update one of the equal items, insure other not updated
   */
  FeatureStructure fsAt1 = newAkof(casSrc, mSrc, Akof1, fsList);
  FeatureStructure fsAt2 = newAkof(casSrc, mSrc, Akof1, fsList);
  casSrc.addFsToIndexes(fsAt1);
  casSrc.addFsToIndexes(fsAt2);

  createStringA(casSrc, mSrc, fsAt1, "at");
  createStringA(casSrc, mSrc, fsAt2, "at");
  TTypeSystem m = getTT(EqTwoTypes);
  remoteCas = setupCas(m);
  verify(remoteCas, "ArrayAuxString");

  FSIterator<FeatureStructure> it = remoteCas.indexRepository.getAllIndexedFS(m.getType(Akof1));
  FeatureStructure fsAt1d = it.next();
  FeatureStructure fsAt2d = it.next();
  StringArrayFS sa1 = (StringArrayFS) maybeGetFeatureKind(fsAt1d, m, "Astring");
  StringArrayFS sa2 = (StringArrayFS) maybeGetFeatureKind(fsAt2d, m, "Astring");
  sa1.set(1, "def");
  assertEquals(sa2.get(1), "abcat");
  assertEquals(sa1.get(1), "def");

  casSrc.reset();

  fsAt1 = newAkof(casSrc, mSrc, Akof1, fsList);
  fsAt2 = newAkof(casSrc, mSrc, Akof1, fsList);
  casSrc.addFsToIndexes(fsAt1);
  casSrc.addFsToIndexes(fsAt2);

  createLongA(casSrc, mSrc, fsAt1, 9);
  createLongA(casSrc, mSrc, fsAt2, 9);
  remoteCas.reset();
  verify(remoteCas, "ArrayAuxLong");

  it = remoteCas.indexRepository.getAllIndexedFS(m.getType(Akof1));
  fsAt1d = it.next();
  fsAt2d = it.next();
  LongArrayFS la1 = (LongArrayFS) maybeGetFeatureKind(fsAt1d, m, "Along");
  LongArrayFS la2 = (LongArrayFS) maybeGetFeatureKind(fsAt2d, m, "Along");
  la1.set(2, 123L);
  assertEquals(la2.get(2), -45 + 9);
  assertEquals(la1.get(2), 123);
}
 
Example 9
Source File: SerializationReinitTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
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 vote down vote up
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;
}