Package org.apache.uima.cas

Examples of org.apache.uima.cas.ByteArrayFS


    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);
View Full Code Here


    // 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);

    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);
    // 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);

    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));
    }
    } 
  }
View Full Code Here

    if (arrayFS instanceof BooleanArrayFS) {
      BooleanArrayFS array = (BooleanArrayFS) arrayFS;
      array.set(slot, Boolean.parseBoolean(value));
    } else if (arrayFS instanceof ByteArrayFS) {
      ByteArrayFS array = (ByteArrayFS) arrayFS;
      array.set(slot, Byte.parseByte(value));
    } else if (arrayFS instanceof ShortArrayFS) {
      ShortArrayFS array = (ShortArrayFS) arrayFS;
      array.set(slot, Short.parseShort(value));
    } else if (arrayFS instanceof IntArrayFS) {
      IntArrayFS array = (IntArrayFS) arrayFS;
      array.set(slot, Integer.parseInt(value));
    } else if (arrayFS instanceof LongArrayFS) {
      LongArrayFS array = (LongArrayFS) arrayFS;
      array.set(slot, Long.parseLong(value));
    } else if (arrayFS instanceof FloatArrayFS) {
      FloatArrayFS array = (FloatArrayFS) arrayFS;
      array.set(slot, Float.parseFloat(value));
    } else if (arrayFS instanceof DoubleArrayFS) {
      DoubleArrayFS array = (DoubleArrayFS) arrayFS;
      array.set(slot, Double.parseDouble(value));
    } else if (arrayFS instanceof StringArrayFS) {
      StringArrayFS array = (StringArrayFS) arrayFS;
      array.set(slot, value);
    } else {
      throw new CasEditorError("Unkown array type!");
    }
  }
View Full Code Here

    if (arrayFS instanceof BooleanArrayFS) {
      BooleanArrayFS array = (BooleanArrayFS) arrayFS;
      return array.get(slot);
    } else if (arrayFS instanceof ByteArrayFS) {
      ByteArrayFS array = (ByteArrayFS) arrayFS;
      return array.get(slot);
    } else if (arrayFS instanceof ShortArrayFS) {
      ShortArrayFS array = (ShortArrayFS) arrayFS;
      return array.get(slot);
    } else if (arrayFS instanceof IntArrayFS) {
      IntArrayFS array = (IntArrayFS) arrayFS;
      return array.get(slot);
    } else if (arrayFS instanceof LongArrayFS) {
      LongArrayFS array = (LongArrayFS) arrayFS;
      return array.get(slot);
    } else if (arrayFS instanceof FloatArrayFS) {
      FloatArrayFS array = (FloatArrayFS) arrayFS;
      return array.get(slot);
    } else if (arrayFS instanceof DoubleArrayFS) {
      DoubleArrayFS array = (DoubleArrayFS) arrayFS;
      return array.get(slot);
    } else if (arrayFS instanceof StringArrayFS) {
      StringArrayFS array = (StringArrayFS) arrayFS;

      String value = array.get(slot);

      if (value == null) {
        value = "";
      }

      return value;
    } else if (arrayFS instanceof ArrayFS) {
      ArrayFS array = (ArrayFS) arrayFS;
      return array.get(slot);
    } else {
      throw new CasEditorError("Unkown array type!");
    }
  }
View Full Code Here

    assertTrue(floatArrayFS.get(1) == (float) (Float.MAX_VALUE / 1000.0));
    assertTrue(floatArrayFS.get(2) == 42);
    assertTrue(floatArrayFS.get(3) == (float) (Float.MIN_VALUE * 1000.0));
    assertTrue(floatArrayFS.get(4) == Float.MIN_VALUE);

    ByteArrayFS byteArrayFS = (ByteArrayFS) fs.getFeatureValue(byteArrayFeature);
    assertTrue(byteArrayFS.get(0) == (byte) 8);
    assertTrue(byteArrayFS.get(1) == (byte) 16);
    assertTrue(byteArrayFS.get(2) == (byte) 64);
    assertTrue(byteArrayFS.get(3) == (byte) 128);
    assertTrue(byteArrayFS.get(4) == (byte) 255);

    BooleanArrayFS boolArrayFS = (BooleanArrayFS) fs.getFeatureValue(booleanArrayFeature);
    assertTrue(boolArrayFS.get(0));
    assertTrue(!boolArrayFS.get(1));
    assertTrue(boolArrayFS.get(2));
View Full Code Here

    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);
View Full Code Here

      // shortarraySofaFS.setLocalSofaData(shortArrayFS);
      CAS shortArrayView =this.cas.createView("shortArraySofaData");
      shortArrayView.setSofaDataArray(shortArrayFS, "shorts");

      // create a byte array fs
      ByteArrayFS byteArrayFS =this.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);
      // create a Sofa and set the SofaArray feature.
      // id = new SofaID_impl();
      // id.setSofaID("byteArraySofaData");
      // SofaFS bytearraySofaFS = cas.createSofa(id, "text");
      // bytearraySofaFS.setLocalSofaData(byteArrayFS);
      CAS byteArrayView =this.cas.createView("byteArraySofaData");
      byteArrayView.setSofaDataArray(byteArrayFS, "bytes");

      // create a long array fs
      LongArrayFS longArrayFS =this.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);
      // create a Sofa and set the SofaArray feature.
      // id = new SofaID_impl();
      // id.setSofaID("longArraySofaData");
      // SofaFS longarraySofaFS = cas.createSofa(id, "text");
      // longarraySofaFS.setLocalSofaData(longArrayFS);
      CAS longArrayView =this.cas.createView("longArraySofaData");
      longArrayView.setSofaDataArray(longArrayFS, "longs");

      DoubleArrayFS doubleArrayFS =this.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"));
      // create a Sofa and set the SofaArray feature.
      // id = new SofaID_impl();
      // id.setSofaID("doubleArraySofaData");
      // SofaFS doublearraySofaFS = cas.createSofa(id, "text");
      // doublearraySofaFS.setLocalSofaData(doubleArrayFS);
      CAS doubleArrayView =this.cas.createView("doubleArraySofaData");
      doubleArrayView.setSofaDataArray(doubleArrayFS, "doubles");

      // create remote sofa and set the SofaURI feature
      // id = new SofaID_impl();
      // id.setSofaID("remoteSofaData");
      // SofaFS remoteSofa = cas.createSofa(id, "text");
      // remoteSofa.setRemoteSofaURI("file:.\\Sofa.xcas");
      CAS remoteView =this.cas.createView("remoteSofaData");
      String sofaFileName = "./Sofa.xcas";
      remoteView.setSofaDataURI("file:" + sofaFileName, "text");

      // read sofa data
      // InputStream is = strSofa.getSofaDataStream();
      InputStream is = stringView.getSofaDataStream();
      assertTrue(is != null);
      byte[] dest = new byte[1];
      StringBuffer buf = new StringBuffer();
      while (is.read(dest) != -1) {
        buf.append((char) dest[0]);
      }
      assertTrue(buf.toString().equals("this beer is good"));

      dest = new byte[4];
      // is = intarraySofaFS.getSofaDataStream();
      is.close();
      is = intArrayView.getSofaDataStream();
      assertTrue(is != null);
      int i = 0;
      while (is.read(dest) != -1) {
        assertTrue(ByteBuffer.wrap(dest).getInt() == intArrayFS.get(i++));
      }

      // is = floatarraySofaFS.getSofaDataStream();
      is.close();
      is = floatArrayView.getSofaDataStream();
      assertTrue(is != null);
      i = 0;
      while (is.read(dest) != -1) {
        assertTrue(ByteBuffer.wrap(dest).getFloat() == floatArrayFS.get(i++));
      }

      dest = new byte[2];
      // is = shortarraySofaFS.getSofaDataStream();
      is.close();
      is = shortArrayView.getSofaDataStream();
      assertTrue(is != null);
      i = 0;
      while (is.read(dest) != -1) {
        assertTrue(ByteBuffer.wrap(dest).getShort() == shortArrayFS.get(i++));
      }

      dest = new byte[1];
      // is = bytearraySofaFS.getSofaDataStream();
      is.close();
      is = byteArrayView.getSofaDataStream();
      assertTrue(is != null);
      i = 0;
      while (is.read(dest) != -1) {
        assertTrue(ByteBuffer.wrap(dest).get() == byteArrayFS.get(i++));
      }

      dest = new byte[8];
      // is = longarraySofaFS.getSofaDataStream();
      is.close();
View Full Code Here

  }
 
  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());
  }
View Full Code Here

    assertEquals(TEST_MIME, testView.getSofa().getSofaMime());
  }
 
  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());
  }
View Full Code Here

     *          a Delta CAS.
     * @return a reference to the Feature Structure in the CAS
     */
    private int createByteArray(String hexString, int xmiId, int addr) {
      int arrayLen = hexString.length() / 2;
      ByteArrayFS fs = null;
     
      if (addr > 0) {   //non-shared and fs exists
      fs = (ByteArrayFS) casBeingFilled.createFS(addr);
        if (fs.size() != arrayLen) {  //if length changes, create newFS
          fs = casBeingFilled.createByteArrayFS(arrayLen);
        }
      } else if (xmiId == -1) { //non-shared and no fs
      fs = casBeingFilled.createByteArrayFS(arrayLen);
      } else  {       //shared
      if (isNewFS(xmiId)) {
        fs = casBeingFilled.createByteArrayFS(arrayLen);
      } else {
        addr = getFsAddrForXmiId(xmiId);
        fs = (ByteArrayFS) casBeingFilled.createFS(addr);
        if (fs.size() != arrayLen) {
          fs = casBeingFilled.createByteArrayFS(arrayLen);
        }
      }
      }
     
      for (int i = 0; i < arrayLen; i++) {
        byte high = hexCharToByte(hexString.charAt(i * 2));
        byte low = hexCharToByte(hexString.charAt(i * 2 + 1));
        byte b = (byte) ((high << 4) | low);
        fs.set(i, b);
      }

      int arrayAddr = ((FeatureStructureImpl) fs).getAddress();
      deserializedFsAddrs.add(arrayAddr);
      addFsAddrXmiIdMapping(arrayAddr, xmiId);
View Full Code Here

TOP

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

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.